Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1998-09-01 |
2 | // Created by: Robert COUBLANC | |
3 | // Copyright (c) 1998-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
12 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
b311480e | 16 | |
58655684 | 17 | #include <OpenGl_GlCore20.hxx> |
0a768f56 | 18 | #include <AIS_Shape.hxx> |
0a768f56 | 19 | #include <AIS_InteractiveObject.hxx> |
20 | #include <AIS_ListOfInteractive.hxx> | |
21 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
22 | #include <DBRep.hxx> | |
2bd4c032 | 23 | #include <Graphic3d_AspectMarker3d.hxx> |
7fd59977 | 24 | #include <Graphic3d_ExportFormat.hxx> |
269294d6 | 25 | #include <Graphic3d_NameOfTextureEnv.hxx> |
a79f67f8 | 26 | #include <Graphic3d_GraduatedTrihedron.hxx> |
269294d6 | 27 | #include <Graphic3d_TextureEnv.hxx> |
28 | #include <Graphic3d_TextureParams.hxx> | |
29 | #include <Graphic3d_TypeOfTextureFilter.hxx> | |
4269bd1b | 30 | #include <Graphic3d_AspectFillArea3d.hxx> |
7fd59977 | 31 | #include <ViewerTest.hxx> |
8625ef7e | 32 | #include <ViewerTest_AutoUpdater.hxx> |
7fd59977 | 33 | #include <ViewerTest_EventManager.hxx> |
4754e164 | 34 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> |
4269bd1b | 35 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> |
7fd59977 | 36 | #include <Visual3d_View.hxx> |
25289ec1 | 37 | #include <Visual3d_ViewManager.hxx> |
12381341 | 38 | #include <V3d_AmbientLight.hxx> |
71215351 | 39 | #include <V3d_ColorScale.hxx> |
12381341 | 40 | #include <V3d_DirectionalLight.hxx> |
25289ec1 | 41 | #include <V3d_LayerMgr.hxx> |
12381341 | 42 | #include <V3d_LayerMgrPointer.hxx> |
43 | #include <V3d_PositionalLight.hxx> | |
44 | #include <V3d_SpotLight.hxx> | |
18d715bd | 45 | #include <NCollection_DoubleMap.hxx> |
46 | #include <NCollection_List.hxx> | |
47 | #include <NCollection_Vector.hxx> | |
7fd59977 | 48 | #include <NIS_View.hxx> |
49 | #include <NIS_Triangulated.hxx> | |
50 | #include <NIS_InteractiveContext.hxx> | |
51 | #include <AIS_InteractiveContext.hxx> | |
52 | #include <Draw_Interpretor.hxx> | |
53 | #include <Draw.hxx> | |
54 | #include <Draw_Appli.hxx> | |
7edf74fd | 55 | #include <Aspect_PrintAlgo.hxx> |
692613e5 | 56 | #include <Image_AlienPixMap.hxx> |
58655684 | 57 | #include <OpenGl_GraphicDriver.hxx> |
208e6839 | 58 | #include <OSD_Timer.hxx> |
900f7229 | 59 | #include <TColStd_HSequenceOfAsciiString.hxx> |
59f45b7c | 60 | #include <TColStd_SequenceOfInteger.hxx> |
4754e164 | 61 | #include <TColStd_HSequenceOfReal.hxx> |
62 | #include <TColgp_Array1OfPnt2d.hxx> | |
197ac94e | 63 | #include <TColStd_MapOfAsciiString.hxx> |
20637bd2 | 64 | #include <Visual3d_LayerItem.hxx> |
20637bd2 | 65 | #include <Aspect_TypeOfLine.hxx> |
692613e5 | 66 | #include <Image_Diff.hxx> |
dc3fe572 | 67 | #include <Aspect_DisplayConnection.hxx> |
4269bd1b | 68 | #include <gp_Pnt.hxx> |
69 | #include <gp_Dir.hxx> | |
70 | #include <gp_Pln.hxx> | |
71 | #include <PrsMgr_PresentableObject.hxx> | |
72 | #include <Graphic3d_ClipPlane.hxx> | |
73 | #include <NCollection_DataMap.hxx> | |
74 | #include <Graphic3d_Texture2Dmanual.hxx> | |
75 | #include <Prs3d_ShadingAspect.hxx> | |
6262338c | 76 | #include <Prs3d_Drawer.hxx> |
7fd59977 | 77 | |
25289ec1 | 78 | #ifdef WNT |
79 | #undef DrawText | |
80 | #endif | |
81 | ||
82 | #include <Visual3d_Layer.hxx> | |
692613e5 | 83 | #include <cstdlib> |
25289ec1 | 84 | |
58655684 | 85 | #if defined(_WIN32) |
4fe56619 | 86 | #include <WNT_WClass.hxx> |
87 | #include <WNT_Window.hxx> | |
88 | ||
89 | #if defined(_MSC_VER) | |
90 | #define _CRT_SECURE_NO_DEPRECATE | |
91 | #pragma warning (disable:4996) | |
92 | #endif | |
93 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
4fe56619 | 94 | #include <Cocoa_Window.hxx> |
7fd59977 | 95 | #else |
4fe56619 | 96 | #include <Xw_Window.hxx> |
97 | #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */ | |
98 | #include <X11/Xutil.h> | |
99 | #include <tk.h> | |
7fd59977 | 100 | #endif |
101 | ||
8625ef7e | 102 | inline Standard_Boolean parseOnOff (Standard_CString theArg, |
103 | Standard_Boolean& theIsOn) | |
104 | { | |
105 | TCollection_AsciiString aFlag (theArg); | |
106 | aFlag.LowerCase(); | |
107 | if (aFlag == "on" | |
108 | || aFlag == "1") | |
109 | { | |
110 | theIsOn = Standard_True; | |
111 | return Standard_True; | |
112 | } | |
113 | else if (aFlag == "off" | |
114 | || aFlag == "0") | |
115 | { | |
116 | theIsOn = Standard_False; | |
117 | return Standard_True; | |
118 | } | |
119 | return Standard_False; | |
120 | } | |
121 | ||
b514beda | 122 | // Auxiliary definitions |
123 | static const char THE_KEY_DELETE = 127; | |
7fd59977 | 124 | |
125 | //============================================================================== | |
126 | // VIEWER GLOBAL VARIABLES | |
127 | //============================================================================== | |
128 | ||
129 | Standard_IMPORT Standard_Boolean Draw_VirtualWindows; | |
b514beda | 130 | Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand); |
7fd59977 | 131 | |
132 | Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv); | |
133 | extern const Handle(NIS_InteractiveContext)& TheNISContext(); | |
4754e164 | 134 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
7fd59977 | 135 | |
b514beda | 136 | extern int VErase (Draw_Interpretor& theDI, |
137 | Standard_Integer theArgNb, | |
138 | const char** theArgVec); | |
139 | ||
58655684 | 140 | #if defined(_WIN32) |
7fd59977 | 141 | static Handle(WNT_Window)& VT_GetWindow() { |
142 | static Handle(WNT_Window) WNTWin; | |
143 | return WNTWin; | |
144 | } | |
4fe56619 | 145 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
4fe56619 | 146 | static Handle(Cocoa_Window)& VT_GetWindow() |
147 | { | |
148 | static Handle(Cocoa_Window) aWindow; | |
149 | return aWindow; | |
150 | } | |
151 | extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow); | |
18d715bd | 152 | extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle); |
153 | extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight); | |
154 | ||
7fd59977 | 155 | #else |
7fd59977 | 156 | static Handle(Xw_Window)& VT_GetWindow(){ |
157 | static Handle(Xw_Window) XWWin; | |
158 | return XWWin; | |
159 | } | |
7fd59977 | 160 | |
161 | static void VProcessEvents(ClientData,int); | |
162 | #endif | |
163 | ||
18d715bd | 164 | static Handle(Aspect_DisplayConnection)& GetDisplayConnection() |
165 | { | |
166 | static Handle(Aspect_DisplayConnection) aDisplayConnection; | |
167 | return aDisplayConnection; | |
168 | } | |
169 | ||
170 | static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection) | |
171 | { | |
172 | GetDisplayConnection() = theDisplayConnection; | |
173 | } | |
174 | ||
58655684 | 175 | #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
18d715bd | 176 | Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow) |
dc3fe572 | 177 | { |
0ebaa4db | 178 | Aspect_Handle aWindowHandle = (Aspect_Handle)NULL; |
58655684 | 179 | #if defined(_WIN32) |
18d715bd | 180 | const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow); |
181 | if (!aWindow.IsNull()) | |
182 | return aWindow->HWindow(); | |
183 | #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
184 | const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow); | |
185 | if (!aWindow.IsNull()) | |
186 | return aWindow->XWindow(); | |
187 | #endif | |
188 | return aWindowHandle; | |
dc3fe572 | 189 | } |
18d715bd | 190 | #endif |
dc3fe572 | 191 | |
de75ed09 | 192 | static Standard_Boolean MyHLRIsOn = Standard_False; |
7fd59977 | 193 | |
18d715bd | 194 | NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews; |
58655684 | 195 | static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts; |
18d715bd | 196 | static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers; |
58655684 | 197 | static OpenGl_Caps ViewerTest_myDefaultCaps; |
18d715bd | 198 | |
7fd59977 | 199 | #define ZCLIPWIDTH 1. |
200 | ||
201 | static void OSWindowSetup(); | |
202 | ||
203 | //============================================================================== | |
204 | // EVENT GLOBAL VARIABLES | |
205 | //============================================================================== | |
206 | ||
207 | static int Start_Rot = 0; | |
208 | static int ZClipIsOn = 0; | |
4fe56619 | 209 | int X_Motion = 0; // Current cursor position |
210 | int Y_Motion = 0; | |
211 | int X_ButtonPress = 0; // Last ButtonPress position | |
212 | int Y_ButtonPress = 0; | |
213 | Standard_Boolean IsDragged = Standard_False; | |
8abada55 | 214 | Standard_Boolean DragFirst = Standard_False; |
7fd59977 | 215 | |
216 | //============================================================================== | |
217 | ||
218 | #ifdef WNT | |
219 | static LRESULT WINAPI ViewerWindowProc( | |
220 | HWND hwnd, | |
221 | UINT uMsg, | |
222 | WPARAM wParam, | |
223 | LPARAM lParam ); | |
224 | static LRESULT WINAPI AdvViewerWindowProc( | |
225 | HWND hwnd, | |
226 | UINT uMsg, | |
227 | WPARAM wParam, | |
228 | LPARAM lParam ); | |
229 | #endif | |
230 | ||
231 | ||
232 | //============================================================================== | |
233 | //function : WClass | |
234 | //purpose : | |
235 | //============================================================================== | |
236 | ||
237 | const Handle(MMgt_TShared)& ViewerTest::WClass() | |
238 | { | |
239 | static Handle(MMgt_TShared) theWClass; | |
58655684 | 240 | #if defined(_WIN32) |
4fe56619 | 241 | if (theWClass.IsNull()) |
242 | { | |
7fd59977 | 243 | theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc, |
244 | CS_VREDRAW | CS_HREDRAW, 0, 0, | |
245 | ::LoadCursor (NULL, IDC_ARROW)); | |
246 | } | |
247 | #endif | |
248 | return theWClass; | |
249 | } | |
250 | ||
18d715bd | 251 | //============================================================================== |
252 | //function : CreateName | |
253 | //purpose : Create numerical name for new object in theMap | |
254 | //============================================================================== | |
255 | template <typename ObjectType> | |
256 | TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap, | |
257 | const TCollection_AsciiString& theDefaultString) | |
258 | { | |
259 | if (theObjectMap.IsEmpty()) | |
260 | return theDefaultString + TCollection_AsciiString(1); | |
261 | ||
262 | Standard_Integer aNextKey = 1; | |
263 | Standard_Boolean isFound = Standard_False; | |
264 | while (!isFound) | |
265 | { | |
266 | TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey); | |
267 | // Look for objects with default names | |
268 | if (theObjectMap.IsBound1(aStringKey)) | |
269 | { | |
270 | aNextKey++; | |
271 | } | |
272 | else | |
273 | isFound = Standard_True; | |
274 | } | |
275 | ||
276 | return theDefaultString + TCollection_AsciiString(aNextKey); | |
277 | } | |
278 | ||
279 | //============================================================================== | |
280 | //structure : ViewerTest_Names | |
281 | //purpose : Allow to operate with full view name: driverName/viewerName/viewName | |
282 | //============================================================================== | |
283 | struct ViewerTest_Names | |
284 | { | |
285 | private: | |
286 | TCollection_AsciiString myDriverName; | |
287 | TCollection_AsciiString myViewerName; | |
288 | TCollection_AsciiString myViewName; | |
289 | ||
290 | public: | |
291 | ||
292 | const TCollection_AsciiString& GetDriverName () const | |
293 | { | |
294 | return myDriverName; | |
295 | } | |
296 | void SetDriverName (const TCollection_AsciiString& theDriverName) | |
297 | { | |
298 | myDriverName = theDriverName; | |
299 | } | |
300 | const TCollection_AsciiString& GetViewerName () const | |
301 | { | |
302 | return myViewerName; | |
303 | } | |
304 | void SetViewerName (const TCollection_AsciiString& theViewerName) | |
305 | { | |
306 | myViewerName = theViewerName; | |
307 | } | |
308 | const TCollection_AsciiString& GetViewName () const | |
309 | { | |
310 | return myViewName; | |
311 | } | |
312 | void SetViewName (const TCollection_AsciiString& theViewName) | |
313 | { | |
314 | myViewName = theViewName; | |
315 | } | |
316 | ||
317 | //=========================================================================== | |
318 | //function : Constructor for ViewerTest_Names | |
319 | //purpose : Get view, viewer, driver names from custom string | |
320 | //=========================================================================== | |
321 | ||
322 | ViewerTest_Names (const TCollection_AsciiString& theInputString) | |
323 | { | |
324 | TCollection_AsciiString aName(theInputString); | |
325 | if (theInputString.IsEmpty()) | |
326 | { | |
327 | // Get current configuration | |
328 | if (ViewerTest_myDrivers.IsEmpty()) | |
329 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
330 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
331 | else | |
332 | myDriverName = ViewerTest_myDrivers.Find2 | |
333 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
334 | ||
335 | if(ViewerTest_myContexts.IsEmpty()) | |
336 | { | |
337 | myViewerName = CreateName <Handle(AIS_InteractiveContext)> | |
338 | (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer")); | |
339 | } | |
340 | else | |
341 | myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext()); | |
342 | ||
343 | myViewName = CreateName <Handle(V3d_View)> | |
344 | (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View")); | |
345 | } | |
346 | else | |
347 | { | |
348 | // There is at least view name | |
349 | Standard_Integer aParserNumber = 0; | |
350 | for (Standard_Integer i = 0; i < 3; ++i) | |
351 | { | |
352 | Standard_Integer aParserPos = aName.SearchFromEnd("/"); | |
353 | if(aParserPos != -1) | |
354 | { | |
355 | aParserNumber++; | |
356 | aName.Split(aParserPos-1); | |
357 | } | |
358 | else | |
359 | break; | |
360 | } | |
361 | if (aParserNumber == 0) | |
362 | { | |
363 | // Only view name | |
364 | if (!ViewerTest::GetAISContext().IsNull()) | |
365 | { | |
366 | myDriverName = ViewerTest_myDrivers.Find2 | |
367 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
368 | myViewerName = ViewerTest_myContexts.Find2 | |
369 | (ViewerTest::GetAISContext()); | |
370 | } | |
371 | else | |
372 | { | |
373 | // There is no opened contexts here, need to create names for viewer and driver | |
374 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
375 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
376 | ||
377 | myViewerName = CreateName <Handle(AIS_InteractiveContext)> | |
378 | (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer")); | |
379 | } | |
380 | myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString); | |
381 | } | |
382 | else if (aParserNumber == 1) | |
383 | { | |
384 | // Here is viewerName/viewName | |
385 | if (!ViewerTest::GetAISContext().IsNull()) | |
386 | myDriverName = ViewerTest_myDrivers.Find2 | |
387 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
388 | else | |
389 | { | |
390 | // There is no opened contexts here, need to create name for driver | |
391 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
392 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
393 | } | |
394 | myViewerName = TCollection_AsciiString(myDriverName + "/" + aName); | |
395 | ||
396 | myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString); | |
397 | } | |
398 | else | |
399 | { | |
400 | //Here is driverName/viewerName/viewName | |
401 | myDriverName = TCollection_AsciiString(aName); | |
402 | ||
403 | TCollection_AsciiString aViewerName(theInputString); | |
404 | aViewerName.Split(aViewerName.SearchFromEnd("/") - 1); | |
405 | myViewerName = TCollection_AsciiString(aViewerName); | |
406 | ||
407 | myViewName = TCollection_AsciiString(theInputString); | |
408 | } | |
409 | } | |
410 | } | |
411 | }; | |
412 | ||
413 | //============================================================================== | |
414 | //function : FindContextByView | |
415 | //purpose : Find AIS_InteractiveContext by View | |
416 | //============================================================================== | |
417 | ||
418 | Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView) | |
419 | { | |
420 | Handle(AIS_InteractiveContext) anAISContext; | |
421 | ||
422 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
423 | anIter (ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
424 | { | |
425 | if (anIter.Value()->CurrentViewer() == theView->Viewer()) | |
426 | return anIter.Key2(); | |
427 | } | |
428 | return anAISContext; | |
429 | } | |
430 | ||
431 | ||
432 | //============================================================================== | |
433 | //function : SetWindowTitle | |
434 | //purpose : Set window title | |
435 | //============================================================================== | |
436 | ||
437 | void SetWindowTitle (const Handle(Aspect_Window)& theWindow, | |
438 | Standard_CString theTitle) | |
439 | { | |
58655684 | 440 | #if defined(_WIN32) |
18d715bd | 441 | SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(), |
442 | theTitle); | |
443 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
444 | SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle); | |
445 | #else | |
446 | if(GetDisplayConnection()->GetDisplay()) | |
447 | { | |
448 | Window aWindow = | |
449 | Handle(Xw_Window)::DownCast(theWindow)->XWindow(); | |
450 | XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle); | |
451 | } | |
452 | #endif | |
453 | } | |
454 | ||
455 | //============================================================================== | |
456 | //function : IsWindowOverlapped | |
457 | //purpose : Check if theWindow overlapp another view | |
458 | //============================================================================== | |
459 | ||
460 | Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft, | |
461 | const Standard_Integer thePxTop, | |
462 | const Standard_Integer thePxRight, | |
463 | const Standard_Integer thePxBottom, | |
464 | TCollection_AsciiString& theViewId) | |
465 | { | |
466 | for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
467 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
468 | { | |
469 | Standard_Integer aTop = 0, | |
470 | aLeft = 0, | |
471 | aRight = 0, | |
472 | aBottom = 0; | |
473 | anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom); | |
474 | if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) || | |
475 | (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) || | |
476 | (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) || | |
477 | (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom)) | |
478 | { | |
479 | theViewId = anIter.Key1(); | |
480 | return Standard_True; | |
481 | } | |
482 | } | |
483 | return Standard_False; | |
484 | } | |
485 | ||
486 | // Workaround: to create and delete non-orthographic views outside ViewerTest | |
487 | void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName) | |
488 | { | |
489 | ViewerTest_myViews.UnBind1 (theName); | |
490 | } | |
491 | ||
492 | void ViewerTest::InitViewName (const TCollection_AsciiString& theName, | |
493 | const Handle(V3d_View)& theView) | |
494 | { | |
495 | ViewerTest_myViews.Bind (theName, theView); | |
496 | } | |
497 | ||
498 | TCollection_AsciiString ViewerTest::GetCurrentViewName () | |
499 | { | |
500 | return ViewerTest_myViews.Find2( ViewerTest::CurrentView()); | |
501 | } | |
7fd59977 | 502 | //============================================================================== |
503 | //function : ViewerInit | |
504 | //purpose : Create the window viewer and initialize all the global variable | |
505 | //============================================================================== | |
506 | ||
18d715bd | 507 | TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft, |
508 | const Standard_Integer thePxTop, | |
509 | const Standard_Integer thePxWidth, | |
510 | const Standard_Integer thePxHeight, | |
511 | Standard_CString theViewName, | |
512 | Standard_CString theDisplayName) | |
7fd59977 | 513 | { |
8c3c9904 | 514 | // Default position and dimension of the viewer window. |
4fe56619 | 515 | // Note that left top corner is set to be sufficiently small to have |
8c3c9904 | 516 | // window fit in the small screens (actual for remote desktops, see #23003). |
4fe56619 | 517 | // The position corresponds to the window's client area, thus some |
8c3c9904 | 518 | // gap is added for window frame to be visible. |
519 | Standard_Integer aPxLeft = 20; | |
520 | Standard_Integer aPxTop = 40; | |
7fd59977 | 521 | Standard_Integer aPxWidth = 409; |
522 | Standard_Integer aPxHeight = 409; | |
18d715bd | 523 | Standard_Boolean toCreateViewer = Standard_False; |
524 | ||
58655684 | 525 | Handle(OpenGl_GraphicDriver) aGraphicDriver; |
18d715bd | 526 | ViewerTest_Names aViewNames(theViewName); |
527 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ())) | |
528 | aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View")); | |
529 | ||
530 | if (thePxLeft != 0) | |
531 | aPxLeft = thePxLeft; | |
532 | if (thePxTop != 0) | |
533 | aPxTop = thePxTop; | |
534 | if (thePxWidth != 0) | |
535 | aPxWidth = thePxWidth; | |
536 | if (thePxHeight != 0) | |
7fd59977 | 537 | aPxHeight = thePxHeight; |
4269bd1b | 538 | |
18d715bd | 539 | // Get graphic driver (create it or get from another view) |
540 | if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName())) | |
541 | { | |
542 | // Get connection string | |
58655684 | 543 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
18d715bd | 544 | TCollection_AsciiString aDisplayName(theDisplayName); |
498ce76b | 545 | if (!aDisplayName.IsEmpty()) |
18d715bd | 546 | SetDisplayConnection (new Aspect_DisplayConnection ()); |
547 | else | |
548 | SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName)); | |
18d715bd | 549 | #else |
498ce76b | 550 | (void)theDisplayName; // avoid warning on unused argument |
18d715bd | 551 | SetDisplayConnection (new Aspect_DisplayConnection ()); |
552 | #endif | |
65993a95 | 553 | aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection()); |
58655684 | 554 | aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps; |
18d715bd | 555 | ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver); |
556 | toCreateViewer = Standard_True; | |
557 | } | |
558 | else | |
559 | { | |
58655684 | 560 | aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName())); |
7fd59977 | 561 | } |
562 | ||
18d715bd | 563 | //Dispose the window if input parameters are default |
564 | if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0) | |
7fd59977 | 565 | { |
18d715bd | 566 | Standard_Integer aTop = 0, |
567 | aLeft = 0, | |
568 | aRight = 0, | |
569 | aBottom = 0, | |
570 | aScreenWidth = 0, | |
571 | aScreenHeight = 0; | |
572 | ||
573 | // Get screen resolution | |
574 | #if defined(_WIN32) || defined(__WIN32__) | |
575 | RECT aWindowSize; | |
576 | GetClientRect(GetDesktopWindow(), &aWindowSize); | |
577 | aScreenHeight = aWindowSize.bottom; | |
578 | aScreenWidth = aWindowSize.right; | |
579 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
580 | GetCocoaScreenResolution (aScreenWidth, aScreenHeight); | |
581 | #else | |
582 | Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay()); | |
583 | aScreenWidth = WidthOfScreen(aScreen); | |
584 | aScreenHeight = HeightOfScreen(aScreen); | |
585 | #endif | |
586 | ||
587 | TCollection_AsciiString anOverlappedViewId(""); | |
773f53f1 | 588 | |
589 | while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)) | |
dc3fe572 | 590 | { |
18d715bd | 591 | ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom); |
592 | ||
593 | if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId) | |
594 | && aRight + 2*aPxWidth + 40 > aScreenWidth) | |
595 | { | |
596 | if (aBottom + aPxHeight + 40 > aScreenHeight) | |
597 | { | |
598 | aPxLeft = 20; | |
599 | aPxTop = 40; | |
600 | break; | |
601 | } | |
602 | aPxLeft = 20; | |
603 | aPxTop = aBottom + 40; | |
604 | } | |
605 | else | |
606 | aPxLeft = aRight + 20; | |
dc3fe572 | 607 | } |
18d715bd | 608 | } |
609 | ||
610 | // Get viewer name | |
611 | TCollection_AsciiString aTitle("3D View - "); | |
612 | aTitle = aTitle + aViewNames.GetViewName() + "(*)"; | |
613 | ||
614 | // Change name of current active window | |
615 | if (!ViewerTest::CurrentView().IsNull()) | |
616 | { | |
617 | TCollection_AsciiString aTitle("3D View - "); | |
618 | aTitle = aTitle | |
619 | + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()); | |
620 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
621 | } | |
622 | ||
623 | // Create viewer | |
eb4320f2 | 624 | Handle(V3d_Viewer) a3DViewer; |
18d715bd | 625 | // If it's the single view, we first look for empty context |
626 | if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty()) | |
627 | { | |
628 | NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
629 | anIter(ViewerTest_myContexts); | |
630 | if (anIter.More()) | |
631 | ViewerTest::SetAISContext (anIter.Value()); | |
632 | a3DViewer = ViewerTest::GetAISContext()->CurrentViewer(); | |
18d715bd | 633 | } |
634 | else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())) | |
635 | { | |
636 | ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName())); | |
637 | a3DViewer = ViewerTest::GetAISContext()->CurrentViewer(); | |
18d715bd | 638 | } |
eb4320f2 | 639 | else if (a3DViewer.IsNull()) |
18d715bd | 640 | { |
641 | toCreateViewer = Standard_True; | |
642 | TCollection_ExtendedString NameOfWindow("Viewer3D"); | |
643 | a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString()); | |
644 | ||
645 | NameOfWindow = TCollection_ExtendedString("Collector"); | |
18d715bd | 646 | |
647 | a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK); | |
18d715bd | 648 | } |
649 | ||
650 | // AIS context setup | |
651 | if (ViewerTest::GetAISContext().IsNull() || | |
652 | !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))) | |
653 | { | |
e79a94b9 | 654 | Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer); |
18d715bd | 655 | ViewerTest::SetAISContext (aContext); |
656 | ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext()); | |
657 | } | |
658 | else | |
e79a94b9 | 659 | { |
18d715bd | 660 | ViewerTest::ResetEventManager(); |
e79a94b9 | 661 | } |
18d715bd | 662 | |
663 | // Create window | |
e79a94b9 | 664 | #if defined(_WIN32) |
665 | VT_GetWindow() = new WNT_Window (aTitle.ToCString(), | |
666 | Handle(WNT_WClass)::DownCast (WClass()), | |
667 | Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW, | |
668 | aPxLeft, aPxTop, | |
669 | aPxWidth, aPxHeight, | |
670 | Quantity_NOC_BLACK); | |
4fe56619 | 671 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
e79a94b9 | 672 | VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(), |
673 | aPxLeft, aPxTop, | |
674 | aPxWidth, aPxHeight); | |
675 | ViewerTest_SetCocoaEventManagerView (VT_GetWindow()); | |
7fd59977 | 676 | #else |
e79a94b9 | 677 | VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(), |
678 | aTitle.ToCString(), | |
679 | aPxLeft, aPxTop, | |
680 | aPxWidth, aPxHeight); | |
7fd59977 | 681 | #endif |
18d715bd | 682 | VT_GetWindow()->SetVirtual (Draw_VirtualWindows); |
7fd59977 | 683 | |
18d715bd | 684 | // NIS setup |
685 | Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow()); | |
4269bd1b | 686 | |
18d715bd | 687 | ViewerTest::CurrentView(aView); |
688 | ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView); | |
689 | TheNISContext()->AttachView (aView); | |
7fd59977 | 690 | |
18d715bd | 691 | // Setup for X11 or NT |
692 | OSWindowSetup(); | |
7fd59977 | 693 | |
18d715bd | 694 | // Set parameters for V3d_View and V3d_Viewer |
695 | const Handle (V3d_View) aV3dView = ViewerTest::CurrentView(); | |
696 | aV3dView->SetComputedMode(Standard_False); | |
697 | MyHLRIsOn = aV3dView->ComputedMode(); | |
698 | aV3dView->SetZClippingDepth(0.5); | |
699 | aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.); | |
7fd59977 | 700 | |
18d715bd | 701 | a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK); |
702 | if (toCreateViewer) | |
703 | { | |
7fd59977 | 704 | a3DViewer->SetDefaultLights(); |
705 | a3DViewer->SetLightOn(); | |
18d715bd | 706 | } |
7fd59977 | 707 | |
e79a94b9 | 708 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
4fe56619 | 709 | #if TCL_MAJOR_VERSION < 8 |
18d715bd | 710 | Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()), |
7fd59977 | 711 | TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() ); |
4fe56619 | 712 | #else |
18d715bd | 713 | Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()), |
7fd59977 | 714 | TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() ); |
4fe56619 | 715 | #endif |
716 | #endif | |
7fd59977 | 717 | |
7fd59977 | 718 | VT_GetWindow()->Map(); |
4269bd1b | 719 | |
18d715bd | 720 | // Set the handle of created view in the event manager |
721 | ViewerTest::ResetEventManager(); | |
722 | ||
4fe56619 | 723 | ViewerTest::CurrentView()->Redraw(); |
18d715bd | 724 | |
725 | aView.Nullify(); | |
726 | a3DViewer.Nullify(); | |
18d715bd | 727 | |
728 | return aViewNames.GetViewName(); | |
729 | } | |
730 | ||
4269bd1b | 731 | //============================================================================== |
732 | //function : RedrawAllViews | |
733 | //purpose : Redraw all created views | |
734 | //============================================================================== | |
735 | void ViewerTest::RedrawAllViews() | |
736 | { | |
737 | NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews); | |
738 | for (; aViewIt.More(); aViewIt.Next()) | |
739 | { | |
740 | const Handle(V3d_View)& aView = aViewIt.Key2(); | |
741 | aView->Redraw(); | |
742 | } | |
743 | } | |
744 | ||
7fd59977 | 745 | //============================================================================== |
746 | //function : Vinit | |
747 | //purpose : Create the window viewer and initialize all the global variable | |
e79a94b9 | 748 | // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event |
7fd59977 | 749 | //============================================================================== |
750 | ||
18d715bd | 751 | static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) |
7fd59977 | 752 | { |
e79a94b9 | 753 | if (theArgsNb > 9) |
18d715bd | 754 | { |
e79a94b9 | 755 | std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n" |
756 | << "Type help for more information.\n"; | |
18d715bd | 757 | return 1; |
758 | } | |
18d715bd | 759 | |
e79a94b9 | 760 | TCollection_AsciiString aViewName, aDisplayName; |
761 | Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0; | |
762 | TCollection_AsciiString aName, aValue; | |
763 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
18d715bd | 764 | { |
e79a94b9 | 765 | const TCollection_AsciiString anArg = theArgVec[anArgIt]; |
766 | TCollection_AsciiString anArgCase = anArg; | |
767 | anArgCase.UpperCase(); | |
1d7ca641 | 768 | if (ViewerTest::SplitParameter (anArg, aName, aValue)) |
18d715bd | 769 | { |
e79a94b9 | 770 | aName.UpperCase(); |
771 | if (aName.IsEqual ("NAME")) | |
18d715bd | 772 | { |
773 | aViewName = aValue; | |
774 | } | |
e79a94b9 | 775 | else if (aName.IsEqual ("L") |
776 | || aName.IsEqual ("LEFT")) | |
777 | { | |
18d715bd | 778 | aPxLeft = aValue.IntegerValue(); |
e79a94b9 | 779 | } |
780 | else if (aName.IsEqual ("T") | |
781 | || aName.IsEqual ("TOP")) | |
782 | { | |
18d715bd | 783 | aPxTop = aValue.IntegerValue(); |
e79a94b9 | 784 | } |
785 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
786 | else if (aName.IsEqual ("DISP") | |
787 | || aName.IsEqual ("DISPLAY")) | |
788 | { | |
18d715bd | 789 | aDisplayName = aValue; |
e79a94b9 | 790 | } |
791 | #endif | |
792 | else if (aName.IsEqual ("W") | |
793 | || aName.IsEqual ("WIDTH")) | |
794 | { | |
18d715bd | 795 | aPxWidth = aValue.IntegerValue(); |
e79a94b9 | 796 | } |
797 | else if (aName.IsEqual ("H") | |
798 | || aName.IsEqual ("HEIGHT")) | |
799 | { | |
18d715bd | 800 | aPxHeight = aValue.IntegerValue(); |
e79a94b9 | 801 | } |
18d715bd | 802 | else |
803 | { | |
e79a94b9 | 804 | std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n"; |
18d715bd | 805 | } |
806 | } | |
e79a94b9 | 807 | else if (aViewName.IsEmpty()) |
808 | { | |
809 | aViewName = anArg; | |
810 | } | |
811 | else | |
812 | { | |
813 | std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n"; | |
814 | } | |
18d715bd | 815 | } |
816 | ||
817 | ViewerTest_Names aViewNames (aViewName); | |
e79a94b9 | 818 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName())) |
18d715bd | 819 | { |
e79a94b9 | 820 | TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName(); |
821 | theDi.Eval (aCommand.ToCString()); | |
18d715bd | 822 | return 0; |
823 | } | |
824 | ||
825 | TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight, | |
826 | aViewName.ToCString(), | |
827 | aDisplayName.ToCString()); | |
e79a94b9 | 828 | theDi << aViewId; |
7fd59977 | 829 | return 0; |
830 | } | |
831 | ||
0a768f56 | 832 | //============================================================================== |
833 | //function : VHLR | |
834 | //purpose : hidden lines removal algorithm | |
e9224045 | 835 | //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}] |
0a768f56 | 836 | //============================================================================== |
837 | ||
838 | static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
839 | { | |
840 | if (ViewerTest::CurrentView().IsNull()) | |
841 | { | |
842 | di << argv[0] << ": Call vinit before this command, please.\n"; | |
843 | return 1; | |
844 | } | |
845 | ||
e9224045 | 846 | if (argc < 2) |
0a768f56 | 847 | { |
848 | di << argv[0] << ": Wrong number of command arguments.\n" | |
849 | << "Type help " << argv[0] << " for more information.\n"; | |
850 | return 1; | |
851 | } | |
852 | ||
e9224045 | 853 | // Enable or disable HLR mode. |
0a768f56 | 854 | Standard_Boolean isHLROn = |
855 | (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False; | |
856 | ||
e9224045 | 857 | if (isHLROn != MyHLRIsOn) |
0a768f56 | 858 | { |
e9224045 | 859 | MyHLRIsOn = isHLROn; |
860 | ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn); | |
0a768f56 | 861 | } |
862 | ||
e9224045 | 863 | // Show or hide hidden lines in HLR mode. |
864 | Standard_Boolean isCurrentShowHidden | |
865 | = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine(); | |
866 | ||
867 | Standard_Boolean isShowHidden = | |
868 | (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False) | |
869 | : isCurrentShowHidden; | |
870 | ||
871 | ||
872 | if (isShowHidden != isCurrentShowHidden) | |
873 | { | |
874 | if (isShowHidden) | |
875 | { | |
876 | ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine(); | |
877 | } | |
878 | else | |
879 | { | |
880 | ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine(); | |
881 | } | |
882 | ||
883 | // Redisplay shapes. | |
884 | if (MyHLRIsOn) | |
885 | { | |
886 | AIS_ListOfInteractive aListOfShapes; | |
887 | ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes); | |
888 | ||
889 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next()) | |
890 | { | |
891 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value()); | |
892 | if (aShape.IsNull()) | |
893 | { | |
894 | continue; | |
895 | } | |
36132a2e | 896 | ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False); |
e9224045 | 897 | } |
898 | } | |
899 | } | |
0a768f56 | 900 | |
e9224045 | 901 | ViewerTest::CurrentView()->Update(); |
0a768f56 | 902 | return 0; |
903 | } | |
904 | ||
905 | //============================================================================== | |
906 | //function : VHLRType | |
907 | //purpose : change type of using HLR algorithm | |
908 | //============================================================================== | |
909 | ||
910 | static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
911 | { | |
912 | if (ViewerTest::CurrentView().IsNull()) | |
913 | { | |
914 | di << argv[0] << ": Call vinit before this command, please.\n"; | |
915 | return 1; | |
916 | } | |
917 | ||
918 | if (argc < 2) | |
919 | { | |
920 | di << argv[0] << ": Wrong number of command arguments.\n" | |
921 | << "Type help " << argv[0] << " for more information.\n"; | |
922 | return 1; | |
923 | } | |
924 | ||
925 | Prs3d_TypeOfHLR aTypeOfHLR = | |
926 | (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo; | |
927 | ||
928 | if (argc == 2) | |
929 | { | |
930 | AIS_ListOfInteractive aListOfShapes; | |
931 | ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes); | |
932 | ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR); | |
933 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); | |
934 | anIter.More(); anIter.Next()) | |
935 | { | |
936 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()); | |
937 | if (aShape.IsNull()) | |
938 | continue; | |
939 | if (aShape->TypeOfHLR() != aTypeOfHLR) | |
940 | aShape->SetTypeOfHLR (aTypeOfHLR); | |
941 | if (MyHLRIsOn) | |
36132a2e | 942 | ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False); |
0a768f56 | 943 | } |
944 | ViewerTest::CurrentView()->Update(); | |
945 | return 0; | |
946 | } | |
947 | else | |
948 | { | |
949 | for (Standard_Integer i = 2; i < argc; ++i) | |
950 | { | |
951 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
952 | TCollection_AsciiString aName (argv[i]); | |
953 | ||
954 | if (!aMap.IsBound2 (aName)) | |
955 | { | |
956 | di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n"; | |
957 | continue; | |
958 | } | |
959 | Handle(AIS_Shape) anAISObject = | |
960 | Handle(AIS_Shape)::DownCast (aMap.Find2(aName)); | |
961 | if (anAISObject.IsNull()) | |
962 | continue; | |
963 | anAISObject->SetTypeOfHLR (aTypeOfHLR); | |
964 | if (MyHLRIsOn) | |
36132a2e | 965 | ViewerTest::GetAISContext()->Redisplay (anAISObject, Standard_False); |
0a768f56 | 966 | } |
967 | ViewerTest::CurrentView()->Update(); | |
968 | } | |
969 | ||
970 | return 0; | |
971 | } | |
972 | ||
18d715bd | 973 | //============================================================================== |
974 | //function : FindViewIdByWindowHandle | |
975 | //purpose : Find theView Id in the map of views by window handle | |
976 | //============================================================================== | |
977 | #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
978 | TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle) | |
979 | { | |
980 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
981 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
982 | { | |
983 | Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window()); | |
984 | if (aWindowHandle == theWindowHandle) | |
985 | return anIter.Key1(); | |
986 | } | |
987 | return TCollection_AsciiString(""); | |
988 | } | |
989 | #endif | |
990 | ||
991 | //============================================================================== | |
992 | //function : ActivateView | |
993 | //purpose : Make the view active | |
994 | //============================================================================== | |
995 | ||
996 | void ActivateView (const TCollection_AsciiString& theViewName) | |
997 | { | |
998 | const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); | |
999 | if (!aView.IsNull()) | |
1000 | { | |
1001 | Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView); | |
1002 | if (!anAISContext.IsNull()) | |
1003 | { | |
1004 | if (!ViewerTest::CurrentView().IsNull()) | |
1005 | { | |
1006 | TCollection_AsciiString aTitle("3D View - "); | |
1007 | aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()); | |
1008 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
1009 | } | |
1010 | ||
1011 | ViewerTest::CurrentView (aView); | |
1012 | // Update degenerate mode | |
1013 | MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode(); | |
1014 | ViewerTest::SetAISContext (anAISContext); | |
1015 | TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - "); | |
1016 | aTitle = aTitle + theViewName + "(*)"; | |
1017 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
1018 | #if defined(_WIN32) || defined(__WIN32__) | |
1019 | VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window()); | |
1020 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
1021 | VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window()); | |
1022 | #else | |
1023 | VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window()); | |
1024 | #endif | |
1025 | SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); | |
1026 | ViewerTest::CurrentView()->Redraw(); | |
1027 | } | |
1028 | } | |
1029 | } | |
1030 | ||
0e93d9e5 | 1031 | //============================================================================== |
1032 | //function : RemoveView | |
1033 | //purpose : | |
1034 | //============================================================================== | |
1035 | void ViewerTest::RemoveView (const Handle(V3d_View)& theView, | |
1036 | const Standard_Boolean theToRemoveContext) | |
1037 | { | |
1038 | if (!ViewerTest_myViews.IsBound2 (theView)) | |
1039 | { | |
1040 | return; | |
1041 | } | |
1042 | ||
1043 | const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView); | |
1044 | RemoveView (aViewName, theToRemoveContext); | |
1045 | } | |
1046 | ||
18d715bd | 1047 | //============================================================================== |
1048 | //function : RemoveView | |
1049 | //purpose : Close and remove view from display, clear maps if neccessary | |
1050 | //============================================================================== | |
1051 | void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved) | |
1052 | { | |
1053 | if (!ViewerTest_myViews.IsBound1(theViewName)) | |
1054 | { | |
1055 | cout << "Wrong view name\n"; | |
1056 | return; | |
1057 | } | |
1058 | ||
1059 | // Activate another view if it's active now | |
1060 | if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView()) | |
1061 | { | |
1062 | if (ViewerTest_myViews.Extent() > 1) | |
1063 | { | |
1064 | TCollection_AsciiString aNewViewName; | |
1065 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator | |
1066 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
1067 | if (anIter.Key1() != theViewName) | |
1068 | { | |
1069 | aNewViewName = anIter.Key1(); | |
1070 | break; | |
1071 | } | |
1072 | ActivateView (aNewViewName); | |
1073 | } | |
1074 | else | |
1075 | { | |
1076 | Handle(V3d_View) anEmptyView; | |
1077 | #if defined(_WIN32) || defined(__WIN32__) | |
1078 | Handle(WNT_Window) anEmptyWindow; | |
1079 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
1080 | Handle(Cocoa_Window) anEmptyWindow; | |
1081 | #else | |
1082 | Handle(Xw_Window) anEmptyWindow; | |
1083 | #endif | |
1084 | VT_GetWindow() = anEmptyWindow; | |
1085 | ViewerTest::CurrentView (anEmptyView); | |
1086 | if (isContextRemoved) | |
1087 | { | |
1088 | Handle(AIS_InteractiveContext) anEmptyContext; | |
1089 | ViewerTest::SetAISContext(anEmptyContext); | |
1090 | } | |
1091 | } | |
1092 | } | |
1093 | ||
1094 | // Delete view | |
1095 | Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); | |
1096 | Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView); | |
1097 | ||
1098 | // Remove view resources | |
1099 | TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView)); | |
1100 | ViewerTest_myViews.UnBind1(theViewName); | |
1101 | aView->Remove(); | |
1102 | ||
1103 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
1104 | XFlush (GetDisplayConnection()->GetDisplay()); | |
1105 | #endif | |
1106 | ||
1107 | // Keep context opened only if the closed view is last to avoid | |
1108 | // unused empty contexts | |
1109 | if (!aCurrentContext.IsNull()) | |
1110 | { | |
1111 | // Check if there are more difined views in the viewer | |
1112 | aCurrentContext->CurrentViewer()->InitDefinedViews(); | |
1113 | if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews()) | |
1114 | { | |
1115 | // Remove driver if there is no viewers that use it | |
1116 | Standard_Boolean isRemoveDriver = Standard_True; | |
1117 | for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
1118 | anIter(ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
1119 | { | |
1120 | if (aCurrentContext != anIter.Key2() && | |
1121 | aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver()) | |
1122 | { | |
1123 | isRemoveDriver = Standard_False; | |
1124 | break; | |
1125 | } | |
1126 | } | |
1127 | if(isRemoveDriver) | |
1128 | { | |
1129 | ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver()); | |
1130 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
1131 | #if TCL_MAJOR_VERSION < 8 | |
1132 | Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay())); | |
1133 | #else | |
1134 | Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay())); | |
1135 | #endif | |
1136 | #endif | |
1137 | } | |
1138 | ||
1139 | ViewerTest_myContexts.UnBind2(aCurrentContext); | |
1140 | } | |
1141 | } | |
1142 | cout << "3D View - " << theViewName << " was deleted.\n"; | |
1143 | ||
1144 | } | |
1145 | ||
1146 | //============================================================================== | |
1147 | //function : VClose | |
1148 | //purpose : Remove the view defined by its name | |
1149 | //============================================================================== | |
1150 | ||
d0cc1cb7 | 1151 | static int VClose (Draw_Interpretor& /*theDi*/, |
1152 | Standard_Integer theArgsNb, | |
1153 | const char** theArgVec) | |
18d715bd | 1154 | { |
18d715bd | 1155 | NCollection_List<TCollection_AsciiString> aViewList; |
d0cc1cb7 | 1156 | if (theArgsNb > 1) |
18d715bd | 1157 | { |
d0cc1cb7 | 1158 | TCollection_AsciiString anArg (theArgVec[1]); |
1159 | anArg.UpperCase(); | |
1160 | if (anArg.IsEqual ("ALL") | |
1161 | || anArg.IsEqual ("*")) | |
1162 | { | |
1163 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews); | |
1164 | anIter.More(); anIter.Next()) | |
1165 | { | |
1166 | aViewList.Append (anIter.Key1()); | |
1167 | } | |
1168 | if (aViewList.IsEmpty()) | |
1169 | { | |
1170 | std::cout << "No view to close\n"; | |
1171 | return 0; | |
1172 | } | |
1173 | } | |
1174 | else | |
18d715bd | 1175 | { |
d0cc1cb7 | 1176 | ViewerTest_Names aViewName (theArgVec[1]); |
1177 | if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName())) | |
1178 | { | |
1179 | std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n"; | |
1180 | return 1; | |
1181 | } | |
1182 | aViewList.Append (aViewName.GetViewName()); | |
18d715bd | 1183 | } |
1184 | } | |
1185 | else | |
1186 | { | |
d0cc1cb7 | 1187 | // close active view |
1188 | if (ViewerTest::CurrentView().IsNull()) | |
1189 | { | |
1190 | std::cerr << "No active view!\n"; | |
1191 | return 1; | |
1192 | } | |
1193 | aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView())); | |
18d715bd | 1194 | } |
1195 | ||
d0cc1cb7 | 1196 | Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1); |
18d715bd | 1197 | for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList); |
1198 | anIter.More(); anIter.Next()) | |
1199 | { | |
d0cc1cb7 | 1200 | ViewerTest::RemoveView (anIter.Value(), toRemoveContext); |
18d715bd | 1201 | } |
1202 | ||
1203 | return 0; | |
1204 | } | |
1205 | ||
1206 | //============================================================================== | |
1207 | //function : VActivate | |
1208 | //purpose : Activate the view defined by its ID | |
1209 | //============================================================================== | |
1210 | ||
1211 | static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
1212 | { | |
1213 | if (theArgsNb > 2) | |
1214 | { | |
1215 | theDi << theArgVec[0] << ": wrong number of command arguments.\n" | |
1216 | << "Usage: " << theArgVec[0] << " ViewID\n"; | |
1217 | return 1; | |
1218 | } | |
1219 | if(theArgsNb == 1) | |
1220 | { | |
1221 | theDi.Eval("vviewlist"); | |
1222 | return 0; | |
1223 | } | |
1224 | ||
1225 | TCollection_AsciiString aNameString(theArgVec[1]); | |
29cb310a | 1226 | if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 ) |
18d715bd | 1227 | { |
1228 | TCollection_AsciiString aTitle("3D View - "); | |
1229 | aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView()); | |
1230 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
1231 | Handle(V3d_View) anEmptyView; | |
1232 | #if defined(_WIN32) || defined(__WIN32__) | |
1233 | Handle(WNT_Window) anEmptyWindow; | |
1234 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
1235 | Handle(Cocoa_Window) anEmptyWindow; | |
1236 | #else | |
1237 | Handle(Xw_Window) anEmptyWindow; | |
1238 | #endif | |
1239 | VT_GetWindow() = anEmptyWindow; | |
1240 | ViewerTest::CurrentView (anEmptyView); | |
1241 | ViewerTest::ResetEventManager(); | |
1242 | theDi << theArgVec[0] << ": all views are inactive\n"; | |
1243 | return 0; | |
1244 | } | |
1245 | ||
1246 | ViewerTest_Names aViewNames(aNameString); | |
1247 | ||
1248 | // Check if this view exists in the viewer with the driver | |
1249 | if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName())) | |
1250 | { | |
1251 | theDi << "Wrong view name\n"; | |
1252 | return 1; | |
1253 | } | |
1254 | ||
1255 | // Check if it is active already | |
1256 | if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName())) | |
1257 | { | |
1258 | theDi << theArgVec[0] << ": the view is active already\n"; | |
1259 | return 0; | |
1260 | } | |
1261 | ||
1262 | ActivateView (aViewNames.GetViewName()); | |
1263 | return 0; | |
1264 | } | |
1265 | ||
1266 | //============================================================================== | |
1267 | //function : VViewList | |
1268 | //purpose : Print current list of views per viewer and graphic driver ID | |
1269 | // shared between viewers | |
1270 | //============================================================================== | |
1271 | ||
1272 | static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
1273 | { | |
1274 | if (theArgsNb > 2) | |
1275 | { | |
1276 | theDi << theArgVec[0] << ": Wrong number of command arguments\n" | |
29cb310a | 1277 | << "Usage: " << theArgVec[0] << " name"; |
18d715bd | 1278 | return 1; |
1279 | } | |
1280 | if (ViewerTest_myContexts.Size() < 1) | |
1281 | return 0; | |
1282 | ||
18d715bd | 1283 | Standard_Boolean isTreeView = |
29cb310a | 1284 | (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 )); |
18d715bd | 1285 | |
1286 | if (isTreeView) | |
1287 | theDi << theArgVec[0] <<":\n"; | |
1288 | ||
1289 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
1290 | aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next()) | |
1291 | { | |
1292 | if (isTreeView) | |
1293 | theDi << aDriverIter.Key1() << ":\n"; | |
1294 | ||
1295 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
1296 | aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next()) | |
1297 | { | |
1298 | if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1) | |
1299 | { | |
1300 | if (isTreeView) | |
1301 | { | |
1302 | TCollection_AsciiString aContextName(aContextIter.Key1()); | |
1303 | theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n"; | |
1304 | } | |
1305 | ||
1306 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
1307 | aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next()) | |
1308 | { | |
1309 | if (aViewIter.Key1().Search(aContextIter.Key1()) != -1) | |
1310 | { | |
1311 | TCollection_AsciiString aViewName(aViewIter.Key1()); | |
1312 | if (isTreeView) | |
1313 | { | |
1314 | if (aViewIter.Value() == ViewerTest::CurrentView()) | |
1315 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n"; | |
1316 | else | |
1317 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n"; | |
1318 | } | |
1319 | else | |
1320 | { | |
1321 | theDi << aViewName << " "; | |
1322 | } | |
1323 | } | |
1324 | } | |
1325 | } | |
1326 | } | |
1327 | } | |
1328 | return 0; | |
1329 | } | |
1330 | ||
7fd59977 | 1331 | //============================================================================== |
4fe56619 | 1332 | //function : VT_ProcessKeyPress |
7fd59977 | 1333 | //purpose : Handle KeyPress event from a CString |
1334 | //============================================================================== | |
4fe56619 | 1335 | void VT_ProcessKeyPress (const char* buf_ret) |
7fd59977 | 1336 | { |
1337 | //cout << "KeyPress" << endl; | |
1338 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
1339 | const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView); | |
1340 | // Letter in alphabetic order | |
1341 | ||
b514beda | 1342 | if (!strcasecmp (buf_ret, "A")) |
1343 | { | |
7fd59977 | 1344 | // AXO |
1345 | aView->SetProj(V3d_XposYnegZpos); | |
1346 | } | |
b514beda | 1347 | else if (!strcasecmp (buf_ret, "D")) |
1348 | { | |
7fd59977 | 1349 | // Reset |
1350 | aView->Reset(); | |
1351 | } | |
b514beda | 1352 | else if (!strcasecmp (buf_ret, "F")) |
1353 | { | |
7fd59977 | 1354 | // FitAll |
1355 | if (aNisView.IsNull()) | |
1356 | aView->FitAll(); | |
1357 | else | |
1358 | aNisView->FitAll3d(); | |
1359 | } | |
b514beda | 1360 | else if (!strcasecmp (buf_ret, "H")) |
1361 | { | |
7fd59977 | 1362 | // HLR |
1363 | cout << "HLR" << endl; | |
de75ed09 | 1364 | aView->SetComputedMode (!aView->ComputedMode()); |
1365 | MyHLRIsOn = aView->ComputedMode(); | |
7fd59977 | 1366 | } |
b514beda | 1367 | else if (!strcasecmp (buf_ret, "P")) |
1368 | { | |
0a768f56 | 1369 | // Type of HLR |
1370 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
1371 | if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo) | |
1372 | aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo); | |
1373 | else | |
1374 | aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo); | |
1375 | if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0) | |
1376 | { | |
1377 | AIS_ListOfInteractive aListOfShapes; | |
1378 | aContext->DisplayedObjects(aListOfShapes); | |
1379 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); | |
1380 | anIter.More(); anIter.Next()) | |
1381 | { | |
1382 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()); | |
1383 | if (aShape.IsNull()) | |
1384 | continue; | |
1385 | if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo) | |
1386 | aShape->SetTypeOfHLR (Prs3d_TOH_Algo); | |
1387 | else | |
1388 | aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo); | |
36132a2e | 1389 | aContext->Redisplay (aShape, Standard_False); |
0a768f56 | 1390 | } |
1391 | } | |
1392 | else | |
1393 | { | |
1394 | for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()) | |
1395 | { | |
1396 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current()); | |
1397 | if (aShape.IsNull()) | |
1398 | continue; | |
1399 | if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo) | |
1400 | aShape->SetTypeOfHLR (Prs3d_TOH_Algo); | |
1401 | else | |
1402 | aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo); | |
36132a2e | 1403 | aContext->Redisplay (aShape, Standard_False); |
0a768f56 | 1404 | } |
1405 | } | |
1406 | ||
1407 | aContext->UpdateCurrentViewer(); | |
4269bd1b | 1408 | |
0a768f56 | 1409 | } |
b514beda | 1410 | else if (!strcasecmp (buf_ret, "S")) |
1411 | { | |
1412 | std::cout << "setup Shaded display mode" << std::endl; | |
4fe56619 | 1413 | |
7fd59977 | 1414 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
1415 | if(Ctx->NbCurrents()==0 || | |
1416 | Ctx->NbSelected()==0) | |
1417 | Ctx->SetDisplayMode(AIS_Shaded); | |
1418 | else{ | |
1419 | if(Ctx->HasOpenedContext()){ | |
1420 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
1421 | Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False); | |
1422 | } | |
1423 | else{ | |
1424 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) | |
1425 | Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False); | |
1426 | } | |
1427 | Ctx->UpdateCurrentViewer(); | |
1428 | } | |
1429 | } | |
b514beda | 1430 | else if (!strcasecmp (buf_ret, "U")) |
1431 | { | |
41811896 | 1432 | // Unset display mode |
b514beda | 1433 | std::cout << "reset display mode to defaults" << std::endl; |
4fe56619 | 1434 | |
7fd59977 | 1435 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
1436 | if(Ctx->NbCurrents()==0 || | |
1437 | Ctx->NbSelected()==0) | |
1438 | Ctx->SetDisplayMode(AIS_WireFrame); | |
1439 | else{ | |
1440 | if(Ctx->HasOpenedContext()){ | |
1441 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
1442 | Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False); | |
1443 | } | |
1444 | else{ | |
1445 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) | |
1446 | Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False); | |
1447 | } | |
1448 | Ctx->UpdateCurrentViewer(); | |
1449 | } | |
1450 | ||
1451 | } | |
b514beda | 1452 | else if (!strcasecmp (buf_ret, "T")) |
1453 | { | |
7fd59977 | 1454 | // Top |
1455 | aView->SetProj(V3d_Zpos); | |
1456 | } | |
b514beda | 1457 | else if (!strcasecmp (buf_ret, "B")) |
1458 | { | |
41811896 | 1459 | // Bottom |
7fd59977 | 1460 | aView->SetProj(V3d_Zneg); |
1461 | } | |
b514beda | 1462 | else if (!strcasecmp (buf_ret, "L")) |
1463 | { | |
41811896 | 1464 | // Left |
7fd59977 | 1465 | aView->SetProj(V3d_Xneg); |
1466 | } | |
b514beda | 1467 | else if (!strcasecmp (buf_ret, "R")) |
1468 | { | |
41811896 | 1469 | // Right |
7fd59977 | 1470 | aView->SetProj(V3d_Xpos); |
1471 | } | |
b514beda | 1472 | else if (!strcasecmp (buf_ret, "W")) |
1473 | { | |
1474 | std::cout << "setup WireFrame display mode" << std::endl; | |
7fd59977 | 1475 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
1476 | if(Ctx->NbCurrents()==0 || | |
1477 | Ctx->NbSelected()==0) | |
1478 | Ctx->SetDisplayMode(AIS_WireFrame); | |
1479 | else{ | |
1480 | if(Ctx->HasOpenedContext()){ | |
1481 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
1482 | Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False); | |
1483 | } | |
1484 | else{ | |
1485 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) | |
1486 | Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False); | |
1487 | } | |
1488 | Ctx->UpdateCurrentViewer(); | |
1489 | } | |
1490 | } | |
b514beda | 1491 | else if (!strcasecmp (buf_ret, "Z")) |
1492 | { | |
7fd59977 | 1493 | // ZCLIP |
7fd59977 | 1494 | if ( ZClipIsOn ) { |
1495 | cout << "ZClipping OFF" << endl; | |
1496 | ZClipIsOn = 0; | |
1497 | ||
1498 | aView->SetZClippingType(V3d_OFF); | |
1499 | aView->Redraw(); | |
1500 | } | |
1501 | else { | |
1502 | cout << "ZClipping ON" << endl; | |
1503 | ZClipIsOn = 1; | |
1504 | ||
1505 | aView->SetZClippingType(V3d_FRONT); | |
1506 | aView->Redraw(); | |
1507 | } | |
1508 | } | |
b514beda | 1509 | else if (!strcasecmp (buf_ret, ",")) |
1510 | { | |
7fd59977 | 1511 | ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView()); |
7fd59977 | 1512 | } |
b514beda | 1513 | else if (!strcasecmp (buf_ret, ".")) |
1514 | { | |
7fd59977 | 1515 | ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView()); |
1516 | } | |
b514beda | 1517 | else if (*buf_ret == THE_KEY_DELETE) |
1518 | { | |
1519 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
1520 | if (!aCtx.IsNull() | |
1521 | && aCtx->NbCurrents() > 0 | |
1522 | && aCtx->NbSelected() > 0) | |
1523 | { | |
1524 | Draw_Interprete ("verase"); | |
1525 | } | |
1526 | } | |
1527 | else | |
1528 | { | |
1529 | // Number | |
91322f44 | 1530 | Standard_Integer Num = Draw::Atoi(buf_ret); |
7fd59977 | 1531 | if(Num>=0 && Num<=7) |
1532 | ViewerTest::StandardModeActivation(Num); | |
1533 | } | |
1534 | } | |
1535 | ||
1536 | //============================================================================== | |
4fe56619 | 1537 | //function : VT_ProcessExpose |
7fd59977 | 1538 | //purpose : Redraw the View on an Expose Event |
1539 | //============================================================================== | |
4fe56619 | 1540 | void VT_ProcessExpose() |
1541 | { | |
1542 | Handle(V3d_View) aView3d = ViewerTest::CurrentView(); | |
1543 | if (!aView3d.IsNull()) | |
1544 | { | |
1545 | aView3d->Redraw(); | |
1546 | } | |
7fd59977 | 1547 | } |
1548 | ||
1549 | //============================================================================== | |
4fe56619 | 1550 | //function : VT_ProcessConfigure |
7fd59977 | 1551 | //purpose : Resize the View on an Configure Event |
1552 | //============================================================================== | |
4fe56619 | 1553 | void VT_ProcessConfigure() |
7fd59977 | 1554 | { |
4fe56619 | 1555 | Handle(V3d_View) aView3d = ViewerTest::CurrentView(); |
1556 | if (aView3d.IsNull()) | |
1557 | { | |
1558 | return; | |
1559 | } | |
1560 | ||
1561 | aView3d->MustBeResized(); | |
1562 | aView3d->Update(); | |
1563 | aView3d->Redraw(); | |
7fd59977 | 1564 | } |
1565 | ||
1566 | //============================================================================== | |
4fe56619 | 1567 | //function : VT_ProcessButton1Press |
7fd59977 | 1568 | //purpose : Picking |
1569 | //============================================================================== | |
e79a94b9 | 1570 | Standard_Boolean VT_ProcessButton1Press (Standard_Integer , |
1571 | const char** theArgVec, | |
1572 | Standard_Boolean theToPick, | |
1573 | Standard_Boolean theIsShift) | |
7fd59977 | 1574 | { |
e79a94b9 | 1575 | if (theToPick) |
1576 | { | |
7fd59977 | 1577 | Standard_Real X, Y, Z; |
e79a94b9 | 1578 | ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z); |
7fd59977 | 1579 | |
e79a94b9 | 1580 | Draw::Set (theArgVec[1], X); |
1581 | Draw::Set (theArgVec[2], Y); | |
1582 | Draw::Set (theArgVec[3], Z); | |
1583 | } | |
7fd59977 | 1584 | |
e79a94b9 | 1585 | if (theIsShift) |
1586 | { | |
1587 | ViewerTest::CurrentEventManager()->ShiftSelect(); | |
1588 | } | |
7fd59977 | 1589 | else |
e79a94b9 | 1590 | { |
1591 | ViewerTest::CurrentEventManager()->Select(); | |
1592 | } | |
7fd59977 | 1593 | |
e79a94b9 | 1594 | return Standard_False; |
7fd59977 | 1595 | } |
1596 | ||
1597 | //============================================================================== | |
4fe56619 | 1598 | //function : VT_ProcessButton1Release |
1599 | //purpose : End selecting | |
7fd59977 | 1600 | //============================================================================== |
4fe56619 | 1601 | void VT_ProcessButton1Release (Standard_Boolean theIsShift) |
1602 | { | |
1603 | if (IsDragged) | |
1604 | { | |
1605 | IsDragged = Standard_False; | |
1606 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
1607 | if (theIsShift) | |
1608 | { | |
1609 | EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion), | |
1610 | Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion)); | |
1611 | } | |
1612 | else | |
1613 | { | |
1614 | EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion), | |
1615 | Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion)); | |
1616 | } | |
1617 | } | |
1618 | } | |
7fd59977 | 1619 | |
4fe56619 | 1620 | //============================================================================== |
1621 | //function : VT_ProcessButton3Press | |
1622 | //purpose : Start Rotation | |
1623 | //============================================================================== | |
1624 | void VT_ProcessButton3Press() | |
1625 | { | |
7fd59977 | 1626 | Start_Rot = 1; |
de75ed09 | 1627 | if (MyHLRIsOn) |
1628 | { | |
1629 | ViewerTest::CurrentView()->SetComputedMode (Standard_False); | |
1630 | } | |
7fd59977 | 1631 | ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress ); |
7fd59977 | 1632 | } |
4fe56619 | 1633 | |
7fd59977 | 1634 | //============================================================================== |
4fe56619 | 1635 | //function : VT_ProcessButton3Release |
1636 | //purpose : End rotation | |
7fd59977 | 1637 | //============================================================================== |
4fe56619 | 1638 | void VT_ProcessButton3Release() |
1639 | { | |
1640 | if (Start_Rot) | |
1641 | { | |
7fd59977 | 1642 | Start_Rot = 0; |
de75ed09 | 1643 | if (MyHLRIsOn) |
1644 | { | |
1645 | ViewerTest::CurrentView()->SetComputedMode (Standard_True); | |
1646 | } | |
7fd59977 | 1647 | } |
7fd59977 | 1648 | } |
1649 | ||
1650 | //============================================================================== | |
1651 | //function : ProcessZClipMotion | |
1652 | //purpose : Zoom | |
1653 | //============================================================================== | |
1654 | ||
1655 | void ProcessZClipMotion() | |
1656 | { | |
1657 | Handle(V3d_View) a3DView = ViewerTest::CurrentView(); | |
1658 | if ( Abs(X_Motion - X_ButtonPress) > 2 ) { | |
7fd59977 | 1659 | |
1660 | //Quantity_Length VDX, VDY; | |
1661 | //a3DView->Size(VDX,VDY); | |
1662 | //Standard_Real VDZ = a3DView->ZSize(); | |
1663 | //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ); | |
1664 | ||
58978f9b | 1665 | Quantity_Length aDx = a3DView->Convert(X_Motion - X_ButtonPress); |
7fd59977 | 1666 | |
1667 | // Front = Depth + width/2. | |
58978f9b | 1668 | Standard_Real aDepth = 0.5; |
1669 | Standard_Real aWidth = 0.1; | |
1670 | a3DView->ZClipping(aDepth,aWidth); | |
7fd59977 | 1671 | |
58978f9b | 1672 | aDepth += aDx; |
7fd59977 | 1673 | |
1674 | //printf("dx %lf Depth %lf Width %lf\n", dx, D, W); | |
1675 | ||
58978f9b | 1676 | a3DView->SetZClippingDepth(aDepth); |
7fd59977 | 1677 | |
1678 | a3DView->Redraw(); | |
1679 | ||
1680 | X_ButtonPress = X_Motion; | |
1681 | Y_ButtonPress = Y_Motion; | |
1682 | } | |
1683 | } | |
1684 | ||
1685 | //============================================================================== | |
1686 | //function : ProcessControlButton1Motion | |
1687 | //purpose : Zoom | |
1688 | //============================================================================== | |
1689 | ||
900f7229 | 1690 | #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX) |
7fd59977 | 1691 | static void ProcessControlButton1Motion() |
1692 | { | |
1693 | ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion); | |
1694 | ||
1695 | X_ButtonPress = X_Motion; | |
1696 | Y_ButtonPress = Y_Motion; | |
1697 | } | |
900f7229 | 1698 | #endif |
7fd59977 | 1699 | |
1700 | //============================================================================== | |
4fe56619 | 1701 | //function : VT_ProcessControlButton2Motion |
1702 | //purpose : Panning | |
7fd59977 | 1703 | //============================================================================== |
4fe56619 | 1704 | void VT_ProcessControlButton2Motion() |
7fd59977 | 1705 | { |
197ac94e | 1706 | Standard_Integer aDx = X_Motion - X_ButtonPress; |
1707 | Standard_Integer aDy = Y_Motion - Y_ButtonPress; | |
7fd59977 | 1708 | |
197ac94e | 1709 | aDy = -aDy; // Xwindow Y axis is from top to Bottom |
7fd59977 | 1710 | |
197ac94e | 1711 | ViewerTest::CurrentView()->Pan (aDx, aDy); |
7fd59977 | 1712 | |
1713 | X_ButtonPress = X_Motion; | |
1714 | Y_ButtonPress = Y_Motion; | |
1715 | } | |
1716 | ||
1717 | //============================================================================== | |
4fe56619 | 1718 | //function : VT_ProcessControlButton3Motion |
7fd59977 | 1719 | //purpose : Rotation |
1720 | //============================================================================== | |
4fe56619 | 1721 | void VT_ProcessControlButton3Motion() |
7fd59977 | 1722 | { |
4fe56619 | 1723 | if (Start_Rot) |
1724 | { | |
1725 | ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion); | |
1726 | } | |
7fd59977 | 1727 | } |
1728 | ||
1729 | //============================================================================== | |
4fe56619 | 1730 | //function : VT_ProcessMotion |
1731 | //purpose : | |
7fd59977 | 1732 | //============================================================================== |
4fe56619 | 1733 | void VT_ProcessMotion() |
7fd59977 | 1734 | { |
1735 | //pre-hilights detected objects at mouse position | |
1736 | ||
1737 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
1738 | EM->MoveTo(X_Motion, Y_Motion); | |
1739 | } | |
1740 | ||
1741 | ||
1742 | void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix) | |
1743 | { | |
1744 | Xpix = X_Motion;Ypix=Y_Motion; | |
1745 | } | |
1746 | ||
44b8f2d6 | 1747 | //============================================================================== |
1748 | //function : ViewProject: implements VAxo, VTop, VLeft, ... | |
1749 | //purpose : Switches to an axonometric, top, left and other views | |
1750 | //============================================================================== | |
1751 | ||
1752 | static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori) | |
1753 | { | |
4fe56619 | 1754 | if ( ViewerTest::CurrentView().IsNull() ) |
44b8f2d6 | 1755 | { |
1756 | di<<"Call vinit before this command, please"<<"\n"; | |
1757 | return 1; | |
1758 | } | |
1759 | ||
1760 | ViewerTest::CurrentView()->SetProj(ori); | |
1761 | return 0; | |
1762 | } | |
1763 | ||
7fd59977 | 1764 | //============================================================================== |
1765 | //function : VAxo | |
1766 | //purpose : Switch to an Axonometric view | |
1767 | //Draw arg : No args | |
1768 | //============================================================================== | |
1769 | ||
1770 | static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** ) | |
44b8f2d6 | 1771 | { |
1772 | return ViewProject(di, V3d_XposYnegZpos); | |
7fd59977 | 1773 | } |
1774 | ||
1775 | //============================================================================== | |
1776 | //function : VTop | |
1777 | //purpose : Switch to a Top View | |
1778 | //Draw arg : No args | |
1779 | //============================================================================== | |
1780 | ||
1781 | static int VTop(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1782 | { | |
44b8f2d6 | 1783 | return ViewProject(di, V3d_Zpos); |
1784 | } | |
7fd59977 | 1785 | |
44b8f2d6 | 1786 | //============================================================================== |
1787 | //function : VBottom | |
1788 | //purpose : Switch to a Bottom View | |
1789 | //Draw arg : No args | |
1790 | //============================================================================== | |
7fd59977 | 1791 | |
44b8f2d6 | 1792 | static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** ) |
1793 | { | |
1794 | return ViewProject(di, V3d_Zneg); | |
1795 | } | |
7fd59977 | 1796 | |
44b8f2d6 | 1797 | //============================================================================== |
1798 | //function : VLeft | |
1799 | //purpose : Switch to a Left View | |
1800 | //Draw arg : No args | |
1801 | //============================================================================== | |
1802 | ||
1803 | static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1804 | { | |
1805 | return ViewProject(di, V3d_Ypos); | |
1806 | } | |
1807 | ||
1808 | //============================================================================== | |
1809 | //function : VRight | |
1810 | //purpose : Switch to a Right View | |
1811 | //Draw arg : No args | |
1812 | //============================================================================== | |
1813 | ||
1814 | static int VRight(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1815 | { | |
1816 | return ViewProject(di, V3d_Yneg); | |
1817 | } | |
7fd59977 | 1818 | |
44b8f2d6 | 1819 | //============================================================================== |
1820 | //function : VFront | |
1821 | //purpose : Switch to a Front View | |
1822 | //Draw arg : No args | |
1823 | //============================================================================== | |
1824 | ||
1825 | static int VFront(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1826 | { | |
1827 | return ViewProject(di, V3d_Xpos); | |
1828 | } | |
1829 | ||
1830 | //============================================================================== | |
1831 | //function : VBack | |
1832 | //purpose : Switch to a Back View | |
1833 | //Draw arg : No args | |
1834 | //============================================================================== | |
1835 | ||
1836 | static int VBack(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1837 | { | |
1838 | return ViewProject(di, V3d_Xneg); | |
7fd59977 | 1839 | } |
1840 | ||
1841 | //============================================================================== | |
1842 | //function : VHelp | |
1843 | //purpose : Dsiplay help on viewer Keyboead and mouse commands | |
1844 | //Draw arg : No args | |
1845 | //============================================================================== | |
1846 | ||
1847 | static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1848 | { | |
1849 | ||
1850 | di << "Q : Quit the application" << "\n"; | |
1851 | ||
1852 | di << "========================="<<"\n"; | |
1853 | di << "F : FitAll" << "\n"; | |
1854 | di << "T : TopView" << "\n"; | |
41811896 | 1855 | di << "B : BottomView" << "\n"; |
1856 | di << "R : RightView" << "\n"; | |
1857 | di << "L : LeftView" << "\n"; | |
7fd59977 | 1858 | di << "A : AxonometricView" << "\n"; |
41811896 | 1859 | di << "D : ResetView" << "\n"; |
7fd59977 | 1860 | |
1861 | di << "========================="<<"\n"; | |
1862 | di << "S : Shading" << "\n"; | |
1863 | di << "W : Wireframe" << "\n"; | |
1864 | di << "H : HidelLineRemoval" << "\n"; | |
41811896 | 1865 | di << "U : Unset display mode" << "\n"; |
b514beda | 1866 | di << "Delete : Remove selection from viewer" << "\n"; |
7fd59977 | 1867 | |
1868 | di << "========================="<<"\n"; | |
1869 | di << "Selection mode "<<"\n"; | |
1870 | di << "0 : Shape" <<"\n"; | |
1871 | di << "1 : Vertex" <<"\n"; | |
1872 | di << "2 : Edge" <<"\n"; | |
1873 | di << "3 : Wire" <<"\n"; | |
1874 | di << "4 : Face" <<"\n"; | |
1875 | di << "5 : Shell" <<"\n"; | |
1876 | di << "6 : Solid" <<"\n"; | |
1877 | di << "7 : Compound" <<"\n"; | |
1878 | ||
41811896 | 1879 | di << "========================="<<"\n"; |
1880 | di << "Z : Switch Z clipping On/Off" << "\n"; | |
1881 | di << ", : Hilight next detected" << "\n"; | |
1882 | di << ". : Hilight previous detected" << "\n"; | |
7fd59977 | 1883 | |
1884 | return 0; | |
1885 | } | |
1886 | ||
7fd59977 | 1887 | #ifdef WNT |
1888 | ||
1889 | static Standard_Boolean Ppick = 0; | |
1890 | static Standard_Integer Pargc = 0; | |
1891 | static const char** Pargv = NULL; | |
1892 | ||
1893 | ||
1894 | static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd, | |
1895 | UINT Msg, | |
1896 | WPARAM wParam, | |
1897 | LPARAM lParam ) | |
1898 | { | |
18d715bd | 1899 | if (!ViewerTest_myViews.IsEmpty()) { |
7fd59977 | 1900 | |
1901 | WPARAM fwKeys = wParam; | |
1902 | ||
1903 | switch( Msg ) { | |
18d715bd | 1904 | case WM_CLOSE: |
1905 | { | |
1906 | // Delete view from map of views | |
1907 | ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd)); | |
1908 | return 0; | |
1909 | } | |
1910 | break; | |
1911 | case WM_ACTIVATE: | |
1912 | if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE | |
1913 | || ViewerTest::CurrentView().IsNull()) | |
1914 | { | |
1915 | // Activate inactive window | |
1916 | if(GetWindowHandle(VT_GetWindow()) != hwnd) | |
1917 | { | |
1918 | ActivateView (FindViewIdByWindowHandle(hwnd)); | |
1919 | } | |
1920 | } | |
1921 | break; | |
7fd59977 | 1922 | case WM_LBUTTONUP: |
8abada55 | 1923 | if (!DragFirst) |
7fd59977 | 1924 | { |
1925 | HDC hdc = GetDC( hwnd ); | |
7fd59977 | 1926 | SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) ); |
1927 | SetROP2( hdc, R2_NOT ); | |
4fe56619 | 1928 | Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion ); |
7fd59977 | 1929 | ReleaseDC( hwnd, hdc ); |
8abada55 | 1930 | VT_ProcessButton1Release (fwKeys & MK_SHIFT); |
7fd59977 | 1931 | } |
8abada55 | 1932 | IsDragged = Standard_False; |
7fd59977 | 1933 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); |
1934 | ||
1935 | case WM_LBUTTONDOWN: | |
1936 | if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) ) | |
1937 | { | |
1938 | IsDragged = Standard_True; | |
1939 | DragFirst = Standard_True; | |
4fe56619 | 1940 | X_ButtonPress = LOWORD(lParam); |
1941 | Y_ButtonPress = HIWORD(lParam); | |
7fd59977 | 1942 | } |
1943 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1944 | ||
1945 | break; | |
1946 | ||
1947 | case WM_MOUSEMOVE: | |
1948 | if( IsDragged ) | |
1949 | { | |
1950 | HDC hdc = GetDC( hwnd ); | |
1951 | ||
1952 | HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) ); | |
1953 | SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) ); | |
1954 | SetROP2( hdc, R2_NOT ); | |
1955 | ||
1956 | if( !DragFirst ) | |
4fe56619 | 1957 | Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion ); |
7fd59977 | 1958 | |
1959 | DragFirst = Standard_False; | |
4fe56619 | 1960 | X_Motion = LOWORD(lParam); |
1961 | Y_Motion = HIWORD(lParam); | |
7fd59977 | 1962 | |
4fe56619 | 1963 | Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion ); |
7fd59977 | 1964 | |
1965 | SelectObject( hdc, anObj ); | |
1966 | ||
1967 | ReleaseDC( hwnd, hdc ); | |
1968 | } | |
1969 | else | |
1970 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1971 | break; | |
1972 | ||
1973 | default: | |
1974 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1975 | } | |
1976 | return 0; | |
1977 | } | |
1978 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1979 | } | |
1980 | ||
1981 | ||
1982 | static LRESULT WINAPI ViewerWindowProc( HWND hwnd, | |
1983 | UINT Msg, | |
1984 | WPARAM wParam, | |
1985 | LPARAM lParam ) | |
1986 | { | |
7fd59977 | 1987 | static int Up = 1; |
1988 | ||
1989 | if ( !ViewerTest::CurrentView().IsNull() ) { | |
1990 | PAINTSTRUCT ps; | |
1991 | ||
1992 | switch( Msg ) { | |
7fd59977 | 1993 | case WM_PAINT: |
7fd59977 | 1994 | BeginPaint(hwnd, &ps); |
1995 | EndPaint(hwnd, &ps); | |
4fe56619 | 1996 | VT_ProcessExpose(); |
7fd59977 | 1997 | break; |
1998 | ||
1999 | case WM_SIZE: | |
4fe56619 | 2000 | VT_ProcessConfigure(); |
7fd59977 | 2001 | break; |
2002 | ||
2003 | case WM_KEYDOWN: | |
4fe56619 | 2004 | if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL)) |
2005 | { | |
7fd59977 | 2006 | char c[2]; |
2007 | c[0] = (char) wParam; | |
2008 | c[1] = '\0'; | |
b514beda | 2009 | if (wParam == VK_DELETE) |
2010 | { | |
2011 | c[0] = THE_KEY_DELETE; | |
2012 | } | |
4ca4bbe8 | 2013 | // comma |
2014 | else if (wParam == VK_OEM_COMMA) | |
2015 | { | |
2016 | c[0] = ','; | |
2017 | } | |
2018 | // dot | |
2019 | else if (wParam == VK_OEM_PERIOD) | |
2020 | { | |
2021 | c[0] = '.'; | |
2022 | } | |
4fe56619 | 2023 | VT_ProcessKeyPress (c); |
7fd59977 | 2024 | } |
2025 | break; | |
2026 | ||
2027 | case WM_LBUTTONUP: | |
2028 | case WM_MBUTTONUP: | |
2029 | case WM_RBUTTONUP: | |
7fd59977 | 2030 | Up = 1; |
4fe56619 | 2031 | VT_ProcessButton3Release(); |
7fd59977 | 2032 | break; |
2033 | ||
2034 | case WM_LBUTTONDOWN: | |
2035 | case WM_MBUTTONDOWN: | |
2036 | case WM_RBUTTONDOWN: | |
2037 | { | |
7fd59977 | 2038 | WPARAM fwKeys = wParam; |
2039 | ||
2040 | Up = 0; | |
2041 | ||
2042 | X_ButtonPress = LOWORD(lParam); | |
2043 | Y_ButtonPress = HIWORD(lParam); | |
2044 | ||
4fe56619 | 2045 | if (Msg == WM_LBUTTONDOWN) |
2046 | { | |
2047 | if (fwKeys & MK_CONTROL) | |
2048 | { | |
2049 | Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT)); | |
2050 | } | |
2051 | else | |
2052 | { | |
2053 | VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT)); | |
2054 | } | |
7fd59977 | 2055 | } |
4fe56619 | 2056 | else if (Msg == WM_RBUTTONDOWN) |
2057 | { | |
7fd59977 | 2058 | // Start rotation |
4fe56619 | 2059 | VT_ProcessButton3Press(); |
7fd59977 | 2060 | } |
2061 | } | |
2062 | break; | |
2063 | ||
2064 | case WM_MOUSEMOVE: | |
2065 | { | |
2066 | //cout << "\t WM_MOUSEMOVE" << endl; | |
2067 | WPARAM fwKeys = wParam; | |
2068 | X_Motion = LOWORD(lParam); | |
2069 | Y_Motion = HIWORD(lParam); | |
2070 | ||
2071 | if ( Up && | |
2072 | fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) { | |
2073 | Up = 0; | |
2074 | X_ButtonPress = LOWORD(lParam); | |
2075 | Y_ButtonPress = HIWORD(lParam); | |
2076 | ||
2077 | if ( fwKeys & MK_RBUTTON ) { | |
2078 | // Start rotation | |
4fe56619 | 2079 | VT_ProcessButton3Press(); |
7fd59977 | 2080 | } |
2081 | } | |
2082 | ||
2083 | if ( fwKeys & MK_CONTROL ) { | |
2084 | if ( fwKeys & MK_LBUTTON ) { | |
2085 | ProcessControlButton1Motion(); | |
2086 | } | |
2087 | else if ( fwKeys & MK_MBUTTON || | |
2088 | ((fwKeys&MK_LBUTTON) && | |
2089 | (fwKeys&MK_RBUTTON) ) ){ | |
4fe56619 | 2090 | VT_ProcessControlButton2Motion(); |
7fd59977 | 2091 | } |
2092 | else if ( fwKeys & MK_RBUTTON ) { | |
4fe56619 | 2093 | VT_ProcessControlButton3Motion(); |
7fd59977 | 2094 | } |
2095 | } | |
2096 | #ifdef BUG | |
2097 | else if ( fwKeys & MK_SHIFT ) { | |
2098 | if ( fwKeys & MK_MBUTTON || | |
2099 | ((fwKeys&MK_LBUTTON) && | |
2100 | (fwKeys&MK_RBUTTON) ) ) { | |
2101 | cout << "ProcessZClipMotion()" << endl; | |
2102 | ProcessZClipMotion(); | |
2103 | } | |
2104 | } | |
2105 | #endif | |
08398024 | 2106 | else if (GetWindowHandle (VT_GetWindow()) == hwnd) |
2107 | { | |
4fe56619 | 2108 | if ((fwKeys & MK_MBUTTON |
2109 | || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON)))) | |
2110 | { | |
7fd59977 | 2111 | ProcessZClipMotion(); |
2112 | } | |
4fe56619 | 2113 | else |
2114 | { | |
2115 | VT_ProcessMotion(); | |
7fd59977 | 2116 | } |
08398024 | 2117 | } |
7fd59977 | 2118 | } |
2119 | break; | |
2120 | ||
2121 | default: | |
2122 | return( DefWindowProc( hwnd, Msg, wParam, lParam )); | |
2123 | } | |
2124 | return 0L; | |
2125 | } | |
2126 | ||
2127 | return DefWindowProc( hwnd, Msg, wParam, lParam ); | |
2128 | } | |
2129 | ||
2130 | ||
2131 | ||
2132 | ||
2133 | //============================================================================== | |
2134 | //function : ViewerMainLoop | |
2135 | //purpose : Get a Event on the view and dispatch it | |
2136 | //============================================================================== | |
2137 | ||
2138 | ||
8263fcd3 | 2139 | int ViewerMainLoop(Standard_Integer argc, const char** argv) |
7fd59977 | 2140 | { |
7fd59977 | 2141 | Ppick = (argc > 0)? 1 : 0; |
2142 | Pargc = argc; | |
2143 | Pargv = argv; | |
2144 | ||
2145 | if ( Ppick ) { | |
2146 | MSG msg; | |
2147 | msg.wParam = 1; | |
2148 | ||
2149 | cout << "Start picking" << endl; | |
2150 | ||
7fd59977 | 2151 | while ( Ppick == 1 ) { |
4fe56619 | 2152 | // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0 |
7fd59977 | 2153 | if (GetMessage(&msg, NULL, 0, 0) ) { |
2154 | TranslateMessage(&msg); | |
2155 | DispatchMessage(&msg); | |
2156 | } | |
2157 | } | |
2158 | ||
2159 | cout << "Picking done" << endl; | |
2160 | } | |
2161 | ||
2162 | return Ppick; | |
2163 | } | |
2164 | ||
4fe56619 | 2165 | #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX) |
7fd59977 | 2166 | |
2167 | int min( int a, int b ) | |
2168 | { | |
2169 | if( a<b ) | |
2170 | return a; | |
2171 | else | |
2172 | return b; | |
2173 | } | |
2174 | ||
2175 | int max( int a, int b ) | |
2176 | { | |
2177 | if( a>b ) | |
2178 | return a; | |
2179 | else | |
2180 | return b; | |
2181 | } | |
2182 | ||
2183 | int ViewerMainLoop(Standard_Integer argc, const char** argv) | |
2184 | ||
4269bd1b | 2185 | { |
18d715bd | 2186 | static XEvent aReport; |
2187 | Standard_Boolean pick = argc > 0; | |
2188 | Display *aDisplay = GetDisplayConnection()->GetDisplay(); | |
2189 | XNextEvent (aDisplay, &aReport); | |
7fd59977 | 2190 | |
18d715bd | 2191 | // Handle event for the chosen display connection |
2192 | switch (aReport.type) { | |
2193 | case ClientMessage: | |
2194 | { | |
eb1ebea4 | 2195 | if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW)) |
18d715bd | 2196 | { |
2197 | // Close the window | |
2198 | ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window)); | |
2199 | } | |
2200 | } | |
2201 | return 0; | |
2202 | case FocusIn: | |
2203 | { | |
2204 | // Activate inactive view | |
2205 | Window aWindow = GetWindowHandle(VT_GetWindow()); | |
2206 | if(aWindow != aReport.xfocus.window) | |
2207 | { | |
2208 | ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window)); | |
2209 | } | |
2210 | } | |
2211 | break; | |
7fd59977 | 2212 | case Expose: |
2213 | { | |
4fe56619 | 2214 | VT_ProcessExpose(); |
7fd59977 | 2215 | } |
2216 | break; | |
2217 | case ConfigureNotify: | |
2218 | { | |
4fe56619 | 2219 | VT_ProcessConfigure(); |
7fd59977 | 2220 | } |
2221 | break; | |
2222 | case KeyPress: | |
2223 | { | |
2224 | ||
2225 | KeySym ks_ret ; | |
2226 | char buf_ret[11] ; | |
2227 | int ret_len ; | |
2228 | XComposeStatus status_in_out; | |
2229 | ||
18d715bd | 2230 | ret_len = XLookupString( ( XKeyEvent *)&aReport , |
7fd59977 | 2231 | (char *) buf_ret , 10 , |
2232 | &ks_ret , &status_in_out ) ; | |
2233 | ||
2234 | ||
2235 | buf_ret[ret_len] = '\0' ; | |
2236 | ||
4fe56619 | 2237 | if (ret_len) |
2238 | { | |
2239 | VT_ProcessKeyPress (buf_ret); | |
7fd59977 | 2240 | } |
2241 | } | |
2242 | break; | |
2243 | case ButtonPress: | |
7fd59977 | 2244 | { |
18d715bd | 2245 | X_ButtonPress = aReport.xbutton.x; |
2246 | Y_ButtonPress = aReport.xbutton.y; | |
7fd59977 | 2247 | |
18d715bd | 2248 | if (aReport.xbutton.button == Button1) |
4fe56619 | 2249 | { |
18d715bd | 2250 | if (aReport.xbutton.state & ControlMask) |
4fe56619 | 2251 | { |
18d715bd | 2252 | pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask)); |
4fe56619 | 2253 | } |
7fd59977 | 2254 | else |
2255 | { | |
2256 | IsDragged = Standard_True; | |
7fd59977 | 2257 | DragFirst = Standard_True; |
2258 | } | |
4fe56619 | 2259 | } |
18d715bd | 2260 | else if (aReport.xbutton.button == Button3) |
4fe56619 | 2261 | { |
7fd59977 | 2262 | // Start rotation |
4fe56619 | 2263 | VT_ProcessButton3Press(); |
2264 | } | |
7fd59977 | 2265 | } |
2266 | break; | |
2267 | case ButtonRelease: | |
2268 | { | |
7fd59977 | 2269 | if( IsDragged ) |
2270 | { | |
2271 | if( !DragFirst ) | |
2272 | { | |
2273 | Aspect_Handle aWindow = VT_GetWindow()->XWindow(); | |
18d715bd | 2274 | GC gc = XCreateGC( aDisplay, aWindow, 0, 0 ); |
2275 | XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) ); | |
7fd59977 | 2276 | } |
2277 | ||
2278 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
2279 | if( aContext.IsNull() ) | |
2280 | { | |
2281 | cout << "The context is null. Please use vinit before createmesh" << endl; | |
2282 | return 0; | |
2283 | } | |
2284 | ||
18d715bd | 2285 | Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask ); |
2286 | if( aReport.xbutton.button==1 ) | |
7fd59977 | 2287 | if( DragFirst ) |
2288 | if( ShiftPressed ) | |
2289 | { | |
2290 | aContext->ShiftSelect(); | |
7fd59977 | 2291 | } |
2292 | else | |
2293 | { | |
2294 | aContext->Select(); | |
7fd59977 | 2295 | } |
2296 | else | |
2297 | if( ShiftPressed ) | |
2298 | { | |
4fe56619 | 2299 | aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), |
2300 | max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ), | |
7fd59977 | 2301 | ViewerTest::CurrentView()); |
7fd59977 | 2302 | } |
2303 | else | |
2304 | { | |
4fe56619 | 2305 | aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), |
2306 | max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ), | |
7fd59977 | 2307 | ViewerTest::CurrentView() ); |
7fd59977 | 2308 | } |
2309 | else | |
4fe56619 | 2310 | VT_ProcessButton3Release(); |
7fd59977 | 2311 | |
2312 | IsDragged = Standard_False; | |
2313 | } | |
2314 | else | |
4fe56619 | 2315 | VT_ProcessButton3Release(); |
7fd59977 | 2316 | } |
2317 | break; | |
2318 | case MotionNotify: | |
2319 | { | |
08398024 | 2320 | if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window) |
2321 | { | |
2322 | break; | |
2323 | } | |
7fd59977 | 2324 | if( IsDragged ) |
2325 | { | |
2326 | Aspect_Handle aWindow = VT_GetWindow()->XWindow(); | |
18d715bd | 2327 | GC gc = XCreateGC( aDisplay, aWindow, 0, 0 ); |
2328 | XSetFunction( aDisplay, gc, GXinvert ); | |
7fd59977 | 2329 | |
2330 | if( !DragFirst ) | |
18d715bd | 2331 | XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) ); |
7fd59977 | 2332 | |
18d715bd | 2333 | X_Motion = aReport.xmotion.x; |
2334 | Y_Motion = aReport.xmotion.y; | |
7fd59977 | 2335 | DragFirst = Standard_False; |
2336 | ||
18d715bd | 2337 | XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) ); |
7fd59977 | 2338 | } |
2339 | else | |
2340 | { | |
18d715bd | 2341 | X_Motion = aReport.xmotion.x; |
2342 | Y_Motion = aReport.xmotion.y; | |
7fd59977 | 2343 | |
18d715bd | 2344 | // remove all the ButtonMotionMaskr |
2345 | while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ; | |
7fd59977 | 2346 | |
18d715bd | 2347 | if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) { |
7fd59977 | 2348 | if ( Abs(X_Motion - X_ButtonPress) > 2 ) { |
2349 | ||
2350 | Quantity_Length VDX, VDY; | |
2351 | ||
2352 | ViewerTest::CurrentView()->Size(VDX,VDY); | |
2353 | Standard_Real VDZ =0 ; | |
2354 | VDZ = ViewerTest::CurrentView()->ZSize(); | |
2355 | ||
7fd59977 | 2356 | printf("%f,%f,%f\n", VDX, VDY, VDZ); |
2357 | ||
2358 | Quantity_Length dx = 0 ; | |
2359 | dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress); | |
2360 | ||
2361 | cout << dx << endl; | |
2362 | ||
2363 | dx = dx / VDX * VDZ; | |
2364 | ||
2365 | cout << dx << endl; | |
2366 | ||
7fd59977 | 2367 | ViewerTest::CurrentView()->Redraw(); |
2368 | } | |
2369 | } | |
2370 | ||
18d715bd | 2371 | if ( aReport.xmotion.state & ControlMask ) { |
2372 | if ( aReport.xmotion.state & Button1Mask ) { | |
7fd59977 | 2373 | ProcessControlButton1Motion(); |
2374 | } | |
18d715bd | 2375 | else if ( aReport.xmotion.state & Button2Mask ) { |
4fe56619 | 2376 | VT_ProcessControlButton2Motion(); |
7fd59977 | 2377 | } |
18d715bd | 2378 | else if ( aReport.xmotion.state & Button3Mask ) { |
4fe56619 | 2379 | VT_ProcessControlButton3Motion(); |
7fd59977 | 2380 | } |
2381 | } | |
4fe56619 | 2382 | else |
2383 | { | |
2384 | VT_ProcessMotion(); | |
7fd59977 | 2385 | } |
2386 | } | |
2387 | } | |
2388 | break; | |
2389 | } | |
7fd59977 | 2390 | return pick; |
2391 | } | |
2392 | ||
2393 | //============================================================================== | |
2394 | //function : VProcessEvents | |
2395 | //purpose : call by Tk_CreateFileHandler() to be able to manage the | |
2396 | // event in the Viewer window | |
2397 | //============================================================================== | |
2398 | ||
2399 | static void VProcessEvents(ClientData,int) | |
2400 | { | |
18d715bd | 2401 | NCollection_Vector<int> anEventNumbers; |
2402 | // Get number of messages from every display | |
2403 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
2404 | anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next()) | |
2405 | { | |
2406 | anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay())); | |
4269bd1b | 2407 | } |
18d715bd | 2408 | // Handle events for every display |
2409 | int anEventIter = 0; | |
2410 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
2411 | anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++) | |
2412 | { | |
4269bd1b | 2413 | for (int i = 0; i < anEventNumbers.Value(anEventIter) && |
18d715bd | 2414 | XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i) |
2415 | { | |
2416 | SetDisplayConnection (anIter.Key2()->GetDisplayConnection()); | |
2417 | int anEventResult = ViewerMainLoop( 0, NULL); | |
2418 | // If window is closed or context was not found finish current event processing loop | |
2419 | if (!anEventResult) | |
2420 | return; | |
2421 | } | |
7fd59977 | 2422 | } |
4269bd1b | 2423 | |
18d715bd | 2424 | SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection()); |
4269bd1b | 2425 | |
7fd59977 | 2426 | } |
2427 | #endif | |
2428 | ||
2429 | //============================================================================== | |
2430 | //function : OSWindowSetup | |
2431 | //purpose : Setup for the X11 window to be able to cath the event | |
2432 | //============================================================================== | |
2433 | ||
2434 | ||
2435 | static void OSWindowSetup() | |
2436 | { | |
4fe56619 | 2437 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
7fd59977 | 2438 | // X11 |
2439 | ||
2440 | Window window = VT_GetWindow()->XWindow(); | |
18d715bd | 2441 | SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); |
2442 | Display *aDisplay = GetDisplayConnection()->GetDisplay(); | |
2443 | XSynchronize(aDisplay, 1); | |
7fd59977 | 2444 | |
2445 | // X11 : For keyboard on SUN | |
2446 | XWMHints wmhints; | |
2447 | wmhints.flags = InputHint; | |
2448 | wmhints.input = 1; | |
2449 | ||
18d715bd | 2450 | XSetWMHints( aDisplay, window, &wmhints); |
7fd59977 | 2451 | |
18d715bd | 2452 | XSelectInput( aDisplay, window, ExposureMask | KeyPressMask | |
7fd59977 | 2453 | ButtonPressMask | ButtonReleaseMask | |
2454 | StructureNotifyMask | | |
2455 | PointerMotionMask | | |
2456 | Button1MotionMask | Button2MotionMask | | |
18d715bd | 2457 | Button3MotionMask | FocusChangeMask |
7fd59977 | 2458 | ); |
18d715bd | 2459 | Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW); |
2460 | XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1); | |
7fd59977 | 2461 | |
18d715bd | 2462 | XSynchronize(aDisplay, 0); |
7fd59977 | 2463 | |
2464 | #else | |
2465 | // WNT | |
2466 | #endif | |
2467 | ||
2468 | } | |
2469 | ||
2470 | ||
2471 | //============================================================================== | |
2472 | //function : VFit | |
2473 | ||
2474 | //purpose : Fitall, no DRAW arguments | |
2475 | //Draw arg : No args | |
2476 | //============================================================================== | |
2477 | ||
2478 | static int VFit(Draw_Interpretor& , Standard_Integer , const char** ) | |
2479 | { | |
2480 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
2481 | Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView); | |
2482 | if (V.IsNull() == Standard_False) { | |
2483 | V->FitAll3d(); | |
2484 | } else if (aView.IsNull() == Standard_False) { | |
2485 | aView->FitAll(); | |
2486 | } | |
2487 | return 0; | |
2488 | } | |
2489 | ||
6262a303 | 2490 | //======================================================================= |
2491 | //function : VFitArea | |
2492 | //purpose : Fit view to show area located between two points | |
2493 | // : given in world 2D or 3D coordinates. | |
2494 | //======================================================================= | |
2495 | static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
2496 | { | |
2497 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
2498 | if (aView.IsNull()) | |
2499 | { | |
2500 | std::cerr << theArgVec[0] << "Error: No active view.\n"; | |
2501 | return 1; | |
2502 | } | |
2503 | ||
2504 | // Parse arguments. | |
2505 | gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0); | |
2506 | gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0); | |
2507 | ||
2508 | if (theArgNb == 5) | |
2509 | { | |
2510 | aWorldPnt1.SetX (Draw::Atof (theArgVec[1])); | |
2511 | aWorldPnt1.SetY (Draw::Atof (theArgVec[2])); | |
2512 | aWorldPnt2.SetX (Draw::Atof (theArgVec[3])); | |
2513 | aWorldPnt2.SetY (Draw::Atof (theArgVec[4])); | |
2514 | } | |
2515 | else if (theArgNb == 7) | |
2516 | { | |
2517 | aWorldPnt1.SetX (Draw::Atof (theArgVec[1])); | |
2518 | aWorldPnt1.SetY (Draw::Atof (theArgVec[2])); | |
2519 | aWorldPnt1.SetZ (Draw::Atof (theArgVec[3])); | |
2520 | aWorldPnt2.SetX (Draw::Atof (theArgVec[4])); | |
2521 | aWorldPnt2.SetY (Draw::Atof (theArgVec[5])); | |
2522 | aWorldPnt2.SetZ (Draw::Atof (theArgVec[6])); | |
2523 | } | |
2524 | else | |
2525 | { | |
2526 | std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n"; | |
2527 | theDI.PrintHelp(theArgVec[0]); | |
2528 | return 1; | |
2529 | } | |
2530 | ||
2531 | // Convert model coordinates to view space | |
2532 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); | |
2533 | gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1); | |
2534 | gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2); | |
2535 | ||
2536 | // Determine fit area | |
2537 | gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y())); | |
2538 | gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y())); | |
2539 | ||
2540 | Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner); | |
2541 | ||
2542 | if (aDiagonal < Precision::Confusion()) | |
2543 | { | |
2544 | std::cerr << theArgVec[0] << "Error: view area is too small.\n"; | |
2545 | return 1; | |
2546 | } | |
2547 | ||
2548 | aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y()); | |
2549 | return 0; | |
2550 | } | |
2551 | ||
7fd59977 | 2552 | //============================================================================== |
2553 | //function : VZFit | |
2554 | //purpose : ZFitall, no DRAW arguments | |
2555 | //Draw arg : No args | |
2556 | //============================================================================== | |
197ac94e | 2557 | static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec) |
7fd59977 | 2558 | { |
197ac94e | 2559 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
2560 | ||
2561 | if (aCurrentView.IsNull()) | |
2562 | { | |
2563 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; | |
2564 | return 1; | |
2565 | } | |
2566 | ||
2567 | if (theArgsNb == 1) | |
2568 | { | |
6bc6a6fc | 2569 | aCurrentView->View()->ZFitAll(); |
197ac94e | 2570 | aCurrentView->Redraw(); |
2571 | return 0; | |
2572 | } | |
2573 | ||
2574 | Standard_Real aScale = 1.0; | |
2575 | ||
2576 | if (theArgsNb >= 2) | |
2577 | { | |
2578 | aScale = Draw::Atoi (theArgVec[1]); | |
2579 | } | |
2580 | ||
6bc6a6fc | 2581 | aCurrentView->View()->ZFitAll (aScale); |
197ac94e | 2582 | aCurrentView->Redraw(); |
7fd59977 | 2583 | |
197ac94e | 2584 | return 0; |
2585 | } | |
7fd59977 | 2586 | |
197ac94e | 2587 | //============================================================================== |
2588 | //function : VRepaint | |
2589 | //purpose : | |
2590 | //============================================================================== | |
2591 | static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** ) | |
7fd59977 | 2592 | { |
2593 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
2594 | if ( !V.IsNull() ) V->Redraw(); return 0; | |
2595 | } | |
2596 | ||
7fd59977 | 2597 | //============================================================================== |
2598 | //function : VClear | |
2599 | //purpose : Remove all the object from the viewer | |
2600 | //Draw arg : No args | |
2601 | //============================================================================== | |
2602 | ||
2603 | static int VClear(Draw_Interpretor& , Standard_Integer , const char** ) | |
2604 | { | |
2605 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
2606 | if(!V.IsNull()) | |
2607 | ViewerTest::Clear(); | |
2608 | return 0; | |
2609 | } | |
2610 | ||
2611 | //============================================================================== | |
2612 | //function : VPick | |
2613 | //purpose : | |
2614 | //============================================================================== | |
2615 | ||
2616 | static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2617 | { if (ViewerTest::CurrentView().IsNull() ) return 1; | |
2618 | ||
2619 | if ( argc < 4 ) { | |
2620 | di << argv[0] << "Invalid number of arguments" << "\n"; | |
2621 | return 1; | |
2622 | } | |
2623 | ||
2624 | while (ViewerMainLoop( argc, argv)) { | |
2625 | } | |
2626 | ||
2627 | return 0; | |
2628 | } | |
2629 | ||
7fd59977 | 2630 | //============================================================================== |
2631 | //function : VSetBg | |
2632 | //purpose : Load image as background | |
2633 | //============================================================================== | |
2634 | ||
2635 | static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2636 | { | |
2637 | if (argc < 2 || argc > 3) | |
2638 | { | |
2639 | di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n"; | |
f8b2ed36 | 2640 | di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n"; |
7fd59977 | 2641 | return 1; |
2642 | } | |
2643 | ||
2644 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2645 | if(AISContext.IsNull()) | |
2646 | { | |
2647 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2648 | return 1; | |
2649 | } | |
2650 | ||
2651 | Aspect_FillMethod aFillType = Aspect_FM_CENTERED; | |
2652 | if (argc == 3) | |
2653 | { | |
2654 | const char* szType = argv[2]; | |
2655 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; | |
2656 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; | |
2657 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; | |
2658 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; | |
2659 | else | |
2660 | { | |
2661 | di << "Wrong fill type : " << szType << "\n"; | |
2662 | di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n"; | |
2663 | return 1; | |
2664 | } | |
2665 | } | |
2666 | ||
2667 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2668 | V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True); | |
2669 | ||
2670 | return 0; | |
2671 | } | |
2672 | ||
f8b2ed36 | 2673 | //============================================================================== |
2674 | //function : VSetBgMode | |
2675 | //purpose : Change background image fill type | |
2676 | //============================================================================== | |
2677 | ||
2678 | static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2679 | { | |
2680 | if (argc != 2) | |
2681 | { | |
2682 | di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n"; | |
2683 | di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n"; | |
2684 | return 1; | |
2685 | } | |
2686 | ||
2687 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2688 | if(AISContext.IsNull()) | |
2689 | { | |
2690 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2691 | return 1; | |
2692 | } | |
1d47d8d0 | 2693 | Aspect_FillMethod aFillType = Aspect_FM_NONE; |
2694 | const char* szType = argv[1]; | |
2695 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; | |
2696 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; | |
2697 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; | |
2698 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; | |
2699 | else | |
f8b2ed36 | 2700 | { |
1d47d8d0 | 2701 | di << "Wrong fill type : " << szType << "\n"; |
2702 | di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n"; | |
2703 | return 1; | |
f8b2ed36 | 2704 | } |
f8b2ed36 | 2705 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); |
2706 | V3dView->SetBgImageStyle(aFillType, Standard_True); | |
f8b2ed36 | 2707 | return 0; |
2708 | } | |
2709 | ||
7fd59977 | 2710 | //============================================================================== |
2711 | //function : VSetGradientBg | |
2712 | //purpose : Mount gradient background | |
2713 | //============================================================================== | |
2714 | static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2715 | { | |
2716 | if (argc != 8 ) | |
2717 | { | |
2718 | di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n"; | |
2719 | di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n"; | |
2720 | di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
2721 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
2722 | return 1; | |
2723 | } | |
2724 | ||
2725 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2726 | if(AISContext.IsNull()) | |
2727 | { | |
2728 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2729 | return 1; | |
2730 | } | |
2731 | if (argc == 8) | |
2732 | { | |
2733 | ||
91322f44 | 2734 | Standard_Real R1 = Draw::Atof(argv[1])/255.; |
2735 | Standard_Real G1 = Draw::Atof(argv[2])/255.; | |
2736 | Standard_Real B1 = Draw::Atof(argv[3])/255.; | |
7fd59977 | 2737 | Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB); |
2738 | ||
91322f44 | 2739 | Standard_Real R2 = Draw::Atof(argv[4])/255.; |
2740 | Standard_Real G2 = Draw::Atof(argv[5])/255.; | |
2741 | Standard_Real B2 = Draw::Atof(argv[6])/255.; | |
7fd59977 | 2742 | |
2743 | Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB); | |
91322f44 | 2744 | int aType = Draw::Atoi(argv[7]); |
7fd59977 | 2745 | if( aType < 0 || aType > 8 ) |
2746 | { | |
2747 | di << "Wrong fill type " << "\n"; | |
2748 | di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
2749 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
2750 | return 1; | |
2751 | } | |
2752 | ||
2753 | Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType); | |
2754 | ||
2755 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2756 | V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1); | |
2757 | } | |
2758 | ||
2759 | return 0; | |
2760 | } | |
2761 | ||
f8b2ed36 | 2762 | //============================================================================== |
2763 | //function : VSetGradientBgMode | |
2764 | //purpose : Change gradient background fill style | |
2765 | //============================================================================== | |
2766 | static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2767 | { | |
2768 | if (argc != 2 ) | |
2769 | { | |
2770 | di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n"; | |
2771 | di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
2772 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
2773 | return 1; | |
2774 | } | |
2775 | ||
2776 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2777 | if(AISContext.IsNull()) | |
2778 | { | |
2779 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2780 | return 1; | |
2781 | } | |
2782 | if (argc == 2) | |
2783 | { | |
91322f44 | 2784 | int aType = Draw::Atoi(argv[1]); |
f8b2ed36 | 2785 | if( aType < 0 || aType > 8 ) |
2786 | { | |
2787 | di << "Wrong fill type " << "\n"; | |
2788 | di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n"; | |
2789 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n"; | |
2790 | return 1; | |
2791 | } | |
2792 | ||
2793 | Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType); | |
2794 | ||
2795 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2796 | V3dView->SetBgGradientStyle( aMethod, 1 ); | |
2797 | } | |
2798 | ||
2799 | return 0; | |
2800 | } | |
2801 | ||
2802 | //============================================================================== | |
2803 | //function : VSetColorBg | |
2804 | //purpose : Set color background | |
2805 | //============================================================================== | |
2806 | static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2807 | { | |
2808 | if (argc != 4 ) | |
2809 | { | |
2810 | di << "Usage : " << argv[0] << " R G B : Set color background" << "\n"; | |
2811 | di << "R,G,B = [0..255]" << "\n"; | |
2812 | return 1; | |
2813 | } | |
2814 | ||
2815 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2816 | if(AISContext.IsNull()) | |
2817 | { | |
2818 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2819 | return 1; | |
2820 | } | |
2821 | if (argc == 4) | |
2822 | { | |
2823 | ||
91322f44 | 2824 | Standard_Real R = Draw::Atof(argv[1])/255.; |
2825 | Standard_Real G = Draw::Atof(argv[2])/255.; | |
2826 | Standard_Real B = Draw::Atof(argv[3])/255.; | |
f8b2ed36 | 2827 | Quantity_Color aColor(R,G,B,Quantity_TOC_RGB); |
2828 | ||
2829 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2830 | V3dView->SetBackgroundColor( aColor ); | |
2831 | V3dView->Update(); | |
2832 | } | |
2833 | ||
2834 | return 0; | |
2835 | } | |
2836 | ||
7fd59977 | 2837 | //============================================================================== |
2838 | //function : VScale | |
2839 | //purpose : View Scaling | |
2840 | //============================================================================== | |
2841 | ||
2842 | static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2843 | { | |
2844 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2845 | if ( V3dView.IsNull() ) return 1; | |
2846 | ||
2847 | if ( argc != 4 ) { | |
2848 | di << argv[0] << "Invalid number of arguments" << "\n"; | |
2849 | return 1; | |
2850 | } | |
91322f44 | 2851 | V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) ); |
7fd59977 | 2852 | return 0; |
2853 | } | |
2854 | //============================================================================== | |
536d98e2 | 2855 | //function : VZBuffTrihedron |
2856 | //purpose : | |
7fd59977 | 2857 | //============================================================================== |
2858 | ||
536d98e2 | 2859 | static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/, |
2860 | Standard_Integer theArgNb, | |
2861 | const char** theArgVec) | |
7fd59977 | 2862 | { |
536d98e2 | 2863 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2864 | if (aView.IsNull()) | |
2865 | { | |
2866 | std::cout << "Error: no active viewer!\n"; | |
2867 | return 1; | |
2868 | } | |
7fd59977 | 2869 | |
536d98e2 | 2870 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
7c8a8fcc | 2871 | |
536d98e2 | 2872 | Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER; |
2873 | V3d_TypeOfVisualization aVisType = V3d_ZBUFFER; | |
2874 | Quantity_Color aLabelsColor = Quantity_NOC_WHITE; | |
2875 | Quantity_Color anArrowColorX = Quantity_NOC_RED; | |
2876 | Quantity_Color anArrowColorY = Quantity_NOC_GREEN; | |
2877 | Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1; | |
2878 | Standard_Real aScale = 0.1; | |
2879 | Standard_Real aSizeRatio = 0.8; | |
2880 | Standard_Real anArrowDiam = 0.05; | |
2881 | Standard_Integer aNbFacets = 12; | |
2882 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
7c8a8fcc | 2883 | { |
536d98e2 | 2884 | Standard_CString anArg = theArgVec[anArgIter]; |
2885 | TCollection_AsciiString aFlag (anArg); | |
2886 | aFlag.LowerCase(); | |
2887 | if (anUpdateTool.parseRedrawMode (aFlag)) | |
7c8a8fcc | 2888 | { |
536d98e2 | 2889 | continue; |
2890 | } | |
2891 | else if (aFlag == "-on") | |
7c8a8fcc | 2892 | { |
536d98e2 | 2893 | continue; |
2894 | } | |
2895 | else if (aFlag == "-off") | |
7c8a8fcc | 2896 | { |
536d98e2 | 2897 | aView->TriedronErase(); |
2898 | return 0; | |
2899 | } | |
2900 | else if (aFlag == "-pos" | |
2901 | || aFlag == "-position" | |
2902 | || aFlag == "-corner") | |
7c8a8fcc | 2903 | { |
536d98e2 | 2904 | if (++anArgIter >= theArgNb) |
2905 | { | |
2906 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
2907 | return 1; | |
2908 | } | |
2909 | ||
2910 | TCollection_AsciiString aPosName (theArgVec[anArgIter]); | |
2911 | aPosName.LowerCase(); | |
2912 | if (aPosName == "center") | |
2913 | { | |
2914 | aPosition = Aspect_TOTP_CENTER; | |
2915 | } | |
2916 | else if (aPosName == "left_lower" | |
2917 | || aPosName == "lower_left" | |
2918 | || aPosName == "leftlower" | |
2919 | || aPosName == "lowerleft") | |
2920 | { | |
2921 | aPosition = Aspect_TOTP_LEFT_LOWER; | |
2922 | } | |
2923 | else if (aPosName == "left_upper" | |
2924 | || aPosName == "upper_left" | |
2925 | || aPosName == "leftupper" | |
2926 | || aPosName == "upperleft") | |
2927 | { | |
2928 | aPosition = Aspect_TOTP_LEFT_UPPER; | |
2929 | } | |
2930 | else if (aPosName == "right_lower" | |
2931 | || aPosName == "lower_right" | |
2932 | || aPosName == "rightlower" | |
2933 | || aPosName == "lowerright") | |
2934 | { | |
2935 | aPosition = Aspect_TOTP_RIGHT_LOWER; | |
2936 | } | |
2937 | else if (aPosName == "right_upper" | |
2938 | || aPosName == "upper_right" | |
2939 | || aPosName == "rightupper" | |
2940 | || aPosName == "upperright") | |
2941 | { | |
2942 | aPosition = Aspect_TOTP_RIGHT_UPPER; | |
2943 | } | |
2944 | else | |
2945 | { | |
2946 | std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n"; | |
2947 | return 1; | |
2948 | } | |
2949 | } | |
2950 | else if (aFlag == "-type") | |
7c8a8fcc | 2951 | { |
536d98e2 | 2952 | if (++anArgIter >= theArgNb) |
2953 | { | |
2954 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
2955 | return 1; | |
2956 | } | |
2957 | ||
2958 | TCollection_AsciiString aTypeName (theArgVec[anArgIter]); | |
2959 | aTypeName.LowerCase(); | |
2960 | if (aTypeName == "wireframe" | |
2961 | || aTypeName == "wire") | |
2962 | { | |
2963 | aVisType = V3d_WIREFRAME; | |
2964 | } | |
2965 | else if (aTypeName == "zbuffer" | |
2966 | || aTypeName == "shaded") | |
2967 | { | |
2968 | aVisType = V3d_ZBUFFER; | |
2969 | } | |
2970 | else | |
2971 | { | |
2972 | std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n"; | |
2973 | } | |
2974 | } | |
2975 | else if (aFlag == "-scale") | |
7c8a8fcc | 2976 | { |
536d98e2 | 2977 | if (++anArgIter >= theArgNb) |
2978 | { | |
2979 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
2980 | return 1; | |
2981 | } | |
2982 | ||
2983 | aScale = Draw::Atof (theArgVec[anArgIter]); | |
7c8a8fcc | 2984 | } |
536d98e2 | 2985 | else if (aFlag == "-size" |
2986 | || aFlag == "-sizeratio") | |
2987 | { | |
2988 | if (++anArgIter >= theArgNb) | |
2989 | { | |
2990 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
2991 | return 1; | |
2992 | } | |
7c8a8fcc | 2993 | |
536d98e2 | 2994 | aSizeRatio = Draw::Atof (theArgVec[anArgIter]); |
2995 | } | |
2996 | else if (aFlag == "-arrowdiam" | |
2997 | || aFlag == "-arrowdiameter") | |
2998 | { | |
2999 | if (++anArgIter >= theArgNb) | |
3000 | { | |
3001 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3002 | return 1; | |
3003 | } | |
7c8a8fcc | 3004 | |
536d98e2 | 3005 | anArrowDiam = Draw::Atof (theArgVec[anArgIter]); |
3006 | } | |
3007 | else if (aFlag == "-nbfacets") | |
3008 | { | |
3009 | if (++anArgIter >= theArgNb) | |
3010 | { | |
3011 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3012 | return 1; | |
3013 | } | |
7c8a8fcc | 3014 | |
536d98e2 | 3015 | aNbFacets = Draw::Atoi (theArgVec[anArgIter]); |
3016 | } | |
3017 | else if (aFlag == "-colorlabel" | |
3018 | || aFlag == "-colorlabels") | |
7c8a8fcc | 3019 | { |
536d98e2 | 3020 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
3021 | theArgVec + anArgIter + 1, | |
3022 | aLabelsColor); | |
3023 | if (aNbParsed == 0) | |
3024 | { | |
3025 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3026 | return 1; | |
3027 | } | |
3028 | anArgIter += aNbParsed; | |
7c8a8fcc | 3029 | } |
536d98e2 | 3030 | else if (aFlag == "-colorarrowx") |
7c8a8fcc | 3031 | { |
536d98e2 | 3032 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
3033 | theArgVec + anArgIter + 1, | |
3034 | anArrowColorX); | |
3035 | if (aNbParsed == 0) | |
3036 | { | |
3037 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3038 | return 1; | |
3039 | } | |
3040 | anArgIter += aNbParsed; | |
3041 | } | |
3042 | else if (aFlag == "-colorarrowy") | |
7c8a8fcc | 3043 | { |
536d98e2 | 3044 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
3045 | theArgVec + anArgIter + 1, | |
3046 | anArrowColorY); | |
3047 | if (aNbParsed == 0) | |
3048 | { | |
3049 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3050 | return 1; | |
3051 | } | |
3052 | anArgIter += aNbParsed; | |
3053 | } | |
3054 | else if (aFlag == "-colorarrowz") | |
7c8a8fcc | 3055 | { |
536d98e2 | 3056 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
3057 | theArgVec + anArgIter + 1, | |
3058 | anArrowColorZ); | |
3059 | if (aNbParsed == 0) | |
3060 | { | |
3061 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3062 | return 1; | |
3063 | } | |
3064 | anArgIter += aNbParsed; | |
3065 | } | |
3066 | else | |
3067 | { | |
3068 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
7c8a8fcc | 3069 | return 1; |
3070 | } | |
7c8a8fcc | 3071 | } |
3072 | ||
536d98e2 | 3073 | aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(), |
3074 | aSizeRatio, anArrowDiam, aNbFacets); | |
3075 | aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType); | |
3076 | aView->View()->ZFitAll(); | |
7fd59977 | 3077 | return 0; |
3078 | } | |
3079 | ||
3080 | //============================================================================== | |
3081 | //function : VRotate | |
3082 | //purpose : Camera Rotating | |
3083 | //============================================================================== | |
3084 | ||
4af098ba | 3085 | static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec) |
3086 | { | |
3087 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3088 | if (aView.IsNull()) | |
3089 | { | |
3090 | std::cout << "No active view!\n"; | |
7fd59977 | 3091 | return 1; |
3092 | } | |
3093 | ||
4af098ba | 3094 | Standard_Boolean hasFlags = Standard_False; |
3095 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
3096 | { | |
3097 | Standard_CString anArg (theArgVec[anArgIter]); | |
3098 | TCollection_AsciiString aFlag (anArg); | |
3099 | aFlag.LowerCase(); | |
3100 | if (aFlag == "-mousestart" | |
3101 | || aFlag == "-mousefrom") | |
3102 | { | |
3103 | hasFlags = Standard_True; | |
3104 | if (anArgIter + 2 >= theArgNb) | |
3105 | { | |
3106 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
3107 | return 1; | |
3108 | } | |
3109 | ||
3110 | Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]); | |
3111 | Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]); | |
3112 | aView->StartRotation (anX, anY); | |
3113 | } | |
3114 | else if (aFlag == "-mousemove") | |
3115 | { | |
3116 | hasFlags = Standard_True; | |
3117 | if (anArgIter + 2 >= theArgNb) | |
3118 | { | |
3119 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
3120 | return 1; | |
3121 | } | |
3122 | ||
3123 | Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]); | |
3124 | Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]); | |
3125 | aView->Rotation (anX, anY); | |
3126 | } | |
3127 | else if (theArgNb != 4 | |
3128 | && theArgNb != 7) | |
3129 | { | |
3130 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
3131 | return 1; | |
3132 | } | |
3133 | } | |
3134 | ||
3135 | if (hasFlags) | |
3136 | { | |
7fd59977 | 3137 | return 0; |
4af098ba | 3138 | } |
3139 | else if (theArgNb == 4) | |
3140 | { | |
3141 | Standard_Real anAX = Draw::Atof (theArgVec[1]); | |
3142 | Standard_Real anAY = Draw::Atof (theArgVec[2]); | |
3143 | Standard_Real anAZ = Draw::Atof (theArgVec[3]); | |
3144 | aView->Rotate (anAX, anAY, anAZ); | |
3145 | return 0; | |
3146 | } | |
3147 | else if (theArgNb == 7) | |
3148 | { | |
3149 | Standard_Real anAX = Draw::Atof (theArgVec[1]); | |
3150 | Standard_Real anAY = Draw::Atof (theArgVec[2]); | |
3151 | Standard_Real anAZ = Draw::Atof (theArgVec[3]); | |
3152 | ||
3153 | Standard_Real anX = Draw::Atof (theArgVec[4]); | |
3154 | Standard_Real anY = Draw::Atof (theArgVec[5]); | |
3155 | Standard_Real anZ = Draw::Atof (theArgVec[6]); | |
3156 | ||
3157 | aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ); | |
7fd59977 | 3158 | return 0; |
7fd59977 | 3159 | } |
4af098ba | 3160 | |
3161 | std::cout << "Error: Invalid number of arguments\n"; | |
3162 | return 1; | |
7fd59977 | 3163 | } |
3164 | ||
3165 | //============================================================================== | |
3166 | //function : VZoom | |
3167 | //purpose : View zoom in / out (relative to current zoom) | |
3168 | //============================================================================== | |
3169 | ||
3170 | static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
3171 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
3172 | if ( V3dView.IsNull() ) { | |
3173 | return 1; | |
3174 | } | |
3175 | ||
3176 | if ( argc == 2 ) { | |
91322f44 | 3177 | Standard_Real coef = Draw::Atof(argv[1]); |
7fd59977 | 3178 | if ( coef <= 0.0 ) { |
3179 | di << argv[1] << "Invalid value" << "\n"; | |
3180 | return 1; | |
3181 | } | |
91322f44 | 3182 | V3dView->SetZoom( Draw::Atof(argv[1]) ); |
7fd59977 | 3183 | return 0; |
3184 | } else { | |
3185 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
3186 | return 1; | |
3187 | } | |
3188 | } | |
3189 | ||
3190 | //============================================================================== | |
3191 | //function : VPan | |
3192 | //purpose : View panning (in pixels) | |
3193 | //============================================================================== | |
3194 | ||
3195 | static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
3196 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
3197 | if ( V3dView.IsNull() ) return 1; | |
3198 | ||
3199 | if ( argc == 3 ) { | |
91322f44 | 3200 | V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) ); |
7fd59977 | 3201 | return 0; |
3202 | } else { | |
3203 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
3204 | return 1; | |
3205 | } | |
3206 | } | |
3207 | ||
49e1a5c7 | 3208 | //============================================================================== |
3209 | //function : VPlace | |
3210 | //purpose : Place the point (in pixels) at the center of the window | |
3211 | //============================================================================== | |
3212 | static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs) | |
3213 | { | |
3214 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3215 | if (aView.IsNull()) | |
3216 | { | |
3217 | std::cerr << theArgs[0] << "Error: no active view." << std::endl; | |
3218 | return 1; | |
3219 | } | |
3220 | ||
3221 | if (theArgNb != 3) | |
3222 | { | |
3223 | std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl; | |
3224 | return 1; | |
3225 | } | |
3226 | ||
3227 | aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale()); | |
3228 | ||
3229 | return 0; | |
3230 | } | |
7fd59977 | 3231 | |
3232 | //============================================================================== | |
3233 | //function : VExport | |
5cedc27f | 3234 | //purpose : Export the view to a vector graphic format (PS, EMF, PDF) |
7fd59977 | 3235 | //============================================================================== |
3236 | ||
3237 | static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3238 | { | |
3239 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
5cedc27f K |
3240 | if (V3dView.IsNull()) |
3241 | return 1; | |
7fd59977 | 3242 | |
5cedc27f K |
3243 | if (argc == 1) |
3244 | { | |
3245 | std::cout << "Usage: " << argv[0] << " Filename [Format]\n"; | |
7fd59977 | 3246 | return 1; |
3247 | } | |
3248 | ||
5cedc27f K |
3249 | Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF; |
3250 | TCollection_AsciiString aFormatStr; | |
3251 | ||
3252 | TCollection_AsciiString aFileName (argv[1]); | |
3253 | Standard_Integer aLen = aFileName.Length(); | |
3254 | ||
3255 | if (argc > 2) | |
3256 | { | |
3257 | aFormatStr = TCollection_AsciiString (argv[2]); | |
3258 | } | |
3259 | else if (aLen >= 4) | |
3260 | { | |
3261 | if (aFileName.Value (aLen - 2) == '.') | |
3262 | { | |
3263 | aFormatStr = aFileName.SubString (aLen - 1, aLen); | |
3264 | } | |
3265 | else if (aFileName.Value (aLen - 3) == '.') | |
3266 | { | |
3267 | aFormatStr = aFileName.SubString (aLen - 2, aLen); | |
3268 | } | |
3269 | else | |
3270 | { | |
3271 | std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n"; | |
3272 | return 1; | |
3273 | } | |
3274 | } | |
3275 | else | |
3276 | { | |
3277 | std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n"; | |
3278 | return 1; | |
3279 | } | |
3280 | ||
3281 | aFormatStr.UpperCase(); | |
3282 | if (aFormatStr == "PS") | |
3283 | anExpFormat = Graphic3d_EF_PostScript; | |
3284 | else if (aFormatStr == "EPS") | |
3285 | anExpFormat = Graphic3d_EF_EnhPostScript; | |
3286 | else if (aFormatStr == "TEX") | |
3287 | anExpFormat = Graphic3d_EF_TEX; | |
3288 | else if (aFormatStr == "PDF") | |
3289 | anExpFormat = Graphic3d_EF_PDF; | |
3290 | else if (aFormatStr == "SVG") | |
3291 | anExpFormat = Graphic3d_EF_SVG; | |
3292 | else if (aFormatStr == "PGF") | |
3293 | anExpFormat = Graphic3d_EF_PGF; | |
3294 | else if (aFormatStr == "EMF") | |
3295 | anExpFormat = Graphic3d_EF_EMF; | |
3296 | else | |
3297 | { | |
3298 | std::cout << "Invalid export format '" << aFormatStr << "'\n"; | |
3299 | return 1; | |
3300 | } | |
3301 | ||
9753e6de | 3302 | try { |
3303 | if (!V3dView->View()->Export (argv[1], anExpFormat)) | |
3304 | { | |
3305 | di << "Error: export of image to " << aFormatStr << " failed!\n"; | |
3306 | } | |
3307 | } | |
3308 | catch (Standard_Failure) | |
5cedc27f | 3309 | { |
9753e6de | 3310 | di << "Error: export of image to " << aFormatStr << " failed"; |
3311 | di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")"; | |
5cedc27f | 3312 | } |
7fd59977 | 3313 | return 0; |
3314 | } | |
3315 | ||
3316 | //============================================================================== | |
3317 | //function : VColorScale | |
3318 | //purpose : representation color scale | |
3319 | //============================================================================== | |
7fd59977 | 3320 | |
71215351 | 3321 | static Standard_Boolean checkColor (const TCollection_AsciiString& theRed, |
3322 | const TCollection_AsciiString& theGreen, | |
3323 | const TCollection_AsciiString& theBlue, | |
3324 | Standard_Real& theRedValue, | |
3325 | Standard_Real& theGreenValue, | |
3326 | Standard_Real& theBlueValue) | |
7fd59977 | 3327 | { |
71215351 | 3328 | if (!theRed.IsRealValue() |
3329 | || !theGreen.IsRealValue() | |
3330 | || !theBlue.IsRealValue()) | |
7fd59977 | 3331 | { |
71215351 | 3332 | std::cout << "Error: RGB color values should be real!\n"; |
3333 | return Standard_True; | |
3334 | } | |
3335 | theRedValue = theRed .RealValue(); | |
3336 | theGreenValue = theGreen.RealValue(); | |
3337 | theBlueValue = theBlue .RealValue(); | |
3338 | if (theRedValue < 0.0 || theRedValue > 1.0 | |
3339 | || theGreenValue < 0.0 || theGreenValue > 1.0 | |
3340 | || theBlueValue < 0.0 || theBlueValue > 1.0) | |
3341 | { | |
3342 | std::cout << "Error: RGB color values should be within range 0..1!\n"; | |
3343 | return Standard_True; | |
7fd59977 | 3344 | } |
71215351 | 3345 | return Standard_False; |
3346 | } | |
7fd59977 | 3347 | |
71215351 | 3348 | static int VColorScale (Draw_Interpretor& theDI, |
3349 | Standard_Integer theArgNb, | |
3350 | const char** theArgVec) | |
3351 | { | |
7fd59977 | 3352 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
71215351 | 3353 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
3354 | if (aContext.IsNull()) | |
3355 | { | |
3356 | std::cout << "Error: no active view!\n"; | |
3357 | return 1; | |
7fd59977 | 3358 | } |
3359 | ||
71215351 | 3360 | Handle(V3d_ColorScale) aCS = Handle(V3d_ColorScale)::DownCast (aView->ColorScale()); |
3361 | if (aCS.IsNull()) | |
3362 | { | |
3363 | std::cout << "Error: color scale is undefined!\n"; | |
7fd59977 | 3364 | return 1; |
7fd59977 | 3365 | } |
71215351 | 3366 | |
3367 | Standard_Real aMinRange = aCS->GetMin(); | |
3368 | Standard_Real aMaxRange = aCS->GetMax(); | |
3369 | Standard_Integer aNbIntervals = aCS->GetNumberOfIntervals(); | |
3370 | Standard_Integer aTextHeight = aCS->GetTextHeight(); | |
3371 | Aspect_TypeOfColorScalePosition aLabPosition = aCS->GetLabelPosition(); | |
3372 | gp_XY aPos (aCS->GetXPosition(), aCS->GetYPosition()); | |
3373 | ||
3374 | ViewerTest_AutoUpdater anUpdateTool (aContext, aView); | |
3375 | ||
3376 | if (theArgNb <= 1) | |
3377 | { | |
3378 | theDI << "Current color scale parameters:\n" | |
3379 | << "Min range: " << aMinRange << "\n" | |
3380 | << "Max range: " << aMaxRange << "\n" | |
3381 | << "Number of intervals: " << aNbIntervals << "\n" | |
3382 | << "Text height: " << aTextHeight << "\n" | |
3383 | << "Color scale position: " << aPos.X() <<" "<< aPos.Y()<< "\n" | |
3384 | << "Color scale title: " << aCS->GetTitle() << "\n" | |
3385 | << "Label position: "; | |
3386 | switch (aLabPosition) | |
3387 | { | |
3388 | case Aspect_TOCSP_NONE: | |
3389 | theDI << "None\n"; | |
3390 | break; | |
3391 | case Aspect_TOCSP_LEFT: | |
3392 | theDI << "Left\n"; | |
3393 | break; | |
3394 | case Aspect_TOCSP_RIGHT: | |
3395 | theDI << "Right\n"; | |
3396 | break; | |
3397 | case Aspect_TOCSP_CENTER: | |
3398 | theDI << "Center\n"; | |
3399 | break; | |
3400 | } | |
3401 | return 0; | |
3402 | } | |
3403 | Standard_CString aFirstArg = theArgVec[1]; | |
3404 | TCollection_AsciiString aFlag (aFirstArg); | |
3405 | aFlag.LowerCase(); | |
3406 | if (aFlag == "-hide" || | |
3407 | aFlag == "-erase") | |
3408 | { | |
3409 | if (theArgNb > 2) | |
3410 | { | |
3411 | std::cout << "Error: wrong syntax at argument '" << theArgVec[1] << "'!\n"; | |
3412 | return 1; | |
3413 | } | |
3414 | if (!aView->ColorScaleIsDisplayed()) | |
3415 | { | |
3416 | std::cout << "Error: color scale is not displayed!\n"; | |
3417 | return 1; | |
3418 | } | |
3419 | else | |
3420 | { | |
3421 | aView->ColorScaleErase(); | |
3422 | return 0; | |
3423 | } | |
3424 | } | |
3425 | else if (aFlag == "-show" || | |
3426 | aFlag == "-display") | |
3427 | { | |
3428 | if (theArgNb > 2) | |
3429 | { | |
3430 | std::cout << "Error: wrong syntax at argument '" << theArgVec[1] << "'!\n"; | |
3431 | return 1; | |
3432 | } | |
3433 | aView->ColorScaleDisplay(); | |
3434 | return 0; | |
3435 | } | |
3436 | ||
3437 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
3438 | { | |
3439 | Standard_CString anArg = theArgVec[anArgIter]; | |
3440 | TCollection_AsciiString aFlag (anArg); | |
3441 | aFlag.LowerCase(); | |
3442 | if (anUpdateTool.parseRedrawMode (aFlag)) | |
3443 | { | |
3444 | continue; | |
3445 | } | |
3446 | else if (aFlag == "-range") | |
3447 | { | |
3448 | if (anArgIter + 3 >= theArgNb) | |
3449 | { | |
3450 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3451 | return 1; | |
3452 | } | |
3453 | ||
3454 | TCollection_AsciiString anArg1 (theArgVec[++anArgIter]); | |
3455 | TCollection_AsciiString anArg2 (theArgVec[++anArgIter]); | |
3456 | TCollection_AsciiString anArg3 (theArgVec[++anArgIter]); | |
3457 | if (!anArg1.IsRealValue()) | |
3458 | { | |
3459 | std::cout << "Error: the minRange value should be real!\n"; | |
3460 | return 1; | |
3461 | } | |
3462 | else if (!anArg2.IsRealValue()) | |
3463 | { | |
3464 | std::cout << "Error: the maxRange value should be real!\n"; | |
3465 | return 1; | |
3466 | } | |
3467 | else if (!anArg3.IsIntegerValue()) | |
3468 | { | |
3469 | std::cout << "Error: the number of intervals should be integer!\n"; | |
3470 | return 1; | |
3471 | } | |
3472 | ||
3473 | aMinRange = anArg1.RealValue(); | |
3474 | aMaxRange = anArg2.RealValue(); | |
3475 | aNbIntervals = anArg3.IntegerValue(); | |
3476 | } | |
3477 | else if (aFlag == "-font") | |
3478 | { | |
3479 | if (anArgIter + 1 >= theArgNb) | |
3480 | { | |
3481 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3482 | return 1; | |
3483 | } | |
3484 | TCollection_AsciiString anArg (theArgVec[anArgIter + 1]); | |
3485 | if (!anArg.IsIntegerValue()) | |
3486 | { | |
3487 | std::cout << "Error: HeightFont value should be integer!\n"; | |
3488 | return 1; | |
3489 | } | |
3490 | ||
3491 | aTextHeight = anArg.IntegerValue(); | |
3492 | anArgIter += 1; | |
3493 | } | |
3494 | else if (aFlag == "-textpos") | |
3495 | { | |
3496 | if (anArgIter + 1 >= theArgNb) | |
3497 | { | |
3498 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3499 | return 1; | |
3500 | } | |
3501 | TCollection_AsciiString anArg (theArgVec[++anArgIter]); | |
3502 | anArg.LowerCase(); | |
3503 | if (anArg == "none") | |
3504 | { | |
3505 | aLabPosition = Aspect_TOCSP_NONE; | |
3506 | } | |
3507 | else if (anArg == "left") | |
3508 | { | |
3509 | aLabPosition = Aspect_TOCSP_LEFT; | |
3510 | } | |
3511 | else if (anArg == "right") | |
3512 | { | |
3513 | aLabPosition = Aspect_TOCSP_RIGHT; | |
3514 | } | |
3515 | else if (anArg == "center") | |
3516 | { | |
3517 | aLabPosition = Aspect_TOCSP_CENTER; | |
3518 | } | |
3519 | else | |
3520 | { | |
3521 | std::cout << "Error: unknown position '" << anArg << "'!\n"; | |
3522 | return 1; | |
3523 | } | |
3524 | } | |
3525 | else if (aFlag == "-xy") | |
3526 | { | |
3527 | if (anArgIter + 2 >= theArgNb) | |
3528 | { | |
3529 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3530 | return 1; | |
3531 | } | |
3532 | ||
3533 | TCollection_AsciiString aX (theArgVec[++anArgIter]); | |
3534 | TCollection_AsciiString aY (theArgVec[++anArgIter]); | |
3535 | if (!aX.IsRealValue() | |
3536 | || !aY.IsRealValue()) | |
3537 | { | |
3538 | std::cout << "Error: coordinates should be real values!\n"; | |
3539 | return 1; | |
3540 | } | |
3541 | ||
3542 | aPos.SetCoord (aX.RealValue(), aY.RealValue()); | |
3543 | } | |
3544 | else if (aFlag == "-color") | |
3545 | { | |
3546 | if (aCS->GetColorType() != Aspect_TOCSD_USER) | |
3547 | { | |
3548 | std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n"; | |
3549 | return 1; | |
3550 | } | |
3551 | ||
3552 | Quantity_NameOfColor aColorName; | |
3553 | if (anArgIter + 4 >= theArgNb) | |
3554 | { | |
3555 | if (anArgIter + 2 >= theArgNb) | |
3556 | { | |
3557 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3558 | return 1; | |
3559 | } | |
3560 | else if (!Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName)) | |
3561 | { | |
3562 | std::cout << "Error: wrong color name: '" << theArgVec[anArgIter + 2] << "' !\n"; | |
3563 | return 1; | |
3564 | } | |
3565 | } | |
3566 | ||
3567 | TCollection_AsciiString anInd (theArgVec[anArgIter + 1]); | |
3568 | if (!anInd.IsIntegerValue()) | |
3569 | { | |
3570 | std::cout << "Error: Index value should be integer!\n"; | |
3571 | return 1; | |
3572 | } | |
3573 | ||
3574 | Standard_Integer anIndex = anInd.IntegerValue(); | |
3575 | if (anIndex < 0 | |
3576 | || anIndex > aNbIntervals - 1) | |
3577 | { | |
3578 | std::cout << "Error: Index value should be within range 0..." << (aNbIntervals - 1) <<"!\n"; | |
3579 | return 1; | |
3580 | } | |
3581 | ||
3582 | if (Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName)) | |
3583 | { | |
3584 | aCS->SetColor (Quantity_Color (aColorName), anIndex); | |
3585 | aCS->SetColorType(Aspect_TOCSD_USER); | |
3586 | anArgIter += 2; | |
3587 | continue; | |
3588 | } | |
3589 | ||
3590 | TCollection_AsciiString aRed (theArgVec[anArgIter + 2]); | |
3591 | TCollection_AsciiString aGreen (theArgVec[anArgIter + 3]); | |
3592 | TCollection_AsciiString aBlue (theArgVec[anArgIter + 4]); | |
3593 | Standard_Real aRedValue,aGreenValue, aBlueValue; | |
3594 | if(checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue)) | |
3595 | { | |
3596 | return 1; | |
3597 | } | |
3598 | aCS->SetColor (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB), anIndex); | |
3599 | aCS->SetColorType (Aspect_TOCSD_USER); | |
3600 | anArgIter += 4; | |
3601 | } | |
3602 | else if (aFlag == "-label") | |
3603 | { | |
3604 | if (aCS->GetColorType() != Aspect_TOCSD_USER) | |
3605 | { | |
3606 | std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n"; | |
3607 | return 1; | |
3608 | } | |
3609 | else if (anArgIter + 2 >= theArgNb) | |
3610 | { | |
3611 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3612 | return 1; | |
3613 | } | |
3614 | ||
3615 | Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]); | |
3616 | if (anIndex < 0 | |
3617 | || anIndex > aNbIntervals) | |
3618 | { | |
3619 | std::cout << "Error: Index value should be within range 0..." << aNbIntervals <<"!\n"; | |
3620 | return 1; | |
3621 | } | |
3622 | ||
3623 | TCollection_ExtendedString aText (theArgVec[anArgIter + 2]); | |
3624 | aCS->SetLabel (aText, anIndex); | |
3625 | aCS->SetLabelType (Aspect_TOCSD_USER); | |
3626 | anArgIter += 2; | |
3627 | } | |
3628 | else if (aFlag == "-colors") | |
3629 | { | |
3630 | Aspect_SequenceOfColor aSeq; | |
3631 | if (anArgIter + aNbIntervals + 1 > theArgNb) | |
3632 | { | |
3633 | std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the " | |
3634 | << aNbIntervals << " intervals\n"; | |
3635 | return 1; | |
3636 | } | |
3637 | ||
3638 | Standard_Integer aColorIter = anArgIter + 1; | |
3639 | while (aColorIter < theArgNb) | |
3640 | { | |
3641 | if (theArgVec[aColorIter][0] == '-') | |
3642 | { | |
3643 | break; | |
3644 | } | |
3645 | ||
3646 | else if (theArgVec[aColorIter][0] >= 97 | |
3647 | && theArgVec[aColorIter][0] <= 122) | |
3648 | { | |
3649 | Quantity_NameOfColor aColorName; | |
3650 | if (!Quantity_Color::ColorFromName (theArgVec[aColorIter], aColorName)) | |
3651 | { | |
3652 | std::cout << "Error: wrong color name: " << theArgVec[aColorIter] << " !\n"; | |
3653 | return 1; | |
3654 | } | |
3655 | aSeq.Append (Quantity_Color (aColorName)); | |
3656 | aColorIter++; | |
3657 | anArgIter++; | |
3658 | } | |
3659 | else | |
3660 | { | |
3661 | TCollection_AsciiString aRed (theArgVec[aColorIter]); | |
3662 | TCollection_AsciiString aGreen (theArgVec[aColorIter + 1]); | |
3663 | TCollection_AsciiString aBlue (theArgVec[aColorIter + 2]); | |
3664 | Standard_Real aRedValue,aGreenValue, aBlueValue; | |
3665 | if (checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue)) | |
3666 | { | |
3667 | return 1; | |
3668 | } | |
3669 | aSeq.Append (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB)); | |
3670 | aColorIter += 3; | |
3671 | anArgIter += 3; | |
3672 | } | |
3673 | } | |
3674 | if (aSeq.Length() < aNbIntervals) | |
3675 | { | |
3676 | std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the " | |
3677 | << aNbIntervals << " intervals\n"; | |
3678 | return 1; | |
3679 | } | |
3680 | ||
3681 | aCS->SetColors (aSeq); | |
3682 | aCS->SetColorType (Aspect_TOCSD_USER); | |
3683 | } | |
3684 | else if (aFlag == "-labels") | |
3685 | { | |
3686 | if (anArgIter + aNbIntervals + 1 >= theArgNb) | |
3687 | { | |
3688 | std::cout << "Error: not enough arguments! You should provide " << (aNbIntervals + 1) | |
3689 | << " text labels for " << aNbIntervals << " intervals.\n"; | |
3690 | return 1; | |
3691 | } | |
3692 | ||
3693 | TColStd_SequenceOfExtendedString aSeq; | |
3694 | for (int aLabelIter = anArgIter + 1; aLabelIter <= anArgIter + aNbIntervals + 1; aLabelIter += 1) | |
3695 | { | |
3696 | aSeq.Append (TCollection_ExtendedString (theArgVec[aLabelIter])); | |
3697 | } | |
3698 | aCS->SetLabels (aSeq); | |
3699 | aCS->SetLabelType (Aspect_TOCSD_USER); | |
3700 | anArgIter += aSeq.Length(); | |
3701 | } | |
3702 | else if (aFlag == "-title") | |
3703 | { | |
3704 | if (anArgIter + 1 >= theArgNb) | |
3705 | { | |
3706 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3707 | return 1; | |
3708 | } | |
3709 | ||
3710 | Standard_Boolean isTwoArgs = Standard_False; | |
3711 | if (anArgIter + 2 < theArgNb) | |
3712 | { | |
3713 | TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]); | |
3714 | aSecondArg.LowerCase(); | |
3715 | if (aSecondArg == "none") | |
3716 | { | |
3717 | aCS->SetTitlePosition (Aspect_TOCSP_NONE); | |
3718 | isTwoArgs = Standard_True; | |
3719 | } | |
3720 | else if (aSecondArg == "left") | |
3721 | { | |
3722 | aCS->SetTitlePosition (Aspect_TOCSP_LEFT); | |
3723 | isTwoArgs = Standard_True; | |
3724 | } | |
3725 | else if (aSecondArg == "right") | |
3726 | { | |
3727 | aCS->SetTitlePosition (Aspect_TOCSP_RIGHT); | |
3728 | isTwoArgs = Standard_True; | |
3729 | } | |
3730 | else if (aSecondArg == "center") | |
3731 | { | |
3732 | aCS->SetTitlePosition (Aspect_TOCSP_CENTER); | |
3733 | isTwoArgs = Standard_True; | |
3734 | } | |
3735 | } | |
3736 | ||
3737 | aCS->SetTitle (theArgVec[anArgIter + 1]); | |
3738 | if (isTwoArgs) | |
3739 | { | |
3740 | anArgIter += 1; | |
3741 | } | |
3742 | anArgIter += 1; | |
3743 | } | |
3744 | else if (aFlag == "-demoversion" | |
3745 | || aFlag == "-demo") | |
3746 | { | |
3747 | aPos.SetCoord (0.0, 0.0); | |
3748 | aTextHeight = 16; | |
3749 | aMinRange = 0.0; | |
3750 | aMaxRange = 100; | |
3751 | aNbIntervals = 10; | |
3752 | aLabPosition = Aspect_TOCSP_RIGHT; | |
3753 | aCS->SetColorType(Aspect_TOCSD_AUTO); | |
3754 | aCS->SetLabelType(Aspect_TOCSD_AUTO); | |
3755 | } | |
3756 | else | |
3757 | { | |
3758 | std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n"; | |
3759 | return 1; | |
3760 | } | |
3761 | } | |
3762 | ||
3763 | aCS->SetPosition (aPos.X(), aPos.Y()); | |
3764 | aCS->SetHeight (0.95); | |
3765 | aCS->SetTextHeight (aTextHeight); | |
3766 | aCS->SetRange (aMinRange, aMaxRange); | |
3767 | aCS->SetNumberOfIntervals (aNbIntervals); | |
3768 | aCS->SetLabelPosition (aLabPosition); | |
3769 | ||
3770 | if (!aView->ColorScaleIsDisplayed()) | |
3771 | { | |
3772 | aView->ColorScaleDisplay(); | |
3773 | } | |
3774 | ||
7fd59977 | 3775 | return 0; |
3776 | } | |
3777 | ||
3778 | //============================================================================== | |
3779 | //function : VGraduatedTrihedron | |
a79f67f8 | 3780 | //purpose : Displays or hides a graduated trihedron |
7fd59977 | 3781 | //============================================================================== |
a79f67f8 | 3782 | static Standard_Boolean GetColor (const TCollection_AsciiString& theValue, |
3783 | Quantity_Color& theColor) | |
13a22457 | 3784 | { |
a79f67f8 | 3785 | Quantity_NameOfColor aColorName; |
3786 | TCollection_AsciiString aVal = theValue; | |
3787 | aVal.UpperCase(); | |
3788 | if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName)) | |
13a22457 | 3789 | { |
a79f67f8 | 3790 | return Standard_False; |
13a22457 | 3791 | } |
a79f67f8 | 3792 | theColor = Quantity_Color (aColorName); |
3793 | return Standard_True; | |
13a22457 S |
3794 | } |
3795 | ||
a79f67f8 | 3796 | static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs) |
7fd59977 | 3797 | { |
a79f67f8 | 3798 | if (theArgNum < 2) |
13a22457 | 3799 | { |
a79f67f8 | 3800 | std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help" |
3801 | << theArgs[0] <<"' for more information.\n"; | |
3802 | return 1; //TCL_ERROR | |
13a22457 | 3803 | } |
7fd59977 | 3804 | |
a79f67f8 | 3805 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs; |
3806 | TCollection_AsciiString aParseKey; | |
3807 | for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt) | |
3808 | { | |
3809 | TCollection_AsciiString anArg (theArgs [anArgIt]); | |
3810 | ||
3811 | if (anArg.Value (1) == '-' && !anArg.IsRealValue()) | |
3812 | { | |
3813 | aParseKey = anArg; | |
3814 | aParseKey.Remove (1); | |
3815 | aParseKey.LowerCase(); | |
3816 | aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString); | |
3817 | continue; | |
3818 | } | |
13a22457 | 3819 | |
a79f67f8 | 3820 | if (aParseKey.IsEmpty()) |
3821 | { | |
3822 | continue; | |
3823 | } | |
3824 | ||
3825 | aMapOfArgs(aParseKey)->Append (anArg); | |
3826 | } | |
3827 | ||
3828 | // Check parameters | |
3829 | for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs); | |
3830 | aMapIt.More(); aMapIt.Next()) | |
7fd59977 | 3831 | { |
a79f67f8 | 3832 | const TCollection_AsciiString& aKey = aMapIt.Key(); |
3833 | const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value(); | |
3834 | ||
3835 | // Bool key, without arguments | |
3836 | if ((aKey.IsEqual ("on") || aKey.IsEqual ("off")) | |
3837 | && anArgs->IsEmpty()) | |
3838 | { | |
3839 | continue; | |
3840 | } | |
3841 | ||
3842 | // One argument | |
3843 | if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname")) | |
3844 | && anArgs->Length() == 1) | |
3845 | { | |
3846 | continue; | |
3847 | } | |
3848 | ||
3849 | // On/off arguments | |
3850 | if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname") | |
3851 | || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks") | |
536d98e2 | 3852 | || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues") |
3853 | || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes")) | |
a79f67f8 | 3854 | && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off"))) |
3855 | { | |
3856 | continue; | |
3857 | } | |
3858 | ||
3859 | // One string argument | |
3860 | if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor") | |
3861 | || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor")) | |
3862 | && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue()) | |
3863 | { | |
3864 | continue; | |
3865 | } | |
3866 | ||
3867 | // One integer argument | |
3868 | if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks") | |
3869 | || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength") | |
3870 | || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset") | |
3871 | || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset")) | |
3872 | && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue()) | |
3873 | { | |
3874 | continue; | |
3875 | } | |
3876 | ||
3877 | // One real argument | |
3878 | if ( aKey.IsEqual ("arrowlength") | |
3879 | && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue())) | |
3880 | { | |
3881 | continue; | |
3882 | } | |
3883 | ||
3884 | // Two string arguments | |
3885 | if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont")) | |
3886 | && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue()) | |
13a22457 | 3887 | { |
a79f67f8 | 3888 | continue; |
13a22457 | 3889 | } |
a79f67f8 | 3890 | |
3891 | TCollection_AsciiString aLowerKey; | |
3892 | aLowerKey = "-"; | |
3893 | aLowerKey += aKey; | |
3894 | aLowerKey.LowerCase(); | |
3895 | std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n"; | |
3896 | std::cout << "Type help for more information.\n"; | |
3897 | return 1; | |
7fd59977 | 3898 | } |
3899 | ||
a79f67f8 | 3900 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); |
3901 | if (anAISContext.IsNull()) | |
3902 | { | |
3903 | std::cout << theArgs[0] << ": " << " please use 'vinit' command to initialize view.\n"; | |
3904 | return 1; | |
3905 | } | |
7fd59977 | 3906 | |
a79f67f8 | 3907 | Standard_Boolean toDisplay = Standard_True; |
3908 | Quantity_Color aColor; | |
3909 | Graphic3d_GraduatedTrihedron aTrihedronData; | |
3910 | // Process parameters | |
3911 | Handle(TColStd_HSequenceOfAsciiString) aValues; | |
3912 | if (aMapOfArgs.Find ("off", aValues)) | |
7fd59977 | 3913 | { |
a79f67f8 | 3914 | toDisplay = Standard_False; |
3915 | } | |
13a22457 | 3916 | |
a79f67f8 | 3917 | // AXES NAMES |
3918 | if (aMapOfArgs.Find ("xname", aValues)) | |
3919 | { | |
3920 | aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1)); | |
3921 | } | |
3922 | if (aMapOfArgs.Find ("yname", aValues)) | |
3923 | { | |
3924 | aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1)); | |
3925 | } | |
3926 | if (aMapOfArgs.Find ("zname", aValues)) | |
3927 | { | |
3928 | aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1)); | |
3929 | } | |
3930 | if (aMapOfArgs.Find ("xdrawname", aValues)) | |
3931 | { | |
536d98e2 | 3932 | aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 3933 | } |
3934 | if (aMapOfArgs.Find ("ydrawname", aValues)) | |
3935 | { | |
536d98e2 | 3936 | aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 3937 | } |
3938 | if (aMapOfArgs.Find ("zdrawname", aValues)) | |
3939 | { | |
536d98e2 | 3940 | aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 3941 | } |
3942 | if (aMapOfArgs.Find ("xnameoffset", aValues)) | |
3943 | { | |
3944 | aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); | |
3945 | } | |
3946 | if (aMapOfArgs.Find ("ynameoffset", aValues)) | |
3947 | { | |
3948 | aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); | |
3949 | } | |
3950 | if (aMapOfArgs.Find ("znameoffset", aValues)) | |
3951 | { | |
3952 | aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); | |
3953 | } | |
13a22457 | 3954 | |
a79f67f8 | 3955 | // COLORS |
3956 | if (aMapOfArgs.Find ("xnamecolor", aValues)) | |
3957 | { | |
3958 | if (!GetColor (aValues->Value(1), aColor)) | |
13a22457 | 3959 | { |
a79f67f8 | 3960 | std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n"; |
3961 | return 1; | |
13a22457 | 3962 | } |
a79f67f8 | 3963 | aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor); |
3964 | } | |
3965 | if (aMapOfArgs.Find ("ynamecolor", aValues)) | |
3966 | { | |
3967 | if (!GetColor (aValues->Value(1), aColor)) | |
13a22457 | 3968 | { |
a79f67f8 | 3969 | std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n"; |
3970 | return 1; | |
3971 | } | |
3972 | aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor); | |
3973 | } | |
3974 | if (aMapOfArgs.Find ("znamecolor", aValues)) | |
3975 | { | |
3976 | if (!GetColor (aValues->Value(1), aColor)) | |
3977 | { | |
3978 | std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n"; | |
3979 | return 1; | |
3980 | } | |
3981 | aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor); | |
3982 | } | |
3983 | if (aMapOfArgs.Find ("xcolor", aValues)) | |
3984 | { | |
3985 | if (!GetColor (aValues->Value(1), aColor)) | |
3986 | { | |
3987 | std::cout << theArgs[0] << "error: -xcolor wrong color name.\n"; | |
3988 | return 1; | |
3989 | } | |
3990 | aTrihedronData.ChangeXAxisAspect().SetColor (aColor); | |
3991 | } | |
3992 | if (aMapOfArgs.Find ("ycolor", aValues)) | |
3993 | { | |
3994 | if (!GetColor (aValues->Value(1), aColor)) | |
3995 | { | |
3996 | std::cout << theArgs[0] << "error: -ycolor wrong color name.\n"; | |
3997 | return 1; | |
3998 | } | |
3999 | aTrihedronData.ChangeYAxisAspect().SetColor (aColor); | |
4000 | } | |
4001 | if (aMapOfArgs.Find ("zcolor", aValues)) | |
4002 | { | |
4003 | if (!GetColor (aValues->Value(1), aColor)) | |
4004 | { | |
4005 | std::cout << theArgs[0] << "error: -zcolor wrong color name.\n"; | |
4006 | return 1; | |
4007 | } | |
4008 | aTrihedronData.ChangeZAxisAspect().SetColor (aColor); | |
4009 | } | |
4010 | ||
4011 | // TICKMARKS | |
4012 | if (aMapOfArgs.Find ("xticks", aValues)) | |
4013 | { | |
536d98e2 | 4014 | aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4015 | } |
4016 | if (aMapOfArgs.Find ("yticks", aValues)) | |
4017 | { | |
536d98e2 | 4018 | aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4019 | } |
4020 | if (aMapOfArgs.Find ("zticks", aValues)) | |
4021 | { | |
536d98e2 | 4022 | aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4023 | } |
4024 | if (aMapOfArgs.Find ("xticklength", aValues)) | |
4025 | { | |
536d98e2 | 4026 | aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4027 | } |
4028 | if (aMapOfArgs.Find ("yticklength", aValues)) | |
4029 | { | |
536d98e2 | 4030 | aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4031 | } |
4032 | if (aMapOfArgs.Find ("zticklength", aValues)) | |
4033 | { | |
536d98e2 | 4034 | aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4035 | } |
4036 | if (aMapOfArgs.Find ("xdrawticks", aValues)) | |
4037 | { | |
536d98e2 | 4038 | aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4039 | } |
4040 | if (aMapOfArgs.Find ("ydrawticks", aValues)) | |
4041 | { | |
536d98e2 | 4042 | aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4043 | } |
4044 | if (aMapOfArgs.Find ("zdrawticks", aValues)) | |
4045 | { | |
536d98e2 | 4046 | aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4047 | } |
4048 | ||
4049 | // VALUES | |
4050 | if (aMapOfArgs.Find ("xdrawvalues", aValues)) | |
4051 | { | |
536d98e2 | 4052 | aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4053 | } |
4054 | if (aMapOfArgs.Find ("ydrawvalues", aValues)) | |
4055 | { | |
536d98e2 | 4056 | aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4057 | } |
4058 | if (aMapOfArgs.Find ("zdrawvalues", aValues)) | |
4059 | { | |
536d98e2 | 4060 | aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4061 | } |
4062 | if (aMapOfArgs.Find ("xvaluesoffset", aValues)) | |
4063 | { | |
4064 | aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); | |
4065 | } | |
4066 | if (aMapOfArgs.Find ("yvaluesoffset", aValues)) | |
4067 | { | |
4068 | aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); | |
4069 | } | |
4070 | if (aMapOfArgs.Find ("zvaluesoffset", aValues)) | |
4071 | { | |
4072 | aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); | |
4073 | } | |
4074 | ||
4075 | // ARROWS | |
4076 | if (aMapOfArgs.Find ("arrowlength", aValues)) | |
4077 | { | |
536d98e2 | 4078 | aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue()); |
a79f67f8 | 4079 | } |
4080 | ||
4081 | // FONTS | |
4082 | if (aMapOfArgs.Find ("namefont", aValues)) | |
4083 | { | |
4084 | aTrihedronData.SetNamesFont (aValues->Value(1)); | |
4085 | } | |
4086 | if (aMapOfArgs.Find ("valuesfont", aValues)) | |
4087 | { | |
4088 | aTrihedronData.SetValuesFont (aValues->Value(1)); | |
4089 | } | |
4090 | ||
536d98e2 | 4091 | if (aMapOfArgs.Find ("drawgrid", aValues)) |
4092 | { | |
4093 | aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on")); | |
4094 | } | |
4095 | if (aMapOfArgs.Find ("drawaxes", aValues)) | |
4096 | { | |
4097 | aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on")); | |
4098 | } | |
4099 | ||
a79f67f8 | 4100 | // The final step: display of erase trihedron |
4101 | if (toDisplay) | |
4102 | { | |
4103 | ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData); | |
13a22457 | 4104 | } |
7fd59977 | 4105 | else |
a79f67f8 | 4106 | { |
4107 | ViewerTest::CurrentView()->GraduatedTrihedronErase(); | |
4108 | } | |
7fd59977 | 4109 | |
4110 | ViewerTest::GetAISContext()->UpdateCurrentViewer(); | |
a79f67f8 | 4111 | ViewerTest::CurrentView()->Redraw(); |
13a22457 | 4112 | |
7fd59977 | 4113 | return 0; |
4114 | } | |
4115 | ||
7edf74fd A |
4116 | //============================================================================== |
4117 | //function : VPrintView | |
4118 | //purpose : Test printing algorithm, print the view to image file with given | |
4119 | // width and height. Printing implemented only for WNT. | |
4120 | //============================================================================== | |
4fe56619 | 4121 | static int VPrintView (Draw_Interpretor& di, Standard_Integer argc, |
7edf74fd A |
4122 | const char** argv) |
4123 | { | |
4124 | #ifndef WNT | |
4125 | di << "Printing implemented only for wnt!\n"; | |
b5ac8292 | 4126 | return 0; |
7edf74fd A |
4127 | #else |
4128 | ||
4129 | Handle(AIS_InteractiveContext) aContextAIS = NULL; | |
4130 | Handle(V3d_View) aView = NULL; | |
4131 | aContextAIS = ViewerTest::GetAISContext(); | |
4132 | if (!aContextAIS.IsNull()) | |
4133 | { | |
4134 | const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer(); | |
4135 | Vwr->InitActiveViews(); | |
4136 | if(Vwr->MoreActiveViews()) | |
4137 | aView = Vwr->ActiveView(); | |
4138 | } | |
4139 | ||
4140 | // check for errors | |
4141 | if (aView.IsNull()) | |
4142 | { | |
4143 | di << "Call vinit before!\n"; | |
4144 | return 1; | |
4145 | } | |
4146 | else if (argc < 4) | |
4147 | { | |
4148 | di << "Use: " << argv[0]; | |
b5ac8292 | 4149 | di << " width height filename [print algo=0] [tile_width tile_height]\n"; |
7edf74fd A |
4150 | di << "width, height of the intermediate buffer for operation\n"; |
4151 | di << "algo : {0|1}\n"; | |
4152 | di << " 0 - stretch algorithm\n"; | |
4153 | di << " 1 - tile algorithm\n"; | |
4154 | di << "test printing algorithms into an intermediate buffer\n"; | |
b5ac8292 | 4155 | di << "using specific tile size if provided\n"; |
7edf74fd A |
4156 | di << "with saving output to an image file\n"; |
4157 | return 1; | |
4158 | } | |
4159 | ||
4160 | // get the input params | |
91322f44 | 4161 | Standard_Integer aWidth = Draw::Atoi (argv[1]); |
4162 | Standard_Integer aHeight = Draw::Atoi (argv[2]); | |
7edf74fd A |
4163 | Standard_Integer aMode = 0; |
4164 | TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]); | |
b5ac8292 | 4165 | if (argc >= 5) |
91322f44 | 4166 | aMode = Draw::Atoi (argv[4]); |
7edf74fd | 4167 | |
b5ac8292 | 4168 | Standard_Integer aTileWidth = 0; |
4169 | Standard_Integer aTileHeight = 0; | |
4170 | Standard_Boolean isTileSizeProvided = Standard_False; | |
4171 | if (argc == 7) | |
4172 | { | |
4173 | isTileSizeProvided = Standard_True; | |
4174 | aTileWidth = Draw::Atoi (argv[5]); | |
4175 | aTileHeight = Draw::Atoi (argv[6]); | |
4176 | } | |
4177 | ||
7edf74fd A |
4178 | // check the input parameters |
4179 | if (aWidth <= 0 || aHeight <= 0) | |
4180 | { | |
4181 | di << "Width and height must be positive values!\n"; | |
4182 | return 1; | |
4183 | } | |
4184 | if (aMode != 0 && aMode != 1) | |
4185 | aMode = 0; | |
4186 | ||
7edf74fd | 4187 | // define compatible bitmap |
692613e5 | 4188 | HDC anDC = CreateCompatibleDC(0); |
7edf74fd A |
4189 | BITMAPINFO aBitmapData; |
4190 | memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER)); | |
4191 | aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); | |
4192 | aBitmapData.bmiHeader.biWidth = aWidth ; | |
4193 | aBitmapData.bmiHeader.biHeight = aHeight; | |
4194 | aBitmapData.bmiHeader.biPlanes = 1; | |
4195 | aBitmapData.bmiHeader.biBitCount = 24; | |
4196 | aBitmapData.bmiHeader.biXPelsPerMeter = 0; | |
4197 | aBitmapData.bmiHeader.biYPelsPerMeter = 0; | |
4198 | aBitmapData.bmiHeader.biClrUsed = 0; | |
4199 | aBitmapData.bmiHeader.biClrImportant = 0; | |
4200 | aBitmapData.bmiHeader.biCompression = BI_RGB; | |
4201 | aBitmapData.bmiHeader.biSizeImage = 0; | |
4202 | ||
4203 | // Create Device Independent Bitmap | |
692613e5 | 4204 | void* aBitsOut = NULL; |
7edf74fd | 4205 | HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS, |
692613e5 | 4206 | &aBitsOut, NULL, 0); |
7edf74fd A |
4207 | HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap); |
4208 | ||
4209 | Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False; | |
692613e5 | 4210 | if (aBitsOut != NULL) |
4fe56619 | 4211 | { |
7edf74fd A |
4212 | if (aMode == 0) |
4213 | isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH); | |
4214 | else | |
b5ac8292 | 4215 | { |
4216 | if (isTileSizeProvided) | |
4217 | { | |
4218 | Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView()); | |
4219 | Graphic3d_PtrFrameBuffer anOldBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO); | |
4220 | aCView->ptrFBO = aView->View()->FBOCreate (aTileWidth, aTileHeight); | |
4221 | ||
4222 | isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE); | |
4223 | ||
4224 | Graphic3d_PtrFrameBuffer aNewBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO); | |
4225 | aView->View()->FBORelease (aNewBuffer); | |
4226 | aCView->ptrFBO = anOldBuffer; | |
4227 | } | |
4228 | else | |
4229 | { | |
4230 | isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE); | |
4231 | } | |
4232 | } | |
7edf74fd A |
4233 | |
4234 | // succesfully printed into an intermediate buffer | |
4235 | if (isPrinted) | |
4236 | { | |
692613e5 | 4237 | Image_PixMap aWrapper; |
4238 | aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4); | |
4239 | aWrapper.SetTopDown (false); | |
4240 | ||
4241 | Image_AlienPixMap anImageBitmap; | |
4242 | anImageBitmap.InitCopy (aWrapper); | |
4243 | isSaved = anImageBitmap.Save (aFileName); | |
7edf74fd A |
4244 | } |
4245 | else | |
4246 | { | |
4247 | di << "Print operation failed due to printing errors or\n"; | |
4248 | di << "insufficient memory available\n"; | |
4249 | di << "Please, try to use smaller dimensions for this test\n"; | |
4250 | di << "command, as it allocates intermediate buffer for storing\n"; | |
4251 | di << "the result\n"; | |
4252 | } | |
4253 | } | |
4254 | else | |
4255 | { | |
4256 | di << "Can't allocate memory for intermediate buffer\n"; | |
4257 | di << "Please use smaller dimensions\n"; | |
4258 | } | |
4259 | ||
4260 | if (aMemoryBitmap) | |
4261 | { | |
4262 | SelectObject (anDC, anOldBitmap); | |
4263 | DeleteObject (aMemoryBitmap); | |
4264 | DeleteDC(anDC); | |
4265 | } | |
4266 | ||
4267 | if (!isSaved) | |
4268 | { | |
4269 | di << "Save to file operation failed. This operation may fail\n"; | |
4270 | di << "if you don't have enough available memory, then you can\n"; | |
4271 | di << "use smaller dimensions for the output file\n"; | |
4272 | return 1; | |
4273 | } | |
4274 | ||
4275 | return 0; | |
4276 | ||
4277 | #endif | |
4278 | } | |
4279 | ||
59f45b7c | 4280 | //============================================================================== |
4281 | //function : VZLayer | |
4282 | //purpose : Test z layer operations for v3d viewer | |
4283 | //============================================================================== | |
4284 | static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
4285 | { | |
4286 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext (); | |
4287 | if (aContextAIS.IsNull()) | |
4288 | { | |
4289 | di << "Call vinit before!\n"; | |
4290 | return 1; | |
4291 | } | |
4292 | else if (argc < 2) | |
4293 | { | |
c5751993 | 4294 | di << "Use: vzlayer "; |
4295 | di << " add/del/get/settings/enable/disable [id]\n"; | |
59f45b7c | 4296 | di << " add - add new z layer to viewer and print its id\n"; |
4297 | di << " del - del z layer by its id\n"; | |
4298 | di << " get - print sequence of z layers in increasing order of their overlay level\n"; | |
c5751993 | 4299 | di << " settings - print status of z layer settings\n"; |
4300 | di << " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n"; | |
4301 | di << " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n"; | |
4302 | di << " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n"; | |
4303 | di << "\nWhere id is the layer identificator\n"; | |
4304 | di << "\nExamples:\n"; | |
4305 | di << " vzlayer add\n"; | |
4306 | di << " vzlayer enable poffset 1\n"; | |
4307 | di << " vzlayer disable depthtest 1\n"; | |
4308 | di << " vzlayer del 1\n"; | |
59f45b7c | 4309 | return 1; |
4310 | } | |
4311 | ||
4312 | const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer(); | |
4313 | if (aViewer.IsNull()) | |
4314 | { | |
4315 | di << "No active viewer!\n"; | |
4316 | return 1; | |
4317 | } | |
4318 | ||
4319 | // perform operation | |
4320 | TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]); | |
4321 | if (anOp == "add") | |
4322 | { | |
4323 | Standard_Integer aNewId; | |
4324 | if (!aViewer->AddZLayer (aNewId)) | |
4325 | { | |
4326 | di << "Impossible to add new z layer!\n"; | |
4327 | return 1; | |
4328 | } | |
4329 | ||
4330 | di << "New z layer added with index: " << aNewId << "\n"; | |
4331 | } | |
4332 | else if (anOp == "del") | |
4333 | { | |
4334 | if (argc < 3) | |
4335 | { | |
4336 | di << "Please also provide as argument id of z layer to remove\n"; | |
4337 | return 1; | |
4338 | } | |
4339 | ||
91322f44 | 4340 | Standard_Integer aDelId = Draw::Atoi (argv[2]); |
59f45b7c | 4341 | if (!aViewer->RemoveZLayer (aDelId)) |
4342 | { | |
4343 | di << "Impossible to remove the z layer or invalid id!\n"; | |
4344 | return 1; | |
4345 | } | |
4346 | ||
a1954302 | 4347 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); |
4348 | anObjIter.More(); anObjIter.Next()) | |
4349 | { | |
4350 | Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1()); | |
4351 | if (aPrs.IsNull() | |
4352 | || aPrs->ZLayer() != aDelId) | |
4353 | { | |
4354 | continue; | |
4355 | } | |
4356 | aPrs->SetZLayer (Graphic3d_ZLayerId_Default); | |
4357 | } | |
4358 | ||
59f45b7c | 4359 | di << "Z layer " << aDelId << " has been removed\n"; |
4360 | } | |
4361 | else if (anOp == "get") | |
4362 | { | |
4363 | TColStd_SequenceOfInteger anIds; | |
4364 | aViewer->GetAllZLayers (anIds); | |
4365 | for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++) | |
4366 | { | |
4367 | di << anIds.Value (aSeqIdx) << " "; | |
4368 | } | |
4369 | ||
4370 | di << "\n"; | |
4371 | } | |
c5751993 | 4372 | else if (anOp == "settings") |
4373 | { | |
4374 | if (argc < 3) | |
4375 | { | |
4376 | di << "Please also provide an id\n"; | |
4377 | return 1; | |
4378 | } | |
4379 | ||
4380 | Standard_Integer anId = Draw::Atoi (argv[2]); | |
4381 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId); | |
4382 | ||
4383 | di << "Depth test - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthTest) ? "enabled" : "disabled") << "\n"; | |
4384 | di << "Depth write - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthWrite) ? "enabled" : "disabled") << "\n"; | |
4385 | di << "Depth buffer clearing - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthClear) ? "enabled" : "disabled") << "\n"; | |
4386 | di << "Depth offset - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthOffset) ? "enabled" : "disabled") << "\n"; | |
4387 | ||
4388 | } | |
4389 | else if (anOp == "enable") | |
4390 | { | |
4391 | if (argc < 3) | |
4392 | { | |
4393 | di << "Please also provide an option to enable\n"; | |
4394 | return 1; | |
4395 | } | |
4396 | ||
4397 | if (argc < 4) | |
4398 | { | |
4399 | di << "Please also provide a layer id\n"; | |
4400 | return 1; | |
4401 | } | |
4402 | ||
4403 | TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]); | |
4404 | Standard_Integer anId = Draw::Atoi (argv[3]); | |
4405 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId); | |
4406 | ||
4407 | if (aSubOp == "depthtest" || aSubOp == "test") | |
4408 | { | |
4409 | aSettings.EnableSetting (Graphic3d_ZLayerDepthTest); | |
4410 | } | |
4411 | else if (aSubOp == "depthwrite" || aSubOp == "write") | |
4412 | { | |
4413 | aSettings.EnableSetting (Graphic3d_ZLayerDepthWrite); | |
4414 | } | |
4415 | else if (aSubOp == "depthclear" || aSubOp == "clear") | |
4416 | { | |
4417 | aSettings.EnableSetting (Graphic3d_ZLayerDepthClear); | |
4418 | } | |
4419 | else if (aSubOp == "depthoffset" || aSubOp == "offset") | |
4420 | { | |
4421 | if (argc < 6) | |
4422 | { | |
4423 | di << "Please also provide a factor and units values for depth offset\n"; | |
4424 | di << "Format is: vzlayer enable offset [factor] [units] [layerId]\n"; | |
4425 | return 1; | |
4426 | } | |
4427 | ||
4428 | Standard_ShortReal aFactor = static_cast<Standard_ShortReal> (Draw::Atof (argv[3])); | |
4429 | Standard_ShortReal aUnits = static_cast<Standard_ShortReal> (Draw::Atof (argv[4])); | |
4430 | anId = Draw::Atoi (argv[5]); | |
4431 | aSettings = aViewer->ZLayerSettings (anId); | |
4432 | ||
4433 | aSettings.DepthOffsetFactor = aFactor; | |
4434 | aSettings.DepthOffsetUnits = aUnits; | |
4435 | ||
4436 | aSettings.EnableSetting (Graphic3d_ZLayerDepthOffset); | |
4437 | } | |
4438 | else if (aSubOp == "positiveoffset" || aSubOp == "poffset") | |
4439 | { | |
4440 | aSettings.SetDepthOffsetPositive(); | |
4441 | } | |
4442 | else if (aSubOp == "negativeoffset" || aSubOp == "noffset") | |
4443 | { | |
4444 | aSettings.SetDepthOffsetNegative(); | |
4445 | } | |
4446 | ||
4447 | aViewer->SetZLayerSettings (anId, aSettings); | |
4448 | } | |
4449 | else if (anOp == "disable") | |
4450 | { | |
4451 | if (argc < 3) | |
4452 | { | |
4453 | di << "Please also provide an option to disable\n"; | |
4454 | return 1; | |
4455 | } | |
4456 | ||
4457 | if (argc < 4) | |
4458 | { | |
4459 | di << "Please also provide a layer id\n"; | |
4460 | return 1; | |
4461 | } | |
4462 | ||
4463 | TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]); | |
4464 | Standard_Integer anId = Draw::Atoi (argv[3]); | |
4465 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId); | |
4466 | ||
4467 | if (aSubOp == "depthtest" || aSubOp == "test") | |
4468 | { | |
4469 | aSettings.DisableSetting (Graphic3d_ZLayerDepthTest); | |
4470 | } | |
4471 | else if (aSubOp == "depthwrite" || aSubOp == "write") | |
4472 | { | |
4473 | aSettings.DisableSetting (Graphic3d_ZLayerDepthWrite); | |
4474 | } | |
4475 | else if (aSubOp == "depthclear" || aSubOp == "clear") | |
4476 | { | |
4477 | aSettings.DisableSetting (Graphic3d_ZLayerDepthClear); | |
4478 | } | |
4479 | else if (aSubOp == "depthoffset" || aSubOp == "offset") | |
4480 | { | |
4481 | aSettings.DisableSetting (Graphic3d_ZLayerDepthOffset); | |
4482 | } | |
4483 | ||
4484 | aViewer->SetZLayerSettings (anId, aSettings); | |
4485 | } | |
59f45b7c | 4486 | else |
4487 | { | |
c5751993 | 4488 | di << "Invalid operation, please use { add / del / get / settings / enable / disable}\n"; |
59f45b7c | 4489 | return 1; |
4490 | } | |
4491 | ||
4492 | return 0; | |
4493 | } | |
4494 | ||
25289ec1 | 4495 | DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem) |
4496 | ||
4497 | // this class provides a presentation of text item in v3d view under-/overlayer | |
4498 | class V3d_TextItem : public Visual3d_LayerItem | |
4499 | { | |
4500 | public: | |
4501 | ||
4502 | // CASCADE RTTI | |
4503 | DEFINE_STANDARD_RTTI(V3d_TextItem) | |
4504 | ||
4505 | // constructor | |
4506 | Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText, | |
4507 | const Standard_Real theX1, | |
4508 | const Standard_Real theY1, | |
4509 | const Standard_Real theHeight, | |
4510 | const TCollection_AsciiString& theFontName, | |
4511 | const Quantity_Color& theColor, | |
4512 | const Quantity_Color& theSubtitleColor, | |
4513 | const Aspect_TypeOfDisplayText& theTypeOfDisplay, | |
4514 | const Handle(Visual3d_Layer)& theLayer); | |
4515 | ||
4516 | // redraw method | |
4517 | Standard_EXPORT void RedrawLayerPrs(); | |
4518 | ||
4519 | private: | |
4520 | ||
4521 | Standard_Real myX1; | |
4522 | Standard_Real myY1; | |
25289ec1 | 4523 | TCollection_AsciiString myText; |
eafb234b | 4524 | Standard_Real myHeight; |
4525 | Handle(Visual3d_Layer) myLayer; | |
25289ec1 | 4526 | Quantity_Color myColor; |
4527 | Quantity_Color mySubtitleColor; | |
4528 | Aspect_TypeOfDisplayText myType; | |
eafb234b | 4529 | TCollection_AsciiString myFontName; |
25289ec1 | 4530 | }; |
4531 | ||
4532 | IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem) | |
4533 | IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem) | |
4534 | ||
4535 | // create and add to display the text item | |
4536 | V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText, | |
4537 | const Standard_Real theX1, | |
4538 | const Standard_Real theY1, | |
4539 | const Standard_Real theHeight, | |
4540 | const TCollection_AsciiString& theFontName, | |
4541 | const Quantity_Color& theColor, | |
4542 | const Quantity_Color& theSubtitleColor, | |
4543 | const Aspect_TypeOfDisplayText& theTypeOfDisplay, | |
4544 | const Handle(Visual3d_Layer)& theLayer) | |
4545 | : myX1 (theX1), myY1 (theY1), | |
4546 | myText (theText), | |
4547 | myHeight (theHeight), | |
4548 | myLayer (theLayer), | |
4549 | myColor (theColor), | |
4550 | mySubtitleColor (theSubtitleColor), | |
4551 | myType (theTypeOfDisplay), | |
4552 | myFontName (theFontName) | |
4553 | { | |
4554 | if (!myLayer.IsNull ()) | |
4555 | myLayer->AddLayerItem (this); | |
4556 | } | |
4557 | ||
4558 | // render item | |
4559 | void V3d_TextItem::RedrawLayerPrs () | |
4fe56619 | 4560 | { |
25289ec1 | 4561 | if (myLayer.IsNull ()) |
4562 | return; | |
4563 | ||
4564 | myLayer->SetColor (myColor); | |
4565 | myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor); | |
4566 | myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight); | |
4567 | } | |
4568 | ||
20637bd2 | 4569 | DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem) |
4570 | ||
4571 | // The Visual3d_LayerItem line item for "vlayerline" command | |
4fe56619 | 4572 | // it provides a presentation of line with user-defined |
20637bd2 | 4573 | // linewidth, linetype and transparency. |
4fe56619 | 4574 | class V3d_LineItem : public Visual3d_LayerItem |
20637bd2 | 4575 | { |
4576 | public: | |
4577 | // CASCADE RTTI | |
4fe56619 | 4578 | DEFINE_STANDARD_RTTI(V3d_LineItem) |
4579 | ||
20637bd2 | 4580 | // constructor |
4581 | Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1, | |
4582 | Standard_Real X2, Standard_Real Y2, | |
4583 | V3d_LayerMgrPointer theLayerMgr, | |
4584 | Aspect_TypeOfLine theType = Aspect_TOL_SOLID, | |
4585 | Standard_Real theWidth = 0.5, | |
4586 | Standard_Real theTransp = 1.0); | |
4587 | ||
4588 | // redraw method | |
4589 | Standard_EXPORT void RedrawLayerPrs(); | |
4590 | ||
4591 | private: | |
4592 | ||
4593 | Standard_Real myX1, myY1, myX2, myY2; | |
eafb234b | 4594 | V3d_LayerMgrPointer myLayerMgr; |
4595 | Aspect_TypeOfLine myType; | |
20637bd2 | 4596 | Standard_Real myWidth; |
4597 | Standard_Real myTransparency; | |
20637bd2 | 4598 | }; |
4599 | ||
4600 | IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem) | |
4601 | IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem) | |
4602 | ||
4603 | // default constructor for line item | |
4fe56619 | 4604 | V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1, |
20637bd2 | 4605 | Standard_Real X2, Standard_Real Y2, |
4606 | V3d_LayerMgrPointer theLayerMgr, | |
4607 | Aspect_TypeOfLine theType, | |
4608 | Standard_Real theWidth, | |
4609 | Standard_Real theTransp) : | |
4610 | myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr), | |
4611 | myType(theType), myWidth(theWidth), myTransparency(theTransp) | |
4612 | { | |
9e4c2fbb | 4613 | if (myLayerMgr && !myLayerMgr->Overlay().IsNull()) |
20637bd2 | 4614 | myLayerMgr->Overlay()->AddLayerItem (this); |
4615 | } | |
4616 | ||
4617 | // render line | |
4618 | void V3d_LineItem::RedrawLayerPrs () | |
4619 | { | |
4620 | Handle (Visual3d_Layer) aOverlay; | |
4fe56619 | 4621 | |
20637bd2 | 4622 | if (myLayerMgr) |
4623 | aOverlay = myLayerMgr->Overlay(); | |
4624 | ||
4625 | if (!aOverlay.IsNull()) | |
4626 | { | |
4627 | Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB); | |
4628 | aOverlay->SetColor(aColor); | |
4629 | aOverlay->SetTransparency((Standard_ShortReal)myTransparency); | |
4630 | aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth); | |
4631 | aOverlay->BeginPolyline(); | |
4632 | aOverlay->AddVertex(myX1, myY1); | |
4633 | aOverlay->AddVertex(myX2, myY2); | |
4634 | aOverlay->ClosePrimitive(); | |
4635 | } | |
4636 | } | |
4637 | ||
4638 | //============================================================================= | |
4639 | //function : VLayerLine | |
4640 | //purpose : Draws line in the v3d view layer with given attributes: linetype, | |
4641 | // : linewidth, transparency coefficient | |
4642 | //============================================================================ | |
4643 | static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
4644 | { | |
4645 | // get the active view | |
4646 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4647 | if (aView.IsNull()) | |
4648 | { | |
4649 | di << "Call vinit before!\n"; | |
4650 | return 1; | |
4651 | } | |
4652 | else if (argc < 5) | |
4653 | { | |
4654 | di << "Use: " << argv[0]; | |
4655 | di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n"; | |
4656 | di << " linetype : { 0 | 1 | 2 | 3 } \n"; | |
4657 | di << " 0 - solid \n"; | |
4658 | di << " 1 - dashed \n"; | |
4659 | di << " 2 - dot \n"; | |
4660 | di << " 3 - dashdot\n"; | |
4661 | di << " transparency : { 0.0 - 1.0 } \n"; | |
4662 | di << " 0.0 - transparent\n"; | |
4663 | di << " 1.0 - visible \n"; | |
4664 | return 1; | |
4665 | } | |
4666 | ||
4667 | // get the input params | |
91322f44 | 4668 | Standard_Real X1 = Draw::Atof(argv[1]); |
4669 | Standard_Real Y1 = Draw::Atof(argv[2]); | |
4670 | Standard_Real X2 = Draw::Atof(argv[3]); | |
4671 | Standard_Real Y2 = Draw::Atof(argv[4]); | |
20637bd2 | 4672 | |
4673 | Standard_Real aWidth = 0.5; | |
4674 | Standard_Integer aType = 0; | |
4675 | Standard_Real aTransparency = 1.0; | |
4676 | ||
4677 | // has width | |
4678 | if (argc > 5) | |
91322f44 | 4679 | aWidth = Draw::Atof(argv[5]); |
20637bd2 | 4680 | |
4681 | // has type | |
4682 | if (argc > 6) | |
91322f44 | 4683 | aType = (Standard_Integer) Draw::Atoi(argv[6]); |
20637bd2 | 4684 | |
4685 | // has transparency | |
4686 | if (argc > 7) | |
4687 | { | |
91322f44 | 4688 | aTransparency = Draw::Atof(argv[7]); |
4fe56619 | 4689 | if (aTransparency < 0 || aTransparency > 1.0) |
20637bd2 | 4690 | aTransparency = 1.0; |
4691 | } | |
4692 | ||
4693 | // select appropriate line type | |
4694 | Aspect_TypeOfLine aLineType; | |
4695 | switch (aType) | |
4696 | { | |
4697 | case 1: | |
4698 | aLineType = Aspect_TOL_DASH; | |
4699 | break; | |
4700 | ||
4701 | case 2: | |
4702 | aLineType = Aspect_TOL_DOT; | |
4703 | break; | |
4704 | ||
4705 | case 3: | |
4706 | aLineType = Aspect_TOL_DOTDASH; | |
4707 | break; | |
4708 | ||
4709 | default: | |
4710 | aLineType = Aspect_TOL_SOLID; | |
4711 | } | |
4712 | ||
4713 | // replace layer manager | |
4714 | Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView); | |
4715 | aView->SetLayerMgr(aMgr); | |
4716 | ||
4717 | // add line item | |
4fe56619 | 4718 | Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2, |
20637bd2 | 4719 | aMgr.operator->(), |
4fe56619 | 4720 | aLineType, aWidth, |
20637bd2 | 4721 | aTransparency); |
4722 | ||
4723 | // update view | |
4724 | aView->MustBeResized(); | |
4725 | aView->Redraw(); | |
4726 | ||
4727 | return 0; | |
4728 | } | |
4729 | ||
25289ec1 | 4730 | //======================================================================= |
4731 | //function : VOverlayText | |
4732 | //purpose : Test text displaying in view overlay | |
4733 | //======================================================================= | |
4734 | static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv) | |
4735 | { | |
4736 | // get the active view | |
4737 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4738 | if (aView.IsNull()) | |
4739 | { | |
4740 | di << "No active view. Please call vinit.\n"; | |
4741 | return 1; | |
4742 | } | |
4743 | else if (argc < 4 || argc > 13) | |
4744 | { | |
4745 | di << "Use: " << argv[0]; | |
4746 | di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n"; | |
4747 | di << "[background_color: R G B]\n"; | |
4748 | di << " height - pixel height of the text (default=10.0)\n"; | |
4749 | di << " font_name - name of font (default=courier)\n"; | |
4750 | di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n"; | |
a6eb515f | 4751 | di << " display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n"; |
25289ec1 | 4752 | di << " background_color- R G B values used for subtitle and decal text\n"; |
4753 | di << "(default=255.0 255.0 255.0)\n"; | |
4754 | return 1; | |
4755 | } | |
4fe56619 | 4756 | |
25289ec1 | 4757 | TCollection_AsciiString aText (argv[1]); |
91322f44 | 4758 | Standard_Real aPosX = Draw::Atof(argv[2]); |
4759 | Standard_Real aPosY = Draw::Atof(argv[3]); | |
4760 | Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0; | |
25289ec1 | 4761 | |
4762 | // font name | |
4763 | TCollection_AsciiString aFontName = "Courier"; | |
4764 | if (argc >= 6) | |
4765 | aFontName = TCollection_AsciiString (argv[5]); | |
4766 | ||
4767 | // text colors | |
4768 | Quantity_Parameter aColorRed = 1.0; | |
4769 | Quantity_Parameter aColorGreen = 1.0; | |
4770 | Quantity_Parameter aColorBlue = 1.0; | |
4771 | if (argc >= 9) | |
4772 | { | |
91322f44 | 4773 | aColorRed = Draw::Atof (argv[6])/255.; |
4774 | aColorGreen = Draw::Atof (argv[7])/255.; | |
4775 | aColorBlue = Draw::Atof (argv[8])/255.; | |
25289ec1 | 4776 | } |
4777 | ||
4778 | // display type | |
4779 | TCollection_AsciiString aDispStr; | |
4780 | if (argc >= 10) | |
4781 | aDispStr = TCollection_AsciiString (argv[9]); | |
4782 | ||
4783 | Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL; | |
4784 | if (aDispStr.IsEqual ("subtitle")) | |
4785 | aTextType = Aspect_TODT_SUBTITLE; | |
4786 | else if (aDispStr.IsEqual ("decal")) | |
4787 | aTextType = Aspect_TODT_DEKALE; | |
4788 | else if (aDispStr.IsEqual ("blend")) | |
4789 | aTextType = Aspect_TODT_BLEND; | |
a6eb515f | 4790 | else if (aDispStr.IsEqual ("dimension")) |
4791 | aTextType = Aspect_TODT_DIMENSION; | |
25289ec1 | 4792 | |
4793 | // subtitle color | |
4794 | Quantity_Parameter aSubRed = 1.0; | |
4795 | Quantity_Parameter aSubGreen = 1.0; | |
4796 | Quantity_Parameter aSubBlue = 1.0; | |
4797 | if (argc == 13) | |
4798 | { | |
91322f44 | 4799 | aSubRed = Draw::Atof (argv[10])/255.; |
4800 | aSubGreen = Draw::Atof (argv[11])/255.; | |
4801 | aSubBlue = Draw::Atof (argv[12])/255.; | |
25289ec1 | 4802 | } |
4803 | ||
4804 | // check fo current overlay | |
4805 | Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer (); | |
4806 | if (anOverlay.IsNull ()) | |
4807 | { | |
4808 | Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView); | |
4809 | anOverlay = aMgr->Overlay (); | |
4810 | aView->SetLayerMgr (aMgr); | |
4811 | } | |
4812 | ||
4fe56619 | 4813 | Quantity_Color aTextColor (aColorRed, aColorGreen, |
25289ec1 | 4814 | aColorBlue, Quantity_TOC_RGB); |
4fe56619 | 4815 | Quantity_Color aSubtColor (aSubRed, aSubGreen, |
25289ec1 | 4816 | aSubBlue, Quantity_TOC_RGB); |
4817 | ||
4818 | // add text item | |
4819 | Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY, | |
4820 | aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay); | |
4821 | ||
4822 | // update view | |
4823 | aView->MustBeResized(); | |
4824 | aView->Redraw(); | |
4825 | ||
4826 | return 0; | |
4827 | } | |
4828 | ||
2bd4c032 | 4829 | //============================================================================== |
4830 | //function : VGrid | |
4831 | //purpose : | |
4832 | //============================================================================== | |
4833 | ||
35e08fe8 | 4834 | static int VGrid (Draw_Interpretor& /*theDI*/, |
2bd4c032 | 4835 | Standard_Integer theArgNb, |
4836 | const char** theArgVec) | |
4837 | { | |
4838 | // get the active view | |
4839 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4840 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
4841 | if (aView.IsNull() || aViewer.IsNull()) | |
4842 | { | |
4843 | std::cerr << "No active view. Please call vinit.\n"; | |
4844 | return 1; | |
4845 | } | |
4846 | ||
4847 | Aspect_GridType aType = aViewer->GridType(); | |
4848 | Aspect_GridDrawMode aMode = aViewer->GridDrawMode(); | |
4849 | ||
4850 | Standard_Integer anIter = 1; | |
4851 | for (; anIter < theArgNb; ++anIter) | |
4852 | { | |
4853 | const char* aValue = theArgVec[anIter]; | |
4854 | if (*aValue == 'r') | |
4855 | { | |
4856 | aType = Aspect_GT_Rectangular; | |
4857 | } | |
4858 | else if (*aValue == 'c') | |
4859 | { | |
4860 | aType = Aspect_GT_Circular; | |
4861 | } | |
4862 | else if (*aValue == 'l') | |
4863 | { | |
4864 | aMode = Aspect_GDM_Lines; | |
4865 | } | |
4866 | else if (*aValue == 'p') | |
4867 | { | |
4868 | aMode = Aspect_GDM_Points; | |
4869 | } | |
4870 | else if (strcmp (aValue, "off" ) == 0) | |
4871 | { | |
4872 | aViewer->DeactivateGrid(); | |
4873 | return 0; | |
4874 | } | |
4875 | else | |
4876 | { | |
4877 | break; | |
4878 | } | |
4879 | } | |
4880 | ||
4881 | Standard_Integer aTail = (theArgNb - anIter); | |
4882 | if (aTail == 0) | |
4883 | { | |
4884 | aViewer->ActivateGrid (aType, aMode); | |
4885 | return 0; | |
4886 | } | |
4887 | else if (aTail != 2 && aTail != 5) | |
4888 | { | |
4889 | std::cerr << "Incorrect arguments number! Usage:\n" | |
4890 | << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n"; | |
4891 | return 1; | |
4892 | } | |
4893 | ||
4894 | Quantity_Length anOriginX, anOriginY; | |
4895 | Quantity_PlaneAngle aRotAngle; | |
4896 | if (aType == Aspect_GT_Rectangular) | |
4897 | { | |
4898 | Quantity_Length aRStepX, aRStepY; | |
4899 | aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle); | |
4900 | ||
91322f44 | 4901 | anOriginX = Draw::Atof (theArgVec[anIter++]); |
4902 | anOriginY = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 4903 | if (aTail == 5) |
4904 | { | |
91322f44 | 4905 | aRStepX = Draw::Atof (theArgVec[anIter++]); |
4906 | aRStepY = Draw::Atof (theArgVec[anIter++]); | |
4907 | aRotAngle = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 4908 | } |
4909 | aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle); | |
4910 | aViewer->ActivateGrid (aType, aMode); | |
4911 | } | |
4912 | else if (aType == Aspect_GT_Circular) | |
4913 | { | |
4914 | Quantity_Length aRadiusStep; | |
4915 | Standard_Integer aDivisionNumber; | |
4916 | aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle); | |
4917 | ||
91322f44 | 4918 | anOriginX = Draw::Atof (theArgVec[anIter++]); |
4919 | anOriginY = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 4920 | if (aTail == 5) |
4921 | { | |
91322f44 | 4922 | aRadiusStep = Draw::Atof (theArgVec[anIter++]); |
4923 | aDivisionNumber = Draw::Atoi (theArgVec[anIter++]); | |
4924 | aRotAngle = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 4925 | } |
4926 | ||
4927 | aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle); | |
4928 | aViewer->ActivateGrid (aType, aMode); | |
4929 | } | |
4930 | ||
4931 | return 0; | |
4932 | } | |
4933 | ||
c40b7d58 | 4934 | //============================================================================== |
4935 | //function : VPriviledgedPlane | |
4936 | //purpose : | |
4937 | //============================================================================== | |
4938 | ||
4939 | static int VPriviledgedPlane (Draw_Interpretor& theDI, | |
4940 | Standard_Integer theArgNb, | |
4941 | const char** theArgVec) | |
4942 | { | |
4943 | if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10) | |
4944 | { | |
4945 | std::cerr << "Error: wrong number of arguments! See usage:\n"; | |
4946 | theDI.PrintHelp (theArgVec[0]); | |
4947 | return 1; | |
4948 | } | |
4949 | ||
4950 | // get the active viewer | |
4951 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
4952 | if (aViewer.IsNull()) | |
4953 | { | |
4954 | std::cerr << "Error: no active viewer. Please call vinit.\n"; | |
4955 | return 1; | |
4956 | } | |
4957 | ||
4958 | if (theArgNb == 1) | |
4959 | { | |
4960 | gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane(); | |
4961 | const gp_Pnt& anOrig = aPriviledgedPlane.Location(); | |
4962 | const gp_Dir& aNorm = aPriviledgedPlane.Direction(); | |
4963 | const gp_Dir& aXDir = aPriviledgedPlane.XDirection(); | |
4964 | theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " " | |
4965 | << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " " | |
4966 | << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n"; | |
4967 | return 0; | |
4968 | } | |
4969 | ||
4970 | Standard_Integer anArgIdx = 1; | |
4971 | Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]); | |
4972 | Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]); | |
4973 | Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]); | |
4974 | Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]); | |
4975 | Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]); | |
4976 | Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]); | |
4977 | ||
4978 | gp_Ax3 aPriviledgedPlane; | |
4979 | gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ); | |
4980 | gp_Dir aNorm (aNormX, aNormY, aNormZ); | |
4981 | if (theArgNb > 7) | |
4982 | { | |
4983 | Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]); | |
4984 | Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]); | |
4985 | Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]); | |
4986 | gp_Dir aXDir (aXDirX, aXDirY, aXDirZ); | |
4987 | aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir); | |
4988 | } | |
4989 | else | |
4990 | { | |
4991 | aPriviledgedPlane = gp_Ax3 (anOrig, aNorm); | |
4992 | } | |
4993 | ||
4994 | aViewer->SetPrivilegedPlane (aPriviledgedPlane); | |
4995 | ||
4996 | return 0; | |
4997 | } | |
4998 | ||
f25b82d6 | 4999 | //============================================================================== |
5000 | //function : VConvert | |
5001 | //purpose : | |
5002 | //============================================================================== | |
5003 | ||
5004 | static int VConvert (Draw_Interpretor& theDI, | |
5005 | Standard_Integer theArgNb, | |
5006 | const char** theArgVec) | |
5007 | { | |
5008 | // get the active view | |
5009 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5010 | if (aView.IsNull()) | |
5011 | { | |
c40b7d58 | 5012 | std::cerr << "Error: no active view. Please call vinit.\n"; |
f25b82d6 | 5013 | return 1; |
5014 | } | |
5015 | ||
5016 | enum { Model, Ray, View, Window, Grid } aMode = Model; | |
5017 | ||
5018 | // access coordinate arguments | |
5019 | TColStd_SequenceOfReal aCoord; | |
5020 | Standard_Integer anArgIdx = 1; | |
5021 | for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx) | |
5022 | { | |
5023 | TCollection_AsciiString anArg (theArgVec[anArgIdx]); | |
5024 | if (!anArg.IsRealValue()) | |
5025 | { | |
5026 | break; | |
5027 | } | |
5028 | aCoord.Append (anArg.RealValue()); | |
5029 | } | |
5030 | ||
5031 | // non-numeric argument too early | |
5032 | if (aCoord.IsEmpty()) | |
5033 | { | |
5034 | std::cerr << "Error: wrong number of arguments! See usage:\n"; | |
5035 | theDI.PrintHelp (theArgVec[0]); | |
5036 | return 1; | |
5037 | } | |
5038 | ||
5039 | // collect all other arguments and options | |
5040 | for (; anArgIdx < theArgNb; ++anArgIdx) | |
5041 | { | |
5042 | TCollection_AsciiString anArg (theArgVec[anArgIdx]); | |
5043 | anArg.LowerCase(); | |
5044 | if (anArg == "window") aMode = Window; | |
5045 | else if (anArg == "view") aMode = View; | |
5046 | else if (anArg == "grid") aMode = Grid; | |
5047 | else if (anArg == "ray") aMode = Ray; | |
5048 | else | |
5049 | { | |
5050 | std::cerr << "Error: wrong argument " << anArg << "! See usage:\n"; | |
5051 | theDI.PrintHelp (theArgVec[0]); | |
5052 | return 1; | |
5053 | } | |
5054 | } | |
5055 | ||
5056 | // complete input checks | |
5057 | if ((aCoord.Length() == 1 && theArgNb > 3) || | |
5058 | (aCoord.Length() == 2 && theArgNb > 4) || | |
5059 | (aCoord.Length() == 3 && theArgNb > 5)) | |
5060 | { | |
5061 | std::cerr << "Error: wrong number of arguments! See usage:\n"; | |
5062 | theDI.PrintHelp (theArgVec[0]); | |
5063 | return 1; | |
5064 | } | |
5065 | ||
5066 | Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; | |
5067 | Standard_Integer aXYp[2] = {0, 0}; | |
5068 | ||
5069 | // convert one-dimensional coordinate | |
5070 | if (aCoord.Length() == 1) | |
5071 | { | |
5072 | switch (aMode) | |
5073 | { | |
5074 | case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer) aCoord (1)); return 0; | |
5075 | case Window : theDI << "Window Vp: " << aView->Convert ((Quantity_Length) aCoord (1)); return 0; | |
5076 | default: | |
5077 | std::cerr << "Error: wrong arguments! See usage:\n"; | |
5078 | theDI.PrintHelp (theArgVec[0]); | |
5079 | return 1; | |
5080 | } | |
5081 | } | |
5082 | ||
5083 | // convert 2D coordinates from projection or view reference space | |
5084 | if (aCoord.Length() == 2) | |
5085 | { | |
5086 | switch (aMode) | |
5087 | { | |
5088 | case Model : | |
5089 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]); | |
5090 | theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n"; | |
5091 | return 0; | |
5092 | ||
5093 | case View : | |
5094 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]); | |
5095 | theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n"; | |
5096 | return 0; | |
5097 | ||
5098 | case Window : | |
5099 | aView->Convert ((V3d_Coordinate) aCoord (1), (V3d_Coordinate) aCoord (2), aXYp[0], aXYp[1]); | |
5100 | theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n"; | |
5101 | return 0; | |
5102 | ||
5103 | case Grid : | |
5104 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]); | |
5105 | aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]); | |
5106 | theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n"; | |
5107 | return 0; | |
5108 | ||
5109 | case Ray : | |
5110 | aView->ConvertWithProj ((Standard_Integer) aCoord (1), | |
5111 | (Standard_Integer) aCoord (2), | |
5112 | aXYZ[0], aXYZ[1], aXYZ[2], | |
5113 | aXYZ[3], aXYZ[4], aXYZ[5]); | |
5114 | theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n"; | |
5115 | return 0; | |
5116 | ||
5117 | default: | |
5118 | std::cerr << "Error: wrong arguments! See usage:\n"; | |
5119 | theDI.PrintHelp (theArgVec[0]); | |
5120 | return 1; | |
5121 | } | |
5122 | } | |
5123 | ||
5124 | // convert 3D coordinates from view reference space | |
5125 | else if (aCoord.Length() == 3) | |
5126 | { | |
5127 | switch (aMode) | |
5128 | { | |
5129 | case Window : | |
5130 | aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]); | |
5131 | theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n"; | |
5132 | return 0; | |
5133 | ||
5134 | case Grid : | |
5135 | aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]); | |
5136 | theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n"; | |
5137 | return 0; | |
5138 | ||
5139 | default: | |
5140 | std::cerr << "Error: wrong arguments! See usage:\n"; | |
5141 | theDI.PrintHelp (theArgVec[0]); | |
5142 | return 1; | |
5143 | } | |
5144 | } | |
5145 | ||
5146 | return 0; | |
5147 | } | |
5148 | ||
208e6839 | 5149 | //============================================================================== |
5150 | //function : VFps | |
5151 | //purpose : | |
5152 | //============================================================================== | |
5153 | ||
5154 | static int VFps (Draw_Interpretor& theDI, | |
5155 | Standard_Integer theArgNb, | |
5156 | const char** theArgVec) | |
5157 | { | |
5158 | // get the active view | |
5159 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5160 | if (aView.IsNull()) | |
5161 | { | |
5162 | std::cerr << "No active view. Please call vinit.\n"; | |
5163 | return 1; | |
5164 | } | |
5165 | ||
91322f44 | 5166 | Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100; |
208e6839 | 5167 | if (aFramesNb <= 0) |
5168 | { | |
5169 | std::cerr << "Incorrect arguments!\n"; | |
5170 | return 1; | |
5171 | } | |
5172 | ||
5173 | // the time is meaningless for first call | |
5174 | // due to async OpenGl rendering | |
5175 | aView->Redraw(); | |
5176 | ||
5177 | // redraw view in loop to estimate average values | |
5178 | OSD_Timer aTimer; | |
5179 | aTimer.Start(); | |
5180 | for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter) | |
5181 | { | |
5182 | aView->Redraw(); | |
5183 | } | |
5184 | aTimer.Stop(); | |
5185 | Standard_Real aCpu; | |
5186 | const Standard_Real aTime = aTimer.ElapsedTime(); | |
5187 | aTimer.OSD_Chronometer::Show (aCpu); | |
5188 | ||
5189 | const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime; | |
5190 | const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb); | |
5191 | ||
5192 | // return statistics | |
5193 | theDI << "FPS: " << aFpsAver << "\n" | |
5194 | << "CPU: " << (1000.0 * aCpuAver) << " msec\n"; | |
5195 | ||
5196 | return 0; | |
5197 | } | |
5198 | ||
58655684 | 5199 | //============================================================================== |
5200 | //function : VGlDebug | |
5201 | //purpose : | |
5202 | //============================================================================== | |
5203 | ||
5204 | static int VGlDebug (Draw_Interpretor& theDI, | |
5205 | Standard_Integer theArgNb, | |
5206 | const char** theArgVec) | |
5207 | { | |
aaf512f1 | 5208 | Handle(OpenGl_GraphicDriver) aDriver; |
5209 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5210 | if (!aView.IsNull()) | |
5211 | { | |
5212 | aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver()); | |
5213 | } | |
c87535af | 5214 | OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps; |
5215 | OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL; | |
5216 | ||
58655684 | 5217 | if (theArgNb < 2) |
5218 | { | |
c87535af | 5219 | TCollection_AsciiString aDebActive, aSyncActive; |
5220 | if (aCaps == NULL) | |
58655684 | 5221 | { |
c87535af | 5222 | aCaps = aDefCaps; |
5223 | } | |
5224 | else | |
5225 | { | |
5226 | Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS), | |
5227 | "GL_ARB_debug_output"); | |
5228 | aDebActive = isActive ? " (active)" : " (inactive)"; | |
5229 | if (isActive) | |
5230 | { | |
5231 | // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB | |
5232 | aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)"; | |
5233 | } | |
58655684 | 5234 | } |
5235 | ||
c87535af | 5236 | theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n" |
5237 | << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n" | |
5238 | << "glslWarn:" << (aCaps->glslWarnings ? "1" : "0") << "\n" | |
5239 | << "extraMsg:" << (aCaps->suppressExtraMsg ? "0" : "1") << "\n"; | |
58655684 | 5240 | return 0; |
5241 | } | |
5242 | ||
c87535af | 5243 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
aaf512f1 | 5244 | { |
c87535af | 5245 | Standard_CString anArg = theArgVec[anArgIter]; |
5246 | TCollection_AsciiString anArgCase (anArg); | |
5247 | anArgCase.LowerCase(); | |
5248 | Standard_Boolean toEnableDebug = Standard_True; | |
5249 | if (anArgCase == "-glsl" | |
5250 | || anArgCase == "-glslwarn" | |
5251 | || anArgCase == "-glslwarns" | |
5252 | || anArgCase == "-glslwarnings") | |
5253 | { | |
5254 | Standard_Boolean toShowWarns = Standard_True; | |
5255 | if (++anArgIter < theArgNb | |
5256 | && !parseOnOff (theArgVec[anArgIter], toShowWarns)) | |
5257 | { | |
5258 | --anArgIter; | |
5259 | } | |
5260 | aDefCaps->glslWarnings = toShowWarns; | |
5261 | if (aCaps != NULL) | |
5262 | { | |
5263 | aCaps->glslWarnings = toShowWarns; | |
5264 | } | |
5265 | } | |
5266 | else if (anArgCase == "-extra" | |
5267 | || anArgCase == "-extramsg" | |
5268 | || anArgCase == "-extramessages") | |
5269 | { | |
5270 | Standard_Boolean toShow = Standard_True; | |
5271 | if (++anArgIter < theArgNb | |
5272 | && !parseOnOff (theArgVec[anArgIter], toShow)) | |
5273 | { | |
5274 | --anArgIter; | |
5275 | } | |
5276 | aDefCaps->suppressExtraMsg = !toShow; | |
5277 | if (aCaps != NULL) | |
5278 | { | |
5279 | aCaps->suppressExtraMsg = !toShow; | |
5280 | } | |
5281 | } | |
5282 | else if (anArgCase == "-noextra" | |
5283 | || anArgCase == "-noextramsg" | |
5284 | || anArgCase == "-noextramessages") | |
5285 | { | |
5286 | Standard_Boolean toSuppress = Standard_True; | |
5287 | if (++anArgIter < theArgNb | |
5288 | && !parseOnOff (theArgVec[anArgIter], toSuppress)) | |
5289 | { | |
5290 | --anArgIter; | |
5291 | } | |
5292 | aDefCaps->suppressExtraMsg = toSuppress; | |
5293 | if (aCaps != NULL) | |
5294 | { | |
5295 | aCaps->suppressExtraMsg = toSuppress; | |
5296 | } | |
5297 | } | |
5298 | else if (anArgCase == "-sync") | |
5299 | { | |
5300 | Standard_Boolean toSync = Standard_True; | |
5301 | if (++anArgIter < theArgNb | |
5302 | && !parseOnOff (theArgVec[anArgIter], toSync)) | |
5303 | { | |
5304 | --anArgIter; | |
5305 | } | |
5306 | aDefCaps->contextSyncDebug = toSync; | |
5307 | if (toSync) | |
5308 | { | |
5309 | aDefCaps->contextDebug = Standard_True; | |
5310 | } | |
5311 | } | |
5312 | else if (anArgCase == "-debug") | |
5313 | { | |
5314 | if (++anArgIter < theArgNb | |
5315 | && !parseOnOff (theArgVec[anArgIter], toEnableDebug)) | |
5316 | { | |
5317 | --anArgIter; | |
5318 | } | |
5319 | aDefCaps->contextDebug = toEnableDebug; | |
5320 | } | |
5321 | else if (parseOnOff (anArg, toEnableDebug) | |
5322 | && (anArgIter + 1 == theArgNb)) | |
5323 | { | |
5324 | // simple alias to turn on almost everything | |
5325 | aDefCaps->contextDebug = toEnableDebug; | |
5326 | aDefCaps->contextSyncDebug = toEnableDebug; | |
5327 | aDefCaps->glslWarnings = toEnableDebug; | |
5328 | } | |
5329 | else | |
5330 | { | |
5331 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
5332 | return 1; | |
5333 | } | |
aaf512f1 | 5334 | } |
5335 | ||
58655684 | 5336 | return 0; |
5337 | } | |
208e6839 | 5338 | |
5339 | //============================================================================== | |
5340 | //function : VVbo | |
5341 | //purpose : | |
5342 | //============================================================================== | |
5343 | ||
58655684 | 5344 | static int VVbo (Draw_Interpretor& theDI, |
208e6839 | 5345 | Standard_Integer theArgNb, |
5346 | const char** theArgVec) | |
5347 | { | |
58655684 | 5348 | const Standard_Boolean toSet = (theArgNb > 1); |
5349 | const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1; | |
5350 | if (toSet) | |
208e6839 | 5351 | { |
58655684 | 5352 | ViewerTest_myDefaultCaps.vboDisable = toUseVbo; |
208e6839 | 5353 | } |
5354 | ||
58655684 | 5355 | // get the context |
5356 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
5357 | if (aContextAIS.IsNull()) | |
208e6839 | 5358 | { |
58655684 | 5359 | if (!toSet) |
5360 | { | |
5361 | std::cerr << "No active view!\n"; | |
5362 | } | |
208e6839 | 5363 | return 1; |
5364 | } | |
58655684 | 5365 | Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver()); |
5366 | if (!aDriver.IsNull()) | |
208e6839 | 5367 | { |
58655684 | 5368 | if (!toSet) |
5369 | { | |
5370 | theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n"; | |
5371 | } | |
5372 | else | |
5373 | { | |
5374 | aDriver->ChangeOptions().vboDisable = toUseVbo; | |
5375 | } | |
208e6839 | 5376 | } |
5377 | ||
208e6839 | 5378 | return 0; |
5379 | } | |
5380 | ||
a577aaab | 5381 | //============================================================================== |
5382 | //function : VCaps | |
5383 | //purpose : | |
5384 | //============================================================================== | |
5385 | ||
5386 | static int VCaps (Draw_Interpretor& theDI, | |
5387 | Standard_Integer theArgNb, | |
5388 | const char** theArgVec) | |
5389 | { | |
5390 | OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps; | |
5391 | Handle(OpenGl_GraphicDriver) aDriver; | |
8625ef7e | 5392 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
5393 | if (!aContext.IsNull()) | |
a577aaab | 5394 | { |
8625ef7e | 5395 | aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver()); |
a577aaab | 5396 | aCaps = &aDriver->ChangeOptions(); |
5397 | } | |
5398 | ||
5399 | if (theArgNb < 2) | |
5400 | { | |
5401 | theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n"; | |
5402 | theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n"; | |
abe46077 | 5403 | theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n"; |
8625ef7e | 5404 | theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n"; |
4e1523ef | 5405 | theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n"; |
a577aaab | 5406 | return 0; |
5407 | } | |
5408 | ||
8625ef7e | 5409 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); |
a577aaab | 5410 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
5411 | { | |
8625ef7e | 5412 | Standard_CString anArg = theArgVec[anArgIter]; |
5413 | TCollection_AsciiString anArgCase (anArg); | |
5414 | anArgCase.LowerCase(); | |
5415 | if (anUpdateTool.parseRedrawMode (anArg)) | |
5416 | { | |
5417 | continue; | |
5418 | } | |
5419 | else if (anArgCase == "-ffp") | |
5420 | { | |
5421 | Standard_Boolean toEnable = Standard_True; | |
5422 | if (++anArgIter < theArgNb | |
5423 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
5424 | { | |
5425 | --anArgIter; | |
5426 | } | |
5427 | aCaps->ffpEnable = toEnable; | |
5428 | } | |
5429 | else if (anArgCase == "-vbo") | |
a577aaab | 5430 | { |
8625ef7e | 5431 | Standard_Boolean toEnable = Standard_True; |
5432 | if (++anArgIter < theArgNb | |
5433 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
5434 | { | |
5435 | --anArgIter; | |
5436 | } | |
5437 | aCaps->vboDisable = !toEnable; | |
a577aaab | 5438 | } |
8625ef7e | 5439 | else if (anArgCase == "-sprite" |
5440 | || anArgCase == "-sprites") | |
a577aaab | 5441 | { |
8625ef7e | 5442 | Standard_Boolean toEnable = Standard_True; |
5443 | if (++anArgIter < theArgNb | |
5444 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
5445 | { | |
5446 | --anArgIter; | |
5447 | } | |
5448 | aCaps->pntSpritesDisable = !toEnable; | |
a577aaab | 5449 | } |
8625ef7e | 5450 | else if (anArgCase == "-softmode") |
abe46077 | 5451 | { |
8625ef7e | 5452 | Standard_Boolean toEnable = Standard_True; |
5453 | if (++anArgIter < theArgNb | |
5454 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
5455 | { | |
5456 | --anArgIter; | |
5457 | } | |
5458 | aCaps->contextNoAccel = toEnable; | |
5459 | } | |
5460 | else if (anArgCase == "-accel" | |
5461 | || anArgCase == "-acceleration") | |
5462 | { | |
5463 | Standard_Boolean toEnable = Standard_True; | |
5464 | if (++anArgIter < theArgNb | |
5465 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
5466 | { | |
5467 | --anArgIter; | |
5468 | } | |
5469 | aCaps->contextNoAccel = !toEnable; | |
abe46077 | 5470 | } |
4e1523ef | 5471 | else if (anArgCase == "-compat" |
5472 | || anArgCase == "-compatprofile" | |
5473 | || anArgCase == "-compatible" | |
5474 | || anArgCase == "-compatibleprofile") | |
5475 | { | |
5476 | Standard_Boolean toEnable = Standard_True; | |
5477 | if (++anArgIter < theArgNb | |
5478 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
5479 | { | |
5480 | --anArgIter; | |
5481 | } | |
5482 | aCaps->contextCompatible = toEnable; | |
5483 | if (!aCaps->contextCompatible) | |
5484 | { | |
5485 | aCaps->ffpEnable = Standard_False; | |
5486 | } | |
5487 | } | |
5488 | else if (anArgCase == "-core" | |
5489 | || anArgCase == "-coreprofile") | |
5490 | { | |
5491 | Standard_Boolean toEnable = Standard_True; | |
5492 | if (++anArgIter < theArgNb | |
5493 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
5494 | { | |
5495 | --anArgIter; | |
5496 | } | |
5497 | aCaps->contextCompatible = !toEnable; | |
5498 | if (!aCaps->contextCompatible) | |
5499 | { | |
5500 | aCaps->ffpEnable = Standard_False; | |
5501 | } | |
5502 | } | |
a577aaab | 5503 | else |
5504 | { | |
8625ef7e | 5505 | std::cout << "Error: unknown argument '" << anArg << "'\n"; |
5506 | return 1; | |
a577aaab | 5507 | } |
5508 | } | |
5509 | if (aCaps != &ViewerTest_myDefaultCaps) | |
5510 | { | |
5511 | ViewerTest_myDefaultCaps = *aCaps; | |
5512 | } | |
5513 | return 0; | |
5514 | } | |
5515 | ||
f0430952 | 5516 | //============================================================================== |
5517 | //function : VMemGpu | |
5518 | //purpose : | |
5519 | //============================================================================== | |
5520 | ||
5521 | static int VMemGpu (Draw_Interpretor& theDI, | |
5522 | Standard_Integer theArgNb, | |
5523 | const char** theArgVec) | |
5524 | { | |
5525 | // get the context | |
5526 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
5527 | if (aContextAIS.IsNull()) | |
5528 | { | |
5529 | std::cerr << "No active view. Please call vinit.\n"; | |
5530 | return 1; | |
5531 | } | |
5532 | ||
dc3fe572 | 5533 | Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver(); |
f0430952 | 5534 | if (aDriver.IsNull()) |
5535 | { | |
5536 | std::cerr << "Graphic driver not available.\n"; | |
5537 | return 1; | |
5538 | } | |
5539 | ||
5540 | Standard_Size aFreeBytes = 0; | |
5541 | TCollection_AsciiString anInfo; | |
5542 | if (!aDriver->MemoryInfo (aFreeBytes, anInfo)) | |
5543 | { | |
5544 | std::cerr << "Information not available.\n"; | |
5545 | return 1; | |
5546 | } | |
5547 | ||
5548 | if (theArgNb > 1 && *theArgVec[1] == 'f') | |
5549 | { | |
5550 | theDI << Standard_Real (aFreeBytes); | |
5551 | } | |
5552 | else | |
5553 | { | |
5554 | theDI << anInfo; | |
5555 | } | |
5556 | ||
5557 | return 0; | |
5558 | } | |
5559 | ||
85e096c3 | 5560 | // ============================================================================== |
5561 | // function : VReadPixel | |
5562 | // purpose : | |
5563 | // ============================================================================== | |
5564 | static int VReadPixel (Draw_Interpretor& theDI, | |
5565 | Standard_Integer theArgNb, | |
5566 | const char** theArgVec) | |
5567 | { | |
5568 | // get the active view | |
5569 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5570 | if (aView.IsNull()) | |
5571 | { | |
5572 | std::cerr << "No active view. Please call vinit.\n"; | |
5573 | return 1; | |
5574 | } | |
5575 | else if (theArgNb < 3) | |
5576 | { | |
5577 | std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n"; | |
5578 | return 1; | |
5579 | } | |
5580 | ||
692613e5 | 5581 | Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; |
5582 | Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA; | |
5583 | ||
85e096c3 | 5584 | Standard_Integer aWidth, aHeight; |
5585 | aView->Window()->Size (aWidth, aHeight); | |
91322f44 | 5586 | const Standard_Integer anX = Draw::Atoi (theArgVec[1]); |
5587 | const Standard_Integer anY = Draw::Atoi (theArgVec[2]); | |
85e096c3 | 5588 | if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight) |
5589 | { | |
5590 | std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n"; | |
5591 | return 1; | |
5592 | } | |
5593 | ||
5594 | Standard_Boolean toShowName = Standard_False; | |
5595 | Standard_Boolean toShowHls = Standard_False; | |
5596 | for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter) | |
5597 | { | |
29cb310a | 5598 | const char* aParam = theArgVec[anIter]; |
5599 | if ( strcasecmp( aParam, "rgb" ) == 0 ) | |
85e096c3 | 5600 | { |
692613e5 | 5601 | aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; |
5602 | aBufferType = Graphic3d_BT_RGB; | |
85e096c3 | 5603 | } |
29cb310a | 5604 | else if ( strcasecmp( aParam, "hls" ) == 0 ) |
85e096c3 | 5605 | { |
692613e5 | 5606 | aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; |
5607 | aBufferType = Graphic3d_BT_RGB; | |
85e096c3 | 5608 | toShowHls = Standard_True; |
5609 | } | |
29cb310a | 5610 | else if ( strcasecmp( aParam, "rgbf" ) == 0 ) |
85e096c3 | 5611 | { |
692613e5 | 5612 | aFormat = Image_PixMap::ImgRGBF; |
5613 | aBufferType = Graphic3d_BT_RGB; | |
85e096c3 | 5614 | } |
29cb310a | 5615 | else if ( strcasecmp( aParam, "rgba" ) == 0 ) |
85e096c3 | 5616 | { |
692613e5 | 5617 | aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; |
5618 | aBufferType = Graphic3d_BT_RGBA; | |
85e096c3 | 5619 | } |
29cb310a | 5620 | else if ( strcasecmp( aParam, "rgbaf" ) == 0 ) |
85e096c3 | 5621 | { |
692613e5 | 5622 | aFormat = Image_PixMap::ImgRGBAF; |
5623 | aBufferType = Graphic3d_BT_RGBA; | |
85e096c3 | 5624 | } |
29cb310a | 5625 | else if ( strcasecmp( aParam, "depth" ) == 0 ) |
85e096c3 | 5626 | { |
692613e5 | 5627 | aFormat = Image_PixMap::ImgGrayF; |
5628 | aBufferType = Graphic3d_BT_Depth; | |
85e096c3 | 5629 | } |
29cb310a | 5630 | else if ( strcasecmp( aParam, "name" ) == 0 ) |
85e096c3 | 5631 | { |
5632 | toShowName = Standard_True; | |
5633 | } | |
5634 | } | |
5635 | ||
692613e5 | 5636 | Image_PixMap anImage; |
5637 | if (!anImage.InitTrash (aFormat, aWidth, aHeight)) | |
5638 | { | |
5639 | std::cerr << "Image allocation failed\n"; | |
5640 | return 1; | |
5641 | } | |
5642 | else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType)) | |
85e096c3 | 5643 | { |
5644 | std::cerr << "Image dump failed\n"; | |
5645 | return 1; | |
5646 | } | |
5647 | ||
5648 | Quantity_Parameter anAlpha; | |
692613e5 | 5649 | Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha); |
85e096c3 | 5650 | if (toShowName) |
5651 | { | |
692613e5 | 5652 | if (aBufferType == Graphic3d_BT_RGBA) |
85e096c3 | 5653 | { |
64c759f8 | 5654 | theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha; |
85e096c3 | 5655 | } |
5656 | else | |
5657 | { | |
64c759f8 | 5658 | theDI << Quantity_Color::StringName (aColor.Name()); |
85e096c3 | 5659 | } |
5660 | } | |
5661 | else | |
5662 | { | |
5663 | switch (aBufferType) | |
5664 | { | |
5665 | default: | |
692613e5 | 5666 | case Graphic3d_BT_RGB: |
85e096c3 | 5667 | { |
5668 | if (toShowHls) | |
5669 | { | |
64c759f8 | 5670 | theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation(); |
85e096c3 | 5671 | } |
5672 | else | |
5673 | { | |
64c759f8 | 5674 | theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue(); |
85e096c3 | 5675 | } |
5676 | break; | |
5677 | } | |
692613e5 | 5678 | case Graphic3d_BT_RGBA: |
85e096c3 | 5679 | { |
64c759f8 | 5680 | theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha; |
85e096c3 | 5681 | break; |
5682 | } | |
692613e5 | 5683 | case Graphic3d_BT_Depth: |
85e096c3 | 5684 | { |
64c759f8 | 5685 | theDI << aColor.Red(); |
85e096c3 | 5686 | break; |
5687 | } | |
5688 | } | |
5689 | } | |
5690 | ||
5691 | return 0; | |
5692 | } | |
5693 | ||
692613e5 | 5694 | //============================================================================== |
5695 | //function : VDiffImage | |
5696 | //purpose : The draw-command compares two images. | |
5697 | //============================================================================== | |
5698 | ||
5699 | static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
5700 | { | |
5701 | if (theArgNb < 6) | |
5702 | { | |
5703 | theDI << "Not enough arguments.\n"; | |
5704 | return 1; | |
5705 | } | |
5706 | ||
5707 | // image file names | |
5708 | const char* anImgPathRef = theArgVec[1]; | |
5709 | const char* anImgPathNew = theArgVec[2]; | |
5710 | ||
5711 | // get string tolerance and check its validity | |
91322f44 | 5712 | Standard_Real aTolColor = Draw::Atof (theArgVec[3]); |
692613e5 | 5713 | if (aTolColor < 0.0) |
5714 | aTolColor = 0.0; | |
5715 | if (aTolColor > 1.0) | |
5716 | aTolColor = 1.0; | |
5717 | ||
91322f44 | 5718 | Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1); |
5719 | Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1); | |
692613e5 | 5720 | |
5721 | // image file of difference | |
5722 | const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL; | |
5723 | ||
5724 | // compare the images | |
5725 | Image_Diff aComparer; | |
5726 | if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite)) | |
5727 | { | |
5728 | return 1; | |
5729 | } | |
5730 | ||
5731 | aComparer.SetColorTolerance (aTolColor); | |
5732 | aComparer.SetBorderFilterOn (isBorderFilterOn); | |
5733 | Standard_Integer aDiffColorsNb = aComparer.Compare(); | |
5734 | theDI << aDiffColorsNb << "\n"; | |
5735 | ||
5736 | // save image of difference | |
936f43da | 5737 | if (aDiffColorsNb >0 && aDiffImagePath != NULL) |
692613e5 | 5738 | { |
5739 | aComparer.SaveDiffImage (aDiffImagePath); | |
5740 | } | |
5741 | ||
5742 | return 0; | |
5743 | } | |
5744 | ||
4754e164 | 5745 | //======================================================================= |
5746 | //function : VSelect | |
5747 | //purpose : Emulates different types of selection by mouse: | |
5748 | // 1) single click selection | |
5749 | // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2) | |
5750 | // 3) selection with polygon having corners at | |
dc3fe572 | 5751 | // pixel positions (x1,y1),...,(xn,yn) |
4754e164 | 5752 | // 4) any of these selections with shift button pressed |
5753 | //======================================================================= | |
5754 | static Standard_Integer VSelect (Draw_Interpretor& di, | |
5755 | Standard_Integer argc, | |
5756 | const char ** argv) | |
5757 | { | |
dc3fe572 | 5758 | if(argc < 3) |
4754e164 | 5759 | { |
5760 | di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n"; | |
5761 | return 1; | |
5762 | } | |
5763 | ||
5764 | Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); | |
dc3fe572 | 5765 | if(myAIScontext.IsNull()) |
4754e164 | 5766 | { |
5767 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
5768 | return 1; | |
5769 | } | |
5770 | const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1)); | |
5771 | Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager(); | |
5772 | aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2])); | |
5773 | if(argc <= 4) | |
5774 | { | |
5775 | if(isShiftSelection) | |
5776 | aCurrentEventManager->ShiftSelect(); | |
5777 | else | |
5778 | aCurrentEventManager->Select(); | |
5779 | } | |
5780 | else if(argc <= 6) | |
5781 | { | |
5782 | if(isShiftSelection) | |
5783 | aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4])); | |
5784 | else | |
5785 | aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4])); | |
5786 | } | |
5787 | else | |
5788 | { | |
5789 | Standard_Integer anUpper = 0; | |
5790 | ||
5791 | if(isShiftSelection) | |
5792 | anUpper = (argc-1)/2; | |
5793 | else | |
5794 | anUpper = argc/2; | |
5795 | TColgp_Array1OfPnt2d aPolyline(1,anUpper); | |
5796 | ||
5797 | for(Standard_Integer i=1;i<=anUpper;++i) | |
5798 | aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i]))); | |
5799 | ||
5800 | if(isShiftSelection) | |
5801 | aCurrentEventManager->ShiftSelect(aPolyline); | |
5802 | else | |
5803 | aCurrentEventManager->Select(aPolyline); | |
5804 | } | |
5805 | return 0; | |
5806 | } | |
5807 | ||
5808 | //======================================================================= | |
5809 | //function : VMoveTo | |
dc3fe572 | 5810 | //purpose : Emulates cursor movement to defined pixel position |
4754e164 | 5811 | //======================================================================= |
5812 | static Standard_Integer VMoveTo (Draw_Interpretor& di, | |
5813 | Standard_Integer argc, | |
5814 | const char ** argv) | |
5815 | { | |
dc3fe572 | 5816 | if(argc != 3) |
4754e164 | 5817 | { |
5818 | di << "Usage : " << argv[0] << " x y" << "\n"; | |
5819 | return 1; | |
5820 | } | |
5821 | ||
5822 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
dc3fe572 | 5823 | if(aContext.IsNull()) |
4754e164 | 5824 | { |
5825 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
5826 | return 1; | |
5827 | } | |
5828 | ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2])); | |
5829 | return 0; | |
5830 | } | |
5831 | ||
197ac94e | 5832 | //================================================================================================= |
4754e164 | 5833 | //function : VViewParams |
dc3fe572 | 5834 | //purpose : Gets or sets AIS View characteristics |
197ac94e | 5835 | //================================================================================================= |
5836 | static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
4754e164 | 5837 | { |
197ac94e | 5838 | Handle(V3d_View) anAISView = ViewerTest::CurrentView(); |
5839 | if (anAISView.IsNull()) | |
4754e164 | 5840 | { |
197ac94e | 5841 | std::cout << theArgVec[0] << ": please initialize or activate view.\n"; |
4754e164 | 5842 | return 1; |
5843 | } | |
197ac94e | 5844 | |
5845 | if (theArgsNb == 1) | |
4754e164 | 5846 | { |
197ac94e | 5847 | // print all of the available view parameters |
5848 | Quantity_Factor anAISViewScale = anAISView->Scale(); | |
5849 | ||
4754e164 | 5850 | Standard_Real anAISViewProjX = 0.0; |
5851 | Standard_Real anAISViewProjY = 0.0; | |
5852 | Standard_Real anAISViewProjZ = 0.0; | |
197ac94e | 5853 | anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ); |
5854 | ||
4754e164 | 5855 | Standard_Real anAISViewUpX = 0.0; |
5856 | Standard_Real anAISViewUpY = 0.0; | |
5857 | Standard_Real anAISViewUpZ = 0.0; | |
197ac94e | 5858 | anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ); |
5859 | ||
4754e164 | 5860 | Standard_Real anAISViewAtX = 0.0; |
5861 | Standard_Real anAISViewAtY = 0.0; | |
5862 | Standard_Real anAISViewAtZ = 0.0; | |
197ac94e | 5863 | anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ); |
5864 | ||
5865 | Standard_Real anAISViewEyeX = 0.0; | |
5866 | Standard_Real anAISViewEyeY = 0.0; | |
5867 | Standard_Real anAISViewEyeZ = 0.0; | |
5868 | anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ); | |
5869 | ||
5870 | theDi << "Scale of current view: " << anAISViewScale << "\n"; | |
5871 | theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n"; | |
5872 | theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n"; | |
5873 | theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n"; | |
5874 | theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n"; | |
5875 | return 0; | |
4754e164 | 5876 | } |
197ac94e | 5877 | |
5878 | // ------------------------- | |
5879 | // Parse options and values | |
5880 | // ------------------------- | |
5881 | ||
900f7229 | 5882 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues; |
197ac94e | 5883 | TCollection_AsciiString aParseKey; |
5884 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
5885 | { | |
5886 | TCollection_AsciiString anArg (theArgVec [anArgIt]); | |
5887 | ||
5888 | if (anArg.Value (1) == '-' && !anArg.IsRealValue()) | |
5889 | { | |
5890 | aParseKey = anArg; | |
5891 | aParseKey.Remove (1); | |
5892 | aParseKey.UpperCase(); | |
900f7229 | 5893 | aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString); |
197ac94e | 5894 | continue; |
5895 | } | |
5896 | ||
3dfe95cd | 5897 | if (aParseKey.IsEmpty()) |
5898 | { | |
5899 | std::cout << theArgVec[0] << ": values should be passed with key.\n"; | |
5900 | std::cout << "Type help for more information.\n"; | |
5901 | return 1; | |
5902 | } | |
5903 | ||
900f7229 | 5904 | aMapOfKeysByValues(aParseKey)->Append (anArg); |
197ac94e | 5905 | } |
5906 | ||
5907 | // --------------------------------------------- | |
5908 | // Change or print parameters, order plays role | |
5909 | // --------------------------------------------- | |
5910 | ||
5911 | // Check arguments for validity | |
900f7229 | 5912 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues); |
197ac94e | 5913 | for (; aMapIt.More(); aMapIt.Next()) |
4754e164 | 5914 | { |
197ac94e | 5915 | const TCollection_AsciiString& aKey = aMapIt.Key(); |
900f7229 | 5916 | const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value(); |
5917 | ||
5918 | if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty())) | |
5919 | && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty())) | |
5920 | && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty())) | |
5921 | && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty())) | |
5922 | && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty())) | |
5923 | && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty())) | |
5924 | && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2)) | |
197ac94e | 5925 | { |
5926 | TCollection_AsciiString aLowerKey; | |
5927 | aLowerKey = "-"; | |
5928 | aLowerKey += aKey; | |
5929 | aLowerKey.LowerCase(); | |
5930 | std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n"; | |
5931 | std::cout << "Type help for more information.\n"; | |
5932 | return 1; | |
5933 | } | |
4754e164 | 5934 | } |
197ac94e | 5935 | |
900f7229 | 5936 | Handle(TColStd_HSequenceOfAsciiString) aValues; |
197ac94e | 5937 | |
5938 | // Change view parameters in proper order | |
5939 | if (aMapOfKeysByValues.Find ("SCALE", aValues)) | |
5940 | { | |
900f7229 | 5941 | if (aValues->IsEmpty()) |
197ac94e | 5942 | { |
5943 | theDi << "Scale: " << anAISView->Scale() << "\n"; | |
5944 | } | |
5945 | else | |
5946 | { | |
900f7229 | 5947 | anAISView->SetScale (aValues->Value(1).RealValue()); |
197ac94e | 5948 | } |
5949 | } | |
3dfe95cd | 5950 | if (aMapOfKeysByValues.Find ("SIZE", aValues)) |
5951 | { | |
900f7229 | 5952 | if (aValues->IsEmpty()) |
3dfe95cd | 5953 | { |
5954 | Standard_Real aSizeX = 0.0; | |
5955 | Standard_Real aSizeY = 0.0; | |
5956 | anAISView->Size (aSizeX, aSizeY); | |
5957 | theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n"; | |
5958 | } | |
5959 | else | |
5960 | { | |
900f7229 | 5961 | anAISView->SetSize (aValues->Value(1).RealValue()); |
3dfe95cd | 5962 | } |
5963 | } | |
197ac94e | 5964 | if (aMapOfKeysByValues.Find ("EYE", aValues)) |
5965 | { | |
900f7229 | 5966 | if (aValues->IsEmpty()) |
197ac94e | 5967 | { |
5968 | Standard_Real anEyeX = 0.0; | |
5969 | Standard_Real anEyeY = 0.0; | |
5970 | Standard_Real anEyeZ = 0.0; | |
5971 | anAISView->Eye (anEyeX, anEyeY, anEyeZ); | |
5972 | theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n"; | |
5973 | } | |
5974 | else | |
5975 | { | |
900f7229 | 5976 | anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue()); |
197ac94e | 5977 | } |
5978 | } | |
5979 | if (aMapOfKeysByValues.Find ("AT", aValues)) | |
5980 | { | |
900f7229 | 5981 | if (aValues->IsEmpty()) |
197ac94e | 5982 | { |
5983 | Standard_Real anAtX = 0.0; | |
5984 | Standard_Real anAtY = 0.0; | |
5985 | Standard_Real anAtZ = 0.0; | |
5986 | anAISView->At (anAtX, anAtY, anAtZ); | |
5987 | theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n"; | |
5988 | } | |
5989 | else | |
5990 | { | |
900f7229 | 5991 | anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue()); |
197ac94e | 5992 | } |
5993 | } | |
5994 | if (aMapOfKeysByValues.Find ("PROJ", aValues)) | |
5995 | { | |
900f7229 | 5996 | if (aValues->IsEmpty()) |
197ac94e | 5997 | { |
5998 | Standard_Real aProjX = 0.0; | |
5999 | Standard_Real aProjY = 0.0; | |
6000 | Standard_Real aProjZ = 0.0; | |
6001 | anAISView->Proj (aProjX, aProjY, aProjZ); | |
6002 | theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n"; | |
6003 | } | |
6004 | else | |
6005 | { | |
900f7229 | 6006 | anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue()); |
197ac94e | 6007 | } |
6008 | } | |
6009 | if (aMapOfKeysByValues.Find ("UP", aValues)) | |
6010 | { | |
900f7229 | 6011 | if (aValues->IsEmpty()) |
197ac94e | 6012 | { |
6013 | Standard_Real anUpX = 0.0; | |
6014 | Standard_Real anUpY = 0.0; | |
6015 | Standard_Real anUpZ = 0.0; | |
6016 | anAISView->Up (anUpX, anUpY, anUpZ); | |
6017 | theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n"; | |
6018 | } | |
6019 | else | |
6020 | { | |
900f7229 | 6021 | anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue()); |
197ac94e | 6022 | } |
6023 | } | |
6024 | if (aMapOfKeysByValues.Find ("CENTER", aValues)) | |
6025 | { | |
900f7229 | 6026 | anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue()); |
197ac94e | 6027 | } |
6028 | ||
4754e164 | 6029 | return 0; |
6030 | } | |
6031 | ||
6032 | //======================================================================= | |
6033 | //function : VChangeSelected | |
dc3fe572 | 6034 | //purpose : Adds the shape to selection or remove one from it |
4754e164 | 6035 | //======================================================================= |
6036 | static Standard_Integer VChangeSelected (Draw_Interpretor& di, | |
6037 | Standard_Integer argc, | |
6038 | const char ** argv) | |
6039 | { | |
6040 | if(argc != 2) | |
6041 | { | |
6042 | di<<"Usage : " << argv[0] << " shape \n"; | |
6043 | return 1; | |
6044 | } | |
6045 | //get AIS_Shape: | |
6046 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6047 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
6048 | TCollection_AsciiString aName(argv[1]); | |
6049 | Handle(AIS_InteractiveObject) anAISObject; | |
6050 | ||
6051 | if(!aMap.IsBound2(aName)) | |
6052 | { | |
6053 | di<<"Use 'vdisplay' before"; | |
6054 | return 1; | |
6055 | } | |
6056 | else | |
6057 | { | |
6058 | anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName)); | |
6059 | if(anAISObject.IsNull()){ | |
6060 | di<<"No interactive object \n"; | |
6061 | return 1; | |
6062 | } | |
6063 | ||
6064 | if(aContext->HasOpenedContext()) | |
6065 | { | |
6066 | aContext->AddOrRemoveSelected(anAISObject); | |
6067 | } | |
dc3fe572 | 6068 | else |
4754e164 | 6069 | { |
6070 | aContext->AddOrRemoveCurrentObject(anAISObject); | |
6071 | } | |
6072 | } | |
6073 | return 0; | |
6074 | } | |
6075 | ||
6076 | //======================================================================= | |
6077 | //function : VZClipping | |
dc3fe572 | 6078 | //purpose : Gets or sets ZClipping mode, width and depth |
4754e164 | 6079 | //======================================================================= |
6080 | static Standard_Integer VZClipping (Draw_Interpretor& di, | |
6081 | Standard_Integer argc, | |
6082 | const char ** argv) | |
6083 | { | |
dc3fe572 | 6084 | if(argc>4) |
4754e164 | 6085 | { |
6086 | di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n" | |
6087 | <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; | |
6088 | return -1; | |
6089 | } | |
6090 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
dc3fe572 | 6091 | if(aContext.IsNull()) |
4754e164 | 6092 | { |
6093 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
6094 | return 1; | |
6095 | } | |
6096 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
1d47d8d0 | 6097 | V3d_TypeOfZclipping aZClippingMode = V3d_OFF; |
4754e164 | 6098 | if(argc==1) |
6099 | { | |
6100 | TCollection_AsciiString aZClippingModeString; | |
6101 | Quantity_Length aDepth, aWidth; | |
6102 | aZClippingMode = aView->ZClipping(aDepth, aWidth); | |
6103 | switch (aZClippingMode) | |
6104 | { | |
6105 | case V3d_OFF: | |
6106 | aZClippingModeString.Copy("OFF"); | |
6107 | break; | |
6108 | case V3d_BACK: | |
6109 | aZClippingModeString.Copy("BACK"); | |
6110 | break; | |
6111 | case V3d_FRONT: | |
6112 | aZClippingModeString.Copy("FRONT"); | |
6113 | break; | |
6114 | case V3d_SLICE: | |
6115 | aZClippingModeString.Copy("SLICE"); | |
6116 | break; | |
6117 | default: | |
6118 | aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode)); | |
6119 | break; | |
6120 | } | |
6121 | di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n" | |
6122 | << "ZClipping depth = " << aDepth << "\n" | |
6123 | << "ZClipping width = " << aWidth << "\n"; | |
6124 | } | |
6125 | else | |
6126 | { | |
6127 | if(argc !=3) | |
6128 | { | |
6129 | Standard_Integer aStatus = 0; | |
6130 | if ( strcmp (argv [1], "OFF") == 0 ) { | |
6131 | aStatus = 1; | |
6132 | aZClippingMode = V3d_OFF; | |
6133 | } | |
6134 | if ( strcmp (argv [1], "BACK") == 0 ) { | |
6135 | aStatus = 1; | |
6136 | aZClippingMode = V3d_BACK; | |
6137 | } | |
6138 | if ( strcmp (argv [1], "FRONT") == 0 ) { | |
6139 | aStatus = 1; | |
6140 | aZClippingMode = V3d_FRONT; | |
6141 | } | |
6142 | if ( strcmp (argv [1], "SLICE") == 0 ) { | |
6143 | aStatus = 1; | |
6144 | aZClippingMode = V3d_SLICE; | |
6145 | } | |
6146 | if (aStatus != 1) | |
6147 | { | |
6148 | di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n" | |
6149 | << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; | |
6150 | return 1; | |
dc3fe572 | 6151 | } |
4754e164 | 6152 | aView->SetZClippingType(aZClippingMode); |
6153 | } | |
6154 | if(argc >2) | |
6155 | { | |
6156 | Quantity_Length aDepth = 0., aWidth = 1.; | |
6157 | if(argc == 3) | |
6158 | { | |
6b62b2da | 6159 | aDepth = Draw::Atof (argv[1]); |
6160 | aWidth = Draw::Atof (argv[2]); | |
4754e164 | 6161 | } |
6162 | else if(argc == 4) | |
6163 | { | |
6b62b2da | 6164 | aDepth = Draw::Atof (argv[2]); |
6165 | aWidth = Draw::Atof (argv[3]); | |
4754e164 | 6166 | } |
dc3fe572 | 6167 | |
4754e164 | 6168 | if(aDepth<0. || aDepth>1.) |
6169 | { | |
6170 | di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n" | |
6171 | << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; | |
6172 | return 1; | |
6173 | } | |
6174 | if(aWidth<0. || aWidth>1.) | |
6175 | { | |
6176 | di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n" | |
6177 | << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n"; | |
6178 | return 1; | |
6179 | } | |
6180 | ||
6181 | aView->SetZClippingDepth(aDepth); | |
6182 | aView->SetZClippingWidth(aWidth); | |
6183 | } | |
6184 | aView->Redraw(); | |
6185 | } | |
6186 | return 0; | |
6187 | } | |
6188 | ||
6189 | //======================================================================= | |
6190 | //function : VNbSelected | |
dc3fe572 | 6191 | //purpose : Returns number of selected objects |
4754e164 | 6192 | //======================================================================= |
6193 | static Standard_Integer VNbSelected (Draw_Interpretor& di, | |
6194 | Standard_Integer argc, | |
6195 | const char ** argv) | |
6196 | { | |
6197 | if(argc != 1) | |
6198 | { | |
6199 | di << "Usage : " << argv[0] << "\n"; | |
6200 | return 1; | |
6201 | } | |
6202 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6203 | if(aContext.IsNull()) | |
6204 | { | |
6205 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
6206 | return 1; | |
6207 | } | |
6208 | di << aContext->NbSelected() << "\n"; | |
6209 | return 0; | |
6210 | } | |
6211 | ||
6212 | //======================================================================= | |
6213 | //function : VAntialiasing | |
dc3fe572 | 6214 | //purpose : Switches altialiasing on or off |
4754e164 | 6215 | //======================================================================= |
6216 | static Standard_Integer VAntialiasing (Draw_Interpretor& di, | |
6217 | Standard_Integer argc, | |
6218 | const char ** argv) | |
6219 | { | |
6220 | if(argc > 2) | |
6221 | { | |
6222 | di << "Usage : " << argv[0] << " [1|0]" << "\n"; | |
6223 | return 1; | |
6224 | } | |
6225 | ||
6226 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6227 | if(aContext.IsNull()) | |
6228 | { | |
6229 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
6230 | return 1; | |
6231 | } | |
6232 | ||
6233 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6234 | ||
6235 | if((argc == 2) && (atof(argv[1]) == 0)) | |
6236 | aView->SetAntialiasingOff(); | |
6237 | else | |
6238 | aView->SetAntialiasingOn(); | |
6239 | aView->Update(); | |
6240 | return 0; | |
6241 | } | |
6242 | ||
6243 | //======================================================================= | |
6244 | //function : VPurgeDisplay | |
dc3fe572 | 6245 | //purpose : Switches altialiasing on or off |
4754e164 | 6246 | //======================================================================= |
6247 | static Standard_Integer VPurgeDisplay (Draw_Interpretor& di, | |
6248 | Standard_Integer argc, | |
6249 | const char ** argv) | |
6250 | { | |
eb4320f2 | 6251 | if (argc > 1) |
4754e164 | 6252 | { |
eb4320f2 | 6253 | di << "Usage : " << argv[0] << "\n"; |
4754e164 | 6254 | return 1; |
6255 | } | |
4754e164 | 6256 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
6257 | if (aContext.IsNull()) | |
6258 | { | |
6259 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
6260 | return 1; | |
6261 | } | |
6262 | aContext->CloseAllContexts(Standard_False); | |
eb4320f2 | 6263 | di << aContext->PurgeDisplay() << "\n"; |
4754e164 | 6264 | return 0; |
6265 | } | |
6266 | ||
6267 | //======================================================================= | |
6268 | //function : VSetViewSize | |
6269 | //purpose : | |
6270 | //======================================================================= | |
6271 | static Standard_Integer VSetViewSize (Draw_Interpretor& di, | |
6272 | Standard_Integer argc, | |
6273 | const char ** argv) | |
6274 | { | |
6275 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6276 | if(aContext.IsNull()) | |
6277 | { | |
6278 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
6279 | return 1; | |
6280 | } | |
6281 | if(argc != 2) | |
6282 | { | |
6283 | di<<"Usage : " << argv[0] << " Size\n"; | |
6284 | return 1; | |
6285 | } | |
6b62b2da | 6286 | Standard_Real aSize = Draw::Atof (argv[1]); |
4754e164 | 6287 | if (aSize <= 0.) |
6288 | { | |
6289 | di<<"Bad Size value : " << aSize << "\n"; | |
6290 | return 1; | |
6291 | } | |
6292 | ||
6293 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6294 | aView->SetSize(aSize); | |
6295 | return 0; | |
6296 | } | |
6297 | ||
6298 | //======================================================================= | |
6299 | //function : VMoveView | |
6300 | //purpose : | |
6301 | //======================================================================= | |
6302 | static Standard_Integer VMoveView (Draw_Interpretor& di, | |
6303 | Standard_Integer argc, | |
6304 | const char ** argv) | |
6305 | { | |
6306 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6307 | if(aContext.IsNull()) | |
6308 | { | |
6309 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
6310 | return 1; | |
6311 | } | |
6312 | if(argc < 4 || argc > 5) | |
6313 | { | |
6314 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; | |
6315 | return 1; | |
6316 | } | |
6b62b2da | 6317 | Standard_Real Dx = Draw::Atof (argv[1]); |
6318 | Standard_Real Dy = Draw::Atof (argv[2]); | |
6319 | Standard_Real Dz = Draw::Atof (argv[3]); | |
4754e164 | 6320 | Standard_Boolean aStart = Standard_True; |
6321 | if (argc == 5) | |
6322 | { | |
6b62b2da | 6323 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 6324 | } |
6325 | ||
6326 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6327 | aView->Move(Dx,Dy,Dz,aStart); | |
6328 | return 0; | |
6329 | } | |
6330 | ||
6331 | //======================================================================= | |
6332 | //function : VTranslateView | |
6333 | //purpose : | |
6334 | //======================================================================= | |
6335 | static Standard_Integer VTranslateView (Draw_Interpretor& di, | |
6336 | Standard_Integer argc, | |
6337 | const char ** argv) | |
6338 | { | |
6339 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6340 | if(aContext.IsNull()) | |
6341 | { | |
6342 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
6343 | return 1; | |
6344 | } | |
6345 | if(argc < 4 || argc > 5) | |
6346 | { | |
6347 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; | |
6348 | return 1; | |
6349 | } | |
6b62b2da | 6350 | Standard_Real Dx = Draw::Atof (argv[1]); |
6351 | Standard_Real Dy = Draw::Atof (argv[2]); | |
6352 | Standard_Real Dz = Draw::Atof (argv[3]); | |
4754e164 | 6353 | Standard_Boolean aStart = Standard_True; |
dc3fe572 | 6354 | if (argc == 5) |
4754e164 | 6355 | { |
6b62b2da | 6356 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 6357 | } |
6358 | ||
6359 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6360 | aView->Translate(Dx,Dy,Dz,aStart); | |
6361 | return 0; | |
6362 | } | |
6363 | ||
6364 | //======================================================================= | |
6365 | //function : VTurnView | |
6366 | //purpose : | |
6367 | //======================================================================= | |
6368 | static Standard_Integer VTurnView (Draw_Interpretor& di, | |
6369 | Standard_Integer argc, | |
6370 | const char ** argv) | |
6371 | { | |
6372 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6373 | if(aContext.IsNull()) { | |
6374 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
6375 | return 1; | |
6376 | } | |
6377 | if(argc < 4 || argc > 5){ | |
6378 | di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n"; | |
6379 | return 1; | |
6380 | } | |
6b62b2da | 6381 | Standard_Real Ax = Draw::Atof (argv[1]); |
6382 | Standard_Real Ay = Draw::Atof (argv[2]); | |
6383 | Standard_Real Az = Draw::Atof (argv[3]); | |
4754e164 | 6384 | Standard_Boolean aStart = Standard_True; |
dc3fe572 | 6385 | if (argc == 5) |
4754e164 | 6386 | { |
6b62b2da | 6387 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 6388 | } |
6389 | ||
6390 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6391 | aView->Turn(Ax,Ay,Az,aStart); | |
6392 | return 0; | |
6393 | } | |
6394 | ||
269294d6 | 6395 | //============================================================================== |
6396 | //function : VTextureEnv | |
6397 | //purpose : ENables or disables environment mapping | |
6398 | //============================================================================== | |
6399 | class OCC_TextureEnv : public Graphic3d_TextureEnv | |
6400 | { | |
6401 | public: | |
6402 | OCC_TextureEnv(const Standard_CString FileName); | |
6403 | OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName); | |
6404 | void SetTextureParameters(const Standard_Boolean theRepeatFlag, | |
6405 | const Standard_Boolean theModulateFlag, | |
6406 | const Graphic3d_TypeOfTextureFilter theFilter, | |
6407 | const Standard_ShortReal theXScale, | |
6408 | const Standard_ShortReal theYScale, | |
6409 | const Standard_ShortReal theXShift, | |
6410 | const Standard_ShortReal theYShift, | |
6411 | const Standard_ShortReal theAngle); | |
6412 | DEFINE_STANDARD_RTTI(OCC_TextureEnv); | |
6413 | }; | |
6414 | DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv); | |
6415 | IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv); | |
6416 | IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv); | |
6417 | ||
6418 | OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName) | |
6419 | : Graphic3d_TextureEnv(theFileName) | |
6420 | { | |
6421 | } | |
6422 | ||
6423 | OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId) | |
6424 | : Graphic3d_TextureEnv(theTexId) | |
6425 | { | |
6426 | } | |
6427 | ||
6428 | void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag, | |
6429 | const Standard_Boolean theModulateFlag, | |
6430 | const Graphic3d_TypeOfTextureFilter theFilter, | |
6431 | const Standard_ShortReal theXScale, | |
6432 | const Standard_ShortReal theYScale, | |
6433 | const Standard_ShortReal theXShift, | |
6434 | const Standard_ShortReal theYShift, | |
6435 | const Standard_ShortReal theAngle) | |
6436 | { | |
6437 | myParams->SetRepeat (theRepeatFlag); | |
6438 | myParams->SetModulate (theModulateFlag); | |
6439 | myParams->SetFilter (theFilter); | |
6440 | myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale)); | |
6441 | myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift)); | |
6442 | myParams->SetRotation (theAngle); | |
6443 | } | |
6444 | ||
35e08fe8 | 6445 | static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec) |
269294d6 | 6446 | { |
6447 | // get the active view | |
6448 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6449 | if (aView.IsNull()) | |
6450 | { | |
6451 | std::cerr << "No active view. Please call vinit.\n"; | |
6452 | return 1; | |
6453 | } | |
6454 | ||
6455 | // Checking the input arguments | |
6456 | Standard_Boolean anEnableFlag = Standard_False; | |
6457 | Standard_Boolean isOk = theArgNb >= 2; | |
6458 | if (isOk) | |
6459 | { | |
6460 | TCollection_AsciiString anEnableOpt(theArgVec[1]); | |
6461 | anEnableFlag = anEnableOpt.IsEqual("on"); | |
6462 | isOk = anEnableFlag || anEnableOpt.IsEqual("off"); | |
6463 | } | |
6464 | if (anEnableFlag) | |
6465 | { | |
6466 | isOk = (theArgNb == 3 || theArgNb == 11); | |
6467 | if (isOk) | |
6468 | { | |
6469 | TCollection_AsciiString aTextureOpt(theArgVec[2]); | |
6470 | isOk = (!aTextureOpt.IsIntegerValue() || | |
6471 | (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN)); | |
6472 | ||
6473 | if (isOk && theArgNb == 11) | |
6474 | { | |
6475 | TCollection_AsciiString aRepeatOpt (theArgVec[3]), | |
6476 | aModulateOpt(theArgVec[4]), | |
6477 | aFilterOpt (theArgVec[5]), | |
6478 | aSScaleOpt (theArgVec[6]), | |
6479 | aTScaleOpt (theArgVec[7]), | |
6480 | aSTransOpt (theArgVec[8]), | |
6481 | aTTransOpt (theArgVec[9]), | |
6482 | anAngleOpt (theArgVec[10]); | |
6483 | isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) && | |
6484 | (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) && | |
6485 | (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) && | |
6486 | aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() && | |
6487 | aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() && | |
6488 | anAngleOpt.IsRealValue()); | |
6489 | } | |
6490 | } | |
6491 | } | |
6492 | ||
6493 | if (!isOk) | |
6494 | { | |
6495 | std::cerr << "Usage :" << std::endl; | |
6496 | std::cerr << theArgVec[0] << " off" << std::endl; | |
6497 | std::cerr << theArgVec[0] << " on {index_of_std_texture(0..7)|texture_file_name} [{clamp|repeat} {decal|modulate} {nearest|bilinear|trilinear} scale_s scale_t translation_s translation_t rotation_degrees]" << std::endl; | |
6498 | return 1; | |
6499 | } | |
6500 | ||
6501 | if (anEnableFlag) | |
6502 | { | |
6503 | TCollection_AsciiString aTextureOpt(theArgVec[2]); | |
6504 | Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ? | |
6505 | new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) : | |
6506 | new OCC_TextureEnv(theArgVec[2]); | |
6507 | ||
6508 | if (theArgNb == 11) | |
6509 | { | |
6510 | TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]); | |
6511 | aTexEnv->SetTextureParameters( | |
6512 | aRepeatOpt. IsEqual("repeat"), | |
6513 | aModulateOpt.IsEqual("modulate"), | |
6514 | aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST : | |
6515 | aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR : | |
6516 | Graphic3d_TOTF_TRILINEAR, | |
6517 | (Standard_ShortReal)Draw::Atof(theArgVec[6]), | |
6518 | (Standard_ShortReal)Draw::Atof(theArgVec[7]), | |
6519 | (Standard_ShortReal)Draw::Atof(theArgVec[8]), | |
6520 | (Standard_ShortReal)Draw::Atof(theArgVec[9]), | |
6521 | (Standard_ShortReal)Draw::Atof(theArgVec[10]) | |
6522 | ); | |
6523 | } | |
6524 | aView->SetTextureEnv(aTexEnv); | |
6525 | aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT); | |
6526 | } | |
6527 | else // Disabling environment mapping | |
6528 | { | |
6529 | aView->SetSurfaceDetail(V3d_TEX_NONE); | |
6530 | Handle(Graphic3d_TextureEnv) aTexture; | |
6531 | aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data | |
6532 | } | |
6533 | ||
6534 | aView->Redraw(); | |
6535 | return 0; | |
6536 | } | |
6537 | ||
4269bd1b | 6538 | //=============================================================================================== |
6539 | //function : VClipPlane | |
6540 | //purpose : | |
6541 | //=============================================================================================== | |
6542 | static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
6543 | { | |
6544 | // use short-cut for created clip planes map of created (or "registered by name") clip planes | |
6545 | typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes; | |
6546 | static MapOfPlanes aRegPlanes; | |
6547 | ||
6548 | if (theArgsNb < 2) | |
6549 | { | |
6550 | theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n"; | |
6551 | return 1; | |
6552 | } | |
6553 | ||
6554 | TCollection_AsciiString aCommand (theArgVec[1]); | |
6555 | ||
6556 | // print maximum number of planes for current viewer | |
6557 | if (aCommand == "maxplanes") | |
6558 | { | |
6559 | if (theArgsNb < 3) | |
6560 | { | |
6561 | theDi << theArgVec[0] << ": view name is required. Type help for more information.\n"; | |
6562 | return 1; | |
6563 | } | |
6564 | ||
6565 | TCollection_AsciiString aViewName (theArgVec[2]); | |
6566 | ||
6567 | if (!ViewerTest_myViews.IsBound1 (aViewName)) | |
6568 | { | |
6569 | theDi << theArgVec[0] << ": view is not found.\n"; | |
6570 | return 1; | |
6571 | } | |
6572 | ||
6573 | const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName); | |
6574 | ||
6575 | theDi << theArgVec[0] << ": " | |
6576 | << aView->Viewer()->Driver()->InquirePlaneLimit() | |
6577 | << " plane slots provided by driver." | |
6578 | << " Note that 2 more planes might be used (reserved for z-clipping).\n"; | |
6579 | ||
6580 | return 0; | |
6581 | } | |
6582 | ||
6583 | // create / delete plane instance | |
6584 | if (aCommand == "create" || aCommand == "delete" || aCommand == "clone") | |
6585 | { | |
6586 | if (theArgsNb < 3) | |
6587 | { | |
6588 | theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n"; | |
6589 | return 1; | |
6590 | } | |
6591 | ||
6592 | Standard_Boolean toCreate = (aCommand == "create"); | |
6593 | Standard_Boolean toClone = (aCommand == "clone"); | |
6594 | TCollection_AsciiString aPlane (theArgVec[2]); | |
6595 | ||
6596 | if (toCreate) | |
6597 | { | |
6598 | if (aRegPlanes.IsBound (aPlane)) | |
6599 | { | |
6600 | theDi << theArgVec[0] << ": plane name is in use.\n"; | |
6601 | return 1; | |
6602 | } | |
6603 | ||
6604 | aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane()); | |
6605 | } | |
6606 | else if (toClone) // toClone | |
6607 | { | |
6608 | if (!aRegPlanes.IsBound (aPlane)) | |
6609 | { | |
6610 | theDi << theArgVec[0] << ": no such plane.\n"; | |
6611 | return 1; | |
6612 | } | |
6613 | ||
6614 | if (theArgsNb < 4) | |
6615 | { | |
6616 | theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n"; | |
6617 | return 1; | |
6618 | } | |
6619 | ||
6620 | TCollection_AsciiString aClone (theArgVec[3]); | |
6621 | if (aRegPlanes.IsBound (aClone)) | |
6622 | { | |
6623 | theDi << theArgVec[0] << ": plane name is in use.\n"; | |
6624 | return 1; | |
6625 | } | |
6626 | ||
6627 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); | |
6628 | ||
6629 | aRegPlanes.Bind (aClone, aClipPlane->Clone()); | |
6630 | } | |
6631 | else// toDelete | |
6632 | { | |
6633 | if (!aRegPlanes.IsBound (aPlane)) | |
6634 | { | |
6635 | theDi << theArgVec[0] << ": no such plane.\n"; | |
6636 | return 1; | |
6637 | } | |
6638 | ||
6639 | Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane); | |
6640 | aRegPlanes.UnBind (aPlane); | |
6641 | ||
6642 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS()); | |
6643 | for (; anIObjIt.More(); anIObjIt.Next()) | |
6644 | { | |
6645 | Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1()); | |
6646 | aPrs->RemoveClipPlane(aClipPlane); | |
6647 | } | |
6648 | ||
6649 | NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews); | |
6650 | for (; aViewIt.More(); aViewIt.Next()) | |
6651 | { | |
6652 | const Handle(V3d_View)& aView = aViewIt.Key2(); | |
6653 | aView->RemoveClipPlane(aClipPlane); | |
6654 | } | |
6655 | ||
6656 | ViewerTest::RedrawAllViews(); | |
6657 | } | |
6658 | ||
6659 | return 0; | |
6660 | } | |
6661 | ||
6662 | // set / unset plane command | |
6663 | if (aCommand == "set" || aCommand == "unset") | |
6664 | { | |
6665 | if (theArgsNb < 4) | |
6666 | { | |
6667 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6668 | return 1; | |
6669 | } | |
6670 | ||
6671 | Standard_Boolean toSet = (aCommand == "set"); | |
6672 | TCollection_AsciiString aPlane (theArgVec [2]); | |
6673 | if (!aRegPlanes.IsBound (aPlane)) | |
6674 | { | |
6675 | theDi << theArgVec[0] << ": no such plane.\n"; | |
6676 | return 1; | |
6677 | } | |
6678 | ||
6679 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); | |
6680 | ||
6681 | TCollection_AsciiString aTarget (theArgVec [3]); | |
6682 | if (aTarget != "object" && aTarget != "view") | |
6683 | { | |
6684 | theDi << theArgVec[0] << ": invalid target.\n"; | |
6685 | return 1; | |
6686 | } | |
6687 | ||
6688 | if (aTarget == "object" || aTarget == "view") | |
6689 | { | |
6690 | if (theArgsNb < 5) | |
6691 | { | |
6692 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6693 | return 1; | |
6694 | } | |
6695 | ||
6696 | Standard_Boolean isObject = (aTarget == "object"); | |
6697 | ||
6698 | for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt) | |
6699 | { | |
6700 | TCollection_AsciiString anEntityName (theArgVec[anIt]); | |
6701 | if (isObject) // to object | |
6702 | { | |
6703 | if (!GetMapOfAIS().IsBound2 (anEntityName)) | |
6704 | { | |
6705 | theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n"; | |
6706 | continue; | |
6707 | } | |
6708 | ||
6709 | Handle(AIS_InteractiveObject) aIObj = | |
6710 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName)); | |
6711 | ||
6712 | if (toSet) | |
6713 | aIObj->AddClipPlane (aClipPlane); | |
6714 | else | |
6715 | aIObj->RemoveClipPlane (aClipPlane); | |
6716 | } | |
6717 | else // to view | |
6718 | { | |
6719 | if (!ViewerTest_myViews.IsBound1 (anEntityName)) | |
6720 | { | |
6721 | theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n"; | |
6722 | continue; | |
6723 | } | |
6724 | ||
6725 | Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName); | |
6726 | if (toSet) | |
6727 | aView->AddClipPlane (aClipPlane); | |
6728 | else | |
6729 | aView->RemoveClipPlane (aClipPlane); | |
6730 | } | |
6731 | } | |
6732 | ||
6733 | ViewerTest::RedrawAllViews(); | |
6734 | } | |
6735 | ||
6736 | return 0; | |
6737 | } | |
6738 | ||
6739 | // change plane command | |
6740 | if (aCommand == "change") | |
6741 | { | |
6742 | if (theArgsNb < 4) | |
6743 | { | |
6744 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6745 | return 1; | |
6746 | } | |
6747 | ||
6748 | TCollection_AsciiString aPlane (theArgVec [2]); | |
6749 | if (!aRegPlanes.IsBound (aPlane)) | |
6750 | { | |
6751 | theDi << theArgVec[0] << ": no such plane.\n"; | |
6752 | return 1; | |
6753 | } | |
6754 | ||
6755 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); | |
6756 | ||
6757 | TCollection_AsciiString aChangeArg (theArgVec [3]); | |
6758 | if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation") | |
6759 | { | |
6760 | theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n"; | |
6761 | return 1; | |
6762 | } | |
6763 | ||
6764 | if (aChangeArg == "on" || aChangeArg == "off") // on / off | |
6765 | { | |
6766 | aClipPlane->SetOn (aChangeArg == "on"); | |
6767 | } | |
6768 | else if (aChangeArg == "equation") // change equation | |
6769 | { | |
6770 | if (theArgsNb < 8) | |
6771 | { | |
6772 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6773 | return 1; | |
6774 | } | |
6775 | ||
6b62b2da | 6776 | Standard_Real aCoeffA = Draw::Atof (theArgVec [4]); |
6777 | Standard_Real aCoeffB = Draw::Atof (theArgVec [5]); | |
6778 | Standard_Real aCoeffC = Draw::Atof (theArgVec [6]); | |
6779 | Standard_Real aCoeffD = Draw::Atof (theArgVec [7]); | |
4269bd1b | 6780 | aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD)); |
6781 | } | |
6782 | else if (aChangeArg == "capping") // change capping aspects | |
6783 | { | |
6784 | if (theArgsNb < 5) | |
6785 | { | |
6786 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6787 | return 1; | |
6788 | } | |
6789 | ||
6790 | TCollection_AsciiString aCappingArg (theArgVec [4]); | |
6791 | if (aCappingArg != "on" && aCappingArg != "off" && | |
6792 | aCappingArg != "color" && aCappingArg != "texname" && | |
6793 | aCappingArg != "texscale" && aCappingArg != "texorigin" && | |
6794 | aCappingArg != "texrotate" && aCappingArg != "hatch") | |
6795 | { | |
6796 | theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n"; | |
6797 | return 1; | |
6798 | } | |
6799 | ||
6800 | if (aCappingArg == "on" || aCappingArg == "off") // on / off capping | |
6801 | { | |
6802 | aClipPlane->SetCapping (aCappingArg == "on"); | |
6803 | } | |
6804 | else if (aCappingArg == "color") // color aspect for capping | |
6805 | { | |
6806 | if (theArgsNb < 8) | |
6807 | { | |
6808 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6809 | return 1; | |
6810 | } | |
6811 | ||
6b62b2da | 6812 | Standard_Real aRed = Draw::Atof (theArgVec [5]); |
6813 | Standard_Real aGrn = Draw::Atof (theArgVec [6]); | |
6814 | Standard_Real aBlu = Draw::Atof (theArgVec [7]); | |
4269bd1b | 6815 | |
6816 | Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial(); | |
8aeeca44 | 6817 | Quantity_Color aColor (aRed, aGrn, aBlu, Quantity_TOC_RGB); |
6818 | aMat.SetAmbientColor (aColor); | |
6819 | aMat.SetDiffuseColor (aColor); | |
4269bd1b | 6820 | aClipPlane->SetCappingMaterial (aMat); |
6821 | } | |
6822 | else if (aCappingArg == "texname") // texture name | |
6823 | { | |
6824 | if (theArgsNb < 6) | |
6825 | { | |
6826 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6827 | return 1; | |
6828 | } | |
6829 | ||
6830 | TCollection_AsciiString aTextureName (theArgVec [5]); | |
6831 | ||
6832 | Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName); | |
6833 | if (!aTexture->IsDone ()) | |
6834 | { | |
6835 | aClipPlane->SetCappingTexture (NULL); | |
6836 | } | |
6837 | else | |
6838 | { | |
6839 | aTexture->EnableModulate(); | |
6840 | aTexture->EnableRepeat(); | |
6841 | aClipPlane->SetCappingTexture (aTexture); | |
6842 | } | |
6843 | } | |
6844 | else if (aCappingArg == "texscale") // texture scale | |
6845 | { | |
6846 | if (aClipPlane->CappingTexture().IsNull()) | |
6847 | { | |
6848 | theDi << theArgVec[0] << ": no texture is set.\n"; | |
6849 | return 1; | |
6850 | } | |
6851 | ||
6852 | if (theArgsNb < 7) | |
6853 | { | |
6854 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6855 | return 1; | |
6856 | } | |
6857 | ||
6858 | Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]); | |
6859 | Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]); | |
6860 | ||
6861 | aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy)); | |
6862 | } | |
6863 | else if (aCappingArg == "texorigin") // texture origin | |
6864 | { | |
6865 | if (aClipPlane->CappingTexture().IsNull()) | |
6866 | { | |
6867 | theDi << theArgVec[0] << ": no texture is set.\n"; | |
6868 | return 1; | |
6869 | } | |
6870 | ||
6871 | if (theArgsNb < 7) | |
6872 | { | |
6873 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6874 | return 1; | |
6875 | } | |
6876 | ||
6877 | Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]); | |
6878 | Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]); | |
6879 | ||
6880 | aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy)); | |
6881 | } | |
6882 | else if (aCappingArg == "texrotate") // texture rotation | |
6883 | { | |
6884 | if (aClipPlane->CappingTexture().IsNull()) | |
6885 | { | |
6886 | theDi << theArgVec[0] << ": no texture is set.\n"; | |
6887 | return 1; | |
6888 | } | |
6889 | ||
6890 | if (theArgsNb < 6) | |
6891 | { | |
6892 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6893 | return 1; | |
6894 | } | |
6895 | ||
6896 | Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]); | |
6897 | ||
6898 | aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot); | |
6899 | } | |
6900 | else if (aCappingArg == "hatch") // hatch style | |
6901 | { | |
6902 | if (theArgsNb < 6) | |
6903 | { | |
6904 | theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n"; | |
6905 | return 1; | |
6906 | } | |
6907 | ||
6908 | TCollection_AsciiString aHatchStr (theArgVec [5]); | |
6909 | if (aHatchStr == "on") | |
6910 | { | |
6911 | aClipPlane->SetCappingHatchOn(); | |
6912 | } | |
6913 | else if (aHatchStr == "off") | |
6914 | { | |
6915 | aClipPlane->SetCappingHatchOff(); | |
6916 | } | |
6917 | else | |
6918 | { | |
6919 | aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5])); | |
6920 | } | |
6921 | } | |
6922 | } | |
6923 | ||
6924 | ViewerTest::RedrawAllViews(); | |
6925 | ||
6926 | return 0; | |
6927 | } | |
6928 | ||
6929 | theDi << theArgVec[0] << ": invalid command. Type help for more information.\n"; | |
6930 | return 1; | |
6931 | } | |
6932 | ||
6933 | //=============================================================================================== | |
6934 | //function : VSetTextureMode | |
6935 | //purpose : | |
6936 | //=============================================================================================== | |
6937 | static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
6938 | { | |
6939 | if (theArgsNb < 3) | |
6940 | { | |
6941 | theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n"; | |
6942 | return 1; | |
6943 | } | |
6944 | ||
6945 | TCollection_AsciiString aViewName (theArgVec[1]); | |
6946 | if (!ViewerTest_myViews.IsBound1 (aViewName)) | |
6947 | { | |
6948 | theDi << theArgVec[0] << ": view is not found.\n"; | |
6949 | return 1; | |
6950 | } | |
6951 | ||
6952 | const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName); | |
6953 | switch (atoi (theArgVec[2])) | |
6954 | { | |
6955 | case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break; | |
6956 | case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break; | |
6957 | case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break; | |
6958 | default: | |
6959 | theDi << theArgVec[0] << ": invalid mode.\n"; | |
6960 | return 1; | |
6961 | } | |
6962 | ||
6963 | aView->Redraw(); | |
6964 | return 0; | |
6965 | } | |
6966 | ||
b5ac8292 | 6967 | //=============================================================================================== |
6968 | //function : VZRange | |
6969 | //purpose : | |
6970 | //=============================================================================================== | |
6971 | static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
6972 | { | |
197ac94e | 6973 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
6974 | ||
6975 | if (aCurrentView.IsNull()) | |
b5ac8292 | 6976 | { |
197ac94e | 6977 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; |
b5ac8292 | 6978 | return 1; |
6979 | } | |
6980 | ||
197ac94e | 6981 | Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera(); |
b5ac8292 | 6982 | |
6983 | if (theArgsNb < 2) | |
6984 | { | |
6985 | theDi << "ZNear: " << aCamera->ZNear() << "\n"; | |
6986 | theDi << "ZFar: " << aCamera->ZFar() << "\n"; | |
6987 | return 0; | |
6988 | } | |
6989 | ||
6990 | if (theArgsNb == 3) | |
6991 | { | |
6b62b2da | 6992 | Standard_Real aNewZNear = Draw::Atof (theArgVec[1]); |
6993 | Standard_Real aNewZFar = Draw::Atof (theArgVec[2]); | |
197ac94e | 6994 | |
6995 | if (aNewZNear >= aNewZFar) | |
6996 | { | |
6997 | std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n"; | |
6998 | return 1; | |
6999 | } | |
7000 | ||
7001 | if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0)) | |
7002 | { | |
7003 | std::cout << theArgVec[0] << ": invalid arguments: "; | |
7004 | std::cout << "znear, zfar should be positive for perspective camera.\n"; | |
7005 | return 1; | |
7006 | } | |
7007 | ||
7008 | aCamera->SetZRange (aNewZNear, aNewZFar); | |
b5ac8292 | 7009 | } |
7010 | else | |
7011 | { | |
197ac94e | 7012 | std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n"; |
b5ac8292 | 7013 | return 1; |
7014 | } | |
7015 | ||
197ac94e | 7016 | aCurrentView->Redraw(); |
7017 | ||
b5ac8292 | 7018 | return 0; |
7019 | } | |
7020 | ||
7021 | //=============================================================================================== | |
7022 | //function : VAutoZFit | |
7023 | //purpose : | |
7024 | //=============================================================================================== | |
7025 | static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
7026 | { | |
197ac94e | 7027 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
7028 | ||
7029 | if (aCurrentView.IsNull()) | |
b5ac8292 | 7030 | { |
197ac94e | 7031 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; |
b5ac8292 | 7032 | return 1; |
7033 | } | |
7034 | ||
6bc6a6fc | 7035 | Standard_Real aScale = aCurrentView->View()->AutoZFitScaleFactor(); |
197ac94e | 7036 | |
7037 | if (theArgsNb > 3) | |
b5ac8292 | 7038 | { |
197ac94e | 7039 | std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n"; |
7040 | return 1; | |
b5ac8292 | 7041 | } |
7042 | ||
197ac94e | 7043 | if (theArgsNb < 2) |
b5ac8292 | 7044 | { |
197ac94e | 7045 | theDi << "Auto z-fit mode: " << "\n" |
6bc6a6fc | 7046 | << "On: " << (aCurrentView->View()->AutoZFitMode() ? "enabled" : "disabled") << "\n" |
197ac94e | 7047 | << "Scale: " << aScale << "\n"; |
7048 | return 0; | |
b5ac8292 | 7049 | } |
197ac94e | 7050 | |
7051 | Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1; | |
7052 | ||
7053 | if (theArgsNb >= 3) | |
b5ac8292 | 7054 | { |
197ac94e | 7055 | aScale = Draw::Atoi (theArgVec[2]); |
b5ac8292 | 7056 | } |
7057 | ||
6bc6a6fc | 7058 | aCurrentView->View()->SetAutoZFitMode (isOn, aScale); |
7059 | aCurrentView->View()->AutoZFit(); | |
197ac94e | 7060 | aCurrentView->Redraw(); |
7061 | ||
b5ac8292 | 7062 | return 0; |
7063 | } | |
7064 | ||
6b62b2da | 7065 | //! Auxiliary function to print projection type |
7066 | inline const char* projTypeName (Graphic3d_Camera::Projection theProjType) | |
7067 | { | |
7068 | switch (theProjType) | |
7069 | { | |
7070 | case Graphic3d_Camera::Projection_Orthographic: return "orthographic"; | |
7071 | case Graphic3d_Camera::Projection_Perspective: return "perspective"; | |
7072 | case Graphic3d_Camera::Projection_Stereo: return "stereoscopic"; | |
7073 | case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye"; | |
7074 | case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye"; | |
7075 | } | |
7076 | return "UNKNOWN"; | |
7077 | } | |
7078 | ||
b5ac8292 | 7079 | //=============================================================================================== |
6b62b2da | 7080 | //function : VCamera |
b5ac8292 | 7081 | //purpose : |
7082 | //=============================================================================================== | |
6b62b2da | 7083 | static int VCamera (Draw_Interpretor& theDI, |
7084 | Standard_Integer theArgsNb, | |
7085 | const char** theArgVec) | |
b5ac8292 | 7086 | { |
6b62b2da | 7087 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
7088 | if (aView.IsNull()) | |
b5ac8292 | 7089 | { |
6b62b2da | 7090 | std::cout << "Error: no active view.\n"; |
b5ac8292 | 7091 | return 1; |
7092 | } | |
7093 | ||
6b62b2da | 7094 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); |
7095 | if (theArgsNb < 2) | |
b5ac8292 | 7096 | { |
6b62b2da | 7097 | theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n"; |
7098 | theDI << "FOVy: " << aCamera->FOVy() << "\n"; | |
7099 | theDI << "Distance: " << aCamera->Distance() << "\n"; | |
7100 | theDI << "IOD: " << aCamera->IOD() << "\n"; | |
7101 | theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n"; | |
7102 | theDI << "ZFocus: " << aCamera->ZFocus() << "\n"; | |
7103 | theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n"; | |
7104 | return 0; | |
b5ac8292 | 7105 | } |
7106 | ||
6b62b2da | 7107 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) |
b5ac8292 | 7108 | { |
6b62b2da | 7109 | Standard_CString anArg = theArgVec[anArgIter]; |
7110 | TCollection_AsciiString anArgCase (anArg); | |
7111 | anArgCase.LowerCase(); | |
7112 | if (anArgCase == "-proj" | |
7113 | || anArgCase == "-projection" | |
7114 | || anArgCase == "-projtype" | |
7115 | || anArgCase == "-projectiontype") | |
7116 | { | |
7117 | theDI << projTypeName (aCamera->ProjectionType()) << " "; | |
7118 | } | |
7119 | else if (anArgCase == "-ortho" | |
7120 | || anArgCase == "-orthographic") | |
b5ac8292 | 7121 | { |
7122 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic); | |
6b62b2da | 7123 | } |
7124 | else if (anArgCase == "-persp" | |
7125 | || anArgCase == "-perspective" | |
7126 | || anArgCase == "-perspmono" | |
7127 | || anArgCase == "-perspectivemono" | |
7128 | || anArgCase == "-mono") | |
b5ac8292 | 7129 | { |
7130 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective); | |
7131 | } | |
6b62b2da | 7132 | else if (anArgCase == "-stereo" |
7133 | || anArgCase == "-stereoscopic" | |
7134 | || anArgCase == "-perspstereo" | |
7135 | || anArgCase == "-perspectivestereo") | |
7136 | { | |
7137 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo); | |
7138 | } | |
7139 | else if (anArgCase == "-left" | |
7140 | || anArgCase == "-lefteye" | |
7141 | || anArgCase == "-monoleft" | |
7142 | || anArgCase == "-monolefteye" | |
7143 | || anArgCase == "-perpsleft" | |
7144 | || anArgCase == "-perpslefteye") | |
b5ac8292 | 7145 | { |
7146 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye); | |
7147 | } | |
6b62b2da | 7148 | else if (anArgCase == "-right" |
7149 | || anArgCase == "-righteye" | |
7150 | || anArgCase == "-monoright" | |
7151 | || anArgCase == "-monorighteye" | |
7152 | || anArgCase == "-perpsright") | |
b5ac8292 | 7153 | { |
7154 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye); | |
7155 | } | |
6b62b2da | 7156 | else if (anArgCase == "-dist" |
7157 | || anArgCase == "-distance") | |
b5ac8292 | 7158 | { |
6b62b2da | 7159 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
7160 | if (anArgValue != NULL | |
7161 | && *anArgValue != '-') | |
7162 | { | |
7163 | ++anArgIter; | |
7164 | aCamera->SetDistance (Draw::Atof (anArgValue)); | |
7165 | continue; | |
7166 | } | |
7167 | theDI << aCamera->Distance() << " "; | |
b5ac8292 | 7168 | } |
6b62b2da | 7169 | else if (anArgCase == "-iod") |
b5ac8292 | 7170 | { |
6b62b2da | 7171 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
7172 | if (anArgValue != NULL | |
7173 | && *anArgValue != '-') | |
7174 | { | |
7175 | ++anArgIter; | |
7176 | aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue)); | |
7177 | continue; | |
7178 | } | |
7179 | theDI << aCamera->IOD() << " "; | |
b5ac8292 | 7180 | } |
6b62b2da | 7181 | else if (anArgCase == "-iodtype") |
b5ac8292 | 7182 | { |
6b62b2da | 7183 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : ""; |
7184 | TCollection_AsciiString anValueCase (anArgValue); | |
7185 | anValueCase.LowerCase(); | |
7186 | if (anValueCase == "abs" | |
7187 | || anValueCase == "absolute") | |
7188 | { | |
7189 | ++anArgIter; | |
7190 | aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD()); | |
7191 | continue; | |
7192 | } | |
7193 | else if (anValueCase == "rel" | |
7194 | || anValueCase == "relative") | |
7195 | { | |
7196 | ++anArgIter; | |
7197 | aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD()); | |
7198 | continue; | |
7199 | } | |
7200 | else if (*anArgValue != '-') | |
7201 | { | |
7202 | std::cout << "Error: unknown IOD type '" << anArgValue << "'\n"; | |
7203 | return 1; | |
7204 | } | |
7205 | switch (aCamera->GetIODType()) | |
7206 | { | |
7207 | case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break; | |
7208 | case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break; | |
7209 | } | |
b5ac8292 | 7210 | } |
6b62b2da | 7211 | else if (anArgCase == "-zfocus") |
b5ac8292 | 7212 | { |
6b62b2da | 7213 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
7214 | if (anArgValue != NULL | |
7215 | && *anArgValue != '-') | |
7216 | { | |
7217 | ++anArgIter; | |
7218 | aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue)); | |
7219 | continue; | |
7220 | } | |
7221 | theDI << aCamera->ZFocus() << " "; | |
b5ac8292 | 7222 | } |
6b62b2da | 7223 | else if (anArgCase == "-zfocustype") |
b5ac8292 | 7224 | { |
6b62b2da | 7225 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : ""; |
7226 | TCollection_AsciiString anValueCase (anArgValue); | |
7227 | anValueCase.LowerCase(); | |
7228 | if (anValueCase == "abs" | |
7229 | || anValueCase == "absolute") | |
7230 | { | |
7231 | ++anArgIter; | |
7232 | aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus()); | |
7233 | continue; | |
7234 | } | |
7235 | else if (anValueCase == "rel" | |
7236 | || anValueCase == "relative") | |
7237 | { | |
7238 | ++anArgIter; | |
7239 | aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus()); | |
7240 | continue; | |
7241 | } | |
7242 | else if (*anArgValue != '-') | |
7243 | { | |
7244 | std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n"; | |
7245 | return 1; | |
7246 | } | |
7247 | switch (aCamera->ZFocusType()) | |
7248 | { | |
7249 | case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break; | |
7250 | case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break; | |
7251 | } | |
7252 | } | |
7253 | else if (anArgCase == "-fov" | |
7254 | || anArgCase == "-fovy") | |
b5ac8292 | 7255 | { |
6b62b2da | 7256 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
7257 | if (anArgValue != NULL | |
7258 | && *anArgValue != '-') | |
7259 | { | |
7260 | ++anArgIter; | |
7261 | aCamera->SetFOVy (Draw::Atof (anArgValue)); | |
7262 | continue; | |
7263 | } | |
7264 | theDI << aCamera->FOVy() << " "; | |
b5ac8292 | 7265 | } |
7266 | else | |
7267 | { | |
6b62b2da | 7268 | std::cout << "Error: unknown argument '" << anArg << "'\n"; |
b5ac8292 | 7269 | return 1; |
7270 | } | |
7271 | } | |
b5ac8292 | 7272 | |
6b62b2da | 7273 | aView->View()->AutoZFit(); |
7274 | aView->Redraw(); | |
b5ac8292 | 7275 | |
7276 | return 0; | |
7277 | } | |
7278 | ||
7279 | //============================================================================== | |
7280 | //function : VStereo | |
7281 | //purpose : | |
7282 | //============================================================================== | |
7283 | ||
7284 | static int VStereo (Draw_Interpretor& theDI, | |
7285 | Standard_Integer theArgNb, | |
7286 | const char** theArgVec) | |
7287 | { | |
7288 | if (theArgNb < 2) | |
7289 | { | |
7290 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
7291 | if (aView.IsNull()) | |
7292 | { | |
7293 | std::cerr << "No active view. Please call vinit.\n"; | |
7294 | return 0; | |
7295 | } | |
7296 | ||
7297 | Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo; | |
7298 | theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n"; | |
7299 | return 0; | |
7300 | } | |
7301 | ||
7302 | ViewerTest_myDefaultCaps.contextStereo = Draw::Atoi (theArgVec[1]) != 0; | |
7303 | return 0; | |
7304 | } | |
7305 | ||
392ac980 | 7306 | //=============================================================================================== |
7307 | //function : VDefaults | |
7308 | //purpose : | |
7309 | //=============================================================================================== | |
7310 | static int VDefaults (Draw_Interpretor& theDi, | |
7311 | Standard_Integer theArgsNb, | |
7312 | const char** theArgVec) | |
7313 | { | |
7314 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); | |
7315 | if (aCtx.IsNull()) | |
7316 | { | |
7317 | std::cerr << "No active viewer!\n"; | |
7318 | return 1; | |
7319 | } | |
7320 | ||
7321 | Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer(); | |
7322 | if (theArgsNb < 2) | |
7323 | { | |
7324 | if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE) | |
7325 | { | |
7326 | theDi << "DeflType: relative\n" | |
7327 | << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n"; | |
7328 | } | |
7329 | else | |
7330 | { | |
7331 | theDi << "DeflType: absolute\n" | |
7332 | << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n"; | |
7333 | } | |
7334 | theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n"; | |
4c513386 | 7335 | theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n"; |
392ac980 | 7336 | return 0; |
7337 | } | |
7338 | ||
7339 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
7340 | { | |
7341 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
4c513386 | 7342 | anArg.UpperCase(); |
7343 | if (anArg == "-ABSDEFL" | |
7344 | || anArg == "-ABSOLUTEDEFLECTION" | |
7345 | || anArg == "-DEFL" | |
7346 | || anArg == "-DEFLECTION") | |
392ac980 | 7347 | { |
4c513386 | 7348 | if (++anArgIter >= theArgsNb) |
7349 | { | |
7350 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
7351 | return 1; | |
7352 | } | |
392ac980 | 7353 | aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE); |
4c513386 | 7354 | aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter])); |
392ac980 | 7355 | } |
4c513386 | 7356 | else if (anArg == "-RELDEFL" |
7357 | || anArg == "-RELATIVEDEFLECTION" | |
7358 | || anArg == "-DEVCOEFF" | |
7359 | || anArg == "-DEVIATIONCOEFF" | |
7360 | || anArg == "-DEVIATIONCOEFFICIENT") | |
392ac980 | 7361 | { |
4c513386 | 7362 | if (++anArgIter >= theArgsNb) |
7363 | { | |
7364 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
7365 | return 1; | |
7366 | } | |
392ac980 | 7367 | aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE); |
4c513386 | 7368 | aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter])); |
392ac980 | 7369 | } |
4c513386 | 7370 | else if (anArg == "-ANGDEFL" |
7371 | || anArg == "-ANGULARDEFL" | |
7372 | || anArg == "-ANGULARDEFLECTION") | |
392ac980 | 7373 | { |
4c513386 | 7374 | if (++anArgIter >= theArgsNb) |
7375 | { | |
7376 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
7377 | return 1; | |
7378 | } | |
392ac980 | 7379 | // currently HLRDeviationAngle is used instead of DeviationAngle in most places |
4c513386 | 7380 | aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0); |
7381 | } | |
7382 | if (anArg == "-AUTOTR" | |
7383 | || anArg == "-AUTOTRIANG" | |
7384 | || anArg == "-AUTOTRIANGULATION") | |
7385 | { | |
7386 | if (++anArgIter >= theArgsNb) | |
7387 | { | |
7388 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
7389 | return 1; | |
7390 | } | |
7391 | TCollection_AsciiString aValue (theArgVec[anArgIter]); | |
7392 | aValue.LowerCase(); | |
7393 | if (aValue == "on" | |
7394 | || aValue == "1") | |
7395 | { | |
7396 | aDefParams->SetAutoTriangulation (Standard_True); | |
7397 | } | |
7398 | else if (aValue == "off" | |
7399 | || aValue == "0") | |
7400 | { | |
7401 | aDefParams->SetAutoTriangulation (Standard_False); | |
7402 | } | |
392ac980 | 7403 | } |
7404 | else | |
7405 | { | |
7406 | std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n"; | |
7407 | } | |
7408 | } | |
7409 | ||
7410 | return 0; | |
7411 | } | |
7412 | ||
12381341 | 7413 | //! Auxiliary method |
7414 | inline void addLight (const Handle(V3d_Light)& theLightNew, | |
7415 | const Standard_Boolean theIsGlobal) | |
7416 | { | |
7417 | if (theLightNew.IsNull()) | |
7418 | { | |
7419 | return; | |
7420 | } | |
7421 | ||
7422 | if (theIsGlobal) | |
7423 | { | |
7424 | ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew); | |
7425 | } | |
7426 | else | |
7427 | { | |
7428 | ViewerTest::CurrentView()->SetLightOn (theLightNew); | |
7429 | } | |
7430 | } | |
7431 | ||
7432 | //! Auxiliary method | |
7433 | inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext) | |
7434 | { | |
7435 | TCollection_AsciiString anArgNextCase (theArgNext); | |
7436 | anArgNextCase.UpperCase(); | |
7437 | if (anArgNextCase.Length() > 5 | |
7438 | && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT")) | |
7439 | { | |
7440 | return theArgNext.SubString (6, theArgNext.Length()).IntegerValue(); | |
7441 | } | |
7442 | else | |
7443 | { | |
7444 | return theArgNext.IntegerValue(); | |
7445 | } | |
7446 | } | |
7447 | ||
7448 | //=============================================================================================== | |
7449 | //function : VLight | |
7450 | //purpose : | |
7451 | //=============================================================================================== | |
7452 | static int VLight (Draw_Interpretor& theDi, | |
7453 | Standard_Integer theArgsNb, | |
7454 | const char** theArgVec) | |
7455 | { | |
7456 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
7457 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
7458 | if (aView.IsNull() | |
7459 | || aViewer.IsNull()) | |
7460 | { | |
7461 | std::cerr << "No active viewer!\n"; | |
7462 | return 1; | |
7463 | } | |
7464 | ||
7465 | Standard_Real anXYZ[3]; | |
7466 | Quantity_Coefficient anAtten[2]; | |
7467 | if (theArgsNb < 2) | |
7468 | { | |
7469 | // print lights info | |
7470 | Standard_Integer aLightId = 0; | |
7471 | for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId) | |
7472 | { | |
7473 | Handle(V3d_Light) aLight = aView->ActiveLight(); | |
7474 | const Quantity_Color aColor = aLight->Color(); | |
7475 | theDi << "Light" << aLightId << "\n"; | |
7476 | switch (aLight->Type()) | |
7477 | { | |
7478 | case V3d_AMBIENT: | |
7479 | { | |
7480 | theDi << " Type: Ambient\n"; | |
7481 | break; | |
7482 | } | |
7483 | case V3d_DIRECTIONAL: | |
7484 | { | |
7485 | Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight); | |
7486 | theDi << " Type: Directional\n"; | |
7487 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
7488 | if (!aLightDir.IsNull()) | |
7489 | { | |
7490 | aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]); | |
7491 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
7492 | aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]); | |
7493 | theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
7494 | } | |
7495 | break; | |
7496 | } | |
7497 | case V3d_POSITIONAL: | |
7498 | { | |
7499 | Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight); | |
7500 | theDi << " Type: Positional\n"; | |
7501 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
7502 | if (!aLightPos.IsNull()) | |
7503 | { | |
7504 | aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]); | |
7505 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
7506 | aLightPos->Attenuation (anAtten[0], anAtten[1]); | |
7507 | theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n"; | |
7508 | } | |
7509 | break; | |
7510 | } | |
7511 | case V3d_SPOT: | |
7512 | { | |
7513 | Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight); | |
7514 | theDi << " Type: Spot\n"; | |
7515 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
7516 | if (!aLightSpot.IsNull()) | |
7517 | { | |
7518 | aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]); | |
7519 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
7520 | aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]); | |
7521 | theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
7522 | aLightSpot->Attenuation (anAtten[0], anAtten[1]); | |
7523 | theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n"; | |
7524 | theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n"; | |
7525 | theDi << " Exponent: " << aLightSpot->Concentration() << "\n"; | |
7526 | } | |
7527 | break; | |
7528 | } | |
7529 | default: | |
7530 | { | |
7531 | theDi << " Type: UNKNOWN\n"; | |
7532 | break; | |
7533 | } | |
7534 | } | |
7535 | theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n"; | |
7536 | } | |
7537 | } | |
7538 | ||
7539 | Handle(V3d_Light) aLightNew; | |
7540 | Handle(V3d_Light) aLightOld; | |
7541 | Standard_Boolean isGlobal = Standard_True; | |
7542 | Standard_Boolean toCreate = Standard_False; | |
7543 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
7544 | { | |
7545 | Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew; | |
7546 | Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr); | |
7547 | Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr); | |
7548 | Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr); | |
7549 | Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr); | |
7550 | ||
7551 | TCollection_AsciiString aName, aValue; | |
7552 | const TCollection_AsciiString anArg (theArgVec[anArgIt]); | |
7553 | TCollection_AsciiString anArgCase (anArg); | |
7554 | anArgCase.UpperCase(); | |
7555 | if (anArgCase.IsEqual ("NEW") | |
7556 | || anArgCase.IsEqual ("ADD") | |
7557 | || anArgCase.IsEqual ("CREATE")) | |
7558 | { | |
7559 | toCreate = Standard_True; | |
7560 | } | |
7561 | else if (anArgCase.IsEqual ("GLOB") | |
7562 | || anArgCase.IsEqual ("GLOBAL")) | |
7563 | { | |
7564 | isGlobal = Standard_True; | |
7565 | } | |
7566 | else if (anArgCase.IsEqual ("LOC") | |
7567 | || anArgCase.IsEqual ("LOCAL")) | |
7568 | { | |
7569 | isGlobal = Standard_False; | |
7570 | } | |
4fe9ad57 | 7571 | else if (anArgCase.IsEqual ("DEF") |
7572 | || anArgCase.IsEqual ("DEFAULTS")) | |
7573 | { | |
7574 | toCreate = Standard_False; | |
7575 | aViewer->SetDefaultLights(); | |
7576 | } | |
7577 | else if (anArgCase.IsEqual ("CLR") | |
7578 | || anArgCase.IsEqual ("CLEAR")) | |
7579 | { | |
7580 | toCreate = Standard_False; | |
7581 | aView->InitActiveLights(); | |
7582 | while (aView->MoreActiveLights()) | |
7583 | { | |
7584 | aViewer->DelLight (aView->ActiveLight()); | |
7585 | aView->InitActiveLights(); | |
7586 | } | |
7587 | } | |
12381341 | 7588 | else if (anArgCase.IsEqual ("AMB") |
7589 | || anArgCase.IsEqual ("AMBIENT") | |
7590 | || anArgCase.IsEqual ("AMBLIGHT")) | |
7591 | { | |
7592 | addLight (aLightNew, isGlobal); | |
7593 | if (!toCreate) | |
7594 | { | |
7595 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7596 | return 1; | |
7597 | } | |
7598 | toCreate = Standard_False; | |
7599 | aLightNew = new V3d_AmbientLight (aViewer); | |
7600 | } | |
7601 | else if (anArgCase.IsEqual ("DIRECTIONAL") | |
7602 | || anArgCase.IsEqual ("DIRLIGHT")) | |
7603 | { | |
7604 | addLight (aLightNew, isGlobal); | |
7605 | if (!toCreate) | |
7606 | { | |
7607 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7608 | return 1; | |
7609 | } | |
7610 | toCreate = Standard_False; | |
7611 | aLightNew = new V3d_DirectionalLight (aViewer); | |
7612 | } | |
7613 | else if (anArgCase.IsEqual ("SPOT") | |
7614 | || anArgCase.IsEqual ("SPOTLIGHT")) | |
7615 | { | |
7616 | addLight (aLightNew, isGlobal); | |
7617 | if (!toCreate) | |
7618 | { | |
7619 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7620 | return 1; | |
7621 | } | |
7622 | toCreate = Standard_False; | |
7623 | aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0); | |
7624 | } | |
7625 | else if (anArgCase.IsEqual ("POSLIGHT") | |
7626 | || anArgCase.IsEqual ("POSITIONAL")) | |
7627 | { | |
7628 | addLight (aLightNew, isGlobal); | |
7629 | if (!toCreate) | |
7630 | { | |
7631 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7632 | return 1; | |
7633 | } | |
7634 | toCreate = Standard_False; | |
7635 | aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0); | |
7636 | } | |
7637 | else if (anArgCase.IsEqual ("CHANGE")) | |
7638 | { | |
7639 | addLight (aLightNew, isGlobal); | |
7640 | aLightNew.Nullify(); | |
7641 | if (++anArgIt >= theArgsNb) | |
7642 | { | |
7643 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7644 | return 1; | |
7645 | } | |
7646 | ||
7647 | const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]); | |
7648 | Standard_Integer aLightIt = 0; | |
7649 | for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt) | |
7650 | { | |
7651 | if (aLightIt == aLightId) | |
7652 | { | |
7653 | aLightOld = aView->ActiveLight(); | |
7654 | break; | |
7655 | } | |
7656 | } | |
7657 | ||
7658 | if (aLightOld.IsNull()) | |
7659 | { | |
7660 | std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n"; | |
7661 | return 1; | |
7662 | } | |
7663 | } | |
7664 | else if (anArgCase.IsEqual ("DEL") | |
7665 | || anArgCase.IsEqual ("DELETE")) | |
7666 | { | |
7667 | Handle(V3d_Light) aLightDel; | |
7668 | if (++anArgIt >= theArgsNb) | |
7669 | { | |
7670 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7671 | return 1; | |
7672 | } | |
7673 | ||
7674 | const TCollection_AsciiString anArgNext (theArgVec[anArgIt]); | |
7675 | const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]); | |
7676 | Standard_Integer aLightIt = 0; | |
7677 | for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt) | |
7678 | { | |
7679 | aLightDel = aView->ActiveLight(); | |
7680 | if (aLightIt == aLightDelId) | |
7681 | { | |
7682 | break; | |
7683 | } | |
7684 | } | |
7685 | if (!aLightDel.IsNull()) | |
7686 | { | |
7687 | aViewer->DelLight (aLightDel); | |
7688 | } | |
7689 | } | |
7690 | else if (anArgCase.IsEqual ("COLOR") | |
7691 | || anArgCase.IsEqual ("COLOUR")) | |
7692 | { | |
7693 | if (++anArgIt >= theArgsNb) | |
7694 | { | |
7695 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7696 | return 1; | |
7697 | } | |
7698 | ||
7699 | TCollection_AsciiString anArgNext (theArgVec[anArgIt]); | |
7700 | anArgNext.UpperCase(); | |
7701 | const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString()); | |
7702 | if (!aLightCurr.IsNull()) | |
7703 | { | |
7704 | aLightCurr->SetColor (aColor); | |
7705 | } | |
7706 | } | |
7707 | else if (anArgCase.IsEqual ("POS") | |
7708 | || anArgCase.IsEqual ("POSITION")) | |
7709 | { | |
7710 | if ((anArgIt + 3) >= theArgsNb) | |
7711 | { | |
7712 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7713 | return 1; | |
7714 | } | |
7715 | ||
7716 | anXYZ[0] = Atof (theArgVec[++anArgIt]); | |
7717 | anXYZ[1] = Atof (theArgVec[++anArgIt]); | |
7718 | anXYZ[2] = Atof (theArgVec[++anArgIt]); | |
7719 | if (!aLightDir.IsNull()) | |
7720 | { | |
7721 | aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]); | |
7722 | } | |
7723 | else if (!aLightPos.IsNull()) | |
7724 | { | |
7725 | aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]); | |
7726 | } | |
7727 | else if (!aLightSpot.IsNull()) | |
7728 | { | |
7729 | aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]); | |
7730 | } | |
7731 | else | |
7732 | { | |
7733 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7734 | return 1; | |
7735 | } | |
7736 | } | |
7737 | else if (anArgCase.IsEqual ("DIR") | |
7738 | || anArgCase.IsEqual ("DIRECTION")) | |
7739 | { | |
7740 | if ((anArgIt + 3) >= theArgsNb) | |
7741 | { | |
7742 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7743 | return 1; | |
7744 | } | |
7745 | ||
7746 | anXYZ[0] = Atof (theArgVec[++anArgIt]); | |
7747 | anXYZ[1] = Atof (theArgVec[++anArgIt]); | |
7748 | anXYZ[2] = Atof (theArgVec[++anArgIt]); | |
7749 | if (!aLightDir.IsNull()) | |
7750 | { | |
7751 | aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]); | |
7752 | } | |
7753 | else if (!aLightSpot.IsNull()) | |
7754 | { | |
7755 | aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]); | |
7756 | } | |
7757 | else | |
7758 | { | |
7759 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7760 | return 1; | |
7761 | } | |
7762 | } | |
4fe9ad57 | 7763 | else if (anArgCase.IsEqual ("ANG") |
7764 | || anArgCase.IsEqual ("ANGLE")) | |
7765 | { | |
7766 | if (++anArgIt >= theArgsNb) | |
7767 | { | |
7768 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7769 | return 1; | |
7770 | } | |
7771 | ||
7772 | Standard_Real anAngle = Atof (theArgVec[anArgIt]); | |
7773 | ||
7774 | if (!aLightSpot.IsNull()) | |
7775 | { | |
7776 | aLightSpot->SetAngle (anAngle / 180.0 * M_PI); | |
7777 | } | |
7778 | } | |
12381341 | 7779 | else if (anArgCase.IsEqual ("CONSTATTEN") |
7780 | || anArgCase.IsEqual ("CONSTATTENUATION")) | |
7781 | { | |
7782 | if (++anArgIt >= theArgsNb) | |
7783 | { | |
7784 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7785 | return 1; | |
7786 | } | |
7787 | ||
7788 | if (!aLightPos.IsNull()) | |
7789 | { | |
7790 | aLightPos->Attenuation (anAtten[0], anAtten[1]); | |
7791 | anAtten[0] = Atof (theArgVec[anArgIt]); | |
7792 | aLightPos->SetAttenuation (anAtten[0], anAtten[1]); | |
7793 | } | |
7794 | else if (!aLightSpot.IsNull()) | |
7795 | { | |
7796 | aLightSpot->Attenuation (anAtten[0], anAtten[1]); | |
7797 | anAtten[0] = Atof (theArgVec[anArgIt]); | |
7798 | aLightSpot->SetAttenuation (anAtten[0], anAtten[1]); | |
7799 | } | |
7800 | else | |
7801 | { | |
7802 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7803 | return 1; | |
7804 | } | |
7805 | } | |
7806 | else if (anArgCase.IsEqual ("LINATTEN") | |
7807 | || anArgCase.IsEqual ("LINEARATTEN") | |
7808 | || anArgCase.IsEqual ("LINEARATTENUATION")) | |
7809 | { | |
7810 | if (++anArgIt >= theArgsNb) | |
7811 | { | |
7812 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7813 | return 1; | |
7814 | } | |
7815 | ||
7816 | if (!aLightPos.IsNull()) | |
7817 | { | |
7818 | aLightPos->Attenuation (anAtten[0], anAtten[1]); | |
7819 | anAtten[1] = Atof (theArgVec[anArgIt]); | |
7820 | aLightPos->SetAttenuation (anAtten[0], anAtten[1]); | |
7821 | } | |
7822 | else if (!aLightSpot.IsNull()) | |
7823 | { | |
7824 | aLightSpot->Attenuation (anAtten[0], anAtten[1]); | |
7825 | anAtten[1] = Atof (theArgVec[anArgIt]); | |
7826 | aLightSpot->SetAttenuation (anAtten[0], anAtten[1]); | |
7827 | } | |
7828 | else | |
7829 | { | |
7830 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7831 | return 1; | |
7832 | } | |
7833 | } | |
7834 | else if (anArgCase.IsEqual ("EXP") | |
7835 | || anArgCase.IsEqual ("EXPONENT") | |
7836 | || anArgCase.IsEqual ("SPOTEXP") | |
7837 | || anArgCase.IsEqual ("SPOTEXPONENT")) | |
7838 | { | |
7839 | if (++anArgIt >= theArgsNb) | |
7840 | { | |
7841 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7842 | return 1; | |
7843 | } | |
7844 | ||
7845 | if (!aLightSpot.IsNull()) | |
7846 | { | |
7847 | aLightSpot->SetConcentration (Atof (theArgVec[anArgIt])); | |
7848 | } | |
7849 | else | |
7850 | { | |
7851 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7852 | return 1; | |
7853 | } | |
7854 | } | |
7855 | else if (anArgCase.IsEqual ("HEAD") | |
7856 | || anArgCase.IsEqual ("HEADLIGHT")) | |
7857 | { | |
7858 | if (++anArgIt >= theArgsNb) | |
7859 | { | |
7860 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7861 | return 1; | |
7862 | } | |
7863 | ||
7864 | if (aLightAmb.IsNull() | |
7865 | && !aLightCurr.IsNull()) | |
7866 | { | |
7867 | aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0); | |
7868 | } | |
7869 | else | |
7870 | { | |
7871 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
7872 | return 1; | |
7873 | } | |
7874 | } | |
7875 | else | |
7876 | { | |
7877 | std::cerr << "Warning: unknown argument '" << anArg << "'\n"; | |
7878 | } | |
7879 | } | |
7880 | ||
7881 | addLight (aLightNew, isGlobal); | |
7882 | aViewer->UpdateLights(); | |
7883 | ||
7884 | return 0; | |
7885 | } | |
7886 | ||
e276548b | 7887 | //======================================================================= |
bc8c79bb | 7888 | //function : VRenderParams |
7889 | //purpose : Enables/disables rendering features | |
e276548b | 7890 | //======================================================================= |
7891 | ||
bc8c79bb | 7892 | static Standard_Integer VRenderParams (Draw_Interpretor& theDI, |
7893 | Standard_Integer theArgNb, | |
7894 | const char** theArgVec) | |
e276548b | 7895 | { |
7ae4a307 | 7896 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
7897 | if (aView.IsNull()) | |
e276548b | 7898 | { |
bc8c79bb | 7899 | std::cerr << "Error: no active viewer!\n"; |
e276548b | 7900 | return 1; |
7901 | } | |
bc8c79bb | 7902 | |
7903 | Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams(); | |
6b62b2da | 7904 | TCollection_AsciiString aCmdName (theArgVec[0]); |
7905 | aCmdName.LowerCase(); | |
7906 | if (aCmdName == "vraytrace") | |
7907 | { | |
7908 | if (theArgNb == 1) | |
7909 | { | |
7910 | theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " "; | |
7911 | return 0; | |
7912 | } | |
7913 | else if (theArgNb == 2) | |
7914 | { | |
7915 | TCollection_AsciiString aValue (theArgVec[1]); | |
7916 | aValue.LowerCase(); | |
7917 | if (aValue == "on" | |
7918 | || aValue == "1") | |
7919 | { | |
7920 | aParams.Method = Graphic3d_RM_RAYTRACING; | |
7921 | aView->Redraw(); | |
7922 | return 0; | |
7923 | } | |
7924 | else if (aValue == "off" | |
7925 | || aValue == "0") | |
7926 | { | |
7927 | aParams.Method = Graphic3d_RM_RASTERIZATION; | |
7928 | aView->Redraw(); | |
7929 | return 0; | |
7930 | } | |
7931 | else | |
7932 | { | |
7933 | std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n"; | |
7934 | return 1; | |
7935 | } | |
7936 | } | |
7937 | else | |
7938 | { | |
7939 | std::cout << "Error: wrong number of arguments\n"; | |
7940 | return 1; | |
7941 | } | |
7942 | } | |
bc8c79bb | 7943 | |
7944 | if (theArgNb < 2) | |
e276548b | 7945 | { |
bc8c79bb | 7946 | theDI << "renderMode: "; |
7947 | switch (aParams.Method) | |
7948 | { | |
7949 | case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break; | |
7950 | case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break; | |
7951 | } | |
7952 | theDI << "\n"; | |
8625ef7e | 7953 | theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n"; |
7954 | theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n"; | |
7955 | theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n"; | |
7956 | theDI << "rayDepth: " << aParams.RaytracingDepth << "\n"; | |
7957 | theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n"; | |
7958 | theDI << "shadingModel: "; | |
7959 | switch (aView->ShadingModel()) | |
7960 | { | |
7961 | case V3d_COLOR: theDI << "color"; break; | |
7962 | case V3d_FLAT: theDI << "flat"; break; | |
7963 | case V3d_GOURAUD: theDI << "gouraud"; break; | |
7964 | case V3d_PHONG: theDI << "phong"; break; | |
7965 | } | |
7966 | theDI << "\n"; | |
bc8c79bb | 7967 | return 0; |
e276548b | 7968 | } |
7969 | ||
bc8c79bb | 7970 | Standard_Boolean toPrint = Standard_False; |
8625ef7e | 7971 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
e276548b | 7972 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
7973 | { | |
bc8c79bb | 7974 | Standard_CString anArg (theArgVec[anArgIter]); |
7975 | TCollection_AsciiString aFlag (anArg); | |
7976 | aFlag.LowerCase(); | |
8625ef7e | 7977 | if (anUpdateTool.parseRedrawMode (aFlag)) |
7978 | { | |
7979 | continue; | |
7980 | } | |
7981 | else if (aFlag == "-echo" | |
7982 | || aFlag == "-print") | |
e276548b | 7983 | { |
bc8c79bb | 7984 | toPrint = Standard_True; |
8625ef7e | 7985 | anUpdateTool.Invalidate(); |
e276548b | 7986 | } |
bc8c79bb | 7987 | else if (aFlag == "-mode" |
7988 | || aFlag == "-rendermode" | |
7989 | || aFlag == "-render_mode") | |
e276548b | 7990 | { |
bc8c79bb | 7991 | if (toPrint) |
7992 | { | |
7993 | switch (aParams.Method) | |
7994 | { | |
7995 | case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break; | |
7996 | case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break; | |
7997 | } | |
7998 | continue; | |
7999 | } | |
e276548b | 8000 | else |
bc8c79bb | 8001 | { |
8002 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
8003 | return 1; | |
8004 | } | |
8005 | } | |
8006 | else if (aFlag == "-ray" | |
8007 | || aFlag == "-raytrace") | |
8008 | { | |
8009 | if (toPrint) | |
8010 | { | |
8011 | theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " "; | |
8012 | continue; | |
8013 | } | |
8014 | ||
8015 | aParams.Method = Graphic3d_RM_RAYTRACING; | |
e276548b | 8016 | } |
bc8c79bb | 8017 | else if (aFlag == "-rast" |
8018 | || aFlag == "-raster" | |
8019 | || aFlag == "-rasterization") | |
e276548b | 8020 | { |
bc8c79bb | 8021 | if (toPrint) |
8022 | { | |
8023 | theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " "; | |
8024 | continue; | |
8025 | } | |
8026 | ||
8027 | aParams.Method = Graphic3d_RM_RASTERIZATION; | |
8028 | } | |
8029 | else if (aFlag == "-raydepth" | |
8030 | || aFlag == "-ray_depth") | |
8031 | { | |
8032 | if (toPrint) | |
8033 | { | |
8034 | theDI << aParams.RaytracingDepth << " "; | |
8035 | continue; | |
8036 | } | |
8037 | else if (++anArgIter >= theArgNb) | |
8038 | { | |
8039 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
8040 | return 1; | |
8041 | } | |
8042 | ||
8043 | const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]); | |
8044 | if (aDepth < 1 || aDepth > 10) | |
8045 | { | |
8046 | std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n"; | |
8047 | return 1; | |
8048 | } | |
e276548b | 8049 | else |
bc8c79bb | 8050 | { |
8051 | aParams.RaytracingDepth = aDepth; | |
8052 | } | |
8053 | } | |
8054 | else if (aFlag == "-shad" | |
8055 | || aFlag == "-shadows") | |
8056 | { | |
8057 | if (toPrint) | |
8058 | { | |
8059 | theDI << (aParams.IsShadowEnabled ? "on" : "off") << " "; | |
8060 | continue; | |
8061 | } | |
8062 | ||
8063 | Standard_Boolean toEnable = Standard_True; | |
8064 | if (++anArgIter < theArgNb | |
8065 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
8066 | { | |
8067 | --anArgIter; | |
8068 | } | |
8069 | aParams.IsShadowEnabled = toEnable; | |
8070 | } | |
8071 | else if (aFlag == "-refl" | |
8072 | || aFlag == "-reflections") | |
8073 | { | |
8074 | if (toPrint) | |
8075 | { | |
8076 | theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " "; | |
8077 | continue; | |
8078 | } | |
8079 | ||
8080 | Standard_Boolean toEnable = Standard_True; | |
8081 | if (++anArgIter < theArgNb | |
8082 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
8083 | { | |
8084 | --anArgIter; | |
8085 | } | |
8086 | aParams.IsReflectionEnabled = toEnable; | |
8087 | } | |
8088 | else if (aFlag == "-fsaa") | |
8089 | { | |
8090 | if (toPrint) | |
8091 | { | |
8092 | theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " "; | |
8093 | continue; | |
8094 | } | |
8095 | ||
8096 | Standard_Boolean toEnable = Standard_True; | |
8097 | if (++anArgIter < theArgNb | |
8098 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
8099 | { | |
8100 | --anArgIter; | |
8101 | } | |
8102 | aParams.IsAntialiasingEnabled = toEnable; | |
8103 | } | |
8104 | else if (aFlag == "-gleam") | |
8105 | { | |
8106 | if (toPrint) | |
8107 | { | |
8108 | theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " "; | |
8109 | continue; | |
8110 | } | |
8111 | ||
8112 | Standard_Boolean toEnable = Standard_True; | |
8113 | if (++anArgIter < theArgNb | |
8114 | && !parseOnOff (theArgVec[anArgIter], toEnable)) | |
8115 | { | |
8116 | --anArgIter; | |
8117 | } | |
8118 | aParams.IsTransparentShadowEnabled = toEnable; | |
e276548b | 8119 | } |
8625ef7e | 8120 | else if (aFlag == "-shademodel" |
8121 | || aFlag == "-shadingmodel" | |
8122 | || aFlag == "-shading") | |
8123 | { | |
8124 | if (toPrint) | |
8125 | { | |
8126 | switch (aView->ShadingModel()) | |
8127 | { | |
8128 | case V3d_COLOR: theDI << "color "; break; | |
8129 | case V3d_FLAT: theDI << "flat "; break; | |
8130 | case V3d_GOURAUD: theDI << "gouraud "; break; | |
8131 | case V3d_PHONG: theDI << "phong "; break; | |
8132 | } | |
8133 | continue; | |
8134 | } | |
8135 | ||
8136 | if (++anArgIter >= theArgNb) | |
8137 | { | |
8138 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
8139 | } | |
8140 | ||
8141 | TCollection_AsciiString aMode (theArgVec[anArgIter]); | |
8142 | aMode.LowerCase(); | |
8143 | if (aMode == "color" | |
8144 | || aMode == "none") | |
8145 | { | |
8146 | aView->SetShadingModel (V3d_COLOR); | |
8147 | } | |
8148 | else if (aMode == "flat" | |
8149 | || aMode == "facet") | |
8150 | { | |
8151 | aView->SetShadingModel (V3d_FLAT); | |
8152 | } | |
8153 | else if (aMode == "gouraud" | |
8154 | || aMode == "vertex" | |
8155 | || aMode == "vert") | |
8156 | { | |
8157 | aView->SetShadingModel (V3d_GOURAUD); | |
8158 | } | |
8159 | else if (aMode == "phong" | |
8160 | || aMode == "fragment" | |
8161 | || aMode == "frag" | |
8162 | || aMode == "pixel") | |
8163 | { | |
8164 | aView->SetShadingModel (V3d_PHONG); | |
8165 | } | |
8166 | else | |
8167 | { | |
8168 | std::cout << "Error: unknown shading model '" << aMode << "'\n"; | |
8169 | return 1; | |
8170 | } | |
8171 | } | |
e276548b | 8172 | else |
8173 | { | |
bc8c79bb | 8174 | std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n"; |
8175 | return 1; | |
e276548b | 8176 | } |
8177 | } | |
e276548b | 8178 | return 0; |
8179 | } | |
8180 | ||
b7cd4ba7 | 8181 | //======================================================================= |
8182 | //function : VFrustumCulling | |
8183 | //purpose : enables/disables view volume's culling. | |
8184 | //======================================================================= | |
8185 | static int VFrustumCulling (Draw_Interpretor& theDI, | |
8186 | Standard_Integer theArgNb, | |
8187 | const char** theArgVec) | |
8188 | { | |
8189 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
8190 | if (aView.IsNull()) | |
8191 | { | |
8192 | std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n"; | |
8193 | return 1; | |
8194 | } | |
8195 | ||
8196 | if (theArgNb < 2) | |
8197 | { | |
8198 | theDI << (aView->IsCullingEnabled() ? "on" : "off"); | |
8199 | return 0; | |
8200 | } | |
8201 | else if (theArgNb != 2) | |
8202 | { | |
8203 | std::cout << theArgVec[0] << " Syntax error: Specify the mode\n"; | |
8204 | return 1; | |
8205 | } | |
8206 | ||
8207 | TCollection_AsciiString aModeStr (theArgVec[1]); | |
8208 | aModeStr.LowerCase(); | |
8209 | Standard_Boolean toEnable = 0; | |
8210 | if (aModeStr == "on") | |
8211 | { | |
8212 | toEnable = 1; | |
8213 | } | |
8214 | else if (aModeStr == "off") | |
8215 | { | |
8216 | toEnable = 0; | |
8217 | } | |
8218 | else | |
8219 | { | |
8220 | toEnable = Draw::Atoi (theArgVec[1]) != 0; | |
8221 | } | |
8222 | ||
8223 | aView->SetFrustumCulling (toEnable); | |
8224 | aView->Redraw(); | |
8225 | return 0; | |
8226 | } | |
8227 | ||
c398b00e | 8228 | //======================================================================= |
8229 | //function : VHighlightSelected | |
8230 | //purpose : | |
8231 | //======================================================================= | |
8232 | static int VHighlightSelected (Draw_Interpretor& theDI, | |
8233 | Standard_Integer theArgNb, | |
8234 | const char** theArgVec) | |
8235 | { | |
8236 | if (ViewerTest::GetAISContext().IsNull()) | |
8237 | { | |
8238 | std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n"; | |
8239 | return 1; | |
8240 | } | |
8241 | ||
8242 | const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
8243 | ||
8244 | if (theArgNb < 2) | |
8245 | { | |
8246 | theDI << (aContext->ToHilightSelected() ? "on" : "off"); | |
8247 | return 0; | |
8248 | } | |
8249 | ||
8250 | if (theArgNb != 2) | |
8251 | { | |
8252 | std::cout << theArgVec[0] << " error : wrong number of parameters." | |
8253 | << "Type 'help" << theArgVec[0] << "' for more information."; | |
8254 | return 1; | |
8255 | } | |
8256 | ||
8257 | // Parse parameter | |
8258 | TCollection_AsciiString aMode (theArgVec[1]); | |
8259 | aMode.LowerCase(); | |
8260 | Standard_Boolean toEnable = Standard_False; | |
8261 | if (aMode.IsEqual ("on")) | |
8262 | { | |
8263 | toEnable = Standard_True; | |
8264 | } | |
8265 | else if (aMode.IsEqual ("off")) | |
8266 | { | |
8267 | toEnable = Standard_False; | |
8268 | } | |
8269 | else | |
8270 | { | |
8271 | toEnable = Draw::Atoi (theArgVec[1]) != 0; | |
8272 | } | |
8273 | ||
8274 | if (toEnable != aContext->ToHilightSelected()) | |
8275 | { | |
8276 | aContext->SetToHilightSelected (toEnable); | |
8277 | ||
8278 | // Move cursor to null position and back to process updating of detection | |
8279 | // and highlighting of selected object immediatly. | |
8280 | Standard_Integer aPixX = 0; | |
8281 | Standard_Integer aPixY = 0; | |
8282 | const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager(); | |
8283 | ||
8284 | anEventManager->GetCurrentPosition (aPixX, aPixY); | |
8285 | anEventManager->MoveTo (0, 0); | |
8286 | anEventManager->MoveTo (aPixX, aPixY); | |
8287 | } | |
8288 | ||
8289 | return 0; | |
8290 | } | |
8291 | ||
0717ddc1 | 8292 | //======================================================================= |
8293 | //function : VXRotate | |
8294 | //purpose : | |
8295 | //======================================================================= | |
8296 | static Standard_Integer VXRotate (Draw_Interpretor& di, | |
8297 | Standard_Integer argc, | |
8298 | const char ** argv) | |
8299 | { | |
8300 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
8301 | if (aContext.IsNull()) | |
8302 | { | |
8303 | di << argv[0] << "ERROR : use 'vinit' command before " << "\n"; | |
8304 | return 1; | |
8305 | } | |
8306 | ||
8307 | if (argc != 3) | |
8308 | { | |
8309 | di << "ERROR : Usage : " << argv[0] << " name angle" << "\n"; | |
8310 | return 1; | |
8311 | } | |
8312 | ||
8313 | TCollection_AsciiString aName (argv[1]); | |
8314 | Standard_Real anAngle = Draw::Atof (argv[2]); | |
8315 | ||
8316 | // find object | |
8317 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
8318 | Handle(AIS_InteractiveObject) anIObj; | |
8319 | if (!aMap.IsBound2 (aName) ) | |
8320 | { | |
8321 | di << "Use 'vdisplay' before" << "\n"; | |
8322 | return 1; | |
8323 | } | |
8324 | else | |
8325 | { | |
8326 | anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName)); | |
8327 | ||
8328 | gp_Trsf aTransform; | |
8329 | aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle); | |
8330 | aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart()); | |
8331 | ||
8332 | aContext->SetLocation (anIObj, aTransform); | |
8333 | aContext->UpdateCurrentViewer(); | |
8334 | } | |
8335 | ||
8336 | return 0; | |
8337 | } | |
8338 | ||
7fd59977 | 8339 | //======================================================================= |
8340 | //function : ViewerCommands | |
8341 | //purpose : | |
8342 | //======================================================================= | |
8343 | ||
8344 | void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) | |
8345 | { | |
8346 | ||
8347 | const char *group = "ZeViewer"; | |
18d715bd | 8348 | theCommands.Add("vinit", |
8349 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
8350 | "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n" | |
8351 | #else | |
8352 | "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n" | |
8353 | #endif | |
8354 | " - Creates new View window with specified name view_name.\n" | |
8355 | "By default the new view is created in the viewer and in" | |
8356 | " graphic driver shared with active view.\n" | |
8357 | " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n" | |
8358 | "If driverName isn't specified the driver will be shared with active view.\n" | |
8359 | "If viewerName isn't specified the viewer will be shared with active view.\n" | |
8360 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
8361 | " - display = HostName.DisplayNumber[:ScreenNumber] : if specified" | |
8362 | "is used in creation of graphic driver\n" | |
8363 | #endif | |
8364 | " - l, t: pixel position of left top corner of the window\n" | |
8365 | " - w,h: width and heigth of window respectively.\n" | |
8366 | "Additional commands for operations with views: vclose, vactivate, vviewlist.\n", | |
7fd59977 | 8367 | __FILE__,VInit,group); |
18d715bd | 8368 | theCommands.Add("vclose" , |
d0cc1cb7 | 8369 | "[view_id [keep_context=0|1]]\n" |
18d715bd | 8370 | "or vclose ALL - to remove all created views\n" |
8371 | " - removes view(viewer window) defined by its view_id.\n" | |
8372 | " - keep_context: by default 0; if 1 and the last view is deleted" | |
8373 | " the current context is not removed.", | |
8374 | __FILE__,VClose,group); | |
8375 | theCommands.Add("vactivate" , | |
8376 | "view_id" | |
8377 | " - activates view(viewer window) defined by its view_id", | |
8378 | __FILE__,VActivate,group); | |
8379 | theCommands.Add("vviewlist", | |
8380 | "vviewlist [format={tree, long}]" | |
8381 | " - prints current list of views per viewer and graphic_driver ID shared between viewers" | |
8382 | " - format: format of result output, if tree the output is a tree view;" | |
8383 | "otherwise it's a list of full view names. By default format = tree", | |
8384 | __FILE__,VViewList,group); | |
7fd59977 | 8385 | theCommands.Add("vhelp" , |
8386 | "vhelp : display help on the viewer commands", | |
8387 | __FILE__,VHelp,group); | |
8388 | theCommands.Add("vtop" , | |
44b8f2d6 | 8389 | "vtop or <T> : Top view" , |
7fd59977 | 8390 | __FILE__,VTop,group); |
44b8f2d6 | 8391 | theCommands.Add("vbottom" , |
8392 | "vbottom : Bottom view" , | |
8393 | __FILE__,VBottom,group); | |
8394 | theCommands.Add("vleft" , | |
8395 | "vleft : Left view" , | |
8396 | __FILE__,VLeft,group); | |
8397 | theCommands.Add("vright" , | |
8398 | "vright : Right view" , | |
8399 | __FILE__,VRight,group); | |
7fd59977 | 8400 | theCommands.Add("vaxo" , |
8401 | " vaxo or <A> : Axonometric view ", | |
8402 | __FILE__,VAxo,group); | |
44b8f2d6 | 8403 | theCommands.Add("vfront" , |
8404 | "vfront : Front view" , | |
8405 | __FILE__,VFront,group); | |
8406 | theCommands.Add("vback" , | |
8407 | "vback : Back view" , | |
8408 | __FILE__,VBack,group); | |
7fd59977 | 8409 | theCommands.Add("vpick" , |
8410 | "vpick : vpick X Y Z [shape subshape] ( all variables as string )", | |
8411 | VPick,group); | |
8412 | theCommands.Add("vfit" , | |
8413 | "vfit or <F> : vfit", | |
8414 | __FILE__,VFit,group); | |
6262a303 | 8415 | theCommands.Add ("vfitarea", |
8416 | "vfitarea x1 y1 x2 y2" | |
8417 | "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2" | |
8418 | "\n\t\t: Fit view to show area located between two points" | |
8419 | "\n\t\t: given in world 2D or 3D corrdinates.", | |
8420 | __FILE__, VFitArea, group); | |
197ac94e | 8421 | theCommands.Add ("vzfit", "vzfit [scale]\n" |
8422 | " Matches Z near, Z far view volume planes to the displayed objects.\n" | |
8423 | " \"scale\" - specifies factor to scale computed z range.\n", | |
8424 | __FILE__, VZFit, group); | |
7fd59977 | 8425 | theCommands.Add("vrepaint", |
8426 | "vrepaint : vrepaint, force redraw", | |
8427 | __FILE__,VRepaint,group); | |
8428 | theCommands.Add("vclear", | |
8429 | "vclear : vclear", | |
8430 | __FILE__,VClear,group); | |
8431 | theCommands.Add("vsetbg", | |
8432 | "vsetbg : vsetbg imagefile [filltype] : Load image as background", | |
8433 | __FILE__,VSetBg,group); | |
f8b2ed36 | 8434 | theCommands.Add("vsetbgmode", |
8435 | "vsetbgmode : vsetbgmode filltype : Change background image fill type", | |
8436 | __FILE__,VSetBgMode,group); | |
7fd59977 | 8437 | theCommands.Add("vsetgradientbg", |
f8b2ed36 | 8438 | "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background", |
7fd59977 | 8439 | __FILE__,VSetGradientBg,group); |
f8b2ed36 | 8440 | theCommands.Add("vsetgrbgmode", |
8441 | "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type", | |
8442 | __FILE__,VSetGradientBgMode,group); | |
8443 | theCommands.Add("vsetcolorbg", | |
8444 | "vsetcolorbg : vsetcolorbg r g b : Set background color", | |
8445 | __FILE__,VSetColorBg,group); | |
7fd59977 | 8446 | theCommands.Add("vscale", |
8447 | "vscale : vscale X Y Z", | |
8448 | __FILE__,VScale,group); | |
8449 | theCommands.Add("vzbufftrihedron", | |
536d98e2 | 8450 | "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]" |
8451 | "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]" | |
8452 | "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]" | |
8453 | "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]" | |
8454 | "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]" | |
8455 | "\n\t\t: Displays a trihedron", | |
8456 | __FILE__,VZBuffTrihedron,group); | |
7fd59977 | 8457 | theCommands.Add("vrotate", |
4af098ba | 8458 | "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]" |
8459 | "\n : Option -mouseStart starts rotation according to the mouse position" | |
8460 | "\n : Option -mouseMove continues rotation with angle computed" | |
8461 | "\n : from last and new mouse position." | |
8462 | "\n : vrotate AX AY AZ [X Y Z]", | |
7fd59977 | 8463 | __FILE__,VRotate,group); |
8464 | theCommands.Add("vzoom", | |
8465 | "vzoom : vzoom coef", | |
8466 | __FILE__,VZoom,group); | |
8467 | theCommands.Add("vpan", | |
8468 | "vpan : vpan dx dy", | |
8469 | __FILE__,VPan,group); | |
8470 | theCommands.Add("vexport", | |
5cedc27f K |
8471 | "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }" |
8472 | " : exports the view to a vector file of a given format" | |
8473 | " : notice that EMF format requires patched gl2ps", | |
7fd59977 | 8474 | __FILE__,VExport,group); |
8475 | theCommands.Add("vcolorscale", | |
71215351 | 8476 | "vcolorscale : vcolorscale [-range RangeMin = 0 RangeMax = 100 Intervals = 10 -font HeightFont = 16 -textpos " |
8477 | "Position = left -xy X = 0 Y = 0] [-noupdate|-update]: draw color scale\n" | |
8478 | "-demo/-demoversion draw a demoversion of color scale.\n" | |
8479 | "-show/display display color scale.\n" | |
8480 | "-hide/erase erase color scale.\n" | |
8481 | "Please note that -show/-hide option must be the first argument!\n" | |
8482 | "-color Index R G B: set color for indexed interval\n" | |
8483 | "-color Index ColorName: set color for indexed interval\n" | |
8484 | "-colors R G B R G B ...: set colors for all intervals\n" | |
8485 | "-colors ColorName1 ColorName2 ...: set colors for all intervals\n" | |
8486 | "-colors supports both color names and rgb values in one call\n" | |
8487 | "-label Index Text: set label for indexed interval\n" | |
8488 | "-labels Text Text Text ...: set labels for all intervals\n" | |
8489 | "-title Title [Position]: set the title for color scale with certain position. Default position = center;\n" | |
8490 | "Available text positions: left, right, center, none;\n", | |
7fd59977 | 8491 | __FILE__,VColorScale,group); |
8492 | theCommands.Add("vgraduatedtrihedron", | |
a79f67f8 | 8493 | "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n" |
8494 | "\t[-namefont Name] [-valuesfont Name]\n" | |
8495 | "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n" | |
8496 | "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]" | |
8497 | "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n" | |
8498 | "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n" | |
8499 | "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]" | |
8500 | "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n" | |
8501 | "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n" | |
8502 | "\t[-xticks Number] [-yticks Number] [-zticks Number]\n" | |
8503 | "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n" | |
536d98e2 | 8504 | "\t[-drawgrid on/off] [-drawaxes on/off]\n" |
a79f67f8 | 8505 | " - Displays or erases graduated trihedron" |
8506 | " - xname, yname, zname - names of axes, default: X, Y, Z\n" | |
8507 | " - namefont - font of axes names. Default: Arial\n" | |
8508 | " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n" | |
8509 | " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n" | |
8510 | " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n" | |
8511 | " - valuesfont - font of axes values. Default: Arial\n" | |
8512 | " - xcolor, ycolor, zcolor - color of axis and values\n" | |
8513 | " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n" | |
8514 | " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n", | |
7fd59977 | 8515 | __FILE__,VGraduatedTrihedron,group); |
7edf74fd | 8516 | theCommands.Add("vprintview" , |
b5ac8292 | 8517 | "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile", |
7edf74fd | 8518 | __FILE__,VPrintView,group); |
59f45b7c | 8519 | theCommands.Add("vzlayer", |
c5751993 | 8520 | "vzlayer add/del/get/settings/enable/disable [id]\n" |
8521 | " add - add new z layer to viewer and print its id\n" | |
8522 | " del - del z layer by its id\n" | |
8523 | " get - print sequence of z layers in increasing order of their overlay level\n" | |
8524 | " settings - print status of z layer settings\n" | |
8525 | " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n" | |
8526 | " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n" | |
8527 | " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n" | |
8528 | "\nWhere id is the layer identificator\n" | |
8529 | "\nExamples:\n" | |
8530 | " vzlayer add\n" | |
8531 | " vzlayer enable poffset 1\n" | |
8532 | " vzlayer disable depthtest 1\n" | |
8533 | " vzlayer del 1\n", | |
59f45b7c | 8534 | __FILE__,VZLayer,group); |
25289ec1 | 8535 | theCommands.Add("voverlaytext", |
8536 | "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]" | |
8537 | " : height - pixel height of the text (default=10.0)" | |
8538 | " : font_name - name of font (default=courier)" | |
8539 | " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) " | |
8540 | " : display_type = {normal/subtitle/decal/blend}, (default=normal) " | |
8541 | " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ", | |
8542 | __FILE__,VOverlayText,group); | |
20637bd2 | 8543 | theCommands.Add("vlayerline", |
8544 | "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]", | |
8545 | __FILE__,VLayerLine,group); | |
2bd4c032 | 8546 | theCommands.Add ("vgrid", |
8547 | "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]" | |
8548 | " : Mode - rectangular or circular" | |
8549 | " : Type - lines or points", | |
8550 | __FILE__, VGrid, group); | |
c40b7d58 | 8551 | theCommands.Add ("vpriviledgedplane", |
8552 | "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]" | |
8553 | "\n\t\t: Ox, Oy, Oz - plane origin" | |
8554 | "\n\t\t: Nx, Ny, Nz - plane normal direction" | |
8555 | "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction" | |
8556 | "\n\t\t: Sets or prints viewer's priviledged plane geometry.", | |
8557 | __FILE__, VPriviledgedPlane, group); | |
f25b82d6 | 8558 | theCommands.Add ("vconvert", |
8559 | "vconvert v [Mode={window|view}]" | |
8560 | "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]" | |
8561 | "\n\t\t: vconvert x y z [Mode={window|grid}]" | |
8562 | "\n\t\t: window - convert to window coordinates, pixels" | |
8563 | "\n\t\t: view - convert to view projection plane" | |
8564 | "\n\t\t: grid - convert to model coordinates, given on grid" | |
8565 | "\n\t\t: ray - convert projection ray to model coordiantes" | |
8566 | "\n\t\t: - vconvert v window : convert view to window;" | |
8567 | "\n\t\t: - vconvert v view : convert window to view;" | |
8568 | "\n\t\t: - vconvert x y window : convert view to window;" | |
8569 | "\n\t\t: - vconvert x y view : convert window to view;" | |
8570 | "\n\t\t: - vconvert x y : convert window to model;" | |
8571 | "\n\t\t: - vconvert x y grid : convert window to model using grid;" | |
8572 | "\n\t\t: - vconvert x y ray : convert window projection line to model;" | |
8573 | "\n\t\t: - vconvert x y z window : convert model to window;" | |
8574 | "\n\t\t: - vconvert x y z grid : convert view to model using grid;" | |
8575 | "\n\t\t: Converts the given coordinates to window/view/model space.", | |
8576 | __FILE__, VConvert, group); | |
208e6839 | 8577 | theCommands.Add ("vfps", |
8578 | "vfps [framesNb=100] : estimate average frame rate for active view", | |
8579 | __FILE__, VFps, group); | |
58655684 | 8580 | theCommands.Add ("vgldebug", |
c87535af | 8581 | "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]" |
8582 | "\n\t\t: [-extraMsg {0|1}] [{0|1}]" | |
8583 | "\n\t\t: Request debug GL context. Should be called BEFORE vinit." | |
8584 | "\n\t\t: Debug context can be requested only on Windows" | |
8585 | "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!" | |
8586 | "\n\t\t: -sync - request synchronized debug GL context" | |
8587 | "\n\t\t: -glslWarn - log GLSL compiler/linker warnings," | |
8588 | "\n\t\t: which are suppressed by default," | |
8589 | "\n\t\t: -extraMsg - log extra diagnostic messages from GL context," | |
8590 | "\n\t\t: which are suppressed by default", | |
58655684 | 8591 | __FILE__, VGlDebug, group); |
208e6839 | 8592 | theCommands.Add ("vvbo", |
58655684 | 8593 | "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects", |
208e6839 | 8594 | __FILE__, VVbo, group); |
b5ac8292 | 8595 | theCommands.Add ("vstereo", |
8596 | "\nvstereo [{0|1}] : turn stereo usage On/Off; affects only newly displayed objects", | |
8597 | __FILE__, VStereo, group); | |
a577aaab | 8598 | theCommands.Add ("vcaps", |
8625ef7e | 8599 | "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]" |
4e1523ef | 8600 | "\n\t\t: [-compatibleContext {0|1}]" |
8625ef7e | 8601 | "\n\t\t: [-softMode {0|1}] [-noupdate|-update]" |
8602 | "\n\t\t: Modify particular graphic driver options:" | |
8603 | "\n\t\t: FFP - use fixed-function pipeline instead of" | |
8604 | "\n\t\t: built-in GLSL programs" | |
4e1523ef | 8605 | "\n\t\t: (requires compatible profile)" |
8625ef7e | 8606 | "\n\t\t: VBO - use Vertex Buffer Object (copy vertex" |
8607 | "\n\t\t: arrays to GPU memory)" | |
8608 | "\n\t\t: sprite - use textured sprites instead of bitmaps" | |
4e1523ef | 8609 | "\n\t\t: Context creation options:" |
8610 | "\n\t\t: softMode - software OpenGL implementation" | |
8611 | "\n\t\t: compatibleProfile - backward-compatible profile" | |
8625ef7e | 8612 | "\n\t\t: Unlike vrenderparams, these parameters control alternative" |
8613 | "\n\t\t: rendering paths producing the same visual result when" | |
8614 | "\n\t\t: possible." | |
8615 | "\n\t\t: Command is intended for testing old hardware compatibility.", | |
a577aaab | 8616 | __FILE__, VCaps, group); |
f0430952 | 8617 | theCommands.Add ("vmemgpu", |
8618 | "vmemgpu [f]: print system-dependent GPU memory information if available;" | |
8619 | " with f option returns free memory in bytes", | |
8620 | __FILE__, VMemGpu, group); | |
85e096c3 | 8621 | theCommands.Add ("vreadpixel", |
8622 | "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]" | |
8623 | " : Read pixel value for active view", | |
8624 | __FILE__, VReadPixel, group); | |
692613e5 | 8625 | theCommands.Add("diffimage", |
8626 | "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]", | |
8627 | __FILE__, VDiffImage, group); | |
4754e164 | 8628 | theCommands.Add ("vselect", |
8629 | "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n" | |
8630 | "- emulates different types of selection:\n" | |
8631 | "- 1) single click selection\n" | |
8632 | "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n" | |
8633 | "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n" | |
8634 | "- 4) any of these selections with shift button pressed", | |
8635 | __FILE__, VSelect, group); | |
8636 | theCommands.Add ("vmoveto", | |
8637 | "vmoveto x y" | |
8638 | "- emulates cursor movement to pixel postion (x,y)", | |
8639 | __FILE__, VMoveTo, group); | |
197ac94e | 8640 | theCommands.Add ("vviewparams", "vviewparams usage:\n" |
8641 | "- vviewparams\n" | |
8642 | "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n" | |
3dfe95cd | 8643 | " [-proj [x y z]] [-center x y] [-size sx]\n" |
197ac94e | 8644 | "- Gets or sets current view parameters.\n" |
8645 | "- If called without arguments, all view parameters are printed.\n" | |
8646 | "- The options are:\n" | |
3dfe95cd | 8647 | " -scale [s] : prints or sets viewport relative scale.\n" |
197ac94e | 8648 | " -eye [x y z] : prints or sets eye location.\n" |
8649 | " -at [x y z] : prints or sets center of look.\n" | |
8650 | " -up [x y z] : prints or sets direction of up vector.\n" | |
8651 | " -proj [x y z] : prints or sets direction of look.\n" | |
3dfe95cd | 8652 | " -center x y : sets location of center of the screen in pixels.\n" |
8653 | " -size [sx] : prints viewport projection width and height sizes\n" | |
8654 | " : or changes the size of its maximum dimension.\n", | |
197ac94e | 8655 | __FILE__, VViewParams, group); |
4754e164 | 8656 | theCommands.Add("vchangeselected", |
dc3fe572 | 8657 | "vchangeselected shape" |
4754e164 | 8658 | "- adds to shape to selection or remove one from it", |
8659 | __FILE__, VChangeSelected, group); | |
8660 | theCommands.Add("vzclipping", | |
8661 | "vzclipping [mode] [depth width]\n" | |
8662 | "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n" | |
8663 | "- gets or sets ZClipping mode, width and depth", | |
8664 | __FILE__,VZClipping,group); | |
8665 | theCommands.Add ("vnbselected", | |
8666 | "vnbselected", __FILE__, VNbSelected, group); | |
6b62b2da | 8667 | theCommands.Add ("vcamera", |
8668 | "vcamera [-ortho] [-projtype]" | |
8669 | "\n\t\t: [-persp]" | |
8670 | "\n\t\t: [-fovy [Angle]] [-distance [Distance]]" | |
8671 | "\n\t\t: [-stereo] [-leftEye] [-rightEye]" | |
8672 | "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]" | |
8673 | "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]" | |
8674 | "\n\t\t: Manage camera parameters." | |
8675 | "\n\t\t: Prints current value when option called without argument." | |
8676 | "\n\t\t: Orthographic camera:" | |
8677 | "\n\t\t: -ortho activate orthographic projection" | |
8678 | "\n\t\t: Perspective camera:" | |
8679 | "\n\t\t: -persp activate perspective projection (mono)" | |
8680 | "\n\t\t: -fovy field of view in y axis, in degrees" | |
8681 | "\n\t\t: -distance distance of eye from camera center" | |
8682 | "\n\t\t: Stereoscopic camera:" | |
8683 | "\n\t\t: -stereo perspective projection (stereo)" | |
8684 | "\n\t\t: -leftEye perspective projection (left eye)" | |
8685 | "\n\t\t: -rightEye perspective projection (right eye)" | |
8686 | "\n\t\t: -iod intraocular distance value" | |
8687 | "\n\t\t: -iodType distance type, absolute or relative" | |
8688 | "\n\t\t: -zfocus stereographic focus value" | |
8689 | "\n\t\t: -zfocusType focus type, absolute or relative", | |
8690 | __FILE__, VCamera, group); | |
b5ac8292 | 8691 | theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n" |
197ac94e | 8692 | "- vautozfit [on={1|0}] [scale]\n" |
8693 | " Prints or changes parameters of automatic z-fit mode:\n" | |
8694 | " \"on\" - turns automatic z-fit on or off\n" | |
8695 | " \"scale\" - specifies factor to scale computed z range.\n", | |
8696 | __FILE__, VAutoZFit, group); | |
b5ac8292 | 8697 | theCommands.Add ("vzrange", "command to manually access znear and zfar values\n" |
8698 | " vzrange - without parameters shows current values\n" | |
8699 | " vzrange [znear] [zfar] - applies provided values to view", | |
8700 | __FILE__,VZRange, group); | |
4754e164 | 8701 | theCommands.Add("vantialiasing", |
8702 | "vantialiasing 1|0", | |
8703 | __FILE__,VAntialiasing,group); | |
8704 | theCommands.Add ("vpurgedisplay", | |
eb4320f2 | 8705 | "vpurgedisplay" |
4754e164 | 8706 | "- removes structures which don't belong to objects displayed in neutral point", |
8707 | __FILE__, VPurgeDisplay, group); | |
8708 | theCommands.Add("vsetviewsize", | |
8709 | "vsetviewsize size", | |
8710 | __FILE__,VSetViewSize,group); | |
8711 | theCommands.Add("vmoveview", | |
8712 | "vmoveview Dx Dy Dz [Start = 1|0]", | |
8713 | __FILE__,VMoveView,group); | |
8714 | theCommands.Add("vtranslateview", | |
8715 | "vtranslateview Dx Dy Dz [Start = 1|0)]", | |
8716 | __FILE__,VTranslateView,group); | |
8717 | theCommands.Add("vturnview", | |
8718 | "vturnview Ax Ay Az [Start = 1|0]", | |
8719 | __FILE__,VTurnView,group); | |
269294d6 | 8720 | theCommands.Add("vtextureenv", |
8721 | "Enables or disables environment mapping in the 3D view, loading the texture from the given standard " | |
8722 | "or user-defined file and optionally applying texture mapping parameters\n" | |
8723 | " Usage:\n" | |
8724 | " vtextureenv off - disables environment mapping\n" | |
8725 | " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n" | |
8726 | " std_texture = (0..7)\n" | |
8727 | " rep = {clamp|repeat}\n" | |
8728 | " mod = {decal|modulate}\n" | |
8729 | " flt = {nearest|bilinear|trilinear}\n" | |
8730 | " ss, st - scale factors for s and t texture coordinates\n" | |
8731 | " ts, tt - translation for s and t texture coordinates\n" | |
8732 | " rot - texture rotation angle in degrees", | |
8733 | __FILE__, VTextureEnv, group); | |
0a768f56 | 8734 | theCommands.Add("vhlr" , |
e9224045 | 8735 | "is_enabled={on|off} [show_hidden={1|0}]" |
0a768f56 | 8736 | " - Hidden line removal algorithm:" |
e9224045 | 8737 | " - is_enabled: if is on HLR algorithm is applied\n" |
8738 | " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n", | |
0a768f56 | 8739 | __FILE__,VHLR,group); |
8740 | theCommands.Add("vhlrtype" , | |
8741 | "algo_type={algo|polyalgo} [shape_1 ... shape_n]" | |
8742 | " - Changes the type of HLR algorithm using for shapes." | |
8743 | " - algo_type: if equals to algo, exact HLR algorithm is applied;\n" | |
8744 | " if equals to polyalgo, polygonal HLR algorithm is applied." | |
8745 | "If shapes are not given HLR algoithm of given type is applied" | |
8746 | " to all shapes in the view\n", | |
8747 | __FILE__,VHLRType,group); | |
4269bd1b | 8748 | theCommands.Add("vclipplane", "vclipplane usage: \n" |
8749 | " maxplanes <view_name> - get plane limit for view.\n" | |
8750 | " create <plane_name> - create new plane.\n" | |
8751 | " delete <plane_name> - delete plane.\n" | |
8752 | " clone <source_plane> <plane_name> - clone the plane definition.\n" | |
8753 | " set/unset <plane_name> object <object list> - set/unset plane for IO.\n" | |
8754 | " set/unset <plane_name> view <view list> - set/unset plane for view.\n" | |
8755 | " change <plane_name> on/off - turn clipping on/off.\n" | |
8756 | " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n" | |
8757 | " change <plane_name> capping on/off - turn capping on/off.\n" | |
8758 | " change <plane_name> capping color <r> <g> <b> - set color.\n" | |
8759 | " change <plane name> capping texname <texture> - set texture.\n" | |
8760 | " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n" | |
8761 | " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n" | |
8762 | " change <plane_name> capping texrotate <angle> - set tex rotation.\n" | |
8763 | " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n" | |
8764 | " please use VSetTextureMode command to enable texture rendering in view.\n" | |
8765 | , __FILE__, VClipPlane, group); | |
8766 | theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n" | |
8767 | " mode can be:\n" | |
8768 | " 0 - no textures enabled in view.\n" | |
8769 | " 1 - only environment textures enabled.\n" | |
8770 | " 2 - all textures enabled.\n" | |
8771 | " this command sets texture details mode for the specified view.\n" | |
8772 | , __FILE__, VSetTextureMode, group); | |
392ac980 | 8773 | theCommands.Add("vdefaults", |
4c513386 | 8774 | "vdefaults [-absDefl value]" |
8775 | "\n\t\t: [-devCoeff value]" | |
8776 | "\n\t\t: [-angDefl value]" | |
8777 | "\n\t\t: [-autoTriang {off/on | 0/1}]" | |
8778 | , __FILE__, VDefaults, group); | |
12381341 | 8779 | theCommands.Add("vlight", |
816d03ee | 8780 | "tool to manage light sources, without arguments shows list of lights." |
8781 | "\n Main commands: " | |
8782 | "\n 'clear' to clear lights" | |
8783 | "\n '{def}aults' to load deafault lights" | |
8784 | "\n 'add' (or 'new') <type> to add any light source" | |
8785 | "\n where <type> is one of {amb}ient|directional|{spot}light|positional" | |
8786 | "\n 'change' <lightId> to edit light source with specified lightId" | |
8787 | "\n\n In addition to 'add' and 'change' commands you can use light parameters:" | |
8788 | "\n {pos}ition X Y Z" | |
8789 | "\n {dir}ection X Y Z (for directional light or for spotlight)" | |
8790 | "\n color colorName" | |
8791 | "\n {head}light 0|1" | |
8792 | "\n {constAtten}uation value" | |
8793 | "\n {linearAtten}uation value" | |
8794 | "\n angle angleDeg" | |
8795 | "\n {spotexp}onent value" | |
8796 | "\n local|global" | |
8797 | "\n\n example: vlight add positional head 1 pos 0 1 1 color red" | |
8798 | "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2", | |
12381341 | 8799 | __FILE__, VLight, group); |
6b62b2da | 8800 | theCommands.Add("vraytrace", |
8801 | "vraytrace [0|1]" | |
8802 | "\n\t\t: Turn on/off raytracing renderer." | |
8803 | "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'." | |
8804 | "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.", | |
8805 | __FILE__, VRenderParams, group); | |
bc8c79bb | 8806 | theCommands.Add("vrenderparams", |
8807 | "\n Manages rendering parameters: " | |
8625ef7e | 8808 | "\n '-rayTrace' Enables GPU ray-tracing" |
8809 | "\n '-raster' Disables GPU ray-tracing" | |
8810 | "\n '-rayDepth 0..10' Defines maximum ray-tracing depth" | |
8811 | "\n '-shadows on|off' Enables/disables shadows rendering" | |
8812 | "\n '-reflections on|off' Enables/disables specular reflections" | |
8813 | "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing" | |
8814 | "\n '-gleam on|off' Enables/disables transparency shadow effects" | |
8815 | "\n '-shadingModel model' Controls shading model from enumeration" | |
8816 | "\n color, flat, gouraud, phong" | |
8817 | "\n Unlike vcaps, these parameters dramatically change visual properties." | |
8818 | "\n Command is intended to control presentation quality depending on" | |
8819 | "\n hardware capabilities and performance.", | |
bc8c79bb | 8820 | __FILE__, VRenderParams, group); |
b7cd4ba7 | 8821 | theCommands.Add("vfrustumculling", |
8822 | "vfrustumculling [toEnable]: enables/disables objects clipping", | |
8823 | __FILE__,VFrustumCulling,group); | |
c398b00e | 8824 | theCommands.Add("vhighlightselected", |
8825 | "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n" | |
8826 | "Without arguments it shows if highlighting of selected objects is enabled now.", | |
8827 | __FILE__,VHighlightSelected,group); | |
49e1a5c7 | 8828 | theCommands.Add ("vplace", |
8829 | "vplace dx dy" | |
8830 | "\n\t\t: Places the point (in pixels) at the center of the window", | |
8831 | __FILE__, VPlace, group); | |
0717ddc1 | 8832 | theCommands.Add("vxrotate", |
8833 | "vxrotate", | |
8834 | __FILE__,VXRotate,group); | |
8835 | ||
7fd59977 | 8836 | } |