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> |
1beb58d7 | 18 | |
19 | #include <AIS_Animation.hxx> | |
20 | #include <AIS_AnimationCamera.hxx> | |
21 | #include <AIS_AnimationObject.hxx> | |
7a324550 | 22 | #include <AIS_ColorScale.hxx> |
625e1958 | 23 | #include <AIS_Manipulator.hxx> |
b12e1c7b | 24 | #include <AIS_RubberBand.hxx> |
0a768f56 | 25 | #include <AIS_Shape.hxx> |
0a768f56 | 26 | #include <AIS_InteractiveObject.hxx> |
27 | #include <AIS_ListOfInteractive.hxx> | |
28 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
29 | #include <DBRep.hxx> | |
61b0191c | 30 | #include <Graphic3d_ArrayOfPolylines.hxx> |
2bd4c032 | 31 | #include <Graphic3d_AspectMarker3d.hxx> |
7fd59977 | 32 | #include <Graphic3d_ExportFormat.hxx> |
269294d6 | 33 | #include <Graphic3d_NameOfTextureEnv.hxx> |
a79f67f8 | 34 | #include <Graphic3d_GraduatedTrihedron.hxx> |
269294d6 | 35 | #include <Graphic3d_TextureEnv.hxx> |
36 | #include <Graphic3d_TextureParams.hxx> | |
37 | #include <Graphic3d_TypeOfTextureFilter.hxx> | |
4269bd1b | 38 | #include <Graphic3d_AspectFillArea3d.hxx> |
7fd59977 | 39 | #include <ViewerTest.hxx> |
8625ef7e | 40 | #include <ViewerTest_AutoUpdater.hxx> |
7fd59977 | 41 | #include <ViewerTest_EventManager.hxx> |
4754e164 | 42 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> |
4269bd1b | 43 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> |
625e1958 | 44 | #include <ViewerTest_CmdParser.hxx> |
12381341 | 45 | #include <V3d_AmbientLight.hxx> |
46 | #include <V3d_DirectionalLight.hxx> | |
12381341 | 47 | #include <V3d_PositionalLight.hxx> |
48 | #include <V3d_SpotLight.hxx> | |
18d715bd | 49 | #include <NCollection_DoubleMap.hxx> |
50 | #include <NCollection_List.hxx> | |
51 | #include <NCollection_Vector.hxx> | |
7fd59977 | 52 | #include <AIS_InteractiveContext.hxx> |
53 | #include <Draw_Interpretor.hxx> | |
54 | #include <Draw.hxx> | |
55 | #include <Draw_Appli.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 <Aspect_TypeOfLine.hxx> |
692613e5 | 65 | #include <Image_Diff.hxx> |
dc3fe572 | 66 | #include <Aspect_DisplayConnection.hxx> |
4269bd1b | 67 | #include <gp_Pnt.hxx> |
68 | #include <gp_Dir.hxx> | |
69 | #include <gp_Pln.hxx> | |
70 | #include <PrsMgr_PresentableObject.hxx> | |
71 | #include <Graphic3d_ClipPlane.hxx> | |
72 | #include <NCollection_DataMap.hxx> | |
73 | #include <Graphic3d_Texture2Dmanual.hxx> | |
74 | #include <Prs3d_ShadingAspect.hxx> | |
6262338c | 75 | #include <Prs3d_Drawer.hxx> |
61b0191c | 76 | #include <Prs3d_LineAspect.hxx> |
77 | #include <Prs3d_Root.hxx> | |
7fd59977 | 78 | |
57c28b61 | 79 | #ifdef _WIN32 |
25289ec1 | 80 | #undef DrawText |
81 | #endif | |
82 | ||
692613e5 | 83 | #include <cstdlib> |
25289ec1 | 84 | |
58655684 | 85 | #if defined(_WIN32) |
4fe56619 | 86 | #include <WNT_WClass.hxx> |
87 | #include <WNT_Window.hxx> | |
4fe56619 | 88 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
4fe56619 | 89 | #include <Cocoa_Window.hxx> |
7fd59977 | 90 | #else |
4fe56619 | 91 | #include <Xw_Window.hxx> |
92 | #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */ | |
93 | #include <X11/Xutil.h> | |
94 | #include <tk.h> | |
7fd59977 | 95 | #endif |
96 | ||
b514beda | 97 | // Auxiliary definitions |
98 | static const char THE_KEY_DELETE = 127; | |
7fd59977 | 99 | |
100 | //============================================================================== | |
101 | // VIEWER GLOBAL VARIABLES | |
102 | //============================================================================== | |
103 | ||
104 | Standard_IMPORT Standard_Boolean Draw_VirtualWindows; | |
b514beda | 105 | Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand); |
7fd59977 | 106 | |
107 | Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv); | |
4754e164 | 108 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
7fd59977 | 109 | |
b514beda | 110 | extern int VErase (Draw_Interpretor& theDI, |
111 | Standard_Integer theArgNb, | |
112 | const char** theArgVec); | |
113 | ||
58655684 | 114 | #if defined(_WIN32) |
7fd59977 | 115 | static Handle(WNT_Window)& VT_GetWindow() { |
116 | static Handle(WNT_Window) WNTWin; | |
117 | return WNTWin; | |
118 | } | |
4fe56619 | 119 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
4fe56619 | 120 | static Handle(Cocoa_Window)& VT_GetWindow() |
121 | { | |
122 | static Handle(Cocoa_Window) aWindow; | |
123 | return aWindow; | |
124 | } | |
125 | extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow); | |
18d715bd | 126 | extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle); |
127 | extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight); | |
128 | ||
7fd59977 | 129 | #else |
7fd59977 | 130 | static Handle(Xw_Window)& VT_GetWindow(){ |
131 | static Handle(Xw_Window) XWWin; | |
132 | return XWWin; | |
133 | } | |
7fd59977 | 134 | |
135 | static void VProcessEvents(ClientData,int); | |
136 | #endif | |
137 | ||
18d715bd | 138 | static Handle(Aspect_DisplayConnection)& GetDisplayConnection() |
139 | { | |
140 | static Handle(Aspect_DisplayConnection) aDisplayConnection; | |
141 | return aDisplayConnection; | |
142 | } | |
143 | ||
144 | static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection) | |
145 | { | |
146 | GetDisplayConnection() = theDisplayConnection; | |
147 | } | |
148 | ||
58655684 | 149 | #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
18d715bd | 150 | Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow) |
dc3fe572 | 151 | { |
0ebaa4db | 152 | Aspect_Handle aWindowHandle = (Aspect_Handle)NULL; |
58655684 | 153 | #if defined(_WIN32) |
18d715bd | 154 | const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow); |
155 | if (!aWindow.IsNull()) | |
156 | return aWindow->HWindow(); | |
157 | #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
158 | const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow); | |
159 | if (!aWindow.IsNull()) | |
160 | return aWindow->XWindow(); | |
161 | #endif | |
162 | return aWindowHandle; | |
dc3fe572 | 163 | } |
18d715bd | 164 | #endif |
dc3fe572 | 165 | |
de75ed09 | 166 | static Standard_Boolean MyHLRIsOn = Standard_False; |
7fd59977 | 167 | |
18d715bd | 168 | NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews; |
58655684 | 169 | static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts; |
18d715bd | 170 | static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers; |
58655684 | 171 | static OpenGl_Caps ViewerTest_myDefaultCaps; |
18d715bd | 172 | |
7fd59977 | 173 | static void OSWindowSetup(); |
174 | ||
f42753ed | 175 | static struct |
176 | { | |
177 | Quantity_Color FlatColor; | |
178 | Quantity_Color GradientColor1; | |
179 | Quantity_Color GradientColor2; | |
180 | Aspect_GradientFillMethod FillMethod; | |
181 | } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE }; | |
182 | ||
7fd59977 | 183 | //============================================================================== |
184 | // EVENT GLOBAL VARIABLES | |
185 | //============================================================================== | |
186 | ||
187 | static int Start_Rot = 0; | |
4fe56619 | 188 | int X_Motion = 0; // Current cursor position |
189 | int Y_Motion = 0; | |
190 | int X_ButtonPress = 0; // Last ButtonPress position | |
191 | int Y_ButtonPress = 0; | |
192 | Standard_Boolean IsDragged = Standard_False; | |
8abada55 | 193 | Standard_Boolean DragFirst = Standard_False; |
1beb58d7 | 194 | Standard_Boolean TheIsAnimating = Standard_False; |
7fd59977 | 195 | |
b12e1c7b | 196 | |
197 | Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand() | |
198 | { | |
199 | static Handle(AIS_RubberBand) aBand; | |
200 | if (aBand.IsNull()) | |
201 | { | |
69adb9ce | 202 | aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0); |
203 | aBand->SetDisplayMode (0); | |
b12e1c7b | 204 | } |
205 | return aBand; | |
206 | } | |
207 | ||
625e1958 | 208 | typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators; |
209 | ||
210 | Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators() | |
211 | { | |
212 | static ViewerTest_MapOfAISManipulators aMap; | |
213 | return aMap; | |
214 | } | |
215 | ||
216 | Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator() | |
217 | { | |
218 | ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators()); | |
219 | for (; anIt.More(); anIt.Next()) | |
220 | { | |
221 | if (anIt.Value()->HasActiveMode()) | |
222 | { | |
223 | return anIt.Value(); | |
224 | } | |
225 | } | |
226 | return NULL; | |
227 | } | |
228 | ||
7fd59977 | 229 | //============================================================================== |
230 | ||
57c28b61 | 231 | #ifdef _WIN32 |
7fd59977 | 232 | static LRESULT WINAPI ViewerWindowProc( |
233 | HWND hwnd, | |
234 | UINT uMsg, | |
235 | WPARAM wParam, | |
236 | LPARAM lParam ); | |
237 | static LRESULT WINAPI AdvViewerWindowProc( | |
238 | HWND hwnd, | |
239 | UINT uMsg, | |
240 | WPARAM wParam, | |
241 | LPARAM lParam ); | |
242 | #endif | |
243 | ||
244 | ||
245 | //============================================================================== | |
246 | //function : WClass | |
247 | //purpose : | |
248 | //============================================================================== | |
249 | ||
ad03c234 | 250 | const Handle(Standard_Transient)& ViewerTest::WClass() |
7fd59977 | 251 | { |
ad03c234 | 252 | static Handle(Standard_Transient) theWClass; |
58655684 | 253 | #if defined(_WIN32) |
4fe56619 | 254 | if (theWClass.IsNull()) |
255 | { | |
7c65581d | 256 | theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc, |
ad03c234 | 257 | CS_VREDRAW | CS_HREDRAW, 0, 0, |
258 | ::LoadCursorW (NULL, IDC_ARROW)); | |
7fd59977 | 259 | } |
260 | #endif | |
261 | return theWClass; | |
262 | } | |
263 | ||
18d715bd | 264 | //============================================================================== |
265 | //function : CreateName | |
266 | //purpose : Create numerical name for new object in theMap | |
267 | //============================================================================== | |
268 | template <typename ObjectType> | |
269 | TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap, | |
270 | const TCollection_AsciiString& theDefaultString) | |
271 | { | |
272 | if (theObjectMap.IsEmpty()) | |
273 | return theDefaultString + TCollection_AsciiString(1); | |
274 | ||
275 | Standard_Integer aNextKey = 1; | |
276 | Standard_Boolean isFound = Standard_False; | |
277 | while (!isFound) | |
278 | { | |
279 | TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey); | |
280 | // Look for objects with default names | |
281 | if (theObjectMap.IsBound1(aStringKey)) | |
282 | { | |
283 | aNextKey++; | |
284 | } | |
285 | else | |
286 | isFound = Standard_True; | |
287 | } | |
288 | ||
289 | return theDefaultString + TCollection_AsciiString(aNextKey); | |
290 | } | |
291 | ||
292 | //============================================================================== | |
293 | //structure : ViewerTest_Names | |
294 | //purpose : Allow to operate with full view name: driverName/viewerName/viewName | |
295 | //============================================================================== | |
296 | struct ViewerTest_Names | |
297 | { | |
298 | private: | |
299 | TCollection_AsciiString myDriverName; | |
300 | TCollection_AsciiString myViewerName; | |
301 | TCollection_AsciiString myViewName; | |
302 | ||
303 | public: | |
304 | ||
305 | const TCollection_AsciiString& GetDriverName () const | |
306 | { | |
307 | return myDriverName; | |
308 | } | |
309 | void SetDriverName (const TCollection_AsciiString& theDriverName) | |
310 | { | |
311 | myDriverName = theDriverName; | |
312 | } | |
313 | const TCollection_AsciiString& GetViewerName () const | |
314 | { | |
315 | return myViewerName; | |
316 | } | |
317 | void SetViewerName (const TCollection_AsciiString& theViewerName) | |
318 | { | |
319 | myViewerName = theViewerName; | |
320 | } | |
321 | const TCollection_AsciiString& GetViewName () const | |
322 | { | |
323 | return myViewName; | |
324 | } | |
325 | void SetViewName (const TCollection_AsciiString& theViewName) | |
326 | { | |
327 | myViewName = theViewName; | |
328 | } | |
329 | ||
330 | //=========================================================================== | |
331 | //function : Constructor for ViewerTest_Names | |
332 | //purpose : Get view, viewer, driver names from custom string | |
333 | //=========================================================================== | |
334 | ||
335 | ViewerTest_Names (const TCollection_AsciiString& theInputString) | |
336 | { | |
337 | TCollection_AsciiString aName(theInputString); | |
338 | if (theInputString.IsEmpty()) | |
339 | { | |
340 | // Get current configuration | |
341 | if (ViewerTest_myDrivers.IsEmpty()) | |
342 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
343 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
344 | else | |
345 | myDriverName = ViewerTest_myDrivers.Find2 | |
346 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
347 | ||
348 | if(ViewerTest_myContexts.IsEmpty()) | |
349 | { | |
350 | myViewerName = CreateName <Handle(AIS_InteractiveContext)> | |
351 | (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer")); | |
352 | } | |
353 | else | |
354 | myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext()); | |
355 | ||
356 | myViewName = CreateName <Handle(V3d_View)> | |
357 | (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View")); | |
358 | } | |
359 | else | |
360 | { | |
361 | // There is at least view name | |
362 | Standard_Integer aParserNumber = 0; | |
363 | for (Standard_Integer i = 0; i < 3; ++i) | |
364 | { | |
365 | Standard_Integer aParserPos = aName.SearchFromEnd("/"); | |
366 | if(aParserPos != -1) | |
367 | { | |
368 | aParserNumber++; | |
369 | aName.Split(aParserPos-1); | |
370 | } | |
371 | else | |
372 | break; | |
373 | } | |
374 | if (aParserNumber == 0) | |
375 | { | |
376 | // Only view name | |
377 | if (!ViewerTest::GetAISContext().IsNull()) | |
378 | { | |
379 | myDriverName = ViewerTest_myDrivers.Find2 | |
380 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
381 | myViewerName = ViewerTest_myContexts.Find2 | |
382 | (ViewerTest::GetAISContext()); | |
383 | } | |
384 | else | |
385 | { | |
386 | // There is no opened contexts here, need to create names for viewer and driver | |
387 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
388 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
389 | ||
390 | myViewerName = CreateName <Handle(AIS_InteractiveContext)> | |
391 | (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer")); | |
392 | } | |
393 | myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString); | |
394 | } | |
395 | else if (aParserNumber == 1) | |
396 | { | |
397 | // Here is viewerName/viewName | |
398 | if (!ViewerTest::GetAISContext().IsNull()) | |
399 | myDriverName = ViewerTest_myDrivers.Find2 | |
400 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
401 | else | |
402 | { | |
403 | // There is no opened contexts here, need to create name for driver | |
404 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
405 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
406 | } | |
407 | myViewerName = TCollection_AsciiString(myDriverName + "/" + aName); | |
408 | ||
409 | myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString); | |
410 | } | |
411 | else | |
412 | { | |
413 | //Here is driverName/viewerName/viewName | |
414 | myDriverName = TCollection_AsciiString(aName); | |
415 | ||
416 | TCollection_AsciiString aViewerName(theInputString); | |
417 | aViewerName.Split(aViewerName.SearchFromEnd("/") - 1); | |
418 | myViewerName = TCollection_AsciiString(aViewerName); | |
419 | ||
420 | myViewName = TCollection_AsciiString(theInputString); | |
421 | } | |
422 | } | |
423 | } | |
424 | }; | |
425 | ||
426 | //============================================================================== | |
427 | //function : FindContextByView | |
428 | //purpose : Find AIS_InteractiveContext by View | |
429 | //============================================================================== | |
430 | ||
431 | Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView) | |
432 | { | |
433 | Handle(AIS_InteractiveContext) anAISContext; | |
434 | ||
435 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
436 | anIter (ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
437 | { | |
438 | if (anIter.Value()->CurrentViewer() == theView->Viewer()) | |
439 | return anIter.Key2(); | |
440 | } | |
441 | return anAISContext; | |
442 | } | |
443 | ||
444 | ||
445 | //============================================================================== | |
446 | //function : SetWindowTitle | |
447 | //purpose : Set window title | |
448 | //============================================================================== | |
449 | ||
450 | void SetWindowTitle (const Handle(Aspect_Window)& theWindow, | |
451 | Standard_CString theTitle) | |
452 | { | |
58655684 | 453 | #if defined(_WIN32) |
ad03c234 | 454 | const TCollection_ExtendedString theTitleW (theTitle); |
455 | SetWindowTextW ((HWND )Handle(WNT_Window)::DownCast(theWindow)->HWindow(), theTitleW.ToWideString()); | |
18d715bd | 456 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
457 | SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle); | |
458 | #else | |
459 | if(GetDisplayConnection()->GetDisplay()) | |
460 | { | |
461 | Window aWindow = | |
462 | Handle(Xw_Window)::DownCast(theWindow)->XWindow(); | |
463 | XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle); | |
464 | } | |
465 | #endif | |
466 | } | |
467 | ||
468 | //============================================================================== | |
469 | //function : IsWindowOverlapped | |
470 | //purpose : Check if theWindow overlapp another view | |
471 | //============================================================================== | |
472 | ||
473 | Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft, | |
474 | const Standard_Integer thePxTop, | |
475 | const Standard_Integer thePxRight, | |
476 | const Standard_Integer thePxBottom, | |
477 | TCollection_AsciiString& theViewId) | |
478 | { | |
479 | for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
480 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
481 | { | |
482 | Standard_Integer aTop = 0, | |
483 | aLeft = 0, | |
484 | aRight = 0, | |
485 | aBottom = 0; | |
486 | anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom); | |
487 | if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) || | |
488 | (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) || | |
489 | (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) || | |
490 | (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom)) | |
491 | { | |
492 | theViewId = anIter.Key1(); | |
493 | return Standard_True; | |
494 | } | |
495 | } | |
496 | return Standard_False; | |
497 | } | |
498 | ||
499 | // Workaround: to create and delete non-orthographic views outside ViewerTest | |
500 | void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName) | |
501 | { | |
502 | ViewerTest_myViews.UnBind1 (theName); | |
503 | } | |
504 | ||
505 | void ViewerTest::InitViewName (const TCollection_AsciiString& theName, | |
506 | const Handle(V3d_View)& theView) | |
507 | { | |
508 | ViewerTest_myViews.Bind (theName, theView); | |
509 | } | |
510 | ||
511 | TCollection_AsciiString ViewerTest::GetCurrentViewName () | |
512 | { | |
513 | return ViewerTest_myViews.Find2( ViewerTest::CurrentView()); | |
514 | } | |
7fd59977 | 515 | //============================================================================== |
516 | //function : ViewerInit | |
517 | //purpose : Create the window viewer and initialize all the global variable | |
518 | //============================================================================== | |
519 | ||
18d715bd | 520 | TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft, |
521 | const Standard_Integer thePxTop, | |
522 | const Standard_Integer thePxWidth, | |
523 | const Standard_Integer thePxHeight, | |
524 | Standard_CString theViewName, | |
525 | Standard_CString theDisplayName) | |
7fd59977 | 526 | { |
8c3c9904 | 527 | // Default position and dimension of the viewer window. |
4fe56619 | 528 | // Note that left top corner is set to be sufficiently small to have |
8c3c9904 | 529 | // window fit in the small screens (actual for remote desktops, see #23003). |
4fe56619 | 530 | // The position corresponds to the window's client area, thus some |
8c3c9904 | 531 | // gap is added for window frame to be visible. |
532 | Standard_Integer aPxLeft = 20; | |
533 | Standard_Integer aPxTop = 40; | |
7fd59977 | 534 | Standard_Integer aPxWidth = 409; |
535 | Standard_Integer aPxHeight = 409; | |
18d715bd | 536 | Standard_Boolean toCreateViewer = Standard_False; |
537 | ||
58655684 | 538 | Handle(OpenGl_GraphicDriver) aGraphicDriver; |
18d715bd | 539 | ViewerTest_Names aViewNames(theViewName); |
540 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ())) | |
541 | aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View")); | |
542 | ||
543 | if (thePxLeft != 0) | |
544 | aPxLeft = thePxLeft; | |
545 | if (thePxTop != 0) | |
546 | aPxTop = thePxTop; | |
547 | if (thePxWidth != 0) | |
548 | aPxWidth = thePxWidth; | |
549 | if (thePxHeight != 0) | |
7fd59977 | 550 | aPxHeight = thePxHeight; |
4269bd1b | 551 | |
18d715bd | 552 | // Get graphic driver (create it or get from another view) |
553 | if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName())) | |
554 | { | |
555 | // Get connection string | |
58655684 | 556 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
18d715bd | 557 | TCollection_AsciiString aDisplayName(theDisplayName); |
498ce76b | 558 | if (!aDisplayName.IsEmpty()) |
18d715bd | 559 | SetDisplayConnection (new Aspect_DisplayConnection ()); |
560 | else | |
561 | SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName)); | |
18d715bd | 562 | #else |
498ce76b | 563 | (void)theDisplayName; // avoid warning on unused argument |
18d715bd | 564 | SetDisplayConnection (new Aspect_DisplayConnection ()); |
565 | #endif | |
14cb22a1 | 566 | |
567 | if (Draw_VirtualWindows) | |
568 | { | |
569 | // don't waste the time waiting for VSync when window is not displayed on the screen | |
570 | ViewerTest_myDefaultCaps.swapInterval = 0; | |
571 | // alternatively we can disable buffer swap at all, but this might be inappropriate for testing | |
572 | //ViewerTest_myDefaultCaps.buffersNoSwap = true; | |
573 | } | |
65993a95 | 574 | aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection()); |
58655684 | 575 | aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps; |
14cb22a1 | 576 | |
18d715bd | 577 | ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver); |
578 | toCreateViewer = Standard_True; | |
579 | } | |
580 | else | |
581 | { | |
58655684 | 582 | aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName())); |
7fd59977 | 583 | } |
584 | ||
18d715bd | 585 | //Dispose the window if input parameters are default |
586 | if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0) | |
7fd59977 | 587 | { |
18d715bd | 588 | Standard_Integer aTop = 0, |
589 | aLeft = 0, | |
590 | aRight = 0, | |
591 | aBottom = 0, | |
592 | aScreenWidth = 0, | |
593 | aScreenHeight = 0; | |
594 | ||
595 | // Get screen resolution | |
596 | #if defined(_WIN32) || defined(__WIN32__) | |
597 | RECT aWindowSize; | |
598 | GetClientRect(GetDesktopWindow(), &aWindowSize); | |
599 | aScreenHeight = aWindowSize.bottom; | |
600 | aScreenWidth = aWindowSize.right; | |
601 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
602 | GetCocoaScreenResolution (aScreenWidth, aScreenHeight); | |
603 | #else | |
604 | Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay()); | |
605 | aScreenWidth = WidthOfScreen(aScreen); | |
606 | aScreenHeight = HeightOfScreen(aScreen); | |
607 | #endif | |
608 | ||
609 | TCollection_AsciiString anOverlappedViewId(""); | |
773f53f1 | 610 | |
611 | while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)) | |
dc3fe572 | 612 | { |
18d715bd | 613 | ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom); |
614 | ||
615 | if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId) | |
616 | && aRight + 2*aPxWidth + 40 > aScreenWidth) | |
617 | { | |
618 | if (aBottom + aPxHeight + 40 > aScreenHeight) | |
619 | { | |
620 | aPxLeft = 20; | |
621 | aPxTop = 40; | |
622 | break; | |
623 | } | |
624 | aPxLeft = 20; | |
625 | aPxTop = aBottom + 40; | |
626 | } | |
627 | else | |
628 | aPxLeft = aRight + 20; | |
dc3fe572 | 629 | } |
18d715bd | 630 | } |
631 | ||
632 | // Get viewer name | |
633 | TCollection_AsciiString aTitle("3D View - "); | |
634 | aTitle = aTitle + aViewNames.GetViewName() + "(*)"; | |
635 | ||
636 | // Change name of current active window | |
637 | if (!ViewerTest::CurrentView().IsNull()) | |
638 | { | |
51740958 | 639 | TCollection_AsciiString anActiveWindowTitle("3D View - "); |
640 | anActiveWindowTitle = anActiveWindowTitle | |
18d715bd | 641 | + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()); |
51740958 | 642 | SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString()); |
18d715bd | 643 | } |
644 | ||
645 | // Create viewer | |
eb4320f2 | 646 | Handle(V3d_Viewer) a3DViewer; |
18d715bd | 647 | // If it's the single view, we first look for empty context |
648 | if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty()) | |
649 | { | |
650 | NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
651 | anIter(ViewerTest_myContexts); | |
652 | if (anIter.More()) | |
653 | ViewerTest::SetAISContext (anIter.Value()); | |
654 | a3DViewer = ViewerTest::GetAISContext()->CurrentViewer(); | |
18d715bd | 655 | } |
656 | else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())) | |
657 | { | |
658 | ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName())); | |
659 | a3DViewer = ViewerTest::GetAISContext()->CurrentViewer(); | |
18d715bd | 660 | } |
eb4320f2 | 661 | else if (a3DViewer.IsNull()) |
18d715bd | 662 | { |
663 | toCreateViewer = Standard_True; | |
6a24c6de | 664 | a3DViewer = new V3d_Viewer(aGraphicDriver); |
f42753ed | 665 | a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor); |
666 | a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1, | |
667 | ViewerTest_DefaultBackground.GradientColor2, | |
668 | ViewerTest_DefaultBackground.FillMethod); | |
18d715bd | 669 | } |
670 | ||
671 | // AIS context setup | |
672 | if (ViewerTest::GetAISContext().IsNull() || | |
673 | !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))) | |
674 | { | |
e79a94b9 | 675 | Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer); |
18d715bd | 676 | ViewerTest::SetAISContext (aContext); |
677 | ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext()); | |
678 | } | |
679 | else | |
e79a94b9 | 680 | { |
18d715bd | 681 | ViewerTest::ResetEventManager(); |
e79a94b9 | 682 | } |
18d715bd | 683 | |
684 | // Create window | |
e79a94b9 | 685 | #if defined(_WIN32) |
686 | VT_GetWindow() = new WNT_Window (aTitle.ToCString(), | |
687 | Handle(WNT_WClass)::DownCast (WClass()), | |
62e1beed | 688 | Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW, |
e79a94b9 | 689 | aPxLeft, aPxTop, |
690 | aPxWidth, aPxHeight, | |
691 | Quantity_NOC_BLACK); | |
4fe56619 | 692 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
e79a94b9 | 693 | VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(), |
694 | aPxLeft, aPxTop, | |
695 | aPxWidth, aPxHeight); | |
696 | ViewerTest_SetCocoaEventManagerView (VT_GetWindow()); | |
7fd59977 | 697 | #else |
e79a94b9 | 698 | VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(), |
699 | aTitle.ToCString(), | |
700 | aPxLeft, aPxTop, | |
701 | aPxWidth, aPxHeight); | |
7fd59977 | 702 | #endif |
18d715bd | 703 | VT_GetWindow()->SetVirtual (Draw_VirtualWindows); |
7fd59977 | 704 | |
d09dda09 | 705 | // View setup |
706 | Handle(V3d_View) aView = a3DViewer->CreateView(); | |
707 | aView->SetWindow (VT_GetWindow()); | |
c3282ec1 | 708 | ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer); |
4269bd1b | 709 | |
18d715bd | 710 | ViewerTest::CurrentView(aView); |
711 | ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView); | |
7fd59977 | 712 | |
18d715bd | 713 | // Setup for X11 or NT |
714 | OSWindowSetup(); | |
7fd59977 | 715 | |
18d715bd | 716 | // Set parameters for V3d_View and V3d_Viewer |
717 | const Handle (V3d_View) aV3dView = ViewerTest::CurrentView(); | |
718 | aV3dView->SetComputedMode(Standard_False); | |
719 | MyHLRIsOn = aV3dView->ComputedMode(); | |
7fd59977 | 720 | |
18d715bd | 721 | a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK); |
722 | if (toCreateViewer) | |
723 | { | |
7fd59977 | 724 | a3DViewer->SetDefaultLights(); |
725 | a3DViewer->SetLightOn(); | |
18d715bd | 726 | } |
7fd59977 | 727 | |
e79a94b9 | 728 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
4fe56619 | 729 | #if TCL_MAJOR_VERSION < 8 |
18d715bd | 730 | Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()), |
7fd59977 | 731 | TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() ); |
4fe56619 | 732 | #else |
18d715bd | 733 | Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()), |
7fd59977 | 734 | TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() ); |
4fe56619 | 735 | #endif |
736 | #endif | |
7fd59977 | 737 | |
7fd59977 | 738 | VT_GetWindow()->Map(); |
4269bd1b | 739 | |
18d715bd | 740 | // Set the handle of created view in the event manager |
741 | ViewerTest::ResetEventManager(); | |
742 | ||
4fe56619 | 743 | ViewerTest::CurrentView()->Redraw(); |
18d715bd | 744 | |
745 | aView.Nullify(); | |
746 | a3DViewer.Nullify(); | |
18d715bd | 747 | |
748 | return aViewNames.GetViewName(); | |
749 | } | |
750 | ||
4269bd1b | 751 | //============================================================================== |
752 | //function : RedrawAllViews | |
753 | //purpose : Redraw all created views | |
754 | //============================================================================== | |
755 | void ViewerTest::RedrawAllViews() | |
756 | { | |
757 | NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews); | |
758 | for (; aViewIt.More(); aViewIt.Next()) | |
759 | { | |
760 | const Handle(V3d_View)& aView = aViewIt.Key2(); | |
761 | aView->Redraw(); | |
762 | } | |
763 | } | |
764 | ||
7fd59977 | 765 | //============================================================================== |
766 | //function : Vinit | |
767 | //purpose : Create the window viewer and initialize all the global variable | |
e79a94b9 | 768 | // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event |
7fd59977 | 769 | //============================================================================== |
770 | ||
18d715bd | 771 | static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) |
7fd59977 | 772 | { |
e79a94b9 | 773 | if (theArgsNb > 9) |
18d715bd | 774 | { |
e79a94b9 | 775 | std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n" |
776 | << "Type help for more information.\n"; | |
18d715bd | 777 | return 1; |
778 | } | |
18d715bd | 779 | |
e79a94b9 | 780 | TCollection_AsciiString aViewName, aDisplayName; |
781 | Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0; | |
782 | TCollection_AsciiString aName, aValue; | |
783 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
18d715bd | 784 | { |
e79a94b9 | 785 | const TCollection_AsciiString anArg = theArgVec[anArgIt]; |
786 | TCollection_AsciiString anArgCase = anArg; | |
787 | anArgCase.UpperCase(); | |
1d7ca641 | 788 | if (ViewerTest::SplitParameter (anArg, aName, aValue)) |
18d715bd | 789 | { |
e79a94b9 | 790 | aName.UpperCase(); |
791 | if (aName.IsEqual ("NAME")) | |
18d715bd | 792 | { |
793 | aViewName = aValue; | |
794 | } | |
e79a94b9 | 795 | else if (aName.IsEqual ("L") |
796 | || aName.IsEqual ("LEFT")) | |
797 | { | |
18d715bd | 798 | aPxLeft = aValue.IntegerValue(); |
e79a94b9 | 799 | } |
800 | else if (aName.IsEqual ("T") | |
801 | || aName.IsEqual ("TOP")) | |
802 | { | |
18d715bd | 803 | aPxTop = aValue.IntegerValue(); |
e79a94b9 | 804 | } |
805 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
806 | else if (aName.IsEqual ("DISP") | |
807 | || aName.IsEqual ("DISPLAY")) | |
808 | { | |
18d715bd | 809 | aDisplayName = aValue; |
e79a94b9 | 810 | } |
811 | #endif | |
812 | else if (aName.IsEqual ("W") | |
813 | || aName.IsEqual ("WIDTH")) | |
814 | { | |
18d715bd | 815 | aPxWidth = aValue.IntegerValue(); |
e79a94b9 | 816 | } |
817 | else if (aName.IsEqual ("H") | |
818 | || aName.IsEqual ("HEIGHT")) | |
819 | { | |
18d715bd | 820 | aPxHeight = aValue.IntegerValue(); |
e79a94b9 | 821 | } |
18d715bd | 822 | else |
823 | { | |
e79a94b9 | 824 | std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n"; |
18d715bd | 825 | } |
826 | } | |
e79a94b9 | 827 | else if (aViewName.IsEmpty()) |
828 | { | |
829 | aViewName = anArg; | |
830 | } | |
831 | else | |
832 | { | |
833 | std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n"; | |
834 | } | |
18d715bd | 835 | } |
836 | ||
837 | ViewerTest_Names aViewNames (aViewName); | |
e79a94b9 | 838 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName())) |
18d715bd | 839 | { |
e79a94b9 | 840 | TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName(); |
841 | theDi.Eval (aCommand.ToCString()); | |
18d715bd | 842 | return 0; |
843 | } | |
844 | ||
845 | TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight, | |
846 | aViewName.ToCString(), | |
847 | aDisplayName.ToCString()); | |
e79a94b9 | 848 | theDi << aViewId; |
7fd59977 | 849 | return 0; |
850 | } | |
851 | ||
0a768f56 | 852 | //============================================================================== |
853 | //function : VHLR | |
854 | //purpose : hidden lines removal algorithm | |
e9224045 | 855 | //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}] |
0a768f56 | 856 | //============================================================================== |
857 | ||
858 | static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
859 | { | |
860 | if (ViewerTest::CurrentView().IsNull()) | |
861 | { | |
862 | di << argv[0] << ": Call vinit before this command, please.\n"; | |
863 | return 1; | |
864 | } | |
865 | ||
e9224045 | 866 | if (argc < 2) |
0a768f56 | 867 | { |
868 | di << argv[0] << ": Wrong number of command arguments.\n" | |
869 | << "Type help " << argv[0] << " for more information.\n"; | |
870 | return 1; | |
871 | } | |
872 | ||
e9224045 | 873 | // Enable or disable HLR mode. |
0a768f56 | 874 | Standard_Boolean isHLROn = |
875 | (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False; | |
876 | ||
e9224045 | 877 | if (isHLROn != MyHLRIsOn) |
0a768f56 | 878 | { |
e9224045 | 879 | MyHLRIsOn = isHLROn; |
880 | ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn); | |
0a768f56 | 881 | } |
882 | ||
e9224045 | 883 | // Show or hide hidden lines in HLR mode. |
884 | Standard_Boolean isCurrentShowHidden | |
885 | = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine(); | |
886 | ||
887 | Standard_Boolean isShowHidden = | |
888 | (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False) | |
889 | : isCurrentShowHidden; | |
890 | ||
891 | ||
892 | if (isShowHidden != isCurrentShowHidden) | |
893 | { | |
894 | if (isShowHidden) | |
895 | { | |
896 | ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine(); | |
897 | } | |
898 | else | |
899 | { | |
900 | ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine(); | |
901 | } | |
902 | ||
903 | // Redisplay shapes. | |
904 | if (MyHLRIsOn) | |
905 | { | |
906 | AIS_ListOfInteractive aListOfShapes; | |
907 | ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes); | |
908 | ||
909 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next()) | |
910 | { | |
911 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value()); | |
912 | if (aShape.IsNull()) | |
913 | { | |
914 | continue; | |
915 | } | |
36132a2e | 916 | ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False); |
e9224045 | 917 | } |
918 | } | |
919 | } | |
0a768f56 | 920 | |
e9224045 | 921 | ViewerTest::CurrentView()->Update(); |
0a768f56 | 922 | return 0; |
923 | } | |
924 | ||
925 | //============================================================================== | |
926 | //function : VHLRType | |
927 | //purpose : change type of using HLR algorithm | |
928 | //============================================================================== | |
929 | ||
930 | static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
931 | { | |
932 | if (ViewerTest::CurrentView().IsNull()) | |
933 | { | |
934 | di << argv[0] << ": Call vinit before this command, please.\n"; | |
935 | return 1; | |
936 | } | |
937 | ||
938 | if (argc < 2) | |
939 | { | |
940 | di << argv[0] << ": Wrong number of command arguments.\n" | |
941 | << "Type help " << argv[0] << " for more information.\n"; | |
942 | return 1; | |
943 | } | |
944 | ||
945 | Prs3d_TypeOfHLR aTypeOfHLR = | |
946 | (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo; | |
947 | ||
948 | if (argc == 2) | |
949 | { | |
950 | AIS_ListOfInteractive aListOfShapes; | |
951 | ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes); | |
952 | ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR); | |
953 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); | |
954 | anIter.More(); anIter.Next()) | |
955 | { | |
956 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()); | |
957 | if (aShape.IsNull()) | |
958 | continue; | |
959 | if (aShape->TypeOfHLR() != aTypeOfHLR) | |
960 | aShape->SetTypeOfHLR (aTypeOfHLR); | |
961 | if (MyHLRIsOn) | |
36132a2e | 962 | ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False); |
0a768f56 | 963 | } |
964 | ViewerTest::CurrentView()->Update(); | |
965 | return 0; | |
966 | } | |
967 | else | |
968 | { | |
969 | for (Standard_Integer i = 2; i < argc; ++i) | |
970 | { | |
971 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
972 | TCollection_AsciiString aName (argv[i]); | |
973 | ||
974 | if (!aMap.IsBound2 (aName)) | |
975 | { | |
586db386 | 976 | di << argv[0] << ": Wrong shape name:" << aName.ToCString() << ".\n"; |
0a768f56 | 977 | continue; |
978 | } | |
979 | Handle(AIS_Shape) anAISObject = | |
980 | Handle(AIS_Shape)::DownCast (aMap.Find2(aName)); | |
981 | if (anAISObject.IsNull()) | |
982 | continue; | |
983 | anAISObject->SetTypeOfHLR (aTypeOfHLR); | |
984 | if (MyHLRIsOn) | |
36132a2e | 985 | ViewerTest::GetAISContext()->Redisplay (anAISObject, Standard_False); |
0a768f56 | 986 | } |
987 | ViewerTest::CurrentView()->Update(); | |
988 | } | |
989 | ||
990 | return 0; | |
991 | } | |
992 | ||
18d715bd | 993 | //============================================================================== |
994 | //function : FindViewIdByWindowHandle | |
995 | //purpose : Find theView Id in the map of views by window handle | |
996 | //============================================================================== | |
997 | #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
998 | TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle) | |
999 | { | |
1000 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
1001 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
1002 | { | |
1003 | Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window()); | |
1004 | if (aWindowHandle == theWindowHandle) | |
1005 | return anIter.Key1(); | |
1006 | } | |
1007 | return TCollection_AsciiString(""); | |
1008 | } | |
1009 | #endif | |
1010 | ||
1011 | //============================================================================== | |
1012 | //function : ActivateView | |
1013 | //purpose : Make the view active | |
1014 | //============================================================================== | |
1015 | ||
1016 | void ActivateView (const TCollection_AsciiString& theViewName) | |
1017 | { | |
1018 | const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); | |
1019 | if (!aView.IsNull()) | |
1020 | { | |
1021 | Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView); | |
1022 | if (!anAISContext.IsNull()) | |
1023 | { | |
1024 | if (!ViewerTest::CurrentView().IsNull()) | |
1025 | { | |
1026 | TCollection_AsciiString aTitle("3D View - "); | |
1027 | aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()); | |
1028 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
1029 | } | |
1030 | ||
1031 | ViewerTest::CurrentView (aView); | |
1032 | // Update degenerate mode | |
1033 | MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode(); | |
1034 | ViewerTest::SetAISContext (anAISContext); | |
1035 | TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - "); | |
1036 | aTitle = aTitle + theViewName + "(*)"; | |
1037 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
1038 | #if defined(_WIN32) || defined(__WIN32__) | |
1039 | VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window()); | |
1040 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
1041 | VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window()); | |
1042 | #else | |
1043 | VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window()); | |
1044 | #endif | |
1045 | SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); | |
1046 | ViewerTest::CurrentView()->Redraw(); | |
1047 | } | |
1048 | } | |
1049 | } | |
1050 | ||
0e93d9e5 | 1051 | //============================================================================== |
1052 | //function : RemoveView | |
1053 | //purpose : | |
1054 | //============================================================================== | |
1055 | void ViewerTest::RemoveView (const Handle(V3d_View)& theView, | |
1056 | const Standard_Boolean theToRemoveContext) | |
1057 | { | |
1058 | if (!ViewerTest_myViews.IsBound2 (theView)) | |
1059 | { | |
1060 | return; | |
1061 | } | |
1062 | ||
1063 | const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView); | |
1064 | RemoveView (aViewName, theToRemoveContext); | |
1065 | } | |
1066 | ||
18d715bd | 1067 | //============================================================================== |
1068 | //function : RemoveView | |
1069 | //purpose : Close and remove view from display, clear maps if neccessary | |
1070 | //============================================================================== | |
1071 | void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved) | |
1072 | { | |
1073 | if (!ViewerTest_myViews.IsBound1(theViewName)) | |
1074 | { | |
1075 | cout << "Wrong view name\n"; | |
1076 | return; | |
1077 | } | |
1078 | ||
1079 | // Activate another view if it's active now | |
1080 | if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView()) | |
1081 | { | |
1082 | if (ViewerTest_myViews.Extent() > 1) | |
1083 | { | |
1084 | TCollection_AsciiString aNewViewName; | |
1085 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator | |
1086 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
1087 | if (anIter.Key1() != theViewName) | |
1088 | { | |
1089 | aNewViewName = anIter.Key1(); | |
1090 | break; | |
1091 | } | |
1092 | ActivateView (aNewViewName); | |
1093 | } | |
1094 | else | |
1095 | { | |
1096 | Handle(V3d_View) anEmptyView; | |
1097 | #if defined(_WIN32) || defined(__WIN32__) | |
1098 | Handle(WNT_Window) anEmptyWindow; | |
1099 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
1100 | Handle(Cocoa_Window) anEmptyWindow; | |
1101 | #else | |
1102 | Handle(Xw_Window) anEmptyWindow; | |
1103 | #endif | |
1104 | VT_GetWindow() = anEmptyWindow; | |
1105 | ViewerTest::CurrentView (anEmptyView); | |
1106 | if (isContextRemoved) | |
1107 | { | |
1108 | Handle(AIS_InteractiveContext) anEmptyContext; | |
1109 | ViewerTest::SetAISContext(anEmptyContext); | |
1110 | } | |
1111 | } | |
1112 | } | |
1113 | ||
1114 | // Delete view | |
1115 | Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); | |
1116 | Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView); | |
1117 | ||
1118 | // Remove view resources | |
18d715bd | 1119 | ViewerTest_myViews.UnBind1(theViewName); |
1120 | aView->Remove(); | |
1121 | ||
1122 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
1123 | XFlush (GetDisplayConnection()->GetDisplay()); | |
1124 | #endif | |
1125 | ||
1126 | // Keep context opened only if the closed view is last to avoid | |
1127 | // unused empty contexts | |
1128 | if (!aCurrentContext.IsNull()) | |
1129 | { | |
1130 | // Check if there are more difined views in the viewer | |
1131 | aCurrentContext->CurrentViewer()->InitDefinedViews(); | |
1132 | if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews()) | |
1133 | { | |
1134 | // Remove driver if there is no viewers that use it | |
1135 | Standard_Boolean isRemoveDriver = Standard_True; | |
1136 | for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
1137 | anIter(ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
1138 | { | |
1139 | if (aCurrentContext != anIter.Key2() && | |
1140 | aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver()) | |
1141 | { | |
1142 | isRemoveDriver = Standard_False; | |
1143 | break; | |
1144 | } | |
1145 | } | |
2ec85268 | 1146 | |
1147 | aCurrentContext->RemoveAll (Standard_False); | |
18d715bd | 1148 | if(isRemoveDriver) |
1149 | { | |
1150 | ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver()); | |
1151 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
1152 | #if TCL_MAJOR_VERSION < 8 | |
1153 | Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay())); | |
1154 | #else | |
1155 | Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay())); | |
1156 | #endif | |
1157 | #endif | |
1158 | } | |
1159 | ||
1160 | ViewerTest_myContexts.UnBind2(aCurrentContext); | |
1161 | } | |
1162 | } | |
1163 | cout << "3D View - " << theViewName << " was deleted.\n"; | |
1164 | ||
1165 | } | |
1166 | ||
1167 | //============================================================================== | |
1168 | //function : VClose | |
1169 | //purpose : Remove the view defined by its name | |
1170 | //============================================================================== | |
1171 | ||
d0cc1cb7 | 1172 | static int VClose (Draw_Interpretor& /*theDi*/, |
1173 | Standard_Integer theArgsNb, | |
1174 | const char** theArgVec) | |
18d715bd | 1175 | { |
18d715bd | 1176 | NCollection_List<TCollection_AsciiString> aViewList; |
d0cc1cb7 | 1177 | if (theArgsNb > 1) |
18d715bd | 1178 | { |
d0cc1cb7 | 1179 | TCollection_AsciiString anArg (theArgVec[1]); |
1180 | anArg.UpperCase(); | |
1181 | if (anArg.IsEqual ("ALL") | |
1182 | || anArg.IsEqual ("*")) | |
1183 | { | |
1184 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews); | |
1185 | anIter.More(); anIter.Next()) | |
1186 | { | |
1187 | aViewList.Append (anIter.Key1()); | |
1188 | } | |
1189 | if (aViewList.IsEmpty()) | |
1190 | { | |
1191 | std::cout << "No view to close\n"; | |
1192 | return 0; | |
1193 | } | |
1194 | } | |
1195 | else | |
18d715bd | 1196 | { |
d0cc1cb7 | 1197 | ViewerTest_Names aViewName (theArgVec[1]); |
1198 | if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName())) | |
1199 | { | |
1200 | std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n"; | |
1201 | return 1; | |
1202 | } | |
1203 | aViewList.Append (aViewName.GetViewName()); | |
18d715bd | 1204 | } |
1205 | } | |
1206 | else | |
1207 | { | |
d0cc1cb7 | 1208 | // close active view |
1209 | if (ViewerTest::CurrentView().IsNull()) | |
1210 | { | |
1211 | std::cerr << "No active view!\n"; | |
1212 | return 1; | |
1213 | } | |
1214 | aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView())); | |
18d715bd | 1215 | } |
1216 | ||
d0cc1cb7 | 1217 | Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1); |
18d715bd | 1218 | for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList); |
1219 | anIter.More(); anIter.Next()) | |
1220 | { | |
d0cc1cb7 | 1221 | ViewerTest::RemoveView (anIter.Value(), toRemoveContext); |
18d715bd | 1222 | } |
1223 | ||
1224 | return 0; | |
1225 | } | |
1226 | ||
1227 | //============================================================================== | |
1228 | //function : VActivate | |
1229 | //purpose : Activate the view defined by its ID | |
1230 | //============================================================================== | |
1231 | ||
1232 | static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
1233 | { | |
1234 | if (theArgsNb > 2) | |
1235 | { | |
1236 | theDi << theArgVec[0] << ": wrong number of command arguments.\n" | |
1237 | << "Usage: " << theArgVec[0] << " ViewID\n"; | |
1238 | return 1; | |
1239 | } | |
1240 | if(theArgsNb == 1) | |
1241 | { | |
1242 | theDi.Eval("vviewlist"); | |
1243 | return 0; | |
1244 | } | |
1245 | ||
1246 | TCollection_AsciiString aNameString(theArgVec[1]); | |
29cb310a | 1247 | if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 ) |
18d715bd | 1248 | { |
1249 | TCollection_AsciiString aTitle("3D View - "); | |
1250 | aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView()); | |
1251 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
1252 | Handle(V3d_View) anEmptyView; | |
1253 | #if defined(_WIN32) || defined(__WIN32__) | |
1254 | Handle(WNT_Window) anEmptyWindow; | |
1255 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
1256 | Handle(Cocoa_Window) anEmptyWindow; | |
1257 | #else | |
1258 | Handle(Xw_Window) anEmptyWindow; | |
1259 | #endif | |
1260 | VT_GetWindow() = anEmptyWindow; | |
1261 | ViewerTest::CurrentView (anEmptyView); | |
1262 | ViewerTest::ResetEventManager(); | |
1263 | theDi << theArgVec[0] << ": all views are inactive\n"; | |
1264 | return 0; | |
1265 | } | |
1266 | ||
1267 | ViewerTest_Names aViewNames(aNameString); | |
1268 | ||
1269 | // Check if this view exists in the viewer with the driver | |
1270 | if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName())) | |
1271 | { | |
1272 | theDi << "Wrong view name\n"; | |
1273 | return 1; | |
1274 | } | |
1275 | ||
1276 | // Check if it is active already | |
1277 | if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName())) | |
1278 | { | |
1279 | theDi << theArgVec[0] << ": the view is active already\n"; | |
1280 | return 0; | |
1281 | } | |
1282 | ||
1283 | ActivateView (aViewNames.GetViewName()); | |
1284 | return 0; | |
1285 | } | |
1286 | ||
1287 | //============================================================================== | |
1288 | //function : VViewList | |
1289 | //purpose : Print current list of views per viewer and graphic driver ID | |
1290 | // shared between viewers | |
1291 | //============================================================================== | |
1292 | ||
1293 | static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
1294 | { | |
1295 | if (theArgsNb > 2) | |
1296 | { | |
1297 | theDi << theArgVec[0] << ": Wrong number of command arguments\n" | |
29cb310a | 1298 | << "Usage: " << theArgVec[0] << " name"; |
18d715bd | 1299 | return 1; |
1300 | } | |
1301 | if (ViewerTest_myContexts.Size() < 1) | |
1302 | return 0; | |
1303 | ||
18d715bd | 1304 | Standard_Boolean isTreeView = |
29cb310a | 1305 | (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 )); |
18d715bd | 1306 | |
1307 | if (isTreeView) | |
1308 | theDi << theArgVec[0] <<":\n"; | |
1309 | ||
1310 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
1311 | aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next()) | |
1312 | { | |
1313 | if (isTreeView) | |
1314 | theDi << aDriverIter.Key1() << ":\n"; | |
1315 | ||
1316 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
1317 | aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next()) | |
1318 | { | |
1319 | if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1) | |
1320 | { | |
1321 | if (isTreeView) | |
1322 | { | |
1323 | TCollection_AsciiString aContextName(aContextIter.Key1()); | |
586db386 | 1324 | theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n"; |
18d715bd | 1325 | } |
1326 | ||
1327 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
1328 | aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next()) | |
1329 | { | |
1330 | if (aViewIter.Key1().Search(aContextIter.Key1()) != -1) | |
1331 | { | |
1332 | TCollection_AsciiString aViewName(aViewIter.Key1()); | |
1333 | if (isTreeView) | |
1334 | { | |
1335 | if (aViewIter.Value() == ViewerTest::CurrentView()) | |
586db386 | 1336 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n"; |
18d715bd | 1337 | else |
1338 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n"; | |
1339 | } | |
1340 | else | |
1341 | { | |
1342 | theDi << aViewName << " "; | |
1343 | } | |
1344 | } | |
1345 | } | |
1346 | } | |
1347 | } | |
1348 | } | |
1349 | return 0; | |
1350 | } | |
1351 | ||
7fd59977 | 1352 | //============================================================================== |
4fe56619 | 1353 | //function : VT_ProcessKeyPress |
7fd59977 | 1354 | //purpose : Handle KeyPress event from a CString |
1355 | //============================================================================== | |
4fe56619 | 1356 | void VT_ProcessKeyPress (const char* buf_ret) |
7fd59977 | 1357 | { |
1358 | //cout << "KeyPress" << endl; | |
1359 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
7fd59977 | 1360 | // Letter in alphabetic order |
1361 | ||
b514beda | 1362 | if (!strcasecmp (buf_ret, "A")) |
1363 | { | |
7fd59977 | 1364 | // AXO |
1365 | aView->SetProj(V3d_XposYnegZpos); | |
1366 | } | |
b514beda | 1367 | else if (!strcasecmp (buf_ret, "D")) |
1368 | { | |
7fd59977 | 1369 | // Reset |
1370 | aView->Reset(); | |
1371 | } | |
b514beda | 1372 | else if (!strcasecmp (buf_ret, "F")) |
1373 | { | |
b586500b | 1374 | if (ViewerTest::GetAISContext()->NbSelected() > 0) |
1375 | { | |
1376 | ViewerTest::GetAISContext()->FitSelected (aView); | |
1377 | } | |
1378 | else | |
1379 | { | |
1380 | // FitAll | |
1381 | aView->FitAll(); | |
1382 | } | |
7fd59977 | 1383 | } |
b514beda | 1384 | else if (!strcasecmp (buf_ret, "H")) |
1385 | { | |
7fd59977 | 1386 | // HLR |
1387 | cout << "HLR" << endl; | |
de75ed09 | 1388 | aView->SetComputedMode (!aView->ComputedMode()); |
1389 | MyHLRIsOn = aView->ComputedMode(); | |
7fd59977 | 1390 | } |
b514beda | 1391 | else if (!strcasecmp (buf_ret, "P")) |
1392 | { | |
0a768f56 | 1393 | // Type of HLR |
1394 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
1395 | if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo) | |
1396 | aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo); | |
1397 | else | |
1398 | aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo); | |
c3282ec1 | 1399 | if (aContext->NbSelected()==0) |
0a768f56 | 1400 | { |
1401 | AIS_ListOfInteractive aListOfShapes; | |
1402 | aContext->DisplayedObjects(aListOfShapes); | |
1403 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); | |
1404 | anIter.More(); anIter.Next()) | |
1405 | { | |
1406 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()); | |
1407 | if (aShape.IsNull()) | |
1408 | continue; | |
1409 | if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo) | |
1410 | aShape->SetTypeOfHLR (Prs3d_TOH_Algo); | |
1411 | else | |
1412 | aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo); | |
36132a2e | 1413 | aContext->Redisplay (aShape, Standard_False); |
0a768f56 | 1414 | } |
1415 | } | |
1416 | else | |
1417 | { | |
c3282ec1 | 1418 | for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected()) |
0a768f56 | 1419 | { |
c3282ec1 | 1420 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive()); |
0a768f56 | 1421 | if (aShape.IsNull()) |
1422 | continue; | |
1423 | if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo) | |
1424 | aShape->SetTypeOfHLR (Prs3d_TOH_Algo); | |
1425 | else | |
1426 | aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo); | |
36132a2e | 1427 | aContext->Redisplay (aShape, Standard_False); |
0a768f56 | 1428 | } |
1429 | } | |
1430 | ||
1431 | aContext->UpdateCurrentViewer(); | |
4269bd1b | 1432 | |
0a768f56 | 1433 | } |
b514beda | 1434 | else if (!strcasecmp (buf_ret, "S")) |
1435 | { | |
1436 | std::cout << "setup Shaded display mode" << std::endl; | |
4fe56619 | 1437 | |
7fd59977 | 1438 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
c3282ec1 | 1439 | if(Ctx->NbSelected()==0) |
0577ae8c | 1440 | Ctx->SetDisplayMode (AIS_Shaded, Standard_True); |
7fd59977 | 1441 | else{ |
c3282ec1 | 1442 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) |
1443 | Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False); | |
7fd59977 | 1444 | Ctx->UpdateCurrentViewer(); |
1445 | } | |
1446 | } | |
b514beda | 1447 | else if (!strcasecmp (buf_ret, "U")) |
1448 | { | |
41811896 | 1449 | // Unset display mode |
b514beda | 1450 | std::cout << "reset display mode to defaults" << std::endl; |
4fe56619 | 1451 | |
7fd59977 | 1452 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
c3282ec1 | 1453 | if(Ctx->NbSelected()==0) |
0577ae8c | 1454 | Ctx->SetDisplayMode (AIS_WireFrame, Standard_True); |
7fd59977 | 1455 | else{ |
c3282ec1 | 1456 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) |
1457 | Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False); | |
7fd59977 | 1458 | Ctx->UpdateCurrentViewer(); |
1459 | } | |
1460 | ||
1461 | } | |
b514beda | 1462 | else if (!strcasecmp (buf_ret, "T")) |
1463 | { | |
7fd59977 | 1464 | // Top |
1465 | aView->SetProj(V3d_Zpos); | |
1466 | } | |
b514beda | 1467 | else if (!strcasecmp (buf_ret, "B")) |
1468 | { | |
41811896 | 1469 | // Bottom |
7fd59977 | 1470 | aView->SetProj(V3d_Zneg); |
1471 | } | |
b514beda | 1472 | else if (!strcasecmp (buf_ret, "L")) |
1473 | { | |
41811896 | 1474 | // Left |
7fd59977 | 1475 | aView->SetProj(V3d_Xneg); |
1476 | } | |
b514beda | 1477 | else if (!strcasecmp (buf_ret, "R")) |
1478 | { | |
41811896 | 1479 | // Right |
7fd59977 | 1480 | aView->SetProj(V3d_Xpos); |
1481 | } | |
b514beda | 1482 | else if (!strcasecmp (buf_ret, "W")) |
1483 | { | |
1484 | std::cout << "setup WireFrame display mode" << std::endl; | |
7fd59977 | 1485 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
c3282ec1 | 1486 | if(Ctx->NbSelected()==0) |
0577ae8c | 1487 | Ctx->SetDisplayMode (AIS_WireFrame, Standard_True); |
7fd59977 | 1488 | else{ |
c3282ec1 | 1489 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) |
1490 | Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False); | |
7fd59977 | 1491 | Ctx->UpdateCurrentViewer(); |
1492 | } | |
1493 | } | |
b514beda | 1494 | else if (!strcasecmp (buf_ret, ",")) |
1495 | { | |
7fd59977 | 1496 | ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView()); |
7fd59977 | 1497 | } |
b514beda | 1498 | else if (!strcasecmp (buf_ret, ".")) |
1499 | { | |
7fd59977 | 1500 | ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView()); |
1501 | } | |
f978241f | 1502 | else if (!strcasecmp (buf_ret, "/")) |
1503 | { | |
1504 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); | |
1505 | if (aCamera->IsStereo()) | |
1506 | { | |
1507 | aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01); | |
1508 | aView->Redraw(); | |
1509 | } | |
1510 | } | |
1511 | else if (!strcasecmp (buf_ret, "*")) | |
1512 | { | |
1513 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); | |
1514 | if (aCamera->IsStereo()) | |
1515 | { | |
1516 | aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01); | |
1517 | aView->Redraw(); | |
1518 | } | |
1519 | } | |
b514beda | 1520 | else if (*buf_ret == THE_KEY_DELETE) |
1521 | { | |
1522 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
1523 | if (!aCtx.IsNull() | |
b514beda | 1524 | && aCtx->NbSelected() > 0) |
1525 | { | |
1526 | Draw_Interprete ("verase"); | |
1527 | } | |
1528 | } | |
1529 | else | |
1530 | { | |
1531 | // Number | |
91322f44 | 1532 | Standard_Integer Num = Draw::Atoi(buf_ret); |
7fd59977 | 1533 | if(Num>=0 && Num<=7) |
1534 | ViewerTest::StandardModeActivation(Num); | |
1535 | } | |
1536 | } | |
1537 | ||
1538 | //============================================================================== | |
4fe56619 | 1539 | //function : VT_ProcessExpose |
7fd59977 | 1540 | //purpose : Redraw the View on an Expose Event |
1541 | //============================================================================== | |
4fe56619 | 1542 | void VT_ProcessExpose() |
1543 | { | |
1544 | Handle(V3d_View) aView3d = ViewerTest::CurrentView(); | |
1545 | if (!aView3d.IsNull()) | |
1546 | { | |
1547 | aView3d->Redraw(); | |
1548 | } | |
7fd59977 | 1549 | } |
1550 | ||
1551 | //============================================================================== | |
4fe56619 | 1552 | //function : VT_ProcessConfigure |
7fd59977 | 1553 | //purpose : Resize the View on an Configure Event |
1554 | //============================================================================== | |
4fe56619 | 1555 | void VT_ProcessConfigure() |
7fd59977 | 1556 | { |
4fe56619 | 1557 | Handle(V3d_View) aView3d = ViewerTest::CurrentView(); |
1558 | if (aView3d.IsNull()) | |
1559 | { | |
1560 | return; | |
1561 | } | |
1562 | ||
1563 | aView3d->MustBeResized(); | |
1564 | aView3d->Update(); | |
1565 | aView3d->Redraw(); | |
7fd59977 | 1566 | } |
1567 | ||
1568 | //============================================================================== | |
4fe56619 | 1569 | //function : VT_ProcessButton1Press |
7fd59977 | 1570 | //purpose : Picking |
1571 | //============================================================================== | |
e79a94b9 | 1572 | Standard_Boolean VT_ProcessButton1Press (Standard_Integer , |
1573 | const char** theArgVec, | |
1574 | Standard_Boolean theToPick, | |
1575 | Standard_Boolean theIsShift) | |
7fd59977 | 1576 | { |
1beb58d7 | 1577 | if (TheIsAnimating) |
1578 | { | |
1579 | TheIsAnimating = Standard_False; | |
1580 | return Standard_False; | |
1581 | } | |
1582 | ||
e79a94b9 | 1583 | if (theToPick) |
1584 | { | |
7fd59977 | 1585 | Standard_Real X, Y, Z; |
e79a94b9 | 1586 | ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z); |
7fd59977 | 1587 | |
e79a94b9 | 1588 | Draw::Set (theArgVec[1], X); |
1589 | Draw::Set (theArgVec[2], Y); | |
1590 | Draw::Set (theArgVec[3], Z); | |
1591 | } | |
7fd59977 | 1592 | |
e79a94b9 | 1593 | if (theIsShift) |
1594 | { | |
1595 | ViewerTest::CurrentEventManager()->ShiftSelect(); | |
1596 | } | |
7fd59977 | 1597 | else |
e79a94b9 | 1598 | { |
1599 | ViewerTest::CurrentEventManager()->Select(); | |
1600 | } | |
7fd59977 | 1601 | |
e79a94b9 | 1602 | return Standard_False; |
7fd59977 | 1603 | } |
1604 | ||
1605 | //============================================================================== | |
4fe56619 | 1606 | //function : VT_ProcessButton1Release |
1607 | //purpose : End selecting | |
7fd59977 | 1608 | //============================================================================== |
4fe56619 | 1609 | void VT_ProcessButton1Release (Standard_Boolean theIsShift) |
1610 | { | |
1611 | if (IsDragged) | |
1612 | { | |
1613 | IsDragged = Standard_False; | |
1614 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
1615 | if (theIsShift) | |
1616 | { | |
2157d6ac | 1617 | EM->ShiftSelect (X_ButtonPress, Y_ButtonPress, |
1618 | X_Motion, Y_Motion); | |
4fe56619 | 1619 | } |
1620 | else | |
1621 | { | |
2157d6ac | 1622 | EM->Select (X_ButtonPress, Y_ButtonPress, |
1623 | X_Motion, Y_Motion); | |
4fe56619 | 1624 | } |
1625 | } | |
1626 | } | |
7fd59977 | 1627 | |
4fe56619 | 1628 | //============================================================================== |
1629 | //function : VT_ProcessButton3Press | |
1630 | //purpose : Start Rotation | |
1631 | //============================================================================== | |
1632 | void VT_ProcessButton3Press() | |
1633 | { | |
7fd59977 | 1634 | Start_Rot = 1; |
de75ed09 | 1635 | if (MyHLRIsOn) |
1636 | { | |
1637 | ViewerTest::CurrentView()->SetComputedMode (Standard_False); | |
1638 | } | |
7fd59977 | 1639 | ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress ); |
7fd59977 | 1640 | } |
4fe56619 | 1641 | |
7fd59977 | 1642 | //============================================================================== |
4fe56619 | 1643 | //function : VT_ProcessButton3Release |
1644 | //purpose : End rotation | |
7fd59977 | 1645 | //============================================================================== |
4fe56619 | 1646 | void VT_ProcessButton3Release() |
1647 | { | |
1648 | if (Start_Rot) | |
1649 | { | |
7fd59977 | 1650 | Start_Rot = 0; |
de75ed09 | 1651 | if (MyHLRIsOn) |
1652 | { | |
1653 | ViewerTest::CurrentView()->SetComputedMode (Standard_True); | |
1654 | } | |
7fd59977 | 1655 | } |
7fd59977 | 1656 | } |
1657 | ||
7fd59977 | 1658 | //============================================================================== |
1659 | //function : ProcessControlButton1Motion | |
1660 | //purpose : Zoom | |
1661 | //============================================================================== | |
1662 | ||
900f7229 | 1663 | #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX) |
7fd59977 | 1664 | static void ProcessControlButton1Motion() |
1665 | { | |
1666 | ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion); | |
1667 | ||
1668 | X_ButtonPress = X_Motion; | |
1669 | Y_ButtonPress = Y_Motion; | |
1670 | } | |
900f7229 | 1671 | #endif |
7fd59977 | 1672 | |
1673 | //============================================================================== | |
4fe56619 | 1674 | //function : VT_ProcessControlButton2Motion |
1675 | //purpose : Panning | |
7fd59977 | 1676 | //============================================================================== |
4fe56619 | 1677 | void VT_ProcessControlButton2Motion() |
7fd59977 | 1678 | { |
197ac94e | 1679 | Standard_Integer aDx = X_Motion - X_ButtonPress; |
1680 | Standard_Integer aDy = Y_Motion - Y_ButtonPress; | |
7fd59977 | 1681 | |
197ac94e | 1682 | aDy = -aDy; // Xwindow Y axis is from top to Bottom |
7fd59977 | 1683 | |
197ac94e | 1684 | ViewerTest::CurrentView()->Pan (aDx, aDy); |
7fd59977 | 1685 | |
1686 | X_ButtonPress = X_Motion; | |
1687 | Y_ButtonPress = Y_Motion; | |
1688 | } | |
1689 | ||
1690 | //============================================================================== | |
4fe56619 | 1691 | //function : VT_ProcessControlButton3Motion |
7fd59977 | 1692 | //purpose : Rotation |
1693 | //============================================================================== | |
4fe56619 | 1694 | void VT_ProcessControlButton3Motion() |
7fd59977 | 1695 | { |
4fe56619 | 1696 | if (Start_Rot) |
1697 | { | |
1698 | ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion); | |
1699 | } | |
7fd59977 | 1700 | } |
1701 | ||
1702 | //============================================================================== | |
4fe56619 | 1703 | //function : VT_ProcessMotion |
1704 | //purpose : | |
7fd59977 | 1705 | //============================================================================== |
4fe56619 | 1706 | void VT_ProcessMotion() |
7fd59977 | 1707 | { |
1708 | //pre-hilights detected objects at mouse position | |
1709 | ||
1710 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
1711 | EM->MoveTo(X_Motion, Y_Motion); | |
1712 | } | |
1713 | ||
1714 | ||
1715 | void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix) | |
1716 | { | |
1717 | Xpix = X_Motion;Ypix=Y_Motion; | |
1718 | } | |
1719 | ||
44b8f2d6 | 1720 | //============================================================================== |
1721 | //function : ViewProject: implements VAxo, VTop, VLeft, ... | |
1722 | //purpose : Switches to an axonometric, top, left and other views | |
1723 | //============================================================================== | |
1724 | ||
1725 | static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori) | |
1726 | { | |
4fe56619 | 1727 | if ( ViewerTest::CurrentView().IsNull() ) |
44b8f2d6 | 1728 | { |
586db386 | 1729 | di<<"Call vinit before this command, please\n"; |
44b8f2d6 | 1730 | return 1; |
1731 | } | |
1732 | ||
1733 | ViewerTest::CurrentView()->SetProj(ori); | |
1734 | return 0; | |
1735 | } | |
1736 | ||
7fd59977 | 1737 | //============================================================================== |
1738 | //function : VAxo | |
1739 | //purpose : Switch to an Axonometric view | |
1740 | //Draw arg : No args | |
1741 | //============================================================================== | |
1742 | ||
1743 | static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** ) | |
44b8f2d6 | 1744 | { |
1745 | return ViewProject(di, V3d_XposYnegZpos); | |
7fd59977 | 1746 | } |
1747 | ||
1748 | //============================================================================== | |
1749 | //function : VTop | |
1750 | //purpose : Switch to a Top View | |
1751 | //Draw arg : No args | |
1752 | //============================================================================== | |
1753 | ||
1754 | static int VTop(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1755 | { | |
44b8f2d6 | 1756 | return ViewProject(di, V3d_Zpos); |
1757 | } | |
7fd59977 | 1758 | |
44b8f2d6 | 1759 | //============================================================================== |
1760 | //function : VBottom | |
1761 | //purpose : Switch to a Bottom View | |
1762 | //Draw arg : No args | |
1763 | //============================================================================== | |
7fd59977 | 1764 | |
44b8f2d6 | 1765 | static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** ) |
1766 | { | |
1767 | return ViewProject(di, V3d_Zneg); | |
1768 | } | |
7fd59977 | 1769 | |
44b8f2d6 | 1770 | //============================================================================== |
1771 | //function : VLeft | |
1772 | //purpose : Switch to a Left View | |
1773 | //Draw arg : No args | |
1774 | //============================================================================== | |
1775 | ||
1776 | static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1777 | { | |
27af3052 | 1778 | return ViewProject(di, V3d_Xneg); |
44b8f2d6 | 1779 | } |
1780 | ||
1781 | //============================================================================== | |
1782 | //function : VRight | |
1783 | //purpose : Switch to a Right View | |
1784 | //Draw arg : No args | |
1785 | //============================================================================== | |
1786 | ||
1787 | static int VRight(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1788 | { | |
27af3052 | 1789 | return ViewProject(di, V3d_Xpos); |
44b8f2d6 | 1790 | } |
7fd59977 | 1791 | |
44b8f2d6 | 1792 | //============================================================================== |
1793 | //function : VFront | |
1794 | //purpose : Switch to a Front View | |
1795 | //Draw arg : No args | |
1796 | //============================================================================== | |
1797 | ||
1798 | static int VFront(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1799 | { | |
27af3052 | 1800 | return ViewProject(di, V3d_Yneg); |
44b8f2d6 | 1801 | } |
1802 | ||
1803 | //============================================================================== | |
1804 | //function : VBack | |
1805 | //purpose : Switch to a Back View | |
1806 | //Draw arg : No args | |
1807 | //============================================================================== | |
1808 | ||
1809 | static int VBack(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1810 | { | |
27af3052 | 1811 | return ViewProject(di, V3d_Ypos); |
7fd59977 | 1812 | } |
1813 | ||
1814 | //============================================================================== | |
1815 | //function : VHelp | |
1816 | //purpose : Dsiplay help on viewer Keyboead and mouse commands | |
1817 | //Draw arg : No args | |
1818 | //============================================================================== | |
1819 | ||
1820 | static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** ) | |
1821 | { | |
1822 | ||
586db386 | 1823 | di << "Q : Quit the application\n"; |
1824 | ||
1825 | di << "=========================\n"; | |
1826 | di << "F : FitAll\n"; | |
1827 | di << "T : TopView\n"; | |
1828 | di << "B : BottomView\n"; | |
1829 | di << "R : RightView\n"; | |
1830 | di << "L : LeftView\n"; | |
1831 | di << "A : AxonometricView\n"; | |
1832 | di << "D : ResetView\n"; | |
1833 | ||
1834 | di << "=========================\n"; | |
1835 | di << "S : Shading\n"; | |
1836 | di << "W : Wireframe\n"; | |
1837 | di << "H : HidelLineRemoval\n"; | |
1838 | di << "U : Unset display mode\n"; | |
1839 | di << "Delete : Remove selection from viewer\n"; | |
1840 | ||
1841 | di << "=========================\n"; | |
1842 | di << "Selection mode \n"; | |
1843 | di << "0 : Shape\n"; | |
1844 | di << "1 : Vertex\n"; | |
1845 | di << "2 : Edge\n"; | |
1846 | di << "3 : Wire\n"; | |
1847 | di << "4 : Face\n"; | |
1848 | di << "5 : Shell\n"; | |
1849 | di << "6 : Solid\n"; | |
1850 | di << "7 : Compound\n"; | |
1851 | ||
1852 | di << "=========================\n"; | |
1853 | di << "Z : Switch Z clipping On/Off\n"; | |
1854 | di << ", : Hilight next detected\n"; | |
1855 | di << ". : Hilight previous detected\n"; | |
7fd59977 | 1856 | |
1857 | return 0; | |
1858 | } | |
1859 | ||
57c28b61 | 1860 | #ifdef _WIN32 |
7fd59977 | 1861 | |
1862 | static Standard_Boolean Ppick = 0; | |
1863 | static Standard_Integer Pargc = 0; | |
1864 | static const char** Pargv = NULL; | |
1865 | ||
1866 | ||
1867 | static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd, | |
1868 | UINT Msg, | |
1869 | WPARAM wParam, | |
1870 | LPARAM lParam ) | |
1871 | { | |
18d715bd | 1872 | if (!ViewerTest_myViews.IsEmpty()) { |
7fd59977 | 1873 | |
1874 | WPARAM fwKeys = wParam; | |
1875 | ||
1876 | switch( Msg ) { | |
18d715bd | 1877 | case WM_CLOSE: |
1878 | { | |
1879 | // Delete view from map of views | |
1880 | ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd)); | |
1881 | return 0; | |
1882 | } | |
1883 | break; | |
1884 | case WM_ACTIVATE: | |
1885 | if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE | |
1886 | || ViewerTest::CurrentView().IsNull()) | |
1887 | { | |
1888 | // Activate inactive window | |
1889 | if(GetWindowHandle(VT_GetWindow()) != hwnd) | |
1890 | { | |
1891 | ActivateView (FindViewIdByWindowHandle(hwnd)); | |
1892 | } | |
1893 | } | |
1894 | break; | |
625e1958 | 1895 | |
7fd59977 | 1896 | case WM_LBUTTONUP: |
625e1958 | 1897 | if (IsDragged && !DragFirst) |
7fd59977 | 1898 | { |
625e1958 | 1899 | if (!GetActiveAISManipulator().IsNull()) |
1900 | { | |
1901 | GetActiveAISManipulator()->StopTransform(); | |
0577ae8c | 1902 | ViewerTest::GetAISContext()->ClearSelected (Standard_True); |
625e1958 | 1903 | } |
1904 | ||
b12e1c7b | 1905 | if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand())) |
1906 | { | |
1907 | ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False); | |
1908 | ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate(); | |
1909 | } | |
1910 | ||
dde68833 | 1911 | VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0); |
7fd59977 | 1912 | } |
8abada55 | 1913 | IsDragged = Standard_False; |
7fd59977 | 1914 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); |
1915 | ||
625e1958 | 1916 | case WM_RBUTTONUP: |
1917 | if (IsDragged && !DragFirst) | |
1918 | { | |
1919 | if (!GetActiveAISManipulator().IsNull()) | |
1920 | { | |
1921 | GetActiveAISManipulator()->StopTransform (Standard_False); | |
0577ae8c | 1922 | ViewerTest::GetAISContext()->ClearSelected (Standard_True); |
625e1958 | 1923 | } |
1924 | IsDragged = Standard_False; | |
1925 | } | |
1926 | return ViewerWindowProc (hwnd, Msg, wParam, lParam); | |
1927 | ||
7fd59977 | 1928 | case WM_LBUTTONDOWN: |
625e1958 | 1929 | if (!GetActiveAISManipulator().IsNull()) |
1930 | { | |
1931 | IsDragged = ( fwKeys == MK_LBUTTON ); | |
1932 | } | |
1933 | else | |
1934 | { | |
1935 | IsDragged = ( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) ); | |
1936 | } | |
1937 | ||
1938 | if (IsDragged) | |
7fd59977 | 1939 | { |
7fd59977 | 1940 | DragFirst = Standard_True; |
4fe56619 | 1941 | X_ButtonPress = LOWORD(lParam); |
1942 | Y_ButtonPress = HIWORD(lParam); | |
7fd59977 | 1943 | } |
1944 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1945 | ||
7fd59977 | 1946 | case WM_MOUSEMOVE: |
b12e1c7b | 1947 | if (IsDragged) |
7fd59977 | 1948 | { |
b12e1c7b | 1949 | X_Motion = LOWORD (lParam); |
1950 | Y_Motion = HIWORD (lParam); | |
625e1958 | 1951 | if (!GetActiveAISManipulator().IsNull()) |
b12e1c7b | 1952 | { |
625e1958 | 1953 | if (DragFirst) |
1954 | { | |
1955 | GetActiveAISManipulator()->StartTransform (X_ButtonPress, Y_ButtonPress, ViewerTest::CurrentView()); | |
1956 | } | |
1957 | else | |
1958 | { | |
1959 | GetActiveAISManipulator()->Transform (X_Motion, Y_Motion, ViewerTest::CurrentView()); | |
1960 | ViewerTest::GetAISContext()->CurrentViewer()->Redraw(); | |
1961 | } | |
69adb9ce | 1962 | } |
625e1958 | 1963 | else |
69adb9ce | 1964 | { |
625e1958 | 1965 | bool toRedraw = false; |
1966 | if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand())) | |
1967 | { | |
1968 | ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False); | |
1969 | toRedraw = true; | |
1970 | } | |
1971 | ||
1972 | RECT aRect; | |
1973 | if (GetClientRect (hwnd, &aRect)) | |
1974 | { | |
1975 | int aHeight = aRect.bottom - aRect.top; | |
1976 | GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion); | |
1977 | ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed); | |
1978 | toRedraw = true; | |
1979 | } | |
1980 | if (toRedraw) | |
1981 | { | |
1982 | ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate(); | |
1983 | } | |
b12e1c7b | 1984 | } |
625e1958 | 1985 | |
1986 | DragFirst = Standard_False; | |
7fd59977 | 1987 | } |
1988 | else | |
1989 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1990 | break; | |
1991 | ||
1992 | default: | |
1993 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1994 | } | |
1995 | return 0; | |
1996 | } | |
1997 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
1998 | } | |
1999 | ||
2000 | ||
2001 | static LRESULT WINAPI ViewerWindowProc( HWND hwnd, | |
2002 | UINT Msg, | |
2003 | WPARAM wParam, | |
2004 | LPARAM lParam ) | |
2005 | { | |
7fd59977 | 2006 | static int Up = 1; |
f978241f | 2007 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); |
2008 | if (aView.IsNull()) | |
2009 | { | |
ad03c234 | 2010 | return DefWindowProcW (hwnd, Msg, wParam, lParam); |
f978241f | 2011 | } |
7fd59977 | 2012 | |
7fd59977 | 2013 | PAINTSTRUCT ps; |
2014 | ||
2015 | switch( Msg ) { | |
7fd59977 | 2016 | case WM_PAINT: |
7fd59977 | 2017 | BeginPaint(hwnd, &ps); |
2018 | EndPaint(hwnd, &ps); | |
4fe56619 | 2019 | VT_ProcessExpose(); |
7fd59977 | 2020 | break; |
2021 | ||
2022 | case WM_SIZE: | |
4fe56619 | 2023 | VT_ProcessConfigure(); |
7fd59977 | 2024 | break; |
f978241f | 2025 | case WM_MOVE: |
2026 | case WM_MOVING: | |
2027 | case WM_SIZING: | |
2028 | switch (aView->RenderingParams().StereoMode) | |
2029 | { | |
2030 | case Graphic3d_StereoMode_RowInterlaced: | |
2031 | case Graphic3d_StereoMode_ColumnInterlaced: | |
2032 | case Graphic3d_StereoMode_ChessBoard: | |
2033 | VT_ProcessConfigure(); // track window moves to reverse stereo pair | |
2034 | break; | |
2035 | default: | |
2036 | break; | |
2037 | } | |
2038 | break; | |
7fd59977 | 2039 | |
2040 | case WM_KEYDOWN: | |
4fe56619 | 2041 | if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL)) |
2042 | { | |
7fd59977 | 2043 | char c[2]; |
2044 | c[0] = (char) wParam; | |
2045 | c[1] = '\0'; | |
b514beda | 2046 | if (wParam == VK_DELETE) |
2047 | { | |
2048 | c[0] = THE_KEY_DELETE; | |
2049 | } | |
4ca4bbe8 | 2050 | // comma |
2051 | else if (wParam == VK_OEM_COMMA) | |
2052 | { | |
2053 | c[0] = ','; | |
2054 | } | |
2055 | // dot | |
2056 | else if (wParam == VK_OEM_PERIOD) | |
2057 | { | |
2058 | c[0] = '.'; | |
2059 | } | |
f978241f | 2060 | else if (wParam == VK_DIVIDE) |
2061 | { | |
2062 | c[0] = '/'; | |
2063 | } | |
2064 | // dot | |
2065 | else if (wParam == VK_MULTIPLY) | |
2066 | { | |
2067 | c[0] = '*'; | |
2068 | } | |
4fe56619 | 2069 | VT_ProcessKeyPress (c); |
7fd59977 | 2070 | } |
2071 | break; | |
2072 | ||
2073 | case WM_LBUTTONUP: | |
2074 | case WM_MBUTTONUP: | |
2075 | case WM_RBUTTONUP: | |
7fd59977 | 2076 | Up = 1; |
4fe56619 | 2077 | VT_ProcessButton3Release(); |
7fd59977 | 2078 | break; |
2079 | ||
2080 | case WM_LBUTTONDOWN: | |
2081 | case WM_MBUTTONDOWN: | |
2082 | case WM_RBUTTONDOWN: | |
2083 | { | |
7fd59977 | 2084 | WPARAM fwKeys = wParam; |
2085 | ||
2086 | Up = 0; | |
2087 | ||
2088 | X_ButtonPress = LOWORD(lParam); | |
2089 | Y_ButtonPress = HIWORD(lParam); | |
2090 | ||
4fe56619 | 2091 | if (Msg == WM_LBUTTONDOWN) |
2092 | { | |
dde68833 | 2093 | if ((fwKeys & MK_CONTROL) != 0) |
4fe56619 | 2094 | { |
dde68833 | 2095 | Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0); |
4fe56619 | 2096 | } |
2097 | else | |
2098 | { | |
dde68833 | 2099 | VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0); |
4fe56619 | 2100 | } |
7fd59977 | 2101 | } |
4fe56619 | 2102 | else if (Msg == WM_RBUTTONDOWN) |
2103 | { | |
7fd59977 | 2104 | // Start rotation |
4fe56619 | 2105 | VT_ProcessButton3Press(); |
7fd59977 | 2106 | } |
2107 | } | |
2108 | break; | |
2109 | ||
f978241f | 2110 | case WM_MOUSEWHEEL: |
2111 | { | |
2112 | int aDelta = GET_WHEEL_DELTA_WPARAM (wParam); | |
2113 | if (wParam & MK_CONTROL) | |
2114 | { | |
2115 | if (aView->Camera()->IsStereo()) | |
2116 | { | |
2117 | Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05); | |
2118 | if (aFocus > 0.2 | |
2119 | && aFocus < 2.0) | |
2120 | { | |
2121 | aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus); | |
2122 | aView->Redraw(); | |
2123 | } | |
2124 | } | |
2125 | } | |
2126 | else | |
2127 | { | |
2128 | aView->Zoom (0, 0, aDelta / 40, aDelta / 40); | |
2129 | } | |
2130 | break; | |
2131 | } | |
2132 | ||
7fd59977 | 2133 | case WM_MOUSEMOVE: |
2134 | { | |
2135 | //cout << "\t WM_MOUSEMOVE" << endl; | |
2136 | WPARAM fwKeys = wParam; | |
2137 | X_Motion = LOWORD(lParam); | |
2138 | Y_Motion = HIWORD(lParam); | |
2139 | ||
2140 | if ( Up && | |
dde68833 | 2141 | (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 ) |
2142 | { | |
7fd59977 | 2143 | Up = 0; |
2144 | X_ButtonPress = LOWORD(lParam); | |
2145 | Y_ButtonPress = HIWORD(lParam); | |
2146 | ||
dde68833 | 2147 | if ((fwKeys & MK_RBUTTON) != 0) { |
7fd59977 | 2148 | // Start rotation |
4fe56619 | 2149 | VT_ProcessButton3Press(); |
7fd59977 | 2150 | } |
2151 | } | |
2152 | ||
dde68833 | 2153 | if ((fwKeys & MK_CONTROL) != 0) |
2154 | { | |
2155 | if ((fwKeys & MK_LBUTTON) != 0) | |
2156 | { | |
7fd59977 | 2157 | ProcessControlButton1Motion(); |
2158 | } | |
dde68833 | 2159 | else if ((fwKeys & MK_MBUTTON) != 0 |
2160 | || ((fwKeys & MK_LBUTTON) != 0 | |
2161 | && (fwKeys & MK_RBUTTON) != 0)) | |
2162 | { | |
2163 | VT_ProcessControlButton2Motion(); | |
2164 | } | |
2165 | else if ((fwKeys & MK_RBUTTON) != 0) | |
2166 | { | |
4fe56619 | 2167 | VT_ProcessControlButton3Motion(); |
7fd59977 | 2168 | } |
2169 | } | |
08398024 | 2170 | else if (GetWindowHandle (VT_GetWindow()) == hwnd) |
2171 | { | |
89a929ea | 2172 | VT_ProcessMotion(); |
08398024 | 2173 | } |
7fd59977 | 2174 | } |
2175 | break; | |
2176 | ||
2177 | default: | |
ad03c234 | 2178 | return DefWindowProcW (hwnd, Msg, wParam, lParam); |
7fd59977 | 2179 | } |
2180 | return 0L; | |
7fd59977 | 2181 | } |
2182 | ||
7fd59977 | 2183 | //============================================================================== |
2184 | //function : ViewerMainLoop | |
2185 | //purpose : Get a Event on the view and dispatch it | |
2186 | //============================================================================== | |
2187 | ||
2188 | ||
8263fcd3 | 2189 | int ViewerMainLoop(Standard_Integer argc, const char** argv) |
7fd59977 | 2190 | { |
7fd59977 | 2191 | Ppick = (argc > 0)? 1 : 0; |
2192 | Pargc = argc; | |
2193 | Pargv = argv; | |
2194 | ||
2195 | if ( Ppick ) { | |
2196 | MSG msg; | |
2197 | msg.wParam = 1; | |
2198 | ||
2199 | cout << "Start picking" << endl; | |
2200 | ||
7fd59977 | 2201 | while ( Ppick == 1 ) { |
4fe56619 | 2202 | // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0 |
ad03c234 | 2203 | if (GetMessageW (&msg, NULL, 0, 0)) |
2204 | { | |
2205 | TranslateMessage (&msg); | |
2206 | DispatchMessageW (&msg); | |
7fd59977 | 2207 | } |
2208 | } | |
2209 | ||
2210 | cout << "Picking done" << endl; | |
2211 | } | |
2212 | ||
2213 | return Ppick; | |
2214 | } | |
2215 | ||
4fe56619 | 2216 | #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX) |
7fd59977 | 2217 | |
2218 | int min( int a, int b ) | |
2219 | { | |
2220 | if( a<b ) | |
2221 | return a; | |
2222 | else | |
2223 | return b; | |
2224 | } | |
2225 | ||
2226 | int max( int a, int b ) | |
2227 | { | |
2228 | if( a>b ) | |
2229 | return a; | |
2230 | else | |
2231 | return b; | |
2232 | } | |
2233 | ||
2234 | int ViewerMainLoop(Standard_Integer argc, const char** argv) | |
2235 | ||
4269bd1b | 2236 | { |
18d715bd | 2237 | static XEvent aReport; |
2238 | Standard_Boolean pick = argc > 0; | |
2239 | Display *aDisplay = GetDisplayConnection()->GetDisplay(); | |
2240 | XNextEvent (aDisplay, &aReport); | |
7fd59977 | 2241 | |
18d715bd | 2242 | // Handle event for the chosen display connection |
2243 | switch (aReport.type) { | |
2244 | case ClientMessage: | |
2245 | { | |
eb1ebea4 | 2246 | if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW)) |
18d715bd | 2247 | { |
2248 | // Close the window | |
2249 | ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window)); | |
2250 | } | |
2251 | } | |
2252 | return 0; | |
2253 | case FocusIn: | |
2254 | { | |
2255 | // Activate inactive view | |
2256 | Window aWindow = GetWindowHandle(VT_GetWindow()); | |
2257 | if(aWindow != aReport.xfocus.window) | |
2258 | { | |
2259 | ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window)); | |
2260 | } | |
2261 | } | |
2262 | break; | |
7fd59977 | 2263 | case Expose: |
2264 | { | |
4fe56619 | 2265 | VT_ProcessExpose(); |
7fd59977 | 2266 | } |
2267 | break; | |
2268 | case ConfigureNotify: | |
2269 | { | |
4fe56619 | 2270 | VT_ProcessConfigure(); |
7fd59977 | 2271 | } |
2272 | break; | |
2273 | case KeyPress: | |
2274 | { | |
2275 | ||
2276 | KeySym ks_ret ; | |
2277 | char buf_ret[11] ; | |
2278 | int ret_len ; | |
2279 | XComposeStatus status_in_out; | |
2280 | ||
18d715bd | 2281 | ret_len = XLookupString( ( XKeyEvent *)&aReport , |
7fd59977 | 2282 | (char *) buf_ret , 10 , |
2283 | &ks_ret , &status_in_out ) ; | |
2284 | ||
2285 | ||
2286 | buf_ret[ret_len] = '\0' ; | |
2287 | ||
4fe56619 | 2288 | if (ret_len) |
2289 | { | |
2290 | VT_ProcessKeyPress (buf_ret); | |
7fd59977 | 2291 | } |
2292 | } | |
2293 | break; | |
2294 | case ButtonPress: | |
7fd59977 | 2295 | { |
18d715bd | 2296 | X_ButtonPress = aReport.xbutton.x; |
2297 | Y_ButtonPress = aReport.xbutton.y; | |
7fd59977 | 2298 | |
18d715bd | 2299 | if (aReport.xbutton.button == Button1) |
4fe56619 | 2300 | { |
18d715bd | 2301 | if (aReport.xbutton.state & ControlMask) |
4fe56619 | 2302 | { |
18d715bd | 2303 | pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask)); |
4fe56619 | 2304 | } |
7fd59977 | 2305 | else |
2306 | { | |
2307 | IsDragged = Standard_True; | |
7fd59977 | 2308 | DragFirst = Standard_True; |
2309 | } | |
4fe56619 | 2310 | } |
18d715bd | 2311 | else if (aReport.xbutton.button == Button3) |
4fe56619 | 2312 | { |
7fd59977 | 2313 | // Start rotation |
4fe56619 | 2314 | VT_ProcessButton3Press(); |
2315 | } | |
7fd59977 | 2316 | } |
2317 | break; | |
2318 | case ButtonRelease: | |
2319 | { | |
7fd59977 | 2320 | if( IsDragged ) |
2321 | { | |
2322 | if( !DragFirst ) | |
2323 | { | |
b12e1c7b | 2324 | if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand())) |
2325 | { | |
2326 | ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False); | |
2327 | ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate(); | |
2328 | } | |
7fd59977 | 2329 | } |
2330 | ||
2331 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
2332 | if( aContext.IsNull() ) | |
2333 | { | |
2334 | cout << "The context is null. Please use vinit before createmesh" << endl; | |
2335 | return 0; | |
2336 | } | |
2337 | ||
18d715bd | 2338 | Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask ); |
2339 | if( aReport.xbutton.button==1 ) | |
7fd59977 | 2340 | if( DragFirst ) |
2341 | if( ShiftPressed ) | |
2342 | { | |
0577ae8c | 2343 | aContext->ShiftSelect (Standard_True); |
7fd59977 | 2344 | } |
2345 | else | |
2346 | { | |
0577ae8c | 2347 | aContext->Select (Standard_True); |
7fd59977 | 2348 | } |
2349 | else | |
2350 | if( ShiftPressed ) | |
2351 | { | |
0577ae8c | 2352 | aContext->ShiftSelect(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion), |
2353 | Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion), | |
2354 | ViewerTest::CurrentView(), Standard_True); | |
7fd59977 | 2355 | } |
2356 | else | |
2357 | { | |
0577ae8c | 2358 | aContext->Select(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion), |
2359 | Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion), | |
2360 | ViewerTest::CurrentView(), Standard_True); | |
7fd59977 | 2361 | } |
2362 | else | |
4fe56619 | 2363 | VT_ProcessButton3Release(); |
7fd59977 | 2364 | |
2365 | IsDragged = Standard_False; | |
2366 | } | |
2367 | else | |
4fe56619 | 2368 | VT_ProcessButton3Release(); |
7fd59977 | 2369 | } |
2370 | break; | |
2371 | case MotionNotify: | |
2372 | { | |
08398024 | 2373 | if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window) |
2374 | { | |
2375 | break; | |
2376 | } | |
7fd59977 | 2377 | if( IsDragged ) |
2378 | { | |
7fd59977 | 2379 | if( !DragFirst ) |
b12e1c7b | 2380 | { |
2381 | if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand())) | |
2382 | { | |
2383 | ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False); | |
b12e1c7b | 2384 | } |
2385 | } | |
7fd59977 | 2386 | |
18d715bd | 2387 | X_Motion = aReport.xmotion.x; |
2388 | Y_Motion = aReport.xmotion.y; | |
7fd59977 | 2389 | DragFirst = Standard_False; |
2390 | ||
b12e1c7b | 2391 | Window aWindow = GetWindowHandle(VT_GetWindow()); |
2392 | Window aRoot; | |
2393 | int anX, anY; | |
2394 | unsigned int aWidth, aHeight, aBorderWidth, aDepth; | |
2395 | XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth); | |
2396 | GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion); | |
69adb9ce | 2397 | ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed); |
b12e1c7b | 2398 | ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate(); |
7fd59977 | 2399 | } |
2400 | else | |
2401 | { | |
18d715bd | 2402 | X_Motion = aReport.xmotion.x; |
2403 | Y_Motion = aReport.xmotion.y; | |
7fd59977 | 2404 | |
18d715bd | 2405 | // remove all the ButtonMotionMaskr |
2406 | while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ; | |
7fd59977 | 2407 | |
18d715bd | 2408 | if ( aReport.xmotion.state & ControlMask ) { |
2409 | if ( aReport.xmotion.state & Button1Mask ) { | |
7fd59977 | 2410 | ProcessControlButton1Motion(); |
2411 | } | |
18d715bd | 2412 | else if ( aReport.xmotion.state & Button2Mask ) { |
4fe56619 | 2413 | VT_ProcessControlButton2Motion(); |
7fd59977 | 2414 | } |
18d715bd | 2415 | else if ( aReport.xmotion.state & Button3Mask ) { |
4fe56619 | 2416 | VT_ProcessControlButton3Motion(); |
7fd59977 | 2417 | } |
2418 | } | |
4fe56619 | 2419 | else |
2420 | { | |
2421 | VT_ProcessMotion(); | |
7fd59977 | 2422 | } |
2423 | } | |
2424 | } | |
2425 | break; | |
2426 | } | |
7fd59977 | 2427 | return pick; |
2428 | } | |
2429 | ||
2430 | //============================================================================== | |
2431 | //function : VProcessEvents | |
2432 | //purpose : call by Tk_CreateFileHandler() to be able to manage the | |
2433 | // event in the Viewer window | |
2434 | //============================================================================== | |
2435 | ||
2436 | static void VProcessEvents(ClientData,int) | |
2437 | { | |
18d715bd | 2438 | NCollection_Vector<int> anEventNumbers; |
2439 | // Get number of messages from every display | |
2440 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
2441 | anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next()) | |
2442 | { | |
2443 | anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay())); | |
4269bd1b | 2444 | } |
18d715bd | 2445 | // Handle events for every display |
2446 | int anEventIter = 0; | |
2447 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
2448 | anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++) | |
2449 | { | |
4269bd1b | 2450 | for (int i = 0; i < anEventNumbers.Value(anEventIter) && |
18d715bd | 2451 | XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i) |
2452 | { | |
2453 | SetDisplayConnection (anIter.Key2()->GetDisplayConnection()); | |
2454 | int anEventResult = ViewerMainLoop( 0, NULL); | |
2455 | // If window is closed or context was not found finish current event processing loop | |
2456 | if (!anEventResult) | |
2457 | return; | |
2458 | } | |
7fd59977 | 2459 | } |
4269bd1b | 2460 | |
18d715bd | 2461 | SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection()); |
4269bd1b | 2462 | |
7fd59977 | 2463 | } |
2464 | #endif | |
2465 | ||
2466 | //============================================================================== | |
2467 | //function : OSWindowSetup | |
2468 | //purpose : Setup for the X11 window to be able to cath the event | |
2469 | //============================================================================== | |
2470 | ||
2471 | ||
2472 | static void OSWindowSetup() | |
2473 | { | |
4fe56619 | 2474 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
7fd59977 | 2475 | // X11 |
2476 | ||
2477 | Window window = VT_GetWindow()->XWindow(); | |
18d715bd | 2478 | SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); |
2479 | Display *aDisplay = GetDisplayConnection()->GetDisplay(); | |
2480 | XSynchronize(aDisplay, 1); | |
7fd59977 | 2481 | |
2482 | // X11 : For keyboard on SUN | |
2483 | XWMHints wmhints; | |
2484 | wmhints.flags = InputHint; | |
2485 | wmhints.input = 1; | |
2486 | ||
18d715bd | 2487 | XSetWMHints( aDisplay, window, &wmhints); |
7fd59977 | 2488 | |
18d715bd | 2489 | XSelectInput( aDisplay, window, ExposureMask | KeyPressMask | |
7fd59977 | 2490 | ButtonPressMask | ButtonReleaseMask | |
2491 | StructureNotifyMask | | |
2492 | PointerMotionMask | | |
2493 | Button1MotionMask | Button2MotionMask | | |
18d715bd | 2494 | Button3MotionMask | FocusChangeMask |
7fd59977 | 2495 | ); |
18d715bd | 2496 | Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW); |
2497 | XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1); | |
7fd59977 | 2498 | |
18d715bd | 2499 | XSynchronize(aDisplay, 0); |
7fd59977 | 2500 | |
2501 | #else | |
57c28b61 | 2502 | // _WIN32 |
7fd59977 | 2503 | #endif |
2504 | ||
2505 | } | |
2506 | ||
7fd59977 | 2507 | //============================================================================== |
2508 | //function : VFit | |
1beb58d7 | 2509 | //purpose : |
7fd59977 | 2510 | //============================================================================== |
2511 | ||
1beb58d7 | 2512 | static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv) |
7fd59977 | 2513 | { |
1beb58d7 | 2514 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2515 | if (aView.IsNull()) | |
b586500b | 2516 | { |
1beb58d7 | 2517 | std::cout << "Error: no active viewer!\n"; |
2518 | return 1; | |
b586500b | 2519 | } |
2520 | ||
1beb58d7 | 2521 | Standard_Boolean toFit = Standard_True; |
2522 | ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView); | |
2523 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
b586500b | 2524 | { |
1beb58d7 | 2525 | TCollection_AsciiString anArg (theArgv[anArgIter]); |
b586500b | 2526 | anArg.LowerCase(); |
1beb58d7 | 2527 | if (anUpdateTool.parseRedrawMode (anArg)) |
b586500b | 2528 | { |
1beb58d7 | 2529 | continue; |
2530 | } | |
2531 | else if (anArg == "-selected") | |
2532 | { | |
2533 | ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False); | |
2534 | toFit = Standard_False; | |
2535 | } | |
2536 | else | |
2537 | { | |
2538 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
b586500b | 2539 | } |
2540 | } | |
2541 | ||
1beb58d7 | 2542 | if (toFit) |
2543 | { | |
2544 | aView->FitAll (0.01, Standard_False); | |
7fd59977 | 2545 | } |
2546 | return 0; | |
2547 | } | |
2548 | ||
6262a303 | 2549 | //======================================================================= |
2550 | //function : VFitArea | |
2551 | //purpose : Fit view to show area located between two points | |
2552 | // : given in world 2D or 3D coordinates. | |
2553 | //======================================================================= | |
2554 | static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
2555 | { | |
2556 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
2557 | if (aView.IsNull()) | |
2558 | { | |
2559 | std::cerr << theArgVec[0] << "Error: No active view.\n"; | |
2560 | return 1; | |
2561 | } | |
2562 | ||
2563 | // Parse arguments. | |
2564 | gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0); | |
2565 | gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0); | |
2566 | ||
2567 | if (theArgNb == 5) | |
2568 | { | |
2569 | aWorldPnt1.SetX (Draw::Atof (theArgVec[1])); | |
2570 | aWorldPnt1.SetY (Draw::Atof (theArgVec[2])); | |
2571 | aWorldPnt2.SetX (Draw::Atof (theArgVec[3])); | |
2572 | aWorldPnt2.SetY (Draw::Atof (theArgVec[4])); | |
2573 | } | |
2574 | else if (theArgNb == 7) | |
2575 | { | |
2576 | aWorldPnt1.SetX (Draw::Atof (theArgVec[1])); | |
2577 | aWorldPnt1.SetY (Draw::Atof (theArgVec[2])); | |
2578 | aWorldPnt1.SetZ (Draw::Atof (theArgVec[3])); | |
2579 | aWorldPnt2.SetX (Draw::Atof (theArgVec[4])); | |
2580 | aWorldPnt2.SetY (Draw::Atof (theArgVec[5])); | |
2581 | aWorldPnt2.SetZ (Draw::Atof (theArgVec[6])); | |
2582 | } | |
2583 | else | |
2584 | { | |
2585 | std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n"; | |
2586 | theDI.PrintHelp(theArgVec[0]); | |
2587 | return 1; | |
2588 | } | |
2589 | ||
2590 | // Convert model coordinates to view space | |
2591 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); | |
2592 | gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1); | |
2593 | gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2); | |
2594 | ||
2595 | // Determine fit area | |
2596 | gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y())); | |
2597 | gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y())); | |
2598 | ||
2599 | Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner); | |
2600 | ||
2601 | if (aDiagonal < Precision::Confusion()) | |
2602 | { | |
2603 | std::cerr << theArgVec[0] << "Error: view area is too small.\n"; | |
2604 | return 1; | |
2605 | } | |
2606 | ||
2607 | aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y()); | |
2608 | return 0; | |
2609 | } | |
2610 | ||
7fd59977 | 2611 | //============================================================================== |
2612 | //function : VZFit | |
2613 | //purpose : ZFitall, no DRAW arguments | |
2614 | //Draw arg : No args | |
2615 | //============================================================================== | |
197ac94e | 2616 | static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec) |
7fd59977 | 2617 | { |
197ac94e | 2618 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
2619 | ||
2620 | if (aCurrentView.IsNull()) | |
2621 | { | |
2622 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; | |
2623 | return 1; | |
2624 | } | |
2625 | ||
2626 | if (theArgsNb == 1) | |
2627 | { | |
c357e426 | 2628 | aCurrentView->ZFitAll(); |
197ac94e | 2629 | aCurrentView->Redraw(); |
2630 | return 0; | |
2631 | } | |
2632 | ||
2633 | Standard_Real aScale = 1.0; | |
2634 | ||
2635 | if (theArgsNb >= 2) | |
2636 | { | |
2637 | aScale = Draw::Atoi (theArgVec[1]); | |
2638 | } | |
2639 | ||
c357e426 | 2640 | aCurrentView->ZFitAll (aScale); |
197ac94e | 2641 | aCurrentView->Redraw(); |
7fd59977 | 2642 | |
197ac94e | 2643 | return 0; |
2644 | } | |
7fd59977 | 2645 | |
197ac94e | 2646 | //============================================================================== |
2647 | //function : VRepaint | |
2648 | //purpose : | |
2649 | //============================================================================== | |
56689b27 | 2650 | static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec) |
7fd59977 | 2651 | { |
56689b27 | 2652 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2653 | if (aView.IsNull()) | |
2654 | { | |
2655 | std::cout << "Error: no active viewer!\n"; | |
2656 | return 1; | |
2657 | } | |
2658 | ||
2659 | Standard_Boolean isImmediateUpdate = Standard_False; | |
2660 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
2661 | { | |
2662 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
2663 | anArg.LowerCase(); | |
2664 | if (anArg == "-immediate") | |
2665 | { | |
2666 | isImmediateUpdate = Standard_True; | |
2667 | if (anArgIter + 1 < theArgNb | |
2668 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate)) | |
2669 | { | |
2670 | ++anArgIter; | |
2671 | } | |
2672 | } | |
2673 | else | |
2674 | { | |
2675 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
2676 | } | |
2677 | } | |
2678 | ||
2679 | if (isImmediateUpdate) | |
2680 | { | |
2681 | aView->RedrawImmediate(); | |
2682 | } | |
2683 | else | |
2684 | { | |
2685 | aView->Redraw(); | |
2686 | } | |
2687 | return 0; | |
7fd59977 | 2688 | } |
2689 | ||
7fd59977 | 2690 | //============================================================================== |
2691 | //function : VClear | |
2692 | //purpose : Remove all the object from the viewer | |
2693 | //Draw arg : No args | |
2694 | //============================================================================== | |
2695 | ||
2696 | static int VClear(Draw_Interpretor& , Standard_Integer , const char** ) | |
2697 | { | |
2698 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
2699 | if(!V.IsNull()) | |
2700 | ViewerTest::Clear(); | |
2701 | return 0; | |
2702 | } | |
2703 | ||
2704 | //============================================================================== | |
2705 | //function : VPick | |
2706 | //purpose : | |
2707 | //============================================================================== | |
2708 | ||
2709 | static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2710 | { if (ViewerTest::CurrentView().IsNull() ) return 1; | |
2711 | ||
2712 | if ( argc < 4 ) { | |
586db386 | 2713 | di << argv[0] << "Invalid number of arguments\n"; |
7fd59977 | 2714 | return 1; |
2715 | } | |
2716 | ||
2717 | while (ViewerMainLoop( argc, argv)) { | |
2718 | } | |
2719 | ||
2720 | return 0; | |
2721 | } | |
2722 | ||
7fd59977 | 2723 | //============================================================================== |
2724 | //function : VSetBg | |
2725 | //purpose : Load image as background | |
2726 | //============================================================================== | |
2727 | ||
2728 | static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2729 | { | |
2730 | if (argc < 2 || argc > 3) | |
2731 | { | |
586db386 | 2732 | di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n"; |
2733 | di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n"; | |
7fd59977 | 2734 | return 1; |
2735 | } | |
2736 | ||
2737 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2738 | if(AISContext.IsNull()) | |
2739 | { | |
2740 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2741 | return 1; | |
2742 | } | |
2743 | ||
2744 | Aspect_FillMethod aFillType = Aspect_FM_CENTERED; | |
2745 | if (argc == 3) | |
2746 | { | |
2747 | const char* szType = argv[2]; | |
2748 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; | |
2749 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; | |
2750 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; | |
2751 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; | |
2752 | else | |
2753 | { | |
2754 | di << "Wrong fill type : " << szType << "\n"; | |
586db386 | 2755 | di << "Must be one of CENTERED, TILED, STRETCH, NONE\n"; |
7fd59977 | 2756 | return 1; |
2757 | } | |
2758 | } | |
2759 | ||
2760 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2761 | V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True); | |
2762 | ||
2763 | return 0; | |
2764 | } | |
2765 | ||
f8b2ed36 | 2766 | //============================================================================== |
2767 | //function : VSetBgMode | |
2768 | //purpose : Change background image fill type | |
2769 | //============================================================================== | |
2770 | ||
2771 | static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2772 | { | |
2773 | if (argc != 2) | |
2774 | { | |
586db386 | 2775 | di << "Usage : " << argv[0] << " filltype : Change background image mode\n"; |
2776 | di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n"; | |
f8b2ed36 | 2777 | return 1; |
2778 | } | |
2779 | ||
2780 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2781 | if(AISContext.IsNull()) | |
2782 | { | |
2783 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2784 | return 1; | |
2785 | } | |
1d47d8d0 | 2786 | Aspect_FillMethod aFillType = Aspect_FM_NONE; |
2787 | const char* szType = argv[1]; | |
2788 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; | |
2789 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; | |
2790 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; | |
2791 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; | |
2792 | else | |
f8b2ed36 | 2793 | { |
1d47d8d0 | 2794 | di << "Wrong fill type : " << szType << "\n"; |
586db386 | 2795 | di << "Must be one of CENTERED, TILED, STRETCH, NONE\n"; |
1d47d8d0 | 2796 | return 1; |
f8b2ed36 | 2797 | } |
f8b2ed36 | 2798 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); |
2799 | V3dView->SetBgImageStyle(aFillType, Standard_True); | |
f8b2ed36 | 2800 | return 0; |
2801 | } | |
2802 | ||
7fd59977 | 2803 | //============================================================================== |
2804 | //function : VSetGradientBg | |
2805 | //purpose : Mount gradient background | |
2806 | //============================================================================== | |
2807 | static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2808 | { | |
2809 | if (argc != 8 ) | |
2810 | { | |
586db386 | 2811 | di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background\n"; |
2812 | di << "R1,G1,B1,R2,G2,B2 = [0..255]\n"; | |
2813 | di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n"; | |
2814 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n"; | |
7fd59977 | 2815 | return 1; |
2816 | } | |
2817 | ||
2818 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2819 | if(AISContext.IsNull()) | |
2820 | { | |
2821 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2822 | return 1; | |
2823 | } | |
2824 | if (argc == 8) | |
2825 | { | |
2826 | ||
91322f44 | 2827 | Standard_Real R1 = Draw::Atof(argv[1])/255.; |
2828 | Standard_Real G1 = Draw::Atof(argv[2])/255.; | |
2829 | Standard_Real B1 = Draw::Atof(argv[3])/255.; | |
7fd59977 | 2830 | Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB); |
2831 | ||
91322f44 | 2832 | Standard_Real R2 = Draw::Atof(argv[4])/255.; |
2833 | Standard_Real G2 = Draw::Atof(argv[5])/255.; | |
2834 | Standard_Real B2 = Draw::Atof(argv[6])/255.; | |
7fd59977 | 2835 | |
2836 | Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB); | |
91322f44 | 2837 | int aType = Draw::Atoi(argv[7]); |
7fd59977 | 2838 | if( aType < 0 || aType > 8 ) |
2839 | { | |
586db386 | 2840 | di << "Wrong fill type \n"; |
2841 | di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n"; | |
2842 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n"; | |
7fd59977 | 2843 | return 1; |
2844 | } | |
2845 | ||
2846 | Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType); | |
2847 | ||
2848 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2849 | V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1); | |
2850 | } | |
2851 | ||
2852 | return 0; | |
2853 | } | |
2854 | ||
f8b2ed36 | 2855 | //============================================================================== |
2856 | //function : VSetGradientBgMode | |
2857 | //purpose : Change gradient background fill style | |
2858 | //============================================================================== | |
2859 | static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2860 | { | |
2861 | if (argc != 2 ) | |
2862 | { | |
586db386 | 2863 | di << "Usage : " << argv[0] << " Type : Change gradient background fill type\n"; |
2864 | di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n"; | |
2865 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n"; | |
f8b2ed36 | 2866 | return 1; |
2867 | } | |
2868 | ||
2869 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2870 | if(AISContext.IsNull()) | |
2871 | { | |
2872 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2873 | return 1; | |
2874 | } | |
2875 | if (argc == 2) | |
2876 | { | |
91322f44 | 2877 | int aType = Draw::Atoi(argv[1]); |
f8b2ed36 | 2878 | if( aType < 0 || aType > 8 ) |
2879 | { | |
586db386 | 2880 | di << "Wrong fill type \n"; |
2881 | di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n"; | |
2882 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n"; | |
f8b2ed36 | 2883 | return 1; |
2884 | } | |
2885 | ||
2886 | Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType); | |
2887 | ||
2888 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2889 | V3dView->SetBgGradientStyle( aMethod, 1 ); | |
2890 | } | |
2891 | ||
2892 | return 0; | |
2893 | } | |
2894 | ||
2895 | //============================================================================== | |
2896 | //function : VSetColorBg | |
2897 | //purpose : Set color background | |
2898 | //============================================================================== | |
2899 | static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2900 | { | |
2901 | if (argc != 4 ) | |
2902 | { | |
586db386 | 2903 | di << "Usage : " << argv[0] << " R G B : Set color background\n"; |
2904 | di << "R,G,B = [0..255]\n"; | |
f8b2ed36 | 2905 | return 1; |
2906 | } | |
2907 | ||
2908 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
2909 | if(AISContext.IsNull()) | |
2910 | { | |
2911 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
2912 | return 1; | |
2913 | } | |
2914 | if (argc == 4) | |
2915 | { | |
2916 | ||
91322f44 | 2917 | Standard_Real R = Draw::Atof(argv[1])/255.; |
2918 | Standard_Real G = Draw::Atof(argv[2])/255.; | |
2919 | Standard_Real B = Draw::Atof(argv[3])/255.; | |
f8b2ed36 | 2920 | Quantity_Color aColor(R,G,B,Quantity_TOC_RGB); |
2921 | ||
2922 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2923 | V3dView->SetBackgroundColor( aColor ); | |
2924 | V3dView->Update(); | |
2925 | } | |
2926 | ||
2927 | return 0; | |
2928 | } | |
2929 | ||
f42753ed | 2930 | //============================================================================== |
2931 | //function : VSetDefaultBg | |
2932 | //purpose : Set default viewer background fill color | |
2933 | //============================================================================== | |
2934 | static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
2935 | { | |
2936 | if (theArgNb != 4 | |
2937 | && theArgNb != 8) | |
2938 | { | |
2939 | std::cout << "Error: wrong syntax! See usage:\n"; | |
2940 | theDI.PrintHelp (theArgVec[0]); | |
2941 | return 1; | |
2942 | } | |
2943 | ||
2944 | ViewerTest_DefaultBackground.FillMethod = | |
2945 | theArgNb == 4 ? Aspect_GFM_NONE | |
2946 | : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]); | |
2947 | ||
2948 | if (theArgNb == 4) | |
2949 | { | |
2950 | Standard_Real R = Draw::Atof (theArgVec[1]) / 255.; | |
2951 | Standard_Real G = Draw::Atof (theArgVec[2]) / 255.; | |
2952 | Standard_Real B = Draw::Atof (theArgVec[3]) / 255.; | |
2953 | ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB); | |
2954 | } | |
2955 | else | |
2956 | { | |
2957 | Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.; | |
2958 | Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.; | |
2959 | Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.; | |
2960 | ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB); | |
2961 | ||
2962 | Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.; | |
2963 | Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.; | |
2964 | Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.; | |
2965 | ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB); | |
2966 | } | |
2967 | ||
2968 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
2969 | anIter (ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
2970 | { | |
2971 | const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer(); | |
2972 | aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor); | |
2973 | aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1, | |
2974 | ViewerTest_DefaultBackground.GradientColor2, | |
2975 | ViewerTest_DefaultBackground.FillMethod); | |
2976 | } | |
2977 | ||
2978 | return 0; | |
2979 | } | |
2980 | ||
7fd59977 | 2981 | //============================================================================== |
2982 | //function : VScale | |
2983 | //purpose : View Scaling | |
2984 | //============================================================================== | |
2985 | ||
2986 | static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2987 | { | |
2988 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
2989 | if ( V3dView.IsNull() ) return 1; | |
2990 | ||
2991 | if ( argc != 4 ) { | |
586db386 | 2992 | di << argv[0] << "Invalid number of arguments\n"; |
7fd59977 | 2993 | return 1; |
2994 | } | |
91322f44 | 2995 | V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) ); |
7fd59977 | 2996 | return 0; |
2997 | } | |
2998 | //============================================================================== | |
536d98e2 | 2999 | //function : VZBuffTrihedron |
3000 | //purpose : | |
7fd59977 | 3001 | //============================================================================== |
3002 | ||
536d98e2 | 3003 | static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/, |
3004 | Standard_Integer theArgNb, | |
3005 | const char** theArgVec) | |
7fd59977 | 3006 | { |
536d98e2 | 3007 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
3008 | if (aView.IsNull()) | |
3009 | { | |
3010 | std::cout << "Error: no active viewer!\n"; | |
3011 | return 1; | |
3012 | } | |
7fd59977 | 3013 | |
536d98e2 | 3014 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
7c8a8fcc | 3015 | |
536d98e2 | 3016 | Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER; |
3017 | V3d_TypeOfVisualization aVisType = V3d_ZBUFFER; | |
3018 | Quantity_Color aLabelsColor = Quantity_NOC_WHITE; | |
3019 | Quantity_Color anArrowColorX = Quantity_NOC_RED; | |
3020 | Quantity_Color anArrowColorY = Quantity_NOC_GREEN; | |
3021 | Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1; | |
3022 | Standard_Real aScale = 0.1; | |
3023 | Standard_Real aSizeRatio = 0.8; | |
3024 | Standard_Real anArrowDiam = 0.05; | |
3025 | Standard_Integer aNbFacets = 12; | |
3026 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
7c8a8fcc | 3027 | { |
536d98e2 | 3028 | Standard_CString anArg = theArgVec[anArgIter]; |
3029 | TCollection_AsciiString aFlag (anArg); | |
3030 | aFlag.LowerCase(); | |
3031 | if (anUpdateTool.parseRedrawMode (aFlag)) | |
7c8a8fcc | 3032 | { |
536d98e2 | 3033 | continue; |
3034 | } | |
3035 | else if (aFlag == "-on") | |
7c8a8fcc | 3036 | { |
536d98e2 | 3037 | continue; |
3038 | } | |
3039 | else if (aFlag == "-off") | |
7c8a8fcc | 3040 | { |
536d98e2 | 3041 | aView->TriedronErase(); |
3042 | return 0; | |
3043 | } | |
3044 | else if (aFlag == "-pos" | |
3045 | || aFlag == "-position" | |
3046 | || aFlag == "-corner") | |
7c8a8fcc | 3047 | { |
536d98e2 | 3048 | if (++anArgIter >= theArgNb) |
3049 | { | |
3050 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3051 | return 1; | |
3052 | } | |
3053 | ||
3054 | TCollection_AsciiString aPosName (theArgVec[anArgIter]); | |
3055 | aPosName.LowerCase(); | |
3056 | if (aPosName == "center") | |
3057 | { | |
3058 | aPosition = Aspect_TOTP_CENTER; | |
3059 | } | |
3060 | else if (aPosName == "left_lower" | |
3061 | || aPosName == "lower_left" | |
3062 | || aPosName == "leftlower" | |
3063 | || aPosName == "lowerleft") | |
3064 | { | |
3065 | aPosition = Aspect_TOTP_LEFT_LOWER; | |
3066 | } | |
3067 | else if (aPosName == "left_upper" | |
3068 | || aPosName == "upper_left" | |
3069 | || aPosName == "leftupper" | |
3070 | || aPosName == "upperleft") | |
3071 | { | |
3072 | aPosition = Aspect_TOTP_LEFT_UPPER; | |
3073 | } | |
3074 | else if (aPosName == "right_lower" | |
3075 | || aPosName == "lower_right" | |
3076 | || aPosName == "rightlower" | |
3077 | || aPosName == "lowerright") | |
3078 | { | |
3079 | aPosition = Aspect_TOTP_RIGHT_LOWER; | |
3080 | } | |
3081 | else if (aPosName == "right_upper" | |
3082 | || aPosName == "upper_right" | |
3083 | || aPosName == "rightupper" | |
3084 | || aPosName == "upperright") | |
3085 | { | |
3086 | aPosition = Aspect_TOTP_RIGHT_UPPER; | |
3087 | } | |
3088 | else | |
3089 | { | |
3090 | std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n"; | |
3091 | return 1; | |
3092 | } | |
3093 | } | |
3094 | else if (aFlag == "-type") | |
7c8a8fcc | 3095 | { |
536d98e2 | 3096 | if (++anArgIter >= theArgNb) |
3097 | { | |
3098 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3099 | return 1; | |
3100 | } | |
3101 | ||
3102 | TCollection_AsciiString aTypeName (theArgVec[anArgIter]); | |
3103 | aTypeName.LowerCase(); | |
3104 | if (aTypeName == "wireframe" | |
3105 | || aTypeName == "wire") | |
3106 | { | |
3107 | aVisType = V3d_WIREFRAME; | |
3108 | } | |
3109 | else if (aTypeName == "zbuffer" | |
3110 | || aTypeName == "shaded") | |
3111 | { | |
3112 | aVisType = V3d_ZBUFFER; | |
3113 | } | |
3114 | else | |
3115 | { | |
3116 | std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n"; | |
3117 | } | |
3118 | } | |
3119 | else if (aFlag == "-scale") | |
7c8a8fcc | 3120 | { |
536d98e2 | 3121 | if (++anArgIter >= theArgNb) |
3122 | { | |
3123 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3124 | return 1; | |
3125 | } | |
3126 | ||
3127 | aScale = Draw::Atof (theArgVec[anArgIter]); | |
7c8a8fcc | 3128 | } |
536d98e2 | 3129 | else if (aFlag == "-size" |
3130 | || aFlag == "-sizeratio") | |
3131 | { | |
3132 | if (++anArgIter >= theArgNb) | |
3133 | { | |
3134 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3135 | return 1; | |
3136 | } | |
7c8a8fcc | 3137 | |
536d98e2 | 3138 | aSizeRatio = Draw::Atof (theArgVec[anArgIter]); |
3139 | } | |
3140 | else if (aFlag == "-arrowdiam" | |
3141 | || aFlag == "-arrowdiameter") | |
3142 | { | |
3143 | if (++anArgIter >= theArgNb) | |
3144 | { | |
3145 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3146 | return 1; | |
3147 | } | |
7c8a8fcc | 3148 | |
536d98e2 | 3149 | anArrowDiam = Draw::Atof (theArgVec[anArgIter]); |
3150 | } | |
3151 | else if (aFlag == "-nbfacets") | |
3152 | { | |
3153 | if (++anArgIter >= theArgNb) | |
3154 | { | |
3155 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3156 | return 1; | |
3157 | } | |
7c8a8fcc | 3158 | |
536d98e2 | 3159 | aNbFacets = Draw::Atoi (theArgVec[anArgIter]); |
3160 | } | |
3161 | else if (aFlag == "-colorlabel" | |
3162 | || aFlag == "-colorlabels") | |
7c8a8fcc | 3163 | { |
536d98e2 | 3164 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
3165 | theArgVec + anArgIter + 1, | |
3166 | aLabelsColor); | |
3167 | if (aNbParsed == 0) | |
3168 | { | |
3169 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3170 | return 1; | |
3171 | } | |
3172 | anArgIter += aNbParsed; | |
7c8a8fcc | 3173 | } |
536d98e2 | 3174 | else if (aFlag == "-colorarrowx") |
7c8a8fcc | 3175 | { |
536d98e2 | 3176 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
3177 | theArgVec + anArgIter + 1, | |
3178 | anArrowColorX); | |
3179 | if (aNbParsed == 0) | |
3180 | { | |
3181 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3182 | return 1; | |
3183 | } | |
3184 | anArgIter += aNbParsed; | |
3185 | } | |
3186 | else if (aFlag == "-colorarrowy") | |
7c8a8fcc | 3187 | { |
536d98e2 | 3188 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
3189 | theArgVec + anArgIter + 1, | |
3190 | anArrowColorY); | |
3191 | if (aNbParsed == 0) | |
3192 | { | |
3193 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3194 | return 1; | |
3195 | } | |
3196 | anArgIter += aNbParsed; | |
3197 | } | |
3198 | else if (aFlag == "-colorarrowz") | |
7c8a8fcc | 3199 | { |
536d98e2 | 3200 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
3201 | theArgVec + anArgIter + 1, | |
3202 | anArrowColorZ); | |
3203 | if (aNbParsed == 0) | |
3204 | { | |
3205 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3206 | return 1; | |
3207 | } | |
3208 | anArgIter += aNbParsed; | |
3209 | } | |
3210 | else | |
3211 | { | |
3212 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
7c8a8fcc | 3213 | return 1; |
3214 | } | |
7c8a8fcc | 3215 | } |
3216 | ||
536d98e2 | 3217 | aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(), |
3218 | aSizeRatio, anArrowDiam, aNbFacets); | |
3219 | aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType); | |
c357e426 | 3220 | aView->ZFitAll(); |
7fd59977 | 3221 | return 0; |
3222 | } | |
3223 | ||
3224 | //============================================================================== | |
3225 | //function : VRotate | |
3226 | //purpose : Camera Rotating | |
3227 | //============================================================================== | |
3228 | ||
4af098ba | 3229 | static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec) |
3230 | { | |
3231 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3232 | if (aView.IsNull()) | |
3233 | { | |
3234 | std::cout << "No active view!\n"; | |
7fd59977 | 3235 | return 1; |
3236 | } | |
3237 | ||
4af098ba | 3238 | Standard_Boolean hasFlags = Standard_False; |
3239 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
3240 | { | |
3241 | Standard_CString anArg (theArgVec[anArgIter]); | |
3242 | TCollection_AsciiString aFlag (anArg); | |
3243 | aFlag.LowerCase(); | |
3244 | if (aFlag == "-mousestart" | |
3245 | || aFlag == "-mousefrom") | |
3246 | { | |
3247 | hasFlags = Standard_True; | |
3248 | if (anArgIter + 2 >= theArgNb) | |
3249 | { | |
3250 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
3251 | return 1; | |
3252 | } | |
3253 | ||
3254 | Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]); | |
3255 | Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]); | |
3256 | aView->StartRotation (anX, anY); | |
3257 | } | |
3258 | else if (aFlag == "-mousemove") | |
3259 | { | |
3260 | hasFlags = Standard_True; | |
3261 | if (anArgIter + 2 >= theArgNb) | |
3262 | { | |
3263 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
3264 | return 1; | |
3265 | } | |
3266 | ||
3267 | Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]); | |
3268 | Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]); | |
3269 | aView->Rotation (anX, anY); | |
3270 | } | |
3271 | else if (theArgNb != 4 | |
3272 | && theArgNb != 7) | |
3273 | { | |
3274 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
3275 | return 1; | |
3276 | } | |
3277 | } | |
3278 | ||
3279 | if (hasFlags) | |
3280 | { | |
7fd59977 | 3281 | return 0; |
4af098ba | 3282 | } |
3283 | else if (theArgNb == 4) | |
3284 | { | |
3285 | Standard_Real anAX = Draw::Atof (theArgVec[1]); | |
3286 | Standard_Real anAY = Draw::Atof (theArgVec[2]); | |
3287 | Standard_Real anAZ = Draw::Atof (theArgVec[3]); | |
3288 | aView->Rotate (anAX, anAY, anAZ); | |
3289 | return 0; | |
3290 | } | |
3291 | else if (theArgNb == 7) | |
3292 | { | |
3293 | Standard_Real anAX = Draw::Atof (theArgVec[1]); | |
3294 | Standard_Real anAY = Draw::Atof (theArgVec[2]); | |
3295 | Standard_Real anAZ = Draw::Atof (theArgVec[3]); | |
3296 | ||
3297 | Standard_Real anX = Draw::Atof (theArgVec[4]); | |
3298 | Standard_Real anY = Draw::Atof (theArgVec[5]); | |
3299 | Standard_Real anZ = Draw::Atof (theArgVec[6]); | |
3300 | ||
3301 | aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ); | |
7fd59977 | 3302 | return 0; |
7fd59977 | 3303 | } |
4af098ba | 3304 | |
3305 | std::cout << "Error: Invalid number of arguments\n"; | |
3306 | return 1; | |
7fd59977 | 3307 | } |
3308 | ||
3309 | //============================================================================== | |
3310 | //function : VZoom | |
3311 | //purpose : View zoom in / out (relative to current zoom) | |
3312 | //============================================================================== | |
3313 | ||
3314 | static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
3315 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
3316 | if ( V3dView.IsNull() ) { | |
3317 | return 1; | |
3318 | } | |
3319 | ||
3320 | if ( argc == 2 ) { | |
91322f44 | 3321 | Standard_Real coef = Draw::Atof(argv[1]); |
7fd59977 | 3322 | if ( coef <= 0.0 ) { |
586db386 | 3323 | di << argv[1] << "Invalid value\n"; |
7fd59977 | 3324 | return 1; |
3325 | } | |
91322f44 | 3326 | V3dView->SetZoom( Draw::Atof(argv[1]) ); |
7fd59977 | 3327 | return 0; |
3328 | } else { | |
586db386 | 3329 | di << argv[0] << " Invalid number of arguments\n"; |
7fd59977 | 3330 | return 1; |
3331 | } | |
3332 | } | |
3333 | ||
3334 | //============================================================================== | |
3335 | //function : VPan | |
3336 | //purpose : View panning (in pixels) | |
3337 | //============================================================================== | |
3338 | ||
3339 | static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
3340 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
3341 | if ( V3dView.IsNull() ) return 1; | |
3342 | ||
3343 | if ( argc == 3 ) { | |
91322f44 | 3344 | V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) ); |
7fd59977 | 3345 | return 0; |
3346 | } else { | |
586db386 | 3347 | di << argv[0] << " Invalid number of arguments\n"; |
7fd59977 | 3348 | return 1; |
3349 | } | |
3350 | } | |
3351 | ||
49e1a5c7 | 3352 | //============================================================================== |
3353 | //function : VPlace | |
3354 | //purpose : Place the point (in pixels) at the center of the window | |
3355 | //============================================================================== | |
3356 | static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs) | |
3357 | { | |
3358 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3359 | if (aView.IsNull()) | |
3360 | { | |
3361 | std::cerr << theArgs[0] << "Error: no active view." << std::endl; | |
3362 | return 1; | |
3363 | } | |
3364 | ||
3365 | if (theArgNb != 3) | |
3366 | { | |
3367 | std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl; | |
3368 | return 1; | |
3369 | } | |
3370 | ||
3371 | aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale()); | |
3372 | ||
3373 | return 0; | |
3374 | } | |
7fd59977 | 3375 | |
3376 | //============================================================================== | |
3377 | //function : VExport | |
5cedc27f | 3378 | //purpose : Export the view to a vector graphic format (PS, EMF, PDF) |
7fd59977 | 3379 | //============================================================================== |
3380 | ||
3381 | static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3382 | { | |
3383 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
5cedc27f K |
3384 | if (V3dView.IsNull()) |
3385 | return 1; | |
7fd59977 | 3386 | |
5cedc27f K |
3387 | if (argc == 1) |
3388 | { | |
3389 | std::cout << "Usage: " << argv[0] << " Filename [Format]\n"; | |
7fd59977 | 3390 | return 1; |
3391 | } | |
3392 | ||
5cedc27f K |
3393 | Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF; |
3394 | TCollection_AsciiString aFormatStr; | |
3395 | ||
3396 | TCollection_AsciiString aFileName (argv[1]); | |
3397 | Standard_Integer aLen = aFileName.Length(); | |
3398 | ||
3399 | if (argc > 2) | |
3400 | { | |
3401 | aFormatStr = TCollection_AsciiString (argv[2]); | |
3402 | } | |
3403 | else if (aLen >= 4) | |
3404 | { | |
3405 | if (aFileName.Value (aLen - 2) == '.') | |
3406 | { | |
c3282ec1 | 3407 | aFormatStr = aFileName.ToCString() + aLen - 2; |
5cedc27f K |
3408 | } |
3409 | else if (aFileName.Value (aLen - 3) == '.') | |
3410 | { | |
c3282ec1 | 3411 | aFormatStr = aFileName.ToCString() + aLen - 3; |
5cedc27f K |
3412 | } |
3413 | else | |
3414 | { | |
3415 | std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n"; | |
3416 | return 1; | |
3417 | } | |
3418 | } | |
3419 | else | |
3420 | { | |
3421 | std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n"; | |
3422 | return 1; | |
3423 | } | |
3424 | ||
3425 | aFormatStr.UpperCase(); | |
3426 | if (aFormatStr == "PS") | |
3427 | anExpFormat = Graphic3d_EF_PostScript; | |
3428 | else if (aFormatStr == "EPS") | |
3429 | anExpFormat = Graphic3d_EF_EnhPostScript; | |
3430 | else if (aFormatStr == "TEX") | |
3431 | anExpFormat = Graphic3d_EF_TEX; | |
3432 | else if (aFormatStr == "PDF") | |
3433 | anExpFormat = Graphic3d_EF_PDF; | |
3434 | else if (aFormatStr == "SVG") | |
3435 | anExpFormat = Graphic3d_EF_SVG; | |
3436 | else if (aFormatStr == "PGF") | |
3437 | anExpFormat = Graphic3d_EF_PGF; | |
3438 | else if (aFormatStr == "EMF") | |
3439 | anExpFormat = Graphic3d_EF_EMF; | |
3440 | else | |
3441 | { | |
3442 | std::cout << "Invalid export format '" << aFormatStr << "'\n"; | |
3443 | return 1; | |
3444 | } | |
3445 | ||
404c8936 | 3446 | Standard_DISABLE_DEPRECATION_WARNINGS |
c357e426 | 3447 | try |
3448 | { | |
3449 | if (!V3dView->Export (argv[1], anExpFormat)) | |
9753e6de | 3450 | { |
3451 | di << "Error: export of image to " << aFormatStr << " failed!\n"; | |
3452 | } | |
3453 | } | |
9775fa61 | 3454 | catch (Standard_Failure const& anException) |
5cedc27f | 3455 | { |
9753e6de | 3456 | di << "Error: export of image to " << aFormatStr << " failed"; |
9775fa61 | 3457 | di << " (exception: " << anException.GetMessageString() << ")"; |
5cedc27f | 3458 | } |
404c8936 | 3459 | Standard_ENABLE_DEPRECATION_WARNINGS |
7fd59977 | 3460 | return 0; |
3461 | } | |
3462 | ||
71215351 | 3463 | static int VColorScale (Draw_Interpretor& theDI, |
3464 | Standard_Integer theArgNb, | |
3465 | const char** theArgVec) | |
3466 | { | |
7fd59977 | 3467 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
71215351 | 3468 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
3469 | if (aContext.IsNull()) | |
3470 | { | |
3471 | std::cout << "Error: no active view!\n"; | |
3472 | return 1; | |
7fd59977 | 3473 | } |
24a88697 | 3474 | if (theArgNb <= 1) |
3475 | { | |
3476 | std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n"; | |
3477 | return 1; | |
3478 | } | |
7fd59977 | 3479 | |
4b3d6eb1 | 3480 | Handle(AIS_ColorScale) aColorScale; |
7a324550 | 3481 | if (GetMapOfAIS().IsBound2 (theArgVec[1])) |
71215351 | 3482 | { |
4b3d6eb1 | 3483 | // find existing object |
3484 | aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1])); | |
3485 | if (aColorScale.IsNull()) | |
7a324550 | 3486 | { |
3487 | std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n"; | |
3488 | return 1; | |
3489 | } | |
3490 | } | |
71215351 | 3491 | |
7a324550 | 3492 | if (theArgNb <= 2) |
3493 | { | |
4b3d6eb1 | 3494 | if (aColorScale.IsNull()) |
3495 | { | |
3496 | std::cout << "Syntax error: colorscale with a given name does not exist.\n"; | |
3497 | return 1; | |
3498 | } | |
3499 | ||
7a324550 | 3500 | theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n" |
4b3d6eb1 | 3501 | << "Min range: " << aColorScale->GetMin() << "\n" |
3502 | << "Max range: " << aColorScale->GetMax() << "\n" | |
3503 | << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n" | |
3504 | << "Text height: " << aColorScale->GetTextHeight() << "\n" | |
3505 | << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n" | |
3506 | << "Color scale title: " << aColorScale->GetTitle() << "\n" | |
71215351 | 3507 | << "Label position: "; |
4b3d6eb1 | 3508 | switch (aColorScale->GetLabelPosition()) |
71215351 | 3509 | { |
3510 | case Aspect_TOCSP_NONE: | |
3511 | theDI << "None\n"; | |
3512 | break; | |
3513 | case Aspect_TOCSP_LEFT: | |
3514 | theDI << "Left\n"; | |
3515 | break; | |
3516 | case Aspect_TOCSP_RIGHT: | |
3517 | theDI << "Right\n"; | |
3518 | break; | |
3519 | case Aspect_TOCSP_CENTER: | |
3520 | theDI << "Center\n"; | |
3521 | break; | |
3522 | } | |
3523 | return 0; | |
3524 | } | |
71215351 | 3525 | |
4b3d6eb1 | 3526 | if (aColorScale.IsNull()) |
3527 | { | |
3528 | aColorScale = new AIS_ColorScale(); | |
3529 | aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD); | |
3530 | aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER)); | |
3531 | } | |
3532 | ||
3533 | ViewerTest_AutoUpdater anUpdateTool (aContext, aView); | |
7a324550 | 3534 | for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter) |
71215351 | 3535 | { |
3536 | Standard_CString anArg = theArgVec[anArgIter]; | |
3537 | TCollection_AsciiString aFlag (anArg); | |
3538 | aFlag.LowerCase(); | |
3539 | if (anUpdateTool.parseRedrawMode (aFlag)) | |
3540 | { | |
3541 | continue; | |
3542 | } | |
3543 | else if (aFlag == "-range") | |
3544 | { | |
3545 | if (anArgIter + 3 >= theArgNb) | |
3546 | { | |
3547 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3548 | return 1; | |
3549 | } | |
3550 | ||
4b3d6eb1 | 3551 | const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]); |
3552 | const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]); | |
3553 | const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]); | |
3554 | if (!aRangeMin.IsRealValue() | |
3555 | || !aRangeMax.IsRealValue()) | |
71215351 | 3556 | { |
4b3d6eb1 | 3557 | std::cout << "Error: the range values should be real!\n"; |
71215351 | 3558 | return 1; |
3559 | } | |
4b3d6eb1 | 3560 | else if (!aNbIntervals.IsIntegerValue()) |
71215351 | 3561 | { |
3562 | std::cout << "Error: the number of intervals should be integer!\n"; | |
3563 | return 1; | |
3564 | } | |
3565 | ||
4b3d6eb1 | 3566 | aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue()); |
3567 | aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue()); | |
71215351 | 3568 | } |
3569 | else if (aFlag == "-font") | |
3570 | { | |
3571 | if (anArgIter + 1 >= theArgNb) | |
3572 | { | |
3573 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3574 | return 1; | |
3575 | } | |
51740958 | 3576 | TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]); |
3577 | if (!aFontArg.IsIntegerValue()) | |
71215351 | 3578 | { |
3579 | std::cout << "Error: HeightFont value should be integer!\n"; | |
3580 | return 1; | |
3581 | } | |
3582 | ||
4b3d6eb1 | 3583 | aColorScale->SetTextHeight (aFontArg.IntegerValue()); |
71215351 | 3584 | anArgIter += 1; |
3585 | } | |
3586 | else if (aFlag == "-textpos") | |
3587 | { | |
3588 | if (anArgIter + 1 >= theArgNb) | |
3589 | { | |
3590 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3591 | return 1; | |
3592 | } | |
4b3d6eb1 | 3593 | |
51740958 | 3594 | TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]); |
3595 | aTextPosArg.LowerCase(); | |
4b3d6eb1 | 3596 | Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE; |
51740958 | 3597 | if (aTextPosArg == "none") |
71215351 | 3598 | { |
3599 | aLabPosition = Aspect_TOCSP_NONE; | |
3600 | } | |
51740958 | 3601 | else if (aTextPosArg == "left") |
71215351 | 3602 | { |
3603 | aLabPosition = Aspect_TOCSP_LEFT; | |
3604 | } | |
51740958 | 3605 | else if (aTextPosArg == "right") |
71215351 | 3606 | { |
3607 | aLabPosition = Aspect_TOCSP_RIGHT; | |
3608 | } | |
51740958 | 3609 | else if (aTextPosArg == "center") |
71215351 | 3610 | { |
3611 | aLabPosition = Aspect_TOCSP_CENTER; | |
3612 | } | |
3613 | else | |
3614 | { | |
51740958 | 3615 | std::cout << "Error: unknown position '" << aTextPosArg << "'!\n"; |
71215351 | 3616 | return 1; |
3617 | } | |
4b3d6eb1 | 3618 | aColorScale->SetLabelPosition (aLabPosition); |
71215351 | 3619 | } |
24a88697 | 3620 | else if (aFlag == "-logarithmic" |
3621 | || aFlag == "-log") | |
3622 | { | |
3623 | if (anArgIter + 1 >= theArgNb) | |
3624 | { | |
3625 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3626 | return 1; | |
3627 | } | |
4b3d6eb1 | 3628 | |
24a88697 | 3629 | Standard_Boolean IsLog; |
3630 | if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog)) | |
3631 | { | |
3632 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3633 | return 1; | |
3634 | } | |
4b3d6eb1 | 3635 | aColorScale->SetLogarithmic (IsLog); |
3636 | } | |
3637 | else if (aFlag == "-huerange" | |
3638 | || aFlag == "-hue") | |
3639 | { | |
3640 | if (anArgIter + 2 >= theArgNb) | |
3641 | { | |
3642 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3643 | return 1; | |
3644 | } | |
3645 | ||
3646 | const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]); | |
3647 | const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]); | |
3648 | aColorScale->SetHueRange (aHueMin, aHueMax); | |
3649 | } | |
3650 | else if (aFlag == "-colorrange") | |
3651 | { | |
3652 | Quantity_Color aColorMin, aColorMax; | |
3653 | Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1), | |
3654 | theArgVec + (anArgIter + 1), | |
3655 | aColorMin); | |
3656 | anArgIter += aNbParsed1; | |
3657 | Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1), | |
3658 | theArgVec + (anArgIter + 1), | |
3659 | aColorMax); | |
3660 | anArgIter += aNbParsed2; | |
3661 | if (aNbParsed1 == 0 | |
3662 | || aNbParsed2 == 0) | |
3663 | { | |
3664 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3665 | return 1; | |
3666 | } | |
3667 | ||
3668 | aColorScale->SetColorRange (aColorMin, aColorMax); | |
3669 | } | |
3670 | else if (aFlag == "-reversed" | |
3671 | || aFlag == "-inverted" | |
3672 | || aFlag == "-topdown" | |
3673 | || aFlag == "-bottomup") | |
3674 | { | |
3675 | Standard_Boolean toEnable = Standard_True; | |
3676 | if (anArgIter + 1 < theArgNb | |
3677 | && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable)) | |
3678 | { | |
3679 | ++anArgIter; | |
3680 | } | |
3681 | aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable); | |
3682 | } | |
3683 | else if (aFlag == "-smooth" | |
3684 | || aFlag == "-smoothtransition") | |
3685 | { | |
3686 | Standard_Boolean toEnable = Standard_True; | |
3687 | if (anArgIter + 1 < theArgNb | |
3688 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
3689 | { | |
3690 | ++anArgIter; | |
3691 | } | |
3692 | aColorScale->SetSmoothTransition (toEnable); | |
24a88697 | 3693 | } |
71215351 | 3694 | else if (aFlag == "-xy") |
3695 | { | |
3696 | if (anArgIter + 2 >= theArgNb) | |
3697 | { | |
3698 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3699 | return 1; | |
3700 | } | |
3701 | ||
4b3d6eb1 | 3702 | const TCollection_AsciiString anX (theArgVec[++anArgIter]); |
3703 | const TCollection_AsciiString anY (theArgVec[++anArgIter]); | |
3704 | if (!anX.IsIntegerValue() | |
3705 | || !anY.IsIntegerValue()) | |
71215351 | 3706 | { |
b4b2ecca | 3707 | std::cout << "Error: coordinates should be integer values!\n"; |
71215351 | 3708 | return 1; |
3709 | } | |
3710 | ||
4b3d6eb1 | 3711 | aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue()); |
b4b2ecca | 3712 | } |
3713 | else if (aFlag == "-width" | |
4b3d6eb1 | 3714 | || aFlag == "-w" |
3715 | || aFlag == "-breadth") | |
b4b2ecca | 3716 | { |
3717 | if (anArgIter + 1 >= theArgNb) | |
3718 | { | |
3719 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3720 | return 1; | |
3721 | } | |
3722 | ||
4b3d6eb1 | 3723 | const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]); |
3724 | if (!aBreadth.IsIntegerValue()) | |
b4b2ecca | 3725 | { |
3726 | std::cout << "Error: a width should be an integer value!\n"; | |
3727 | return 1; | |
3728 | } | |
4b3d6eb1 | 3729 | aColorScale->SetBreadth (aBreadth.IntegerValue()); |
b4b2ecca | 3730 | } |
3731 | else if (aFlag == "-height" | |
3732 | || aFlag == "-h") | |
3733 | { | |
3734 | if (anArgIter + 1 >= theArgNb) | |
3735 | { | |
3736 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3737 | return 1; | |
3738 | } | |
3739 | ||
4b3d6eb1 | 3740 | const TCollection_AsciiString aHeight (theArgVec[++anArgIter]); |
3741 | if (!aHeight.IsIntegerValue()) | |
b4b2ecca | 3742 | { |
3743 | std::cout << "Error: a width should be an integer value!\n"; | |
3744 | return 1; | |
3745 | } | |
4b3d6eb1 | 3746 | aColorScale->SetHeight (aHeight.IntegerValue()); |
71215351 | 3747 | } |
3748 | else if (aFlag == "-color") | |
3749 | { | |
4b3d6eb1 | 3750 | if (aColorScale->GetColorType() != Aspect_TOCSD_USER) |
71215351 | 3751 | { |
3752 | std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n"; | |
3753 | return 1; | |
3754 | } | |
4b3d6eb1 | 3755 | else if (anArgIter + 2 >= theArgNb) |
71215351 | 3756 | { |
4b3d6eb1 | 3757 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; |
3758 | return 1; | |
71215351 | 3759 | } |
3760 | ||
4b3d6eb1 | 3761 | const TCollection_AsciiString anInd (theArgVec[++anArgIter]); |
71215351 | 3762 | if (!anInd.IsIntegerValue()) |
3763 | { | |
3764 | std::cout << "Error: Index value should be integer!\n"; | |
3765 | return 1; | |
3766 | } | |
4b3d6eb1 | 3767 | const Standard_Integer anIndex = anInd.IntegerValue(); |
3768 | if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals()) | |
71215351 | 3769 | { |
4b3d6eb1 | 3770 | std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() <<"!\n"; |
71215351 | 3771 | return 1; |
3772 | } | |
3773 | ||
4b3d6eb1 | 3774 | Quantity_Color aColor; |
3775 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1), | |
3776 | theArgVec + (anArgIter + 1), | |
3777 | aColor); | |
3778 | if (aNbParsed == 0) | |
71215351 | 3779 | { |
4b3d6eb1 | 3780 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; |
71215351 | 3781 | return 1; |
3782 | } | |
4b3d6eb1 | 3783 | aColorScale->SetIntervalColor (aColor, anIndex); |
3784 | aColorScale->SetColorType (Aspect_TOCSD_USER); | |
3785 | anArgIter += aNbParsed; | |
71215351 | 3786 | } |
3787 | else if (aFlag == "-label") | |
3788 | { | |
4b3d6eb1 | 3789 | if (aColorScale->GetColorType() != Aspect_TOCSD_USER) |
71215351 | 3790 | { |
3791 | std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n"; | |
3792 | return 1; | |
3793 | } | |
3794 | else if (anArgIter + 2 >= theArgNb) | |
3795 | { | |
3796 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3797 | return 1; | |
3798 | } | |
3799 | ||
3800 | Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]); | |
4b3d6eb1 | 3801 | if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1) |
71215351 | 3802 | { |
4b3d6eb1 | 3803 | std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() + 1 <<"!\n"; |
71215351 | 3804 | return 1; |
3805 | } | |
3806 | ||
3807 | TCollection_ExtendedString aText (theArgVec[anArgIter + 2]); | |
4b3d6eb1 | 3808 | aColorScale->SetLabel (aText, anIndex); |
3809 | aColorScale->SetLabelType (Aspect_TOCSD_USER); | |
71215351 | 3810 | anArgIter += 2; |
3811 | } | |
4b3d6eb1 | 3812 | else if (aFlag == "-labelat" |
3813 | || aFlag == "-labat" | |
3814 | || aFlag == "-labelatborder" | |
3815 | || aFlag == "-labatborder" | |
3816 | || aFlag == "-labelatcenter" | |
3817 | || aFlag == "-labatcenter") | |
71215351 | 3818 | { |
4b3d6eb1 | 3819 | Standard_Boolean toEnable = Standard_True; |
3820 | if (aFlag == "-labelat" | |
3821 | || aFlag == "-labat") | |
71215351 | 3822 | { |
4b3d6eb1 | 3823 | Standard_Integer aLabAtBorder = -1; |
3824 | if (++anArgIter >= theArgNb) | |
71215351 | 3825 | { |
4b3d6eb1 | 3826 | TCollection_AsciiString anAtBorder (theArgVec[anArgIter]); |
3827 | anAtBorder.LowerCase(); | |
3828 | if (anAtBorder == "border") | |
71215351 | 3829 | { |
4b3d6eb1 | 3830 | aLabAtBorder = 1; |
71215351 | 3831 | } |
4b3d6eb1 | 3832 | else if (anAtBorder == "center") |
71215351 | 3833 | { |
4b3d6eb1 | 3834 | aLabAtBorder = 0; |
71215351 | 3835 | } |
71215351 | 3836 | } |
4b3d6eb1 | 3837 | if (aLabAtBorder == -1) |
3838 | { | |
3839 | std::cout << "Syntax error at argument '" << anArg << "'!\n"; | |
3840 | return 1; | |
3841 | } | |
3842 | toEnable = (aLabAtBorder == 1); | |
3843 | } | |
3844 | else if (anArgIter + 1 < theArgNb | |
3845 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
3846 | { | |
3847 | ++anArgIter; | |
71215351 | 3848 | } |
4b3d6eb1 | 3849 | aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter" |
3850 | || aFlag == "-labatcenter" | |
3851 | ? !toEnable | |
3852 | : toEnable); | |
3853 | } | |
3854 | else if (aFlag == "-colors") | |
3855 | { | |
3856 | Aspect_SequenceOfColor aSeq; | |
3857 | for (;;) | |
3858 | { | |
3859 | Quantity_Color aColor; | |
3860 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1), | |
3861 | theArgVec + (anArgIter + 1), | |
3862 | aColor); | |
3863 | if (aNbParsed == 0) | |
3864 | { | |
3865 | break; | |
3866 | } | |
3867 | anArgIter += aNbParsed; | |
3868 | aSeq.Append (aColor); | |
3869 | } | |
3870 | if (aSeq.Length() != aColorScale->GetNumberOfIntervals()) | |
71215351 | 3871 | { |
3872 | std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the " | |
4b3d6eb1 | 3873 | << aColorScale->GetNumberOfIntervals() << " intervals\n"; |
71215351 | 3874 | return 1; |
3875 | } | |
3876 | ||
4b3d6eb1 | 3877 | aColorScale->SetColors (aSeq); |
3878 | aColorScale->SetColorType (Aspect_TOCSD_USER); | |
71215351 | 3879 | } |
4b3d6eb1 | 3880 | else if (aFlag == "-labels" |
3881 | || aFlag == "-freelabels") | |
71215351 | 3882 | { |
4b3d6eb1 | 3883 | if (anArgIter + 1 >= theArgNb) |
3884 | { | |
3885 | std::cout << "Syntax error at argument '" << anArg << "'!\n"; | |
3886 | return 1; | |
3887 | } | |
3888 | ||
3889 | Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder() | |
3890 | ? aColorScale->GetNumberOfIntervals() + 1 | |
3891 | : aColorScale->GetNumberOfIntervals(); | |
3892 | if (aFlag == "-freelabels") | |
3893 | { | |
3894 | ++anArgIter; | |
3895 | aNbLabels = Draw::Atoi (theArgVec[anArgIter]); | |
3896 | } | |
3897 | if (anArgIter + aNbLabels >= theArgNb) | |
71215351 | 3898 | { |
4b3d6eb1 | 3899 | std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n"; |
71215351 | 3900 | return 1; |
3901 | } | |
3902 | ||
3903 | TColStd_SequenceOfExtendedString aSeq; | |
4b3d6eb1 | 3904 | for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter) |
71215351 | 3905 | { |
4b3d6eb1 | 3906 | aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter])); |
71215351 | 3907 | } |
4b3d6eb1 | 3908 | aColorScale->SetLabels (aSeq); |
3909 | aColorScale->SetLabelType (Aspect_TOCSD_USER); | |
71215351 | 3910 | } |
3911 | else if (aFlag == "-title") | |
3912 | { | |
3913 | if (anArgIter + 1 >= theArgNb) | |
3914 | { | |
3915 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3916 | return 1; | |
3917 | } | |
3918 | ||
3919 | Standard_Boolean isTwoArgs = Standard_False; | |
3920 | if (anArgIter + 2 < theArgNb) | |
3921 | { | |
3922 | TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]); | |
3923 | aSecondArg.LowerCase(); | |
4b3d6eb1 | 3924 | Standard_DISABLE_DEPRECATION_WARNINGS |
71215351 | 3925 | if (aSecondArg == "none") |
3926 | { | |
4b3d6eb1 | 3927 | aColorScale->SetTitlePosition (Aspect_TOCSP_NONE); |
71215351 | 3928 | isTwoArgs = Standard_True; |
3929 | } | |
3930 | else if (aSecondArg == "left") | |
3931 | { | |
4b3d6eb1 | 3932 | aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT); |
71215351 | 3933 | isTwoArgs = Standard_True; |
3934 | } | |
3935 | else if (aSecondArg == "right") | |
3936 | { | |
4b3d6eb1 | 3937 | aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT); |
71215351 | 3938 | isTwoArgs = Standard_True; |
3939 | } | |
3940 | else if (aSecondArg == "center") | |
3941 | { | |
4b3d6eb1 | 3942 | aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER); |
71215351 | 3943 | isTwoArgs = Standard_True; |
3944 | } | |
4b3d6eb1 | 3945 | Standard_ENABLE_DEPRECATION_WARNINGS |
71215351 | 3946 | } |
3947 | ||
4b3d6eb1 | 3948 | aColorScale->SetTitle (theArgVec[anArgIter + 1]); |
71215351 | 3949 | if (isTwoArgs) |
3950 | { | |
3951 | anArgIter += 1; | |
3952 | } | |
3953 | anArgIter += 1; | |
3954 | } | |
3955 | else if (aFlag == "-demoversion" | |
3956 | || aFlag == "-demo") | |
3957 | { | |
4b3d6eb1 | 3958 | aColorScale->SetPosition (0, 0); |
3959 | aColorScale->SetTextHeight (16); | |
3960 | aColorScale->SetRange (0.0, 100.0); | |
3961 | aColorScale->SetNumberOfIntervals (10); | |
3962 | aColorScale->SetBreadth (0); | |
3963 | aColorScale->SetHeight (0); | |
3964 | aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT); | |
3965 | aColorScale->SetColorType (Aspect_TOCSD_AUTO); | |
3966 | aColorScale->SetLabelType (Aspect_TOCSD_AUTO); | |
71215351 | 3967 | } |
d5514578 | 3968 | else if (aFlag == "-findcolor") |
3969 | { | |
3970 | if (anArgIter + 1 >= theArgNb) | |
3971 | { | |
3972 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3973 | return 1; | |
3974 | } | |
3975 | ||
3976 | TCollection_AsciiString anArg1 (theArgVec[++anArgIter]); | |
3977 | ||
3978 | if (!anArg1.IsRealValue()) | |
3979 | { | |
3980 | std::cout << "Error: the value should be real!\n"; | |
3981 | return 1; | |
3982 | } | |
3983 | ||
3984 | Quantity_Color aColor; | |
4b3d6eb1 | 3985 | aColorScale->FindColor (anArg1.RealValue(), aColor); |
d5514578 | 3986 | theDI << Quantity_Color::StringName (aColor.Name()); |
3987 | return 0; | |
3988 | } | |
71215351 | 3989 | else |
3990 | { | |
3991 | std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n"; | |
3992 | return 1; | |
3993 | } | |
3994 | } | |
4b3d6eb1 | 3995 | |
3996 | Standard_Integer aWinWidth = 0, aWinHeight = 0; | |
3997 | aView->Window()->Size (aWinWidth, aWinHeight); | |
3998 | if (aColorScale->GetBreadth() == 0) | |
b4b2ecca | 3999 | { |
4b3d6eb1 | 4000 | aColorScale->SetBreadth (aWinWidth); |
b4b2ecca | 4001 | } |
4b3d6eb1 | 4002 | if (aColorScale->GetHeight() == 0) |
4003 | { | |
4004 | aColorScale->SetHeight (aWinHeight); | |
4005 | } | |
4006 | aColorScale->SetToUpdate(); | |
4007 | ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True); | |
7fd59977 | 4008 | return 0; |
4009 | } | |
4010 | ||
4011 | //============================================================================== | |
4012 | //function : VGraduatedTrihedron | |
a79f67f8 | 4013 | //purpose : Displays or hides a graduated trihedron |
7fd59977 | 4014 | //============================================================================== |
a79f67f8 | 4015 | static Standard_Boolean GetColor (const TCollection_AsciiString& theValue, |
4016 | Quantity_Color& theColor) | |
13a22457 | 4017 | { |
a79f67f8 | 4018 | Quantity_NameOfColor aColorName; |
4019 | TCollection_AsciiString aVal = theValue; | |
4020 | aVal.UpperCase(); | |
4021 | if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName)) | |
13a22457 | 4022 | { |
a79f67f8 | 4023 | return Standard_False; |
13a22457 | 4024 | } |
a79f67f8 | 4025 | theColor = Quantity_Color (aColorName); |
4026 | return Standard_True; | |
13a22457 S |
4027 | } |
4028 | ||
a79f67f8 | 4029 | static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs) |
7fd59977 | 4030 | { |
a79f67f8 | 4031 | if (theArgNum < 2) |
13a22457 | 4032 | { |
a79f67f8 | 4033 | std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help" |
4034 | << theArgs[0] <<"' for more information.\n"; | |
4035 | return 1; //TCL_ERROR | |
13a22457 | 4036 | } |
7fd59977 | 4037 | |
a79f67f8 | 4038 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs; |
4039 | TCollection_AsciiString aParseKey; | |
4040 | for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt) | |
4041 | { | |
4042 | TCollection_AsciiString anArg (theArgs [anArgIt]); | |
4043 | ||
4044 | if (anArg.Value (1) == '-' && !anArg.IsRealValue()) | |
4045 | { | |
4046 | aParseKey = anArg; | |
4047 | aParseKey.Remove (1); | |
4048 | aParseKey.LowerCase(); | |
4049 | aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString); | |
4050 | continue; | |
4051 | } | |
13a22457 | 4052 | |
a79f67f8 | 4053 | if (aParseKey.IsEmpty()) |
4054 | { | |
4055 | continue; | |
4056 | } | |
4057 | ||
4058 | aMapOfArgs(aParseKey)->Append (anArg); | |
4059 | } | |
4060 | ||
4061 | // Check parameters | |
4062 | for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs); | |
4063 | aMapIt.More(); aMapIt.Next()) | |
7fd59977 | 4064 | { |
a79f67f8 | 4065 | const TCollection_AsciiString& aKey = aMapIt.Key(); |
4066 | const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value(); | |
4067 | ||
4068 | // Bool key, without arguments | |
4069 | if ((aKey.IsEqual ("on") || aKey.IsEqual ("off")) | |
4070 | && anArgs->IsEmpty()) | |
4071 | { | |
4072 | continue; | |
4073 | } | |
4074 | ||
4075 | // One argument | |
4076 | if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname")) | |
4077 | && anArgs->Length() == 1) | |
4078 | { | |
4079 | continue; | |
4080 | } | |
4081 | ||
4082 | // On/off arguments | |
4083 | if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname") | |
4084 | || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks") | |
536d98e2 | 4085 | || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues") |
4086 | || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes")) | |
a79f67f8 | 4087 | && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off"))) |
4088 | { | |
4089 | continue; | |
4090 | } | |
4091 | ||
4092 | // One string argument | |
4093 | if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor") | |
4094 | || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor")) | |
4095 | && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue()) | |
4096 | { | |
4097 | continue; | |
4098 | } | |
4099 | ||
4100 | // One integer argument | |
4101 | if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks") | |
4102 | || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength") | |
4103 | || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset") | |
4104 | || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset")) | |
4105 | && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue()) | |
4106 | { | |
4107 | continue; | |
4108 | } | |
4109 | ||
4110 | // One real argument | |
4111 | if ( aKey.IsEqual ("arrowlength") | |
4112 | && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue())) | |
4113 | { | |
4114 | continue; | |
4115 | } | |
4116 | ||
4117 | // Two string arguments | |
4118 | if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont")) | |
4119 | && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue()) | |
13a22457 | 4120 | { |
a79f67f8 | 4121 | continue; |
13a22457 | 4122 | } |
a79f67f8 | 4123 | |
4124 | TCollection_AsciiString aLowerKey; | |
4125 | aLowerKey = "-"; | |
4126 | aLowerKey += aKey; | |
4127 | aLowerKey.LowerCase(); | |
4128 | std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n"; | |
4129 | std::cout << "Type help for more information.\n"; | |
4130 | return 1; | |
7fd59977 | 4131 | } |
4132 | ||
a79f67f8 | 4133 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); |
4134 | if (anAISContext.IsNull()) | |
4135 | { | |
586db386 | 4136 | std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n"; |
a79f67f8 | 4137 | return 1; |
4138 | } | |
7fd59977 | 4139 | |
a79f67f8 | 4140 | Standard_Boolean toDisplay = Standard_True; |
4141 | Quantity_Color aColor; | |
4142 | Graphic3d_GraduatedTrihedron aTrihedronData; | |
4143 | // Process parameters | |
4144 | Handle(TColStd_HSequenceOfAsciiString) aValues; | |
4145 | if (aMapOfArgs.Find ("off", aValues)) | |
7fd59977 | 4146 | { |
a79f67f8 | 4147 | toDisplay = Standard_False; |
4148 | } | |
13a22457 | 4149 | |
a79f67f8 | 4150 | // AXES NAMES |
4151 | if (aMapOfArgs.Find ("xname", aValues)) | |
4152 | { | |
4153 | aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1)); | |
4154 | } | |
4155 | if (aMapOfArgs.Find ("yname", aValues)) | |
4156 | { | |
4157 | aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1)); | |
4158 | } | |
4159 | if (aMapOfArgs.Find ("zname", aValues)) | |
4160 | { | |
4161 | aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1)); | |
4162 | } | |
4163 | if (aMapOfArgs.Find ("xdrawname", aValues)) | |
4164 | { | |
536d98e2 | 4165 | aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4166 | } |
4167 | if (aMapOfArgs.Find ("ydrawname", aValues)) | |
4168 | { | |
536d98e2 | 4169 | aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4170 | } |
4171 | if (aMapOfArgs.Find ("zdrawname", aValues)) | |
4172 | { | |
536d98e2 | 4173 | aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4174 | } |
4175 | if (aMapOfArgs.Find ("xnameoffset", aValues)) | |
4176 | { | |
4177 | aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); | |
4178 | } | |
4179 | if (aMapOfArgs.Find ("ynameoffset", aValues)) | |
4180 | { | |
4181 | aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); | |
4182 | } | |
4183 | if (aMapOfArgs.Find ("znameoffset", aValues)) | |
4184 | { | |
4185 | aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); | |
4186 | } | |
13a22457 | 4187 | |
a79f67f8 | 4188 | // COLORS |
4189 | if (aMapOfArgs.Find ("xnamecolor", aValues)) | |
4190 | { | |
4191 | if (!GetColor (aValues->Value(1), aColor)) | |
13a22457 | 4192 | { |
a79f67f8 | 4193 | std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n"; |
4194 | return 1; | |
13a22457 | 4195 | } |
a79f67f8 | 4196 | aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor); |
4197 | } | |
4198 | if (aMapOfArgs.Find ("ynamecolor", aValues)) | |
4199 | { | |
4200 | if (!GetColor (aValues->Value(1), aColor)) | |
13a22457 | 4201 | { |
a79f67f8 | 4202 | std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n"; |
4203 | return 1; | |
4204 | } | |
4205 | aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor); | |
4206 | } | |
4207 | if (aMapOfArgs.Find ("znamecolor", aValues)) | |
4208 | { | |
4209 | if (!GetColor (aValues->Value(1), aColor)) | |
4210 | { | |
4211 | std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n"; | |
4212 | return 1; | |
4213 | } | |
4214 | aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor); | |
4215 | } | |
4216 | if (aMapOfArgs.Find ("xcolor", aValues)) | |
4217 | { | |
4218 | if (!GetColor (aValues->Value(1), aColor)) | |
4219 | { | |
4220 | std::cout << theArgs[0] << "error: -xcolor wrong color name.\n"; | |
4221 | return 1; | |
4222 | } | |
4223 | aTrihedronData.ChangeXAxisAspect().SetColor (aColor); | |
4224 | } | |
4225 | if (aMapOfArgs.Find ("ycolor", aValues)) | |
4226 | { | |
4227 | if (!GetColor (aValues->Value(1), aColor)) | |
4228 | { | |
4229 | std::cout << theArgs[0] << "error: -ycolor wrong color name.\n"; | |
4230 | return 1; | |
4231 | } | |
4232 | aTrihedronData.ChangeYAxisAspect().SetColor (aColor); | |
4233 | } | |
4234 | if (aMapOfArgs.Find ("zcolor", aValues)) | |
4235 | { | |
4236 | if (!GetColor (aValues->Value(1), aColor)) | |
4237 | { | |
4238 | std::cout << theArgs[0] << "error: -zcolor wrong color name.\n"; | |
4239 | return 1; | |
4240 | } | |
4241 | aTrihedronData.ChangeZAxisAspect().SetColor (aColor); | |
4242 | } | |
4243 | ||
4244 | // TICKMARKS | |
4245 | if (aMapOfArgs.Find ("xticks", aValues)) | |
4246 | { | |
536d98e2 | 4247 | aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4248 | } |
4249 | if (aMapOfArgs.Find ("yticks", aValues)) | |
4250 | { | |
536d98e2 | 4251 | aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4252 | } |
4253 | if (aMapOfArgs.Find ("zticks", aValues)) | |
4254 | { | |
536d98e2 | 4255 | aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4256 | } |
4257 | if (aMapOfArgs.Find ("xticklength", aValues)) | |
4258 | { | |
536d98e2 | 4259 | aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4260 | } |
4261 | if (aMapOfArgs.Find ("yticklength", aValues)) | |
4262 | { | |
536d98e2 | 4263 | aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4264 | } |
4265 | if (aMapOfArgs.Find ("zticklength", aValues)) | |
4266 | { | |
536d98e2 | 4267 | aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4268 | } |
4269 | if (aMapOfArgs.Find ("xdrawticks", aValues)) | |
4270 | { | |
536d98e2 | 4271 | aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4272 | } |
4273 | if (aMapOfArgs.Find ("ydrawticks", aValues)) | |
4274 | { | |
536d98e2 | 4275 | aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4276 | } |
4277 | if (aMapOfArgs.Find ("zdrawticks", aValues)) | |
4278 | { | |
536d98e2 | 4279 | aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4280 | } |
4281 | ||
4282 | // VALUES | |
4283 | if (aMapOfArgs.Find ("xdrawvalues", aValues)) | |
4284 | { | |
536d98e2 | 4285 | aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4286 | } |
4287 | if (aMapOfArgs.Find ("ydrawvalues", aValues)) | |
4288 | { | |
536d98e2 | 4289 | aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4290 | } |
4291 | if (aMapOfArgs.Find ("zdrawvalues", aValues)) | |
4292 | { | |
536d98e2 | 4293 | aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4294 | } |
4295 | if (aMapOfArgs.Find ("xvaluesoffset", aValues)) | |
4296 | { | |
4297 | aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); | |
4298 | } | |
4299 | if (aMapOfArgs.Find ("yvaluesoffset", aValues)) | |
4300 | { | |
4301 | aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); | |
4302 | } | |
4303 | if (aMapOfArgs.Find ("zvaluesoffset", aValues)) | |
4304 | { | |
4305 | aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); | |
4306 | } | |
4307 | ||
4308 | // ARROWS | |
4309 | if (aMapOfArgs.Find ("arrowlength", aValues)) | |
4310 | { | |
536d98e2 | 4311 | aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue()); |
a79f67f8 | 4312 | } |
4313 | ||
4314 | // FONTS | |
4315 | if (aMapOfArgs.Find ("namefont", aValues)) | |
4316 | { | |
4317 | aTrihedronData.SetNamesFont (aValues->Value(1)); | |
4318 | } | |
4319 | if (aMapOfArgs.Find ("valuesfont", aValues)) | |
4320 | { | |
4321 | aTrihedronData.SetValuesFont (aValues->Value(1)); | |
4322 | } | |
4323 | ||
536d98e2 | 4324 | if (aMapOfArgs.Find ("drawgrid", aValues)) |
4325 | { | |
4326 | aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on")); | |
4327 | } | |
4328 | if (aMapOfArgs.Find ("drawaxes", aValues)) | |
4329 | { | |
4330 | aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on")); | |
4331 | } | |
4332 | ||
a79f67f8 | 4333 | // The final step: display of erase trihedron |
4334 | if (toDisplay) | |
4335 | { | |
4336 | ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData); | |
13a22457 | 4337 | } |
7fd59977 | 4338 | else |
a79f67f8 | 4339 | { |
4340 | ViewerTest::CurrentView()->GraduatedTrihedronErase(); | |
4341 | } | |
7fd59977 | 4342 | |
4343 | ViewerTest::GetAISContext()->UpdateCurrentViewer(); | |
a79f67f8 | 4344 | ViewerTest::CurrentView()->Redraw(); |
13a22457 | 4345 | |
7fd59977 | 4346 | return 0; |
4347 | } | |
4348 | ||
3bffef55 | 4349 | //============================================================================== |
4350 | //function : VTile | |
4351 | //purpose : | |
4352 | //============================================================================== | |
4353 | static int VTile (Draw_Interpretor& theDI, | |
4354 | Standard_Integer theArgNb, | |
4355 | const char** theArgVec) | |
4356 | { | |
4357 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4358 | if (aView.IsNull()) | |
4359 | { | |
4360 | std::cerr << "Error: no active viewer.\n"; | |
4361 | return 1; | |
4362 | } | |
4363 | ||
4364 | Graphic3d_CameraTile aTile = aView->Camera()->Tile(); | |
4365 | if (theArgNb < 2) | |
4366 | { | |
4367 | theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n" | |
4368 | << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n" | |
4369 | << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n"; | |
4370 | return 0; | |
4371 | } | |
4372 | ||
4373 | aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y()); | |
4374 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
4375 | { | |
4376 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
4377 | anArg.LowerCase(); | |
4378 | if (anArg == "-lowerleft" | |
4379 | || anArg == "-upperleft") | |
4380 | { | |
4381 | if (anArgIter + 3 < theArgNb) | |
4382 | { | |
4383 | std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n"; | |
4384 | return 1; | |
4385 | } | |
4386 | aTile.IsTopDown = (anArg == "-upperleft") == Standard_True; | |
4387 | aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]); | |
4388 | aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]); | |
4389 | } | |
4390 | else if (anArg == "-total" | |
4391 | || anArg == "-totalsize" | |
4392 | || anArg == "-viewsize") | |
4393 | { | |
4394 | if (anArgIter + 3 < theArgNb) | |
4395 | { | |
4396 | std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n"; | |
4397 | return 1; | |
4398 | } | |
4399 | aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]); | |
4400 | aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]); | |
4401 | if (aTile.TotalSize.x() < 1 | |
4402 | || aTile.TotalSize.y() < 1) | |
4403 | { | |
4404 | std::cerr << "Error: total size is incorrect.\n"; | |
4405 | return 1; | |
4406 | } | |
4407 | } | |
4408 | else if (anArg == "-tilesize") | |
4409 | { | |
4410 | if (anArgIter + 3 < theArgNb) | |
4411 | { | |
4412 | std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n"; | |
4413 | return 1; | |
4414 | } | |
4415 | ||
4416 | aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]); | |
4417 | aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]); | |
4418 | if (aTile.TileSize.x() < 1 | |
4419 | || aTile.TileSize.y() < 1) | |
4420 | { | |
4421 | std::cerr << "Error: tile size is incorrect.\n"; | |
4422 | return 1; | |
4423 | } | |
4424 | } | |
4425 | else if (anArg == "-unset") | |
4426 | { | |
4427 | aView->Camera()->SetTile (Graphic3d_CameraTile()); | |
4428 | aView->Redraw(); | |
4429 | return 0; | |
4430 | } | |
4431 | } | |
4432 | ||
4433 | if (aTile.TileSize.x() < 1 | |
4434 | || aTile.TileSize.y() < 1) | |
4435 | { | |
4436 | std::cerr << "Error: tile size is undefined.\n"; | |
4437 | return 1; | |
4438 | } | |
4439 | else if (aTile.TotalSize.x() < 1 | |
4440 | || aTile.TotalSize.y() < 1) | |
4441 | { | |
4442 | std::cerr << "Error: total size is undefined.\n"; | |
4443 | return 1; | |
4444 | } | |
4445 | ||
4446 | aView->Camera()->SetTile (aTile); | |
4447 | aView->Redraw(); | |
4448 | return 0; | |
4449 | } | |
4450 | ||
7c3ef2f7 | 4451 | //! Format ZLayer ID. |
4452 | inline const char* formZLayerId (const Standard_Integer theLayerId) | |
4453 | { | |
4454 | switch (theLayerId) | |
4455 | { | |
4456 | case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]"; | |
4457 | case Graphic3d_ZLayerId_Default: return "[DEFAULT]"; | |
4458 | case Graphic3d_ZLayerId_Top: return "[TOP]"; | |
4459 | case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]"; | |
4460 | case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]"; | |
4461 | case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]"; | |
4462 | } | |
4463 | return ""; | |
4464 | } | |
4465 | ||
4466 | //! Print the ZLayer information. | |
4467 | inline void printZLayerInfo (Draw_Interpretor& theDI, | |
4468 | const Graphic3d_ZLayerSettings& theLayer) | |
4469 | { | |
4470 | if (!theLayer.Name().IsEmpty()) | |
4471 | { | |
4472 | theDI << " Name: " << theLayer.Name() << "\n"; | |
4473 | } | |
4474 | if (theLayer.IsImmediate()) | |
4475 | { | |
4476 | theDI << " Immediate: TRUE\n"; | |
4477 | } | |
4478 | theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n"; | |
4479 | theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n"; | |
4480 | theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n"; | |
4481 | theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n"; | |
4482 | if (theLayer.PolygonOffset().Mode != Aspect_POM_None) | |
4483 | { | |
4484 | theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n"; | |
4485 | } | |
4486 | } | |
4487 | ||
59f45b7c | 4488 | //============================================================================== |
4489 | //function : VZLayer | |
4490 | //purpose : Test z layer operations for v3d viewer | |
4491 | //============================================================================== | |
7c3ef2f7 | 4492 | static int VZLayer (Draw_Interpretor& theDI, |
4493 | Standard_Integer theArgNb, | |
4494 | const char** theArgVec) | |
59f45b7c | 4495 | { |
7c3ef2f7 | 4496 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); |
59f45b7c | 4497 | if (aContextAIS.IsNull()) |
4498 | { | |
7c3ef2f7 | 4499 | std::cout << "No active viewer!\n"; |
59f45b7c | 4500 | return 1; |
4501 | } | |
4502 | ||
4503 | const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer(); | |
7c3ef2f7 | 4504 | if (theArgNb < 2) |
59f45b7c | 4505 | { |
7c3ef2f7 | 4506 | TColStd_SequenceOfInteger aLayers; |
4507 | aViewer->GetAllZLayers (aLayers); | |
4508 | for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next()) | |
4509 | { | |
4510 | theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n"; | |
4511 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value()); | |
4512 | printZLayerInfo (theDI, aSettings); | |
4513 | } | |
59f45b7c | 4514 | return 1; |
4515 | } | |
4516 | ||
7c3ef2f7 | 4517 | Standard_Integer anArgIter = 1; |
4518 | Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN; | |
4519 | ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView()); | |
4520 | if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter])) | |
59f45b7c | 4521 | { |
7c3ef2f7 | 4522 | ++anArgIter; |
4523 | } | |
59f45b7c | 4524 | |
7c3ef2f7 | 4525 | TCollection_AsciiString aFirstArg (theArgVec[anArgIter]); |
4526 | if (aFirstArg.IsIntegerValue()) | |
4527 | { | |
4528 | ++anArgIter; | |
4529 | aLayerId = aFirstArg.IntegerValue(); | |
59f45b7c | 4530 | } |
7c3ef2f7 | 4531 | else |
59f45b7c | 4532 | { |
7c3ef2f7 | 4533 | aFirstArg.LowerCase(); |
4534 | if (aFirstArg == "default" | |
4535 | || aFirstArg == "def") | |
59f45b7c | 4536 | { |
7c3ef2f7 | 4537 | aLayerId = Graphic3d_ZLayerId_Default; |
4538 | ++anArgIter; | |
59f45b7c | 4539 | } |
7c3ef2f7 | 4540 | else if (aFirstArg == "top") |
59f45b7c | 4541 | { |
7c3ef2f7 | 4542 | aLayerId = Graphic3d_ZLayerId_Top; |
4543 | ++anArgIter; | |
59f45b7c | 4544 | } |
7c3ef2f7 | 4545 | else if (aFirstArg == "topmost") |
a1954302 | 4546 | { |
7c3ef2f7 | 4547 | aLayerId = Graphic3d_ZLayerId_Topmost; |
4548 | ++anArgIter; | |
a1954302 | 4549 | } |
7c3ef2f7 | 4550 | else if (aFirstArg == "overlay" |
4551 | || aFirstArg == "toposd") | |
59f45b7c | 4552 | { |
7c3ef2f7 | 4553 | aLayerId = Graphic3d_ZLayerId_TopOSD; |
4554 | ++anArgIter; | |
59f45b7c | 4555 | } |
7c3ef2f7 | 4556 | else if (aFirstArg == "underlay" |
4557 | || aFirstArg == "botosd") | |
c5751993 | 4558 | { |
7c3ef2f7 | 4559 | aLayerId = Graphic3d_ZLayerId_BotOSD; |
4560 | ++anArgIter; | |
c5751993 | 4561 | } |
7c3ef2f7 | 4562 | else |
c5751993 | 4563 | { |
7c3ef2f7 | 4564 | TColStd_SequenceOfInteger aLayers; |
4565 | aViewer->GetAllZLayers (aLayers); | |
4566 | for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next()) | |
4567 | { | |
4568 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value()); | |
4569 | if (TCollection_AsciiString::IsSameString (aSettings.Name(), aFirstArg, Standard_False)) | |
4570 | { | |
4571 | aLayerId = aLayeriter.Value(); | |
4572 | ++anArgIter; | |
4573 | break; | |
4574 | } | |
4575 | } | |
c5751993 | 4576 | } |
7c3ef2f7 | 4577 | } |
c5751993 | 4578 | |
7c3ef2f7 | 4579 | for (; anArgIter < theArgNb; ++anArgIter) |
4580 | { | |
4581 | // perform operation | |
4582 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
4583 | anArg.LowerCase(); | |
4584 | if (anUpdateTool.parseRedrawMode (anArg)) | |
c5751993 | 4585 | { |
7c3ef2f7 | 4586 | // |
c5751993 | 4587 | } |
7c3ef2f7 | 4588 | else if (anArg == "-add" |
4589 | || anArg == "add") | |
c5751993 | 4590 | { |
7c3ef2f7 | 4591 | aLayerId = Graphic3d_ZLayerId_UNKNOWN; |
4592 | if (!aViewer->AddZLayer (aLayerId)) | |
4593 | { | |
4594 | std::cout << "Error: can not add a new z layer!\n"; | |
4595 | return 0; | |
4596 | } | |
4597 | ||
4598 | theDI << aLayerId; | |
c5751993 | 4599 | } |
7c3ef2f7 | 4600 | else if (anArg == "-del" |
4601 | || anArg == "-delete" | |
4602 | || anArg == "del") | |
c5751993 | 4603 | { |
7c3ef2f7 | 4604 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) |
4605 | { | |
4606 | if (++anArgIter >= theArgNb) | |
4607 | { | |
4608 | std::cout << "Syntax error: id of z layer to remove is missing\n"; | |
4609 | return 1; | |
4610 | } | |
4611 | ||
4612 | aLayerId = Draw::Atoi (theArgVec[anArgIter]); | |
4613 | } | |
4614 | ||
4615 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN | |
4616 | || aLayerId == Graphic3d_ZLayerId_Default | |
4617 | || aLayerId == Graphic3d_ZLayerId_Top | |
4618 | || aLayerId == Graphic3d_ZLayerId_Topmost | |
4619 | || aLayerId == Graphic3d_ZLayerId_TopOSD | |
4620 | || aLayerId == Graphic3d_ZLayerId_BotOSD) | |
4621 | { | |
4622 | std::cout << "Syntax error: standard Z layer can not be removed\n"; | |
4623 | return 1; | |
4624 | } | |
4625 | ||
4626 | // move all object displayed in removing layer to default layer | |
4627 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); | |
4628 | anObjIter.More(); anObjIter.Next()) | |
4629 | { | |
4630 | Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1()); | |
4631 | if (aPrs.IsNull() | |
4632 | || aPrs->ZLayer() != aLayerId) | |
4633 | { | |
4634 | continue; | |
4635 | } | |
4636 | aPrs->SetZLayer (Graphic3d_ZLayerId_Default); | |
4637 | } | |
4638 | ||
4639 | if (!aViewer->RemoveZLayer (aLayerId)) | |
4640 | { | |
4641 | std::cout << "Z layer can not be removed!\n"; | |
4642 | } | |
4643 | else | |
4644 | { | |
4645 | theDI << aLayerId << " "; | |
4646 | } | |
c5751993 | 4647 | } |
7c3ef2f7 | 4648 | else if (anArg == "-get" |
4649 | || anArg == "get") | |
c5751993 | 4650 | { |
7c3ef2f7 | 4651 | TColStd_SequenceOfInteger aLayers; |
4652 | aViewer->GetAllZLayers (aLayers); | |
4653 | for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next()) | |
4654 | { | |
4655 | theDI << aLayeriter.Value() << " "; | |
4656 | } | |
4657 | ||
4658 | theDI << "\n"; | |
c5751993 | 4659 | } |
7c3ef2f7 | 4660 | else if (anArg == "-name") |
c5751993 | 4661 | { |
7c3ef2f7 | 4662 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) |
c5751993 | 4663 | { |
7c3ef2f7 | 4664 | std::cout << "Syntax error: id of Z layer is missing\n"; |
c5751993 | 4665 | return 1; |
4666 | } | |
4667 | ||
7c3ef2f7 | 4668 | if (++anArgIter >= theArgNb) |
4669 | { | |
4670 | std::cout << "Syntax error: name is missing\n"; | |
4671 | return 1; | |
4672 | } | |
c5751993 | 4673 | |
7c3ef2f7 | 4674 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); |
4675 | aSettings.SetName (theArgVec[anArgIter]); | |
4676 | aViewer->SetZLayerSettings (aLayerId, aSettings); | |
c5751993 | 4677 | } |
7c3ef2f7 | 4678 | else if (anArg == "-origin") |
c5751993 | 4679 | { |
7c3ef2f7 | 4680 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) |
4681 | { | |
4682 | std::cout << "Syntax error: id of Z layer is missing\n"; | |
4683 | return 1; | |
4684 | } | |
4685 | ||
4686 | if (anArgIter + 2 >= theArgNb) | |
4687 | { | |
4688 | std::cout << "Syntax error: origin coordinates are missing\n"; | |
4689 | return 1; | |
4690 | } | |
4691 | ||
4692 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); | |
4693 | gp_XYZ anOrigin; | |
4694 | anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1])); | |
4695 | anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2])); | |
4696 | anOrigin.SetZ (0.0); | |
4697 | if (anArgIter + 3 < theArgNb) | |
4698 | { | |
4699 | anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3])); | |
4700 | anArgIter += 3; | |
4701 | } | |
4702 | else | |
4703 | { | |
4704 | anArgIter += 2; | |
4705 | } | |
4706 | aSettings.SetOrigin (anOrigin); | |
4707 | aViewer->SetZLayerSettings (aLayerId, aSettings); | |
c5751993 | 4708 | } |
7c3ef2f7 | 4709 | else if (anArg == "-settings" |
4710 | || anArg == "settings") | |
c5751993 | 4711 | { |
7c3ef2f7 | 4712 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) |
4713 | { | |
4714 | if (++anArgIter >= theArgNb) | |
4715 | { | |
4716 | std::cout << "Syntax error: id of Z layer is missing\n"; | |
4717 | return 1; | |
4718 | } | |
4719 | ||
4720 | aLayerId = Draw::Atoi (theArgVec[anArgIter]); | |
4721 | } | |
4722 | ||
4723 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); | |
4724 | printZLayerInfo (theDI, aSettings); | |
c5751993 | 4725 | } |
7c3ef2f7 | 4726 | else if (anArg == "-enable" |
4727 | || anArg == "enable" | |
4728 | || anArg == "-disable" | |
4729 | || anArg == "disable") | |
83da37b1 | 4730 | { |
7c3ef2f7 | 4731 | const Standard_Boolean toEnable = anArg == "-enable" |
4732 | || anArg == "enable"; | |
4733 | if (++anArgIter >= theArgNb) | |
4734 | { | |
4735 | std::cout << "Syntax error: option name is missing\n"; | |
4736 | return 1; | |
4737 | } | |
c5751993 | 4738 | |
7c3ef2f7 | 4739 | TCollection_AsciiString aSubOp (theArgVec[anArgIter]); |
4740 | aSubOp.LowerCase(); | |
4741 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) | |
4742 | { | |
4743 | if (++anArgIter >= theArgNb) | |
4744 | { | |
4745 | std::cout << "Syntax error: id of Z layer is missing\n"; | |
4746 | return 1; | |
4747 | } | |
c5751993 | 4748 | |
7c3ef2f7 | 4749 | aLayerId = Draw::Atoi (theArgVec[anArgIter]); |
4750 | } | |
c5751993 | 4751 | |
7c3ef2f7 | 4752 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); |
4753 | if (aSubOp == "depthtest" | |
4754 | || aSubOp == "test") | |
4755 | { | |
4756 | aSettings.SetEnableDepthTest (toEnable); | |
4757 | } | |
4758 | else if (aSubOp == "depthwrite" | |
4759 | || aSubOp == "write") | |
4760 | { | |
4761 | aSettings.SetEnableDepthWrite (toEnable); | |
4762 | } | |
4763 | else if (aSubOp == "depthclear" | |
4764 | || aSubOp == "clear") | |
4765 | { | |
4766 | aSettings.SetClearDepth (toEnable); | |
4767 | } | |
4768 | else if (aSubOp == "depthoffset" | |
4769 | || aSubOp == "offset") | |
4770 | { | |
4771 | Graphic3d_PolygonOffset aParams; | |
4772 | aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None; | |
4773 | if (toEnable) | |
4774 | { | |
4775 | if (anArgIter + 2 >= theArgNb) | |
4776 | { | |
4777 | std::cout << "Syntax error: factor and units values for depth offset are missing\n"; | |
4778 | return 1; | |
4779 | } | |
c5751993 | 4780 | |
7c3ef2f7 | 4781 | aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter])); |
4782 | aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter])); | |
4783 | } | |
4784 | aSettings.SetPolygonOffset (aParams); | |
4785 | } | |
4786 | else if (aSubOp == "positiveoffset" | |
4787 | || aSubOp == "poffset") | |
4788 | { | |
4789 | if (toEnable) | |
4790 | { | |
4791 | aSettings.SetDepthOffsetPositive(); | |
4792 | } | |
4793 | else | |
4794 | { | |
4795 | aSettings.SetPolygonOffset (Graphic3d_PolygonOffset()); | |
4796 | } | |
4797 | } | |
4798 | else if (aSubOp == "negativeoffset" | |
4799 | || aSubOp == "noffset") | |
4800 | { | |
4801 | if (toEnable) | |
4802 | { | |
4803 | aSettings.SetDepthOffsetNegative(); | |
4804 | } | |
4805 | else | |
4806 | { | |
4807 | aSettings.SetPolygonOffset(Graphic3d_PolygonOffset()); | |
4808 | } | |
4809 | } | |
4810 | else if (aSubOp == "textureenv") | |
4811 | { | |
4812 | aSettings.SetEnvironmentTexture (toEnable); | |
4813 | } | |
4814 | ||
4815 | aViewer->SetZLayerSettings (aLayerId, aSettings); | |
c5751993 | 4816 | } |
7c3ef2f7 | 4817 | else |
83da37b1 | 4818 | { |
7c3ef2f7 | 4819 | std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n"; |
4820 | return 1; | |
83da37b1 | 4821 | } |
59f45b7c | 4822 | } |
4823 | ||
4824 | return 0; | |
4825 | } | |
4826 | ||
c357e426 | 4827 | // The interactive presentation of 2d layer item |
4828 | // for "vlayerline" command it provides a presentation of | |
4829 | // line with user-defined linewidth, linetype and transparency. | |
61b0191c | 4830 | class V3d_LineItem : public AIS_InteractiveObject |
20637bd2 | 4831 | { |
4832 | public: | |
4833 | // CASCADE RTTI | |
92efcf78 | 4834 | DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject) |
4fe56619 | 4835 | |
20637bd2 | 4836 | // constructor |
4837 | Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1, | |
4838 | Standard_Real X2, Standard_Real Y2, | |
20637bd2 | 4839 | Aspect_TypeOfLine theType = Aspect_TOL_SOLID, |
4840 | Standard_Real theWidth = 0.5, | |
4841 | Standard_Real theTransp = 1.0); | |
4842 | ||
61b0191c | 4843 | private: |
4844 | ||
4845 | void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, | |
4846 | const Handle(Prs3d_Presentation)& thePresentation, | |
79104795 | 4847 | const Standard_Integer theMode) Standard_OVERRIDE; |
61b0191c | 4848 | |
4849 | void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/, | |
79104795 | 4850 | const Standard_Integer /*aMode*/) Standard_OVERRIDE |
4851 | {} | |
20637bd2 | 4852 | |
4853 | private: | |
4854 | ||
4855 | Standard_Real myX1, myY1, myX2, myY2; | |
eafb234b | 4856 | Aspect_TypeOfLine myType; |
20637bd2 | 4857 | Standard_Real myWidth; |
20637bd2 | 4858 | }; |
4859 | ||
20637bd2 | 4860 | // default constructor for line item |
4fe56619 | 4861 | V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1, |
20637bd2 | 4862 | Standard_Real X2, Standard_Real Y2, |
20637bd2 | 4863 | Aspect_TypeOfLine theType, |
4864 | Standard_Real theWidth, | |
4865 | Standard_Real theTransp) : | |
61b0191c | 4866 | myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), |
4867 | myType(theType), myWidth(theWidth) | |
20637bd2 | 4868 | { |
61b0191c | 4869 | SetTransparency (1-theTransp); |
20637bd2 | 4870 | } |
4871 | ||
4872 | // render line | |
61b0191c | 4873 | void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/, |
4874 | const Handle(Prs3d_Presentation)& thePresentation, | |
4875 | const Standard_Integer /*theMode*/) | |
20637bd2 | 4876 | { |
61b0191c | 4877 | thePresentation->Clear(); |
4878 | Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB); | |
4879 | Standard_Integer aWidth, aHeight; | |
4880 | ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight); | |
4881 | Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation); | |
4882 | Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5); | |
4883 | aPrim->AddVertex(myX1, aHeight-myY1, 0.); | |
4884 | aPrim->AddVertex(myX2, aHeight-myY2, 0.); | |
4885 | Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth); | |
4886 | aGroup->SetPrimitivesAspect (anAspect->Aspect()); | |
4887 | aGroup->AddPrimitiveArray (aPrim); | |
20637bd2 | 4888 | } |
4889 | ||
4890 | //============================================================================= | |
4891 | //function : VLayerLine | |
4892 | //purpose : Draws line in the v3d view layer with given attributes: linetype, | |
4893 | // : linewidth, transparency coefficient | |
4894 | //============================================================================ | |
4895 | static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
4896 | { | |
4897 | // get the active view | |
4898 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4899 | if (aView.IsNull()) | |
4900 | { | |
4901 | di << "Call vinit before!\n"; | |
4902 | return 1; | |
4903 | } | |
4904 | else if (argc < 5) | |
4905 | { | |
4906 | di << "Use: " << argv[0]; | |
4907 | di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n"; | |
4908 | di << " linetype : { 0 | 1 | 2 | 3 } \n"; | |
4909 | di << " 0 - solid \n"; | |
4910 | di << " 1 - dashed \n"; | |
4911 | di << " 2 - dot \n"; | |
4912 | di << " 3 - dashdot\n"; | |
4913 | di << " transparency : { 0.0 - 1.0 } \n"; | |
4914 | di << " 0.0 - transparent\n"; | |
4915 | di << " 1.0 - visible \n"; | |
4916 | return 1; | |
4917 | } | |
4918 | ||
61b0191c | 4919 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
20637bd2 | 4920 | // get the input params |
91322f44 | 4921 | Standard_Real X1 = Draw::Atof(argv[1]); |
4922 | Standard_Real Y1 = Draw::Atof(argv[2]); | |
4923 | Standard_Real X2 = Draw::Atof(argv[3]); | |
4924 | Standard_Real Y2 = Draw::Atof(argv[4]); | |
20637bd2 | 4925 | |
3a4a3962 | 4926 | Standard_Real aWidth = 0.5; |
4927 | Standard_Real aTransparency = 1.0; | |
20637bd2 | 4928 | |
4929 | // has width | |
4930 | if (argc > 5) | |
91322f44 | 4931 | aWidth = Draw::Atof(argv[5]); |
20637bd2 | 4932 | |
3a4a3962 | 4933 | // select appropriate line type |
4934 | Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID; | |
4935 | if (argc > 6 | |
4936 | && !ViewerTest::ParseLineType (argv[6], aLineType)) | |
4937 | { | |
4938 | std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n"; | |
4939 | return 1; | |
4940 | } | |
20637bd2 | 4941 | |
4942 | // has transparency | |
4943 | if (argc > 7) | |
4944 | { | |
91322f44 | 4945 | aTransparency = Draw::Atof(argv[7]); |
4fe56619 | 4946 | if (aTransparency < 0 || aTransparency > 1.0) |
20637bd2 | 4947 | aTransparency = 1.0; |
4948 | } | |
4949 | ||
61b0191c | 4950 | static Handle (V3d_LineItem) aLine; |
4951 | if (!aLine.IsNull()) | |
25289ec1 | 4952 | { |
0577ae8c | 4953 | aContext->Erase (aLine, Standard_False); |
25289ec1 | 4954 | } |
61b0191c | 4955 | aLine = new V3d_LineItem (X1, Y1, X2, Y2, |
4956 | aLineType, aWidth, | |
4957 | aTransparency); | |
25289ec1 | 4958 | |
778cd667 | 4959 | aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER)); |
61b0191c | 4960 | aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD); |
4961 | aLine->SetToUpdate(); | |
4962 | aContext->Display (aLine, Standard_True); | |
25289ec1 | 4963 | |
4964 | return 0; | |
4965 | } | |
4966 | ||
61b0191c | 4967 | |
2bd4c032 | 4968 | //============================================================================== |
4969 | //function : VGrid | |
4970 | //purpose : | |
4971 | //============================================================================== | |
4972 | ||
35e08fe8 | 4973 | static int VGrid (Draw_Interpretor& /*theDI*/, |
2bd4c032 | 4974 | Standard_Integer theArgNb, |
4975 | const char** theArgVec) | |
4976 | { | |
4977 | // get the active view | |
4978 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4979 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
4980 | if (aView.IsNull() || aViewer.IsNull()) | |
4981 | { | |
4982 | std::cerr << "No active view. Please call vinit.\n"; | |
4983 | return 1; | |
4984 | } | |
4985 | ||
4986 | Aspect_GridType aType = aViewer->GridType(); | |
4987 | Aspect_GridDrawMode aMode = aViewer->GridDrawMode(); | |
224f48fa | 4988 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
2bd4c032 | 4989 | Standard_Integer anIter = 1; |
4990 | for (; anIter < theArgNb; ++anIter) | |
4991 | { | |
4992 | const char* aValue = theArgVec[anIter]; | |
224f48fa | 4993 | if (anUpdateTool.parseRedrawMode (aValue)) |
4994 | { | |
4995 | continue; | |
4996 | } | |
4997 | else if (*aValue == 'r') | |
2bd4c032 | 4998 | { |
4999 | aType = Aspect_GT_Rectangular; | |
5000 | } | |
5001 | else if (*aValue == 'c') | |
5002 | { | |
5003 | aType = Aspect_GT_Circular; | |
5004 | } | |
5005 | else if (*aValue == 'l') | |
5006 | { | |
5007 | aMode = Aspect_GDM_Lines; | |
5008 | } | |
5009 | else if (*aValue == 'p') | |
5010 | { | |
5011 | aMode = Aspect_GDM_Points; | |
5012 | } | |
5013 | else if (strcmp (aValue, "off" ) == 0) | |
5014 | { | |
5015 | aViewer->DeactivateGrid(); | |
5016 | return 0; | |
5017 | } | |
5018 | else | |
5019 | { | |
5020 | break; | |
5021 | } | |
5022 | } | |
5023 | ||
5024 | Standard_Integer aTail = (theArgNb - anIter); | |
5025 | if (aTail == 0) | |
5026 | { | |
5027 | aViewer->ActivateGrid (aType, aMode); | |
5028 | return 0; | |
5029 | } | |
5030 | else if (aTail != 2 && aTail != 5) | |
5031 | { | |
5032 | std::cerr << "Incorrect arguments number! Usage:\n" | |
5033 | << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n"; | |
5034 | return 1; | |
5035 | } | |
5036 | ||
5037 | Quantity_Length anOriginX, anOriginY; | |
5038 | Quantity_PlaneAngle aRotAngle; | |
5039 | if (aType == Aspect_GT_Rectangular) | |
5040 | { | |
5041 | Quantity_Length aRStepX, aRStepY; | |
5042 | aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle); | |
5043 | ||
91322f44 | 5044 | anOriginX = Draw::Atof (theArgVec[anIter++]); |
5045 | anOriginY = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 5046 | if (aTail == 5) |
5047 | { | |
91322f44 | 5048 | aRStepX = Draw::Atof (theArgVec[anIter++]); |
5049 | aRStepY = Draw::Atof (theArgVec[anIter++]); | |
5050 | aRotAngle = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 5051 | } |
5052 | aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle); | |
5053 | aViewer->ActivateGrid (aType, aMode); | |
5054 | } | |
5055 | else if (aType == Aspect_GT_Circular) | |
5056 | { | |
5057 | Quantity_Length aRadiusStep; | |
5058 | Standard_Integer aDivisionNumber; | |
5059 | aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle); | |
5060 | ||
91322f44 | 5061 | anOriginX = Draw::Atof (theArgVec[anIter++]); |
5062 | anOriginY = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 5063 | if (aTail == 5) |
5064 | { | |
91322f44 | 5065 | aRadiusStep = Draw::Atof (theArgVec[anIter++]); |
5066 | aDivisionNumber = Draw::Atoi (theArgVec[anIter++]); | |
5067 | aRotAngle = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 5068 | } |
5069 | ||
5070 | aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle); | |
5071 | aViewer->ActivateGrid (aType, aMode); | |
5072 | } | |
5073 | ||
5074 | return 0; | |
5075 | } | |
5076 | ||
c40b7d58 | 5077 | //============================================================================== |
5078 | //function : VPriviledgedPlane | |
5079 | //purpose : | |
5080 | //============================================================================== | |
5081 | ||
5082 | static int VPriviledgedPlane (Draw_Interpretor& theDI, | |
5083 | Standard_Integer theArgNb, | |
5084 | const char** theArgVec) | |
5085 | { | |
5086 | if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10) | |
5087 | { | |
5088 | std::cerr << "Error: wrong number of arguments! See usage:\n"; | |
5089 | theDI.PrintHelp (theArgVec[0]); | |
5090 | return 1; | |
5091 | } | |
5092 | ||
5093 | // get the active viewer | |
5094 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
5095 | if (aViewer.IsNull()) | |
5096 | { | |
5097 | std::cerr << "Error: no active viewer. Please call vinit.\n"; | |
5098 | return 1; | |
5099 | } | |
5100 | ||
5101 | if (theArgNb == 1) | |
5102 | { | |
5103 | gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane(); | |
5104 | const gp_Pnt& anOrig = aPriviledgedPlane.Location(); | |
5105 | const gp_Dir& aNorm = aPriviledgedPlane.Direction(); | |
5106 | const gp_Dir& aXDir = aPriviledgedPlane.XDirection(); | |
5107 | theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " " | |
5108 | << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " " | |
5109 | << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n"; | |
5110 | return 0; | |
5111 | } | |
5112 | ||
5113 | Standard_Integer anArgIdx = 1; | |
5114 | Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]); | |
5115 | Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]); | |
5116 | Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]); | |
5117 | Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]); | |
5118 | Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]); | |
5119 | Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]); | |
5120 | ||
5121 | gp_Ax3 aPriviledgedPlane; | |
5122 | gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ); | |
5123 | gp_Dir aNorm (aNormX, aNormY, aNormZ); | |
5124 | if (theArgNb > 7) | |
5125 | { | |
5126 | Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]); | |
5127 | Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]); | |
5128 | Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]); | |
5129 | gp_Dir aXDir (aXDirX, aXDirY, aXDirZ); | |
5130 | aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir); | |
5131 | } | |
5132 | else | |
5133 | { | |
5134 | aPriviledgedPlane = gp_Ax3 (anOrig, aNorm); | |
5135 | } | |
5136 | ||
5137 | aViewer->SetPrivilegedPlane (aPriviledgedPlane); | |
5138 | ||
5139 | return 0; | |
5140 | } | |
5141 | ||
f25b82d6 | 5142 | //============================================================================== |
5143 | //function : VConvert | |
5144 | //purpose : | |
5145 | //============================================================================== | |
5146 | ||
5147 | static int VConvert (Draw_Interpretor& theDI, | |
5148 | Standard_Integer theArgNb, | |
5149 | const char** theArgVec) | |
5150 | { | |
5151 | // get the active view | |
5152 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5153 | if (aView.IsNull()) | |
5154 | { | |
c40b7d58 | 5155 | std::cerr << "Error: no active view. Please call vinit.\n"; |
f25b82d6 | 5156 | return 1; |
5157 | } | |
5158 | ||
5159 | enum { Model, Ray, View, Window, Grid } aMode = Model; | |
5160 | ||
5161 | // access coordinate arguments | |
5162 | TColStd_SequenceOfReal aCoord; | |
5163 | Standard_Integer anArgIdx = 1; | |
5164 | for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx) | |
5165 | { | |
5166 | TCollection_AsciiString anArg (theArgVec[anArgIdx]); | |
5167 | if (!anArg.IsRealValue()) | |
5168 | { | |
5169 | break; | |
5170 | } | |
5171 | aCoord.Append (anArg.RealValue()); | |
5172 | } | |
5173 | ||
5174 | // non-numeric argument too early | |
5175 | if (aCoord.IsEmpty()) | |
5176 | { | |
5177 | std::cerr << "Error: wrong number of arguments! See usage:\n"; | |
5178 | theDI.PrintHelp (theArgVec[0]); | |
5179 | return 1; | |
5180 | } | |
5181 | ||
5182 | // collect all other arguments and options | |
5183 | for (; anArgIdx < theArgNb; ++anArgIdx) | |
5184 | { | |
5185 | TCollection_AsciiString anArg (theArgVec[anArgIdx]); | |
5186 | anArg.LowerCase(); | |
5187 | if (anArg == "window") aMode = Window; | |
5188 | else if (anArg == "view") aMode = View; | |
5189 | else if (anArg == "grid") aMode = Grid; | |
5190 | else if (anArg == "ray") aMode = Ray; | |
5191 | else | |
5192 | { | |
5193 | std::cerr << "Error: wrong argument " << anArg << "! See usage:\n"; | |
5194 | theDI.PrintHelp (theArgVec[0]); | |
5195 | return 1; | |
5196 | } | |
5197 | } | |
5198 | ||
5199 | // complete input checks | |
5200 | if ((aCoord.Length() == 1 && theArgNb > 3) || | |
5201 | (aCoord.Length() == 2 && theArgNb > 4) || | |
5202 | (aCoord.Length() == 3 && theArgNb > 5)) | |
5203 | { | |
5204 | std::cerr << "Error: wrong number of arguments! See usage:\n"; | |
5205 | theDI.PrintHelp (theArgVec[0]); | |
5206 | return 1; | |
5207 | } | |
5208 | ||
5209 | Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; | |
5210 | Standard_Integer aXYp[2] = {0, 0}; | |
5211 | ||
5212 | // convert one-dimensional coordinate | |
5213 | if (aCoord.Length() == 1) | |
5214 | { | |
5215 | switch (aMode) | |
5216 | { | |
5217 | case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer) aCoord (1)); return 0; | |
5218 | case Window : theDI << "Window Vp: " << aView->Convert ((Quantity_Length) aCoord (1)); return 0; | |
5219 | default: | |
5220 | std::cerr << "Error: wrong arguments! See usage:\n"; | |
5221 | theDI.PrintHelp (theArgVec[0]); | |
5222 | return 1; | |
5223 | } | |
5224 | } | |
5225 | ||
5226 | // convert 2D coordinates from projection or view reference space | |
5227 | if (aCoord.Length() == 2) | |
5228 | { | |
5229 | switch (aMode) | |
5230 | { | |
5231 | case Model : | |
5232 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]); | |
5233 | theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n"; | |
5234 | return 0; | |
5235 | ||
5236 | case View : | |
5237 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]); | |
5238 | theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n"; | |
5239 | return 0; | |
5240 | ||
5241 | case Window : | |
5242 | aView->Convert ((V3d_Coordinate) aCoord (1), (V3d_Coordinate) aCoord (2), aXYp[0], aXYp[1]); | |
5243 | theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n"; | |
5244 | return 0; | |
5245 | ||
5246 | case Grid : | |
5247 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]); | |
5248 | aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]); | |
5249 | theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n"; | |
5250 | return 0; | |
5251 | ||
5252 | case Ray : | |
5253 | aView->ConvertWithProj ((Standard_Integer) aCoord (1), | |
5254 | (Standard_Integer) aCoord (2), | |
5255 | aXYZ[0], aXYZ[1], aXYZ[2], | |
5256 | aXYZ[3], aXYZ[4], aXYZ[5]); | |
5257 | theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n"; | |
5258 | return 0; | |
5259 | ||
5260 | default: | |
5261 | std::cerr << "Error: wrong arguments! See usage:\n"; | |
5262 | theDI.PrintHelp (theArgVec[0]); | |
5263 | return 1; | |
5264 | } | |
5265 | } | |
5266 | ||
5267 | // convert 3D coordinates from view reference space | |
5268 | else if (aCoord.Length() == 3) | |
5269 | { | |
5270 | switch (aMode) | |
5271 | { | |
5272 | case Window : | |
5273 | aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]); | |
5274 | theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n"; | |
5275 | return 0; | |
5276 | ||
5277 | case Grid : | |
5278 | aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]); | |
5279 | theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n"; | |
5280 | return 0; | |
5281 | ||
5282 | default: | |
5283 | std::cerr << "Error: wrong arguments! See usage:\n"; | |
5284 | theDI.PrintHelp (theArgVec[0]); | |
5285 | return 1; | |
5286 | } | |
5287 | } | |
5288 | ||
5289 | return 0; | |
5290 | } | |
5291 | ||
208e6839 | 5292 | //============================================================================== |
5293 | //function : VFps | |
5294 | //purpose : | |
5295 | //============================================================================== | |
5296 | ||
5297 | static int VFps (Draw_Interpretor& theDI, | |
5298 | Standard_Integer theArgNb, | |
5299 | const char** theArgVec) | |
5300 | { | |
5301 | // get the active view | |
5302 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5303 | if (aView.IsNull()) | |
5304 | { | |
5305 | std::cerr << "No active view. Please call vinit.\n"; | |
5306 | return 1; | |
5307 | } | |
5308 | ||
91322f44 | 5309 | Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100; |
208e6839 | 5310 | if (aFramesNb <= 0) |
5311 | { | |
5312 | std::cerr << "Incorrect arguments!\n"; | |
5313 | return 1; | |
5314 | } | |
5315 | ||
5316 | // the time is meaningless for first call | |
5317 | // due to async OpenGl rendering | |
5318 | aView->Redraw(); | |
5319 | ||
5320 | // redraw view in loop to estimate average values | |
5321 | OSD_Timer aTimer; | |
5322 | aTimer.Start(); | |
5323 | for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter) | |
5324 | { | |
5325 | aView->Redraw(); | |
5326 | } | |
5327 | aTimer.Stop(); | |
5328 | Standard_Real aCpu; | |
5329 | const Standard_Real aTime = aTimer.ElapsedTime(); | |
5330 | aTimer.OSD_Chronometer::Show (aCpu); | |
5331 | ||
5332 | const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime; | |
5333 | const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb); | |
5334 | ||
5335 | // return statistics | |
5336 | theDI << "FPS: " << aFpsAver << "\n" | |
5337 | << "CPU: " << (1000.0 * aCpuAver) << " msec\n"; | |
5338 | ||
8c820969 | 5339 | // compute additional statistics in ray-tracing mode |
5340 | Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams(); | |
5341 | ||
5342 | if (aParams.Method == Graphic3d_RM_RAYTRACING) | |
5343 | { | |
5344 | Standard_Integer aSizeX; | |
5345 | Standard_Integer aSizeY; | |
5346 | ||
5347 | aView->Window()->Size (aSizeX, aSizeY); | |
5348 | ||
5349 | // 1 shadow ray and 1 secondary ray pew each bounce | |
5350 | const Standard_Real aMRays = aSizeX * aSizeY * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f; | |
5351 | ||
5352 | theDI << "MRays/sec (upper bound): " << aMRays << "\n"; | |
5353 | } | |
5354 | ||
208e6839 | 5355 | return 0; |
5356 | } | |
5357 | ||
58655684 | 5358 | //============================================================================== |
5359 | //function : VGlDebug | |
5360 | //purpose : | |
5361 | //============================================================================== | |
5362 | ||
5363 | static int VGlDebug (Draw_Interpretor& theDI, | |
5364 | Standard_Integer theArgNb, | |
5365 | const char** theArgVec) | |
5366 | { | |
aaf512f1 | 5367 | Handle(OpenGl_GraphicDriver) aDriver; |
5368 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5369 | if (!aView.IsNull()) | |
5370 | { | |
5371 | aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver()); | |
5372 | } | |
c87535af | 5373 | OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps; |
5374 | OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL; | |
5375 | ||
58655684 | 5376 | if (theArgNb < 2) |
5377 | { | |
c87535af | 5378 | TCollection_AsciiString aDebActive, aSyncActive; |
5379 | if (aCaps == NULL) | |
58655684 | 5380 | { |
c87535af | 5381 | aCaps = aDefCaps; |
5382 | } | |
5383 | else | |
5384 | { | |
5385 | Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS), | |
5386 | "GL_ARB_debug_output"); | |
5387 | aDebActive = isActive ? " (active)" : " (inactive)"; | |
5388 | if (isActive) | |
5389 | { | |
5390 | // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB | |
5391 | aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)"; | |
5392 | } | |
58655684 | 5393 | } |
5394 | ||
c87535af | 5395 | theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n" |
5396 | << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n" | |
5397 | << "glslWarn:" << (aCaps->glslWarnings ? "1" : "0") << "\n" | |
5398 | << "extraMsg:" << (aCaps->suppressExtraMsg ? "0" : "1") << "\n"; | |
58655684 | 5399 | return 0; |
5400 | } | |
5401 | ||
c87535af | 5402 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
aaf512f1 | 5403 | { |
c87535af | 5404 | Standard_CString anArg = theArgVec[anArgIter]; |
5405 | TCollection_AsciiString anArgCase (anArg); | |
5406 | anArgCase.LowerCase(); | |
5407 | Standard_Boolean toEnableDebug = Standard_True; | |
5408 | if (anArgCase == "-glsl" | |
5409 | || anArgCase == "-glslwarn" | |
5410 | || anArgCase == "-glslwarns" | |
5411 | || anArgCase == "-glslwarnings") | |
5412 | { | |
5413 | Standard_Boolean toShowWarns = Standard_True; | |
5414 | if (++anArgIter < theArgNb | |
a5565a3c | 5415 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns)) |
c87535af | 5416 | { |
5417 | --anArgIter; | |
5418 | } | |
5419 | aDefCaps->glslWarnings = toShowWarns; | |
5420 | if (aCaps != NULL) | |
5421 | { | |
5422 | aCaps->glslWarnings = toShowWarns; | |
5423 | } | |
5424 | } | |
5425 | else if (anArgCase == "-extra" | |
5426 | || anArgCase == "-extramsg" | |
5427 | || anArgCase == "-extramessages") | |
5428 | { | |
5429 | Standard_Boolean toShow = Standard_True; | |
5430 | if (++anArgIter < theArgNb | |
a5565a3c | 5431 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow)) |
c87535af | 5432 | { |
5433 | --anArgIter; | |
5434 | } | |
5435 | aDefCaps->suppressExtraMsg = !toShow; | |
5436 | if (aCaps != NULL) | |
5437 | { | |
5438 | aCaps->suppressExtraMsg = !toShow; | |
5439 | } | |
5440 | } | |
5441 | else if (anArgCase == "-noextra" | |
5442 | || anArgCase == "-noextramsg" | |
5443 | || anArgCase == "-noextramessages") | |
5444 | { | |
5445 | Standard_Boolean toSuppress = Standard_True; | |
5446 | if (++anArgIter < theArgNb | |
a5565a3c | 5447 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress)) |
c87535af | 5448 | { |
5449 | --anArgIter; | |
5450 | } | |
5451 | aDefCaps->suppressExtraMsg = toSuppress; | |
5452 | if (aCaps != NULL) | |
5453 | { | |
5454 | aCaps->suppressExtraMsg = toSuppress; | |
5455 | } | |
5456 | } | |
5457 | else if (anArgCase == "-sync") | |
5458 | { | |
5459 | Standard_Boolean toSync = Standard_True; | |
5460 | if (++anArgIter < theArgNb | |
a5565a3c | 5461 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync)) |
c87535af | 5462 | { |
5463 | --anArgIter; | |
5464 | } | |
5465 | aDefCaps->contextSyncDebug = toSync; | |
5466 | if (toSync) | |
5467 | { | |
5468 | aDefCaps->contextDebug = Standard_True; | |
5469 | } | |
5470 | } | |
5471 | else if (anArgCase == "-debug") | |
5472 | { | |
5473 | if (++anArgIter < theArgNb | |
a5565a3c | 5474 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug)) |
c87535af | 5475 | { |
5476 | --anArgIter; | |
5477 | } | |
5478 | aDefCaps->contextDebug = toEnableDebug; | |
5479 | } | |
a5565a3c | 5480 | else if (ViewerTest::ParseOnOff (anArg, toEnableDebug) |
c87535af | 5481 | && (anArgIter + 1 == theArgNb)) |
5482 | { | |
5483 | // simple alias to turn on almost everything | |
5484 | aDefCaps->contextDebug = toEnableDebug; | |
5485 | aDefCaps->contextSyncDebug = toEnableDebug; | |
5486 | aDefCaps->glslWarnings = toEnableDebug; | |
5487 | } | |
5488 | else | |
5489 | { | |
5490 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
5491 | return 1; | |
5492 | } | |
aaf512f1 | 5493 | } |
5494 | ||
58655684 | 5495 | return 0; |
5496 | } | |
208e6839 | 5497 | |
5498 | //============================================================================== | |
5499 | //function : VVbo | |
5500 | //purpose : | |
5501 | //============================================================================== | |
5502 | ||
58655684 | 5503 | static int VVbo (Draw_Interpretor& theDI, |
208e6839 | 5504 | Standard_Integer theArgNb, |
5505 | const char** theArgVec) | |
5506 | { | |
58655684 | 5507 | const Standard_Boolean toSet = (theArgNb > 1); |
5508 | const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1; | |
5509 | if (toSet) | |
208e6839 | 5510 | { |
58655684 | 5511 | ViewerTest_myDefaultCaps.vboDisable = toUseVbo; |
208e6839 | 5512 | } |
5513 | ||
58655684 | 5514 | // get the context |
5515 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
5516 | if (aContextAIS.IsNull()) | |
208e6839 | 5517 | { |
58655684 | 5518 | if (!toSet) |
5519 | { | |
5520 | std::cerr << "No active view!\n"; | |
5521 | } | |
208e6839 | 5522 | return 1; |
5523 | } | |
58655684 | 5524 | Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver()); |
5525 | if (!aDriver.IsNull()) | |
208e6839 | 5526 | { |
58655684 | 5527 | if (!toSet) |
5528 | { | |
5529 | theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n"; | |
5530 | } | |
5531 | else | |
5532 | { | |
5533 | aDriver->ChangeOptions().vboDisable = toUseVbo; | |
5534 | } | |
208e6839 | 5535 | } |
5536 | ||
208e6839 | 5537 | return 0; |
5538 | } | |
5539 | ||
a577aaab | 5540 | //============================================================================== |
5541 | //function : VCaps | |
5542 | //purpose : | |
5543 | //============================================================================== | |
5544 | ||
5545 | static int VCaps (Draw_Interpretor& theDI, | |
5546 | Standard_Integer theArgNb, | |
5547 | const char** theArgVec) | |
5548 | { | |
5549 | OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps; | |
5550 | Handle(OpenGl_GraphicDriver) aDriver; | |
8625ef7e | 5551 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
5552 | if (!aContext.IsNull()) | |
a577aaab | 5553 | { |
8625ef7e | 5554 | aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver()); |
a577aaab | 5555 | aCaps = &aDriver->ChangeOptions(); |
5556 | } | |
5557 | ||
5558 | if (theArgNb < 2) | |
5559 | { | |
5560 | theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n"; | |
5561 | theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n"; | |
abe46077 | 5562 | theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n"; |
8625ef7e | 5563 | theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n"; |
f978241f | 5564 | theDI << "VSync: " << aCaps->swapInterval << "\n"; |
4e1523ef | 5565 | theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n"; |
f978241f | 5566 | theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n"; |
56689b27 | 5567 | theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n"; |
a577aaab | 5568 | return 0; |
5569 | } | |
5570 | ||
8625ef7e | 5571 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); |
a577aaab | 5572 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
5573 | { | |
8625ef7e | 5574 | Standard_CString anArg = theArgVec[anArgIter]; |
5575 | TCollection_AsciiString anArgCase (anArg); | |
5576 | anArgCase.LowerCase(); | |
5577 | if (anUpdateTool.parseRedrawMode (anArg)) | |
5578 | { | |
5579 | continue; | |
5580 | } | |
f978241f | 5581 | else if (anArgCase == "-vsync" |
5582 | || anArgCase == "-swapinterval") | |
5583 | { | |
5584 | Standard_Boolean toEnable = Standard_True; | |
5585 | if (++anArgIter < theArgNb | |
a5565a3c | 5586 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
f978241f | 5587 | { |
5588 | --anArgIter; | |
5589 | } | |
5590 | aCaps->swapInterval = toEnable; | |
5591 | } | |
8625ef7e | 5592 | else if (anArgCase == "-ffp") |
5593 | { | |
5594 | Standard_Boolean toEnable = Standard_True; | |
5595 | if (++anArgIter < theArgNb | |
a5565a3c | 5596 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 5597 | { |
5598 | --anArgIter; | |
5599 | } | |
5600 | aCaps->ffpEnable = toEnable; | |
5601 | } | |
5602 | else if (anArgCase == "-vbo") | |
a577aaab | 5603 | { |
8625ef7e | 5604 | Standard_Boolean toEnable = Standard_True; |
5605 | if (++anArgIter < theArgNb | |
a5565a3c | 5606 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 5607 | { |
5608 | --anArgIter; | |
5609 | } | |
5610 | aCaps->vboDisable = !toEnable; | |
a577aaab | 5611 | } |
8625ef7e | 5612 | else if (anArgCase == "-sprite" |
5613 | || anArgCase == "-sprites") | |
a577aaab | 5614 | { |
8625ef7e | 5615 | Standard_Boolean toEnable = Standard_True; |
5616 | if (++anArgIter < theArgNb | |
a5565a3c | 5617 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 5618 | { |
5619 | --anArgIter; | |
5620 | } | |
5621 | aCaps->pntSpritesDisable = !toEnable; | |
a577aaab | 5622 | } |
8625ef7e | 5623 | else if (anArgCase == "-softmode") |
abe46077 | 5624 | { |
8625ef7e | 5625 | Standard_Boolean toEnable = Standard_True; |
5626 | if (++anArgIter < theArgNb | |
a5565a3c | 5627 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 5628 | { |
5629 | --anArgIter; | |
5630 | } | |
5631 | aCaps->contextNoAccel = toEnable; | |
5632 | } | |
56689b27 | 5633 | else if (anArgCase == "-winbuffer" |
5634 | || anArgCase == "-windowbuffer" | |
5635 | || anArgCase == "-usewinbuffer" | |
5636 | || anArgCase == "-usewindowbuffer" | |
5637 | || anArgCase == "-usesystembuffer") | |
5638 | { | |
5639 | Standard_Boolean toEnable = Standard_True; | |
5640 | if (++anArgIter < theArgNb | |
5641 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
5642 | { | |
5643 | --anArgIter; | |
5644 | } | |
5645 | aCaps->useSystemBuffer = toEnable; | |
5646 | } | |
8625ef7e | 5647 | else if (anArgCase == "-accel" |
5648 | || anArgCase == "-acceleration") | |
5649 | { | |
5650 | Standard_Boolean toEnable = Standard_True; | |
5651 | if (++anArgIter < theArgNb | |
a5565a3c | 5652 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 5653 | { |
5654 | --anArgIter; | |
5655 | } | |
5656 | aCaps->contextNoAccel = !toEnable; | |
abe46077 | 5657 | } |
4e1523ef | 5658 | else if (anArgCase == "-compat" |
5659 | || anArgCase == "-compatprofile" | |
5660 | || anArgCase == "-compatible" | |
5661 | || anArgCase == "-compatibleprofile") | |
5662 | { | |
5663 | Standard_Boolean toEnable = Standard_True; | |
5664 | if (++anArgIter < theArgNb | |
a5565a3c | 5665 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
4e1523ef | 5666 | { |
5667 | --anArgIter; | |
5668 | } | |
5669 | aCaps->contextCompatible = toEnable; | |
5670 | if (!aCaps->contextCompatible) | |
5671 | { | |
5672 | aCaps->ffpEnable = Standard_False; | |
5673 | } | |
5674 | } | |
5675 | else if (anArgCase == "-core" | |
5676 | || anArgCase == "-coreprofile") | |
5677 | { | |
5678 | Standard_Boolean toEnable = Standard_True; | |
5679 | if (++anArgIter < theArgNb | |
a5565a3c | 5680 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
4e1523ef | 5681 | { |
5682 | --anArgIter; | |
5683 | } | |
5684 | aCaps->contextCompatible = !toEnable; | |
5685 | if (!aCaps->contextCompatible) | |
5686 | { | |
5687 | aCaps->ffpEnable = Standard_False; | |
5688 | } | |
5689 | } | |
f978241f | 5690 | else if (anArgCase == "-stereo" |
5691 | || anArgCase == "-quadbuffer") | |
5692 | { | |
5693 | Standard_Boolean toEnable = Standard_True; | |
5694 | if (++anArgIter < theArgNb | |
a5565a3c | 5695 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
f978241f | 5696 | { |
5697 | --anArgIter; | |
5698 | } | |
5699 | aCaps->contextStereo = toEnable; | |
5700 | } | |
a577aaab | 5701 | else |
5702 | { | |
8625ef7e | 5703 | std::cout << "Error: unknown argument '" << anArg << "'\n"; |
5704 | return 1; | |
a577aaab | 5705 | } |
5706 | } | |
5707 | if (aCaps != &ViewerTest_myDefaultCaps) | |
5708 | { | |
5709 | ViewerTest_myDefaultCaps = *aCaps; | |
5710 | } | |
5711 | return 0; | |
5712 | } | |
5713 | ||
f0430952 | 5714 | //============================================================================== |
5715 | //function : VMemGpu | |
5716 | //purpose : | |
5717 | //============================================================================== | |
5718 | ||
5719 | static int VMemGpu (Draw_Interpretor& theDI, | |
5720 | Standard_Integer theArgNb, | |
5721 | const char** theArgVec) | |
5722 | { | |
5723 | // get the context | |
5724 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
5725 | if (aContextAIS.IsNull()) | |
5726 | { | |
5727 | std::cerr << "No active view. Please call vinit.\n"; | |
5728 | return 1; | |
5729 | } | |
5730 | ||
dc3fe572 | 5731 | Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver(); |
f0430952 | 5732 | if (aDriver.IsNull()) |
5733 | { | |
5734 | std::cerr << "Graphic driver not available.\n"; | |
5735 | return 1; | |
5736 | } | |
5737 | ||
5738 | Standard_Size aFreeBytes = 0; | |
5739 | TCollection_AsciiString anInfo; | |
5740 | if (!aDriver->MemoryInfo (aFreeBytes, anInfo)) | |
5741 | { | |
5742 | std::cerr << "Information not available.\n"; | |
5743 | return 1; | |
5744 | } | |
5745 | ||
5746 | if (theArgNb > 1 && *theArgVec[1] == 'f') | |
5747 | { | |
5748 | theDI << Standard_Real (aFreeBytes); | |
5749 | } | |
5750 | else | |
5751 | { | |
5752 | theDI << anInfo; | |
5753 | } | |
5754 | ||
5755 | return 0; | |
5756 | } | |
5757 | ||
85e096c3 | 5758 | // ============================================================================== |
5759 | // function : VReadPixel | |
5760 | // purpose : | |
5761 | // ============================================================================== | |
5762 | static int VReadPixel (Draw_Interpretor& theDI, | |
5763 | Standard_Integer theArgNb, | |
5764 | const char** theArgVec) | |
5765 | { | |
5766 | // get the active view | |
5767 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5768 | if (aView.IsNull()) | |
5769 | { | |
5770 | std::cerr << "No active view. Please call vinit.\n"; | |
5771 | return 1; | |
5772 | } | |
5773 | else if (theArgNb < 3) | |
5774 | { | |
5775 | std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n"; | |
5776 | return 1; | |
5777 | } | |
5778 | ||
dc858f4c | 5779 | Image_Format aFormat = Image_Format_RGBA; |
5780 | Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA; | |
692613e5 | 5781 | |
85e096c3 | 5782 | Standard_Integer aWidth, aHeight; |
5783 | aView->Window()->Size (aWidth, aHeight); | |
91322f44 | 5784 | const Standard_Integer anX = Draw::Atoi (theArgVec[1]); |
5785 | const Standard_Integer anY = Draw::Atoi (theArgVec[2]); | |
85e096c3 | 5786 | if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight) |
5787 | { | |
5788 | std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n"; | |
5789 | return 1; | |
5790 | } | |
5791 | ||
5792 | Standard_Boolean toShowName = Standard_False; | |
5793 | Standard_Boolean toShowHls = Standard_False; | |
5794 | for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter) | |
5795 | { | |
dc858f4c | 5796 | TCollection_AsciiString aParam (theArgVec[anIter]); |
5797 | aParam.LowerCase(); | |
5798 | if (aParam == "rgb") | |
85e096c3 | 5799 | { |
dc858f4c | 5800 | aFormat = Image_Format_RGB; |
692613e5 | 5801 | aBufferType = Graphic3d_BT_RGB; |
85e096c3 | 5802 | } |
dc858f4c | 5803 | else if (aParam == "hls") |
85e096c3 | 5804 | { |
dc858f4c | 5805 | aFormat = Image_Format_RGB; |
692613e5 | 5806 | aBufferType = Graphic3d_BT_RGB; |
85e096c3 | 5807 | toShowHls = Standard_True; |
5808 | } | |
dc858f4c | 5809 | else if (aParam == "rgbf") |
85e096c3 | 5810 | { |
dc858f4c | 5811 | aFormat = Image_Format_RGBF; |
692613e5 | 5812 | aBufferType = Graphic3d_BT_RGB; |
85e096c3 | 5813 | } |
dc858f4c | 5814 | else if (aParam == "rgba") |
85e096c3 | 5815 | { |
dc858f4c | 5816 | aFormat = Image_Format_RGBA; |
692613e5 | 5817 | aBufferType = Graphic3d_BT_RGBA; |
85e096c3 | 5818 | } |
dc858f4c | 5819 | else if (aParam == "rgbaf") |
85e096c3 | 5820 | { |
dc858f4c | 5821 | aFormat = Image_Format_RGBAF; |
692613e5 | 5822 | aBufferType = Graphic3d_BT_RGBA; |
85e096c3 | 5823 | } |
dc858f4c | 5824 | else if (aParam == "depth") |
85e096c3 | 5825 | { |
dc858f4c | 5826 | aFormat = Image_Format_GrayF; |
692613e5 | 5827 | aBufferType = Graphic3d_BT_Depth; |
85e096c3 | 5828 | } |
dc858f4c | 5829 | else if (aParam == "name") |
85e096c3 | 5830 | { |
5831 | toShowName = Standard_True; | |
5832 | } | |
5833 | } | |
5834 | ||
692613e5 | 5835 | Image_PixMap anImage; |
5836 | if (!anImage.InitTrash (aFormat, aWidth, aHeight)) | |
5837 | { | |
5838 | std::cerr << "Image allocation failed\n"; | |
5839 | return 1; | |
5840 | } | |
5841 | else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType)) | |
85e096c3 | 5842 | { |
5843 | std::cerr << "Image dump failed\n"; | |
5844 | return 1; | |
5845 | } | |
5846 | ||
5847 | Quantity_Parameter anAlpha; | |
692613e5 | 5848 | Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha); |
85e096c3 | 5849 | if (toShowName) |
5850 | { | |
692613e5 | 5851 | if (aBufferType == Graphic3d_BT_RGBA) |
85e096c3 | 5852 | { |
64c759f8 | 5853 | theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha; |
85e096c3 | 5854 | } |
5855 | else | |
5856 | { | |
64c759f8 | 5857 | theDI << Quantity_Color::StringName (aColor.Name()); |
85e096c3 | 5858 | } |
5859 | } | |
5860 | else | |
5861 | { | |
5862 | switch (aBufferType) | |
5863 | { | |
5864 | default: | |
692613e5 | 5865 | case Graphic3d_BT_RGB: |
85e096c3 | 5866 | { |
5867 | if (toShowHls) | |
5868 | { | |
64c759f8 | 5869 | theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation(); |
85e096c3 | 5870 | } |
5871 | else | |
5872 | { | |
64c759f8 | 5873 | theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue(); |
85e096c3 | 5874 | } |
5875 | break; | |
5876 | } | |
692613e5 | 5877 | case Graphic3d_BT_RGBA: |
85e096c3 | 5878 | { |
64c759f8 | 5879 | theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha; |
85e096c3 | 5880 | break; |
5881 | } | |
692613e5 | 5882 | case Graphic3d_BT_Depth: |
85e096c3 | 5883 | { |
64c759f8 | 5884 | theDI << aColor.Red(); |
85e096c3 | 5885 | break; |
5886 | } | |
5887 | } | |
5888 | } | |
5889 | ||
5890 | return 0; | |
5891 | } | |
5892 | ||
692613e5 | 5893 | //============================================================================== |
5894 | //function : VDiffImage | |
5895 | //purpose : The draw-command compares two images. | |
5896 | //============================================================================== | |
5897 | ||
5898 | static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
5899 | { | |
5900 | if (theArgNb < 6) | |
5901 | { | |
5902 | theDI << "Not enough arguments.\n"; | |
5903 | return 1; | |
5904 | } | |
5905 | ||
5906 | // image file names | |
5907 | const char* anImgPathRef = theArgVec[1]; | |
5908 | const char* anImgPathNew = theArgVec[2]; | |
5909 | ||
5910 | // get string tolerance and check its validity | |
91322f44 | 5911 | Standard_Real aTolColor = Draw::Atof (theArgVec[3]); |
692613e5 | 5912 | if (aTolColor < 0.0) |
5913 | aTolColor = 0.0; | |
5914 | if (aTolColor > 1.0) | |
5915 | aTolColor = 1.0; | |
5916 | ||
91322f44 | 5917 | Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1); |
5918 | Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1); | |
692613e5 | 5919 | |
5920 | // image file of difference | |
5921 | const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL; | |
5922 | ||
5923 | // compare the images | |
5924 | Image_Diff aComparer; | |
5925 | if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite)) | |
5926 | { | |
5927 | return 1; | |
5928 | } | |
5929 | ||
5930 | aComparer.SetColorTolerance (aTolColor); | |
5931 | aComparer.SetBorderFilterOn (isBorderFilterOn); | |
5932 | Standard_Integer aDiffColorsNb = aComparer.Compare(); | |
5933 | theDI << aDiffColorsNb << "\n"; | |
5934 | ||
5935 | // save image of difference | |
936f43da | 5936 | if (aDiffColorsNb >0 && aDiffImagePath != NULL) |
692613e5 | 5937 | { |
5938 | aComparer.SaveDiffImage (aDiffImagePath); | |
5939 | } | |
5940 | ||
5941 | return 0; | |
5942 | } | |
5943 | ||
4754e164 | 5944 | //======================================================================= |
5945 | //function : VSelect | |
5946 | //purpose : Emulates different types of selection by mouse: | |
5947 | // 1) single click selection | |
5948 | // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2) | |
5949 | // 3) selection with polygon having corners at | |
dc3fe572 | 5950 | // pixel positions (x1,y1),...,(xn,yn) |
4754e164 | 5951 | // 4) any of these selections with shift button pressed |
5952 | //======================================================================= | |
5953 | static Standard_Integer VSelect (Draw_Interpretor& di, | |
5954 | Standard_Integer argc, | |
5955 | const char ** argv) | |
5956 | { | |
dc3fe572 | 5957 | if(argc < 3) |
4754e164 | 5958 | { |
586db386 | 5959 | di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]\n"; |
4754e164 | 5960 | return 1; |
5961 | } | |
5962 | ||
5963 | Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); | |
dc3fe572 | 5964 | if(myAIScontext.IsNull()) |
4754e164 | 5965 | { |
5966 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
5967 | return 1; | |
5968 | } | |
2157d6ac | 5969 | |
5970 | const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1)); | |
5971 | Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1; | |
5972 | TCollection_AsciiString anArg; | |
5973 | anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2]; | |
5974 | anArg.LowerCase(); | |
5975 | if (anArg == "-allowoverlap") | |
5976 | { | |
5977 | Standard_Boolean isValidated = isShiftSelection ? argc == 8 | |
5978 | : argc == 7; | |
5979 | if (!isValidated) | |
5980 | { | |
5981 | di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection"; | |
5982 | return 1; | |
5983 | } | |
5984 | ||
5985 | Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]); | |
dde68833 | 5986 | myAIScontext->MainSelector()->AllowOverlapDetection (isToAllow != 0); |
2157d6ac | 5987 | aCoordsNb -= 2; |
5988 | } | |
5989 | ||
4754e164 | 5990 | Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager(); |
5991 | aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2])); | |
2157d6ac | 5992 | if(aCoordsNb == 2) |
4754e164 | 5993 | { |
5994 | if(isShiftSelection) | |
5995 | aCurrentEventManager->ShiftSelect(); | |
5996 | else | |
5997 | aCurrentEventManager->Select(); | |
5998 | } | |
2157d6ac | 5999 | else if(aCoordsNb == 4) |
4754e164 | 6000 | { |
6001 | if(isShiftSelection) | |
2157d6ac | 6002 | aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False); |
4754e164 | 6003 | else |
2157d6ac | 6004 | aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False); |
4754e164 | 6005 | } |
6006 | else | |
6007 | { | |
2157d6ac | 6008 | TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2); |
4754e164 | 6009 | |
2157d6ac | 6010 | for(Standard_Integer i=1;i<=aCoordsNb / 2;++i) |
4754e164 | 6011 | aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i]))); |
6012 | ||
6013 | if(isShiftSelection) | |
6014 | aCurrentEventManager->ShiftSelect(aPolyline); | |
6015 | else | |
6016 | aCurrentEventManager->Select(aPolyline); | |
6017 | } | |
6018 | return 0; | |
6019 | } | |
6020 | ||
6021 | //======================================================================= | |
6022 | //function : VMoveTo | |
dc3fe572 | 6023 | //purpose : Emulates cursor movement to defined pixel position |
4754e164 | 6024 | //======================================================================= |
6025 | static Standard_Integer VMoveTo (Draw_Interpretor& di, | |
6026 | Standard_Integer argc, | |
6027 | const char ** argv) | |
6028 | { | |
dc3fe572 | 6029 | if(argc != 3) |
4754e164 | 6030 | { |
586db386 | 6031 | di << "Usage : " << argv[0] << " x y\n"; |
4754e164 | 6032 | return 1; |
6033 | } | |
6034 | ||
6035 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
dc3fe572 | 6036 | if(aContext.IsNull()) |
4754e164 | 6037 | { |
6038 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
6039 | return 1; | |
6040 | } | |
6041 | ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2])); | |
6042 | return 0; | |
6043 | } | |
6044 | ||
1beb58d7 | 6045 | namespace |
6046 | { | |
6047 | //! Global map storing all animations registered in ViewerTest. | |
6048 | static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap; | |
6049 | ||
6050 | //! The animation calling the Draw Harness command. | |
6051 | class ViewerTest_AnimationProc : public AIS_Animation | |
6052 | { | |
6053 | public: | |
6054 | ||
6055 | //! Main constructor. | |
6056 | ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName, | |
6057 | Draw_Interpretor* theDI, | |
6058 | const TCollection_AsciiString& theCommand) | |
6059 | : AIS_Animation (theAnimationName), | |
6060 | myDrawInter(theDI), | |
6061 | myCommand (theCommand) | |
6062 | { | |
6063 | // | |
6064 | } | |
6065 | ||
6066 | protected: | |
6067 | ||
6068 | //! Evaluate the command. | |
6069 | virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE | |
6070 | { | |
6071 | TCollection_AsciiString aCmd = myCommand; | |
6072 | replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts)); | |
6073 | replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts)); | |
6074 | replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts)); | |
6075 | replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized)); | |
6076 | replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized)); | |
6077 | myDrawInter->Eval (aCmd.ToCString()); | |
6078 | } | |
6079 | ||
6080 | //! Find the keyword in the command and replace it with value. | |
6081 | //! @return the position of the keyword to pass value | |
6082 | void replace (TCollection_AsciiString& theCmd, | |
6083 | const TCollection_AsciiString& theKey, | |
6084 | const TCollection_AsciiString& theVal) | |
6085 | { | |
6086 | TCollection_AsciiString aCmd (theCmd); | |
6087 | aCmd.LowerCase(); | |
6088 | const Standard_Integer aPos = aCmd.Search (theKey); | |
6089 | if (aPos == -1) | |
6090 | { | |
6091 | return; | |
6092 | } | |
6093 | ||
6094 | TCollection_AsciiString aPart1, aPart2; | |
6095 | Standard_Integer aPart1To = aPos - 1; | |
6096 | if (aPart1To >= 1 | |
6097 | && aPart1To <= theCmd.Length()) | |
6098 | { | |
6099 | aPart1 = theCmd.SubString (1, aPart1To); | |
6100 | } | |
6101 | ||
6102 | Standard_Integer aPart2From = aPos + theKey.Length(); | |
6103 | if (aPart2From >= 1 | |
6104 | && aPart2From <= theCmd.Length()) | |
6105 | { | |
6106 | aPart2 = theCmd.SubString (aPart2From, theCmd.Length()); | |
6107 | } | |
6108 | ||
6109 | theCmd = aPart1 + theVal + aPart2; | |
6110 | } | |
6111 | ||
6112 | protected: | |
6113 | ||
6114 | Draw_Interpretor* myDrawInter; | |
6115 | TCollection_AsciiString myCommand; | |
6116 | ||
6117 | }; | |
6118 | ||
6119 | //! Replace the animation with the new one. | |
6120 | static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation, | |
6121 | Handle(AIS_Animation)& theAnimation, | |
6122 | const Handle(AIS_Animation)& theAnimationNew) | |
6123 | { | |
6124 | theAnimationNew->CopyFrom (theAnimation); | |
6125 | if (!theParentAnimation.IsNull()) | |
6126 | { | |
6127 | theParentAnimation->Replace (theAnimation, theAnimationNew); | |
6128 | } | |
6129 | else | |
6130 | { | |
6131 | ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name()); | |
6132 | ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew); | |
6133 | } | |
6134 | theAnimation = theAnimationNew; | |
6135 | } | |
6136 | ||
6137 | //! Parse the point. | |
6138 | static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt) | |
6139 | { | |
6140 | const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] }; | |
6141 | if (!anXYZ[0].IsRealValue() | |
6142 | || !anXYZ[1].IsRealValue() | |
6143 | || !anXYZ[2].IsRealValue()) | |
6144 | { | |
6145 | return Standard_False; | |
6146 | } | |
6147 | ||
6148 | thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue()); | |
6149 | return Standard_True; | |
6150 | } | |
6151 | ||
6152 | //! Parse the quaternion. | |
6153 | static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot) | |
6154 | { | |
6155 | const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]}; | |
6156 | if (!anXYZW[0].IsRealValue() | |
6157 | || !anXYZW[1].IsRealValue() | |
6158 | || !anXYZW[2].IsRealValue() | |
6159 | || !anXYZW[3].IsRealValue()) | |
6160 | { | |
6161 | return Standard_False; | |
6162 | } | |
6163 | ||
6164 | theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue()); | |
6165 | return Standard_True; | |
6166 | } | |
6167 | ||
6168 | } | |
6169 | ||
197ac94e | 6170 | //================================================================================================= |
4754e164 | 6171 | //function : VViewParams |
dc3fe572 | 6172 | //purpose : Gets or sets AIS View characteristics |
197ac94e | 6173 | //================================================================================================= |
6174 | static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
4754e164 | 6175 | { |
1beb58d7 | 6176 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
6177 | if (aView.IsNull()) | |
4754e164 | 6178 | { |
197ac94e | 6179 | std::cout << theArgVec[0] << ": please initialize or activate view.\n"; |
4754e164 | 6180 | return 1; |
6181 | } | |
197ac94e | 6182 | |
1beb58d7 | 6183 | Standard_Boolean toSetProj = Standard_False; |
6184 | Standard_Boolean toSetUp = Standard_False; | |
6185 | Standard_Boolean toSetAt = Standard_False; | |
6186 | Standard_Boolean toSetEye = Standard_False; | |
6187 | Standard_Boolean toSetScale = Standard_False; | |
6188 | Standard_Boolean toSetSize = Standard_False; | |
6189 | Standard_Boolean toSetCenter2d = Standard_False; | |
6190 | Quantity_Factor aViewScale = aView->Scale(); | |
6191 | Quantity_Length aViewSize = 1.0; | |
6192 | Graphic3d_Vec2i aCenter2d; | |
6193 | gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye; | |
6194 | aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3)); | |
6195 | aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3)); | |
6196 | aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3)); | |
6197 | aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3)); | |
197ac94e | 6198 | if (theArgsNb == 1) |
4754e164 | 6199 | { |
197ac94e | 6200 | // print all of the available view parameters |
1beb58d7 | 6201 | char aText[4096]; |
6202 | Sprintf (aText, | |
6203 | "Scale: %g\n" | |
6204 | "Proj: %12g %12g %12g\n" | |
6205 | "Up: %12g %12g %12g\n" | |
6206 | "At: %12g %12g %12g\n" | |
6207 | "Eye: %12g %12g %12g\n", | |
6208 | aViewScale, | |
6209 | aViewProj.X(), aViewProj.Y(), aViewProj.Z(), | |
6210 | aViewUp.X(), aViewUp.Y(), aViewUp.Z(), | |
6211 | aViewAt.X(), aViewAt.Y(), aViewAt.Z(), | |
6212 | aViewEye.X(), aViewEye.Y(), aViewEye.Z()); | |
6213 | theDi << aText; | |
197ac94e | 6214 | return 0; |
4754e164 | 6215 | } |
197ac94e | 6216 | |
1beb58d7 | 6217 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
6218 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
197ac94e | 6219 | { |
1beb58d7 | 6220 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
6221 | anArg.LowerCase(); | |
6222 | if (anUpdateTool.parseRedrawMode (anArg)) | |
197ac94e | 6223 | { |
197ac94e | 6224 | continue; |
6225 | } | |
1beb58d7 | 6226 | else if (anArg == "-cmd" |
6227 | || anArg == "-command" | |
6228 | || anArg == "-args") | |
6229 | { | |
6230 | char aText[4096]; | |
6231 | Sprintf (aText, | |
6232 | "-scale %g " | |
6233 | "-proj %g %g %g " | |
6234 | "-up %g %g %g " | |
6235 | "-at %g %g %g\n", | |
6236 | aViewScale, | |
6237 | aViewProj.X(), aViewProj.Y(), aViewProj.Z(), | |
6238 | aViewUp.X(), aViewUp.Y(), aViewUp.Z(), | |
6239 | aViewAt.X(), aViewAt.Y(), aViewAt.Z()); | |
6240 | theDi << aText; | |
6241 | } | |
6242 | else if (anArg == "-scale" | |
6243 | || anArg == "-size") | |
6244 | { | |
6245 | if (anArgIter + 1 < theArgsNb | |
6246 | && *theArgVec[anArgIter + 1] != '-') | |
6247 | { | |
6248 | const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]); | |
6249 | if (aValueArg.IsRealValue()) | |
6250 | { | |
6251 | ++anArgIter; | |
6252 | if (anArg == "-scale") | |
6253 | { | |
6254 | toSetScale = Standard_True; | |
6255 | aViewScale = aValueArg.RealValue(); | |
6256 | } | |
6257 | else if (anArg == "-size") | |
6258 | { | |
6259 | toSetSize = Standard_True; | |
6260 | aViewSize = aValueArg.RealValue(); | |
6261 | } | |
6262 | continue; | |
6263 | } | |
6264 | } | |
6265 | if (anArg == "-scale") | |
6266 | { | |
6267 | theDi << "Scale: " << aView->Scale() << "\n"; | |
6268 | } | |
6269 | else if (anArg == "-size") | |
6270 | { | |
6271 | Graphic3d_Vec2d aSizeXY; | |
6272 | aView->Size (aSizeXY.x(), aSizeXY.y()); | |
6273 | theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n"; | |
6274 | } | |
6275 | } | |
6276 | else if (anArg == "-eye" | |
6277 | || anArg == "-at" | |
6278 | || anArg == "-up" | |
6279 | || anArg == "-proj") | |
6280 | { | |
6281 | if (anArgIter + 3 < theArgsNb) | |
6282 | { | |
6283 | gp_XYZ anXYZ; | |
6284 | if (parseXYZ (theArgVec + anArgIter + 1, anXYZ)) | |
6285 | { | |
6286 | anArgIter += 3; | |
6287 | if (anArg == "-eye") | |
6288 | { | |
6289 | toSetEye = Standard_True; | |
6290 | aViewEye = anXYZ; | |
6291 | } | |
6292 | else if (anArg == "-at") | |
6293 | { | |
6294 | toSetAt = Standard_True; | |
6295 | aViewAt = anXYZ; | |
6296 | } | |
6297 | else if (anArg == "-up") | |
6298 | { | |
6299 | toSetUp = Standard_True; | |
6300 | aViewUp = anXYZ; | |
6301 | } | |
6302 | else if (anArg == "-proj") | |
6303 | { | |
6304 | toSetProj = Standard_True; | |
6305 | aViewProj = anXYZ; | |
6306 | } | |
6307 | continue; | |
6308 | } | |
6309 | } | |
197ac94e | 6310 | |
1beb58d7 | 6311 | if (anArg == "-eye") |
6312 | { | |
6313 | theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n"; | |
6314 | } | |
6315 | else if (anArg == "-at") | |
6316 | { | |
6317 | theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n"; | |
6318 | } | |
6319 | else if (anArg == "-up") | |
6320 | { | |
6321 | theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n"; | |
6322 | } | |
6323 | else if (anArg == "-proj") | |
6324 | { | |
6325 | theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n"; | |
6326 | } | |
6327 | } | |
6328 | else if (anArg == "-center") | |
3dfe95cd | 6329 | { |
1beb58d7 | 6330 | if (anArgIter + 2 < theArgsNb) |
6331 | { | |
6332 | const TCollection_AsciiString anX (theArgVec[anArgIter + 1]); | |
6333 | const TCollection_AsciiString anY (theArgVec[anArgIter + 2]); | |
6334 | if (anX.IsIntegerValue() | |
6335 | && anY.IsIntegerValue()) | |
6336 | { | |
6337 | toSetCenter2d = Standard_True; | |
6338 | aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()); | |
6339 | } | |
6340 | } | |
6341 | } | |
6342 | else | |
6343 | { | |
6344 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
3dfe95cd | 6345 | return 1; |
6346 | } | |
1beb58d7 | 6347 | } |
3dfe95cd | 6348 | |
1beb58d7 | 6349 | // change view parameters in proper order |
6350 | if (toSetScale) | |
6351 | { | |
6352 | aView->SetScale (aViewScale); | |
6353 | } | |
6354 | if (toSetSize) | |
6355 | { | |
6356 | aView->SetSize (aViewSize); | |
6357 | } | |
6358 | if (toSetEye) | |
6359 | { | |
6360 | aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z()); | |
6361 | } | |
6362 | if (toSetAt) | |
6363 | { | |
6364 | aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z()); | |
6365 | } | |
6366 | if (toSetProj) | |
6367 | { | |
6368 | aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z()); | |
6369 | } | |
6370 | if (toSetUp) | |
6371 | { | |
6372 | aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z()); | |
6373 | } | |
6374 | if (toSetCenter2d) | |
6375 | { | |
6376 | aView->SetCenter (aCenter2d.x(), aCenter2d.y()); | |
197ac94e | 6377 | } |
6378 | ||
1beb58d7 | 6379 | return 0; |
6380 | } | |
197ac94e | 6381 | |
1beb58d7 | 6382 | //============================================================================== |
6383 | //function : VAnimation | |
6384 | //purpose : | |
6385 | //============================================================================== | |
6386 | static Standard_Integer VAnimation (Draw_Interpretor& theDI, | |
6387 | Standard_Integer theArgNb, | |
6388 | const char** theArgVec) | |
6389 | { | |
6390 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
6391 | if (theArgNb < 2) | |
4754e164 | 6392 | { |
1beb58d7 | 6393 | for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator |
6394 | anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next()) | |
6395 | { | |
6396 | theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n"; | |
197ac94e | 6397 | } |
1beb58d7 | 6398 | return 0; |
6399 | } | |
6400 | if (aCtx.IsNull()) | |
6401 | { | |
6402 | std::cout << "Error: no active view\n"; | |
6403 | return 1; | |
4754e164 | 6404 | } |
197ac94e | 6405 | |
1beb58d7 | 6406 | Standard_Integer anArgIter = 1; |
6407 | TCollection_AsciiString aNameArg (theArgVec[anArgIter++]); | |
6408 | if (aNameArg.IsEmpty()) | |
6409 | { | |
6410 | std::cout << "Syntax error: animation name is not defined.\n"; | |
6411 | return 1; | |
6412 | } | |
6413 | ||
6414 | TCollection_AsciiString aNameArgLower = aNameArg; | |
6415 | aNameArgLower.LowerCase(); | |
6416 | if (aNameArgLower == "-reset" | |
6417 | || aNameArgLower == "-clear") | |
6418 | { | |
6419 | ViewerTest_AnimationTimelineMap.Clear(); | |
6420 | return 0; | |
6421 | } | |
6422 | else if (aNameArg.Value (1) == '-') | |
6423 | { | |
6424 | std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n"; | |
6425 | return 1; | |
6426 | } | |
197ac94e | 6427 | |
1beb58d7 | 6428 | const char* aNameSplitter = "/"; |
6429 | Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter); | |
6430 | if (aSplitPos == -1) | |
197ac94e | 6431 | { |
1beb58d7 | 6432 | aNameSplitter = "."; |
6433 | aSplitPos = aNameArg.Search (aNameSplitter); | |
6434 | } | |
6435 | ||
6436 | // find existing or create a new animation by specified name within syntax "parent.child". | |
6437 | Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation; | |
6438 | for (; !aNameArg.IsEmpty();) | |
6439 | { | |
6440 | TCollection_AsciiString aNameParent; | |
6441 | if (aSplitPos != -1) | |
197ac94e | 6442 | { |
1beb58d7 | 6443 | if (aSplitPos == aNameArg.Length()) |
6444 | { | |
6445 | std::cout << "Syntax error: animation name is not defined.\n"; | |
6446 | return 1; | |
6447 | } | |
6448 | ||
6449 | aNameParent = aNameArg.SubString ( 1, aSplitPos - 1); | |
6450 | aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length()); | |
6451 | ||
6452 | aSplitPos = aNameArg.Search (aNameSplitter); | |
197ac94e | 6453 | } |
6454 | else | |
6455 | { | |
1beb58d7 | 6456 | aNameParent = aNameArg; |
6457 | aNameArg.Clear(); | |
197ac94e | 6458 | } |
1beb58d7 | 6459 | |
6460 | if (anAnimation.IsNull()) | |
3dfe95cd | 6461 | { |
1beb58d7 | 6462 | if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation)) |
6463 | { | |
6464 | anAnimation = new AIS_Animation (aNameParent); | |
6465 | ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation); | |
6466 | } | |
6467 | aRootAnimation = anAnimation; | |
3dfe95cd | 6468 | } |
6469 | else | |
6470 | { | |
1beb58d7 | 6471 | aParentAnimation = anAnimation; |
6472 | anAnimation = aParentAnimation->Find (aNameParent); | |
6473 | if (anAnimation.IsNull()) | |
6474 | { | |
6475 | anAnimation = new AIS_Animation (aNameParent); | |
6476 | aParentAnimation->Add (anAnimation); | |
6477 | } | |
3dfe95cd | 6478 | } |
6479 | } | |
1beb58d7 | 6480 | |
6481 | if (anArgIter >= theArgNb) | |
197ac94e | 6482 | { |
1beb58d7 | 6483 | // just print the list of children |
6484 | for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next()) | |
197ac94e | 6485 | { |
1beb58d7 | 6486 | theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n"; |
197ac94e | 6487 | } |
1beb58d7 | 6488 | return 0; |
197ac94e | 6489 | } |
1beb58d7 | 6490 | |
bf7b2ceb | 6491 | // animation parameters |
1beb58d7 | 6492 | Standard_Boolean toPlay = Standard_False; |
6493 | Standard_Real aPlaySpeed = 1.0; | |
6494 | Standard_Real aPlayStartTime = anAnimation->StartPts(); | |
6495 | Standard_Real aPlayDuration = anAnimation->Duration(); | |
bf7b2ceb | 6496 | Standard_Integer aFpsNum = 0; |
6497 | Standard_Integer aFpsDen = 1; | |
1beb58d7 | 6498 | Standard_Boolean isFreeCamera = Standard_False; |
6499 | Standard_Boolean isLockLoop = Standard_False; | |
6500 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6501 | for (; anArgIter < theArgNb; ++anArgIter) | |
197ac94e | 6502 | { |
1beb58d7 | 6503 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
6504 | anArg.LowerCase(); | |
bf7b2ceb | 6505 | // general options |
1beb58d7 | 6506 | if (anArg == "-reset" |
6507 | || anArg == "-clear") | |
197ac94e | 6508 | { |
1beb58d7 | 6509 | anAnimation->Clear(); |
6510 | } | |
6511 | else if (anArg == "-remove" | |
6512 | || anArg == "-del" | |
6513 | || anArg == "-delete") | |
6514 | { | |
6515 | if (!aParentAnimation.IsNull()) | |
6516 | { | |
6517 | ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name()); | |
6518 | } | |
6519 | else | |
6520 | { | |
6521 | aParentAnimation->Remove (anAnimation); | |
6522 | } | |
6523 | } | |
bf7b2ceb | 6524 | // playback options |
1beb58d7 | 6525 | else if (anArg == "-play") |
6526 | { | |
6527 | toPlay = Standard_True; | |
6528 | if (++anArgIter < theArgNb) | |
6529 | { | |
6530 | if (*theArgVec[anArgIter] == '-') | |
6531 | { | |
6532 | --anArgIter; | |
6533 | continue; | |
6534 | } | |
6535 | aPlayStartTime = Draw::Atof (theArgVec[anArgIter]); | |
6536 | ||
6537 | if (++anArgIter < theArgNb) | |
6538 | { | |
6539 | if (*theArgVec[anArgIter] == '-') | |
6540 | { | |
6541 | --anArgIter; | |
6542 | continue; | |
6543 | } | |
6544 | aPlayDuration = Draw::Atof (theArgVec[anArgIter]); | |
6545 | } | |
6546 | } | |
6547 | } | |
6548 | else if (anArg == "-resume") | |
6549 | { | |
6550 | toPlay = Standard_True; | |
6551 | aPlayStartTime = anAnimation->ElapsedTime(); | |
6552 | if (++anArgIter < theArgNb) | |
6553 | { | |
6554 | if (*theArgVec[anArgIter] == '-') | |
6555 | { | |
6556 | --anArgIter; | |
6557 | continue; | |
6558 | } | |
6559 | ||
6560 | aPlayDuration = Draw::Atof (theArgVec[anArgIter]); | |
6561 | } | |
6562 | } | |
6563 | else if (anArg == "-playspeed" | |
6564 | || anArg == "-speed") | |
6565 | { | |
6566 | if (++anArgIter >= theArgNb) | |
6567 | { | |
6568 | std::cout << "Syntax error at " << anArg << ".\n"; | |
6569 | return 1; | |
6570 | } | |
6571 | aPlaySpeed = Draw::Atof (theArgVec[anArgIter]); | |
6572 | } | |
6573 | else if (anArg == "-lock" | |
6574 | || anArg == "-lockloop" | |
6575 | || anArg == "-playlockloop") | |
6576 | { | |
6577 | isLockLoop = Standard_True; | |
6578 | } | |
6579 | else if (anArg == "-freecamera" | |
6580 | || anArg == "-playfreecamera" | |
6581 | || anArg == "-freelook") | |
6582 | { | |
6583 | isFreeCamera = Standard_True; | |
6584 | } | |
6585 | else if (anArg == "-fps") | |
6586 | { | |
6587 | if (++anArgIter >= theArgNb) | |
6588 | { | |
6589 | std::cout << "Syntax error at " << anArg << ".\n"; | |
6590 | return 1; | |
6591 | } | |
bf7b2ceb | 6592 | |
6593 | TCollection_AsciiString aFpsArg (theArgVec[anArgIter]); | |
6594 | Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length()); | |
6595 | if (aSplitIndex == 0) | |
6596 | { | |
6597 | aFpsNum = aFpsArg.IntegerValue(); | |
6598 | } | |
6599 | else | |
6600 | { | |
6601 | const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex); | |
6602 | aFpsArg.Split (aFpsArg.Length() - 1); | |
6603 | const TCollection_AsciiString aNumStr = aFpsArg; | |
6604 | aFpsNum = aNumStr.IntegerValue(); | |
6605 | aFpsDen = aDenStr.IntegerValue(); | |
6606 | if (aFpsDen < 1) | |
6607 | { | |
6608 | std::cout << "Syntax error at " << anArg << ".\n"; | |
6609 | return 1; | |
6610 | } | |
6611 | } | |
1beb58d7 | 6612 | } |
bf7b2ceb | 6613 | // animation definition options |
1beb58d7 | 6614 | else if (anArg == "-start" |
6615 | || anArg == "-starttime" | |
6616 | || anArg == "-startpts") | |
6617 | { | |
6618 | if (++anArgIter >= theArgNb) | |
6619 | { | |
6620 | std::cout << "Syntax error at " << anArg << ".\n"; | |
6621 | return 1; | |
6622 | } | |
6623 | ||
6624 | anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter])); | |
6625 | aRootAnimation->UpdateTotalDuration(); | |
6626 | } | |
6627 | else if (anArg == "-end" | |
6628 | || anArg == "-endtime" | |
6629 | || anArg == "-endpts") | |
6630 | { | |
6631 | if (++anArgIter >= theArgNb) | |
6632 | { | |
6633 | std::cout << "Syntax error at " << anArg << ".\n"; | |
6634 | return 1; | |
6635 | } | |
6636 | ||
6637 | anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts()); | |
6638 | aRootAnimation->UpdateTotalDuration(); | |
6639 | } | |
6640 | else if (anArg == "-dur" | |
6641 | || anArg == "-duration") | |
6642 | { | |
6643 | if (++anArgIter >= theArgNb) | |
6644 | { | |
6645 | std::cout << "Syntax error at " << anArg << ".\n"; | |
6646 | return 1; | |
6647 | } | |
6648 | ||
6649 | anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter])); | |
6650 | aRootAnimation->UpdateTotalDuration(); | |
6651 | } | |
6652 | else if (anArg == "-command" | |
6653 | || anArg == "-cmd" | |
6654 | || anArg == "-invoke" | |
6655 | || anArg == "-eval" | |
6656 | || anArg == "-proc") | |
6657 | { | |
6658 | if (++anArgIter >= theArgNb) | |
6659 | { | |
6660 | std::cout << "Syntax error at " << anArg << ".\n"; | |
6661 | return 1; | |
6662 | } | |
6663 | ||
6664 | Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]); | |
6665 | replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation); | |
6666 | } | |
6667 | else if (anArg == "-objecttrsf" | |
6668 | || anArg == "-objectransformation" | |
6669 | || anArg == "-objtransformation" | |
6670 | || anArg == "-objtrsf" | |
6671 | || anArg == "-object" | |
6672 | || anArg == "-obj") | |
6673 | { | |
6674 | if (++anArgIter >= theArgNb) | |
6675 | { | |
6676 | std::cout << "Syntax error at " << anArg << ".\n"; | |
6677 | return 1; | |
6678 | } | |
6679 | ||
6680 | TCollection_AsciiString anObjName (theArgVec[anArgIter]); | |
6681 | const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS(); | |
6682 | if (!aMapOfAIS.IsBound2 (anObjName)) | |
6683 | { | |
6684 | std::cout << "Syntax error: wrong object name at " << anArg << "\n"; | |
6685 | return 1; | |
6686 | } | |
6687 | ||
6688 | Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (aMapOfAIS.Find2 (anObjName)); | |
6689 | gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() }; | |
6690 | gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() }; | |
6691 | gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() }; | |
6692 | Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() }; | |
6693 | Standard_Boolean isTrsfSet = Standard_False; | |
6694 | Standard_Integer aTrsfArgIter = anArgIter + 1; | |
6695 | for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter) | |
6696 | { | |
6697 | TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]); | |
6698 | aTrsfArg.LowerCase(); | |
6699 | const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1; | |
6700 | if (aTrsfArg.StartsWith ("-rotation") | |
6701 | || aTrsfArg.StartsWith ("-rot")) | |
6702 | { | |
6703 | isTrsfSet = Standard_True; | |
6704 | if (aTrsfArgIter + 4 >= theArgNb | |
6705 | || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex])) | |
6706 | { | |
6707 | std::cout << "Syntax error at " << aTrsfArg << ".\n"; | |
6708 | return 1; | |
6709 | } | |
6710 | aTrsfArgIter += 4; | |
6711 | } | |
6712 | else if (aTrsfArg.StartsWith ("-location") | |
6713 | || aTrsfArg.StartsWith ("-loc")) | |
6714 | { | |
6715 | isTrsfSet = Standard_True; | |
6716 | if (aTrsfArgIter + 3 >= theArgNb | |
6717 | || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex])) | |
6718 | { | |
6719 | std::cout << "Syntax error at " << aTrsfArg << ".\n"; | |
6720 | return 1; | |
6721 | } | |
6722 | aTrsfArgIter += 3; | |
6723 | } | |
6724 | else if (aTrsfArg.StartsWith ("-scale")) | |
6725 | { | |
6726 | isTrsfSet = Standard_True; | |
6727 | if (++aTrsfArgIter >= theArgNb) | |
6728 | { | |
6729 | std::cout << "Syntax error at " << aTrsfArg << ".\n"; | |
6730 | return 1; | |
6731 | } | |
6732 | ||
6733 | const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]); | |
6734 | if (!aScaleStr.IsRealValue()) | |
6735 | { | |
6736 | std::cout << "Syntax error at " << aTrsfArg << ".\n"; | |
6737 | return 1; | |
6738 | } | |
6739 | aScales[anIndex] = aScaleStr.RealValue(); | |
6740 | } | |
6741 | else | |
6742 | { | |
6743 | anArgIter = aTrsfArgIter - 1; | |
6744 | break; | |
6745 | } | |
6746 | } | |
6747 | if (!isTrsfSet) | |
6748 | { | |
6749 | std::cout << "Syntax error at " << anArg << ".\n"; | |
6750 | return 1; | |
6751 | } | |
6752 | else if (aTrsfArgIter >= theArgNb) | |
6753 | { | |
6754 | anArgIter = theArgNb; | |
6755 | } | |
6756 | ||
6757 | aTrsfs[0].SetRotation (aRotQuats[0]); | |
6758 | aTrsfs[1].SetRotation (aRotQuats[1]); | |
6759 | aTrsfs[0].SetTranslationPart (aLocPnts[0]); | |
6760 | aTrsfs[1].SetTranslationPart (aLocPnts[1]); | |
6761 | aTrsfs[0].SetScaleFactor (aScales[0]); | |
6762 | aTrsfs[1].SetScaleFactor (aScales[1]); | |
6763 | ||
6764 | Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]); | |
6765 | replaceAnimation (aParentAnimation, anAnimation, anObjAnimation); | |
6766 | } | |
6767 | else if (anArg == "-viewtrsf" | |
6768 | || anArg == "-view") | |
6769 | { | |
6770 | Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation); | |
6771 | if (aCamAnimation.IsNull()) | |
6772 | { | |
6773 | aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView); | |
6774 | replaceAnimation (aParentAnimation, anAnimation, aCamAnimation); | |
6775 | } | |
6776 | ||
6777 | Handle(Graphic3d_Camera) aCams[2] = | |
6778 | { | |
6779 | new Graphic3d_Camera (aCamAnimation->View()->Camera()), | |
6780 | new Graphic3d_Camera (aCamAnimation->View()->Camera()) | |
6781 | }; | |
6782 | ||
6783 | Standard_Boolean isTrsfSet = Standard_False; | |
6784 | Standard_Integer aViewArgIter = anArgIter + 1; | |
6785 | for (; aViewArgIter < theArgNb; ++aViewArgIter) | |
6786 | { | |
6787 | TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]); | |
6788 | aViewArg.LowerCase(); | |
6789 | const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1; | |
6790 | if (aViewArg.StartsWith ("-scale")) | |
6791 | { | |
6792 | isTrsfSet = Standard_True; | |
6793 | if (++aViewArgIter >= theArgNb) | |
6794 | { | |
6795 | std::cout << "Syntax error at " << anArg << ".\n"; | |
6796 | return 1; | |
6797 | } | |
6798 | ||
6799 | const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]); | |
6800 | if (!aScaleStr.IsRealValue()) | |
6801 | { | |
6802 | std::cout << "Syntax error at " << aViewArg << ".\n"; | |
6803 | return 1; | |
6804 | } | |
6805 | Standard_Real aScale = aScaleStr.RealValue(); | |
6806 | aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale; | |
6807 | aCams[anIndex]->SetScale (aScale); | |
6808 | } | |
6809 | else if (aViewArg.StartsWith ("-eye") | |
6810 | || aViewArg.StartsWith ("-center") | |
6811 | || aViewArg.StartsWith ("-at") | |
6812 | || aViewArg.StartsWith ("-up")) | |
6813 | { | |
6814 | isTrsfSet = Standard_True; | |
6815 | gp_XYZ anXYZ; | |
6816 | if (aViewArgIter + 3 >= theArgNb | |
6817 | || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ)) | |
6818 | { | |
6819 | std::cout << "Syntax error at " << aViewArg << ".\n"; | |
6820 | return 1; | |
6821 | } | |
6822 | aViewArgIter += 3; | |
6823 | ||
6824 | if (aViewArg.StartsWith ("-eye")) | |
6825 | { | |
6826 | aCams[anIndex]->SetEye (anXYZ); | |
6827 | } | |
6828 | else if (aViewArg.StartsWith ("-center") | |
6829 | || aViewArg.StartsWith ("-at")) | |
6830 | { | |
6831 | aCams[anIndex]->SetCenter (anXYZ); | |
6832 | } | |
6833 | else if (aViewArg.StartsWith ("-up")) | |
6834 | { | |
6835 | aCams[anIndex]->SetUp (anXYZ); | |
6836 | } | |
6837 | } | |
6838 | else | |
6839 | { | |
6840 | anArgIter = aViewArgIter - 1; | |
6841 | break; | |
6842 | } | |
6843 | } | |
6844 | if (!isTrsfSet) | |
6845 | { | |
6846 | std::cout << "Syntax error at " << anArg << ".\n"; | |
6847 | return 1; | |
6848 | } | |
6849 | else if (aViewArgIter >= theArgNb) | |
6850 | { | |
6851 | anArgIter = theArgNb; | |
6852 | } | |
6853 | ||
6854 | aCamAnimation->SetCameraStart(aCams[0]); | |
6855 | aCamAnimation->SetCameraEnd (aCams[1]); | |
197ac94e | 6856 | } |
6857 | else | |
6858 | { | |
1beb58d7 | 6859 | std::cout << "Syntax error at " << anArg << ".\n"; |
6860 | return 1; | |
197ac94e | 6861 | } |
6862 | } | |
1beb58d7 | 6863 | |
6864 | if (!toPlay) | |
197ac94e | 6865 | { |
1beb58d7 | 6866 | return 0; |
6867 | } | |
6868 | ||
6869 | // Start animation timeline and process frame updating. | |
6870 | TheIsAnimating = Standard_True; | |
6871 | const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False); | |
6872 | Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera()); | |
bf7b2ceb | 6873 | anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0); |
1beb58d7 | 6874 | if (isFreeCamera) |
6875 | { | |
6876 | aView->Camera()->Copy (aCameraBack); | |
6877 | } | |
6878 | ||
6879 | const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration; | |
bf7b2ceb | 6880 | if (aFpsNum <= 0) |
1beb58d7 | 6881 | { |
6882 | while (!anAnimation->IsStopped()) | |
197ac94e | 6883 | { |
1beb58d7 | 6884 | aCameraBack->Copy (aView->Camera()); |
6885 | const Standard_Real aPts = anAnimation->UpdateTimer(); | |
6886 | if (isFreeCamera) | |
6887 | { | |
6888 | aView->Camera()->Copy (aCameraBack); | |
6889 | } | |
6890 | ||
6891 | if (aPts >= anUpperPts) | |
6892 | { | |
6893 | anAnimation->Pause(); | |
6894 | break; | |
6895 | } | |
6896 | ||
6897 | if (aView->IsInvalidated()) | |
6898 | { | |
6899 | aView->Redraw(); | |
6900 | } | |
6901 | else | |
6902 | { | |
6903 | aView->RedrawImmediate(); | |
6904 | } | |
6905 | ||
6906 | if (!isLockLoop) | |
6907 | { | |
6908 | // handle user events | |
6909 | theDI.Eval ("after 1 set waiter 1"); | |
6910 | theDI.Eval ("vwait waiter"); | |
6911 | } | |
6912 | if (!TheIsAnimating) | |
6913 | { | |
6914 | anAnimation->Pause(); | |
6915 | theDI << aPts; | |
6916 | break; | |
6917 | } | |
6918 | } | |
6919 | ||
6920 | if (aView->IsInvalidated()) | |
6921 | { | |
6922 | aView->Redraw(); | |
197ac94e | 6923 | } |
6924 | else | |
6925 | { | |
1beb58d7 | 6926 | aView->RedrawImmediate(); |
197ac94e | 6927 | } |
6928 | } | |
1beb58d7 | 6929 | else |
197ac94e | 6930 | { |
bf7b2ceb | 6931 | OSD_Timer aPerfTimer; |
6932 | aPerfTimer.Start(); | |
1beb58d7 | 6933 | |
6934 | // Manage frame-rated animation here | |
6935 | Standard_Real aPts = aPlayStartTime; | |
bf7b2ceb | 6936 | int64_t aNbFrames = 0; |
6937 | for (; aPts <= anUpperPts;) | |
197ac94e | 6938 | { |
bf7b2ceb | 6939 | const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aFpsDen) / Standard_Real(aFpsNum)) * Standard_Real(aNbFrames)); |
6940 | aPts = aPlayStartTime + aRecPts; | |
6941 | ++aNbFrames; | |
1beb58d7 | 6942 | if (!anAnimation->Update (aPts)) |
6943 | { | |
6944 | break; | |
6945 | } | |
6946 | ||
1beb58d7 | 6947 | aView->Redraw(); |
197ac94e | 6948 | } |
bf7b2ceb | 6949 | |
6950 | aPerfTimer.Stop(); | |
1beb58d7 | 6951 | anAnimation->Stop(); |
bf7b2ceb | 6952 | const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime(); |
6953 | theDI << "Average FPS: " << aRecFps << "\n" | |
6954 | << "Nb. Frames: " << Standard_Real(aNbFrames); | |
6955 | ||
6956 | aView->Redraw(); | |
197ac94e | 6957 | } |
6958 | ||
1beb58d7 | 6959 | aView->SetImmediateUpdate (wasImmediateUpdate); |
6960 | TheIsAnimating = Standard_False; | |
4754e164 | 6961 | return 0; |
6962 | } | |
6963 | ||
1beb58d7 | 6964 | |
4754e164 | 6965 | //======================================================================= |
6966 | //function : VChangeSelected | |
dc3fe572 | 6967 | //purpose : Adds the shape to selection or remove one from it |
4754e164 | 6968 | //======================================================================= |
6969 | static Standard_Integer VChangeSelected (Draw_Interpretor& di, | |
6970 | Standard_Integer argc, | |
6971 | const char ** argv) | |
6972 | { | |
6973 | if(argc != 2) | |
6974 | { | |
6975 | di<<"Usage : " << argv[0] << " shape \n"; | |
6976 | return 1; | |
6977 | } | |
6978 | //get AIS_Shape: | |
6979 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6980 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
6981 | TCollection_AsciiString aName(argv[1]); | |
6982 | Handle(AIS_InteractiveObject) anAISObject; | |
6983 | ||
6984 | if(!aMap.IsBound2(aName)) | |
6985 | { | |
6986 | di<<"Use 'vdisplay' before"; | |
6987 | return 1; | |
6988 | } | |
6989 | else | |
6990 | { | |
6991 | anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName)); | |
6992 | if(anAISObject.IsNull()){ | |
6993 | di<<"No interactive object \n"; | |
6994 | return 1; | |
6995 | } | |
6996 | ||
0577ae8c | 6997 | aContext->AddOrRemoveSelected(anAISObject, Standard_True); |
4754e164 | 6998 | } |
6999 | return 0; | |
7000 | } | |
7001 | ||
4754e164 | 7002 | //======================================================================= |
7003 | //function : VNbSelected | |
dc3fe572 | 7004 | //purpose : Returns number of selected objects |
4754e164 | 7005 | //======================================================================= |
7006 | static Standard_Integer VNbSelected (Draw_Interpretor& di, | |
7007 | Standard_Integer argc, | |
7008 | const char ** argv) | |
7009 | { | |
7010 | if(argc != 1) | |
7011 | { | |
7012 | di << "Usage : " << argv[0] << "\n"; | |
7013 | return 1; | |
7014 | } | |
7015 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
7016 | if(aContext.IsNull()) | |
7017 | { | |
7018 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
7019 | return 1; | |
7020 | } | |
7021 | di << aContext->NbSelected() << "\n"; | |
7022 | return 0; | |
7023 | } | |
7024 | ||
4754e164 | 7025 | //======================================================================= |
7026 | //function : VPurgeDisplay | |
dc3fe572 | 7027 | //purpose : Switches altialiasing on or off |
4754e164 | 7028 | //======================================================================= |
7029 | static Standard_Integer VPurgeDisplay (Draw_Interpretor& di, | |
7030 | Standard_Integer argc, | |
7031 | const char ** argv) | |
7032 | { | |
eb4320f2 | 7033 | if (argc > 1) |
4754e164 | 7034 | { |
eb4320f2 | 7035 | di << "Usage : " << argv[0] << "\n"; |
4754e164 | 7036 | return 1; |
7037 | } | |
4754e164 | 7038 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
7039 | if (aContext.IsNull()) | |
7040 | { | |
7041 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
7042 | return 1; | |
7043 | } | |
404c8936 | 7044 | |
eb4320f2 | 7045 | di << aContext->PurgeDisplay() << "\n"; |
4754e164 | 7046 | return 0; |
7047 | } | |
7048 | ||
7049 | //======================================================================= | |
7050 | //function : VSetViewSize | |
7051 | //purpose : | |
7052 | //======================================================================= | |
7053 | static Standard_Integer VSetViewSize (Draw_Interpretor& di, | |
7054 | Standard_Integer argc, | |
7055 | const char ** argv) | |
7056 | { | |
7057 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
7058 | if(aContext.IsNull()) | |
7059 | { | |
7060 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
7061 | return 1; | |
7062 | } | |
7063 | if(argc != 2) | |
7064 | { | |
7065 | di<<"Usage : " << argv[0] << " Size\n"; | |
7066 | return 1; | |
7067 | } | |
6b62b2da | 7068 | Standard_Real aSize = Draw::Atof (argv[1]); |
4754e164 | 7069 | if (aSize <= 0.) |
7070 | { | |
7071 | di<<"Bad Size value : " << aSize << "\n"; | |
7072 | return 1; | |
7073 | } | |
7074 | ||
7075 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
7076 | aView->SetSize(aSize); | |
7077 | return 0; | |
7078 | } | |
7079 | ||
7080 | //======================================================================= | |
7081 | //function : VMoveView | |
7082 | //purpose : | |
7083 | //======================================================================= | |
7084 | static Standard_Integer VMoveView (Draw_Interpretor& di, | |
7085 | Standard_Integer argc, | |
7086 | const char ** argv) | |
7087 | { | |
7088 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
7089 | if(aContext.IsNull()) | |
7090 | { | |
7091 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
7092 | return 1; | |
7093 | } | |
7094 | if(argc < 4 || argc > 5) | |
7095 | { | |
7096 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; | |
7097 | return 1; | |
7098 | } | |
6b62b2da | 7099 | Standard_Real Dx = Draw::Atof (argv[1]); |
7100 | Standard_Real Dy = Draw::Atof (argv[2]); | |
7101 | Standard_Real Dz = Draw::Atof (argv[3]); | |
4754e164 | 7102 | Standard_Boolean aStart = Standard_True; |
7103 | if (argc == 5) | |
7104 | { | |
6b62b2da | 7105 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 7106 | } |
7107 | ||
7108 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
7109 | aView->Move(Dx,Dy,Dz,aStart); | |
7110 | return 0; | |
7111 | } | |
7112 | ||
7113 | //======================================================================= | |
7114 | //function : VTranslateView | |
7115 | //purpose : | |
7116 | //======================================================================= | |
7117 | static Standard_Integer VTranslateView (Draw_Interpretor& di, | |
7118 | Standard_Integer argc, | |
7119 | const char ** argv) | |
7120 | { | |
7121 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
7122 | if(aContext.IsNull()) | |
7123 | { | |
7124 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
7125 | return 1; | |
7126 | } | |
7127 | if(argc < 4 || argc > 5) | |
7128 | { | |
7129 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; | |
7130 | return 1; | |
7131 | } | |
6b62b2da | 7132 | Standard_Real Dx = Draw::Atof (argv[1]); |
7133 | Standard_Real Dy = Draw::Atof (argv[2]); | |
7134 | Standard_Real Dz = Draw::Atof (argv[3]); | |
4754e164 | 7135 | Standard_Boolean aStart = Standard_True; |
dc3fe572 | 7136 | if (argc == 5) |
4754e164 | 7137 | { |
6b62b2da | 7138 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 7139 | } |
7140 | ||
7141 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
7142 | aView->Translate(Dx,Dy,Dz,aStart); | |
7143 | return 0; | |
7144 | } | |
7145 | ||
7146 | //======================================================================= | |
7147 | //function : VTurnView | |
7148 | //purpose : | |
7149 | //======================================================================= | |
7150 | static Standard_Integer VTurnView (Draw_Interpretor& di, | |
7151 | Standard_Integer argc, | |
7152 | const char ** argv) | |
7153 | { | |
7154 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
7155 | if(aContext.IsNull()) { | |
7156 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
7157 | return 1; | |
7158 | } | |
7159 | if(argc < 4 || argc > 5){ | |
7160 | di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n"; | |
7161 | return 1; | |
7162 | } | |
6b62b2da | 7163 | Standard_Real Ax = Draw::Atof (argv[1]); |
7164 | Standard_Real Ay = Draw::Atof (argv[2]); | |
7165 | Standard_Real Az = Draw::Atof (argv[3]); | |
4754e164 | 7166 | Standard_Boolean aStart = Standard_True; |
dc3fe572 | 7167 | if (argc == 5) |
4754e164 | 7168 | { |
6b62b2da | 7169 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 7170 | } |
7171 | ||
7172 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
7173 | aView->Turn(Ax,Ay,Az,aStart); | |
7174 | return 0; | |
7175 | } | |
7176 | ||
269294d6 | 7177 | //============================================================================== |
7178 | //function : VTextureEnv | |
7179 | //purpose : ENables or disables environment mapping | |
7180 | //============================================================================== | |
7181 | class OCC_TextureEnv : public Graphic3d_TextureEnv | |
7182 | { | |
7183 | public: | |
7184 | OCC_TextureEnv(const Standard_CString FileName); | |
7185 | OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName); | |
7186 | void SetTextureParameters(const Standard_Boolean theRepeatFlag, | |
7187 | const Standard_Boolean theModulateFlag, | |
7188 | const Graphic3d_TypeOfTextureFilter theFilter, | |
7189 | const Standard_ShortReal theXScale, | |
7190 | const Standard_ShortReal theYScale, | |
7191 | const Standard_ShortReal theXShift, | |
7192 | const Standard_ShortReal theYShift, | |
7193 | const Standard_ShortReal theAngle); | |
68858c7d | 7194 | DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv) |
269294d6 | 7195 | }; |
a3f6f591 | 7196 | DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv) |
ec357c5c | 7197 | |
269294d6 | 7198 | OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName) |
7199 | : Graphic3d_TextureEnv(theFileName) | |
7200 | { | |
7201 | } | |
7202 | ||
7203 | OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId) | |
7204 | : Graphic3d_TextureEnv(theTexId) | |
7205 | { | |
7206 | } | |
7207 | ||
7208 | void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag, | |
7209 | const Standard_Boolean theModulateFlag, | |
7210 | const Graphic3d_TypeOfTextureFilter theFilter, | |
7211 | const Standard_ShortReal theXScale, | |
7212 | const Standard_ShortReal theYScale, | |
7213 | const Standard_ShortReal theXShift, | |
7214 | const Standard_ShortReal theYShift, | |
7215 | const Standard_ShortReal theAngle) | |
7216 | { | |
7217 | myParams->SetRepeat (theRepeatFlag); | |
7218 | myParams->SetModulate (theModulateFlag); | |
7219 | myParams->SetFilter (theFilter); | |
7220 | myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale)); | |
7221 | myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift)); | |
7222 | myParams->SetRotation (theAngle); | |
7223 | } | |
7224 | ||
35e08fe8 | 7225 | static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec) |
269294d6 | 7226 | { |
7227 | // get the active view | |
7228 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
7229 | if (aView.IsNull()) | |
7230 | { | |
7231 | std::cerr << "No active view. Please call vinit.\n"; | |
7232 | return 1; | |
7233 | } | |
7234 | ||
7235 | // Checking the input arguments | |
7236 | Standard_Boolean anEnableFlag = Standard_False; | |
7237 | Standard_Boolean isOk = theArgNb >= 2; | |
7238 | if (isOk) | |
7239 | { | |
7240 | TCollection_AsciiString anEnableOpt(theArgVec[1]); | |
7241 | anEnableFlag = anEnableOpt.IsEqual("on"); | |
7242 | isOk = anEnableFlag || anEnableOpt.IsEqual("off"); | |
7243 | } | |
7244 | if (anEnableFlag) | |
7245 | { | |
7246 | isOk = (theArgNb == 3 || theArgNb == 11); | |
7247 | if (isOk) | |
7248 | { | |
7249 | TCollection_AsciiString aTextureOpt(theArgVec[2]); | |
7250 | isOk = (!aTextureOpt.IsIntegerValue() || | |
7251 | (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN)); | |
7252 | ||
7253 | if (isOk && theArgNb == 11) | |
7254 | { | |
7255 | TCollection_AsciiString aRepeatOpt (theArgVec[3]), | |
7256 | aModulateOpt(theArgVec[4]), | |
7257 | aFilterOpt (theArgVec[5]), | |
7258 | aSScaleOpt (theArgVec[6]), | |
7259 | aTScaleOpt (theArgVec[7]), | |
7260 | aSTransOpt (theArgVec[8]), | |
7261 | aTTransOpt (theArgVec[9]), | |
7262 | anAngleOpt (theArgVec[10]); | |
7263 | isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) && | |
7264 | (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) && | |
7265 | (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) && | |
7266 | aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() && | |
7267 | aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() && | |
7268 | anAngleOpt.IsRealValue()); | |
7269 | } | |
7270 | } | |
7271 | } | |
7272 | ||
7273 | if (!isOk) | |
7274 | { | |
7275 | std::cerr << "Usage :" << std::endl; | |
7276 | std::cerr << theArgVec[0] << " off" << std::endl; | |
7277 | 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; | |
7278 | return 1; | |
7279 | } | |
7280 | ||
7281 | if (anEnableFlag) | |
7282 | { | |
7283 | TCollection_AsciiString aTextureOpt(theArgVec[2]); | |
7284 | Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ? | |
7285 | new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) : | |
7286 | new OCC_TextureEnv(theArgVec[2]); | |
7287 | ||
7288 | if (theArgNb == 11) | |
7289 | { | |
7290 | TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]); | |
7291 | aTexEnv->SetTextureParameters( | |
7292 | aRepeatOpt. IsEqual("repeat"), | |
7293 | aModulateOpt.IsEqual("modulate"), | |
7294 | aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST : | |
7295 | aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR : | |
7296 | Graphic3d_TOTF_TRILINEAR, | |
7297 | (Standard_ShortReal)Draw::Atof(theArgVec[6]), | |
7298 | (Standard_ShortReal)Draw::Atof(theArgVec[7]), | |
7299 | (Standard_ShortReal)Draw::Atof(theArgVec[8]), | |
7300 | (Standard_ShortReal)Draw::Atof(theArgVec[9]), | |
7301 | (Standard_ShortReal)Draw::Atof(theArgVec[10]) | |
7302 | ); | |
7303 | } | |
7304 | aView->SetTextureEnv(aTexEnv); | |
269294d6 | 7305 | } |
7306 | else // Disabling environment mapping | |
7307 | { | |
269294d6 | 7308 | Handle(Graphic3d_TextureEnv) aTexture; |
7309 | aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data | |
7310 | } | |
7311 | ||
7312 | aView->Redraw(); | |
7313 | return 0; | |
7314 | } | |
7315 | ||
3e05329c | 7316 | namespace |
7317 | { | |
7318 | typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes; | |
7319 | ||
7320 | //! Remove registered clipping plane from all views and objects. | |
7321 | static void removePlane (MapOfPlanes& theRegPlanes, | |
7322 | const TCollection_AsciiString& theName) | |
7323 | { | |
7324 | Handle(Graphic3d_ClipPlane) aClipPlane; | |
7325 | if (!theRegPlanes.Find (theName, aClipPlane)) | |
7326 | { | |
7327 | std::cout << "Warning: no such plane.\n"; | |
7328 | return; | |
7329 | } | |
7330 | ||
7331 | theRegPlanes.UnBind (theName); | |
7332 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS()); | |
7333 | anIObjIt.More(); anIObjIt.Next()) | |
7334 | { | |
7335 | Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1()); | |
7336 | aPrs->RemoveClipPlane (aClipPlane); | |
7337 | } | |
7338 | ||
7339 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews); | |
7340 | aViewIt.More(); aViewIt.Next()) | |
7341 | { | |
7342 | const Handle(V3d_View)& aView = aViewIt.Key2(); | |
7343 | aView->RemoveClipPlane(aClipPlane); | |
7344 | } | |
7345 | ||
7346 | ViewerTest::RedrawAllViews(); | |
7347 | } | |
7348 | } | |
7349 | ||
4269bd1b | 7350 | //=============================================================================================== |
7351 | //function : VClipPlane | |
7352 | //purpose : | |
7353 | //=============================================================================================== | |
7354 | static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
7355 | { | |
7356 | // use short-cut for created clip planes map of created (or "registered by name") clip planes | |
4269bd1b | 7357 | static MapOfPlanes aRegPlanes; |
7358 | ||
7359 | if (theArgsNb < 2) | |
7360 | { | |
3e05329c | 7361 | for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next()) |
7362 | { | |
7363 | theDi << aPlaneIter.Key() << " "; | |
7364 | } | |
7365 | return 0; | |
4269bd1b | 7366 | } |
7367 | ||
7368 | TCollection_AsciiString aCommand (theArgVec[1]); | |
3e05329c | 7369 | aCommand.LowerCase(); |
7370 | const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView(); | |
7371 | if (anActiveView.IsNull()) | |
7372 | { | |
7373 | std::cout << "Error: no active view.\n"; | |
7374 | return 1; | |
7375 | } | |
4269bd1b | 7376 | |
7377 | // print maximum number of planes for current viewer | |
3e05329c | 7378 | if (aCommand == "-maxplanes" |
7379 | || aCommand == "maxplanes") | |
4269bd1b | 7380 | { |
3e05329c | 7381 | theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit() |
7382 | << " plane slots provided by driver.\n"; | |
4269bd1b | 7383 | return 0; |
7384 | } | |
7385 | ||
7386 | // create / delete plane instance | |
3e05329c | 7387 | if (aCommand == "-create" |
7388 | || aCommand == "create" | |
7389 | || aCommand == "-delete" | |
7390 | || aCommand == "delete" | |
7391 | || aCommand == "-clone" | |
7392 | || aCommand == "clone") | |
4269bd1b | 7393 | { |
7394 | if (theArgsNb < 3) | |
7395 | { | |
3e05329c | 7396 | std::cout << "Syntax error: plane name is required.\n"; |
4269bd1b | 7397 | return 1; |
7398 | } | |
7399 | ||
3e05329c | 7400 | Standard_Boolean toCreate = aCommand == "-create" |
7401 | || aCommand == "create"; | |
7402 | Standard_Boolean toClone = aCommand == "-clone" | |
7403 | || aCommand == "clone"; | |
7404 | Standard_Boolean toDelete = aCommand == "-delete" | |
7405 | || aCommand == "delete"; | |
4269bd1b | 7406 | TCollection_AsciiString aPlane (theArgVec[2]); |
7407 | ||
7408 | if (toCreate) | |
7409 | { | |
7410 | if (aRegPlanes.IsBound (aPlane)) | |
7411 | { | |
3e05329c | 7412 | std::cout << "Warning: existing plane has been overridden.\n"; |
7413 | toDelete = true; | |
7414 | } | |
7415 | else | |
7416 | { | |
7417 | aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane()); | |
7418 | return 0; | |
4269bd1b | 7419 | } |
4269bd1b | 7420 | } |
7421 | else if (toClone) // toClone | |
7422 | { | |
7423 | if (!aRegPlanes.IsBound (aPlane)) | |
7424 | { | |
3e05329c | 7425 | std::cout << "Error: no such plane.\n"; |
4269bd1b | 7426 | return 1; |
7427 | } | |
3e05329c | 7428 | else if (theArgsNb < 4) |
4269bd1b | 7429 | { |
3e05329c | 7430 | std::cout << "Syntax error: enter name for new plane.\n"; |
4269bd1b | 7431 | return 1; |
7432 | } | |
7433 | ||
7434 | TCollection_AsciiString aClone (theArgVec[3]); | |
7435 | if (aRegPlanes.IsBound (aClone)) | |
7436 | { | |
3e05329c | 7437 | std::cout << "Error: plane name is in use.\n"; |
4269bd1b | 7438 | return 1; |
7439 | } | |
7440 | ||
7441 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); | |
7442 | ||
7443 | aRegPlanes.Bind (aClone, aClipPlane->Clone()); | |
3e05329c | 7444 | return 0; |
4269bd1b | 7445 | } |
4269bd1b | 7446 | |
3e05329c | 7447 | if (toDelete) |
7448 | { | |
7449 | if (aPlane == "ALL" | |
7450 | || aPlane == "all" | |
7451 | || aPlane == "*") | |
4269bd1b | 7452 | { |
3e05329c | 7453 | for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();) |
7454 | { | |
7455 | aPlane = aPlaneIter.Key(); | |
7456 | removePlane (aRegPlanes, aPlane); | |
7457 | aPlaneIter = MapOfPlanes::Iterator (aRegPlanes); | |
7458 | } | |
4269bd1b | 7459 | } |
3e05329c | 7460 | else |
4269bd1b | 7461 | { |
3e05329c | 7462 | removePlane (aRegPlanes, aPlane); |
4269bd1b | 7463 | } |
4269bd1b | 7464 | } |
7465 | ||
3e05329c | 7466 | if (toCreate) |
7467 | { | |
7468 | aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane()); | |
7469 | } | |
4269bd1b | 7470 | return 0; |
7471 | } | |
7472 | ||
7473 | // set / unset plane command | |
3e05329c | 7474 | if (aCommand == "set" |
7475 | || aCommand == "unset") | |
4269bd1b | 7476 | { |
3e05329c | 7477 | if (theArgsNb < 5) |
4269bd1b | 7478 | { |
3e05329c | 7479 | std::cout << "Syntax error: need more arguments.\n"; |
4269bd1b | 7480 | return 1; |
7481 | } | |
7482 | ||
3e05329c | 7483 | // redirect to new syntax |
7484 | NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1); | |
7485 | anArgVec.SetValue (1, theArgVec[0]); | |
7486 | anArgVec.SetValue (2, theArgVec[2]); | |
7487 | anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset"); | |
7488 | for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt) | |
4269bd1b | 7489 | { |
3e05329c | 7490 | anArgVec.SetValue (anIt, theArgVec[anIt]); |
4269bd1b | 7491 | } |
7492 | ||
3e05329c | 7493 | return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst()); |
4269bd1b | 7494 | } |
7495 | ||
7496 | // change plane command | |
3e05329c | 7497 | TCollection_AsciiString aPlaneName; |
7498 | Handle(Graphic3d_ClipPlane) aClipPlane; | |
7499 | Standard_Integer anArgIter = 0; | |
7500 | if (aCommand == "-change" | |
7501 | || aCommand == "change") | |
4269bd1b | 7502 | { |
3e05329c | 7503 | // old syntax support |
7504 | if (theArgsNb < 3) | |
4269bd1b | 7505 | { |
3e05329c | 7506 | std::cout << "Syntax error: need more arguments.\n"; |
4269bd1b | 7507 | return 1; |
7508 | } | |
7509 | ||
3e05329c | 7510 | anArgIter = 3; |
7511 | aPlaneName = theArgVec[2]; | |
7512 | if (!aRegPlanes.Find (aPlaneName, aClipPlane)) | |
4269bd1b | 7513 | { |
3e05329c | 7514 | std::cout << "Error: no such plane '" << aPlaneName << "'.\n"; |
4269bd1b | 7515 | return 1; |
7516 | } | |
3e05329c | 7517 | } |
7518 | else if (aRegPlanes.Find (theArgVec[1], aClipPlane)) | |
7519 | { | |
7520 | anArgIter = 2; | |
7521 | aPlaneName = theArgVec[1]; | |
7522 | } | |
7523 | else | |
7524 | { | |
7525 | anArgIter = 2; | |
7526 | aPlaneName = theArgVec[1]; | |
7527 | aClipPlane = new Graphic3d_ClipPlane(); | |
7528 | aRegPlanes.Bind (aPlaneName, aClipPlane); | |
7529 | theDi << "Created new plane " << aPlaneName << ".\n"; | |
7530 | } | |
4269bd1b | 7531 | |
3e05329c | 7532 | if (theArgsNb - anArgIter < 1) |
7533 | { | |
7534 | std::cout << "Syntax error: need more arguments.\n"; | |
7535 | return 1; | |
7536 | } | |
4269bd1b | 7537 | |
3e05329c | 7538 | for (; anArgIter < theArgsNb; ++anArgIter) |
7539 | { | |
7540 | const char** aChangeArgs = theArgVec + anArgIter; | |
7541 | Standard_Integer aNbChangeArgs = theArgsNb - anArgIter; | |
7542 | TCollection_AsciiString aChangeArg (aChangeArgs[0]); | |
7543 | aChangeArg.LowerCase(); | |
4269bd1b | 7544 | |
3e05329c | 7545 | Standard_Boolean toEnable = Standard_True; |
7546 | if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable)) | |
4269bd1b | 7547 | { |
3e05329c | 7548 | aClipPlane->SetOn (toEnable); |
4269bd1b | 7549 | } |
3e05329c | 7550 | else if (aChangeArg == "-equation" |
7551 | || aChangeArg == "equation") | |
4269bd1b | 7552 | { |
3e05329c | 7553 | if (aNbChangeArgs < 5) |
4269bd1b | 7554 | { |
3e05329c | 7555 | std::cout << "Syntax error: need more arguments.\n"; |
4269bd1b | 7556 | return 1; |
7557 | } | |
7558 | ||
3e05329c | 7559 | Standard_Real aCoeffA = Draw::Atof (aChangeArgs [1]); |
7560 | Standard_Real aCoeffB = Draw::Atof (aChangeArgs [2]); | |
7561 | Standard_Real aCoeffC = Draw::Atof (aChangeArgs [3]); | |
7562 | Standard_Real aCoeffD = Draw::Atof (aChangeArgs [4]); | |
4269bd1b | 7563 | aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD)); |
3e05329c | 7564 | anArgIter += 4; |
4269bd1b | 7565 | } |
3e05329c | 7566 | else if (aChangeArg == "-capping" |
7567 | || aChangeArg == "capping") | |
4269bd1b | 7568 | { |
3e05329c | 7569 | if (aNbChangeArgs < 2) |
4269bd1b | 7570 | { |
3e05329c | 7571 | std::cout << "Syntax error: need more arguments.\n"; |
4269bd1b | 7572 | return 1; |
7573 | } | |
7574 | ||
3e05329c | 7575 | if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) |
4269bd1b | 7576 | { |
3e05329c | 7577 | aClipPlane->SetCapping (toEnable); |
7578 | anArgIter += 1; | |
7579 | } | |
7580 | else | |
7581 | { | |
7582 | // just skip otherwise (old syntax) | |
7583 | } | |
7584 | } | |
7585 | else if (aChangeArg == "-useobjectmaterial" | |
7586 | || aChangeArg == "-useobjectmat" | |
7587 | || aChangeArg == "-useobjmat" | |
7588 | || aChangeArg == "-useobjmaterial") | |
7589 | { | |
7590 | if (aNbChangeArgs < 2) | |
7591 | { | |
7592 | std::cout << "Syntax error: need more arguments.\n"; | |
4269bd1b | 7593 | return 1; |
7594 | } | |
7595 | ||
3e05329c | 7596 | if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) |
4269bd1b | 7597 | { |
3e05329c | 7598 | aClipPlane->SetUseObjectMaterial (toEnable == Standard_True); |
7599 | anArgIter += 1; | |
4269bd1b | 7600 | } |
3e05329c | 7601 | } |
7602 | else if (aChangeArg == "-useobjecttexture" | |
7603 | || aChangeArg == "-useobjecttex" | |
7604 | || aChangeArg == "-useobjtexture" | |
7605 | || aChangeArg == "-useobjtex") | |
7606 | { | |
7607 | if (aNbChangeArgs < 2) | |
4269bd1b | 7608 | { |
3e05329c | 7609 | std::cout << "Syntax error: need more arguments.\n"; |
7610 | return 1; | |
7611 | } | |
4269bd1b | 7612 | |
3e05329c | 7613 | if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) |
7614 | { | |
7615 | aClipPlane->SetUseObjectTexture (toEnable == Standard_True); | |
7616 | anArgIter += 1; | |
7617 | } | |
7618 | } | |
7619 | else if (aChangeArg == "-useobjectshader" | |
7620 | || aChangeArg == "-useobjshader") | |
7621 | { | |
7622 | if (aNbChangeArgs < 2) | |
7623 | { | |
7624 | std::cout << "Syntax error: need more arguments.\n"; | |
7625 | return 1; | |
7626 | } | |
4269bd1b | 7627 | |
3e05329c | 7628 | if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) |
7629 | { | |
7630 | aClipPlane->SetUseObjectShader (toEnable == Standard_True); | |
7631 | anArgIter += 1; | |
4269bd1b | 7632 | } |
3e05329c | 7633 | } |
7634 | else if (aChangeArg == "-color" | |
7635 | || aChangeArg == "color") | |
7636 | { | |
7637 | Quantity_Color aColor; | |
7638 | Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1, | |
7639 | aChangeArgs + 1, | |
7640 | aColor); | |
7641 | if (aNbParsed == 0) | |
4269bd1b | 7642 | { |
3e05329c | 7643 | std::cout << "Syntax error: need more arguments.\n"; |
7644 | return 1; | |
7645 | } | |
4269bd1b | 7646 | |
3e05329c | 7647 | Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial(); |
7648 | aMat.SetAmbientColor (aColor); | |
7649 | aMat.SetDiffuseColor (aColor); | |
7650 | aClipPlane->SetCappingMaterial (aMat); | |
7651 | anArgIter += aNbParsed; | |
7652 | } | |
7653 | else if (aChangeArg == "-texname" | |
7654 | || aChangeArg == "texname") | |
7655 | { | |
7656 | if (aNbChangeArgs < 2) | |
7657 | { | |
7658 | std::cout << "Syntax error: need more arguments.\n"; | |
7659 | return 1; | |
7660 | } | |
4269bd1b | 7661 | |
3e05329c | 7662 | TCollection_AsciiString aTextureName (aChangeArgs[1]); |
7663 | Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName); | |
7664 | if (!aTexture->IsDone()) | |
7665 | { | |
7666 | aClipPlane->SetCappingTexture (NULL); | |
4269bd1b | 7667 | } |
3e05329c | 7668 | else |
4269bd1b | 7669 | { |
3e05329c | 7670 | aTexture->EnableModulate(); |
7671 | aTexture->EnableRepeat(); | |
7672 | aClipPlane->SetCappingTexture (aTexture); | |
7673 | } | |
7674 | anArgIter += 1; | |
7675 | } | |
7676 | else if (aChangeArg == "-texscale" | |
7677 | || aChangeArg == "texscale") | |
7678 | { | |
7679 | if (aClipPlane->CappingTexture().IsNull()) | |
7680 | { | |
7681 | std::cout << "Error: no texture is set.\n"; | |
7682 | return 1; | |
7683 | } | |
4269bd1b | 7684 | |
3e05329c | 7685 | if (aNbChangeArgs < 3) |
7686 | { | |
7687 | std::cout << "Syntax error: need more arguments.\n"; | |
7688 | return 1; | |
7689 | } | |
4269bd1b | 7690 | |
3e05329c | 7691 | Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); |
7692 | Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]); | |
7693 | aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy)); | |
7694 | anArgIter += 2; | |
7695 | } | |
7696 | else if (aChangeArg == "-texorigin" | |
7697 | || aChangeArg == "texorigin") // texture origin | |
7698 | { | |
7699 | if (aClipPlane->CappingTexture().IsNull()) | |
7700 | { | |
7701 | std::cout << "Error: no texture is set.\n"; | |
7702 | return 1; | |
7703 | } | |
4269bd1b | 7704 | |
3e05329c | 7705 | if (aNbChangeArgs < 3) |
7706 | { | |
7707 | std::cout << "Syntax error: need more arguments.\n"; | |
7708 | return 1; | |
4269bd1b | 7709 | } |
3e05329c | 7710 | |
7711 | Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); | |
7712 | Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]); | |
7713 | ||
7714 | aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy)); | |
7715 | anArgIter += 2; | |
7716 | } | |
7717 | else if (aChangeArg == "-texrotate" | |
7718 | || aChangeArg == "texrotate") // texture rotation | |
7719 | { | |
7720 | if (aClipPlane->CappingTexture().IsNull()) | |
4269bd1b | 7721 | { |
3e05329c | 7722 | std::cout << "Error: no texture is set.\n"; |
7723 | return 1; | |
7724 | } | |
4269bd1b | 7725 | |
3e05329c | 7726 | if (aNbChangeArgs < 2) |
7727 | { | |
7728 | std::cout << "Syntax error: need more arguments.\n"; | |
7729 | return 1; | |
7730 | } | |
4269bd1b | 7731 | |
3e05329c | 7732 | Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); |
7733 | aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot); | |
7734 | anArgIter += 1; | |
7735 | } | |
7736 | else if (aChangeArg == "-hatch" | |
7737 | || aChangeArg == "hatch") | |
7738 | { | |
7739 | if (aNbChangeArgs < 2) | |
7740 | { | |
7741 | std::cout << "Syntax error: need more arguments.\n"; | |
7742 | return 1; | |
7743 | } | |
4269bd1b | 7744 | |
3e05329c | 7745 | TCollection_AsciiString aHatchStr (aChangeArgs[1]); |
7746 | aHatchStr.LowerCase(); | |
7747 | if (aHatchStr == "on") | |
7748 | { | |
7749 | aClipPlane->SetCappingHatchOn(); | |
7750 | } | |
7751 | else if (aHatchStr == "off") | |
7752 | { | |
7753 | aClipPlane->SetCappingHatchOff(); | |
4269bd1b | 7754 | } |
3e05329c | 7755 | else |
4269bd1b | 7756 | { |
3e05329c | 7757 | aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1])); |
7758 | } | |
7759 | anArgIter += 1; | |
7760 | } | |
7761 | else if (aChangeArg == "-delete" | |
7762 | || aChangeArg == "delete") | |
7763 | { | |
7764 | removePlane (aRegPlanes, aPlaneName); | |
7765 | return 0; | |
7766 | } | |
7767 | else if (aChangeArg == "-set" | |
7768 | || aChangeArg == "-unset") | |
7769 | { | |
7770 | // set / unset plane command | |
7771 | Standard_Boolean toSet = aChangeArg == "-set"; | |
7772 | Standard_Integer anIt = 1; | |
7773 | for (; anIt < aNbChangeArgs; ++anIt) | |
7774 | { | |
7775 | TCollection_AsciiString anEntityName (aChangeArgs[anIt]); | |
7776 | if (anEntityName.IsEmpty() | |
7777 | || anEntityName.Value (1) == '-') | |
4269bd1b | 7778 | { |
3e05329c | 7779 | break; |
4269bd1b | 7780 | } |
3e05329c | 7781 | else if (ViewerTest_myViews.IsBound1 (anEntityName)) |
4269bd1b | 7782 | { |
3e05329c | 7783 | Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName); |
7784 | if (toSet) | |
7785 | { | |
7786 | aView->AddClipPlane (aClipPlane); | |
7787 | } | |
7788 | else | |
7789 | { | |
7790 | aView->RemoveClipPlane (aClipPlane); | |
7791 | } | |
7792 | continue; | |
4269bd1b | 7793 | } |
3e05329c | 7794 | else if (GetMapOfAIS().IsBound2 (anEntityName)) |
4269bd1b | 7795 | { |
3e05329c | 7796 | Handle(AIS_InteractiveObject) aIObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName)); |
7797 | if (toSet) | |
7798 | { | |
7799 | aIObj->AddClipPlane (aClipPlane); | |
7800 | } | |
7801 | else | |
7802 | { | |
7803 | aIObj->RemoveClipPlane (aClipPlane); | |
7804 | } | |
4269bd1b | 7805 | } |
3e05329c | 7806 | else |
4269bd1b | 7807 | { |
3e05329c | 7808 | std::cout << "Error: object/view '" << anEntityName << "' is not found!\n"; |
7809 | return 1; | |
4269bd1b | 7810 | } |
3e05329c | 7811 | } |
7812 | ||
7813 | if (anIt == 1) | |
7814 | { | |
7815 | // apply to active view | |
7816 | if (toSet) | |
4269bd1b | 7817 | { |
3e05329c | 7818 | anActiveView->AddClipPlane (aClipPlane); |
4269bd1b | 7819 | } |
7820 | else | |
7821 | { | |
3e05329c | 7822 | anActiveView->RemoveClipPlane (aClipPlane); |
4269bd1b | 7823 | } |
7824 | } | |
3e05329c | 7825 | else |
7826 | { | |
7827 | anArgIter = anArgIter + anIt - 1; | |
7828 | } | |
7829 | } | |
7830 | else | |
7831 | { | |
7832 | std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n"; | |
7833 | return 1; | |
4269bd1b | 7834 | } |
4269bd1b | 7835 | } |
7836 | ||
3e05329c | 7837 | ViewerTest::RedrawAllViews(); |
7838 | return 0; | |
4269bd1b | 7839 | } |
7840 | ||
b5ac8292 | 7841 | //=============================================================================================== |
7842 | //function : VZRange | |
7843 | //purpose : | |
7844 | //=============================================================================================== | |
7845 | static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
7846 | { | |
197ac94e | 7847 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
7848 | ||
7849 | if (aCurrentView.IsNull()) | |
b5ac8292 | 7850 | { |
197ac94e | 7851 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; |
b5ac8292 | 7852 | return 1; |
7853 | } | |
7854 | ||
197ac94e | 7855 | Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera(); |
b5ac8292 | 7856 | |
7857 | if (theArgsNb < 2) | |
7858 | { | |
7859 | theDi << "ZNear: " << aCamera->ZNear() << "\n"; | |
7860 | theDi << "ZFar: " << aCamera->ZFar() << "\n"; | |
7861 | return 0; | |
7862 | } | |
7863 | ||
7864 | if (theArgsNb == 3) | |
7865 | { | |
6b62b2da | 7866 | Standard_Real aNewZNear = Draw::Atof (theArgVec[1]); |
7867 | Standard_Real aNewZFar = Draw::Atof (theArgVec[2]); | |
197ac94e | 7868 | |
7869 | if (aNewZNear >= aNewZFar) | |
7870 | { | |
7871 | std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n"; | |
7872 | return 1; | |
7873 | } | |
7874 | ||
7875 | if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0)) | |
7876 | { | |
7877 | std::cout << theArgVec[0] << ": invalid arguments: "; | |
7878 | std::cout << "znear, zfar should be positive for perspective camera.\n"; | |
7879 | return 1; | |
7880 | } | |
7881 | ||
7882 | aCamera->SetZRange (aNewZNear, aNewZFar); | |
b5ac8292 | 7883 | } |
7884 | else | |
7885 | { | |
197ac94e | 7886 | std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n"; |
b5ac8292 | 7887 | return 1; |
7888 | } | |
7889 | ||
197ac94e | 7890 | aCurrentView->Redraw(); |
7891 | ||
b5ac8292 | 7892 | return 0; |
7893 | } | |
7894 | ||
7895 | //=============================================================================================== | |
7896 | //function : VAutoZFit | |
7897 | //purpose : | |
7898 | //=============================================================================================== | |
7899 | static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
7900 | { | |
197ac94e | 7901 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
7902 | ||
7903 | if (aCurrentView.IsNull()) | |
b5ac8292 | 7904 | { |
197ac94e | 7905 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; |
b5ac8292 | 7906 | return 1; |
7907 | } | |
7908 | ||
c357e426 | 7909 | Standard_Real aScale = aCurrentView->AutoZFitScaleFactor(); |
197ac94e | 7910 | |
7911 | if (theArgsNb > 3) | |
b5ac8292 | 7912 | { |
197ac94e | 7913 | std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n"; |
7914 | return 1; | |
b5ac8292 | 7915 | } |
7916 | ||
197ac94e | 7917 | if (theArgsNb < 2) |
b5ac8292 | 7918 | { |
586db386 | 7919 | theDi << "Auto z-fit mode: \n" |
c357e426 | 7920 | << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n" |
197ac94e | 7921 | << "Scale: " << aScale << "\n"; |
7922 | return 0; | |
b5ac8292 | 7923 | } |
197ac94e | 7924 | |
7925 | Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1; | |
7926 | ||
7927 | if (theArgsNb >= 3) | |
b5ac8292 | 7928 | { |
197ac94e | 7929 | aScale = Draw::Atoi (theArgVec[2]); |
b5ac8292 | 7930 | } |
7931 | ||
c357e426 | 7932 | aCurrentView->SetAutoZFitMode (isOn, aScale); |
7933 | aCurrentView->AutoZFit(); | |
197ac94e | 7934 | aCurrentView->Redraw(); |
7935 | ||
b5ac8292 | 7936 | return 0; |
7937 | } | |
7938 | ||
6b62b2da | 7939 | //! Auxiliary function to print projection type |
7940 | inline const char* projTypeName (Graphic3d_Camera::Projection theProjType) | |
7941 | { | |
7942 | switch (theProjType) | |
7943 | { | |
7944 | case Graphic3d_Camera::Projection_Orthographic: return "orthographic"; | |
7945 | case Graphic3d_Camera::Projection_Perspective: return "perspective"; | |
7946 | case Graphic3d_Camera::Projection_Stereo: return "stereoscopic"; | |
7947 | case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye"; | |
7948 | case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye"; | |
7949 | } | |
7950 | return "UNKNOWN"; | |
7951 | } | |
7952 | ||
b5ac8292 | 7953 | //=============================================================================================== |
6b62b2da | 7954 | //function : VCamera |
b5ac8292 | 7955 | //purpose : |
7956 | //=============================================================================================== | |
6b62b2da | 7957 | static int VCamera (Draw_Interpretor& theDI, |
7958 | Standard_Integer theArgsNb, | |
7959 | const char** theArgVec) | |
b5ac8292 | 7960 | { |
6b62b2da | 7961 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
7962 | if (aView.IsNull()) | |
b5ac8292 | 7963 | { |
6b62b2da | 7964 | std::cout << "Error: no active view.\n"; |
b5ac8292 | 7965 | return 1; |
7966 | } | |
7967 | ||
6b62b2da | 7968 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); |
7969 | if (theArgsNb < 2) | |
b5ac8292 | 7970 | { |
6b62b2da | 7971 | theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n"; |
7972 | theDI << "FOVy: " << aCamera->FOVy() << "\n"; | |
7973 | theDI << "Distance: " << aCamera->Distance() << "\n"; | |
7974 | theDI << "IOD: " << aCamera->IOD() << "\n"; | |
7975 | theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n"; | |
7976 | theDI << "ZFocus: " << aCamera->ZFocus() << "\n"; | |
7977 | theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n"; | |
7978 | return 0; | |
b5ac8292 | 7979 | } |
7980 | ||
6b62b2da | 7981 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) |
b5ac8292 | 7982 | { |
6b62b2da | 7983 | Standard_CString anArg = theArgVec[anArgIter]; |
7984 | TCollection_AsciiString anArgCase (anArg); | |
7985 | anArgCase.LowerCase(); | |
7986 | if (anArgCase == "-proj" | |
7987 | || anArgCase == "-projection" | |
7988 | || anArgCase == "-projtype" | |
7989 | || anArgCase == "-projectiontype") | |
7990 | { | |
7991 | theDI << projTypeName (aCamera->ProjectionType()) << " "; | |
7992 | } | |
7993 | else if (anArgCase == "-ortho" | |
7994 | || anArgCase == "-orthographic") | |
b5ac8292 | 7995 | { |
7996 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic); | |
6b62b2da | 7997 | } |
7998 | else if (anArgCase == "-persp" | |
7999 | || anArgCase == "-perspective" | |
8000 | || anArgCase == "-perspmono" | |
8001 | || anArgCase == "-perspectivemono" | |
8002 | || anArgCase == "-mono") | |
b5ac8292 | 8003 | { |
8004 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective); | |
8005 | } | |
6b62b2da | 8006 | else if (anArgCase == "-stereo" |
8007 | || anArgCase == "-stereoscopic" | |
8008 | || anArgCase == "-perspstereo" | |
8009 | || anArgCase == "-perspectivestereo") | |
8010 | { | |
8011 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo); | |
8012 | } | |
8013 | else if (anArgCase == "-left" | |
8014 | || anArgCase == "-lefteye" | |
8015 | || anArgCase == "-monoleft" | |
8016 | || anArgCase == "-monolefteye" | |
8017 | || anArgCase == "-perpsleft" | |
8018 | || anArgCase == "-perpslefteye") | |
b5ac8292 | 8019 | { |
8020 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye); | |
8021 | } | |
6b62b2da | 8022 | else if (anArgCase == "-right" |
8023 | || anArgCase == "-righteye" | |
8024 | || anArgCase == "-monoright" | |
8025 | || anArgCase == "-monorighteye" | |
8026 | || anArgCase == "-perpsright") | |
b5ac8292 | 8027 | { |
8028 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye); | |
8029 | } | |
6b62b2da | 8030 | else if (anArgCase == "-dist" |
8031 | || anArgCase == "-distance") | |
b5ac8292 | 8032 | { |
6b62b2da | 8033 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
8034 | if (anArgValue != NULL | |
8035 | && *anArgValue != '-') | |
8036 | { | |
8037 | ++anArgIter; | |
8038 | aCamera->SetDistance (Draw::Atof (anArgValue)); | |
8039 | continue; | |
8040 | } | |
8041 | theDI << aCamera->Distance() << " "; | |
b5ac8292 | 8042 | } |
6b62b2da | 8043 | else if (anArgCase == "-iod") |
b5ac8292 | 8044 | { |
6b62b2da | 8045 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
8046 | if (anArgValue != NULL | |
8047 | && *anArgValue != '-') | |
8048 | { | |
8049 | ++anArgIter; | |
8050 | aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue)); | |
8051 | continue; | |
8052 | } | |
8053 | theDI << aCamera->IOD() << " "; | |
b5ac8292 | 8054 | } |
6b62b2da | 8055 | else if (anArgCase == "-iodtype") |
b5ac8292 | 8056 | { |
6b62b2da | 8057 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : ""; |
8058 | TCollection_AsciiString anValueCase (anArgValue); | |
8059 | anValueCase.LowerCase(); | |
8060 | if (anValueCase == "abs" | |
8061 | || anValueCase == "absolute") | |
8062 | { | |
8063 | ++anArgIter; | |
8064 | aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD()); | |
8065 | continue; | |
8066 | } | |
8067 | else if (anValueCase == "rel" | |
8068 | || anValueCase == "relative") | |
8069 | { | |
8070 | ++anArgIter; | |
8071 | aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD()); | |
8072 | continue; | |
8073 | } | |
8074 | else if (*anArgValue != '-') | |
8075 | { | |
8076 | std::cout << "Error: unknown IOD type '" << anArgValue << "'\n"; | |
8077 | return 1; | |
8078 | } | |
8079 | switch (aCamera->GetIODType()) | |
8080 | { | |
8081 | case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break; | |
8082 | case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break; | |
8083 | } | |
b5ac8292 | 8084 | } |
6b62b2da | 8085 | else if (anArgCase == "-zfocus") |
b5ac8292 | 8086 | { |
6b62b2da | 8087 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
8088 | if (anArgValue != NULL | |
8089 | && *anArgValue != '-') | |
8090 | { | |
8091 | ++anArgIter; | |
8092 | aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue)); | |
8093 | continue; | |
8094 | } | |
8095 | theDI << aCamera->ZFocus() << " "; | |
b5ac8292 | 8096 | } |
6b62b2da | 8097 | else if (anArgCase == "-zfocustype") |
b5ac8292 | 8098 | { |
6b62b2da | 8099 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : ""; |
8100 | TCollection_AsciiString anValueCase (anArgValue); | |
8101 | anValueCase.LowerCase(); | |
8102 | if (anValueCase == "abs" | |
8103 | || anValueCase == "absolute") | |
8104 | { | |
8105 | ++anArgIter; | |
8106 | aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus()); | |
8107 | continue; | |
8108 | } | |
8109 | else if (anValueCase == "rel" | |
8110 | || anValueCase == "relative") | |
8111 | { | |
8112 | ++anArgIter; | |
8113 | aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus()); | |
8114 | continue; | |
8115 | } | |
8116 | else if (*anArgValue != '-') | |
8117 | { | |
8118 | std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n"; | |
8119 | return 1; | |
8120 | } | |
8121 | switch (aCamera->ZFocusType()) | |
8122 | { | |
8123 | case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break; | |
8124 | case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break; | |
8125 | } | |
8126 | } | |
8127 | else if (anArgCase == "-fov" | |
8128 | || anArgCase == "-fovy") | |
b5ac8292 | 8129 | { |
6b62b2da | 8130 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
8131 | if (anArgValue != NULL | |
8132 | && *anArgValue != '-') | |
8133 | { | |
8134 | ++anArgIter; | |
8135 | aCamera->SetFOVy (Draw::Atof (anArgValue)); | |
8136 | continue; | |
8137 | } | |
8138 | theDI << aCamera->FOVy() << " "; | |
b5ac8292 | 8139 | } |
8140 | else | |
8141 | { | |
6b62b2da | 8142 | std::cout << "Error: unknown argument '" << anArg << "'\n"; |
b5ac8292 | 8143 | return 1; |
8144 | } | |
8145 | } | |
b5ac8292 | 8146 | |
c357e426 | 8147 | aView->AutoZFit(); |
6b62b2da | 8148 | aView->Redraw(); |
b5ac8292 | 8149 | |
8150 | return 0; | |
8151 | } | |
8152 | ||
f978241f | 8153 | //! Parse stereo output mode |
8154 | inline Standard_Boolean parseStereoMode (Standard_CString theArg, | |
8155 | Graphic3d_StereoMode& theMode) | |
8156 | { | |
8157 | TCollection_AsciiString aFlag (theArg); | |
8158 | aFlag.LowerCase(); | |
8159 | if (aFlag == "quadbuffer") | |
8160 | { | |
8161 | theMode = Graphic3d_StereoMode_QuadBuffer; | |
8162 | } | |
8163 | else if (aFlag == "anaglyph") | |
8164 | { | |
8165 | theMode = Graphic3d_StereoMode_Anaglyph; | |
8166 | } | |
8167 | else if (aFlag == "row" | |
8168 | || aFlag == "rowinterlaced") | |
8169 | { | |
8170 | theMode = Graphic3d_StereoMode_RowInterlaced; | |
8171 | } | |
8172 | else if (aFlag == "col" | |
8173 | || aFlag == "colinterlaced" | |
8174 | || aFlag == "columninterlaced") | |
8175 | { | |
8176 | theMode = Graphic3d_StereoMode_ColumnInterlaced; | |
8177 | } | |
8178 | else if (aFlag == "chess" | |
8179 | || aFlag == "chessboard") | |
8180 | { | |
8181 | theMode = Graphic3d_StereoMode_ChessBoard; | |
8182 | } | |
8183 | else if (aFlag == "sbs" | |
8184 | || aFlag == "sidebyside") | |
8185 | { | |
8186 | theMode = Graphic3d_StereoMode_SideBySide; | |
8187 | } | |
8188 | else if (aFlag == "ou" | |
8189 | || aFlag == "overunder") | |
8190 | { | |
8191 | theMode = Graphic3d_StereoMode_OverUnder; | |
8192 | } | |
8193 | else if (aFlag == "pageflip" | |
8194 | || aFlag == "softpageflip") | |
8195 | { | |
8196 | theMode = Graphic3d_StereoMode_SoftPageFlip; | |
8197 | } | |
8198 | else | |
8199 | { | |
8200 | return Standard_False; | |
8201 | } | |
8202 | return Standard_True; | |
8203 | } | |
8204 | ||
8205 | //! Parse anaglyph filter | |
8206 | inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg, | |
8207 | Graphic3d_RenderingParams::Anaglyph& theFilter) | |
8208 | { | |
8209 | TCollection_AsciiString aFlag (theArg); | |
8210 | aFlag.LowerCase(); | |
8211 | if (aFlag == "redcyansimple") | |
8212 | { | |
8213 | theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple; | |
8214 | } | |
8215 | else if (aFlag == "redcyan" | |
8216 | || aFlag == "redcyanoptimized") | |
8217 | { | |
8218 | theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized; | |
8219 | } | |
8220 | else if (aFlag == "yellowbluesimple") | |
8221 | { | |
8222 | theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple; | |
8223 | } | |
8224 | else if (aFlag == "yellowblue" | |
8225 | || aFlag == "yellowblueoptimized") | |
8226 | { | |
8227 | theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized; | |
8228 | } | |
8229 | else if (aFlag == "greenmagenta" | |
8230 | || aFlag == "greenmagentasimple") | |
8231 | { | |
8232 | theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple; | |
8233 | } | |
8234 | else | |
8235 | { | |
8236 | return Standard_False; | |
8237 | } | |
8238 | return Standard_True; | |
8239 | } | |
8240 | ||
b5ac8292 | 8241 | //============================================================================== |
8242 | //function : VStereo | |
8243 | //purpose : | |
8244 | //============================================================================== | |
8245 | ||
8246 | static int VStereo (Draw_Interpretor& theDI, | |
8247 | Standard_Integer theArgNb, | |
8248 | const char** theArgVec) | |
8249 | { | |
f978241f | 8250 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
b5ac8292 | 8251 | if (theArgNb < 2) |
8252 | { | |
b5ac8292 | 8253 | if (aView.IsNull()) |
8254 | { | |
f978241f | 8255 | std::cout << "Error: no active viewer!\n"; |
b5ac8292 | 8256 | return 0; |
8257 | } | |
8258 | ||
8259 | Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo; | |
8260 | theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n"; | |
bf02aa7d | 8261 | if (isActive) |
8262 | { | |
8263 | TCollection_AsciiString aMode; | |
8264 | switch (aView->RenderingParams().StereoMode) | |
8265 | { | |
8266 | case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break; | |
8267 | case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break; | |
8268 | case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break; | |
8269 | case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break; | |
8270 | case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break; | |
8271 | case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break; | |
8272 | case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break; | |
8273 | case Graphic3d_StereoMode_Anaglyph : | |
8274 | aMode = "anaglyph"; | |
8275 | switch (aView->RenderingParams().AnaglyphFilter) | |
8276 | { | |
8277 | case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break; | |
8278 | case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break; | |
8279 | case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break; | |
8280 | case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break; | |
8281 | case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break; | |
8282 | default: break; | |
8283 | } | |
8284 | default: break; | |
8285 | } | |
8286 | theDI << "Mode " << aMode << "\n"; | |
8287 | } | |
b5ac8292 | 8288 | return 0; |
8289 | } | |
8290 | ||
f978241f | 8291 | Handle(Graphic3d_Camera) aCamera; |
8292 | Graphic3d_RenderingParams* aParams = NULL; | |
8293 | Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer; | |
8294 | if (!aView.IsNull()) | |
8295 | { | |
8296 | aParams = &aView->ChangeRenderingParams(); | |
8297 | aMode = aParams->StereoMode; | |
8298 | aCamera = aView->Camera(); | |
8299 | } | |
8300 | ||
8301 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); | |
8302 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
8303 | { | |
8304 | Standard_CString anArg = theArgVec[anArgIter]; | |
8305 | TCollection_AsciiString aFlag (anArg); | |
8306 | aFlag.LowerCase(); | |
8307 | if (anUpdateTool.parseRedrawMode (aFlag)) | |
8308 | { | |
8309 | continue; | |
8310 | } | |
8311 | else if (aFlag == "0" | |
8312 | || aFlag == "off") | |
8313 | { | |
8314 | if (++anArgIter < theArgNb) | |
8315 | { | |
8316 | std::cout << "Error: wrong number of arguments!\n"; | |
8317 | return 1; | |
8318 | } | |
8319 | ||
8320 | if (!aCamera.IsNull() | |
8321 | && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo) | |
8322 | { | |
8323 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective); | |
8324 | } | |
8325 | ViewerTest_myDefaultCaps.contextStereo = Standard_False; | |
8326 | return 0; | |
8327 | } | |
8328 | else if (aFlag == "1" | |
8329 | || aFlag == "on") | |
8330 | { | |
8331 | if (++anArgIter < theArgNb) | |
8332 | { | |
8333 | std::cout << "Error: wrong number of arguments!\n"; | |
8334 | return 1; | |
8335 | } | |
8336 | ||
8337 | if (!aCamera.IsNull()) | |
8338 | { | |
8339 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo); | |
8340 | } | |
8341 | ViewerTest_myDefaultCaps.contextStereo = Standard_True; | |
8342 | return 0; | |
8343 | } | |
8344 | else if (aFlag == "-reverse" | |
8345 | || aFlag == "-reversed" | |
8346 | || aFlag == "-swap") | |
8347 | { | |
8348 | Standard_Boolean toEnable = Standard_True; | |
8349 | if (++anArgIter < theArgNb | |
a5565a3c | 8350 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
f978241f | 8351 | { |
8352 | --anArgIter; | |
8353 | } | |
8354 | aParams->ToReverseStereo = toEnable; | |
8355 | } | |
8356 | else if (aFlag == "-noreverse" | |
8357 | || aFlag == "-noswap") | |
8358 | { | |
8359 | Standard_Boolean toDisable = Standard_True; | |
8360 | if (++anArgIter < theArgNb | |
a5565a3c | 8361 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable)) |
f978241f | 8362 | { |
8363 | --anArgIter; | |
8364 | } | |
8365 | aParams->ToReverseStereo = !toDisable; | |
8366 | } | |
8367 | else if (aFlag == "-mode" | |
8368 | || aFlag == "-stereomode") | |
8369 | { | |
8370 | if (++anArgIter >= theArgNb | |
8371 | || !parseStereoMode (theArgVec[anArgIter], aMode)) | |
8372 | { | |
8373 | std::cout << "Error: syntax error at '" << anArg << "'\n"; | |
8374 | return 1; | |
8375 | } | |
8376 | ||
8377 | if (aMode == Graphic3d_StereoMode_QuadBuffer) | |
8378 | { | |
8379 | ViewerTest_myDefaultCaps.contextStereo = Standard_True; | |
8380 | } | |
8381 | } | |
8382 | else if (aFlag == "-anaglyph" | |
8383 | || aFlag == "-anaglyphfilter") | |
8384 | { | |
8385 | Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple; | |
8386 | if (++anArgIter >= theArgNb | |
8387 | || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter)) | |
8388 | { | |
8389 | std::cout << "Error: syntax error at '" << anArg << "'\n"; | |
8390 | return 1; | |
8391 | } | |
8392 | ||
8393 | aMode = Graphic3d_StereoMode_Anaglyph; | |
8394 | aParams->AnaglyphFilter = aFilter; | |
8395 | } | |
8396 | else if (parseStereoMode (anArg, aMode)) // short syntax | |
8397 | { | |
8398 | if (aMode == Graphic3d_StereoMode_QuadBuffer) | |
8399 | { | |
8400 | ViewerTest_myDefaultCaps.contextStereo = Standard_True; | |
8401 | } | |
8402 | } | |
8403 | else | |
8404 | { | |
8405 | std::cout << "Error: syntax error at '" << anArg << "'\n"; | |
8406 | return 1; | |
8407 | } | |
8408 | } | |
8409 | ||
8410 | if (!aView.IsNull()) | |
8411 | { | |
8412 | aParams->StereoMode = aMode; | |
8413 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo); | |
8414 | } | |
b5ac8292 | 8415 | return 0; |
8416 | } | |
8417 | ||
392ac980 | 8418 | //=============================================================================================== |
8419 | //function : VDefaults | |
8420 | //purpose : | |
8421 | //=============================================================================================== | |
8422 | static int VDefaults (Draw_Interpretor& theDi, | |
8423 | Standard_Integer theArgsNb, | |
8424 | const char** theArgVec) | |
8425 | { | |
8426 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); | |
8427 | if (aCtx.IsNull()) | |
8428 | { | |
8429 | std::cerr << "No active viewer!\n"; | |
8430 | return 1; | |
8431 | } | |
8432 | ||
8433 | Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer(); | |
8434 | if (theArgsNb < 2) | |
8435 | { | |
8436 | if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE) | |
8437 | { | |
8438 | theDi << "DeflType: relative\n" | |
8439 | << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n"; | |
8440 | } | |
8441 | else | |
8442 | { | |
8443 | theDi << "DeflType: absolute\n" | |
8444 | << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n"; | |
8445 | } | |
8446 | theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n"; | |
4c513386 | 8447 | theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n"; |
392ac980 | 8448 | return 0; |
8449 | } | |
8450 | ||
8451 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
8452 | { | |
8453 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
4c513386 | 8454 | anArg.UpperCase(); |
8455 | if (anArg == "-ABSDEFL" | |
8456 | || anArg == "-ABSOLUTEDEFLECTION" | |
8457 | || anArg == "-DEFL" | |
8458 | || anArg == "-DEFLECTION") | |
392ac980 | 8459 | { |
4c513386 | 8460 | if (++anArgIter >= theArgsNb) |
8461 | { | |
8462 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
8463 | return 1; | |
8464 | } | |
392ac980 | 8465 | aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE); |
4c513386 | 8466 | aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter])); |
392ac980 | 8467 | } |
4c513386 | 8468 | else if (anArg == "-RELDEFL" |
8469 | || anArg == "-RELATIVEDEFLECTION" | |
8470 | || anArg == "-DEVCOEFF" | |
8471 | || anArg == "-DEVIATIONCOEFF" | |
8472 | || anArg == "-DEVIATIONCOEFFICIENT") | |
392ac980 | 8473 | { |
4c513386 | 8474 | if (++anArgIter >= theArgsNb) |
8475 | { | |
8476 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
8477 | return 1; | |
8478 | } | |
392ac980 | 8479 | aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE); |
4c513386 | 8480 | aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter])); |
392ac980 | 8481 | } |
4c513386 | 8482 | else if (anArg == "-ANGDEFL" |
8483 | || anArg == "-ANGULARDEFL" | |
8484 | || anArg == "-ANGULARDEFLECTION") | |
392ac980 | 8485 | { |
4c513386 | 8486 | if (++anArgIter >= theArgsNb) |
8487 | { | |
8488 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
8489 | return 1; | |
8490 | } | |
392ac980 | 8491 | // currently HLRDeviationAngle is used instead of DeviationAngle in most places |
4c513386 | 8492 | aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0); |
8493 | } | |
385c43e7 | 8494 | else if (anArg == "-AUTOTR" |
8495 | || anArg == "-AUTOTRIANG" | |
8496 | || anArg == "-AUTOTRIANGULATION") | |
4c513386 | 8497 | { |
8498 | if (++anArgIter >= theArgsNb) | |
8499 | { | |
8500 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
8501 | return 1; | |
8502 | } | |
8503 | TCollection_AsciiString aValue (theArgVec[anArgIter]); | |
8504 | aValue.LowerCase(); | |
8505 | if (aValue == "on" | |
8506 | || aValue == "1") | |
8507 | { | |
8508 | aDefParams->SetAutoTriangulation (Standard_True); | |
8509 | } | |
8510 | else if (aValue == "off" | |
8511 | || aValue == "0") | |
8512 | { | |
8513 | aDefParams->SetAutoTriangulation (Standard_False); | |
8514 | } | |
392ac980 | 8515 | } |
8516 | else | |
8517 | { | |
8518 | std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n"; | |
8519 | } | |
8520 | } | |
8521 | ||
8522 | return 0; | |
8523 | } | |
8524 | ||
12381341 | 8525 | //! Auxiliary method |
8526 | inline void addLight (const Handle(V3d_Light)& theLightNew, | |
8527 | const Standard_Boolean theIsGlobal) | |
8528 | { | |
8529 | if (theLightNew.IsNull()) | |
8530 | { | |
8531 | return; | |
8532 | } | |
8533 | ||
8534 | if (theIsGlobal) | |
8535 | { | |
8536 | ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew); | |
8537 | } | |
8538 | else | |
8539 | { | |
8540 | ViewerTest::CurrentView()->SetLightOn (theLightNew); | |
8541 | } | |
8542 | } | |
8543 | ||
8544 | //! Auxiliary method | |
8545 | inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext) | |
8546 | { | |
8547 | TCollection_AsciiString anArgNextCase (theArgNext); | |
8548 | anArgNextCase.UpperCase(); | |
8549 | if (anArgNextCase.Length() > 5 | |
8550 | && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT")) | |
8551 | { | |
8552 | return theArgNext.SubString (6, theArgNext.Length()).IntegerValue(); | |
8553 | } | |
8554 | else | |
8555 | { | |
8556 | return theArgNext.IntegerValue(); | |
8557 | } | |
8558 | } | |
8559 | ||
8560 | //=============================================================================================== | |
8561 | //function : VLight | |
8562 | //purpose : | |
8563 | //=============================================================================================== | |
8564 | static int VLight (Draw_Interpretor& theDi, | |
8565 | Standard_Integer theArgsNb, | |
8566 | const char** theArgVec) | |
8567 | { | |
8568 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
8569 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
8570 | if (aView.IsNull() | |
8571 | || aViewer.IsNull()) | |
8572 | { | |
8573 | std::cerr << "No active viewer!\n"; | |
8574 | return 1; | |
8575 | } | |
8576 | ||
8577 | Standard_Real anXYZ[3]; | |
8578 | Quantity_Coefficient anAtten[2]; | |
8579 | if (theArgsNb < 2) | |
8580 | { | |
8581 | // print lights info | |
8582 | Standard_Integer aLightId = 0; | |
6a24c6de | 8583 | for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId) |
12381341 | 8584 | { |
6a24c6de | 8585 | Handle(V3d_Light) aLight = aLightIter.Value(); |
12381341 | 8586 | const Quantity_Color aColor = aLight->Color(); |
8587 | theDi << "Light" << aLightId << "\n"; | |
8588 | switch (aLight->Type()) | |
8589 | { | |
8590 | case V3d_AMBIENT: | |
8591 | { | |
189f85a3 | 8592 | theDi << " Type: Ambient\n"; |
8593 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
12381341 | 8594 | break; |
8595 | } | |
8596 | case V3d_DIRECTIONAL: | |
8597 | { | |
8598 | Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight); | |
189f85a3 | 8599 | theDi << " Type: Directional\n"; |
8600 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
8601 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
8602 | theDi << " Smoothness: " << aLight->Smoothness() << "\n"; | |
12381341 | 8603 | if (!aLightDir.IsNull()) |
8604 | { | |
8605 | aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]); | |
189f85a3 | 8606 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; |
12381341 | 8607 | aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]); |
189f85a3 | 8608 | theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; |
12381341 | 8609 | } |
8610 | break; | |
8611 | } | |
8612 | case V3d_POSITIONAL: | |
8613 | { | |
8614 | Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight); | |
189f85a3 | 8615 | theDi << " Type: Positional\n"; |
8616 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
8617 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
8618 | theDi << " Smoothness: " << aLight->Smoothness() << "\n"; | |
12381341 | 8619 | if (!aLightPos.IsNull()) |
8620 | { | |
8621 | aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]); | |
189f85a3 | 8622 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; |
12381341 | 8623 | aLightPos->Attenuation (anAtten[0], anAtten[1]); |
189f85a3 | 8624 | theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n"; |
12381341 | 8625 | } |
8626 | break; | |
8627 | } | |
8628 | case V3d_SPOT: | |
8629 | { | |
8630 | Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight); | |
189f85a3 | 8631 | theDi << " Type: Spot\n"; |
8632 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
8633 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
12381341 | 8634 | if (!aLightSpot.IsNull()) |
8635 | { | |
8636 | aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]); | |
189f85a3 | 8637 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; |
12381341 | 8638 | aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]); |
189f85a3 | 8639 | theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; |
12381341 | 8640 | aLightSpot->Attenuation (anAtten[0], anAtten[1]); |
189f85a3 | 8641 | theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n"; |
8642 | theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n"; | |
8643 | theDi << " Exponent: " << aLightSpot->Concentration() << "\n"; | |
12381341 | 8644 | } |
8645 | break; | |
8646 | } | |
8647 | default: | |
8648 | { | |
189f85a3 | 8649 | theDi << " Type: UNKNOWN\n"; |
12381341 | 8650 | break; |
8651 | } | |
8652 | } | |
8653 | theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n"; | |
8654 | } | |
8655 | } | |
8656 | ||
8657 | Handle(V3d_Light) aLightNew; | |
8658 | Handle(V3d_Light) aLightOld; | |
8659 | Standard_Boolean isGlobal = Standard_True; | |
8660 | Standard_Boolean toCreate = Standard_False; | |
8661 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
8662 | { | |
8663 | Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew; | |
8664 | Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr); | |
8665 | Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr); | |
8666 | Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr); | |
8667 | Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr); | |
8668 | ||
8669 | TCollection_AsciiString aName, aValue; | |
8670 | const TCollection_AsciiString anArg (theArgVec[anArgIt]); | |
8671 | TCollection_AsciiString anArgCase (anArg); | |
8672 | anArgCase.UpperCase(); | |
8673 | if (anArgCase.IsEqual ("NEW") | |
8674 | || anArgCase.IsEqual ("ADD") | |
8675 | || anArgCase.IsEqual ("CREATE")) | |
8676 | { | |
8677 | toCreate = Standard_True; | |
8678 | } | |
8679 | else if (anArgCase.IsEqual ("GLOB") | |
8680 | || anArgCase.IsEqual ("GLOBAL")) | |
8681 | { | |
8682 | isGlobal = Standard_True; | |
8683 | } | |
8684 | else if (anArgCase.IsEqual ("LOC") | |
8685 | || anArgCase.IsEqual ("LOCAL")) | |
8686 | { | |
8687 | isGlobal = Standard_False; | |
8688 | } | |
4fe9ad57 | 8689 | else if (anArgCase.IsEqual ("DEF") |
8690 | || anArgCase.IsEqual ("DEFAULTS")) | |
8691 | { | |
8692 | toCreate = Standard_False; | |
8693 | aViewer->SetDefaultLights(); | |
8694 | } | |
8695 | else if (anArgCase.IsEqual ("CLR") | |
8696 | || anArgCase.IsEqual ("CLEAR")) | |
8697 | { | |
8698 | toCreate = Standard_False; | |
6a24c6de | 8699 | for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();) |
4fe9ad57 | 8700 | { |
6a24c6de | 8701 | Handle(V3d_Light) aLight = aLightIter.Value(); |
8702 | aViewer->DelLight (aLight); | |
8703 | aLightIter = aView->ActiveLightIterator(); | |
4fe9ad57 | 8704 | } |
8705 | } | |
12381341 | 8706 | else if (anArgCase.IsEqual ("AMB") |
8707 | || anArgCase.IsEqual ("AMBIENT") | |
8708 | || anArgCase.IsEqual ("AMBLIGHT")) | |
8709 | { | |
8710 | addLight (aLightNew, isGlobal); | |
8711 | if (!toCreate) | |
8712 | { | |
8713 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8714 | return 1; | |
8715 | } | |
8716 | toCreate = Standard_False; | |
8717 | aLightNew = new V3d_AmbientLight (aViewer); | |
8718 | } | |
8719 | else if (anArgCase.IsEqual ("DIRECTIONAL") | |
8720 | || anArgCase.IsEqual ("DIRLIGHT")) | |
8721 | { | |
8722 | addLight (aLightNew, isGlobal); | |
8723 | if (!toCreate) | |
8724 | { | |
8725 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8726 | return 1; | |
8727 | } | |
8728 | toCreate = Standard_False; | |
8729 | aLightNew = new V3d_DirectionalLight (aViewer); | |
8730 | } | |
8731 | else if (anArgCase.IsEqual ("SPOT") | |
8732 | || anArgCase.IsEqual ("SPOTLIGHT")) | |
8733 | { | |
8734 | addLight (aLightNew, isGlobal); | |
8735 | if (!toCreate) | |
8736 | { | |
8737 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8738 | return 1; | |
8739 | } | |
8740 | toCreate = Standard_False; | |
8741 | aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0); | |
8742 | } | |
8743 | else if (anArgCase.IsEqual ("POSLIGHT") | |
8744 | || anArgCase.IsEqual ("POSITIONAL")) | |
8745 | { | |
8746 | addLight (aLightNew, isGlobal); | |
8747 | if (!toCreate) | |
8748 | { | |
8749 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8750 | return 1; | |
8751 | } | |
8752 | toCreate = Standard_False; | |
8753 | aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0); | |
8754 | } | |
8755 | else if (anArgCase.IsEqual ("CHANGE")) | |
8756 | { | |
8757 | addLight (aLightNew, isGlobal); | |
8758 | aLightNew.Nullify(); | |
8759 | if (++anArgIt >= theArgsNb) | |
8760 | { | |
8761 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8762 | return 1; | |
8763 | } | |
8764 | ||
8765 | const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]); | |
8766 | Standard_Integer aLightIt = 0; | |
6a24c6de | 8767 | for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt) |
12381341 | 8768 | { |
8769 | if (aLightIt == aLightId) | |
8770 | { | |
6a24c6de | 8771 | aLightOld = aLightIter.Value(); |
12381341 | 8772 | break; |
8773 | } | |
8774 | } | |
8775 | ||
8776 | if (aLightOld.IsNull()) | |
8777 | { | |
8778 | std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n"; | |
8779 | return 1; | |
8780 | } | |
8781 | } | |
8782 | else if (anArgCase.IsEqual ("DEL") | |
8783 | || anArgCase.IsEqual ("DELETE")) | |
8784 | { | |
8785 | Handle(V3d_Light) aLightDel; | |
8786 | if (++anArgIt >= theArgsNb) | |
8787 | { | |
8788 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8789 | return 1; | |
8790 | } | |
8791 | ||
8792 | const TCollection_AsciiString anArgNext (theArgVec[anArgIt]); | |
8793 | const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]); | |
8794 | Standard_Integer aLightIt = 0; | |
6a24c6de | 8795 | for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt) |
12381341 | 8796 | { |
6a24c6de | 8797 | aLightDel = aLightIter.Value(); |
12381341 | 8798 | if (aLightIt == aLightDelId) |
8799 | { | |
8800 | break; | |
8801 | } | |
8802 | } | |
8803 | if (!aLightDel.IsNull()) | |
8804 | { | |
8805 | aViewer->DelLight (aLightDel); | |
8806 | } | |
8807 | } | |
8808 | else if (anArgCase.IsEqual ("COLOR") | |
8809 | || anArgCase.IsEqual ("COLOUR")) | |
8810 | { | |
8811 | if (++anArgIt >= theArgsNb) | |
8812 | { | |
8813 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8814 | return 1; | |
8815 | } | |
8816 | ||
8817 | TCollection_AsciiString anArgNext (theArgVec[anArgIt]); | |
8818 | anArgNext.UpperCase(); | |
8819 | const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString()); | |
8820 | if (!aLightCurr.IsNull()) | |
8821 | { | |
8822 | aLightCurr->SetColor (aColor); | |
8823 | } | |
8824 | } | |
8825 | else if (anArgCase.IsEqual ("POS") | |
8826 | || anArgCase.IsEqual ("POSITION")) | |
8827 | { | |
8828 | if ((anArgIt + 3) >= theArgsNb) | |
8829 | { | |
8830 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8831 | return 1; | |
8832 | } | |
8833 | ||
8834 | anXYZ[0] = Atof (theArgVec[++anArgIt]); | |
8835 | anXYZ[1] = Atof (theArgVec[++anArgIt]); | |
8836 | anXYZ[2] = Atof (theArgVec[++anArgIt]); | |
8837 | if (!aLightDir.IsNull()) | |
8838 | { | |
8839 | aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]); | |
8840 | } | |
8841 | else if (!aLightPos.IsNull()) | |
8842 | { | |
8843 | aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]); | |
8844 | } | |
8845 | else if (!aLightSpot.IsNull()) | |
8846 | { | |
8847 | aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]); | |
8848 | } | |
8849 | else | |
8850 | { | |
8851 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8852 | return 1; | |
8853 | } | |
8854 | } | |
8855 | else if (anArgCase.IsEqual ("DIR") | |
8856 | || anArgCase.IsEqual ("DIRECTION")) | |
8857 | { | |
8858 | if ((anArgIt + 3) >= theArgsNb) | |
8859 | { | |
8860 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8861 | return 1; | |
8862 | } | |
8863 | ||
8864 | anXYZ[0] = Atof (theArgVec[++anArgIt]); | |
8865 | anXYZ[1] = Atof (theArgVec[++anArgIt]); | |
8866 | anXYZ[2] = Atof (theArgVec[++anArgIt]); | |
8867 | if (!aLightDir.IsNull()) | |
8868 | { | |
8869 | aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]); | |
8870 | } | |
8871 | else if (!aLightSpot.IsNull()) | |
8872 | { | |
8873 | aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]); | |
8874 | } | |
8875 | else | |
8876 | { | |
8877 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8878 | return 1; | |
8879 | } | |
8880 | } | |
189f85a3 | 8881 | else if (anArgCase.IsEqual ("SM") |
8882 | || anArgCase.IsEqual ("SMOOTHNESS")) | |
8883 | { | |
8884 | if (++anArgIt >= theArgsNb) | |
8885 | { | |
8886 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8887 | return 1; | |
8888 | } | |
8889 | ||
8890 | Standard_Real aSmoothness = Atof (theArgVec[anArgIt]); | |
8891 | ||
8892 | if (fabs (aSmoothness) < Precision::Confusion()) | |
8893 | { | |
8894 | aLightCurr->SetIntensity (1.f); | |
8895 | } | |
8896 | else if (fabs (aLightCurr->Smoothness()) < Precision::Confusion()) | |
8897 | { | |
8898 | aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f); | |
8899 | } | |
8900 | else | |
8901 | { | |
8902 | Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness()); | |
8903 | aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio)); | |
8904 | } | |
8905 | ||
8906 | if (!aLightPos.IsNull()) | |
8907 | { | |
8908 | aLightPos->SetSmoothRadius (aSmoothness); | |
8909 | } | |
8910 | else if (!aLightDir.IsNull()) | |
8911 | { | |
8912 | aLightDir->SetSmoothAngle (aSmoothness); | |
8913 | } | |
8914 | } | |
8915 | else if (anArgCase.IsEqual ("INT") | |
8916 | || anArgCase.IsEqual ("INTENSITY")) | |
8917 | { | |
8918 | if (++anArgIt >= theArgsNb) | |
8919 | { | |
8920 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8921 | return 1; | |
8922 | } | |
8923 | ||
8924 | Standard_Real aIntensity = Atof (theArgVec[anArgIt]); | |
8925 | ||
8926 | if (!aLightCurr.IsNull()) | |
8927 | { | |
8928 | aLightCurr->SetIntensity (aIntensity); | |
8929 | } | |
8930 | } | |
4fe9ad57 | 8931 | else if (anArgCase.IsEqual ("ANG") |
8932 | || anArgCase.IsEqual ("ANGLE")) | |
8933 | { | |
8934 | if (++anArgIt >= theArgsNb) | |
8935 | { | |
8936 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8937 | return 1; | |
8938 | } | |
8939 | ||
8940 | Standard_Real anAngle = Atof (theArgVec[anArgIt]); | |
8941 | ||
8942 | if (!aLightSpot.IsNull()) | |
8943 | { | |
8944 | aLightSpot->SetAngle (anAngle / 180.0 * M_PI); | |
8945 | } | |
8946 | } | |
12381341 | 8947 | else if (anArgCase.IsEqual ("CONSTATTEN") |
8948 | || anArgCase.IsEqual ("CONSTATTENUATION")) | |
8949 | { | |
8950 | if (++anArgIt >= theArgsNb) | |
8951 | { | |
8952 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8953 | return 1; | |
8954 | } | |
8955 | ||
8956 | if (!aLightPos.IsNull()) | |
8957 | { | |
8958 | aLightPos->Attenuation (anAtten[0], anAtten[1]); | |
8959 | anAtten[0] = Atof (theArgVec[anArgIt]); | |
8960 | aLightPos->SetAttenuation (anAtten[0], anAtten[1]); | |
8961 | } | |
8962 | else if (!aLightSpot.IsNull()) | |
8963 | { | |
8964 | aLightSpot->Attenuation (anAtten[0], anAtten[1]); | |
8965 | anAtten[0] = Atof (theArgVec[anArgIt]); | |
8966 | aLightSpot->SetAttenuation (anAtten[0], anAtten[1]); | |
8967 | } | |
8968 | else | |
8969 | { | |
8970 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8971 | return 1; | |
8972 | } | |
8973 | } | |
8974 | else if (anArgCase.IsEqual ("LINATTEN") | |
8975 | || anArgCase.IsEqual ("LINEARATTEN") | |
8976 | || anArgCase.IsEqual ("LINEARATTENUATION")) | |
8977 | { | |
8978 | if (++anArgIt >= theArgsNb) | |
8979 | { | |
8980 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8981 | return 1; | |
8982 | } | |
8983 | ||
8984 | if (!aLightPos.IsNull()) | |
8985 | { | |
8986 | aLightPos->Attenuation (anAtten[0], anAtten[1]); | |
8987 | anAtten[1] = Atof (theArgVec[anArgIt]); | |
8988 | aLightPos->SetAttenuation (anAtten[0], anAtten[1]); | |
8989 | } | |
8990 | else if (!aLightSpot.IsNull()) | |
8991 | { | |
8992 | aLightSpot->Attenuation (anAtten[0], anAtten[1]); | |
8993 | anAtten[1] = Atof (theArgVec[anArgIt]); | |
8994 | aLightSpot->SetAttenuation (anAtten[0], anAtten[1]); | |
8995 | } | |
8996 | else | |
8997 | { | |
8998 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
8999 | return 1; | |
9000 | } | |
9001 | } | |
9002 | else if (anArgCase.IsEqual ("EXP") | |
9003 | || anArgCase.IsEqual ("EXPONENT") | |
9004 | || anArgCase.IsEqual ("SPOTEXP") | |
9005 | || anArgCase.IsEqual ("SPOTEXPONENT")) | |
9006 | { | |
9007 | if (++anArgIt >= theArgsNb) | |
9008 | { | |
9009 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
9010 | return 1; | |
9011 | } | |
9012 | ||
9013 | if (!aLightSpot.IsNull()) | |
9014 | { | |
9015 | aLightSpot->SetConcentration (Atof (theArgVec[anArgIt])); | |
9016 | } | |
9017 | else | |
9018 | { | |
9019 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
9020 | return 1; | |
9021 | } | |
9022 | } | |
9023 | else if (anArgCase.IsEqual ("HEAD") | |
9024 | || anArgCase.IsEqual ("HEADLIGHT")) | |
9025 | { | |
9026 | if (++anArgIt >= theArgsNb) | |
9027 | { | |
9028 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
9029 | return 1; | |
9030 | } | |
9031 | ||
9032 | if (aLightAmb.IsNull() | |
9033 | && !aLightCurr.IsNull()) | |
9034 | { | |
9035 | aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0); | |
9036 | } | |
9037 | else | |
9038 | { | |
9039 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
9040 | return 1; | |
9041 | } | |
9042 | } | |
9043 | else | |
9044 | { | |
9045 | std::cerr << "Warning: unknown argument '" << anArg << "'\n"; | |
9046 | } | |
9047 | } | |
9048 | ||
9049 | addLight (aLightNew, isGlobal); | |
9050 | aViewer->UpdateLights(); | |
9051 | ||
9052 | return 0; | |
9053 | } | |
9054 | ||
e276548b | 9055 | //======================================================================= |
bc8c79bb | 9056 | //function : VRenderParams |
9057 | //purpose : Enables/disables rendering features | |
e276548b | 9058 | //======================================================================= |
9059 | ||
bc8c79bb | 9060 | static Standard_Integer VRenderParams (Draw_Interpretor& theDI, |
9061 | Standard_Integer theArgNb, | |
9062 | const char** theArgVec) | |
e276548b | 9063 | { |
7ae4a307 | 9064 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
9065 | if (aView.IsNull()) | |
e276548b | 9066 | { |
bc8c79bb | 9067 | std::cerr << "Error: no active viewer!\n"; |
e276548b | 9068 | return 1; |
9069 | } | |
bc8c79bb | 9070 | |
9071 | Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams(); | |
6b62b2da | 9072 | TCollection_AsciiString aCmdName (theArgVec[0]); |
9073 | aCmdName.LowerCase(); | |
9074 | if (aCmdName == "vraytrace") | |
9075 | { | |
9076 | if (theArgNb == 1) | |
9077 | { | |
9078 | theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " "; | |
9079 | return 0; | |
9080 | } | |
9081 | else if (theArgNb == 2) | |
9082 | { | |
9083 | TCollection_AsciiString aValue (theArgVec[1]); | |
9084 | aValue.LowerCase(); | |
9085 | if (aValue == "on" | |
9086 | || aValue == "1") | |
9087 | { | |
9088 | aParams.Method = Graphic3d_RM_RAYTRACING; | |
9089 | aView->Redraw(); | |
9090 | return 0; | |
9091 | } | |
9092 | else if (aValue == "off" | |
9093 | || aValue == "0") | |
9094 | { | |
9095 | aParams.Method = Graphic3d_RM_RASTERIZATION; | |
9096 | aView->Redraw(); | |
9097 | return 0; | |
9098 | } | |
9099 | else | |
9100 | { | |
9101 | std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n"; | |
9102 | return 1; | |
9103 | } | |
9104 | } | |
9105 | else | |
9106 | { | |
9107 | std::cout << "Error: wrong number of arguments\n"; | |
9108 | return 1; | |
9109 | } | |
9110 | } | |
bc8c79bb | 9111 | |
9112 | if (theArgNb < 2) | |
e276548b | 9113 | { |
bc8c79bb | 9114 | theDI << "renderMode: "; |
9115 | switch (aParams.Method) | |
9116 | { | |
9117 | case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break; | |
9118 | case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break; | |
9119 | } | |
9120 | theDI << "\n"; | |
b4327ba8 | 9121 | theDI << "msaa: " << aParams.NbMsaaSamples << "\n"; |
56689b27 | 9122 | theDI << "rendScale: " << aParams.RenderResolutionScale << "\n"; |
b4327ba8 | 9123 | theDI << "rayDepth: " << aParams.RaytracingDepth << "\n"; |
9124 | theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n"; | |
9125 | theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n"; | |
9126 | theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n"; | |
9127 | theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n"; | |
9128 | theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n"; | |
9129 | theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n"; | |
9130 | theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n"; | |
9131 | theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n"; | |
9132 | theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n"; | |
b09447ed | 9133 | theDI << "max radiance: " << aParams.RadianceClampingValue << "\n"; |
4eaaf9d8 | 9134 | theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n"; |
8625ef7e | 9135 | theDI << "shadingModel: "; |
9136 | switch (aView->ShadingModel()) | |
9137 | { | |
9138 | case V3d_COLOR: theDI << "color"; break; | |
9139 | case V3d_FLAT: theDI << "flat"; break; | |
9140 | case V3d_GOURAUD: theDI << "gouraud"; break; | |
9141 | case V3d_PHONG: theDI << "phong"; break; | |
9142 | } | |
9143 | theDI << "\n"; | |
bc8c79bb | 9144 | return 0; |
e276548b | 9145 | } |
9146 | ||
bc8c79bb | 9147 | Standard_Boolean toPrint = Standard_False; |
8625ef7e | 9148 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
e276548b | 9149 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
9150 | { | |
bc8c79bb | 9151 | Standard_CString anArg (theArgVec[anArgIter]); |
9152 | TCollection_AsciiString aFlag (anArg); | |
9153 | aFlag.LowerCase(); | |
8625ef7e | 9154 | if (anUpdateTool.parseRedrawMode (aFlag)) |
9155 | { | |
9156 | continue; | |
9157 | } | |
9158 | else if (aFlag == "-echo" | |
9159 | || aFlag == "-print") | |
e276548b | 9160 | { |
bc8c79bb | 9161 | toPrint = Standard_True; |
8625ef7e | 9162 | anUpdateTool.Invalidate(); |
e276548b | 9163 | } |
bc8c79bb | 9164 | else if (aFlag == "-mode" |
9165 | || aFlag == "-rendermode" | |
9166 | || aFlag == "-render_mode") | |
e276548b | 9167 | { |
bc8c79bb | 9168 | if (toPrint) |
9169 | { | |
9170 | switch (aParams.Method) | |
9171 | { | |
9172 | case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break; | |
9173 | case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break; | |
9174 | } | |
9175 | continue; | |
9176 | } | |
e276548b | 9177 | else |
bc8c79bb | 9178 | { |
9179 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
9180 | return 1; | |
9181 | } | |
9182 | } | |
9183 | else if (aFlag == "-ray" | |
9184 | || aFlag == "-raytrace") | |
9185 | { | |
9186 | if (toPrint) | |
9187 | { | |
9188 | theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " "; | |
9189 | continue; | |
9190 | } | |
9191 | ||
9192 | aParams.Method = Graphic3d_RM_RAYTRACING; | |
e276548b | 9193 | } |
bc8c79bb | 9194 | else if (aFlag == "-rast" |
9195 | || aFlag == "-raster" | |
9196 | || aFlag == "-rasterization") | |
e276548b | 9197 | { |
bc8c79bb | 9198 | if (toPrint) |
9199 | { | |
9200 | theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " "; | |
9201 | continue; | |
9202 | } | |
9203 | ||
9204 | aParams.Method = Graphic3d_RM_RASTERIZATION; | |
9205 | } | |
3c4b62a4 | 9206 | else if (aFlag == "-msaa") |
9207 | { | |
9208 | if (toPrint) | |
9209 | { | |
9210 | theDI << aParams.NbMsaaSamples << " "; | |
9211 | continue; | |
9212 | } | |
9213 | else if (++anArgIter >= theArgNb) | |
9214 | { | |
9215 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
9216 | return 1; | |
9217 | } | |
9218 | ||
9219 | const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]); | |
9220 | if (aNbSamples < 0) | |
9221 | { | |
9222 | std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n"; | |
9223 | return 1; | |
9224 | } | |
9225 | else | |
9226 | { | |
9227 | aParams.NbMsaaSamples = aNbSamples; | |
9228 | } | |
9229 | } | |
56689b27 | 9230 | else if (aFlag == "-rendscale" |
9231 | || aFlag == "-renderscale" | |
9232 | || aFlag == "-renderresolutionscale") | |
9233 | { | |
9234 | if (toPrint) | |
9235 | { | |
9236 | theDI << aParams.RenderResolutionScale << " "; | |
9237 | continue; | |
9238 | } | |
9239 | else if (++anArgIter >= theArgNb) | |
9240 | { | |
9241 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
9242 | return 1; | |
9243 | } | |
9244 | ||
9245 | const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]); | |
9246 | if (aScale < 0.01) | |
9247 | { | |
9248 | std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n"; | |
9249 | return 1; | |
9250 | } | |
9251 | else | |
9252 | { | |
9253 | aParams.RenderResolutionScale = Standard_ShortReal(aScale); | |
9254 | } | |
9255 | } | |
bc8c79bb | 9256 | else if (aFlag == "-raydepth" |
9257 | || aFlag == "-ray_depth") | |
9258 | { | |
9259 | if (toPrint) | |
9260 | { | |
9261 | theDI << aParams.RaytracingDepth << " "; | |
9262 | continue; | |
9263 | } | |
9264 | else if (++anArgIter >= theArgNb) | |
9265 | { | |
9266 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
9267 | return 1; | |
9268 | } | |
9269 | ||
9270 | const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]); | |
189f85a3 | 9271 | |
9272 | // We allow RaytracingDepth be more than 10 in case of GI enabled | |
9273 | if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled)) | |
bc8c79bb | 9274 | { |
9275 | std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n"; | |
9276 | return 1; | |
9277 | } | |
e276548b | 9278 | else |
bc8c79bb | 9279 | { |
9280 | aParams.RaytracingDepth = aDepth; | |
9281 | } | |
9282 | } | |
9283 | else if (aFlag == "-shad" | |
9284 | || aFlag == "-shadows") | |
9285 | { | |
9286 | if (toPrint) | |
9287 | { | |
9288 | theDI << (aParams.IsShadowEnabled ? "on" : "off") << " "; | |
9289 | continue; | |
9290 | } | |
9291 | ||
9292 | Standard_Boolean toEnable = Standard_True; | |
9293 | if (++anArgIter < theArgNb | |
a5565a3c | 9294 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 9295 | { |
9296 | --anArgIter; | |
9297 | } | |
9298 | aParams.IsShadowEnabled = toEnable; | |
9299 | } | |
9300 | else if (aFlag == "-refl" | |
9301 | || aFlag == "-reflections") | |
9302 | { | |
9303 | if (toPrint) | |
9304 | { | |
9305 | theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " "; | |
9306 | continue; | |
9307 | } | |
9308 | ||
9309 | Standard_Boolean toEnable = Standard_True; | |
9310 | if (++anArgIter < theArgNb | |
a5565a3c | 9311 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 9312 | { |
9313 | --anArgIter; | |
9314 | } | |
9315 | aParams.IsReflectionEnabled = toEnable; | |
9316 | } | |
9317 | else if (aFlag == "-fsaa") | |
9318 | { | |
9319 | if (toPrint) | |
9320 | { | |
9321 | theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " "; | |
9322 | continue; | |
9323 | } | |
9324 | ||
9325 | Standard_Boolean toEnable = Standard_True; | |
9326 | if (++anArgIter < theArgNb | |
a5565a3c | 9327 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 9328 | { |
9329 | --anArgIter; | |
9330 | } | |
9331 | aParams.IsAntialiasingEnabled = toEnable; | |
9332 | } | |
9333 | else if (aFlag == "-gleam") | |
9334 | { | |
9335 | if (toPrint) | |
9336 | { | |
9337 | theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " "; | |
9338 | continue; | |
9339 | } | |
9340 | ||
9341 | Standard_Boolean toEnable = Standard_True; | |
9342 | if (++anArgIter < theArgNb | |
a5565a3c | 9343 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 9344 | { |
9345 | --anArgIter; | |
9346 | } | |
9347 | aParams.IsTransparentShadowEnabled = toEnable; | |
e276548b | 9348 | } |
189f85a3 | 9349 | else if (aFlag == "-gi") |
9350 | { | |
9351 | if (toPrint) | |
9352 | { | |
9353 | theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " "; | |
9354 | continue; | |
9355 | } | |
9356 | ||
9357 | Standard_Boolean toEnable = Standard_True; | |
9358 | if (++anArgIter < theArgNb | |
a5565a3c | 9359 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
189f85a3 | 9360 | { |
9361 | --anArgIter; | |
9362 | } | |
9363 | aParams.IsGlobalIlluminationEnabled = toEnable; | |
9364 | if (!toEnable) | |
9365 | { | |
9366 | aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10); | |
9367 | } | |
9368 | } | |
8c820969 | 9369 | else if (aFlag == "-blockedrng" |
9370 | || aFlag == "-brng") | |
9371 | { | |
9372 | if (toPrint) | |
9373 | { | |
9374 | theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " "; | |
9375 | continue; | |
9376 | } | |
9377 | ||
9378 | Standard_Boolean toEnable = Standard_True; | |
9379 | if (++anArgIter < theArgNb | |
a5565a3c | 9380 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8c820969 | 9381 | { |
9382 | --anArgIter; | |
9383 | } | |
9384 | aParams.CoherentPathTracingMode = toEnable; | |
9385 | } | |
b09447ed | 9386 | else if (aFlag == "-maxrad") |
9387 | { | |
9388 | if (toPrint) | |
9389 | { | |
9390 | theDI << aParams.RadianceClampingValue << " "; | |
9391 | continue; | |
9392 | } | |
9393 | else if (++anArgIter >= theArgNb) | |
9394 | { | |
9395 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
9396 | return 1; | |
9397 | } | |
9398 | ||
9399 | const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter]; | |
9400 | if (!aMaxRadStr.IsRealValue()) | |
9401 | { | |
9402 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
9403 | return 1; | |
9404 | } | |
9405 | ||
9406 | const Standard_Real aMaxRadiance = aMaxRadStr.RealValue(); | |
9407 | if (aMaxRadiance <= 0.0) | |
9408 | { | |
9409 | std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n"; | |
9410 | return 1; | |
9411 | } | |
9412 | else | |
9413 | { | |
9414 | aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance); | |
9415 | } | |
9416 | } | |
3a9b5dc8 | 9417 | else if (aFlag == "-iss") |
9418 | { | |
9419 | if (toPrint) | |
9420 | { | |
9421 | theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " "; | |
9422 | continue; | |
9423 | } | |
9424 | ||
9425 | Standard_Boolean toEnable = Standard_True; | |
9426 | if (++anArgIter < theArgNb | |
9427 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
9428 | { | |
9429 | --anArgIter; | |
9430 | } | |
9431 | aParams.AdaptiveScreenSampling = toEnable; | |
9432 | } | |
9433 | else if (aFlag == "-issd") | |
9434 | { | |
9435 | if (toPrint) | |
9436 | { | |
9437 | theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " "; | |
9438 | continue; | |
9439 | } | |
9440 | ||
9441 | Standard_Boolean toEnable = Standard_True; | |
9442 | if (++anArgIter < theArgNb | |
9443 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
9444 | { | |
9445 | --anArgIter; | |
9446 | } | |
9447 | aParams.ShowSamplingTiles = toEnable; | |
9448 | } | |
4eaaf9d8 | 9449 | else if (aFlag == "-nbtiles") |
9450 | { | |
9451 | if (toPrint) | |
9452 | { | |
9453 | theDI << aParams.NbRayTracingTiles << " "; | |
9454 | continue; | |
9455 | } | |
9456 | else if (++anArgIter >= theArgNb) | |
9457 | { | |
9458 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
9459 | return 1; | |
9460 | } | |
9461 | ||
9462 | const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]); | |
9463 | ||
9464 | if (aNbTiles < 64) | |
9465 | { | |
9466 | std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n"; | |
9467 | std::cerr << "Specify value in range [64, 1024].\n"; | |
9468 | return 1; | |
9469 | } | |
9470 | else | |
9471 | { | |
9472 | aParams.NbRayTracingTiles = aNbTiles; | |
9473 | } | |
9474 | } | |
189f85a3 | 9475 | else if (aFlag == "-env") |
9476 | { | |
9477 | if (toPrint) | |
9478 | { | |
9479 | theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " "; | |
9480 | continue; | |
9481 | } | |
9482 | ||
9483 | Standard_Boolean toEnable = Standard_True; | |
9484 | if (++anArgIter < theArgNb | |
a5565a3c | 9485 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
189f85a3 | 9486 | { |
9487 | --anArgIter; | |
9488 | } | |
9489 | aParams.UseEnvironmentMapBackground = toEnable; | |
9490 | } | |
b4327ba8 | 9491 | else if (aFlag == "-twoside") |
9492 | { | |
9493 | if (toPrint) | |
9494 | { | |
9495 | theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " "; | |
9496 | continue; | |
9497 | } | |
9498 | ||
9499 | Standard_Boolean toEnable = Standard_True; | |
9500 | if (++anArgIter < theArgNb | |
9501 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
9502 | { | |
9503 | --anArgIter; | |
9504 | } | |
9505 | aParams.TwoSidedBsdfModels = toEnable; | |
9506 | } | |
8625ef7e | 9507 | else if (aFlag == "-shademodel" |
9508 | || aFlag == "-shadingmodel" | |
9509 | || aFlag == "-shading") | |
9510 | { | |
9511 | if (toPrint) | |
9512 | { | |
9513 | switch (aView->ShadingModel()) | |
9514 | { | |
9515 | case V3d_COLOR: theDI << "color "; break; | |
9516 | case V3d_FLAT: theDI << "flat "; break; | |
9517 | case V3d_GOURAUD: theDI << "gouraud "; break; | |
9518 | case V3d_PHONG: theDI << "phong "; break; | |
9519 | } | |
9520 | continue; | |
9521 | } | |
9522 | ||
9523 | if (++anArgIter >= theArgNb) | |
9524 | { | |
9525 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
9526 | } | |
9527 | ||
9528 | TCollection_AsciiString aMode (theArgVec[anArgIter]); | |
9529 | aMode.LowerCase(); | |
9530 | if (aMode == "color" | |
9531 | || aMode == "none") | |
9532 | { | |
9533 | aView->SetShadingModel (V3d_COLOR); | |
9534 | } | |
9535 | else if (aMode == "flat" | |
9536 | || aMode == "facet") | |
9537 | { | |
9538 | aView->SetShadingModel (V3d_FLAT); | |
9539 | } | |
9540 | else if (aMode == "gouraud" | |
9541 | || aMode == "vertex" | |
9542 | || aMode == "vert") | |
9543 | { | |
9544 | aView->SetShadingModel (V3d_GOURAUD); | |
9545 | } | |
9546 | else if (aMode == "phong" | |
9547 | || aMode == "fragment" | |
9548 | || aMode == "frag" | |
9549 | || aMode == "pixel") | |
9550 | { | |
9551 | aView->SetShadingModel (V3d_PHONG); | |
9552 | } | |
9553 | else | |
9554 | { | |
9555 | std::cout << "Error: unknown shading model '" << aMode << "'\n"; | |
9556 | return 1; | |
9557 | } | |
9558 | } | |
4b1c8733 | 9559 | else if (aFlag == "-resolution") |
9560 | { | |
9561 | if (++anArgIter >= theArgNb) | |
9562 | { | |
9563 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
9564 | return 1; | |
9565 | } | |
9566 | ||
9567 | TCollection_AsciiString aResolution (theArgVec[anArgIter]); | |
9568 | if (aResolution.IsIntegerValue()) | |
9569 | { | |
9570 | aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString())); | |
9571 | } | |
9572 | else | |
9573 | { | |
9574 | std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n"; | |
9575 | return 1; | |
9576 | } | |
9577 | } | |
d877e610 | 9578 | else if (aFlag == "-rebuildglsl" |
9579 | || aFlag == "-rebuild") | |
9580 | { | |
9581 | if (toPrint) | |
9582 | { | |
9583 | theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " "; | |
9584 | continue; | |
9585 | } | |
9586 | ||
9587 | Standard_Boolean toEnable = Standard_True; | |
9588 | if (++anArgIter < theArgNb | |
9589 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
9590 | { | |
9591 | --anArgIter; | |
9592 | } | |
9593 | aParams.RebuildRayTracingShaders = toEnable; | |
9594 | } | |
e276548b | 9595 | else |
9596 | { | |
bc8c79bb | 9597 | std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n"; |
9598 | return 1; | |
e276548b | 9599 | } |
9600 | } | |
189f85a3 | 9601 | |
9602 | return 0; | |
9603 | } | |
9604 | ||
9605 | //======================================================================= | |
9606 | //function : VProgressiveMode | |
9607 | //purpose : | |
9608 | //======================================================================= | |
9609 | #if defined(_WIN32) | |
9610 | static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/, | |
9611 | Standard_Integer /*theNbArgs*/, | |
9612 | const char** /*theArgs*/) | |
9613 | { | |
9614 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
9615 | if (aView.IsNull()) | |
9616 | { | |
9617 | std::cerr << "Error: no active viewer!\n"; | |
9618 | return 1; | |
9619 | } | |
9620 | ||
9621 | std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl; | |
9622 | ||
9623 | for (;;) | |
9624 | { | |
9625 | aView->Redraw(); | |
9626 | ||
9627 | Standard_Boolean toExit = Standard_False; | |
9628 | ||
9629 | MSG aMsg; | |
ad03c234 | 9630 | while (PeekMessageW (&aMsg, NULL, 0, 0, PM_REMOVE)) |
189f85a3 | 9631 | { |
9632 | if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b)) | |
9633 | { | |
9634 | toExit = Standard_True; | |
9635 | } | |
9636 | ||
9637 | TranslateMessage (&aMsg); | |
ad03c234 | 9638 | DispatchMessageW (&aMsg); |
189f85a3 | 9639 | } |
9640 | ||
9641 | if (toExit) | |
9642 | { | |
9643 | break; | |
9644 | } | |
9645 | } | |
9646 | ||
e276548b | 9647 | return 0; |
9648 | } | |
189f85a3 | 9649 | #endif |
e276548b | 9650 | |
b7cd4ba7 | 9651 | //======================================================================= |
9652 | //function : VFrustumCulling | |
9653 | //purpose : enables/disables view volume's culling. | |
9654 | //======================================================================= | |
9655 | static int VFrustumCulling (Draw_Interpretor& theDI, | |
9656 | Standard_Integer theArgNb, | |
9657 | const char** theArgVec) | |
9658 | { | |
9659 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
9660 | if (aView.IsNull()) | |
9661 | { | |
9662 | std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n"; | |
9663 | return 1; | |
9664 | } | |
9665 | ||
9666 | if (theArgNb < 2) | |
9667 | { | |
9668 | theDI << (aView->IsCullingEnabled() ? "on" : "off"); | |
9669 | return 0; | |
9670 | } | |
9671 | else if (theArgNb != 2) | |
9672 | { | |
9673 | std::cout << theArgVec[0] << " Syntax error: Specify the mode\n"; | |
9674 | return 1; | |
9675 | } | |
9676 | ||
9677 | TCollection_AsciiString aModeStr (theArgVec[1]); | |
9678 | aModeStr.LowerCase(); | |
9679 | Standard_Boolean toEnable = 0; | |
9680 | if (aModeStr == "on") | |
9681 | { | |
9682 | toEnable = 1; | |
9683 | } | |
9684 | else if (aModeStr == "off") | |
9685 | { | |
9686 | toEnable = 0; | |
9687 | } | |
9688 | else | |
9689 | { | |
9690 | toEnable = Draw::Atoi (theArgVec[1]) != 0; | |
9691 | } | |
9692 | ||
9693 | aView->SetFrustumCulling (toEnable); | |
9694 | aView->Redraw(); | |
9695 | return 0; | |
9696 | } | |
9697 | ||
c398b00e | 9698 | //======================================================================= |
9699 | //function : VHighlightSelected | |
9700 | //purpose : | |
9701 | //======================================================================= | |
9702 | static int VHighlightSelected (Draw_Interpretor& theDI, | |
9703 | Standard_Integer theArgNb, | |
9704 | const char** theArgVec) | |
9705 | { | |
9706 | if (ViewerTest::GetAISContext().IsNull()) | |
9707 | { | |
9708 | std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n"; | |
9709 | return 1; | |
9710 | } | |
9711 | ||
9712 | const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
9713 | ||
9714 | if (theArgNb < 2) | |
9715 | { | |
9716 | theDI << (aContext->ToHilightSelected() ? "on" : "off"); | |
9717 | return 0; | |
9718 | } | |
9719 | ||
9720 | if (theArgNb != 2) | |
9721 | { | |
9722 | std::cout << theArgVec[0] << " error : wrong number of parameters." | |
9723 | << "Type 'help" << theArgVec[0] << "' for more information."; | |
9724 | return 1; | |
9725 | } | |
9726 | ||
9727 | // Parse parameter | |
9728 | TCollection_AsciiString aMode (theArgVec[1]); | |
9729 | aMode.LowerCase(); | |
9730 | Standard_Boolean toEnable = Standard_False; | |
9731 | if (aMode.IsEqual ("on")) | |
9732 | { | |
9733 | toEnable = Standard_True; | |
9734 | } | |
9735 | else if (aMode.IsEqual ("off")) | |
9736 | { | |
9737 | toEnable = Standard_False; | |
9738 | } | |
9739 | else | |
9740 | { | |
9741 | toEnable = Draw::Atoi (theArgVec[1]) != 0; | |
9742 | } | |
9743 | ||
9744 | if (toEnable != aContext->ToHilightSelected()) | |
9745 | { | |
9746 | aContext->SetToHilightSelected (toEnable); | |
9747 | ||
9748 | // Move cursor to null position and back to process updating of detection | |
9749 | // and highlighting of selected object immediatly. | |
9750 | Standard_Integer aPixX = 0; | |
9751 | Standard_Integer aPixY = 0; | |
9752 | const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager(); | |
9753 | ||
9754 | anEventManager->GetCurrentPosition (aPixX, aPixY); | |
9755 | anEventManager->MoveTo (0, 0); | |
9756 | anEventManager->MoveTo (aPixX, aPixY); | |
9757 | } | |
9758 | ||
9759 | return 0; | |
9760 | } | |
9761 | ||
0717ddc1 | 9762 | //======================================================================= |
9763 | //function : VXRotate | |
9764 | //purpose : | |
9765 | //======================================================================= | |
9766 | static Standard_Integer VXRotate (Draw_Interpretor& di, | |
9767 | Standard_Integer argc, | |
9768 | const char ** argv) | |
9769 | { | |
9770 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
9771 | if (aContext.IsNull()) | |
9772 | { | |
586db386 | 9773 | di << argv[0] << "ERROR : use 'vinit' command before \n"; |
0717ddc1 | 9774 | return 1; |
9775 | } | |
9776 | ||
9777 | if (argc != 3) | |
9778 | { | |
586db386 | 9779 | di << "ERROR : Usage : " << argv[0] << " name angle\n"; |
0717ddc1 | 9780 | return 1; |
9781 | } | |
9782 | ||
9783 | TCollection_AsciiString aName (argv[1]); | |
9784 | Standard_Real anAngle = Draw::Atof (argv[2]); | |
9785 | ||
9786 | // find object | |
9787 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
9788 | Handle(AIS_InteractiveObject) anIObj; | |
9789 | if (!aMap.IsBound2 (aName) ) | |
9790 | { | |
586db386 | 9791 | di << "Use 'vdisplay' before\n"; |
0717ddc1 | 9792 | return 1; |
9793 | } | |
9794 | else | |
9795 | { | |
9796 | anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName)); | |
9797 | ||
9798 | gp_Trsf aTransform; | |
9799 | aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle); | |
9800 | aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart()); | |
9801 | ||
9802 | aContext->SetLocation (anIObj, aTransform); | |
9803 | aContext->UpdateCurrentViewer(); | |
9804 | } | |
9805 | ||
9806 | return 0; | |
9807 | } | |
9808 | ||
625e1958 | 9809 | //=============================================================================================== |
9810 | //class : ViewerTest_AISManipulator | |
9811 | //purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances | |
9812 | //=============================================================================================== | |
9813 | DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator) | |
9814 | ||
9815 | class ViewerTest_AISManipulator : public AIS_Manipulator | |
9816 | { | |
9817 | public: | |
9818 | ||
9819 | ViewerTest_AISManipulator() : AIS_Manipulator() | |
9820 | { | |
9821 | GetMapOfAISManipulators().Add (this); | |
9822 | } | |
9823 | ||
9824 | virtual ~ViewerTest_AISManipulator() | |
9825 | { | |
9826 | GetMapOfAISManipulators().Remove (this); | |
9827 | } | |
9828 | ||
9829 | DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator) | |
9830 | }; | |
9831 | ||
9832 | IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator) | |
9833 | IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator) | |
9834 | ||
9835 | //=============================================================================================== | |
9836 | //function : VManipulator | |
9837 | //purpose : | |
9838 | //=============================================================================================== | |
9839 | static int VManipulator (Draw_Interpretor& theDi, | |
9840 | Standard_Integer theArgsNb, | |
9841 | const char** theArgVec) | |
9842 | { | |
9843 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
9844 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
9845 | ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False); | |
9846 | if (aView.IsNull() | |
9847 | || aViewer.IsNull()) | |
9848 | { | |
9849 | std::cerr << "No active viewer!\n"; | |
9850 | return 1; | |
9851 | } | |
9852 | ||
9853 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView()); | |
9854 | Standard_Integer anArgIter = 1; | |
9855 | for (; anArgIter < theArgsNb; ++anArgIter) | |
9856 | { | |
9857 | anUpdateTool.parseRedrawMode (theArgVec[anArgIter]); | |
9858 | } | |
9859 | ||
9860 | ViewerTest_CmdParser aCmd; | |
9861 | aCmd.AddDescription ("Manages manipulator for interactive objects:"); | |
9862 | aCmd.AddOption ("attach", "... object - attach manipulator to an object"); | |
9863 | aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching"); | |
9864 | aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching "); | |
9865 | aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching "); | |
9866 | aCmd.AddOption ("detach", "... - detach manipulator"); | |
9867 | ||
9868 | aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation"); | |
9869 | aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation"); | |
9870 | aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation"); | |
9871 | ||
9872 | aCmd.AddOption ("move", "... x y z - move object"); | |
9873 | aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object"); | |
9874 | aCmd.AddOption ("scale", "... factor - scale object"); | |
9875 | ||
9876 | aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection"); | |
9877 | aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform"); | |
9878 | aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform"); | |
9879 | aCmd.AddOption ("gap", "... value - set gap between sub-parts"); | |
9880 | aCmd.AddOption ("part", "... axis mode {0|1} - set visual part"); | |
9881 | aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator"); | |
9882 | aCmd.AddOption ("size", "... size - set size of manipulator"); | |
9883 | aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence"); | |
9884 | ||
9885 | aCmd.Parse (theArgsNb, theArgVec); | |
9886 | ||
9887 | if (aCmd.HasOption ("help")) | |
9888 | { | |
9889 | theDi.PrintHelp (theArgVec[0]); | |
9890 | return 0; | |
9891 | } | |
9892 | ||
9893 | ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS(); | |
9894 | ||
9895 | TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str()); | |
9896 | ||
9897 | if (aName.IsEmpty()) | |
9898 | { | |
9899 | std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n"; | |
9900 | return 1; | |
9901 | } | |
9902 | ||
9903 | // ---------------------------------- | |
9904 | // detach existing manipulator object | |
9905 | // ---------------------------------- | |
9906 | ||
9907 | if (aCmd.HasOption ("detach")) | |
9908 | { | |
9909 | if (!aMapAIS.IsBound2 (aName)) | |
9910 | { | |
9911 | std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n"; | |
9912 | return 1; | |
9913 | } | |
9914 | ||
9915 | Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName)); | |
9916 | if (aManipulator.IsNull()) | |
9917 | { | |
9918 | std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n"; | |
9919 | return 1; | |
9920 | } | |
9921 | ||
9922 | aManipulator->Detach(); | |
9923 | aMapAIS.UnBind2 (aName); | |
0577ae8c | 9924 | ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True); |
625e1958 | 9925 | |
9926 | return 0; | |
9927 | } | |
9928 | ||
9929 | // ----------------------------------------------- | |
9930 | // find or create manipulator if it does not exist | |
9931 | // ----------------------------------------------- | |
9932 | ||
9933 | Handle(AIS_Manipulator) aManipulator; | |
9934 | if (!aMapAIS.IsBound2 (aName)) | |
9935 | { | |
9936 | std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n"; | |
9937 | ||
9938 | aManipulator = new ViewerTest_AISManipulator(); | |
9939 | aMapAIS.Bind (aManipulator, aName); | |
9940 | } | |
9941 | else | |
9942 | { | |
9943 | aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName)); | |
9944 | if (aManipulator.IsNull()) | |
9945 | { | |
9946 | std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n"; | |
9947 | return 1; | |
9948 | } | |
9949 | } | |
9950 | ||
9951 | // ----------------------------------------- | |
9952 | // change properties of manipulator instance | |
9953 | // ----------------------------------------- | |
9954 | ||
9955 | if (aCmd.HasOption ("autoActivate", 1, Standard_True)) | |
9956 | { | |
9957 | aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate")); | |
9958 | } | |
9959 | if (aCmd.HasOption ("followTranslation", 1, Standard_True)) | |
9960 | { | |
9961 | aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation")); | |
9962 | } | |
9963 | if (aCmd.HasOption ("followRotation", 1, Standard_True)) | |
9964 | { | |
9965 | aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation")); | |
9966 | } | |
9967 | if (aCmd.HasOption ("gap", 1, Standard_True)) | |
9968 | { | |
9969 | aManipulator->SetGap (aCmd.ArgFloat ("gap")); | |
9970 | } | |
9971 | if (aCmd.HasOption ("part", 3, Standard_True)) | |
9972 | { | |
9973 | Standard_Integer anAxis = aCmd.ArgInt ("part", 0); | |
9974 | Standard_Integer aMode = aCmd.ArgInt ("part", 1); | |
9975 | Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2); | |
9976 | if (aMode < 1 || aMode > 3) | |
9977 | { | |
9978 | std::cerr << theArgVec[0] << " error: mode value should be in range [1, 3].\n"; | |
9979 | return 1; | |
9980 | } | |
9981 | ||
9982 | aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff); | |
9983 | } | |
9984 | if (aCmd.HasOption ("pos", 3, Standard_True)) | |
9985 | { | |
9986 | gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0); | |
9987 | gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction(); | |
9988 | gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection(); | |
9989 | ||
9990 | aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir)); | |
9991 | } | |
9992 | if (aCmd.HasOption ("size", 1, Standard_True)) | |
9993 | { | |
9994 | aManipulator->SetSize (aCmd.ArgFloat ("size")); | |
9995 | } | |
9996 | if (aCmd.HasOption ("zoomable", 1, Standard_True)) | |
9997 | { | |
9998 | aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable")); | |
9999 | ||
10000 | if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator)) | |
10001 | { | |
10002 | ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False); | |
10003 | ViewerTest::GetAISContext()->Display (aManipulator, Standard_False); | |
10004 | } | |
10005 | } | |
10006 | ||
10007 | // --------------------------------------------------- | |
10008 | // attach, detach or access manipulator from an object | |
10009 | // --------------------------------------------------- | |
10010 | ||
10011 | if (aCmd.HasOption ("attach")) | |
10012 | { | |
10013 | // Find an object and attach manipulator to it | |
10014 | if (!aCmd.HasOption ("attach", 1, Standard_True)) | |
10015 | { | |
10016 | return 1; | |
10017 | } | |
10018 | ||
10019 | TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str()); | |
10020 | if (!aMapAIS.IsBound2 (anObjName)) | |
10021 | { | |
10022 | std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n"; | |
10023 | return 1; | |
10024 | } | |
10025 | ||
10026 | Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (aMapAIS.Find2 (anObjName)); | |
10027 | ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators()); | |
10028 | for (; anIt.More(); anIt.Next()) | |
10029 | { | |
10030 | if (anIt.Value()->IsAttached() | |
10031 | && anIt.Value()->Object() == anObject) | |
10032 | { | |
10033 | std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n"; | |
10034 | return 1; | |
10035 | } | |
10036 | } | |
10037 | ||
10038 | AIS_Manipulator::OptionsForAttach anOptions; | |
10039 | if (aCmd.HasOption ("adjustPosition", 1, Standard_True)) | |
10040 | { | |
10041 | anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition")); | |
10042 | } | |
10043 | if (aCmd.HasOption ("adjustSize", 1, Standard_True)) | |
10044 | { | |
10045 | anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize")); | |
10046 | } | |
10047 | if (aCmd.HasOption ("enableModes", 1, Standard_True)) | |
10048 | { | |
10049 | anOptions.SetEnableModes (aCmd.ArgBool ("enableModes")); | |
10050 | } | |
10051 | ||
10052 | aManipulator->Attach (anObject, anOptions); | |
10053 | } | |
10054 | ||
10055 | // -------------------------------------- | |
10056 | // apply transformation using manipulator | |
10057 | // -------------------------------------- | |
10058 | ||
10059 | if (aCmd.HasOption ("startTransform", 2, Standard_True)) | |
10060 | { | |
10061 | aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView()); | |
10062 | } | |
10063 | if (aCmd.HasOption ("transform", 2, Standard_True)) | |
10064 | { | |
10065 | aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView()); | |
10066 | } | |
10067 | if (aCmd.HasOption ("stopTransform")) | |
10068 | { | |
10069 | Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort"); | |
10070 | ||
10071 | aManipulator->StopTransform (toApply); | |
10072 | } | |
10073 | ||
10074 | gp_Trsf aT; | |
10075 | if (aCmd.HasOption ("move", 3, Standard_True)) | |
10076 | { | |
10077 | aT.SetTranslationPart (aCmd.ArgVec ("move")); | |
10078 | } | |
10079 | if (aCmd.HasOption ("rotate", 7, Standard_True)) | |
10080 | { | |
10081 | aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6)); | |
10082 | } | |
10083 | if (aCmd.HasOption ("scale", 1)) | |
10084 | { | |
10085 | aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale")); | |
10086 | } | |
10087 | ||
10088 | if (aT.Form() != gp_Identity) | |
10089 | { | |
10090 | aManipulator->Transform (aT); | |
10091 | } | |
10092 | ||
0577ae8c | 10093 | ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True); |
625e1958 | 10094 | |
10095 | return 0; | |
10096 | } | |
10097 | ||
8e5fb5ea | 10098 | //=============================================================================================== |
10099 | //function : VSelectionProperties | |
10100 | //purpose : | |
10101 | //=============================================================================================== | |
10102 | static int VSelectionProperties (Draw_Interpretor& theDi, | |
10103 | Standard_Integer theArgsNb, | |
10104 | const char** theArgVec) | |
10105 | { | |
10106 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); | |
10107 | if (aCtx.IsNull()) | |
10108 | { | |
10109 | std::cerr << "No active viewer!\n"; | |
10110 | return 1; | |
10111 | } | |
10112 | ||
f838dac4 | 10113 | Standard_Boolean toPrint = theArgsNb == 1; |
10114 | Standard_Boolean toRedraw = Standard_False; | |
10115 | Standard_Integer anArgIter = 1; | |
10116 | Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None; | |
10117 | if (anArgIter < theArgsNb) | |
10118 | { | |
10119 | TCollection_AsciiString anArgFirst (theArgVec[anArgIter]); | |
10120 | anArgFirst.LowerCase(); | |
10121 | ++anArgIter; | |
10122 | if (anArgFirst == "dynhighlight" | |
10123 | || anArgFirst == "dynhilight" | |
10124 | || anArgFirst == "dynamichighlight" | |
10125 | || anArgFirst == "dynamichilight") | |
10126 | { | |
10127 | aType = Prs3d_TypeOfHighlight_Dynamic; | |
10128 | } | |
10129 | else if (anArgFirst == "localdynhighlight" | |
10130 | || anArgFirst == "localdynhilight" | |
10131 | || anArgFirst == "localdynamichighlight" | |
10132 | || anArgFirst == "localdynamichilight") | |
10133 | { | |
10134 | aType = Prs3d_TypeOfHighlight_LocalDynamic; | |
10135 | } | |
10136 | else if (anArgFirst == "selhighlight" | |
10137 | || anArgFirst == "selhilight" | |
10138 | || anArgFirst == "selectedhighlight" | |
10139 | || anArgFirst == "selectedhilight") | |
10140 | { | |
10141 | aType = Prs3d_TypeOfHighlight_Selected; | |
10142 | } | |
10143 | else if (anArgFirst == "localselhighlight" | |
10144 | || anArgFirst == "localselhilight" | |
10145 | || anArgFirst == "localselectedhighlight" | |
10146 | || anArgFirst == "localselectedhilight") | |
10147 | { | |
10148 | aType = Prs3d_TypeOfHighlight_LocalSelected; | |
10149 | } | |
10150 | else | |
10151 | { | |
10152 | --anArgIter; | |
10153 | } | |
10154 | } | |
10155 | for (; anArgIter < theArgsNb; ++anArgIter) | |
10156 | { | |
10157 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
10158 | anArg.LowerCase(); | |
10159 | if (anArg == "-help") | |
10160 | { | |
10161 | theDi.PrintHelp (theArgVec[0]); | |
10162 | return 0; | |
10163 | } | |
10164 | else if (anArg == "-print") | |
10165 | { | |
10166 | toPrint = Standard_True; | |
10167 | } | |
10168 | else if (anArg == "-autoactivate") | |
10169 | { | |
10170 | Standard_Boolean toEnable = Standard_True; | |
10171 | if (anArgIter + 1 < theArgsNb | |
10172 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
10173 | { | |
10174 | ++anArgIter; | |
10175 | } | |
10176 | aCtx->SetAutoActivateSelection (toEnable); | |
10177 | } | |
14c4193d | 10178 | else if (anArg == "-pickstrategy" |
10179 | || anArg == "-pickingstrategy") | |
10180 | { | |
10181 | if (++anArgIter >= theArgsNb) | |
10182 | { | |
10183 | std::cout << "Syntax error: type of highlighting is undefined\n"; | |
10184 | return 1; | |
10185 | } | |
10186 | ||
10187 | SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable; | |
10188 | TCollection_AsciiString aVal (theArgVec[anArgIter]); | |
10189 | aVal.LowerCase(); | |
10190 | if (aVal == "first" | |
10191 | || aVal == "firstaccepted" | |
10192 | || aVal == "firstacceptable") | |
10193 | { | |
10194 | aStrategy = SelectMgr_PickingStrategy_FirstAcceptable; | |
10195 | } | |
10196 | else if (aVal == "topmost" | |
10197 | || aVal == "onlyTopmost") | |
10198 | { | |
10199 | aStrategy = SelectMgr_PickingStrategy_OnlyTopmost; | |
10200 | } | |
10201 | else | |
10202 | { | |
10203 | std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n"; | |
10204 | return 1; | |
10205 | } | |
10206 | ||
10207 | aCtx->SetPickingStrategy (aStrategy); | |
10208 | } | |
f838dac4 | 10209 | else if (anArg == "-pixtol" |
10210 | && anArgIter + 1 < theArgsNb) | |
10211 | { | |
10212 | aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter])); | |
10213 | } | |
10214 | else if ((anArg == "-mode" | |
10215 | || anArg == "-dispmode") | |
10216 | && anArgIter + 1 < theArgsNb) | |
10217 | { | |
10218 | if (aType == Prs3d_TypeOfHighlight_None) | |
10219 | { | |
10220 | std::cout << "Syntax error: type of highlighting is undefined\n"; | |
10221 | return 1; | |
10222 | } | |
8e5fb5ea | 10223 | |
f838dac4 | 10224 | const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]); |
10225 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); | |
10226 | aStyle->SetDisplayMode (aDispMode); | |
10227 | toRedraw = Standard_True; | |
10228 | } | |
10229 | else if (anArg == "-layer" | |
10230 | && anArgIter + 1 < theArgsNb) | |
10231 | { | |
10232 | if (aType == Prs3d_TypeOfHighlight_None) | |
10233 | { | |
10234 | std::cout << "Syntax error: type of highlighting is undefined\n"; | |
10235 | return 1; | |
10236 | } | |
8e5fb5ea | 10237 | |
f838dac4 | 10238 | const Standard_Integer aNewLayer = Draw::Atoi (theArgVec[++anArgIter]); |
10239 | if (aNewLayer != Graphic3d_ZLayerId_UNKNOWN) | |
10240 | { | |
10241 | TColStd_SequenceOfInteger aLayers; | |
10242 | aCtx->CurrentViewer()->GetAllZLayers (aLayers); | |
10243 | if (std::find (aLayers.begin(), aLayers.end(), aNewLayer) == aLayers.end()) | |
10244 | { | |
10245 | std::cout << "Syntax error: Layer " << aNewLayer << " is undefined\n"; | |
10246 | return 1; | |
10247 | } | |
10248 | } | |
8e5fb5ea | 10249 | |
f838dac4 | 10250 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); |
10251 | aStyle->SetZLayer (aNewLayer); | |
10252 | toRedraw = Standard_True; | |
10253 | } | |
10254 | else if (anArg == "-hicolor" | |
10255 | || anArg == "-selcolor" | |
10256 | || anArg == "-color") | |
10257 | { | |
10258 | if (anArg.StartsWith ("-hi")) | |
10259 | { | |
10260 | aType = Prs3d_TypeOfHighlight_Dynamic; | |
10261 | } | |
10262 | else if (anArg.StartsWith ("-sel")) | |
10263 | { | |
10264 | aType = Prs3d_TypeOfHighlight_Selected; | |
10265 | } | |
10266 | else if (aType == Prs3d_TypeOfHighlight_None) | |
10267 | { | |
10268 | std::cout << "Syntax error: type of highlighting is undefined\n"; | |
10269 | return 1; | |
10270 | } | |
8e5fb5ea | 10271 | |
f838dac4 | 10272 | Quantity_Color aColor; |
10273 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1, | |
10274 | theArgVec + anArgIter + 1, | |
10275 | aColor); | |
10276 | if (aNbParsed == 0) | |
10277 | { | |
10278 | std::cout << "Syntax error: need more arguments.\n"; | |
10279 | return 1; | |
10280 | } | |
10281 | anArgIter += aNbParsed; | |
8e5fb5ea | 10282 | |
f838dac4 | 10283 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); |
10284 | aStyle->SetColor (aColor); | |
10285 | toRedraw = Standard_True; | |
10286 | } | |
10287 | else if ((anArg == "-transp" | |
10288 | || anArg == "-transparency" | |
10289 | || anArg == "-hitransp" | |
10290 | || anArg == "-seltransp" | |
10291 | || anArg == "-hitransplocal" | |
10292 | || anArg == "-seltransplocal") | |
10293 | && anArgIter + 1 < theArgsNb) | |
10294 | { | |
10295 | if (anArg.StartsWith ("-hi")) | |
10296 | { | |
10297 | aType = Prs3d_TypeOfHighlight_Dynamic; | |
10298 | } | |
10299 | else if (anArg.StartsWith ("-sel")) | |
10300 | { | |
10301 | aType = Prs3d_TypeOfHighlight_Selected; | |
10302 | } | |
10303 | else if (aType == Prs3d_TypeOfHighlight_None) | |
10304 | { | |
10305 | std::cout << "Syntax error: type of highlighting is undefined\n"; | |
10306 | return 1; | |
10307 | } | |
8e5fb5ea | 10308 | |
f838dac4 | 10309 | const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]); |
10310 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); | |
10311 | aStyle->SetTransparency ((Standard_ShortReal )aTransp); | |
10312 | toRedraw = Standard_True; | |
10313 | } | |
10314 | else if ((anArg == "-mat" | |
10315 | || anArg == "-material") | |
10316 | && anArgIter + 1 < theArgsNb) | |
10317 | { | |
10318 | if (aType == Prs3d_TypeOfHighlight_None) | |
10319 | { | |
10320 | std::cout << "Syntax error: type of highlighting is undefined\n"; | |
10321 | return 1; | |
10322 | } | |
8e5fb5ea | 10323 | |
f838dac4 | 10324 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); |
10325 | Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]); | |
10326 | if (aMatName != Graphic3d_NOM_DEFAULT) | |
10327 | { | |
10328 | ++anArgIter; | |
10329 | Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d(); | |
10330 | *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect(); | |
10331 | Graphic3d_MaterialAspect aMat (aMatName); | |
10332 | aMat.SetColor (aStyle->Color()); | |
10333 | aMat.SetTransparency (aStyle->Transparency()); | |
10334 | anAspect->SetFrontMaterial (aMat); | |
10335 | anAspect->SetInteriorColor (aStyle->Color()); | |
10336 | aStyle->SetBasicFillAreaAspect (anAspect); | |
10337 | } | |
10338 | else | |
10339 | { | |
10340 | aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)()); | |
10341 | } | |
10342 | toRedraw = Standard_True; | |
10343 | } | |
10344 | else | |
10345 | { | |
10346 | std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n"; | |
10347 | } | |
8e5fb5ea | 10348 | } |
10349 | ||
f838dac4 | 10350 | if (toPrint) |
8e5fb5ea | 10351 | { |
f838dac4 | 10352 | const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle(); |
10353 | const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle(); | |
8e5fb5ea | 10354 | theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n"; |
10355 | theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n"; | |
f838dac4 | 10356 | theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n"; |
10357 | theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n"; | |
10358 | theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n"; | |
10359 | theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n"; | |
10360 | theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n"; | |
10361 | theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n"; | |
10362 | theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n"; | |
10363 | theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n"; | |
8e5fb5ea | 10364 | } |
10365 | ||
10366 | if (aCtx->NbSelected() != 0 && toRedraw) | |
10367 | { | |
10368 | aCtx->HilightSelected (Standard_True); | |
10369 | } | |
10370 | ||
10371 | return 0; | |
10372 | } | |
10373 | ||
decdee7d | 10374 | //=============================================================================================== |
10375 | //function : VDumpSelectionImage | |
10376 | //purpose : | |
10377 | //=============================================================================================== | |
10378 | static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/, | |
10379 | Standard_Integer theArgsNb, | |
10380 | const char** theArgVec) | |
10381 | { | |
10382 | if (theArgsNb < 2) | |
10383 | { | |
10384 | std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n"; | |
10385 | return 1; | |
10386 | } | |
10387 | ||
10388 | const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext(); | |
10389 | if (aContext.IsNull()) | |
10390 | { | |
10391 | std::cout << "Error: no active view.\n"; | |
10392 | return 1; | |
10393 | } | |
10394 | ||
10395 | TCollection_AsciiString aFile; | |
10396 | StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth; | |
dc858f4c | 10397 | Image_Format anImgFormat = Image_Format_BGR; |
decdee7d | 10398 | Standard_Integer aPickedIndex = 1; |
10399 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
10400 | { | |
10401 | TCollection_AsciiString aParam (theArgVec[anArgIter]); | |
10402 | aParam.LowerCase(); | |
10403 | if (aParam == "-type") | |
10404 | { | |
10405 | if (++anArgIter >= theArgsNb) | |
10406 | { | |
10407 | std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n"; | |
10408 | return 1; | |
10409 | } | |
10410 | ||
10411 | TCollection_AsciiString aValue (theArgVec[anArgIter]); | |
10412 | aValue.LowerCase(); | |
10413 | if (aValue == "depth" | |
10414 | || aValue == "normdepth" | |
10415 | || aValue == "normalizeddepth") | |
10416 | { | |
10417 | aType = StdSelect_TypeOfSelectionImage_NormalizedDepth; | |
dc858f4c | 10418 | anImgFormat = Image_Format_GrayF; |
decdee7d | 10419 | } |
10420 | if (aValue == "depthinverted" | |
10421 | || aValue == "normdepthinverted" | |
10422 | || aValue == "normalizeddepthinverted" | |
10423 | || aValue == "inverted") | |
10424 | { | |
10425 | aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted; | |
dc858f4c | 10426 | anImgFormat = Image_Format_GrayF; |
decdee7d | 10427 | } |
10428 | else if (aValue == "unnormdepth" | |
10429 | || aValue == "unnormalizeddepth") | |
10430 | { | |
10431 | aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth; | |
dc858f4c | 10432 | anImgFormat = Image_Format_GrayF; |
decdee7d | 10433 | } |
10434 | else if (aValue == "objectcolor" | |
10435 | || aValue == "object" | |
10436 | || aValue == "color") | |
10437 | { | |
10438 | aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject; | |
10439 | } | |
10440 | else if (aValue == "entitycolor" | |
10441 | || aValue == "entity") | |
10442 | { | |
10443 | aType = StdSelect_TypeOfSelectionImage_ColoredEntity; | |
10444 | } | |
10445 | else if (aValue == "ownercolor" | |
10446 | || aValue == "owner") | |
10447 | { | |
10448 | aType = StdSelect_TypeOfSelectionImage_ColoredOwner; | |
10449 | } | |
10450 | else if (aValue == "selectionmodecolor" | |
10451 | || aValue == "selectionmode" | |
10452 | || aValue == "selmodecolor" | |
10453 | || aValue == "selmode") | |
10454 | { | |
10455 | aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode; | |
10456 | } | |
10457 | } | |
10458 | else if (aParam == "-picked" | |
10459 | || aParam == "-pickeddepth" | |
10460 | || aParam == "-pickedindex") | |
10461 | { | |
10462 | if (++anArgIter >= theArgsNb) | |
10463 | { | |
10464 | std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n"; | |
10465 | return 1; | |
10466 | } | |
10467 | ||
10468 | aPickedIndex = Draw::Atoi (theArgVec[anArgIter]); | |
10469 | } | |
10470 | else if (aFile.IsEmpty()) | |
10471 | { | |
10472 | aFile = theArgVec[anArgIter]; | |
10473 | } | |
10474 | else | |
10475 | { | |
10476 | std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n"; | |
10477 | return 1; | |
10478 | } | |
10479 | } | |
10480 | if (aFile.IsEmpty()) | |
10481 | { | |
10482 | std::cout << "Syntax error: image file name is missing.\n"; | |
10483 | return 1; | |
10484 | } | |
10485 | ||
10486 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); | |
10487 | Standard_Integer aWidth = 0, aHeight = 0; | |
10488 | aView->Window()->Size (aWidth, aHeight); | |
10489 | ||
10490 | Image_AlienPixMap aPixMap; | |
10491 | if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight)) | |
10492 | { | |
10493 | std::cout << "Error: can't allocate image.\n"; | |
10494 | return 1; | |
10495 | } | |
10496 | if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex)) | |
10497 | { | |
10498 | std::cout << "Error: can't generate selection image.\n"; | |
10499 | return 1; | |
10500 | } | |
10501 | if (!aPixMap.Save (aFile)) | |
10502 | { | |
10503 | std::cout << "Error: can't save selection image.\n"; | |
10504 | return 0; | |
10505 | } | |
10506 | return 0; | |
10507 | } | |
10508 | ||
7fd59977 | 10509 | //======================================================================= |
10510 | //function : ViewerCommands | |
10511 | //purpose : | |
10512 | //======================================================================= | |
10513 | ||
10514 | void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) | |
10515 | { | |
10516 | ||
10517 | const char *group = "ZeViewer"; | |
18d715bd | 10518 | theCommands.Add("vinit", |
10519 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
10520 | "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n" | |
10521 | #else | |
10522 | "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n" | |
10523 | #endif | |
10524 | " - Creates new View window with specified name view_name.\n" | |
10525 | "By default the new view is created in the viewer and in" | |
10526 | " graphic driver shared with active view.\n" | |
10527 | " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n" | |
10528 | "If driverName isn't specified the driver will be shared with active view.\n" | |
10529 | "If viewerName isn't specified the viewer will be shared with active view.\n" | |
10530 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
10531 | " - display = HostName.DisplayNumber[:ScreenNumber] : if specified" | |
10532 | "is used in creation of graphic driver\n" | |
10533 | #endif | |
10534 | " - l, t: pixel position of left top corner of the window\n" | |
10535 | " - w,h: width and heigth of window respectively.\n" | |
10536 | "Additional commands for operations with views: vclose, vactivate, vviewlist.\n", | |
7fd59977 | 10537 | __FILE__,VInit,group); |
18d715bd | 10538 | theCommands.Add("vclose" , |
d0cc1cb7 | 10539 | "[view_id [keep_context=0|1]]\n" |
18d715bd | 10540 | "or vclose ALL - to remove all created views\n" |
10541 | " - removes view(viewer window) defined by its view_id.\n" | |
10542 | " - keep_context: by default 0; if 1 and the last view is deleted" | |
10543 | " the current context is not removed.", | |
10544 | __FILE__,VClose,group); | |
10545 | theCommands.Add("vactivate" , | |
10546 | "view_id" | |
10547 | " - activates view(viewer window) defined by its view_id", | |
10548 | __FILE__,VActivate,group); | |
10549 | theCommands.Add("vviewlist", | |
10550 | "vviewlist [format={tree, long}]" | |
10551 | " - prints current list of views per viewer and graphic_driver ID shared between viewers" | |
10552 | " - format: format of result output, if tree the output is a tree view;" | |
10553 | "otherwise it's a list of full view names. By default format = tree", | |
10554 | __FILE__,VViewList,group); | |
7fd59977 | 10555 | theCommands.Add("vhelp" , |
10556 | "vhelp : display help on the viewer commands", | |
10557 | __FILE__,VHelp,group); | |
10558 | theCommands.Add("vtop" , | |
27af3052 | 10559 | "vtop or <T> : Top view. Orientation +X+Y" , |
7fd59977 | 10560 | __FILE__,VTop,group); |
44b8f2d6 | 10561 | theCommands.Add("vbottom" , |
27af3052 | 10562 | "vbottom : Bottom view. Orientation +X-Y" , |
44b8f2d6 | 10563 | __FILE__,VBottom,group); |
10564 | theCommands.Add("vleft" , | |
27af3052 | 10565 | "vleft : Left view. Orientation -Y+Z" , |
44b8f2d6 | 10566 | __FILE__,VLeft,group); |
10567 | theCommands.Add("vright" , | |
27af3052 | 10568 | "vright : Right view. Orientation +Y+Z" , |
44b8f2d6 | 10569 | __FILE__,VRight,group); |
7fd59977 | 10570 | theCommands.Add("vaxo" , |
27af3052 | 10571 | " vaxo or <A> : Axonometric view. Orientation +X-Y+Z", |
7fd59977 | 10572 | __FILE__,VAxo,group); |
44b8f2d6 | 10573 | theCommands.Add("vfront" , |
27af3052 | 10574 | "vfront : Front view. Orientation +X+Z" , |
44b8f2d6 | 10575 | __FILE__,VFront,group); |
10576 | theCommands.Add("vback" , | |
27af3052 | 10577 | "vback : Back view. Orientation -X+Z" , |
44b8f2d6 | 10578 | __FILE__,VBack,group); |
7fd59977 | 10579 | theCommands.Add("vpick" , |
10580 | "vpick : vpick X Y Z [shape subshape] ( all variables as string )", | |
10581 | VPick,group); | |
1beb58d7 | 10582 | theCommands.Add("vfit", |
10583 | "vfit or <F> [-selected] [-noupdate]" | |
b586500b | 10584 | "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects", |
7fd59977 | 10585 | __FILE__,VFit,group); |
6262a303 | 10586 | theCommands.Add ("vfitarea", |
10587 | "vfitarea x1 y1 x2 y2" | |
10588 | "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2" | |
10589 | "\n\t\t: Fit view to show area located between two points" | |
10590 | "\n\t\t: given in world 2D or 3D corrdinates.", | |
10591 | __FILE__, VFitArea, group); | |
197ac94e | 10592 | theCommands.Add ("vzfit", "vzfit [scale]\n" |
10593 | " Matches Z near, Z far view volume planes to the displayed objects.\n" | |
10594 | " \"scale\" - specifies factor to scale computed z range.\n", | |
10595 | __FILE__, VZFit, group); | |
7fd59977 | 10596 | theCommands.Add("vrepaint", |
56689b27 | 10597 | "vrepaint [-immediate]" |
10598 | "\n\t\t: force redraw", | |
7fd59977 | 10599 | __FILE__,VRepaint,group); |
10600 | theCommands.Add("vclear", | |
faea8b40 | 10601 | "vclear : vclear" |
10602 | "\n\t\t: remove all the object from the viewer", | |
7fd59977 | 10603 | __FILE__,VClear,group); |
10604 | theCommands.Add("vsetbg", | |
10605 | "vsetbg : vsetbg imagefile [filltype] : Load image as background", | |
10606 | __FILE__,VSetBg,group); | |
f8b2ed36 | 10607 | theCommands.Add("vsetbgmode", |
10608 | "vsetbgmode : vsetbgmode filltype : Change background image fill type", | |
10609 | __FILE__,VSetBgMode,group); | |
7fd59977 | 10610 | theCommands.Add("vsetgradientbg", |
f8b2ed36 | 10611 | "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background", |
7fd59977 | 10612 | __FILE__,VSetGradientBg,group); |
f8b2ed36 | 10613 | theCommands.Add("vsetgrbgmode", |
10614 | "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type", | |
10615 | __FILE__,VSetGradientBgMode,group); | |
10616 | theCommands.Add("vsetcolorbg", | |
10617 | "vsetcolorbg : vsetcolorbg r g b : Set background color", | |
10618 | __FILE__,VSetColorBg,group); | |
f42753ed | 10619 | theCommands.Add("vsetdefaultbg", |
10620 | "vsetdefaultbg r g b\n" | |
10621 | "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode" | |
10622 | "\n\t\t: Set default viewer background fill color (flat/gradient).", | |
10623 | __FILE__,VSetDefaultBg,group); | |
7fd59977 | 10624 | theCommands.Add("vscale", |
10625 | "vscale : vscale X Y Z", | |
10626 | __FILE__,VScale,group); | |
10627 | theCommands.Add("vzbufftrihedron", | |
536d98e2 | 10628 | "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]" |
10629 | "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]" | |
10630 | "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]" | |
10631 | "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]" | |
10632 | "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]" | |
10633 | "\n\t\t: Displays a trihedron", | |
10634 | __FILE__,VZBuffTrihedron,group); | |
7fd59977 | 10635 | theCommands.Add("vrotate", |
4af098ba | 10636 | "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]" |
10637 | "\n : Option -mouseStart starts rotation according to the mouse position" | |
10638 | "\n : Option -mouseMove continues rotation with angle computed" | |
10639 | "\n : from last and new mouse position." | |
10640 | "\n : vrotate AX AY AZ [X Y Z]", | |
7fd59977 | 10641 | __FILE__,VRotate,group); |
10642 | theCommands.Add("vzoom", | |
10643 | "vzoom : vzoom coef", | |
10644 | __FILE__,VZoom,group); | |
10645 | theCommands.Add("vpan", | |
10646 | "vpan : vpan dx dy", | |
10647 | __FILE__,VPan,group); | |
10648 | theCommands.Add("vexport", | |
5cedc27f K |
10649 | "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }" |
10650 | " : exports the view to a vector file of a given format" | |
10651 | " : notice that EMF format requires patched gl2ps", | |
7fd59977 | 10652 | __FILE__,VExport,group); |
10653 | theCommands.Add("vcolorscale", | |
4b3d6eb1 | 10654 | "vcolorscale name [-noupdate|-update] [-demo]" |
10655 | "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]" | |
10656 | "\n\t\t: [-font HeightFont=20]" | |
10657 | "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]" | |
10658 | "\n\t\t: [-smoothTransition {on|off}=off]" | |
10659 | "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]" | |
10660 | "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]" | |
10661 | "\n\t\t: [-textpos {left|right|center|none}=right]" | |
10662 | "\n\t\t: [-labelAtBorder {on|off}=on]" | |
10663 | "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]" | |
10664 | "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]" | |
10665 | "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]" | |
10666 | "\n\t\t: [-xy Left=0 Bottom=0]" | |
10667 | "\n\t\t: -demo - displays a color scale with demonstratio values" | |
10668 | "\n\t\t: -colors - set colors for all intervals" | |
10669 | "\n\t\t: -color - set color for specific interval" | |
10670 | "\n\t\t: -textpos - horizontal label position relative to color scale bar" | |
10671 | "\n\t\t: -labelAtBorder - vertical label position relative to color interval;" | |
10672 | "\n\t\t: at border means the value inbetween neighbor intervals," | |
10673 | "\n\t\t: at center means the center value within current interval" | |
10674 | "\n\t\t: -labels - set labels for all intervals" | |
10675 | "\n\t\t: -freeLabels - same as -labels but does not require" | |
10676 | "\n\t\t: matching the number of intervals" | |
10677 | "\n\t\t: -label - set label for specific interval" | |
10678 | "\n\t\t: -title - set title" | |
10679 | "\n\t\t: -reversed - setup smooth color transition between intervals" | |
10680 | "\n\t\t: -smoothTransition - swap colorscale direction" | |
10681 | "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values" | |
10682 | __FILE__, VColorScale, group); | |
7fd59977 | 10683 | theCommands.Add("vgraduatedtrihedron", |
a79f67f8 | 10684 | "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n" |
10685 | "\t[-namefont Name] [-valuesfont Name]\n" | |
10686 | "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n" | |
10687 | "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]" | |
10688 | "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n" | |
10689 | "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n" | |
10690 | "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]" | |
10691 | "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n" | |
10692 | "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n" | |
10693 | "\t[-xticks Number] [-yticks Number] [-zticks Number]\n" | |
10694 | "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n" | |
536d98e2 | 10695 | "\t[-drawgrid on/off] [-drawaxes on/off]\n" |
a79f67f8 | 10696 | " - Displays or erases graduated trihedron" |
10697 | " - xname, yname, zname - names of axes, default: X, Y, Z\n" | |
10698 | " - namefont - font of axes names. Default: Arial\n" | |
10699 | " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n" | |
10700 | " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n" | |
10701 | " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n" | |
10702 | " - valuesfont - font of axes values. Default: Arial\n" | |
10703 | " - xcolor, ycolor, zcolor - color of axis and values\n" | |
10704 | " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n" | |
10705 | " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n", | |
7fd59977 | 10706 | __FILE__,VGraduatedTrihedron,group); |
3bffef55 | 10707 | theCommands.Add("vtile" , |
10708 | "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]" | |
10709 | "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)." | |
10710 | "\n\t\t: -totalSize the size of virtual bigger viewport" | |
10711 | "\n\t\t: -tileSize tile size (the view size will be used if omitted)" | |
10712 | "\n\t\t: -lowerLeft tile offset as lower left corner" | |
10713 | "\n\t\t: -upperLeft tile offset as upper left corner", | |
10714 | __FILE__, VTile, group); | |
59f45b7c | 10715 | theCommands.Add("vzlayer", |
7c3ef2f7 | 10716 | "vzlayer [layerId]" |
10717 | "\n\t\t: [-add|-delete|-get|-settings]" | |
10718 | "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]" | |
10719 | "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv}]" | |
10720 | "\n\t\t: ZLayer list management:" | |
10721 | "\n\t\t: -add add new z layer to viewer and print its id" | |
10722 | "\n\t\t: -delete delete z layer" | |
10723 | "\n\t\t: -get print sequence of z layers" | |
10724 | "\n\t\t: -settings print status of z layer settings" | |
10725 | "\n\t\t: -disable disables given setting" | |
10726 | "\n\t\t: -enable enables given setting", | |
59f45b7c | 10727 | __FILE__,VZLayer,group); |
20637bd2 | 10728 | theCommands.Add("vlayerline", |
10729 | "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]", | |
10730 | __FILE__,VLayerLine,group); | |
2bd4c032 | 10731 | theCommands.Add ("vgrid", |
10732 | "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]" | |
10733 | " : Mode - rectangular or circular" | |
10734 | " : Type - lines or points", | |
10735 | __FILE__, VGrid, group); | |
c40b7d58 | 10736 | theCommands.Add ("vpriviledgedplane", |
10737 | "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]" | |
10738 | "\n\t\t: Ox, Oy, Oz - plane origin" | |
10739 | "\n\t\t: Nx, Ny, Nz - plane normal direction" | |
10740 | "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction" | |
10741 | "\n\t\t: Sets or prints viewer's priviledged plane geometry.", | |
10742 | __FILE__, VPriviledgedPlane, group); | |
f25b82d6 | 10743 | theCommands.Add ("vconvert", |
10744 | "vconvert v [Mode={window|view}]" | |
10745 | "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]" | |
10746 | "\n\t\t: vconvert x y z [Mode={window|grid}]" | |
10747 | "\n\t\t: window - convert to window coordinates, pixels" | |
10748 | "\n\t\t: view - convert to view projection plane" | |
10749 | "\n\t\t: grid - convert to model coordinates, given on grid" | |
10750 | "\n\t\t: ray - convert projection ray to model coordiantes" | |
10751 | "\n\t\t: - vconvert v window : convert view to window;" | |
10752 | "\n\t\t: - vconvert v view : convert window to view;" | |
10753 | "\n\t\t: - vconvert x y window : convert view to window;" | |
10754 | "\n\t\t: - vconvert x y view : convert window to view;" | |
10755 | "\n\t\t: - vconvert x y : convert window to model;" | |
10756 | "\n\t\t: - vconvert x y grid : convert window to model using grid;" | |
10757 | "\n\t\t: - vconvert x y ray : convert window projection line to model;" | |
10758 | "\n\t\t: - vconvert x y z window : convert model to window;" | |
10759 | "\n\t\t: - vconvert x y z grid : convert view to model using grid;" | |
10760 | "\n\t\t: Converts the given coordinates to window/view/model space.", | |
10761 | __FILE__, VConvert, group); | |
208e6839 | 10762 | theCommands.Add ("vfps", |
10763 | "vfps [framesNb=100] : estimate average frame rate for active view", | |
10764 | __FILE__, VFps, group); | |
58655684 | 10765 | theCommands.Add ("vgldebug", |
c87535af | 10766 | "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]" |
10767 | "\n\t\t: [-extraMsg {0|1}] [{0|1}]" | |
10768 | "\n\t\t: Request debug GL context. Should be called BEFORE vinit." | |
10769 | "\n\t\t: Debug context can be requested only on Windows" | |
10770 | "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!" | |
10771 | "\n\t\t: -sync - request synchronized debug GL context" | |
10772 | "\n\t\t: -glslWarn - log GLSL compiler/linker warnings," | |
10773 | "\n\t\t: which are suppressed by default," | |
10774 | "\n\t\t: -extraMsg - log extra diagnostic messages from GL context," | |
10775 | "\n\t\t: which are suppressed by default", | |
58655684 | 10776 | __FILE__, VGlDebug, group); |
208e6839 | 10777 | theCommands.Add ("vvbo", |
58655684 | 10778 | "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects", |
208e6839 | 10779 | __FILE__, VVbo, group); |
b5ac8292 | 10780 | theCommands.Add ("vstereo", |
f978241f | 10781 | "vstereo [0|1] [-mode Mode] [-reverse {0|1}]" |
10782 | "\n\t\t: [-anaglyph Filter]" | |
10783 | "\n\t\t: Control stereo output mode. Available modes for -mode:" | |
10784 | "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo," | |
10785 | "\n\t\t: requires driver support." | |
10786 | "\n\t\t: Should be called BEFORE vinit!" | |
10787 | "\n\t\t: anaglyph - Anaglyph glasses" | |
10788 | "\n\t\t: rowInterlaced - row-interlaced display" | |
10789 | "\n\t\t: columnInterlaced - column-interlaced display" | |
10790 | "\n\t\t: chessBoard - chess-board output" | |
10791 | "\n\t\t: sideBySide - horizontal pair" | |
10792 | "\n\t\t: overUnder - vertical pair" | |
10793 | "\n\t\t: Available Anaglyph filters for -anaglyph:" | |
10794 | "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple," | |
10795 | "\n\t\t: greenMagentaSimple", | |
b5ac8292 | 10796 | __FILE__, VStereo, group); |
a577aaab | 10797 | theCommands.Add ("vcaps", |
8625ef7e | 10798 | "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]" |
1dfe71a6 | 10799 | "\n\t\t: [-compatibleProfile {0|1}]" |
56689b27 | 10800 | "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]" |
f978241f | 10801 | "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]" |
8625ef7e | 10802 | "\n\t\t: [-softMode {0|1}] [-noupdate|-update]" |
10803 | "\n\t\t: Modify particular graphic driver options:" | |
10804 | "\n\t\t: FFP - use fixed-function pipeline instead of" | |
10805 | "\n\t\t: built-in GLSL programs" | |
4e1523ef | 10806 | "\n\t\t: (requires compatible profile)" |
8625ef7e | 10807 | "\n\t\t: VBO - use Vertex Buffer Object (copy vertex" |
10808 | "\n\t\t: arrays to GPU memory)" | |
10809 | "\n\t\t: sprite - use textured sprites instead of bitmaps" | |
f978241f | 10810 | "\n\t\t: vsync - switch VSync on or off" |
56689b27 | 10811 | "\n\t\t: winBuffer - allow using window buffer for rendering" |
4e1523ef | 10812 | "\n\t\t: Context creation options:" |
10813 | "\n\t\t: softMode - software OpenGL implementation" | |
10814 | "\n\t\t: compatibleProfile - backward-compatible profile" | |
f978241f | 10815 | "\n\t\t: quadbuffer - QuadBuffer" |
8625ef7e | 10816 | "\n\t\t: Unlike vrenderparams, these parameters control alternative" |
10817 | "\n\t\t: rendering paths producing the same visual result when" | |
10818 | "\n\t\t: possible." | |
10819 | "\n\t\t: Command is intended for testing old hardware compatibility.", | |
a577aaab | 10820 | __FILE__, VCaps, group); |
f0430952 | 10821 | theCommands.Add ("vmemgpu", |
10822 | "vmemgpu [f]: print system-dependent GPU memory information if available;" | |
10823 | " with f option returns free memory in bytes", | |
10824 | __FILE__, VMemGpu, group); | |
85e096c3 | 10825 | theCommands.Add ("vreadpixel", |
10826 | "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]" | |
10827 | " : Read pixel value for active view", | |
10828 | __FILE__, VReadPixel, group); | |
692613e5 | 10829 | theCommands.Add("diffimage", |
10830 | "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]", | |
10831 | __FILE__, VDiffImage, group); | |
4754e164 | 10832 | theCommands.Add ("vselect", |
2157d6ac | 10833 | "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n" |
4754e164 | 10834 | "- emulates different types of selection:\n" |
10835 | "- 1) single click selection\n" | |
10836 | "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n" | |
10837 | "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n" | |
faea8b40 | 10838 | "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n" |
10839 | " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n" | |
10840 | " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. " | |
2157d6ac | 10841 | " (partial inclusion - overlap - is not allowed by default)\n" |
10842 | "- 5) any of these selections with shift button pressed", | |
4754e164 | 10843 | __FILE__, VSelect, group); |
10844 | theCommands.Add ("vmoveto", | |
10845 | "vmoveto x y" | |
10846 | "- emulates cursor movement to pixel postion (x,y)", | |
10847 | __FILE__, VMoveTo, group); | |
1beb58d7 | 10848 | theCommands.Add ("vviewparams", |
10849 | "vviewparams [-args] [-scale [s]]" | |
10850 | "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]" | |
10851 | "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]" | |
10852 | "\n\t\t: Manage current view parameters or prints all" | |
10853 | "\n\t\t: current values when called without argument." | |
10854 | "\n\t\t: -scale [s] prints or sets viewport relative scale" | |
10855 | "\n\t\t: -eye [x y z] prints or sets eye location" | |
10856 | "\n\t\t: -at [x y z] prints or sets center of look" | |
10857 | "\n\t\t: -up [x y z] prints or sets direction of up vector" | |
10858 | "\n\t\t: -proj [x y z] prints or sets direction of look" | |
10859 | "\n\t\t: -center x y sets location of center of the screen in pixels" | |
10860 | "\n\t\t: -size [sx] prints viewport projection width and height sizes" | |
10861 | "\n\t\t: or changes the size of its maximum dimension" | |
10862 | "\n\t\t: -args prints vviewparams arguments for restoring current view", | |
197ac94e | 10863 | __FILE__, VViewParams, group); |
1beb58d7 | 10864 | |
10865 | theCommands.Add("vanimation", "Alias for vanim", | |
10866 | __FILE__, VAnimation, group); | |
10867 | ||
10868 | theCommands.Add("vanim", | |
10869 | "List existing animations:" | |
10870 | "\n\t\t: vanim" | |
10871 | "\n\t\t: Animation playback:" | |
10872 | "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]" | |
10873 | "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]" | |
10874 | "\n\t\t: -speed playback speed (1.0 is normal speed)" | |
10875 | "\n\t\t: -freeLook skip camera animations" | |
10876 | "\n\t\t: -lockLoop disable any interactions" | |
10877 | "\n\t\t:" | |
10878 | "\n\t\t: Animation definition:" | |
10879 | "\n\t\t: vanim Name/sub/name [-clear] [-delete]" | |
10880 | "\n\t\t: [start TimeSec] [duration TimeSec]" | |
10881 | "\n\t\t:" | |
10882 | "\n\t\t: Animation name defined in path-style (anim/name or anim.name)" | |
10883 | "\n\t\t: specifies nested animations." | |
10884 | "\n\t\t: There is no syntax to explicitly add new animation," | |
10885 | "\n\t\t: and all non-existing animations within the name will be" | |
10886 | "\n\t\t: implicitly created on first use (including parents)." | |
10887 | "\n\t\t:" | |
10888 | "\n\t\t: Each animation might define the SINGLE action (see below)," | |
10889 | "\n\t\t: like camera transition, object transformation or custom callback." | |
10890 | "\n\t\t: Child animations can be used for defining concurrent actions." | |
10891 | "\n\t\t:" | |
10892 | "\n\t\t: Camera animation:" | |
10893 | "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]" | |
10894 | "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]" | |
10895 | "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]" | |
10896 | "\n\t\t: [-scale1 Scale] [-scale2 Scale]" | |
10897 | "\n\t\t: -eyeX camera Eye positions pair (start and end)" | |
10898 | "\n\t\t: -atX camera Center positions pair" | |
10899 | "\n\t\t: -upX camera Up directions pair" | |
10900 | "\n\t\t: -scaleX camera Scale factors pair" | |
10901 | "\n\t\t: Object animation:" | |
10902 | "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]" | |
10903 | "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]" | |
10904 | "\n\t\t: [-scale1 Scale] [-scale2 Scale]" | |
10905 | "\n\t\t: -locX object Location points pair (translation)" | |
10906 | "\n\t\t: -rotX object Orientations pair (quaternions)" | |
10907 | "\n\t\t: -scaleX object Scale factors pair (quaternions)" | |
10908 | "\n\t\t: Custom callback:" | |
10909 | "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\"" | |
10910 | "\n\t\t: %Pts overall animation presentation timestamp" | |
10911 | "\n\t\t: %LocalPts local animation timestamp" | |
10912 | "\n\t\t: %Normalized local animation normalized value in range 0..1" | |
10913 | __FILE__, VAnimation, group); | |
10914 | ||
4754e164 | 10915 | theCommands.Add("vchangeselected", |
dc3fe572 | 10916 | "vchangeselected shape" |
4754e164 | 10917 | "- adds to shape to selection or remove one from it", |
10918 | __FILE__, VChangeSelected, group); | |
4754e164 | 10919 | theCommands.Add ("vnbselected", |
faea8b40 | 10920 | "vnbselected" |
10921 | "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group); | |
6b62b2da | 10922 | theCommands.Add ("vcamera", |
10923 | "vcamera [-ortho] [-projtype]" | |
10924 | "\n\t\t: [-persp]" | |
10925 | "\n\t\t: [-fovy [Angle]] [-distance [Distance]]" | |
10926 | "\n\t\t: [-stereo] [-leftEye] [-rightEye]" | |
10927 | "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]" | |
10928 | "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]" | |
10929 | "\n\t\t: Manage camera parameters." | |
10930 | "\n\t\t: Prints current value when option called without argument." | |
10931 | "\n\t\t: Orthographic camera:" | |
10932 | "\n\t\t: -ortho activate orthographic projection" | |
10933 | "\n\t\t: Perspective camera:" | |
10934 | "\n\t\t: -persp activate perspective projection (mono)" | |
10935 | "\n\t\t: -fovy field of view in y axis, in degrees" | |
10936 | "\n\t\t: -distance distance of eye from camera center" | |
10937 | "\n\t\t: Stereoscopic camera:" | |
10938 | "\n\t\t: -stereo perspective projection (stereo)" | |
10939 | "\n\t\t: -leftEye perspective projection (left eye)" | |
10940 | "\n\t\t: -rightEye perspective projection (right eye)" | |
10941 | "\n\t\t: -iod intraocular distance value" | |
10942 | "\n\t\t: -iodType distance type, absolute or relative" | |
10943 | "\n\t\t: -zfocus stereographic focus value" | |
10944 | "\n\t\t: -zfocusType focus type, absolute or relative", | |
10945 | __FILE__, VCamera, group); | |
b5ac8292 | 10946 | theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n" |
197ac94e | 10947 | "- vautozfit [on={1|0}] [scale]\n" |
10948 | " Prints or changes parameters of automatic z-fit mode:\n" | |
10949 | " \"on\" - turns automatic z-fit on or off\n" | |
10950 | " \"scale\" - specifies factor to scale computed z range.\n", | |
10951 | __FILE__, VAutoZFit, group); | |
b5ac8292 | 10952 | theCommands.Add ("vzrange", "command to manually access znear and zfar values\n" |
10953 | " vzrange - without parameters shows current values\n" | |
10954 | " vzrange [znear] [zfar] - applies provided values to view", | |
10955 | __FILE__,VZRange, group); | |
4754e164 | 10956 | theCommands.Add ("vpurgedisplay", |
eb4320f2 | 10957 | "vpurgedisplay" |
4754e164 | 10958 | "- removes structures which don't belong to objects displayed in neutral point", |
10959 | __FILE__, VPurgeDisplay, group); | |
10960 | theCommands.Add("vsetviewsize", | |
10961 | "vsetviewsize size", | |
10962 | __FILE__,VSetViewSize,group); | |
10963 | theCommands.Add("vmoveview", | |
10964 | "vmoveview Dx Dy Dz [Start = 1|0]", | |
10965 | __FILE__,VMoveView,group); | |
10966 | theCommands.Add("vtranslateview", | |
10967 | "vtranslateview Dx Dy Dz [Start = 1|0)]", | |
10968 | __FILE__,VTranslateView,group); | |
10969 | theCommands.Add("vturnview", | |
10970 | "vturnview Ax Ay Az [Start = 1|0]", | |
10971 | __FILE__,VTurnView,group); | |
269294d6 | 10972 | theCommands.Add("vtextureenv", |
10973 | "Enables or disables environment mapping in the 3D view, loading the texture from the given standard " | |
10974 | "or user-defined file and optionally applying texture mapping parameters\n" | |
10975 | " Usage:\n" | |
10976 | " vtextureenv off - disables environment mapping\n" | |
10977 | " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n" | |
10978 | " std_texture = (0..7)\n" | |
10979 | " rep = {clamp|repeat}\n" | |
10980 | " mod = {decal|modulate}\n" | |
10981 | " flt = {nearest|bilinear|trilinear}\n" | |
10982 | " ss, st - scale factors for s and t texture coordinates\n" | |
10983 | " ts, tt - translation for s and t texture coordinates\n" | |
10984 | " rot - texture rotation angle in degrees", | |
10985 | __FILE__, VTextureEnv, group); | |
0a768f56 | 10986 | theCommands.Add("vhlr" , |
e9224045 | 10987 | "is_enabled={on|off} [show_hidden={1|0}]" |
0a768f56 | 10988 | " - Hidden line removal algorithm:" |
e9224045 | 10989 | " - is_enabled: if is on HLR algorithm is applied\n" |
10990 | " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n", | |
0a768f56 | 10991 | __FILE__,VHLR,group); |
10992 | theCommands.Add("vhlrtype" , | |
10993 | "algo_type={algo|polyalgo} [shape_1 ... shape_n]" | |
10994 | " - Changes the type of HLR algorithm using for shapes." | |
10995 | " - algo_type: if equals to algo, exact HLR algorithm is applied;\n" | |
10996 | " if equals to polyalgo, polygonal HLR algorithm is applied." | |
10997 | "If shapes are not given HLR algoithm of given type is applied" | |
10998 | " to all shapes in the view\n", | |
10999 | __FILE__,VHLRType,group); | |
3e05329c | 11000 | theCommands.Add("vclipplane", |
11001 | "vclipplane planeName [{0|1}]" | |
11002 | "\n\t\t: [-equation A B C D]" | |
11003 | "\n\t\t: [-set|-unset [objects|views]]" | |
11004 | "\n\t\t: [-maxPlanes]" | |
11005 | "\n\t\t: [-capping {0|1}]" | |
11006 | "\n\t\t: [-color R G B] [-hatch {on|off|ID}]" | |
11007 | "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]" | |
11008 | "\n\t\t: [-texRotate Angle]" | |
11009 | "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]" | |
11010 | "\n\t\t: [-useObjShader {0|1}]" | |
11011 | "\n\t\t: Clipping planes management:" | |
11012 | "\n\t\t: -maxPlanes print plane limit for view" | |
11013 | "\n\t\t: -delete delete plane with given name" | |
11014 | "\n\t\t: {off|on|0|1} turn clipping on/off" | |
11015 | "\n\t\t: -set|-unset set/unset plane for Object or View list;" | |
11016 | "\n\t\t: applied to active View when list is omitted" | |
11017 | "\n\t\t: -equation A B C D change plane equation" | |
11018 | "\n\t\t: -clone SourcePlane NewPlane clone the plane definition." | |
11019 | "\n\t\t: Capping options:" | |
11020 | "\n\t\t: -capping {off|on|0|1} turn capping on/off" | |
11021 | "\n\t\t: -color R G B set capping color" | |
11022 | "\n\t\t: -texName Texture set capping texture" | |
11023 | "\n\t\t: -texScale SX SY set capping tex scale" | |
11024 | "\n\t\t: -texOrigin TX TY set capping tex origin" | |
11025 | "\n\t\t: -texRotate Angle set capping tex rotation" | |
11026 | "\n\t\t: -hatch {on|off|ID} set capping hatching mask" | |
11027 | "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object" | |
11028 | "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object" | |
11029 | "\n\t\t: -useObjShader {off|on|0|1} use shader program of object", | |
11030 | __FILE__, VClipPlane, group); | |
392ac980 | 11031 | theCommands.Add("vdefaults", |
4c513386 | 11032 | "vdefaults [-absDefl value]" |
11033 | "\n\t\t: [-devCoeff value]" | |
11034 | "\n\t\t: [-angDefl value]" | |
11035 | "\n\t\t: [-autoTriang {off/on | 0/1}]" | |
11036 | , __FILE__, VDefaults, group); | |
12381341 | 11037 | theCommands.Add("vlight", |
816d03ee | 11038 | "tool to manage light sources, without arguments shows list of lights." |
11039 | "\n Main commands: " | |
11040 | "\n 'clear' to clear lights" | |
11041 | "\n '{def}aults' to load deafault lights" | |
11042 | "\n 'add' (or 'new') <type> to add any light source" | |
11043 | "\n where <type> is one of {amb}ient|directional|{spot}light|positional" | |
11044 | "\n 'change' <lightId> to edit light source with specified lightId" | |
11045 | "\n\n In addition to 'add' and 'change' commands you can use light parameters:" | |
11046 | "\n {pos}ition X Y Z" | |
11047 | "\n {dir}ection X Y Z (for directional light or for spotlight)" | |
11048 | "\n color colorName" | |
11049 | "\n {head}light 0|1" | |
189f85a3 | 11050 | "\n {sm}oothness value" |
11051 | "\n {int}ensity value" | |
816d03ee | 11052 | "\n {constAtten}uation value" |
11053 | "\n {linearAtten}uation value" | |
11054 | "\n angle angleDeg" | |
11055 | "\n {spotexp}onent value" | |
11056 | "\n local|global" | |
11057 | "\n\n example: vlight add positional head 1 pos 0 1 1 color red" | |
11058 | "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2", | |
12381341 | 11059 | __FILE__, VLight, group); |
6b62b2da | 11060 | theCommands.Add("vraytrace", |
11061 | "vraytrace [0|1]" | |
189f85a3 | 11062 | "\n\t\t: Turns on/off ray-tracing renderer." |
6b62b2da | 11063 | "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'." |
11064 | "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.", | |
11065 | __FILE__, VRenderParams, group); | |
bc8c79bb | 11066 | theCommands.Add("vrenderparams", |
11067 | "\n Manages rendering parameters: " | |
4eaaf9d8 | 11068 | "\n '-raster' Disables GPU ray-tracing" |
11069 | "\n '-msaa 0..4' Specifies number of samples for MSAA" | |
56689b27 | 11070 | "\n '-rendScale value Rendering resolution scale factor" |
4eaaf9d8 | 11071 | "\n '-rayTrace' Enables GPU ray-tracing" |
11072 | "\n '-rayDepth 0..10' Defines maximum ray-tracing depth" | |
11073 | "\n '-shadows on|off' Enables/disables shadows rendering" | |
11074 | "\n '-reflections on|off' Enables/disables specular reflections" | |
11075 | "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing" | |
11076 | "\n '-gleam on|off' Enables/disables transparency shadow effects" | |
11077 | "\n '-gi on|off' Enables/disables global illumination effects" | |
11078 | "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)" | |
11079 | "\n '-env on|off' Enables/disables environment map background" | |
11080 | "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)" | |
11081 | "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)" | |
11082 | "\n '-issd on|off' Shows screen sampling distribution in ISS mode" | |
11083 | "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)" | |
11084 | "\n '-nbtiles 64..1024' Specifies number of screen tiles in ISS mode" | |
11085 | "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)" | |
11086 | "\n '-shadingModel model' Controls shading model from enumeration" | |
11087 | "\n color, flat, gouraud, phong" | |
11088 | "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size" | |
8625ef7e | 11089 | "\n Unlike vcaps, these parameters dramatically change visual properties." |
11090 | "\n Command is intended to control presentation quality depending on" | |
11091 | "\n hardware capabilities and performance.", | |
bc8c79bb | 11092 | __FILE__, VRenderParams, group); |
b7cd4ba7 | 11093 | theCommands.Add("vfrustumculling", |
11094 | "vfrustumculling [toEnable]: enables/disables objects clipping", | |
11095 | __FILE__,VFrustumCulling,group); | |
c398b00e | 11096 | theCommands.Add("vhighlightselected", |
11097 | "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n" | |
11098 | "Without arguments it shows if highlighting of selected objects is enabled now.", | |
11099 | __FILE__,VHighlightSelected,group); | |
49e1a5c7 | 11100 | theCommands.Add ("vplace", |
11101 | "vplace dx dy" | |
11102 | "\n\t\t: Places the point (in pixels) at the center of the window", | |
11103 | __FILE__, VPlace, group); | |
0717ddc1 | 11104 | theCommands.Add("vxrotate", |
11105 | "vxrotate", | |
11106 | __FILE__,VXRotate,group); | |
11107 | ||
625e1958 | 11108 | theCommands.Add("vmanipulator", |
11109 | "\n vmanipulator Name [-attach AISObject | -detach | ...]" | |
11110 | "\n tool to create and manage AIS manipulators." | |
11111 | "\n Options: " | |
11112 | "\n '-attach AISObject' attach manipulator to AISObject" | |
11113 | "\n '-adjustPosition {0|1}' adjust position when attaching" | |
11114 | "\n '-adjustSize {0|1}' adjust size when attaching" | |
11115 | "\n '-enableModes {0|1}' enable modes when attaching" | |
11116 | "\n '-detach' detach manipulator" | |
11117 | "\n '-startTransform mouse_x mouse_y' - invoke start of transformation" | |
11118 | "\n '-transform mouse_x mouse_y' - invoke transformation" | |
11119 | "\n '-stopTransform [abort]' - invoke stop of transformation" | |
11120 | "\n '-move x y z' - move attached object" | |
11121 | "\n '-rotate x y z dx dy dz angle' - rotate attached object" | |
11122 | "\n '-scale factor' - scale attached object" | |
11123 | "\n '-autoActivate {0|1}' - set activation on detection" | |
11124 | "\n '-followTranslation {0|1}' - set following translation transform" | |
11125 | "\n '-followRotation {0|1}' - set following rotation transform" | |
11126 | "\n '-gap value' - set gap between sub-parts" | |
11127 | "\n '-part axis mode {0|1}' - set visual part" | |
11128 | "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator" | |
11129 | "\n '-size value' - set size of manipulator" | |
11130 | "\n '-zoomable {0|1}' - set zoom persistence", | |
11131 | __FILE__, VManipulator, group); | |
11132 | ||
8e5fb5ea | 11133 | theCommands.Add("vselprops", |
f838dac4 | 11134 | "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]" |
8e5fb5ea | 11135 | "\n Customizes selection and dynamic highlight parameters for the whole interactive context:" |
11136 | "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode" | |
14c4193d | 11137 | "\n -pickStrategy {first|topmost} : defines picking strategy" |
11138 | "\n 'first' to pick first acceptable (default)" | |
11139 | "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)" | |
8e5fb5ea | 11140 | "\n -pixTol value : sets up pixel tolerance" |
f838dac4 | 11141 | "\n -dispMode dispMode : sets display mode for highlighting" |
11142 | "\n -layer ZLayer : sets ZLayer for highlighting" | |
11143 | "\n -color {name|r g b} : sets highlight color" | |
11144 | "\n -transp value : sets transparency coefficient for highlight" | |
11145 | "\n -material material : sets highlight material" | |
8e5fb5ea | 11146 | "\n -print : prints current state of all mentioned parameters", |
11147 | __FILE__, VSelectionProperties, group); | |
11148 | ||
decdee7d | 11149 | theCommands.Add ("vseldump", |
11150 | "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1" | |
11151 | "\n\t\t: Generate an image based on detection results:" | |
11152 | "\n\t\t: depth normalized depth values" | |
11153 | "\n\t\t: unnormDepth unnormalized depth values" | |
11154 | "\n\t\t: object color of detected object" | |
11155 | "\n\t\t: owner color of detected owner" | |
11156 | "\n\t\t: selMode color of selection mode" | |
11157 | "\n\t\t: entity color of etected entity", | |
11158 | __FILE__, VDumpSelectionImage, group); | |
11159 | ||
189f85a3 | 11160 | #if defined(_WIN32) |
11161 | theCommands.Add("vprogressive", | |
11162 | "vprogressive", | |
11163 | __FILE__, VProgressiveMode, group); | |
11164 | #endif | |
7fd59977 | 11165 | } |