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> | |
30a1b24e | 22 | #include <AIS_CameraFrustum.hxx> |
7a324550 | 23 | #include <AIS_ColorScale.hxx> |
625e1958 | 24 | #include <AIS_Manipulator.hxx> |
b12e1c7b | 25 | #include <AIS_RubberBand.hxx> |
0a768f56 | 26 | #include <AIS_Shape.hxx> |
0a768f56 | 27 | #include <AIS_InteractiveObject.hxx> |
28 | #include <AIS_ListOfInteractive.hxx> | |
29 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
8a590580 | 30 | #include <Aspect_Grid.hxx> |
0a768f56 | 31 | #include <DBRep.hxx> |
08f8a185 | 32 | #include <Draw_ProgressIndicator.hxx> |
61b0191c | 33 | #include <Graphic3d_ArrayOfPolylines.hxx> |
2bd4c032 | 34 | #include <Graphic3d_AspectMarker3d.hxx> |
269294d6 | 35 | #include <Graphic3d_NameOfTextureEnv.hxx> |
a79f67f8 | 36 | #include <Graphic3d_GraduatedTrihedron.hxx> |
269294d6 | 37 | #include <Graphic3d_TextureEnv.hxx> |
38 | #include <Graphic3d_TextureParams.hxx> | |
39 | #include <Graphic3d_TypeOfTextureFilter.hxx> | |
4269bd1b | 40 | #include <Graphic3d_AspectFillArea3d.hxx> |
7fd59977 | 41 | #include <ViewerTest.hxx> |
8625ef7e | 42 | #include <ViewerTest_AutoUpdater.hxx> |
7fd59977 | 43 | #include <ViewerTest_EventManager.hxx> |
4754e164 | 44 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> |
4269bd1b | 45 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> |
625e1958 | 46 | #include <ViewerTest_CmdParser.hxx> |
12381341 | 47 | #include <V3d_AmbientLight.hxx> |
48 | #include <V3d_DirectionalLight.hxx> | |
12381341 | 49 | #include <V3d_PositionalLight.hxx> |
50 | #include <V3d_SpotLight.hxx> | |
08f8a185 | 51 | #include <Message_ProgressSentry.hxx> |
18d715bd | 52 | #include <NCollection_DoubleMap.hxx> |
53 | #include <NCollection_List.hxx> | |
54 | #include <NCollection_Vector.hxx> | |
7fd59977 | 55 | #include <AIS_InteractiveContext.hxx> |
56 | #include <Draw_Interpretor.hxx> | |
57 | #include <Draw.hxx> | |
58 | #include <Draw_Appli.hxx> | |
692613e5 | 59 | #include <Image_AlienPixMap.hxx> |
08f8a185 | 60 | #include <Image_VideoRecorder.hxx> |
58655684 | 61 | #include <OpenGl_GraphicDriver.hxx> |
208e6839 | 62 | #include <OSD_Timer.hxx> |
900f7229 | 63 | #include <TColStd_HSequenceOfAsciiString.hxx> |
59f45b7c | 64 | #include <TColStd_SequenceOfInteger.hxx> |
4754e164 | 65 | #include <TColStd_HSequenceOfReal.hxx> |
66 | #include <TColgp_Array1OfPnt2d.hxx> | |
197ac94e | 67 | #include <TColStd_MapOfAsciiString.hxx> |
20637bd2 | 68 | #include <Aspect_TypeOfLine.hxx> |
692613e5 | 69 | #include <Image_Diff.hxx> |
dc3fe572 | 70 | #include <Aspect_DisplayConnection.hxx> |
4269bd1b | 71 | #include <gp_Pnt.hxx> |
72 | #include <gp_Dir.hxx> | |
73 | #include <gp_Pln.hxx> | |
74 | #include <PrsMgr_PresentableObject.hxx> | |
75 | #include <Graphic3d_ClipPlane.hxx> | |
76 | #include <NCollection_DataMap.hxx> | |
77 | #include <Graphic3d_Texture2Dmanual.hxx> | |
78 | #include <Prs3d_ShadingAspect.hxx> | |
6262338c | 79 | #include <Prs3d_Drawer.hxx> |
61b0191c | 80 | #include <Prs3d_LineAspect.hxx> |
81 | #include <Prs3d_Root.hxx> | |
fd3f6bd0 | 82 | #include <Prs3d_Text.hxx> |
83 | #include <Select3D_SensitivePrimitiveArray.hxx> | |
7fd59977 | 84 | |
57c28b61 | 85 | #ifdef _WIN32 |
25289ec1 | 86 | #undef DrawText |
87 | #endif | |
88 | ||
692613e5 | 89 | #include <cstdlib> |
25289ec1 | 90 | |
58655684 | 91 | #if defined(_WIN32) |
4fe56619 | 92 | #include <WNT_WClass.hxx> |
93 | #include <WNT_Window.hxx> | |
4fe56619 | 94 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
4fe56619 | 95 | #include <Cocoa_Window.hxx> |
7fd59977 | 96 | #else |
4fe56619 | 97 | #include <Xw_Window.hxx> |
98 | #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */ | |
99 | #include <X11/Xutil.h> | |
100 | #include <tk.h> | |
7fd59977 | 101 | #endif |
102 | ||
b514beda | 103 | // Auxiliary definitions |
104 | static const char THE_KEY_DELETE = 127; | |
fd3f6bd0 | 105 | static const char THE_KEY_ESCAPE = 27; |
7fd59977 | 106 | |
107 | //============================================================================== | |
108 | // VIEWER GLOBAL VARIABLES | |
109 | //============================================================================== | |
110 | ||
111 | Standard_IMPORT Standard_Boolean Draw_VirtualWindows; | |
b514beda | 112 | Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand); |
7fd59977 | 113 | |
114 | Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv); | |
4754e164 | 115 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
7fd59977 | 116 | |
b514beda | 117 | extern int VErase (Draw_Interpretor& theDI, |
118 | Standard_Integer theArgNb, | |
119 | const char** theArgVec); | |
120 | ||
58655684 | 121 | #if defined(_WIN32) |
7fd59977 | 122 | static Handle(WNT_Window)& VT_GetWindow() { |
123 | static Handle(WNT_Window) WNTWin; | |
124 | return WNTWin; | |
125 | } | |
4fe56619 | 126 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
4fe56619 | 127 | static Handle(Cocoa_Window)& VT_GetWindow() |
128 | { | |
129 | static Handle(Cocoa_Window) aWindow; | |
130 | return aWindow; | |
131 | } | |
132 | extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow); | |
18d715bd | 133 | extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle); |
134 | extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight); | |
135 | ||
7fd59977 | 136 | #else |
7fd59977 | 137 | static Handle(Xw_Window)& VT_GetWindow(){ |
138 | static Handle(Xw_Window) XWWin; | |
139 | return XWWin; | |
140 | } | |
7fd59977 | 141 | |
142 | static void VProcessEvents(ClientData,int); | |
143 | #endif | |
144 | ||
18d715bd | 145 | static Handle(Aspect_DisplayConnection)& GetDisplayConnection() |
146 | { | |
147 | static Handle(Aspect_DisplayConnection) aDisplayConnection; | |
148 | return aDisplayConnection; | |
149 | } | |
150 | ||
151 | static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection) | |
152 | { | |
153 | GetDisplayConnection() = theDisplayConnection; | |
154 | } | |
155 | ||
58655684 | 156 | #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
18d715bd | 157 | Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow) |
dc3fe572 | 158 | { |
0ebaa4db | 159 | Aspect_Handle aWindowHandle = (Aspect_Handle)NULL; |
58655684 | 160 | #if defined(_WIN32) |
18d715bd | 161 | const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow); |
162 | if (!aWindow.IsNull()) | |
163 | return aWindow->HWindow(); | |
164 | #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
165 | const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow); | |
166 | if (!aWindow.IsNull()) | |
167 | return aWindow->XWindow(); | |
168 | #endif | |
169 | return aWindowHandle; | |
dc3fe572 | 170 | } |
18d715bd | 171 | #endif |
dc3fe572 | 172 | |
2e93433e | 173 | //! Setting additional flag to store 2D mode of the View to avoid scene rotation by mouse/key events |
174 | class ViewerTest_V3dView : public V3d_View | |
175 | { | |
176 | DEFINE_STANDARD_RTTI_INLINE(ViewerTest_V3dView, V3d_View) | |
177 | public: | |
178 | //! Initializes the view. | |
179 | ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const V3d_TypeOfView theType = V3d_ORTHOGRAPHIC, | |
180 | bool theIs2dMode = false) | |
181 | : V3d_View (theViewer, theType), myIs2dMode (theIs2dMode) {} | |
182 | ||
183 | //! Initializes the view by copying. | |
184 | ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const Handle(V3d_View)& theView) | |
185 | : V3d_View (theViewer, theView), myIs2dMode (false) | |
186 | { | |
187 | if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (theView)) | |
188 | { | |
189 | myIs2dMode = aV3dView->IsViewIn2DMode(); | |
190 | } | |
191 | } | |
192 | ||
193 | //! Returns true if 2D mode is set for the view | |
194 | bool IsViewIn2DMode() const { return myIs2dMode; } | |
195 | ||
196 | //! Sets 2D mode for the view | |
197 | void SetView2DMode (bool the2dMode) { myIs2dMode = the2dMode; } | |
198 | ||
199 | public: | |
200 | ||
201 | //! Returns true if active view in 2D mode. | |
202 | static bool IsCurrentViewIn2DMode() | |
203 | { | |
204 | if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView())) | |
205 | { | |
206 | return aV3dView->IsViewIn2DMode(); | |
207 | } | |
208 | return false; | |
209 | } | |
210 | ||
211 | //! Set if active view in 2D mode. | |
212 | static void SetCurrentView2DMode (bool theIs2d) | |
213 | { | |
214 | if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView())) | |
215 | { | |
216 | aV3dView->SetView2DMode (theIs2d); | |
217 | } | |
218 | } | |
219 | ||
220 | private: | |
221 | ||
222 | Standard_Boolean myIs2dMode; //!< 2D mode flag | |
223 | ||
224 | }; | |
225 | ||
18d715bd | 226 | NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews; |
58655684 | 227 | static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts; |
18d715bd | 228 | static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers; |
58655684 | 229 | static OpenGl_Caps ViewerTest_myDefaultCaps; |
18d715bd | 230 | |
7fd59977 | 231 | static void OSWindowSetup(); |
232 | ||
f42753ed | 233 | static struct |
234 | { | |
235 | Quantity_Color FlatColor; | |
236 | Quantity_Color GradientColor1; | |
237 | Quantity_Color GradientColor2; | |
238 | Aspect_GradientFillMethod FillMethod; | |
239 | } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE }; | |
240 | ||
7fd59977 | 241 | //============================================================================== |
242 | // EVENT GLOBAL VARIABLES | |
243 | //============================================================================== | |
244 | ||
245 | static int Start_Rot = 0; | |
1eeef710 | 246 | Standard_Boolean HasHlrOnBeforeRotation = Standard_False; |
4fe56619 | 247 | int X_Motion = 0; // Current cursor position |
248 | int Y_Motion = 0; | |
249 | int X_ButtonPress = 0; // Last ButtonPress position | |
250 | int Y_ButtonPress = 0; | |
251 | Standard_Boolean IsDragged = Standard_False; | |
8abada55 | 252 | Standard_Boolean DragFirst = Standard_False; |
1beb58d7 | 253 | Standard_Boolean TheIsAnimating = Standard_False; |
fd3f6bd0 | 254 | Standard_Boolean Draw_ToExitOnCloseView = Standard_False; |
255 | Standard_Boolean Draw_ToCloseViewOnEsc = Standard_False; | |
7fd59977 | 256 | |
b12e1c7b | 257 | |
258 | Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand() | |
259 | { | |
260 | static Handle(AIS_RubberBand) aBand; | |
261 | if (aBand.IsNull()) | |
262 | { | |
69adb9ce | 263 | aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0); |
264 | aBand->SetDisplayMode (0); | |
b12e1c7b | 265 | } |
266 | return aBand; | |
267 | } | |
268 | ||
625e1958 | 269 | typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators; |
270 | ||
271 | Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators() | |
272 | { | |
273 | static ViewerTest_MapOfAISManipulators aMap; | |
274 | return aMap; | |
275 | } | |
276 | ||
277 | Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator() | |
278 | { | |
279 | ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators()); | |
280 | for (; anIt.More(); anIt.Next()) | |
281 | { | |
282 | if (anIt.Value()->HasActiveMode()) | |
283 | { | |
284 | return anIt.Value(); | |
285 | } | |
286 | } | |
287 | return NULL; | |
288 | } | |
289 | ||
7fd59977 | 290 | //============================================================================== |
291 | ||
57c28b61 | 292 | #ifdef _WIN32 |
7fd59977 | 293 | static LRESULT WINAPI ViewerWindowProc( |
294 | HWND hwnd, | |
295 | UINT uMsg, | |
296 | WPARAM wParam, | |
297 | LPARAM lParam ); | |
298 | static LRESULT WINAPI AdvViewerWindowProc( | |
299 | HWND hwnd, | |
300 | UINT uMsg, | |
301 | WPARAM wParam, | |
302 | LPARAM lParam ); | |
303 | #endif | |
304 | ||
305 | ||
306 | //============================================================================== | |
307 | //function : WClass | |
308 | //purpose : | |
309 | //============================================================================== | |
310 | ||
ad03c234 | 311 | const Handle(Standard_Transient)& ViewerTest::WClass() |
7fd59977 | 312 | { |
ad03c234 | 313 | static Handle(Standard_Transient) theWClass; |
58655684 | 314 | #if defined(_WIN32) |
4fe56619 | 315 | if (theWClass.IsNull()) |
316 | { | |
7c65581d | 317 | theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc, |
ad03c234 | 318 | CS_VREDRAW | CS_HREDRAW, 0, 0, |
c85a994a | 319 | ::LoadCursor (NULL, IDC_ARROW)); |
7fd59977 | 320 | } |
321 | #endif | |
322 | return theWClass; | |
323 | } | |
324 | ||
18d715bd | 325 | //============================================================================== |
326 | //function : CreateName | |
327 | //purpose : Create numerical name for new object in theMap | |
328 | //============================================================================== | |
329 | template <typename ObjectType> | |
330 | TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap, | |
331 | const TCollection_AsciiString& theDefaultString) | |
332 | { | |
333 | if (theObjectMap.IsEmpty()) | |
334 | return theDefaultString + TCollection_AsciiString(1); | |
335 | ||
336 | Standard_Integer aNextKey = 1; | |
337 | Standard_Boolean isFound = Standard_False; | |
338 | while (!isFound) | |
339 | { | |
340 | TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey); | |
341 | // Look for objects with default names | |
342 | if (theObjectMap.IsBound1(aStringKey)) | |
343 | { | |
344 | aNextKey++; | |
345 | } | |
346 | else | |
347 | isFound = Standard_True; | |
348 | } | |
349 | ||
350 | return theDefaultString + TCollection_AsciiString(aNextKey); | |
351 | } | |
352 | ||
353 | //============================================================================== | |
354 | //structure : ViewerTest_Names | |
355 | //purpose : Allow to operate with full view name: driverName/viewerName/viewName | |
356 | //============================================================================== | |
357 | struct ViewerTest_Names | |
358 | { | |
359 | private: | |
360 | TCollection_AsciiString myDriverName; | |
361 | TCollection_AsciiString myViewerName; | |
362 | TCollection_AsciiString myViewName; | |
363 | ||
364 | public: | |
365 | ||
366 | const TCollection_AsciiString& GetDriverName () const | |
367 | { | |
368 | return myDriverName; | |
369 | } | |
370 | void SetDriverName (const TCollection_AsciiString& theDriverName) | |
371 | { | |
372 | myDriverName = theDriverName; | |
373 | } | |
374 | const TCollection_AsciiString& GetViewerName () const | |
375 | { | |
376 | return myViewerName; | |
377 | } | |
378 | void SetViewerName (const TCollection_AsciiString& theViewerName) | |
379 | { | |
380 | myViewerName = theViewerName; | |
381 | } | |
382 | const TCollection_AsciiString& GetViewName () const | |
383 | { | |
384 | return myViewName; | |
385 | } | |
386 | void SetViewName (const TCollection_AsciiString& theViewName) | |
387 | { | |
388 | myViewName = theViewName; | |
389 | } | |
390 | ||
391 | //=========================================================================== | |
392 | //function : Constructor for ViewerTest_Names | |
393 | //purpose : Get view, viewer, driver names from custom string | |
394 | //=========================================================================== | |
395 | ||
396 | ViewerTest_Names (const TCollection_AsciiString& theInputString) | |
397 | { | |
398 | TCollection_AsciiString aName(theInputString); | |
399 | if (theInputString.IsEmpty()) | |
400 | { | |
401 | // Get current configuration | |
402 | if (ViewerTest_myDrivers.IsEmpty()) | |
403 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
404 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
405 | else | |
406 | myDriverName = ViewerTest_myDrivers.Find2 | |
407 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
408 | ||
409 | if(ViewerTest_myContexts.IsEmpty()) | |
410 | { | |
411 | myViewerName = CreateName <Handle(AIS_InteractiveContext)> | |
412 | (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer")); | |
413 | } | |
414 | else | |
c48e2889 | 415 | { |
18d715bd | 416 | myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext()); |
c48e2889 | 417 | } |
18d715bd | 418 | |
c48e2889 | 419 | myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View")); |
18d715bd | 420 | } |
421 | else | |
422 | { | |
423 | // There is at least view name | |
424 | Standard_Integer aParserNumber = 0; | |
425 | for (Standard_Integer i = 0; i < 3; ++i) | |
426 | { | |
427 | Standard_Integer aParserPos = aName.SearchFromEnd("/"); | |
428 | if(aParserPos != -1) | |
429 | { | |
430 | aParserNumber++; | |
431 | aName.Split(aParserPos-1); | |
432 | } | |
433 | else | |
434 | break; | |
435 | } | |
436 | if (aParserNumber == 0) | |
437 | { | |
438 | // Only view name | |
439 | if (!ViewerTest::GetAISContext().IsNull()) | |
440 | { | |
441 | myDriverName = ViewerTest_myDrivers.Find2 | |
442 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
443 | myViewerName = ViewerTest_myContexts.Find2 | |
444 | (ViewerTest::GetAISContext()); | |
445 | } | |
446 | else | |
447 | { | |
448 | // There is no opened contexts here, need to create names for viewer and driver | |
449 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
450 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
451 | ||
452 | myViewerName = CreateName <Handle(AIS_InteractiveContext)> | |
453 | (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer")); | |
454 | } | |
455 | myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString); | |
456 | } | |
457 | else if (aParserNumber == 1) | |
458 | { | |
459 | // Here is viewerName/viewName | |
460 | if (!ViewerTest::GetAISContext().IsNull()) | |
461 | myDriverName = ViewerTest_myDrivers.Find2 | |
462 | (ViewerTest::GetAISContext()->CurrentViewer()->Driver()); | |
463 | else | |
464 | { | |
465 | // There is no opened contexts here, need to create name for driver | |
466 | myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)> | |
467 | (ViewerTest_myDrivers, TCollection_AsciiString("Driver")); | |
468 | } | |
469 | myViewerName = TCollection_AsciiString(myDriverName + "/" + aName); | |
470 | ||
471 | myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString); | |
472 | } | |
473 | else | |
474 | { | |
475 | //Here is driverName/viewerName/viewName | |
476 | myDriverName = TCollection_AsciiString(aName); | |
477 | ||
478 | TCollection_AsciiString aViewerName(theInputString); | |
479 | aViewerName.Split(aViewerName.SearchFromEnd("/") - 1); | |
480 | myViewerName = TCollection_AsciiString(aViewerName); | |
481 | ||
482 | myViewName = TCollection_AsciiString(theInputString); | |
483 | } | |
484 | } | |
485 | } | |
486 | }; | |
487 | ||
488 | //============================================================================== | |
489 | //function : FindContextByView | |
490 | //purpose : Find AIS_InteractiveContext by View | |
491 | //============================================================================== | |
492 | ||
493 | Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView) | |
494 | { | |
495 | Handle(AIS_InteractiveContext) anAISContext; | |
496 | ||
497 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
498 | anIter (ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
499 | { | |
500 | if (anIter.Value()->CurrentViewer() == theView->Viewer()) | |
501 | return anIter.Key2(); | |
502 | } | |
503 | return anAISContext; | |
504 | } | |
505 | ||
506 | ||
507 | //============================================================================== | |
508 | //function : SetWindowTitle | |
509 | //purpose : Set window title | |
510 | //============================================================================== | |
511 | ||
512 | void SetWindowTitle (const Handle(Aspect_Window)& theWindow, | |
513 | Standard_CString theTitle) | |
514 | { | |
58655684 | 515 | #if defined(_WIN32) |
ad03c234 | 516 | const TCollection_ExtendedString theTitleW (theTitle); |
517 | SetWindowTextW ((HWND )Handle(WNT_Window)::DownCast(theWindow)->HWindow(), theTitleW.ToWideString()); | |
18d715bd | 518 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
519 | SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle); | |
520 | #else | |
521 | if(GetDisplayConnection()->GetDisplay()) | |
522 | { | |
523 | Window aWindow = | |
524 | Handle(Xw_Window)::DownCast(theWindow)->XWindow(); | |
525 | XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle); | |
526 | } | |
527 | #endif | |
528 | } | |
529 | ||
530 | //============================================================================== | |
531 | //function : IsWindowOverlapped | |
532 | //purpose : Check if theWindow overlapp another view | |
533 | //============================================================================== | |
534 | ||
535 | Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft, | |
536 | const Standard_Integer thePxTop, | |
537 | const Standard_Integer thePxRight, | |
538 | const Standard_Integer thePxBottom, | |
539 | TCollection_AsciiString& theViewId) | |
540 | { | |
541 | for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
542 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
543 | { | |
544 | Standard_Integer aTop = 0, | |
545 | aLeft = 0, | |
546 | aRight = 0, | |
547 | aBottom = 0; | |
548 | anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom); | |
549 | if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) || | |
550 | (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) || | |
551 | (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) || | |
552 | (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom)) | |
553 | { | |
554 | theViewId = anIter.Key1(); | |
555 | return Standard_True; | |
556 | } | |
557 | } | |
558 | return Standard_False; | |
559 | } | |
560 | ||
561 | // Workaround: to create and delete non-orthographic views outside ViewerTest | |
562 | void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName) | |
563 | { | |
564 | ViewerTest_myViews.UnBind1 (theName); | |
565 | } | |
566 | ||
567 | void ViewerTest::InitViewName (const TCollection_AsciiString& theName, | |
568 | const Handle(V3d_View)& theView) | |
569 | { | |
570 | ViewerTest_myViews.Bind (theName, theView); | |
571 | } | |
572 | ||
573 | TCollection_AsciiString ViewerTest::GetCurrentViewName () | |
574 | { | |
575 | return ViewerTest_myViews.Find2( ViewerTest::CurrentView()); | |
576 | } | |
7fd59977 | 577 | //============================================================================== |
578 | //function : ViewerInit | |
579 | //purpose : Create the window viewer and initialize all the global variable | |
580 | //============================================================================== | |
581 | ||
18d715bd | 582 | TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft, |
583 | const Standard_Integer thePxTop, | |
584 | const Standard_Integer thePxWidth, | |
585 | const Standard_Integer thePxHeight, | |
9e04ccdc | 586 | const TCollection_AsciiString& theViewName, |
587 | const TCollection_AsciiString& theDisplayName, | |
588 | const Handle(V3d_View)& theViewToClone) | |
7fd59977 | 589 | { |
8c3c9904 | 590 | // Default position and dimension of the viewer window. |
4fe56619 | 591 | // Note that left top corner is set to be sufficiently small to have |
8c3c9904 | 592 | // window fit in the small screens (actual for remote desktops, see #23003). |
4fe56619 | 593 | // The position corresponds to the window's client area, thus some |
8c3c9904 | 594 | // gap is added for window frame to be visible. |
595 | Standard_Integer aPxLeft = 20; | |
596 | Standard_Integer aPxTop = 40; | |
7fd59977 | 597 | Standard_Integer aPxWidth = 409; |
598 | Standard_Integer aPxHeight = 409; | |
18d715bd | 599 | Standard_Boolean toCreateViewer = Standard_False; |
9e04ccdc | 600 | if (!theViewToClone.IsNull()) |
601 | { | |
602 | theViewToClone->Window()->Size (aPxWidth, aPxHeight); | |
603 | } | |
18d715bd | 604 | |
58655684 | 605 | Handle(OpenGl_GraphicDriver) aGraphicDriver; |
18d715bd | 606 | ViewerTest_Names aViewNames(theViewName); |
607 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ())) | |
608 | aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View")); | |
609 | ||
610 | if (thePxLeft != 0) | |
611 | aPxLeft = thePxLeft; | |
612 | if (thePxTop != 0) | |
613 | aPxTop = thePxTop; | |
614 | if (thePxWidth != 0) | |
615 | aPxWidth = thePxWidth; | |
616 | if (thePxHeight != 0) | |
7fd59977 | 617 | aPxHeight = thePxHeight; |
4269bd1b | 618 | |
18d715bd | 619 | // Get graphic driver (create it or get from another view) |
620 | if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName())) | |
621 | { | |
622 | // Get connection string | |
58655684 | 623 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
18d715bd | 624 | TCollection_AsciiString aDisplayName(theDisplayName); |
498ce76b | 625 | if (!aDisplayName.IsEmpty()) |
18d715bd | 626 | SetDisplayConnection (new Aspect_DisplayConnection ()); |
627 | else | |
628 | SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName)); | |
18d715bd | 629 | #else |
498ce76b | 630 | (void)theDisplayName; // avoid warning on unused argument |
18d715bd | 631 | SetDisplayConnection (new Aspect_DisplayConnection ()); |
632 | #endif | |
14cb22a1 | 633 | |
634 | if (Draw_VirtualWindows) | |
635 | { | |
636 | // don't waste the time waiting for VSync when window is not displayed on the screen | |
637 | ViewerTest_myDefaultCaps.swapInterval = 0; | |
638 | // alternatively we can disable buffer swap at all, but this might be inappropriate for testing | |
639 | //ViewerTest_myDefaultCaps.buffersNoSwap = true; | |
640 | } | |
65993a95 | 641 | aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection()); |
58655684 | 642 | aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps; |
14cb22a1 | 643 | |
18d715bd | 644 | ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver); |
645 | toCreateViewer = Standard_True; | |
646 | } | |
647 | else | |
648 | { | |
58655684 | 649 | aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName())); |
7fd59977 | 650 | } |
651 | ||
18d715bd | 652 | //Dispose the window if input parameters are default |
653 | if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0) | |
7fd59977 | 654 | { |
18d715bd | 655 | Standard_Integer aTop = 0, |
656 | aLeft = 0, | |
657 | aRight = 0, | |
658 | aBottom = 0, | |
659 | aScreenWidth = 0, | |
660 | aScreenHeight = 0; | |
661 | ||
662 | // Get screen resolution | |
663 | #if defined(_WIN32) || defined(__WIN32__) | |
664 | RECT aWindowSize; | |
665 | GetClientRect(GetDesktopWindow(), &aWindowSize); | |
666 | aScreenHeight = aWindowSize.bottom; | |
667 | aScreenWidth = aWindowSize.right; | |
668 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
669 | GetCocoaScreenResolution (aScreenWidth, aScreenHeight); | |
670 | #else | |
671 | Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay()); | |
672 | aScreenWidth = WidthOfScreen(aScreen); | |
673 | aScreenHeight = HeightOfScreen(aScreen); | |
674 | #endif | |
675 | ||
676 | TCollection_AsciiString anOverlappedViewId(""); | |
773f53f1 | 677 | |
678 | while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)) | |
dc3fe572 | 679 | { |
18d715bd | 680 | ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom); |
681 | ||
682 | if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId) | |
683 | && aRight + 2*aPxWidth + 40 > aScreenWidth) | |
684 | { | |
685 | if (aBottom + aPxHeight + 40 > aScreenHeight) | |
686 | { | |
687 | aPxLeft = 20; | |
688 | aPxTop = 40; | |
689 | break; | |
690 | } | |
691 | aPxLeft = 20; | |
692 | aPxTop = aBottom + 40; | |
693 | } | |
694 | else | |
695 | aPxLeft = aRight + 20; | |
dc3fe572 | 696 | } |
18d715bd | 697 | } |
698 | ||
699 | // Get viewer name | |
700 | TCollection_AsciiString aTitle("3D View - "); | |
701 | aTitle = aTitle + aViewNames.GetViewName() + "(*)"; | |
702 | ||
703 | // Change name of current active window | |
704 | if (!ViewerTest::CurrentView().IsNull()) | |
705 | { | |
51740958 | 706 | TCollection_AsciiString anActiveWindowTitle("3D View - "); |
707 | anActiveWindowTitle = anActiveWindowTitle | |
18d715bd | 708 | + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()); |
51740958 | 709 | SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString()); |
18d715bd | 710 | } |
711 | ||
712 | // Create viewer | |
eb4320f2 | 713 | Handle(V3d_Viewer) a3DViewer; |
18d715bd | 714 | // If it's the single view, we first look for empty context |
715 | if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty()) | |
716 | { | |
717 | NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
718 | anIter(ViewerTest_myContexts); | |
719 | if (anIter.More()) | |
720 | ViewerTest::SetAISContext (anIter.Value()); | |
721 | a3DViewer = ViewerTest::GetAISContext()->CurrentViewer(); | |
18d715bd | 722 | } |
723 | else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())) | |
724 | { | |
725 | ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName())); | |
726 | a3DViewer = ViewerTest::GetAISContext()->CurrentViewer(); | |
18d715bd | 727 | } |
eb4320f2 | 728 | else if (a3DViewer.IsNull()) |
18d715bd | 729 | { |
730 | toCreateViewer = Standard_True; | |
6a24c6de | 731 | a3DViewer = new V3d_Viewer(aGraphicDriver); |
f42753ed | 732 | a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor); |
733 | a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1, | |
734 | ViewerTest_DefaultBackground.GradientColor2, | |
735 | ViewerTest_DefaultBackground.FillMethod); | |
18d715bd | 736 | } |
737 | ||
738 | // AIS context setup | |
739 | if (ViewerTest::GetAISContext().IsNull() || | |
740 | !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))) | |
741 | { | |
e79a94b9 | 742 | Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer); |
18d715bd | 743 | ViewerTest::SetAISContext (aContext); |
744 | ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext()); | |
745 | } | |
746 | else | |
e79a94b9 | 747 | { |
18d715bd | 748 | ViewerTest::ResetEventManager(); |
e79a94b9 | 749 | } |
18d715bd | 750 | |
751 | // Create window | |
e79a94b9 | 752 | #if defined(_WIN32) |
753 | VT_GetWindow() = new WNT_Window (aTitle.ToCString(), | |
754 | Handle(WNT_WClass)::DownCast (WClass()), | |
62e1beed | 755 | Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW, |
e79a94b9 | 756 | aPxLeft, aPxTop, |
757 | aPxWidth, aPxHeight, | |
758 | Quantity_NOC_BLACK); | |
4fe56619 | 759 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
e79a94b9 | 760 | VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(), |
761 | aPxLeft, aPxTop, | |
762 | aPxWidth, aPxHeight); | |
763 | ViewerTest_SetCocoaEventManagerView (VT_GetWindow()); | |
7fd59977 | 764 | #else |
e79a94b9 | 765 | VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(), |
766 | aTitle.ToCString(), | |
767 | aPxLeft, aPxTop, | |
768 | aPxWidth, aPxHeight); | |
7fd59977 | 769 | #endif |
18d715bd | 770 | VT_GetWindow()->SetVirtual (Draw_VirtualWindows); |
7fd59977 | 771 | |
d09dda09 | 772 | // View setup |
9e04ccdc | 773 | Handle(V3d_View) aView; |
774 | if (!theViewToClone.IsNull()) | |
775 | { | |
2e93433e | 776 | aView = new ViewerTest_V3dView (a3DViewer, theViewToClone); |
9e04ccdc | 777 | } |
778 | else | |
779 | { | |
2e93433e | 780 | aView = new ViewerTest_V3dView (a3DViewer, a3DViewer->DefaultTypeOfView()); |
9e04ccdc | 781 | } |
782 | ||
d09dda09 | 783 | aView->SetWindow (VT_GetWindow()); |
c3282ec1 | 784 | ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer); |
4269bd1b | 785 | |
18d715bd | 786 | ViewerTest::CurrentView(aView); |
787 | ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView); | |
7fd59977 | 788 | |
18d715bd | 789 | // Setup for X11 or NT |
790 | OSWindowSetup(); | |
7fd59977 | 791 | |
18d715bd | 792 | // Set parameters for V3d_View and V3d_Viewer |
793 | const Handle (V3d_View) aV3dView = ViewerTest::CurrentView(); | |
794 | aV3dView->SetComputedMode(Standard_False); | |
7fd59977 | 795 | |
18d715bd | 796 | a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK); |
797 | if (toCreateViewer) | |
798 | { | |
7fd59977 | 799 | a3DViewer->SetDefaultLights(); |
800 | a3DViewer->SetLightOn(); | |
18d715bd | 801 | } |
7fd59977 | 802 | |
e79a94b9 | 803 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
4fe56619 | 804 | #if TCL_MAJOR_VERSION < 8 |
18d715bd | 805 | Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()), |
7fd59977 | 806 | TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() ); |
4fe56619 | 807 | #else |
18d715bd | 808 | Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()), |
7fd59977 | 809 | TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() ); |
4fe56619 | 810 | #endif |
811 | #endif | |
7fd59977 | 812 | |
7fd59977 | 813 | VT_GetWindow()->Map(); |
4269bd1b | 814 | |
18d715bd | 815 | // Set the handle of created view in the event manager |
816 | ViewerTest::ResetEventManager(); | |
817 | ||
4fe56619 | 818 | ViewerTest::CurrentView()->Redraw(); |
18d715bd | 819 | |
820 | aView.Nullify(); | |
821 | a3DViewer.Nullify(); | |
18d715bd | 822 | |
823 | return aViewNames.GetViewName(); | |
824 | } | |
825 | ||
4269bd1b | 826 | //============================================================================== |
827 | //function : RedrawAllViews | |
828 | //purpose : Redraw all created views | |
829 | //============================================================================== | |
830 | void ViewerTest::RedrawAllViews() | |
831 | { | |
832 | NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews); | |
833 | for (; aViewIt.More(); aViewIt.Next()) | |
834 | { | |
835 | const Handle(V3d_View)& aView = aViewIt.Key2(); | |
836 | aView->Redraw(); | |
837 | } | |
838 | } | |
839 | ||
7fd59977 | 840 | //============================================================================== |
841 | //function : Vinit | |
842 | //purpose : Create the window viewer and initialize all the global variable | |
e79a94b9 | 843 | // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event |
7fd59977 | 844 | //============================================================================== |
845 | ||
18d715bd | 846 | static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) |
7fd59977 | 847 | { |
e79a94b9 | 848 | TCollection_AsciiString aViewName, aDisplayName; |
849 | Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0; | |
9e04ccdc | 850 | Handle(V3d_View) aCopyFrom; |
e79a94b9 | 851 | TCollection_AsciiString aName, aValue; |
2e93433e | 852 | int is2dMode = -1; |
e79a94b9 | 853 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) |
18d715bd | 854 | { |
e79a94b9 | 855 | const TCollection_AsciiString anArg = theArgVec[anArgIt]; |
856 | TCollection_AsciiString anArgCase = anArg; | |
fd3f6bd0 | 857 | anArgCase.LowerCase(); |
858 | if (anArgIt + 1 < theArgsNb | |
859 | && anArgCase == "-name") | |
860 | { | |
861 | aViewName = theArgVec[++anArgIt]; | |
862 | } | |
863 | else if (anArgIt + 1 < theArgsNb | |
864 | && (anArgCase == "-left" | |
865 | || anArgCase == "-l")) | |
866 | { | |
867 | aPxLeft = Draw::Atoi (theArgVec[++anArgIt]); | |
868 | } | |
869 | else if (anArgIt + 1 < theArgsNb | |
870 | && (anArgCase == "-top" | |
871 | || anArgCase == "-t")) | |
872 | { | |
873 | aPxTop = Draw::Atoi (theArgVec[++anArgIt]); | |
874 | } | |
875 | else if (anArgIt + 1 < theArgsNb | |
876 | && (anArgCase == "-width" | |
877 | || anArgCase == "-w")) | |
878 | { | |
879 | aPxWidth = Draw::Atoi (theArgVec[++anArgIt]); | |
880 | } | |
881 | else if (anArgIt + 1 < theArgsNb | |
882 | && (anArgCase == "-height" | |
883 | || anArgCase == "-h")) | |
18d715bd | 884 | { |
fd3f6bd0 | 885 | aPxHeight = Draw::Atoi (theArgVec[++anArgIt]); |
886 | } | |
887 | else if (anArgCase == "-exitonclose") | |
888 | { | |
889 | Draw_ToExitOnCloseView = true; | |
890 | if (anArgIt + 1 < theArgsNb | |
891 | && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToExitOnCloseView)) | |
892 | { | |
893 | ++anArgIt; | |
894 | } | |
895 | } | |
896 | else if (anArgCase == "-closeonescape" | |
897 | || anArgCase == "-closeonesc") | |
898 | { | |
899 | Draw_ToCloseViewOnEsc = true; | |
900 | if (anArgIt + 1 < theArgsNb | |
901 | && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToCloseViewOnEsc)) | |
902 | { | |
903 | ++anArgIt; | |
904 | } | |
905 | } | |
2e93433e | 906 | else if (anArgCase == "-2d_mode" |
907 | || anArgCase == "-2dmode" | |
908 | || anArgCase == "-2d") | |
909 | { | |
910 | bool toEnable = true; | |
911 | if (anArgIt + 1 < theArgsNb | |
912 | && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], toEnable)) | |
913 | { | |
914 | ++anArgIt; | |
915 | } | |
916 | is2dMode = toEnable ? 1 : 0; | |
917 | } | |
fd3f6bd0 | 918 | else if (anArgIt + 1 < theArgsNb |
919 | && (anArgCase == "-disp" | |
920 | || anArgCase == "-display")) | |
921 | { | |
922 | aDisplayName = theArgVec[++anArgIt]; | |
923 | } | |
9e04ccdc | 924 | else if (!ViewerTest::CurrentView().IsNull() |
925 | && aCopyFrom.IsNull() | |
926 | && (anArgCase == "-copy" | |
927 | || anArgCase == "-clone" | |
928 | || anArgCase == "-cloneactive" | |
929 | || anArgCase == "-cloneactiveview")) | |
930 | { | |
931 | aCopyFrom = ViewerTest::CurrentView(); | |
932 | } | |
fd3f6bd0 | 933 | // old syntax |
934 | else if (ViewerTest::SplitParameter (anArg, aName, aValue)) | |
935 | { | |
936 | aName.LowerCase(); | |
937 | if (aName == "name") | |
18d715bd | 938 | { |
939 | aViewName = aValue; | |
940 | } | |
fd3f6bd0 | 941 | else if (aName == "l" |
942 | || aName == "left") | |
e79a94b9 | 943 | { |
18d715bd | 944 | aPxLeft = aValue.IntegerValue(); |
e79a94b9 | 945 | } |
fd3f6bd0 | 946 | else if (aName == "t" |
947 | || aName == "top") | |
e79a94b9 | 948 | { |
18d715bd | 949 | aPxTop = aValue.IntegerValue(); |
e79a94b9 | 950 | } |
fd3f6bd0 | 951 | else if (aName == "disp" |
952 | || aName == "display") | |
e79a94b9 | 953 | { |
18d715bd | 954 | aDisplayName = aValue; |
e79a94b9 | 955 | } |
fd3f6bd0 | 956 | else if (aName == "w" |
957 | || aName == "width") | |
e79a94b9 | 958 | { |
18d715bd | 959 | aPxWidth = aValue.IntegerValue(); |
e79a94b9 | 960 | } |
fd3f6bd0 | 961 | else if (aName == "h" |
962 | || aName == "height") | |
e79a94b9 | 963 | { |
18d715bd | 964 | aPxHeight = aValue.IntegerValue(); |
e79a94b9 | 965 | } |
18d715bd | 966 | else |
967 | { | |
fd3f6bd0 | 968 | std::cout << "Syntax error: unknown argument " << anArg << ".\n"; |
969 | return 1; | |
18d715bd | 970 | } |
971 | } | |
e79a94b9 | 972 | else if (aViewName.IsEmpty()) |
973 | { | |
974 | aViewName = anArg; | |
975 | } | |
976 | else | |
977 | { | |
fd3f6bd0 | 978 | std::cout << "Syntax error: unknown argument " << anArg << ".\n"; |
979 | return 1; | |
e79a94b9 | 980 | } |
18d715bd | 981 | } |
982 | ||
fd3f6bd0 | 983 | #if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX)) |
984 | if (!aDisplayName.IsEmpty()) | |
985 | { | |
986 | aDisplayName.Clear(); | |
987 | std::cout << "Warning: display parameter will be ignored.\n"; | |
988 | } | |
989 | #endif | |
990 | ||
18d715bd | 991 | ViewerTest_Names aViewNames (aViewName); |
e79a94b9 | 992 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName())) |
18d715bd | 993 | { |
e79a94b9 | 994 | TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName(); |
995 | theDi.Eval (aCommand.ToCString()); | |
2e93433e | 996 | if (is2dMode != -1) |
997 | { | |
998 | ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1); | |
999 | } | |
18d715bd | 1000 | return 0; |
1001 | } | |
1002 | ||
1003 | TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight, | |
9e04ccdc | 1004 | aViewName, aDisplayName, aCopyFrom); |
2e93433e | 1005 | if (is2dMode != -1) |
1006 | { | |
1007 | ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1); | |
1008 | } | |
e79a94b9 | 1009 | theDi << aViewId; |
7fd59977 | 1010 | return 0; |
1011 | } | |
1012 | ||
1eeef710 | 1013 | //! Parse HLR algo type. |
1014 | static Standard_Boolean parseHlrAlgoType (const char* theName, | |
1015 | Prs3d_TypeOfHLR& theType) | |
1016 | { | |
1017 | TCollection_AsciiString aName (theName); | |
1018 | aName.LowerCase(); | |
1019 | if (aName == "polyalgo") | |
1020 | { | |
1021 | theType = Prs3d_TOH_PolyAlgo; | |
1022 | } | |
1023 | else if (aName == "algo") | |
1024 | { | |
1025 | theType = Prs3d_TOH_Algo; | |
1026 | } | |
1027 | else | |
1028 | { | |
1029 | return Standard_False; | |
1030 | } | |
1031 | return Standard_True; | |
1032 | } | |
1033 | ||
0a768f56 | 1034 | //============================================================================== |
1035 | //function : VHLR | |
1036 | //purpose : hidden lines removal algorithm | |
1037 | //============================================================================== | |
1038 | ||
1039 | static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1040 | { | |
1eeef710 | 1041 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); |
1042 | const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
1043 | if (aView.IsNull()) | |
0a768f56 | 1044 | { |
1eeef710 | 1045 | std::cerr << "Error: No opened viewer!\n"; |
0a768f56 | 1046 | return 1; |
1047 | } | |
1048 | ||
1eeef710 | 1049 | Standard_Boolean hasHlrOnArg = Standard_False; |
1050 | Standard_Boolean hasShowHiddenArg = Standard_False; | |
1051 | Standard_Boolean isHLROn = Standard_False; | |
1052 | Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine(); | |
1053 | Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet; | |
1054 | ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView); | |
1055 | for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter) | |
0a768f56 | 1056 | { |
1eeef710 | 1057 | TCollection_AsciiString anArg (argv[anArgIter]); |
1058 | anArg.LowerCase(); | |
1059 | if (anUpdateTool.parseRedrawMode (anArg)) | |
1060 | { | |
1061 | continue; | |
1062 | } | |
1063 | else if (anArg == "-showhidden" | |
1064 | && anArgIter + 1 < argc | |
1065 | && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden)) | |
1066 | { | |
1067 | ++anArgIter; | |
1068 | hasShowHiddenArg = Standard_True; | |
1069 | continue; | |
1070 | } | |
1071 | else if ((anArg == "-type" | |
1072 | || anArg == "-algo" | |
1073 | || anArg == "-algotype") | |
1074 | && anArgIter + 1 < argc | |
1075 | && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR)) | |
1076 | { | |
1077 | ++anArgIter; | |
1078 | continue; | |
1079 | } | |
1080 | else if (!hasHlrOnArg | |
1081 | && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn)) | |
1082 | { | |
1083 | hasHlrOnArg = Standard_True; | |
1084 | continue; | |
1085 | } | |
1086 | // old syntax | |
1087 | else if (!hasShowHiddenArg | |
1088 | && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden)) | |
1089 | { | |
1090 | hasShowHiddenArg = Standard_True; | |
1091 | continue; | |
1092 | } | |
1093 | else | |
1094 | { | |
1095 | std::cout << "Syntax error at '" << argv[anArgIter] << "'\n"; | |
1096 | return 1; | |
1097 | } | |
0a768f56 | 1098 | } |
1eeef710 | 1099 | if (!hasHlrOnArg) |
0a768f56 | 1100 | { |
1eeef710 | 1101 | di << "HLR: " << aView->ComputedMode() << "\n"; |
1102 | di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n"; | |
1103 | di << "HlrAlgo: "; | |
1104 | switch (aCtx->DefaultDrawer()->TypeOfHLR()) | |
1105 | { | |
1106 | case Prs3d_TOH_NotSet: di << "NotSet\n"; break; | |
1107 | case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break; | |
1108 | case Prs3d_TOH_Algo: di << "Algo\n"; break; | |
1109 | } | |
1110 | anUpdateTool.Invalidate(); | |
1111 | return 0; | |
0a768f56 | 1112 | } |
1113 | ||
1eeef710 | 1114 | Standard_Boolean toRecompute = Standard_False; |
1115 | if (aTypeOfHLR != Prs3d_TOH_NotSet | |
1116 | && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR()) | |
e9224045 | 1117 | { |
1eeef710 | 1118 | toRecompute = Standard_True; |
1119 | aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR); | |
1120 | } | |
1121 | if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine()) | |
1122 | { | |
1123 | toRecompute = Standard_True; | |
1124 | if (toShowHidden) | |
e9224045 | 1125 | { |
1eeef710 | 1126 | aCtx->DefaultDrawer()->EnableDrawHiddenLine(); |
e9224045 | 1127 | } |
1128 | else | |
1129 | { | |
1eeef710 | 1130 | aCtx->DefaultDrawer()->DisableDrawHiddenLine(); |
e9224045 | 1131 | } |
1eeef710 | 1132 | } |
e9224045 | 1133 | |
1eeef710 | 1134 | // redisplay shapes |
1135 | if (aView->ComputedMode() && isHLROn && toRecompute) | |
1136 | { | |
1137 | AIS_ListOfInteractive aListOfShapes; | |
1138 | aCtx->DisplayedObjects (aListOfShapes); | |
1139 | for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next()) | |
e9224045 | 1140 | { |
1eeef710 | 1141 | if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value())) |
e9224045 | 1142 | { |
1eeef710 | 1143 | aCtx->Redisplay (aShape, Standard_False); |
e9224045 | 1144 | } |
1145 | } | |
1146 | } | |
0a768f56 | 1147 | |
1eeef710 | 1148 | aView->SetComputedMode (isHLROn); |
0a768f56 | 1149 | return 0; |
1150 | } | |
1151 | ||
1152 | //============================================================================== | |
1153 | //function : VHLRType | |
1154 | //purpose : change type of using HLR algorithm | |
1155 | //============================================================================== | |
1156 | ||
1eeef710 | 1157 | static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv) |
0a768f56 | 1158 | { |
1eeef710 | 1159 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); |
1160 | const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
1161 | if (aView.IsNull()) | |
0a768f56 | 1162 | { |
1eeef710 | 1163 | std::cerr << "Error: No opened viewer!\n"; |
0a768f56 | 1164 | return 1; |
1165 | } | |
1166 | ||
1eeef710 | 1167 | Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet; |
1168 | ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView); | |
1169 | AIS_ListOfInteractive aListOfShapes; | |
1170 | for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter) | |
0a768f56 | 1171 | { |
1eeef710 | 1172 | TCollection_AsciiString anArg (argv[anArgIter]); |
1173 | anArg.LowerCase(); | |
1174 | if (anUpdateTool.parseRedrawMode (anArg)) | |
0a768f56 | 1175 | { |
1eeef710 | 1176 | continue; |
0a768f56 | 1177 | } |
1eeef710 | 1178 | else if ((anArg == "-type" |
1179 | || anArg == "-algo" | |
1180 | || anArg == "-algotype") | |
1181 | && anArgIter + 1 < argc | |
1182 | && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR)) | |
1183 | { | |
1184 | ++anArgIter; | |
1185 | continue; | |
1186 | } | |
1187 | // old syntax | |
1188 | else if (aTypeOfHLR == Prs3d_TOH_NotSet | |
1189 | && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR)) | |
1190 | { | |
1191 | continue; | |
1192 | } | |
1193 | else | |
0a768f56 | 1194 | { |
1195 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
1eeef710 | 1196 | TCollection_AsciiString aName (argv[anArgIter]); |
0a768f56 | 1197 | if (!aMap.IsBound2 (aName)) |
1198 | { | |
1eeef710 | 1199 | std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n"; |
1200 | return 1; | |
0a768f56 | 1201 | } |
1eeef710 | 1202 | |
1203 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName)); | |
1204 | if (aShape.IsNull()) | |
1205 | { | |
1206 | std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n"; | |
1207 | return 1; | |
1208 | } | |
1209 | aListOfShapes.Append (aShape); | |
1210 | continue; | |
0a768f56 | 1211 | } |
1eeef710 | 1212 | } |
1213 | if (aTypeOfHLR == Prs3d_TOH_NotSet) | |
1214 | { | |
1215 | std::cout << "Syntax error: wrong number of arguments!\n"; | |
1216 | return 1; | |
1217 | } | |
1218 | ||
1219 | const Standard_Boolean isGlobal = aListOfShapes.IsEmpty(); | |
1220 | if (isGlobal) | |
1221 | { | |
1222 | aCtx->DisplayedObjects (aListOfShapes); | |
1223 | aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR); | |
0a768f56 | 1224 | } |
1225 | ||
1eeef710 | 1226 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next()) |
1227 | { | |
1228 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()); | |
1229 | if (aShape.IsNull()) | |
1230 | { | |
1231 | continue; | |
1232 | } | |
1233 | ||
1234 | const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR | |
1235 | && aView->ComputedMode(); | |
1236 | if (!isGlobal | |
1237 | || aShape->TypeOfHLR() != aTypeOfHLR) | |
1238 | { | |
1239 | aShape->SetTypeOfHLR (aTypeOfHLR); | |
1240 | } | |
1241 | if (toUpdateShape) | |
1242 | { | |
1243 | aCtx->Redisplay (aShape, Standard_False); | |
1244 | } | |
1245 | } | |
0a768f56 | 1246 | return 0; |
1247 | } | |
1248 | ||
18d715bd | 1249 | //============================================================================== |
1250 | //function : FindViewIdByWindowHandle | |
1251 | //purpose : Find theView Id in the map of views by window handle | |
1252 | //============================================================================== | |
1253 | #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
1254 | TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle) | |
1255 | { | |
1256 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator | |
1257 | anIter(ViewerTest_myViews); anIter.More(); anIter.Next()) | |
1258 | { | |
1259 | Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window()); | |
1260 | if (aWindowHandle == theWindowHandle) | |
1261 | return anIter.Key1(); | |
1262 | } | |
1263 | return TCollection_AsciiString(""); | |
1264 | } | |
1265 | #endif | |
1266 | ||
e084dbbc | 1267 | //! Make the view active |
1268 | void ActivateView (const TCollection_AsciiString& theViewName, | |
1269 | Standard_Boolean theToUpdate = Standard_True) | |
18d715bd | 1270 | { |
1271 | const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); | |
e084dbbc | 1272 | if (aView.IsNull()) |
18d715bd | 1273 | { |
e084dbbc | 1274 | return; |
1275 | } | |
18d715bd | 1276 | |
e084dbbc | 1277 | Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView); |
1278 | if (!anAISContext.IsNull()) | |
1279 | { | |
1280 | if (!ViewerTest::CurrentView().IsNull()) | |
1281 | { | |
1282 | TCollection_AsciiString aTitle("3D View - "); | |
1283 | aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()); | |
18d715bd | 1284 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); |
e084dbbc | 1285 | } |
1286 | ||
1287 | ViewerTest::CurrentView (aView); | |
1288 | ViewerTest::SetAISContext (anAISContext); | |
1289 | TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ") + theViewName + "(*)"; | |
1290 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
1eeef710 | 1291 | #if defined(_WIN32) |
e084dbbc | 1292 | VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window()); |
18d715bd | 1293 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
e084dbbc | 1294 | VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window()); |
18d715bd | 1295 | #else |
e084dbbc | 1296 | VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window()); |
18d715bd | 1297 | #endif |
e084dbbc | 1298 | SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); |
1299 | if (theToUpdate) | |
1300 | { | |
18d715bd | 1301 | ViewerTest::CurrentView()->Redraw(); |
1302 | } | |
1303 | } | |
1304 | } | |
1305 | ||
0e93d9e5 | 1306 | //============================================================================== |
1307 | //function : RemoveView | |
1308 | //purpose : | |
1309 | //============================================================================== | |
1310 | void ViewerTest::RemoveView (const Handle(V3d_View)& theView, | |
1311 | const Standard_Boolean theToRemoveContext) | |
1312 | { | |
1313 | if (!ViewerTest_myViews.IsBound2 (theView)) | |
1314 | { | |
1315 | return; | |
1316 | } | |
1317 | ||
1318 | const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView); | |
1319 | RemoveView (aViewName, theToRemoveContext); | |
1320 | } | |
1321 | ||
18d715bd | 1322 | //============================================================================== |
1323 | //function : RemoveView | |
1324 | //purpose : Close and remove view from display, clear maps if neccessary | |
1325 | //============================================================================== | |
1326 | void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved) | |
1327 | { | |
1328 | if (!ViewerTest_myViews.IsBound1(theViewName)) | |
1329 | { | |
1330 | cout << "Wrong view name\n"; | |
1331 | return; | |
1332 | } | |
1333 | ||
1334 | // Activate another view if it's active now | |
1335 | if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView()) | |
1336 | { | |
1337 | if (ViewerTest_myViews.Extent() > 1) | |
1338 | { | |
1339 | TCollection_AsciiString aNewViewName; | |
c48e2889 | 1340 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews); |
1341 | anIter.More(); anIter.Next()) | |
1342 | { | |
18d715bd | 1343 | if (anIter.Key1() != theViewName) |
1344 | { | |
1345 | aNewViewName = anIter.Key1(); | |
1346 | break; | |
1347 | } | |
c48e2889 | 1348 | } |
1349 | ActivateView (aNewViewName); | |
18d715bd | 1350 | } |
1351 | else | |
1352 | { | |
e084dbbc | 1353 | VT_GetWindow().Nullify(); |
1354 | ViewerTest::CurrentView (Handle(V3d_View)()); | |
18d715bd | 1355 | if (isContextRemoved) |
1356 | { | |
1357 | Handle(AIS_InteractiveContext) anEmptyContext; | |
1358 | ViewerTest::SetAISContext(anEmptyContext); | |
1359 | } | |
1360 | } | |
1361 | } | |
1362 | ||
1363 | // Delete view | |
1364 | Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName); | |
1365 | Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView); | |
1366 | ||
1367 | // Remove view resources | |
18d715bd | 1368 | ViewerTest_myViews.UnBind1(theViewName); |
851dacdb | 1369 | aView->Window()->Unmap(); |
18d715bd | 1370 | aView->Remove(); |
1371 | ||
1372 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
1373 | XFlush (GetDisplayConnection()->GetDisplay()); | |
1374 | #endif | |
1375 | ||
1376 | // Keep context opened only if the closed view is last to avoid | |
1377 | // unused empty contexts | |
1378 | if (!aCurrentContext.IsNull()) | |
1379 | { | |
1380 | // Check if there are more difined views in the viewer | |
1381 | aCurrentContext->CurrentViewer()->InitDefinedViews(); | |
1382 | if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews()) | |
1383 | { | |
1384 | // Remove driver if there is no viewers that use it | |
1385 | Standard_Boolean isRemoveDriver = Standard_True; | |
1386 | for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
1387 | anIter(ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
1388 | { | |
1389 | if (aCurrentContext != anIter.Key2() && | |
1390 | aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver()) | |
1391 | { | |
1392 | isRemoveDriver = Standard_False; | |
1393 | break; | |
1394 | } | |
1395 | } | |
2ec85268 | 1396 | |
1397 | aCurrentContext->RemoveAll (Standard_False); | |
18d715bd | 1398 | if(isRemoveDriver) |
1399 | { | |
1400 | ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver()); | |
1401 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
1402 | #if TCL_MAJOR_VERSION < 8 | |
1403 | Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay())); | |
1404 | #else | |
1405 | Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay())); | |
1406 | #endif | |
1407 | #endif | |
1408 | } | |
1409 | ||
1410 | ViewerTest_myContexts.UnBind2(aCurrentContext); | |
1411 | } | |
1412 | } | |
1413 | cout << "3D View - " << theViewName << " was deleted.\n"; | |
fd3f6bd0 | 1414 | if (Draw_ToExitOnCloseView) |
1415 | { | |
1416 | Draw_Interprete ("exit"); | |
1417 | } | |
18d715bd | 1418 | } |
1419 | ||
1420 | //============================================================================== | |
1421 | //function : VClose | |
1422 | //purpose : Remove the view defined by its name | |
1423 | //============================================================================== | |
1424 | ||
d0cc1cb7 | 1425 | static int VClose (Draw_Interpretor& /*theDi*/, |
1426 | Standard_Integer theArgsNb, | |
1427 | const char** theArgVec) | |
18d715bd | 1428 | { |
18d715bd | 1429 | NCollection_List<TCollection_AsciiString> aViewList; |
d0cc1cb7 | 1430 | if (theArgsNb > 1) |
18d715bd | 1431 | { |
d0cc1cb7 | 1432 | TCollection_AsciiString anArg (theArgVec[1]); |
1433 | anArg.UpperCase(); | |
1434 | if (anArg.IsEqual ("ALL") | |
1435 | || anArg.IsEqual ("*")) | |
1436 | { | |
1437 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews); | |
1438 | anIter.More(); anIter.Next()) | |
1439 | { | |
1440 | aViewList.Append (anIter.Key1()); | |
1441 | } | |
1442 | if (aViewList.IsEmpty()) | |
1443 | { | |
1444 | std::cout << "No view to close\n"; | |
1445 | return 0; | |
1446 | } | |
1447 | } | |
1448 | else | |
18d715bd | 1449 | { |
d0cc1cb7 | 1450 | ViewerTest_Names aViewName (theArgVec[1]); |
1451 | if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName())) | |
1452 | { | |
1453 | std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n"; | |
1454 | return 1; | |
1455 | } | |
1456 | aViewList.Append (aViewName.GetViewName()); | |
18d715bd | 1457 | } |
1458 | } | |
1459 | else | |
1460 | { | |
d0cc1cb7 | 1461 | // close active view |
1462 | if (ViewerTest::CurrentView().IsNull()) | |
1463 | { | |
1464 | std::cerr << "No active view!\n"; | |
1465 | return 1; | |
1466 | } | |
1467 | aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView())); | |
18d715bd | 1468 | } |
1469 | ||
d0cc1cb7 | 1470 | Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1); |
18d715bd | 1471 | for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList); |
1472 | anIter.More(); anIter.Next()) | |
1473 | { | |
d0cc1cb7 | 1474 | ViewerTest::RemoveView (anIter.Value(), toRemoveContext); |
18d715bd | 1475 | } |
1476 | ||
1477 | return 0; | |
1478 | } | |
1479 | ||
1480 | //============================================================================== | |
1481 | //function : VActivate | |
1482 | //purpose : Activate the view defined by its ID | |
1483 | //============================================================================== | |
1484 | ||
1485 | static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
1486 | { | |
e084dbbc | 1487 | if (theArgsNb == 1) |
18d715bd | 1488 | { |
1489 | theDi.Eval("vviewlist"); | |
1490 | return 0; | |
1491 | } | |
1492 | ||
e084dbbc | 1493 | TCollection_AsciiString aNameString; |
1494 | Standard_Boolean toUpdate = Standard_True; | |
1495 | Standard_Boolean toActivate = Standard_True; | |
1496 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
18d715bd | 1497 | { |
e084dbbc | 1498 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
1499 | anArg.LowerCase(); | |
1500 | if (toUpdate | |
1501 | && anArg == "-noupdate") | |
1502 | { | |
1503 | toUpdate = Standard_False; | |
1504 | } | |
1505 | else if (toActivate | |
1506 | && aNameString.IsEmpty() | |
1507 | && anArg == "none") | |
1508 | { | |
1509 | TCollection_AsciiString aTitle("3D View - "); | |
1510 | aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView()); | |
1511 | SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString()); | |
1512 | VT_GetWindow().Nullify(); | |
1513 | ViewerTest::CurrentView (Handle(V3d_View)()); | |
1514 | ViewerTest::ResetEventManager(); | |
1515 | theDi << theArgVec[0] << ": all views are inactive\n"; | |
1516 | toActivate = Standard_False; | |
1517 | } | |
1518 | else if (toActivate | |
1519 | && aNameString.IsEmpty()) | |
1520 | { | |
1521 | aNameString = theArgVec[anArgIter]; | |
1522 | } | |
1523 | else | |
1524 | { | |
1525 | std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n"; | |
1526 | return 1; | |
1527 | } | |
18d715bd | 1528 | } |
1529 | ||
e084dbbc | 1530 | if (!toActivate) |
1531 | { | |
1532 | return 0; | |
1533 | } | |
1534 | else if (aNameString.IsEmpty()) | |
1535 | { | |
1536 | std::cout << "Syntax error: wrong number of arguments\n"; | |
1537 | return 1; | |
1538 | } | |
18d715bd | 1539 | |
1540 | // Check if this view exists in the viewer with the driver | |
e084dbbc | 1541 | ViewerTest_Names aViewNames (aNameString); |
18d715bd | 1542 | if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName())) |
1543 | { | |
e084dbbc | 1544 | theDi << "Syntax error: wrong view name '" << aNameString << "'\n"; |
18d715bd | 1545 | return 1; |
1546 | } | |
1547 | ||
1548 | // Check if it is active already | |
1549 | if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName())) | |
1550 | { | |
1551 | theDi << theArgVec[0] << ": the view is active already\n"; | |
1552 | return 0; | |
1553 | } | |
1554 | ||
e084dbbc | 1555 | ActivateView (aViewNames.GetViewName(), toUpdate); |
18d715bd | 1556 | return 0; |
1557 | } | |
1558 | ||
1559 | //============================================================================== | |
1560 | //function : VViewList | |
1561 | //purpose : Print current list of views per viewer and graphic driver ID | |
1562 | // shared between viewers | |
1563 | //============================================================================== | |
1564 | ||
1565 | static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
1566 | { | |
1567 | if (theArgsNb > 2) | |
1568 | { | |
1569 | theDi << theArgVec[0] << ": Wrong number of command arguments\n" | |
29cb310a | 1570 | << "Usage: " << theArgVec[0] << " name"; |
18d715bd | 1571 | return 1; |
1572 | } | |
1573 | if (ViewerTest_myContexts.Size() < 1) | |
1574 | return 0; | |
1575 | ||
18d715bd | 1576 | Standard_Boolean isTreeView = |
29cb310a | 1577 | (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 )); |
18d715bd | 1578 | |
1579 | if (isTreeView) | |
c48e2889 | 1580 | { |
18d715bd | 1581 | theDi << theArgVec[0] <<":\n"; |
c48e2889 | 1582 | } |
18d715bd | 1583 | |
c48e2889 | 1584 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers); |
1585 | aDriverIter.More(); aDriverIter.Next()) | |
1586 | { | |
1587 | if (isTreeView) | |
1588 | theDi << aDriverIter.Key1() << ":\n"; | |
18d715bd | 1589 | |
c48e2889 | 1590 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator |
1591 | aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next()) | |
1592 | { | |
1593 | if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1) | |
18d715bd | 1594 | { |
c48e2889 | 1595 | if (isTreeView) |
18d715bd | 1596 | { |
c48e2889 | 1597 | TCollection_AsciiString aContextName(aContextIter.Key1()); |
1598 | theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n"; | |
1599 | } | |
18d715bd | 1600 | |
c48e2889 | 1601 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews); |
1602 | aViewIter.More(); aViewIter.Next()) | |
1603 | { | |
1604 | if (aViewIter.Key1().Search(aContextIter.Key1()) != -1) | |
18d715bd | 1605 | { |
c48e2889 | 1606 | TCollection_AsciiString aViewName(aViewIter.Key1()); |
1607 | if (isTreeView) | |
18d715bd | 1608 | { |
c48e2889 | 1609 | if (aViewIter.Value() == ViewerTest::CurrentView()) |
1610 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n"; | |
18d715bd | 1611 | else |
c48e2889 | 1612 | theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n"; |
1613 | } | |
1614 | else | |
1615 | { | |
1616 | theDi << aViewName << " "; | |
18d715bd | 1617 | } |
1618 | } | |
1619 | } | |
1620 | } | |
1621 | } | |
c48e2889 | 1622 | } |
18d715bd | 1623 | return 0; |
1624 | } | |
1625 | ||
7fd59977 | 1626 | //============================================================================== |
4fe56619 | 1627 | //function : VT_ProcessKeyPress |
7fd59977 | 1628 | //purpose : Handle KeyPress event from a CString |
1629 | //============================================================================== | |
4fe56619 | 1630 | void VT_ProcessKeyPress (const char* buf_ret) |
7fd59977 | 1631 | { |
1632 | //cout << "KeyPress" << endl; | |
1633 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
7fd59977 | 1634 | // Letter in alphabetic order |
1635 | ||
2e93433e | 1636 | if (!strcasecmp (buf_ret, "A") |
1637 | && !ViewerTest_V3dView::IsCurrentViewIn2DMode()) | |
b514beda | 1638 | { |
7fd59977 | 1639 | // AXO |
1640 | aView->SetProj(V3d_XposYnegZpos); | |
1641 | } | |
2e93433e | 1642 | else if (!strcasecmp (buf_ret, "D") |
1643 | && !ViewerTest_V3dView::IsCurrentViewIn2DMode()) | |
b514beda | 1644 | { |
7fd59977 | 1645 | // Reset |
1646 | aView->Reset(); | |
1647 | } | |
b514beda | 1648 | else if (!strcasecmp (buf_ret, "F")) |
1649 | { | |
b586500b | 1650 | if (ViewerTest::GetAISContext()->NbSelected() > 0) |
1651 | { | |
1652 | ViewerTest::GetAISContext()->FitSelected (aView); | |
1653 | } | |
1654 | else | |
1655 | { | |
1656 | // FitAll | |
1657 | aView->FitAll(); | |
1658 | } | |
7fd59977 | 1659 | } |
b514beda | 1660 | else if (!strcasecmp (buf_ret, "H")) |
1661 | { | |
7fd59977 | 1662 | // HLR |
1eeef710 | 1663 | std::cout << "HLR" << std::endl; |
de75ed09 | 1664 | aView->SetComputedMode (!aView->ComputedMode()); |
1eeef710 | 1665 | aView->Redraw(); |
7fd59977 | 1666 | } |
b514beda | 1667 | else if (!strcasecmp (buf_ret, "P")) |
1668 | { | |
0a768f56 | 1669 | // Type of HLR |
1670 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
1671 | if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo) | |
1672 | aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo); | |
1673 | else | |
1674 | aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo); | |
c3282ec1 | 1675 | if (aContext->NbSelected()==0) |
0a768f56 | 1676 | { |
1677 | AIS_ListOfInteractive aListOfShapes; | |
1678 | aContext->DisplayedObjects(aListOfShapes); | |
1679 | for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); | |
1680 | anIter.More(); anIter.Next()) | |
1681 | { | |
1682 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()); | |
1683 | if (aShape.IsNull()) | |
1684 | continue; | |
1685 | if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo) | |
1686 | aShape->SetTypeOfHLR (Prs3d_TOH_Algo); | |
1687 | else | |
1688 | aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo); | |
36132a2e | 1689 | aContext->Redisplay (aShape, Standard_False); |
0a768f56 | 1690 | } |
1691 | } | |
1692 | else | |
1693 | { | |
c3282ec1 | 1694 | for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected()) |
0a768f56 | 1695 | { |
c3282ec1 | 1696 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive()); |
0a768f56 | 1697 | if (aShape.IsNull()) |
1698 | continue; | |
1699 | if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo) | |
1700 | aShape->SetTypeOfHLR (Prs3d_TOH_Algo); | |
1701 | else | |
1702 | aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo); | |
36132a2e | 1703 | aContext->Redisplay (aShape, Standard_False); |
0a768f56 | 1704 | } |
1705 | } | |
1706 | ||
1707 | aContext->UpdateCurrentViewer(); | |
4269bd1b | 1708 | |
0a768f56 | 1709 | } |
b514beda | 1710 | else if (!strcasecmp (buf_ret, "S")) |
1711 | { | |
1712 | std::cout << "setup Shaded display mode" << std::endl; | |
4fe56619 | 1713 | |
7fd59977 | 1714 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
c3282ec1 | 1715 | if(Ctx->NbSelected()==0) |
0577ae8c | 1716 | Ctx->SetDisplayMode (AIS_Shaded, Standard_True); |
7fd59977 | 1717 | else{ |
c3282ec1 | 1718 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) |
1719 | Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False); | |
7fd59977 | 1720 | Ctx->UpdateCurrentViewer(); |
1721 | } | |
1722 | } | |
b514beda | 1723 | else if (!strcasecmp (buf_ret, "U")) |
1724 | { | |
41811896 | 1725 | // Unset display mode |
b514beda | 1726 | std::cout << "reset display mode to defaults" << std::endl; |
4fe56619 | 1727 | |
7fd59977 | 1728 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
c3282ec1 | 1729 | if(Ctx->NbSelected()==0) |
0577ae8c | 1730 | Ctx->SetDisplayMode (AIS_WireFrame, Standard_True); |
7fd59977 | 1731 | else{ |
c3282ec1 | 1732 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) |
1733 | Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False); | |
7fd59977 | 1734 | Ctx->UpdateCurrentViewer(); |
1735 | } | |
1736 | ||
1737 | } | |
2e93433e | 1738 | else if (!strcasecmp (buf_ret, "T") |
1739 | && !ViewerTest_V3dView::IsCurrentViewIn2DMode()) | |
b514beda | 1740 | { |
7fd59977 | 1741 | // Top |
1742 | aView->SetProj(V3d_Zpos); | |
1743 | } | |
2e93433e | 1744 | else if (!strcasecmp (buf_ret, "B") |
1745 | && !ViewerTest_V3dView::IsCurrentViewIn2DMode()) | |
b514beda | 1746 | { |
41811896 | 1747 | // Bottom |
7fd59977 | 1748 | aView->SetProj(V3d_Zneg); |
1749 | } | |
2e93433e | 1750 | else if (!strcasecmp (buf_ret, "L") |
1751 | && !ViewerTest_V3dView::IsCurrentViewIn2DMode()) | |
b514beda | 1752 | { |
41811896 | 1753 | // Left |
7fd59977 | 1754 | aView->SetProj(V3d_Xneg); |
1755 | } | |
2e93433e | 1756 | else if (!strcasecmp (buf_ret, "R") |
1757 | && !ViewerTest_V3dView::IsCurrentViewIn2DMode()) | |
b514beda | 1758 | { |
41811896 | 1759 | // Right |
7fd59977 | 1760 | aView->SetProj(V3d_Xpos); |
1761 | } | |
b514beda | 1762 | else if (!strcasecmp (buf_ret, "W")) |
1763 | { | |
1764 | std::cout << "setup WireFrame display mode" << std::endl; | |
7fd59977 | 1765 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); |
c3282ec1 | 1766 | if(Ctx->NbSelected()==0) |
0577ae8c | 1767 | Ctx->SetDisplayMode (AIS_WireFrame, Standard_True); |
7fd59977 | 1768 | else{ |
c3282ec1 | 1769 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) |
1770 | Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False); | |
7fd59977 | 1771 | Ctx->UpdateCurrentViewer(); |
1772 | } | |
1773 | } | |
b514beda | 1774 | else if (!strcasecmp (buf_ret, ",")) |
1775 | { | |
7fd59977 | 1776 | ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView()); |
7fd59977 | 1777 | } |
b514beda | 1778 | else if (!strcasecmp (buf_ret, ".")) |
1779 | { | |
7fd59977 | 1780 | ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView()); |
1781 | } | |
f978241f | 1782 | else if (!strcasecmp (buf_ret, "/")) |
1783 | { | |
1784 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); | |
1785 | if (aCamera->IsStereo()) | |
1786 | { | |
1787 | aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01); | |
1788 | aView->Redraw(); | |
1789 | } | |
1790 | } | |
1791 | else if (!strcasecmp (buf_ret, "*")) | |
1792 | { | |
1793 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); | |
1794 | if (aCamera->IsStereo()) | |
1795 | { | |
1796 | aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01); | |
1797 | aView->Redraw(); | |
1798 | } | |
1799 | } | |
b514beda | 1800 | else if (*buf_ret == THE_KEY_DELETE) |
1801 | { | |
1802 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
1803 | if (!aCtx.IsNull() | |
b514beda | 1804 | && aCtx->NbSelected() > 0) |
1805 | { | |
1806 | Draw_Interprete ("verase"); | |
1807 | } | |
1808 | } | |
fd3f6bd0 | 1809 | else if (*buf_ret == THE_KEY_ESCAPE) |
1810 | { | |
1811 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
1812 | if (!aCtx.IsNull() | |
1813 | && Draw_ToCloseViewOnEsc) | |
1814 | { | |
1815 | Draw_Interprete (Draw_ToExitOnCloseView ? "exit" : "vclose"); | |
1816 | } | |
1817 | } | |
b514beda | 1818 | else |
1819 | { | |
1820 | // Number | |
8c088c52 | 1821 | const Standard_Integer aSelMode = Draw::Atoi(buf_ret); |
1822 | if (aSelMode >= 0 && aSelMode <= 7) | |
1823 | { | |
1824 | bool toEnable = true; | |
1825 | if (const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext()) | |
1826 | { | |
1827 | AIS_ListOfInteractive aPrsList; | |
1828 | aCtx->DisplayedObjects (aPrsList); | |
1829 | for (AIS_ListOfInteractive::Iterator aPrsIter (aPrsList); aPrsIter.More() && toEnable; aPrsIter.Next()) | |
1830 | { | |
1831 | TColStd_ListOfInteger aModes; | |
1832 | aCtx->ActivatedModes (aPrsIter.Value(), aModes); | |
1833 | for (TColStd_ListOfInteger::Iterator aModeIter (aModes); aModeIter.More() && toEnable; aModeIter.Next()) | |
1834 | { | |
1835 | if (aModeIter.Value() == aSelMode) | |
1836 | { | |
1837 | toEnable = false; | |
1838 | } | |
1839 | } | |
1840 | } | |
1841 | } | |
1842 | TCollection_AsciiString aCmd = TCollection_AsciiString ("vselmode ") + aSelMode + (toEnable ? " 1" : " 0"); | |
1843 | Draw_Interprete (aCmd.ToCString()); | |
1844 | } | |
7fd59977 | 1845 | } |
1846 | } | |
1847 | ||
1848 | //============================================================================== | |
4fe56619 | 1849 | //function : VT_ProcessExpose |
7fd59977 | 1850 | //purpose : Redraw the View on an Expose Event |
1851 | //============================================================================== | |
4fe56619 | 1852 | void VT_ProcessExpose() |
1853 | { | |
1854 | Handle(V3d_View) aView3d = ViewerTest::CurrentView(); | |
1855 | if (!aView3d.IsNull()) | |
1856 | { | |
1857 | aView3d->Redraw(); | |
1858 | } | |
7fd59977 | 1859 | } |
1860 | ||
1861 | //============================================================================== | |
4fe56619 | 1862 | //function : VT_ProcessConfigure |
7fd59977 | 1863 | //purpose : Resize the View on an Configure Event |
1864 | //============================================================================== | |
4fe56619 | 1865 | void VT_ProcessConfigure() |
7fd59977 | 1866 | { |
4fe56619 | 1867 | Handle(V3d_View) aView3d = ViewerTest::CurrentView(); |
1868 | if (aView3d.IsNull()) | |
1869 | { | |
1870 | return; | |
1871 | } | |
1872 | ||
1873 | aView3d->MustBeResized(); | |
1874 | aView3d->Update(); | |
1875 | aView3d->Redraw(); | |
7fd59977 | 1876 | } |
1877 | ||
1878 | //============================================================================== | |
4fe56619 | 1879 | //function : VT_ProcessButton1Press |
7fd59977 | 1880 | //purpose : Picking |
1881 | //============================================================================== | |
e79a94b9 | 1882 | Standard_Boolean VT_ProcessButton1Press (Standard_Integer , |
1883 | const char** theArgVec, | |
1884 | Standard_Boolean theToPick, | |
1885 | Standard_Boolean theIsShift) | |
7fd59977 | 1886 | { |
1beb58d7 | 1887 | if (TheIsAnimating) |
1888 | { | |
1889 | TheIsAnimating = Standard_False; | |
1890 | return Standard_False; | |
1891 | } | |
1892 | ||
e79a94b9 | 1893 | if (theToPick) |
1894 | { | |
7fd59977 | 1895 | Standard_Real X, Y, Z; |
e79a94b9 | 1896 | ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z); |
7fd59977 | 1897 | |
e79a94b9 | 1898 | Draw::Set (theArgVec[1], X); |
1899 | Draw::Set (theArgVec[2], Y); | |
1900 | Draw::Set (theArgVec[3], Z); | |
1901 | } | |
7fd59977 | 1902 | |
e79a94b9 | 1903 | if (theIsShift) |
1904 | { | |
1905 | ViewerTest::CurrentEventManager()->ShiftSelect(); | |
1906 | } | |
7fd59977 | 1907 | else |
e79a94b9 | 1908 | { |
1909 | ViewerTest::CurrentEventManager()->Select(); | |
1910 | } | |
7fd59977 | 1911 | |
e79a94b9 | 1912 | return Standard_False; |
7fd59977 | 1913 | } |
1914 | ||
1915 | //============================================================================== | |
4fe56619 | 1916 | //function : VT_ProcessButton1Release |
1917 | //purpose : End selecting | |
7fd59977 | 1918 | //============================================================================== |
4fe56619 | 1919 | void VT_ProcessButton1Release (Standard_Boolean theIsShift) |
1920 | { | |
1921 | if (IsDragged) | |
1922 | { | |
1923 | IsDragged = Standard_False; | |
1924 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
1925 | if (theIsShift) | |
1926 | { | |
2157d6ac | 1927 | EM->ShiftSelect (X_ButtonPress, Y_ButtonPress, |
1928 | X_Motion, Y_Motion); | |
4fe56619 | 1929 | } |
1930 | else | |
1931 | { | |
2157d6ac | 1932 | EM->Select (X_ButtonPress, Y_ButtonPress, |
1933 | X_Motion, Y_Motion); | |
4fe56619 | 1934 | } |
1935 | } | |
1936 | } | |
7fd59977 | 1937 | |
4fe56619 | 1938 | //============================================================================== |
1939 | //function : VT_ProcessButton3Press | |
1940 | //purpose : Start Rotation | |
1941 | //============================================================================== | |
1942 | void VT_ProcessButton3Press() | |
1943 | { | |
2e93433e | 1944 | if (ViewerTest_V3dView::IsCurrentViewIn2DMode()) |
1945 | { | |
1946 | return; | |
1947 | } | |
1948 | ||
7fd59977 | 1949 | Start_Rot = 1; |
1eeef710 | 1950 | HasHlrOnBeforeRotation = ViewerTest::CurrentView()->ComputedMode(); |
1951 | if (HasHlrOnBeforeRotation) | |
de75ed09 | 1952 | { |
1953 | ViewerTest::CurrentView()->SetComputedMode (Standard_False); | |
1954 | } | |
7fd59977 | 1955 | ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress ); |
7fd59977 | 1956 | } |
4fe56619 | 1957 | |
7fd59977 | 1958 | //============================================================================== |
4fe56619 | 1959 | //function : VT_ProcessButton3Release |
1960 | //purpose : End rotation | |
7fd59977 | 1961 | //============================================================================== |
4fe56619 | 1962 | void VT_ProcessButton3Release() |
1963 | { | |
1964 | if (Start_Rot) | |
1965 | { | |
7fd59977 | 1966 | Start_Rot = 0; |
1eeef710 | 1967 | if (HasHlrOnBeforeRotation) |
de75ed09 | 1968 | { |
1eeef710 | 1969 | HasHlrOnBeforeRotation = Standard_False; |
de75ed09 | 1970 | ViewerTest::CurrentView()->SetComputedMode (Standard_True); |
1eeef710 | 1971 | ViewerTest::CurrentView()->Redraw(); |
de75ed09 | 1972 | } |
7fd59977 | 1973 | } |
7fd59977 | 1974 | } |
1975 | ||
7fd59977 | 1976 | //============================================================================== |
1977 | //function : ProcessControlButton1Motion | |
1978 | //purpose : Zoom | |
1979 | //============================================================================== | |
1980 | ||
900f7229 | 1981 | #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX) |
7fd59977 | 1982 | static void ProcessControlButton1Motion() |
1983 | { | |
1984 | ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion); | |
1985 | ||
1986 | X_ButtonPress = X_Motion; | |
1987 | Y_ButtonPress = Y_Motion; | |
1988 | } | |
900f7229 | 1989 | #endif |
7fd59977 | 1990 | |
1991 | //============================================================================== | |
4fe56619 | 1992 | //function : VT_ProcessControlButton2Motion |
1993 | //purpose : Panning | |
7fd59977 | 1994 | //============================================================================== |
4fe56619 | 1995 | void VT_ProcessControlButton2Motion() |
7fd59977 | 1996 | { |
197ac94e | 1997 | Standard_Integer aDx = X_Motion - X_ButtonPress; |
1998 | Standard_Integer aDy = Y_Motion - Y_ButtonPress; | |
7fd59977 | 1999 | |
197ac94e | 2000 | aDy = -aDy; // Xwindow Y axis is from top to Bottom |
7fd59977 | 2001 | |
197ac94e | 2002 | ViewerTest::CurrentView()->Pan (aDx, aDy); |
7fd59977 | 2003 | |
2004 | X_ButtonPress = X_Motion; | |
2005 | Y_ButtonPress = Y_Motion; | |
2006 | } | |
2007 | ||
2008 | //============================================================================== | |
4fe56619 | 2009 | //function : VT_ProcessControlButton3Motion |
7fd59977 | 2010 | //purpose : Rotation |
2011 | //============================================================================== | |
4fe56619 | 2012 | void VT_ProcessControlButton3Motion() |
7fd59977 | 2013 | { |
4fe56619 | 2014 | if (Start_Rot) |
2015 | { | |
2016 | ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion); | |
2017 | } | |
7fd59977 | 2018 | } |
2019 | ||
2020 | //============================================================================== | |
4fe56619 | 2021 | //function : VT_ProcessMotion |
2022 | //purpose : | |
7fd59977 | 2023 | //============================================================================== |
4fe56619 | 2024 | void VT_ProcessMotion() |
7fd59977 | 2025 | { |
2026 | //pre-hilights detected objects at mouse position | |
2027 | ||
2028 | Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
2029 | EM->MoveTo(X_Motion, Y_Motion); | |
2030 | } | |
2031 | ||
2032 | ||
2033 | void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix) | |
2034 | { | |
2035 | Xpix = X_Motion;Ypix=Y_Motion; | |
2036 | } | |
2037 | ||
44b8f2d6 | 2038 | //============================================================================== |
2039 | //function : ViewProject: implements VAxo, VTop, VLeft, ... | |
2040 | //purpose : Switches to an axonometric, top, left and other views | |
2041 | //============================================================================== | |
2042 | ||
2043 | static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori) | |
2044 | { | |
4fe56619 | 2045 | if ( ViewerTest::CurrentView().IsNull() ) |
44b8f2d6 | 2046 | { |
586db386 | 2047 | di<<"Call vinit before this command, please\n"; |
44b8f2d6 | 2048 | return 1; |
2049 | } | |
2050 | ||
2051 | ViewerTest::CurrentView()->SetProj(ori); | |
2052 | return 0; | |
2053 | } | |
2054 | ||
7fd59977 | 2055 | //============================================================================== |
2056 | //function : VAxo | |
2057 | //purpose : Switch to an Axonometric view | |
2058 | //Draw arg : No args | |
2059 | //============================================================================== | |
2060 | ||
2061 | static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** ) | |
44b8f2d6 | 2062 | { |
2063 | return ViewProject(di, V3d_XposYnegZpos); | |
7fd59977 | 2064 | } |
2065 | ||
2066 | //============================================================================== | |
2067 | //function : VTop | |
2068 | //purpose : Switch to a Top View | |
2069 | //Draw arg : No args | |
2070 | //============================================================================== | |
2071 | ||
2072 | static int VTop(Draw_Interpretor& di, Standard_Integer , const char** ) | |
2073 | { | |
44b8f2d6 | 2074 | return ViewProject(di, V3d_Zpos); |
2075 | } | |
7fd59977 | 2076 | |
44b8f2d6 | 2077 | //============================================================================== |
2078 | //function : VBottom | |
2079 | //purpose : Switch to a Bottom View | |
2080 | //Draw arg : No args | |
2081 | //============================================================================== | |
7fd59977 | 2082 | |
44b8f2d6 | 2083 | static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** ) |
2084 | { | |
2085 | return ViewProject(di, V3d_Zneg); | |
2086 | } | |
7fd59977 | 2087 | |
44b8f2d6 | 2088 | //============================================================================== |
2089 | //function : VLeft | |
2090 | //purpose : Switch to a Left View | |
2091 | //Draw arg : No args | |
2092 | //============================================================================== | |
2093 | ||
2094 | static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** ) | |
2095 | { | |
27af3052 | 2096 | return ViewProject(di, V3d_Xneg); |
44b8f2d6 | 2097 | } |
2098 | ||
2099 | //============================================================================== | |
2100 | //function : VRight | |
2101 | //purpose : Switch to a Right View | |
2102 | //Draw arg : No args | |
2103 | //============================================================================== | |
2104 | ||
2105 | static int VRight(Draw_Interpretor& di, Standard_Integer , const char** ) | |
2106 | { | |
27af3052 | 2107 | return ViewProject(di, V3d_Xpos); |
44b8f2d6 | 2108 | } |
7fd59977 | 2109 | |
44b8f2d6 | 2110 | //============================================================================== |
2111 | //function : VFront | |
2112 | //purpose : Switch to a Front View | |
2113 | //Draw arg : No args | |
2114 | //============================================================================== | |
2115 | ||
2116 | static int VFront(Draw_Interpretor& di, Standard_Integer , const char** ) | |
2117 | { | |
27af3052 | 2118 | return ViewProject(di, V3d_Yneg); |
44b8f2d6 | 2119 | } |
2120 | ||
2121 | //============================================================================== | |
2122 | //function : VBack | |
2123 | //purpose : Switch to a Back View | |
2124 | //Draw arg : No args | |
2125 | //============================================================================== | |
2126 | ||
2127 | static int VBack(Draw_Interpretor& di, Standard_Integer , const char** ) | |
2128 | { | |
27af3052 | 2129 | return ViewProject(di, V3d_Ypos); |
7fd59977 | 2130 | } |
2131 | ||
2132 | //============================================================================== | |
2133 | //function : VHelp | |
2134 | //purpose : Dsiplay help on viewer Keyboead and mouse commands | |
2135 | //Draw arg : No args | |
2136 | //============================================================================== | |
2137 | ||
2138 | static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** ) | |
2139 | { | |
2140 | ||
586db386 | 2141 | di << "Q : Quit the application\n"; |
2142 | ||
2143 | di << "=========================\n"; | |
2144 | di << "F : FitAll\n"; | |
2145 | di << "T : TopView\n"; | |
2146 | di << "B : BottomView\n"; | |
2147 | di << "R : RightView\n"; | |
2148 | di << "L : LeftView\n"; | |
2149 | di << "A : AxonometricView\n"; | |
2150 | di << "D : ResetView\n"; | |
2151 | ||
2152 | di << "=========================\n"; | |
2153 | di << "S : Shading\n"; | |
2154 | di << "W : Wireframe\n"; | |
2155 | di << "H : HidelLineRemoval\n"; | |
2156 | di << "U : Unset display mode\n"; | |
2157 | di << "Delete : Remove selection from viewer\n"; | |
2158 | ||
2159 | di << "=========================\n"; | |
2160 | di << "Selection mode \n"; | |
2161 | di << "0 : Shape\n"; | |
2162 | di << "1 : Vertex\n"; | |
2163 | di << "2 : Edge\n"; | |
2164 | di << "3 : Wire\n"; | |
2165 | di << "4 : Face\n"; | |
2166 | di << "5 : Shell\n"; | |
2167 | di << "6 : Solid\n"; | |
2168 | di << "7 : Compound\n"; | |
2169 | ||
2170 | di << "=========================\n"; | |
2171 | di << "Z : Switch Z clipping On/Off\n"; | |
2172 | di << ", : Hilight next detected\n"; | |
2173 | di << ". : Hilight previous detected\n"; | |
7fd59977 | 2174 | |
2175 | return 0; | |
2176 | } | |
2177 | ||
57c28b61 | 2178 | #ifdef _WIN32 |
7fd59977 | 2179 | |
2180 | static Standard_Boolean Ppick = 0; | |
2181 | static Standard_Integer Pargc = 0; | |
2182 | static const char** Pargv = NULL; | |
2183 | ||
2184 | ||
2185 | static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd, | |
2186 | UINT Msg, | |
2187 | WPARAM wParam, | |
2188 | LPARAM lParam ) | |
2189 | { | |
18d715bd | 2190 | if (!ViewerTest_myViews.IsEmpty()) { |
7fd59977 | 2191 | |
2192 | WPARAM fwKeys = wParam; | |
2193 | ||
2194 | switch( Msg ) { | |
18d715bd | 2195 | case WM_CLOSE: |
2196 | { | |
2197 | // Delete view from map of views | |
2198 | ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd)); | |
2199 | return 0; | |
2200 | } | |
2201 | break; | |
2202 | case WM_ACTIVATE: | |
2203 | if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE | |
2204 | || ViewerTest::CurrentView().IsNull()) | |
2205 | { | |
2206 | // Activate inactive window | |
2207 | if(GetWindowHandle(VT_GetWindow()) != hwnd) | |
2208 | { | |
2209 | ActivateView (FindViewIdByWindowHandle(hwnd)); | |
2210 | } | |
2211 | } | |
2212 | break; | |
625e1958 | 2213 | |
7fd59977 | 2214 | case WM_LBUTTONUP: |
625e1958 | 2215 | if (IsDragged && !DragFirst) |
7fd59977 | 2216 | { |
625e1958 | 2217 | if (!GetActiveAISManipulator().IsNull()) |
2218 | { | |
2219 | GetActiveAISManipulator()->StopTransform(); | |
0577ae8c | 2220 | ViewerTest::GetAISContext()->ClearSelected (Standard_True); |
625e1958 | 2221 | } |
2222 | ||
b12e1c7b | 2223 | if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand())) |
2224 | { | |
2225 | ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False); | |
2226 | ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate(); | |
2227 | } | |
2228 | ||
dde68833 | 2229 | VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0); |
7fd59977 | 2230 | } |
8abada55 | 2231 | IsDragged = Standard_False; |
7fd59977 | 2232 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); |
2233 | ||
625e1958 | 2234 | case WM_RBUTTONUP: |
2235 | if (IsDragged && !DragFirst) | |
2236 | { | |
2237 | if (!GetActiveAISManipulator().IsNull()) | |
2238 | { | |
2239 | GetActiveAISManipulator()->StopTransform (Standard_False); | |
0577ae8c | 2240 | ViewerTest::GetAISContext()->ClearSelected (Standard_True); |
625e1958 | 2241 | } |
2242 | IsDragged = Standard_False; | |
2243 | } | |
2244 | return ViewerWindowProc (hwnd, Msg, wParam, lParam); | |
2245 | ||
7fd59977 | 2246 | case WM_LBUTTONDOWN: |
625e1958 | 2247 | if (!GetActiveAISManipulator().IsNull()) |
2248 | { | |
2249 | IsDragged = ( fwKeys == MK_LBUTTON ); | |
2250 | } | |
2251 | else | |
2252 | { | |
2253 | IsDragged = ( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) ); | |
2254 | } | |
2255 | ||
2256 | if (IsDragged) | |
7fd59977 | 2257 | { |
7fd59977 | 2258 | DragFirst = Standard_True; |
4fe56619 | 2259 | X_ButtonPress = LOWORD(lParam); |
2260 | Y_ButtonPress = HIWORD(lParam); | |
7fd59977 | 2261 | } |
2262 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
2263 | ||
7fd59977 | 2264 | case WM_MOUSEMOVE: |
b12e1c7b | 2265 | if (IsDragged) |
7fd59977 | 2266 | { |
b12e1c7b | 2267 | X_Motion = LOWORD (lParam); |
2268 | Y_Motion = HIWORD (lParam); | |
625e1958 | 2269 | if (!GetActiveAISManipulator().IsNull()) |
b12e1c7b | 2270 | { |
625e1958 | 2271 | if (DragFirst) |
2272 | { | |
2273 | GetActiveAISManipulator()->StartTransform (X_ButtonPress, Y_ButtonPress, ViewerTest::CurrentView()); | |
2274 | } | |
2275 | else | |
2276 | { | |
2277 | GetActiveAISManipulator()->Transform (X_Motion, Y_Motion, ViewerTest::CurrentView()); | |
2278 | ViewerTest::GetAISContext()->CurrentViewer()->Redraw(); | |
2279 | } | |
69adb9ce | 2280 | } |
625e1958 | 2281 | else |
69adb9ce | 2282 | { |
625e1958 | 2283 | bool toRedraw = false; |
2284 | if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand())) | |
2285 | { | |
2286 | ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False); | |
2287 | toRedraw = true; | |
2288 | } | |
2289 | ||
2290 | RECT aRect; | |
2291 | if (GetClientRect (hwnd, &aRect)) | |
2292 | { | |
2293 | int aHeight = aRect.bottom - aRect.top; | |
2294 | GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion); | |
68dcee02 | 2295 | ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed); |
625e1958 | 2296 | toRedraw = true; |
2297 | } | |
2298 | if (toRedraw) | |
2299 | { | |
2300 | ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate(); | |
2301 | } | |
b12e1c7b | 2302 | } |
625e1958 | 2303 | |
2304 | DragFirst = Standard_False; | |
7fd59977 | 2305 | } |
2306 | else | |
2307 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
2308 | break; | |
2309 | ||
2310 | default: | |
2311 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
2312 | } | |
2313 | return 0; | |
2314 | } | |
2315 | return ViewerWindowProc( hwnd, Msg, wParam, lParam ); | |
2316 | } | |
2317 | ||
2318 | ||
2319 | static LRESULT WINAPI ViewerWindowProc( HWND hwnd, | |
2320 | UINT Msg, | |
2321 | WPARAM wParam, | |
2322 | LPARAM lParam ) | |
2323 | { | |
7fd59977 | 2324 | static int Up = 1; |
f978241f | 2325 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); |
2326 | if (aView.IsNull()) | |
2327 | { | |
ad03c234 | 2328 | return DefWindowProcW (hwnd, Msg, wParam, lParam); |
f978241f | 2329 | } |
7fd59977 | 2330 | |
7fd59977 | 2331 | PAINTSTRUCT ps; |
2332 | ||
2333 | switch( Msg ) { | |
7fd59977 | 2334 | case WM_PAINT: |
7fd59977 | 2335 | BeginPaint(hwnd, &ps); |
2336 | EndPaint(hwnd, &ps); | |
4fe56619 | 2337 | VT_ProcessExpose(); |
7fd59977 | 2338 | break; |
2339 | ||
2340 | case WM_SIZE: | |
4fe56619 | 2341 | VT_ProcessConfigure(); |
7fd59977 | 2342 | break; |
f978241f | 2343 | case WM_MOVE: |
2344 | case WM_MOVING: | |
2345 | case WM_SIZING: | |
2346 | switch (aView->RenderingParams().StereoMode) | |
2347 | { | |
2348 | case Graphic3d_StereoMode_RowInterlaced: | |
2349 | case Graphic3d_StereoMode_ColumnInterlaced: | |
2350 | case Graphic3d_StereoMode_ChessBoard: | |
2351 | VT_ProcessConfigure(); // track window moves to reverse stereo pair | |
2352 | break; | |
2353 | default: | |
2354 | break; | |
2355 | } | |
2356 | break; | |
7fd59977 | 2357 | |
2358 | case WM_KEYDOWN: | |
4fe56619 | 2359 | if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL)) |
2360 | { | |
7fd59977 | 2361 | char c[2]; |
2362 | c[0] = (char) wParam; | |
2363 | c[1] = '\0'; | |
b514beda | 2364 | if (wParam == VK_DELETE) |
2365 | { | |
2366 | c[0] = THE_KEY_DELETE; | |
2367 | } | |
fd3f6bd0 | 2368 | else if (wParam == VK_ESCAPE) |
2369 | { | |
2370 | c[0] = THE_KEY_ESCAPE; | |
2371 | } | |
4ca4bbe8 | 2372 | // comma |
2373 | else if (wParam == VK_OEM_COMMA) | |
2374 | { | |
2375 | c[0] = ','; | |
2376 | } | |
2377 | // dot | |
2378 | else if (wParam == VK_OEM_PERIOD) | |
2379 | { | |
2380 | c[0] = '.'; | |
2381 | } | |
f978241f | 2382 | else if (wParam == VK_DIVIDE) |
2383 | { | |
2384 | c[0] = '/'; | |
2385 | } | |
2386 | // dot | |
2387 | else if (wParam == VK_MULTIPLY) | |
2388 | { | |
2389 | c[0] = '*'; | |
2390 | } | |
4fe56619 | 2391 | VT_ProcessKeyPress (c); |
7fd59977 | 2392 | } |
2393 | break; | |
2394 | ||
2395 | case WM_LBUTTONUP: | |
2396 | case WM_MBUTTONUP: | |
2397 | case WM_RBUTTONUP: | |
7fd59977 | 2398 | Up = 1; |
4fe56619 | 2399 | VT_ProcessButton3Release(); |
7fd59977 | 2400 | break; |
2401 | ||
2402 | case WM_LBUTTONDOWN: | |
2403 | case WM_MBUTTONDOWN: | |
2404 | case WM_RBUTTONDOWN: | |
2405 | { | |
7fd59977 | 2406 | WPARAM fwKeys = wParam; |
2407 | ||
2408 | Up = 0; | |
2409 | ||
2410 | X_ButtonPress = LOWORD(lParam); | |
2411 | Y_ButtonPress = HIWORD(lParam); | |
2412 | ||
4fe56619 | 2413 | if (Msg == WM_LBUTTONDOWN) |
2414 | { | |
dde68833 | 2415 | if ((fwKeys & MK_CONTROL) != 0) |
4fe56619 | 2416 | { |
dde68833 | 2417 | Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0); |
4fe56619 | 2418 | } |
2419 | else | |
2420 | { | |
dde68833 | 2421 | VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0); |
4fe56619 | 2422 | } |
7fd59977 | 2423 | } |
4fe56619 | 2424 | else if (Msg == WM_RBUTTONDOWN) |
2425 | { | |
7fd59977 | 2426 | // Start rotation |
4fe56619 | 2427 | VT_ProcessButton3Press(); |
7fd59977 | 2428 | } |
2429 | } | |
2430 | break; | |
2431 | ||
f978241f | 2432 | case WM_MOUSEWHEEL: |
2433 | { | |
2434 | int aDelta = GET_WHEEL_DELTA_WPARAM (wParam); | |
2435 | if (wParam & MK_CONTROL) | |
2436 | { | |
2437 | if (aView->Camera()->IsStereo()) | |
2438 | { | |
2439 | Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05); | |
2440 | if (aFocus > 0.2 | |
2441 | && aFocus < 2.0) | |
2442 | { | |
2443 | aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus); | |
2444 | aView->Redraw(); | |
2445 | } | |
2446 | } | |
2447 | } | |
2448 | else | |
2449 | { | |
2450 | aView->Zoom (0, 0, aDelta / 40, aDelta / 40); | |
2451 | } | |
2452 | break; | |
2453 | } | |
2454 | ||
7fd59977 | 2455 | case WM_MOUSEMOVE: |
2456 | { | |
2457 | //cout << "\t WM_MOUSEMOVE" << endl; | |
2458 | WPARAM fwKeys = wParam; | |
2459 | X_Motion = LOWORD(lParam); | |
2460 | Y_Motion = HIWORD(lParam); | |
2461 | ||
2462 | if ( Up && | |
dde68833 | 2463 | (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 ) |
2464 | { | |
7fd59977 | 2465 | Up = 0; |
2466 | X_ButtonPress = LOWORD(lParam); | |
2467 | Y_ButtonPress = HIWORD(lParam); | |
2468 | ||
dde68833 | 2469 | if ((fwKeys & MK_RBUTTON) != 0) { |
7fd59977 | 2470 | // Start rotation |
4fe56619 | 2471 | VT_ProcessButton3Press(); |
7fd59977 | 2472 | } |
2473 | } | |
2474 | ||
dde68833 | 2475 | if ((fwKeys & MK_CONTROL) != 0) |
2476 | { | |
2477 | if ((fwKeys & MK_LBUTTON) != 0) | |
2478 | { | |
7fd59977 | 2479 | ProcessControlButton1Motion(); |
2480 | } | |
dde68833 | 2481 | else if ((fwKeys & MK_MBUTTON) != 0 |
2482 | || ((fwKeys & MK_LBUTTON) != 0 | |
2483 | && (fwKeys & MK_RBUTTON) != 0)) | |
2484 | { | |
2485 | VT_ProcessControlButton2Motion(); | |
2486 | } | |
2487 | else if ((fwKeys & MK_RBUTTON) != 0) | |
2488 | { | |
4fe56619 | 2489 | VT_ProcessControlButton3Motion(); |
7fd59977 | 2490 | } |
2491 | } | |
08398024 | 2492 | else if (GetWindowHandle (VT_GetWindow()) == hwnd) |
2493 | { | |
89a929ea | 2494 | VT_ProcessMotion(); |
08398024 | 2495 | } |
7fd59977 | 2496 | } |
2497 | break; | |
2498 | ||
2499 | default: | |
ad03c234 | 2500 | return DefWindowProcW (hwnd, Msg, wParam, lParam); |
7fd59977 | 2501 | } |
2502 | return 0L; | |
7fd59977 | 2503 | } |
2504 | ||
7fd59977 | 2505 | //============================================================================== |
2506 | //function : ViewerMainLoop | |
2507 | //purpose : Get a Event on the view and dispatch it | |
2508 | //============================================================================== | |
2509 | ||
2510 | ||
8263fcd3 | 2511 | int ViewerMainLoop(Standard_Integer argc, const char** argv) |
7fd59977 | 2512 | { |
7fd59977 | 2513 | Ppick = (argc > 0)? 1 : 0; |
2514 | Pargc = argc; | |
2515 | Pargv = argv; | |
2516 | ||
2517 | if ( Ppick ) { | |
2518 | MSG msg; | |
2519 | msg.wParam = 1; | |
2520 | ||
2521 | cout << "Start picking" << endl; | |
2522 | ||
7fd59977 | 2523 | while ( Ppick == 1 ) { |
4fe56619 | 2524 | // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0 |
ad03c234 | 2525 | if (GetMessageW (&msg, NULL, 0, 0)) |
2526 | { | |
2527 | TranslateMessage (&msg); | |
2528 | DispatchMessageW (&msg); | |
7fd59977 | 2529 | } |
2530 | } | |
2531 | ||
2532 | cout << "Picking done" << endl; | |
2533 | } | |
2534 | ||
2535 | return Ppick; | |
2536 | } | |
2537 | ||
4fe56619 | 2538 | #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX) |
7fd59977 | 2539 | |
2540 | int min( int a, int b ) | |
2541 | { | |
2542 | if( a<b ) | |
2543 | return a; | |
2544 | else | |
2545 | return b; | |
2546 | } | |
2547 | ||
2548 | int max( int a, int b ) | |
2549 | { | |
2550 | if( a>b ) | |
2551 | return a; | |
2552 | else | |
2553 | return b; | |
2554 | } | |
2555 | ||
2556 | int ViewerMainLoop(Standard_Integer argc, const char** argv) | |
2557 | ||
4269bd1b | 2558 | { |
18d715bd | 2559 | static XEvent aReport; |
2560 | Standard_Boolean pick = argc > 0; | |
2561 | Display *aDisplay = GetDisplayConnection()->GetDisplay(); | |
2562 | XNextEvent (aDisplay, &aReport); | |
7fd59977 | 2563 | |
18d715bd | 2564 | // Handle event for the chosen display connection |
2565 | switch (aReport.type) { | |
2566 | case ClientMessage: | |
2567 | { | |
eb1ebea4 | 2568 | if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW)) |
18d715bd | 2569 | { |
2570 | // Close the window | |
2571 | ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window)); | |
2572 | } | |
2573 | } | |
2574 | return 0; | |
2575 | case FocusIn: | |
2576 | { | |
2577 | // Activate inactive view | |
2578 | Window aWindow = GetWindowHandle(VT_GetWindow()); | |
2579 | if(aWindow != aReport.xfocus.window) | |
2580 | { | |
2581 | ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window)); | |
2582 | } | |
2583 | } | |
2584 | break; | |
7fd59977 | 2585 | case Expose: |
2586 | { | |
4fe56619 | 2587 | VT_ProcessExpose(); |
7fd59977 | 2588 | } |
2589 | break; | |
2590 | case ConfigureNotify: | |
2591 | { | |
4fe56619 | 2592 | VT_ProcessConfigure(); |
7fd59977 | 2593 | } |
2594 | break; | |
2595 | case KeyPress: | |
2596 | { | |
2597 | ||
2598 | KeySym ks_ret ; | |
2599 | char buf_ret[11] ; | |
2600 | int ret_len ; | |
2601 | XComposeStatus status_in_out; | |
2602 | ||
18d715bd | 2603 | ret_len = XLookupString( ( XKeyEvent *)&aReport , |
7fd59977 | 2604 | (char *) buf_ret , 10 , |
2605 | &ks_ret , &status_in_out ) ; | |
2606 | ||
2607 | ||
2608 | buf_ret[ret_len] = '\0' ; | |
2609 | ||
4fe56619 | 2610 | if (ret_len) |
2611 | { | |
2612 | VT_ProcessKeyPress (buf_ret); | |
7fd59977 | 2613 | } |
2614 | } | |
2615 | break; | |
2616 | case ButtonPress: | |
7fd59977 | 2617 | { |
18d715bd | 2618 | X_ButtonPress = aReport.xbutton.x; |
2619 | Y_ButtonPress = aReport.xbutton.y; | |
7fd59977 | 2620 | |
18d715bd | 2621 | if (aReport.xbutton.button == Button1) |
4fe56619 | 2622 | { |
18d715bd | 2623 | if (aReport.xbutton.state & ControlMask) |
4fe56619 | 2624 | { |
18d715bd | 2625 | pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask)); |
4fe56619 | 2626 | } |
7fd59977 | 2627 | else |
2628 | { | |
2629 | IsDragged = Standard_True; | |
7fd59977 | 2630 | DragFirst = Standard_True; |
2631 | } | |
4fe56619 | 2632 | } |
18d715bd | 2633 | else if (aReport.xbutton.button == Button3) |
4fe56619 | 2634 | { |
7fd59977 | 2635 | // Start rotation |
4fe56619 | 2636 | VT_ProcessButton3Press(); |
2637 | } | |
7fd59977 | 2638 | } |
2639 | break; | |
2640 | case ButtonRelease: | |
2641 | { | |
7fd59977 | 2642 | if( IsDragged ) |
2643 | { | |
2644 | if( !DragFirst ) | |
2645 | { | |
b12e1c7b | 2646 | if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand())) |
2647 | { | |
2648 | ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False); | |
2649 | ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate(); | |
2650 | } | |
7fd59977 | 2651 | } |
2652 | ||
2653 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
2654 | if( aContext.IsNull() ) | |
2655 | { | |
2656 | cout << "The context is null. Please use vinit before createmesh" << endl; | |
2657 | return 0; | |
2658 | } | |
2659 | ||
18d715bd | 2660 | Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask ); |
2661 | if( aReport.xbutton.button==1 ) | |
7fd59977 | 2662 | if( DragFirst ) |
2663 | if( ShiftPressed ) | |
2664 | { | |
0577ae8c | 2665 | aContext->ShiftSelect (Standard_True); |
7fd59977 | 2666 | } |
2667 | else | |
2668 | { | |
0577ae8c | 2669 | aContext->Select (Standard_True); |
7fd59977 | 2670 | } |
2671 | else | |
2672 | if( ShiftPressed ) | |
2673 | { | |
0577ae8c | 2674 | aContext->ShiftSelect(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion), |
2675 | Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion), | |
2676 | ViewerTest::CurrentView(), Standard_True); | |
7fd59977 | 2677 | } |
2678 | else | |
2679 | { | |
0577ae8c | 2680 | aContext->Select(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion), |
2681 | Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion), | |
2682 | ViewerTest::CurrentView(), Standard_True); | |
7fd59977 | 2683 | } |
2684 | else | |
4fe56619 | 2685 | VT_ProcessButton3Release(); |
7fd59977 | 2686 | |
2687 | IsDragged = Standard_False; | |
2688 | } | |
2689 | else | |
4fe56619 | 2690 | VT_ProcessButton3Release(); |
7fd59977 | 2691 | } |
2692 | break; | |
2693 | case MotionNotify: | |
2694 | { | |
08398024 | 2695 | if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window) |
2696 | { | |
2697 | break; | |
2698 | } | |
7fd59977 | 2699 | if( IsDragged ) |
2700 | { | |
7fd59977 | 2701 | if( !DragFirst ) |
b12e1c7b | 2702 | { |
2703 | if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand())) | |
2704 | { | |
2705 | ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False); | |
b12e1c7b | 2706 | } |
2707 | } | |
7fd59977 | 2708 | |
18d715bd | 2709 | X_Motion = aReport.xmotion.x; |
2710 | Y_Motion = aReport.xmotion.y; | |
7fd59977 | 2711 | DragFirst = Standard_False; |
2712 | ||
b12e1c7b | 2713 | Window aWindow = GetWindowHandle(VT_GetWindow()); |
2714 | Window aRoot; | |
2715 | int anX, anY; | |
2716 | unsigned int aWidth, aHeight, aBorderWidth, aDepth; | |
2717 | XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth); | |
2718 | GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion); | |
68dcee02 | 2719 | ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed); |
b12e1c7b | 2720 | ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate(); |
7fd59977 | 2721 | } |
2722 | else | |
2723 | { | |
18d715bd | 2724 | X_Motion = aReport.xmotion.x; |
2725 | Y_Motion = aReport.xmotion.y; | |
7fd59977 | 2726 | |
18d715bd | 2727 | // remove all the ButtonMotionMaskr |
2728 | while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ; | |
7fd59977 | 2729 | |
18d715bd | 2730 | if ( aReport.xmotion.state & ControlMask ) { |
2731 | if ( aReport.xmotion.state & Button1Mask ) { | |
7fd59977 | 2732 | ProcessControlButton1Motion(); |
2733 | } | |
18d715bd | 2734 | else if ( aReport.xmotion.state & Button2Mask ) { |
4fe56619 | 2735 | VT_ProcessControlButton2Motion(); |
7fd59977 | 2736 | } |
18d715bd | 2737 | else if ( aReport.xmotion.state & Button3Mask ) { |
4fe56619 | 2738 | VT_ProcessControlButton3Motion(); |
7fd59977 | 2739 | } |
2740 | } | |
4fe56619 | 2741 | else |
2742 | { | |
2743 | VT_ProcessMotion(); | |
7fd59977 | 2744 | } |
2745 | } | |
2746 | } | |
2747 | break; | |
2748 | } | |
7fd59977 | 2749 | return pick; |
2750 | } | |
2751 | ||
2752 | //============================================================================== | |
2753 | //function : VProcessEvents | |
2754 | //purpose : call by Tk_CreateFileHandler() to be able to manage the | |
2755 | // event in the Viewer window | |
2756 | //============================================================================== | |
2757 | ||
2758 | static void VProcessEvents(ClientData,int) | |
2759 | { | |
18d715bd | 2760 | NCollection_Vector<int> anEventNumbers; |
2761 | // Get number of messages from every display | |
2762 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
2763 | anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next()) | |
2764 | { | |
2765 | anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay())); | |
4269bd1b | 2766 | } |
18d715bd | 2767 | // Handle events for every display |
2768 | int anEventIter = 0; | |
2769 | for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator | |
2770 | anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++) | |
2771 | { | |
4269bd1b | 2772 | for (int i = 0; i < anEventNumbers.Value(anEventIter) && |
18d715bd | 2773 | XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i) |
2774 | { | |
2775 | SetDisplayConnection (anIter.Key2()->GetDisplayConnection()); | |
2776 | int anEventResult = ViewerMainLoop( 0, NULL); | |
2777 | // If window is closed or context was not found finish current event processing loop | |
2778 | if (!anEventResult) | |
2779 | return; | |
2780 | } | |
7fd59977 | 2781 | } |
4269bd1b | 2782 | |
18d715bd | 2783 | SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection()); |
4269bd1b | 2784 | |
7fd59977 | 2785 | } |
2786 | #endif | |
2787 | ||
2788 | //============================================================================== | |
2789 | //function : OSWindowSetup | |
2790 | //purpose : Setup for the X11 window to be able to cath the event | |
2791 | //============================================================================== | |
2792 | ||
2793 | ||
2794 | static void OSWindowSetup() | |
2795 | { | |
4fe56619 | 2796 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
7fd59977 | 2797 | // X11 |
2798 | ||
2799 | Window window = VT_GetWindow()->XWindow(); | |
18d715bd | 2800 | SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection()); |
2801 | Display *aDisplay = GetDisplayConnection()->GetDisplay(); | |
2802 | XSynchronize(aDisplay, 1); | |
7fd59977 | 2803 | |
2804 | // X11 : For keyboard on SUN | |
2805 | XWMHints wmhints; | |
2806 | wmhints.flags = InputHint; | |
2807 | wmhints.input = 1; | |
2808 | ||
18d715bd | 2809 | XSetWMHints( aDisplay, window, &wmhints); |
7fd59977 | 2810 | |
18d715bd | 2811 | XSelectInput( aDisplay, window, ExposureMask | KeyPressMask | |
7fd59977 | 2812 | ButtonPressMask | ButtonReleaseMask | |
2813 | StructureNotifyMask | | |
2814 | PointerMotionMask | | |
2815 | Button1MotionMask | Button2MotionMask | | |
18d715bd | 2816 | Button3MotionMask | FocusChangeMask |
7fd59977 | 2817 | ); |
18d715bd | 2818 | Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW); |
2819 | XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1); | |
7fd59977 | 2820 | |
18d715bd | 2821 | XSynchronize(aDisplay, 0); |
7fd59977 | 2822 | |
2823 | #else | |
57c28b61 | 2824 | // _WIN32 |
7fd59977 | 2825 | #endif |
2826 | ||
2827 | } | |
2828 | ||
7fd59977 | 2829 | //============================================================================== |
2830 | //function : VFit | |
1beb58d7 | 2831 | //purpose : |
7fd59977 | 2832 | //============================================================================== |
2833 | ||
1beb58d7 | 2834 | static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv) |
7fd59977 | 2835 | { |
1beb58d7 | 2836 | const Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2837 | if (aView.IsNull()) | |
b586500b | 2838 | { |
1beb58d7 | 2839 | std::cout << "Error: no active viewer!\n"; |
2840 | return 1; | |
b586500b | 2841 | } |
2842 | ||
1beb58d7 | 2843 | Standard_Boolean toFit = Standard_True; |
2844 | ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView); | |
2845 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
b586500b | 2846 | { |
1beb58d7 | 2847 | TCollection_AsciiString anArg (theArgv[anArgIter]); |
b586500b | 2848 | anArg.LowerCase(); |
1beb58d7 | 2849 | if (anUpdateTool.parseRedrawMode (anArg)) |
b586500b | 2850 | { |
1beb58d7 | 2851 | continue; |
2852 | } | |
2853 | else if (anArg == "-selected") | |
2854 | { | |
2855 | ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False); | |
2856 | toFit = Standard_False; | |
2857 | } | |
2858 | else | |
2859 | { | |
2860 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
b586500b | 2861 | } |
2862 | } | |
2863 | ||
1beb58d7 | 2864 | if (toFit) |
2865 | { | |
2866 | aView->FitAll (0.01, Standard_False); | |
7fd59977 | 2867 | } |
2868 | return 0; | |
2869 | } | |
2870 | ||
6262a303 | 2871 | //======================================================================= |
2872 | //function : VFitArea | |
2873 | //purpose : Fit view to show area located between two points | |
2874 | // : given in world 2D or 3D coordinates. | |
2875 | //======================================================================= | |
2876 | static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
2877 | { | |
2878 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
2879 | if (aView.IsNull()) | |
2880 | { | |
2881 | std::cerr << theArgVec[0] << "Error: No active view.\n"; | |
2882 | return 1; | |
2883 | } | |
2884 | ||
2885 | // Parse arguments. | |
2886 | gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0); | |
2887 | gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0); | |
2888 | ||
2889 | if (theArgNb == 5) | |
2890 | { | |
2891 | aWorldPnt1.SetX (Draw::Atof (theArgVec[1])); | |
2892 | aWorldPnt1.SetY (Draw::Atof (theArgVec[2])); | |
2893 | aWorldPnt2.SetX (Draw::Atof (theArgVec[3])); | |
2894 | aWorldPnt2.SetY (Draw::Atof (theArgVec[4])); | |
2895 | } | |
2896 | else if (theArgNb == 7) | |
2897 | { | |
2898 | aWorldPnt1.SetX (Draw::Atof (theArgVec[1])); | |
2899 | aWorldPnt1.SetY (Draw::Atof (theArgVec[2])); | |
2900 | aWorldPnt1.SetZ (Draw::Atof (theArgVec[3])); | |
2901 | aWorldPnt2.SetX (Draw::Atof (theArgVec[4])); | |
2902 | aWorldPnt2.SetY (Draw::Atof (theArgVec[5])); | |
2903 | aWorldPnt2.SetZ (Draw::Atof (theArgVec[6])); | |
2904 | } | |
2905 | else | |
2906 | { | |
2907 | std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n"; | |
2908 | theDI.PrintHelp(theArgVec[0]); | |
2909 | return 1; | |
2910 | } | |
2911 | ||
2912 | // Convert model coordinates to view space | |
2913 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); | |
2914 | gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1); | |
2915 | gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2); | |
2916 | ||
2917 | // Determine fit area | |
2918 | gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y())); | |
2919 | gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y())); | |
2920 | ||
2921 | Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner); | |
2922 | ||
2923 | if (aDiagonal < Precision::Confusion()) | |
2924 | { | |
2925 | std::cerr << theArgVec[0] << "Error: view area is too small.\n"; | |
2926 | return 1; | |
2927 | } | |
2928 | ||
2929 | aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y()); | |
2930 | return 0; | |
2931 | } | |
2932 | ||
7fd59977 | 2933 | //============================================================================== |
2934 | //function : VZFit | |
2935 | //purpose : ZFitall, no DRAW arguments | |
2936 | //Draw arg : No args | |
2937 | //============================================================================== | |
197ac94e | 2938 | static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec) |
7fd59977 | 2939 | { |
197ac94e | 2940 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
2941 | ||
2942 | if (aCurrentView.IsNull()) | |
2943 | { | |
2944 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; | |
2945 | return 1; | |
2946 | } | |
2947 | ||
2948 | if (theArgsNb == 1) | |
2949 | { | |
c357e426 | 2950 | aCurrentView->ZFitAll(); |
197ac94e | 2951 | aCurrentView->Redraw(); |
2952 | return 0; | |
2953 | } | |
2954 | ||
2955 | Standard_Real aScale = 1.0; | |
2956 | ||
2957 | if (theArgsNb >= 2) | |
2958 | { | |
2959 | aScale = Draw::Atoi (theArgVec[1]); | |
2960 | } | |
2961 | ||
c357e426 | 2962 | aCurrentView->ZFitAll (aScale); |
197ac94e | 2963 | aCurrentView->Redraw(); |
7fd59977 | 2964 | |
197ac94e | 2965 | return 0; |
2966 | } | |
7fd59977 | 2967 | |
197ac94e | 2968 | //============================================================================== |
2969 | //function : VRepaint | |
2970 | //purpose : | |
2971 | //============================================================================== | |
56689b27 | 2972 | static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec) |
7fd59977 | 2973 | { |
56689b27 | 2974 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
2975 | if (aView.IsNull()) | |
2976 | { | |
2977 | std::cout << "Error: no active viewer!\n"; | |
2978 | return 1; | |
2979 | } | |
2980 | ||
2981 | Standard_Boolean isImmediateUpdate = Standard_False; | |
2982 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
2983 | { | |
2984 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
2985 | anArg.LowerCase(); | |
2986 | if (anArg == "-immediate") | |
2987 | { | |
2988 | isImmediateUpdate = Standard_True; | |
2989 | if (anArgIter + 1 < theArgNb | |
2990 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate)) | |
2991 | { | |
2992 | ++anArgIter; | |
2993 | } | |
2994 | } | |
2995 | else | |
2996 | { | |
2997 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
2998 | } | |
2999 | } | |
3000 | ||
3001 | if (isImmediateUpdate) | |
3002 | { | |
3003 | aView->RedrawImmediate(); | |
3004 | } | |
3005 | else | |
3006 | { | |
3007 | aView->Redraw(); | |
3008 | } | |
3009 | return 0; | |
7fd59977 | 3010 | } |
3011 | ||
7fd59977 | 3012 | //============================================================================== |
3013 | //function : VClear | |
3014 | //purpose : Remove all the object from the viewer | |
3015 | //Draw arg : No args | |
3016 | //============================================================================== | |
3017 | ||
3018 | static int VClear(Draw_Interpretor& , Standard_Integer , const char** ) | |
3019 | { | |
3020 | Handle(V3d_View) V = ViewerTest::CurrentView(); | |
3021 | if(!V.IsNull()) | |
3022 | ViewerTest::Clear(); | |
3023 | return 0; | |
3024 | } | |
3025 | ||
3026 | //============================================================================== | |
3027 | //function : VPick | |
3028 | //purpose : | |
3029 | //============================================================================== | |
3030 | ||
3031 | static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3032 | { if (ViewerTest::CurrentView().IsNull() ) return 1; | |
3033 | ||
3034 | if ( argc < 4 ) { | |
586db386 | 3035 | di << argv[0] << "Invalid number of arguments\n"; |
7fd59977 | 3036 | return 1; |
3037 | } | |
3038 | ||
3039 | while (ViewerMainLoop( argc, argv)) { | |
3040 | } | |
3041 | ||
3042 | return 0; | |
3043 | } | |
3044 | ||
7fd59977 | 3045 | //============================================================================== |
3046 | //function : VSetBg | |
3047 | //purpose : Load image as background | |
3048 | //============================================================================== | |
3049 | ||
3050 | static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3051 | { | |
3052 | if (argc < 2 || argc > 3) | |
3053 | { | |
586db386 | 3054 | di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n"; |
3055 | di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n"; | |
7fd59977 | 3056 | return 1; |
3057 | } | |
3058 | ||
3059 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
3060 | if(AISContext.IsNull()) | |
3061 | { | |
3062 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
3063 | return 1; | |
3064 | } | |
3065 | ||
3066 | Aspect_FillMethod aFillType = Aspect_FM_CENTERED; | |
3067 | if (argc == 3) | |
3068 | { | |
3069 | const char* szType = argv[2]; | |
3070 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; | |
3071 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; | |
3072 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; | |
3073 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; | |
3074 | else | |
3075 | { | |
3076 | di << "Wrong fill type : " << szType << "\n"; | |
586db386 | 3077 | di << "Must be one of CENTERED, TILED, STRETCH, NONE\n"; |
7fd59977 | 3078 | return 1; |
3079 | } | |
3080 | } | |
3081 | ||
3082 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
3083 | V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True); | |
3084 | ||
3085 | return 0; | |
3086 | } | |
3087 | ||
f8b2ed36 | 3088 | //============================================================================== |
3089 | //function : VSetBgMode | |
3090 | //purpose : Change background image fill type | |
3091 | //============================================================================== | |
3092 | ||
3093 | static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3094 | { | |
3095 | if (argc != 2) | |
3096 | { | |
586db386 | 3097 | di << "Usage : " << argv[0] << " filltype : Change background image mode\n"; |
3098 | di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n"; | |
f8b2ed36 | 3099 | return 1; |
3100 | } | |
3101 | ||
3102 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
3103 | if(AISContext.IsNull()) | |
3104 | { | |
3105 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
3106 | return 1; | |
3107 | } | |
1d47d8d0 | 3108 | Aspect_FillMethod aFillType = Aspect_FM_NONE; |
3109 | const char* szType = argv[1]; | |
3110 | if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE; | |
3111 | else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED; | |
3112 | else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED; | |
3113 | else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH; | |
3114 | else | |
f8b2ed36 | 3115 | { |
1d47d8d0 | 3116 | di << "Wrong fill type : " << szType << "\n"; |
586db386 | 3117 | di << "Must be one of CENTERED, TILED, STRETCH, NONE\n"; |
1d47d8d0 | 3118 | return 1; |
f8b2ed36 | 3119 | } |
f8b2ed36 | 3120 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); |
3121 | V3dView->SetBgImageStyle(aFillType, Standard_True); | |
f8b2ed36 | 3122 | return 0; |
3123 | } | |
3124 | ||
7fd59977 | 3125 | //============================================================================== |
3126 | //function : VSetGradientBg | |
3127 | //purpose : Mount gradient background | |
3128 | //============================================================================== | |
3129 | static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3130 | { | |
3131 | if (argc != 8 ) | |
3132 | { | |
586db386 | 3133 | di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background\n"; |
3134 | di << "R1,G1,B1,R2,G2,B2 = [0..255]\n"; | |
3135 | di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n"; | |
3136 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n"; | |
7fd59977 | 3137 | return 1; |
3138 | } | |
3139 | ||
3140 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
3141 | if(AISContext.IsNull()) | |
3142 | { | |
3143 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
3144 | return 1; | |
3145 | } | |
3146 | if (argc == 8) | |
3147 | { | |
3148 | ||
91322f44 | 3149 | Standard_Real R1 = Draw::Atof(argv[1])/255.; |
3150 | Standard_Real G1 = Draw::Atof(argv[2])/255.; | |
3151 | Standard_Real B1 = Draw::Atof(argv[3])/255.; | |
7fd59977 | 3152 | Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB); |
3153 | ||
91322f44 | 3154 | Standard_Real R2 = Draw::Atof(argv[4])/255.; |
3155 | Standard_Real G2 = Draw::Atof(argv[5])/255.; | |
3156 | Standard_Real B2 = Draw::Atof(argv[6])/255.; | |
7fd59977 | 3157 | |
3158 | Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB); | |
91322f44 | 3159 | int aType = Draw::Atoi(argv[7]); |
7fd59977 | 3160 | if( aType < 0 || aType > 8 ) |
3161 | { | |
586db386 | 3162 | di << "Wrong fill type \n"; |
3163 | di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n"; | |
3164 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n"; | |
7fd59977 | 3165 | return 1; |
3166 | } | |
3167 | ||
3168 | Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType); | |
3169 | ||
3170 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
3171 | V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1); | |
3172 | } | |
3173 | ||
3174 | return 0; | |
3175 | } | |
3176 | ||
f8b2ed36 | 3177 | //============================================================================== |
3178 | //function : VSetGradientBgMode | |
3179 | //purpose : Change gradient background fill style | |
3180 | //============================================================================== | |
3181 | static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3182 | { | |
3183 | if (argc != 2 ) | |
3184 | { | |
586db386 | 3185 | di << "Usage : " << argv[0] << " Type : Change gradient background fill type\n"; |
3186 | di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n"; | |
3187 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n"; | |
f8b2ed36 | 3188 | return 1; |
3189 | } | |
3190 | ||
3191 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
3192 | if(AISContext.IsNull()) | |
3193 | { | |
3194 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
3195 | return 1; | |
3196 | } | |
3197 | if (argc == 2) | |
3198 | { | |
91322f44 | 3199 | int aType = Draw::Atoi(argv[1]); |
f8b2ed36 | 3200 | if( aType < 0 || aType > 8 ) |
3201 | { | |
586db386 | 3202 | di << "Wrong fill type \n"; |
3203 | di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n"; | |
3204 | di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n"; | |
f8b2ed36 | 3205 | return 1; |
3206 | } | |
3207 | ||
3208 | Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType); | |
3209 | ||
3210 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
3211 | V3dView->SetBgGradientStyle( aMethod, 1 ); | |
3212 | } | |
3213 | ||
3214 | return 0; | |
3215 | } | |
3216 | ||
3217 | //============================================================================== | |
3218 | //function : VSetColorBg | |
3219 | //purpose : Set color background | |
3220 | //============================================================================== | |
3221 | static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3222 | { | |
3223 | if (argc != 4 ) | |
3224 | { | |
586db386 | 3225 | di << "Usage : " << argv[0] << " R G B : Set color background\n"; |
3226 | di << "R,G,B = [0..255]\n"; | |
f8b2ed36 | 3227 | return 1; |
3228 | } | |
3229 | ||
3230 | Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext(); | |
3231 | if(AISContext.IsNull()) | |
3232 | { | |
3233 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
3234 | return 1; | |
3235 | } | |
3236 | if (argc == 4) | |
3237 | { | |
3238 | ||
91322f44 | 3239 | Standard_Real R = Draw::Atof(argv[1])/255.; |
3240 | Standard_Real G = Draw::Atof(argv[2])/255.; | |
3241 | Standard_Real B = Draw::Atof(argv[3])/255.; | |
f8b2ed36 | 3242 | Quantity_Color aColor(R,G,B,Quantity_TOC_RGB); |
3243 | ||
3244 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
3245 | V3dView->SetBackgroundColor( aColor ); | |
3246 | V3dView->Update(); | |
3247 | } | |
3248 | ||
3249 | return 0; | |
3250 | } | |
3251 | ||
f42753ed | 3252 | //============================================================================== |
3253 | //function : VSetDefaultBg | |
3254 | //purpose : Set default viewer background fill color | |
3255 | //============================================================================== | |
3256 | static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
3257 | { | |
3258 | if (theArgNb != 4 | |
3259 | && theArgNb != 8) | |
3260 | { | |
3261 | std::cout << "Error: wrong syntax! See usage:\n"; | |
3262 | theDI.PrintHelp (theArgVec[0]); | |
3263 | return 1; | |
3264 | } | |
3265 | ||
3266 | ViewerTest_DefaultBackground.FillMethod = | |
3267 | theArgNb == 4 ? Aspect_GFM_NONE | |
3268 | : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]); | |
3269 | ||
3270 | if (theArgNb == 4) | |
3271 | { | |
3272 | Standard_Real R = Draw::Atof (theArgVec[1]) / 255.; | |
3273 | Standard_Real G = Draw::Atof (theArgVec[2]) / 255.; | |
3274 | Standard_Real B = Draw::Atof (theArgVec[3]) / 255.; | |
3275 | ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB); | |
3276 | } | |
3277 | else | |
3278 | { | |
3279 | Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.; | |
3280 | Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.; | |
3281 | Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.; | |
3282 | ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB); | |
3283 | ||
3284 | Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.; | |
3285 | Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.; | |
3286 | Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.; | |
3287 | ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB); | |
3288 | } | |
3289 | ||
3290 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator | |
3291 | anIter (ViewerTest_myContexts); anIter.More(); anIter.Next()) | |
3292 | { | |
3293 | const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer(); | |
3294 | aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor); | |
3295 | aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1, | |
3296 | ViewerTest_DefaultBackground.GradientColor2, | |
3297 | ViewerTest_DefaultBackground.FillMethod); | |
3298 | } | |
3299 | ||
3300 | return 0; | |
3301 | } | |
3302 | ||
7fd59977 | 3303 | //============================================================================== |
3304 | //function : VScale | |
3305 | //purpose : View Scaling | |
3306 | //============================================================================== | |
3307 | ||
3308 | static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3309 | { | |
3310 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
3311 | if ( V3dView.IsNull() ) return 1; | |
3312 | ||
3313 | if ( argc != 4 ) { | |
586db386 | 3314 | di << argv[0] << "Invalid number of arguments\n"; |
7fd59977 | 3315 | return 1; |
3316 | } | |
91322f44 | 3317 | V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) ); |
7fd59977 | 3318 | return 0; |
3319 | } | |
3320 | //============================================================================== | |
536d98e2 | 3321 | //function : VZBuffTrihedron |
3322 | //purpose : | |
7fd59977 | 3323 | //============================================================================== |
3324 | ||
536d98e2 | 3325 | static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/, |
3326 | Standard_Integer theArgNb, | |
3327 | const char** theArgVec) | |
7fd59977 | 3328 | { |
536d98e2 | 3329 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
3330 | if (aView.IsNull()) | |
3331 | { | |
3332 | std::cout << "Error: no active viewer!\n"; | |
3333 | return 1; | |
3334 | } | |
7fd59977 | 3335 | |
536d98e2 | 3336 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
7c8a8fcc | 3337 | |
536d98e2 | 3338 | Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER; |
3339 | V3d_TypeOfVisualization aVisType = V3d_ZBUFFER; | |
3340 | Quantity_Color aLabelsColor = Quantity_NOC_WHITE; | |
3341 | Quantity_Color anArrowColorX = Quantity_NOC_RED; | |
3342 | Quantity_Color anArrowColorY = Quantity_NOC_GREEN; | |
3343 | Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1; | |
3344 | Standard_Real aScale = 0.1; | |
3345 | Standard_Real aSizeRatio = 0.8; | |
3346 | Standard_Real anArrowDiam = 0.05; | |
3347 | Standard_Integer aNbFacets = 12; | |
3348 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
7c8a8fcc | 3349 | { |
536d98e2 | 3350 | Standard_CString anArg = theArgVec[anArgIter]; |
3351 | TCollection_AsciiString aFlag (anArg); | |
3352 | aFlag.LowerCase(); | |
3353 | if (anUpdateTool.parseRedrawMode (aFlag)) | |
7c8a8fcc | 3354 | { |
536d98e2 | 3355 | continue; |
3356 | } | |
3357 | else if (aFlag == "-on") | |
7c8a8fcc | 3358 | { |
536d98e2 | 3359 | continue; |
3360 | } | |
3361 | else if (aFlag == "-off") | |
7c8a8fcc | 3362 | { |
536d98e2 | 3363 | aView->TriedronErase(); |
3364 | return 0; | |
3365 | } | |
3366 | else if (aFlag == "-pos" | |
3367 | || aFlag == "-position" | |
3368 | || aFlag == "-corner") | |
7c8a8fcc | 3369 | { |
536d98e2 | 3370 | if (++anArgIter >= theArgNb) |
3371 | { | |
3372 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3373 | return 1; | |
3374 | } | |
3375 | ||
3376 | TCollection_AsciiString aPosName (theArgVec[anArgIter]); | |
3377 | aPosName.LowerCase(); | |
3378 | if (aPosName == "center") | |
3379 | { | |
3380 | aPosition = Aspect_TOTP_CENTER; | |
3381 | } | |
3382 | else if (aPosName == "left_lower" | |
3383 | || aPosName == "lower_left" | |
3384 | || aPosName == "leftlower" | |
3385 | || aPosName == "lowerleft") | |
3386 | { | |
3387 | aPosition = Aspect_TOTP_LEFT_LOWER; | |
3388 | } | |
3389 | else if (aPosName == "left_upper" | |
3390 | || aPosName == "upper_left" | |
3391 | || aPosName == "leftupper" | |
3392 | || aPosName == "upperleft") | |
3393 | { | |
3394 | aPosition = Aspect_TOTP_LEFT_UPPER; | |
3395 | } | |
3396 | else if (aPosName == "right_lower" | |
3397 | || aPosName == "lower_right" | |
3398 | || aPosName == "rightlower" | |
3399 | || aPosName == "lowerright") | |
3400 | { | |
3401 | aPosition = Aspect_TOTP_RIGHT_LOWER; | |
3402 | } | |
3403 | else if (aPosName == "right_upper" | |
3404 | || aPosName == "upper_right" | |
3405 | || aPosName == "rightupper" | |
3406 | || aPosName == "upperright") | |
3407 | { | |
3408 | aPosition = Aspect_TOTP_RIGHT_UPPER; | |
3409 | } | |
3410 | else | |
3411 | { | |
3412 | std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n"; | |
3413 | return 1; | |
3414 | } | |
3415 | } | |
3416 | else if (aFlag == "-type") | |
7c8a8fcc | 3417 | { |
536d98e2 | 3418 | if (++anArgIter >= theArgNb) |
3419 | { | |
3420 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3421 | return 1; | |
3422 | } | |
3423 | ||
3424 | TCollection_AsciiString aTypeName (theArgVec[anArgIter]); | |
3425 | aTypeName.LowerCase(); | |
3426 | if (aTypeName == "wireframe" | |
3427 | || aTypeName == "wire") | |
3428 | { | |
3429 | aVisType = V3d_WIREFRAME; | |
3430 | } | |
3431 | else if (aTypeName == "zbuffer" | |
3432 | || aTypeName == "shaded") | |
3433 | { | |
3434 | aVisType = V3d_ZBUFFER; | |
3435 | } | |
3436 | else | |
3437 | { | |
3438 | std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n"; | |
3439 | } | |
3440 | } | |
3441 | else if (aFlag == "-scale") | |
7c8a8fcc | 3442 | { |
536d98e2 | 3443 | if (++anArgIter >= theArgNb) |
3444 | { | |
3445 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3446 | return 1; | |
3447 | } | |
3448 | ||
3449 | aScale = Draw::Atof (theArgVec[anArgIter]); | |
7c8a8fcc | 3450 | } |
536d98e2 | 3451 | else if (aFlag == "-size" |
3452 | || aFlag == "-sizeratio") | |
3453 | { | |
3454 | if (++anArgIter >= theArgNb) | |
3455 | { | |
3456 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3457 | return 1; | |
3458 | } | |
7c8a8fcc | 3459 | |
536d98e2 | 3460 | aSizeRatio = Draw::Atof (theArgVec[anArgIter]); |
3461 | } | |
3462 | else if (aFlag == "-arrowdiam" | |
3463 | || aFlag == "-arrowdiameter") | |
3464 | { | |
3465 | if (++anArgIter >= theArgNb) | |
3466 | { | |
3467 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3468 | return 1; | |
3469 | } | |
7c8a8fcc | 3470 | |
536d98e2 | 3471 | anArrowDiam = Draw::Atof (theArgVec[anArgIter]); |
3472 | } | |
3473 | else if (aFlag == "-nbfacets") | |
3474 | { | |
3475 | if (++anArgIter >= theArgNb) | |
3476 | { | |
3477 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3478 | return 1; | |
3479 | } | |
7c8a8fcc | 3480 | |
536d98e2 | 3481 | aNbFacets = Draw::Atoi (theArgVec[anArgIter]); |
3482 | } | |
3483 | else if (aFlag == "-colorlabel" | |
3484 | || aFlag == "-colorlabels") | |
7c8a8fcc | 3485 | { |
536d98e2 | 3486 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
3487 | theArgVec + anArgIter + 1, | |
3488 | aLabelsColor); | |
3489 | if (aNbParsed == 0) | |
3490 | { | |
3491 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3492 | return 1; | |
3493 | } | |
3494 | anArgIter += aNbParsed; | |
7c8a8fcc | 3495 | } |
536d98e2 | 3496 | else if (aFlag == "-colorarrowx") |
7c8a8fcc | 3497 | { |
536d98e2 | 3498 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
3499 | theArgVec + anArgIter + 1, | |
3500 | anArrowColorX); | |
3501 | if (aNbParsed == 0) | |
3502 | { | |
3503 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3504 | return 1; | |
3505 | } | |
3506 | anArgIter += aNbParsed; | |
3507 | } | |
3508 | else if (aFlag == "-colorarrowy") | |
7c8a8fcc | 3509 | { |
536d98e2 | 3510 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
3511 | theArgVec + anArgIter + 1, | |
3512 | anArrowColorY); | |
3513 | if (aNbParsed == 0) | |
3514 | { | |
3515 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3516 | return 1; | |
3517 | } | |
3518 | anArgIter += aNbParsed; | |
3519 | } | |
3520 | else if (aFlag == "-colorarrowz") | |
7c8a8fcc | 3521 | { |
536d98e2 | 3522 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, |
3523 | theArgVec + anArgIter + 1, | |
3524 | anArrowColorZ); | |
3525 | if (aNbParsed == 0) | |
3526 | { | |
3527 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3528 | return 1; | |
3529 | } | |
3530 | anArgIter += aNbParsed; | |
3531 | } | |
3532 | else | |
3533 | { | |
3534 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
7c8a8fcc | 3535 | return 1; |
3536 | } | |
7c8a8fcc | 3537 | } |
3538 | ||
536d98e2 | 3539 | aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(), |
3540 | aSizeRatio, anArrowDiam, aNbFacets); | |
3541 | aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType); | |
c357e426 | 3542 | aView->ZFitAll(); |
7fd59977 | 3543 | return 0; |
3544 | } | |
3545 | ||
3546 | //============================================================================== | |
3547 | //function : VRotate | |
3548 | //purpose : Camera Rotating | |
3549 | //============================================================================== | |
3550 | ||
4af098ba | 3551 | static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec) |
3552 | { | |
3553 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3554 | if (aView.IsNull()) | |
3555 | { | |
3556 | std::cout << "No active view!\n"; | |
7fd59977 | 3557 | return 1; |
3558 | } | |
3559 | ||
4af098ba | 3560 | Standard_Boolean hasFlags = Standard_False; |
3561 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
3562 | { | |
3563 | Standard_CString anArg (theArgVec[anArgIter]); | |
3564 | TCollection_AsciiString aFlag (anArg); | |
3565 | aFlag.LowerCase(); | |
3566 | if (aFlag == "-mousestart" | |
3567 | || aFlag == "-mousefrom") | |
3568 | { | |
3569 | hasFlags = Standard_True; | |
3570 | if (anArgIter + 2 >= theArgNb) | |
3571 | { | |
3572 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
3573 | return 1; | |
3574 | } | |
3575 | ||
3576 | Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]); | |
3577 | Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]); | |
3578 | aView->StartRotation (anX, anY); | |
3579 | } | |
3580 | else if (aFlag == "-mousemove") | |
3581 | { | |
3582 | hasFlags = Standard_True; | |
3583 | if (anArgIter + 2 >= theArgNb) | |
3584 | { | |
3585 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
3586 | return 1; | |
3587 | } | |
3588 | ||
3589 | Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]); | |
3590 | Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]); | |
3591 | aView->Rotation (anX, anY); | |
3592 | } | |
3593 | else if (theArgNb != 4 | |
3594 | && theArgNb != 7) | |
3595 | { | |
3596 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
3597 | return 1; | |
3598 | } | |
3599 | } | |
3600 | ||
3601 | if (hasFlags) | |
3602 | { | |
7fd59977 | 3603 | return 0; |
4af098ba | 3604 | } |
3605 | else if (theArgNb == 4) | |
3606 | { | |
3607 | Standard_Real anAX = Draw::Atof (theArgVec[1]); | |
3608 | Standard_Real anAY = Draw::Atof (theArgVec[2]); | |
3609 | Standard_Real anAZ = Draw::Atof (theArgVec[3]); | |
3610 | aView->Rotate (anAX, anAY, anAZ); | |
3611 | return 0; | |
3612 | } | |
3613 | else if (theArgNb == 7) | |
3614 | { | |
3615 | Standard_Real anAX = Draw::Atof (theArgVec[1]); | |
3616 | Standard_Real anAY = Draw::Atof (theArgVec[2]); | |
3617 | Standard_Real anAZ = Draw::Atof (theArgVec[3]); | |
3618 | ||
3619 | Standard_Real anX = Draw::Atof (theArgVec[4]); | |
3620 | Standard_Real anY = Draw::Atof (theArgVec[5]); | |
3621 | Standard_Real anZ = Draw::Atof (theArgVec[6]); | |
3622 | ||
3623 | aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ); | |
7fd59977 | 3624 | return 0; |
7fd59977 | 3625 | } |
4af098ba | 3626 | |
3627 | std::cout << "Error: Invalid number of arguments\n"; | |
3628 | return 1; | |
7fd59977 | 3629 | } |
3630 | ||
3631 | //============================================================================== | |
3632 | //function : VZoom | |
3633 | //purpose : View zoom in / out (relative to current zoom) | |
3634 | //============================================================================== | |
3635 | ||
3636 | static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
3637 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
3638 | if ( V3dView.IsNull() ) { | |
3639 | return 1; | |
3640 | } | |
3641 | ||
3642 | if ( argc == 2 ) { | |
91322f44 | 3643 | Standard_Real coef = Draw::Atof(argv[1]); |
7fd59977 | 3644 | if ( coef <= 0.0 ) { |
586db386 | 3645 | di << argv[1] << "Invalid value\n"; |
7fd59977 | 3646 | return 1; |
3647 | } | |
91322f44 | 3648 | V3dView->SetZoom( Draw::Atof(argv[1]) ); |
7fd59977 | 3649 | return 0; |
3650 | } else { | |
586db386 | 3651 | di << argv[0] << " Invalid number of arguments\n"; |
7fd59977 | 3652 | return 1; |
3653 | } | |
3654 | } | |
3655 | ||
3656 | //============================================================================== | |
3657 | //function : VPan | |
3658 | //purpose : View panning (in pixels) | |
3659 | //============================================================================== | |
3660 | ||
3661 | static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
3662 | Handle(V3d_View) V3dView = ViewerTest::CurrentView(); | |
3663 | if ( V3dView.IsNull() ) return 1; | |
3664 | ||
3665 | if ( argc == 3 ) { | |
91322f44 | 3666 | V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) ); |
7fd59977 | 3667 | return 0; |
3668 | } else { | |
586db386 | 3669 | di << argv[0] << " Invalid number of arguments\n"; |
7fd59977 | 3670 | return 1; |
3671 | } | |
3672 | } | |
3673 | ||
49e1a5c7 | 3674 | //============================================================================== |
3675 | //function : VPlace | |
3676 | //purpose : Place the point (in pixels) at the center of the window | |
3677 | //============================================================================== | |
3678 | static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs) | |
3679 | { | |
3680 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3681 | if (aView.IsNull()) | |
3682 | { | |
3683 | std::cerr << theArgs[0] << "Error: no active view." << std::endl; | |
3684 | return 1; | |
3685 | } | |
3686 | ||
3687 | if (theArgNb != 3) | |
3688 | { | |
3689 | std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl; | |
3690 | return 1; | |
3691 | } | |
3692 | ||
3693 | aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale()); | |
3694 | ||
3695 | return 0; | |
3696 | } | |
7fd59977 | 3697 | |
71215351 | 3698 | static int VColorScale (Draw_Interpretor& theDI, |
3699 | Standard_Integer theArgNb, | |
3700 | const char** theArgVec) | |
3701 | { | |
7fd59977 | 3702 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
71215351 | 3703 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
3704 | if (aContext.IsNull()) | |
3705 | { | |
3706 | std::cout << "Error: no active view!\n"; | |
3707 | return 1; | |
7fd59977 | 3708 | } |
24a88697 | 3709 | if (theArgNb <= 1) |
3710 | { | |
3711 | std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n"; | |
3712 | return 1; | |
3713 | } | |
7fd59977 | 3714 | |
4b3d6eb1 | 3715 | Handle(AIS_ColorScale) aColorScale; |
7a324550 | 3716 | if (GetMapOfAIS().IsBound2 (theArgVec[1])) |
71215351 | 3717 | { |
4b3d6eb1 | 3718 | // find existing object |
3719 | aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1])); | |
3720 | if (aColorScale.IsNull()) | |
7a324550 | 3721 | { |
3722 | std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n"; | |
3723 | return 1; | |
3724 | } | |
3725 | } | |
71215351 | 3726 | |
7a324550 | 3727 | if (theArgNb <= 2) |
3728 | { | |
4b3d6eb1 | 3729 | if (aColorScale.IsNull()) |
3730 | { | |
3731 | std::cout << "Syntax error: colorscale with a given name does not exist.\n"; | |
3732 | return 1; | |
3733 | } | |
3734 | ||
7a324550 | 3735 | theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n" |
4b3d6eb1 | 3736 | << "Min range: " << aColorScale->GetMin() << "\n" |
3737 | << "Max range: " << aColorScale->GetMax() << "\n" | |
3738 | << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n" | |
3739 | << "Text height: " << aColorScale->GetTextHeight() << "\n" | |
3740 | << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n" | |
3741 | << "Color scale title: " << aColorScale->GetTitle() << "\n" | |
71215351 | 3742 | << "Label position: "; |
4b3d6eb1 | 3743 | switch (aColorScale->GetLabelPosition()) |
71215351 | 3744 | { |
3745 | case Aspect_TOCSP_NONE: | |
3746 | theDI << "None\n"; | |
3747 | break; | |
3748 | case Aspect_TOCSP_LEFT: | |
3749 | theDI << "Left\n"; | |
3750 | break; | |
3751 | case Aspect_TOCSP_RIGHT: | |
3752 | theDI << "Right\n"; | |
3753 | break; | |
3754 | case Aspect_TOCSP_CENTER: | |
3755 | theDI << "Center\n"; | |
3756 | break; | |
3757 | } | |
3758 | return 0; | |
3759 | } | |
71215351 | 3760 | |
4b3d6eb1 | 3761 | if (aColorScale.IsNull()) |
3762 | { | |
3763 | aColorScale = new AIS_ColorScale(); | |
3764 | aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD); | |
3765 | aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER)); | |
3766 | } | |
3767 | ||
3768 | ViewerTest_AutoUpdater anUpdateTool (aContext, aView); | |
7a324550 | 3769 | for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter) |
71215351 | 3770 | { |
3771 | Standard_CString anArg = theArgVec[anArgIter]; | |
3772 | TCollection_AsciiString aFlag (anArg); | |
3773 | aFlag.LowerCase(); | |
3774 | if (anUpdateTool.parseRedrawMode (aFlag)) | |
3775 | { | |
3776 | continue; | |
3777 | } | |
3778 | else if (aFlag == "-range") | |
3779 | { | |
3780 | if (anArgIter + 3 >= theArgNb) | |
3781 | { | |
3782 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3783 | return 1; | |
3784 | } | |
3785 | ||
4b3d6eb1 | 3786 | const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]); |
3787 | const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]); | |
3788 | const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]); | |
3789 | if (!aRangeMin.IsRealValue() | |
3790 | || !aRangeMax.IsRealValue()) | |
71215351 | 3791 | { |
4b3d6eb1 | 3792 | std::cout << "Error: the range values should be real!\n"; |
71215351 | 3793 | return 1; |
3794 | } | |
4b3d6eb1 | 3795 | else if (!aNbIntervals.IsIntegerValue()) |
71215351 | 3796 | { |
3797 | std::cout << "Error: the number of intervals should be integer!\n"; | |
3798 | return 1; | |
3799 | } | |
3800 | ||
4b3d6eb1 | 3801 | aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue()); |
3802 | aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue()); | |
71215351 | 3803 | } |
3804 | else if (aFlag == "-font") | |
3805 | { | |
3806 | if (anArgIter + 1 >= theArgNb) | |
3807 | { | |
3808 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3809 | return 1; | |
3810 | } | |
51740958 | 3811 | TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]); |
3812 | if (!aFontArg.IsIntegerValue()) | |
71215351 | 3813 | { |
3814 | std::cout << "Error: HeightFont value should be integer!\n"; | |
3815 | return 1; | |
3816 | } | |
3817 | ||
4b3d6eb1 | 3818 | aColorScale->SetTextHeight (aFontArg.IntegerValue()); |
71215351 | 3819 | anArgIter += 1; |
3820 | } | |
3821 | else if (aFlag == "-textpos") | |
3822 | { | |
3823 | if (anArgIter + 1 >= theArgNb) | |
3824 | { | |
3825 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3826 | return 1; | |
3827 | } | |
4b3d6eb1 | 3828 | |
51740958 | 3829 | TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]); |
3830 | aTextPosArg.LowerCase(); | |
4b3d6eb1 | 3831 | Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE; |
51740958 | 3832 | if (aTextPosArg == "none") |
71215351 | 3833 | { |
3834 | aLabPosition = Aspect_TOCSP_NONE; | |
3835 | } | |
51740958 | 3836 | else if (aTextPosArg == "left") |
71215351 | 3837 | { |
3838 | aLabPosition = Aspect_TOCSP_LEFT; | |
3839 | } | |
51740958 | 3840 | else if (aTextPosArg == "right") |
71215351 | 3841 | { |
3842 | aLabPosition = Aspect_TOCSP_RIGHT; | |
3843 | } | |
51740958 | 3844 | else if (aTextPosArg == "center") |
71215351 | 3845 | { |
3846 | aLabPosition = Aspect_TOCSP_CENTER; | |
3847 | } | |
3848 | else | |
3849 | { | |
51740958 | 3850 | std::cout << "Error: unknown position '" << aTextPosArg << "'!\n"; |
71215351 | 3851 | return 1; |
3852 | } | |
4b3d6eb1 | 3853 | aColorScale->SetLabelPosition (aLabPosition); |
71215351 | 3854 | } |
24a88697 | 3855 | else if (aFlag == "-logarithmic" |
3856 | || aFlag == "-log") | |
3857 | { | |
3858 | if (anArgIter + 1 >= theArgNb) | |
3859 | { | |
3860 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3861 | return 1; | |
3862 | } | |
4b3d6eb1 | 3863 | |
24a88697 | 3864 | Standard_Boolean IsLog; |
3865 | if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog)) | |
3866 | { | |
3867 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3868 | return 1; | |
3869 | } | |
4b3d6eb1 | 3870 | aColorScale->SetLogarithmic (IsLog); |
3871 | } | |
3872 | else if (aFlag == "-huerange" | |
3873 | || aFlag == "-hue") | |
3874 | { | |
3875 | if (anArgIter + 2 >= theArgNb) | |
3876 | { | |
3877 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3878 | return 1; | |
3879 | } | |
3880 | ||
3881 | const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]); | |
3882 | const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]); | |
3883 | aColorScale->SetHueRange (aHueMin, aHueMax); | |
3884 | } | |
3885 | else if (aFlag == "-colorrange") | |
3886 | { | |
3887 | Quantity_Color aColorMin, aColorMax; | |
3888 | Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1), | |
3889 | theArgVec + (anArgIter + 1), | |
3890 | aColorMin); | |
3891 | anArgIter += aNbParsed1; | |
3892 | Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1), | |
3893 | theArgVec + (anArgIter + 1), | |
3894 | aColorMax); | |
3895 | anArgIter += aNbParsed2; | |
3896 | if (aNbParsed1 == 0 | |
3897 | || aNbParsed2 == 0) | |
3898 | { | |
3899 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; | |
3900 | return 1; | |
3901 | } | |
3902 | ||
3903 | aColorScale->SetColorRange (aColorMin, aColorMax); | |
3904 | } | |
3905 | else if (aFlag == "-reversed" | |
3906 | || aFlag == "-inverted" | |
3907 | || aFlag == "-topdown" | |
3908 | || aFlag == "-bottomup") | |
3909 | { | |
3910 | Standard_Boolean toEnable = Standard_True; | |
3911 | if (anArgIter + 1 < theArgNb | |
3912 | && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable)) | |
3913 | { | |
3914 | ++anArgIter; | |
3915 | } | |
3916 | aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable); | |
3917 | } | |
3918 | else if (aFlag == "-smooth" | |
3919 | || aFlag == "-smoothtransition") | |
3920 | { | |
3921 | Standard_Boolean toEnable = Standard_True; | |
3922 | if (anArgIter + 1 < theArgNb | |
3923 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
3924 | { | |
3925 | ++anArgIter; | |
3926 | } | |
3927 | aColorScale->SetSmoothTransition (toEnable); | |
24a88697 | 3928 | } |
71215351 | 3929 | else if (aFlag == "-xy") |
3930 | { | |
3931 | if (anArgIter + 2 >= theArgNb) | |
3932 | { | |
3933 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3934 | return 1; | |
3935 | } | |
3936 | ||
4b3d6eb1 | 3937 | const TCollection_AsciiString anX (theArgVec[++anArgIter]); |
3938 | const TCollection_AsciiString anY (theArgVec[++anArgIter]); | |
3939 | if (!anX.IsIntegerValue() | |
3940 | || !anY.IsIntegerValue()) | |
71215351 | 3941 | { |
b4b2ecca | 3942 | std::cout << "Error: coordinates should be integer values!\n"; |
71215351 | 3943 | return 1; |
3944 | } | |
3945 | ||
4b3d6eb1 | 3946 | aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue()); |
b4b2ecca | 3947 | } |
3948 | else if (aFlag == "-width" | |
4b3d6eb1 | 3949 | || aFlag == "-w" |
3950 | || aFlag == "-breadth") | |
b4b2ecca | 3951 | { |
3952 | if (anArgIter + 1 >= theArgNb) | |
3953 | { | |
3954 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3955 | return 1; | |
3956 | } | |
3957 | ||
4b3d6eb1 | 3958 | const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]); |
3959 | if (!aBreadth.IsIntegerValue()) | |
b4b2ecca | 3960 | { |
3961 | std::cout << "Error: a width should be an integer value!\n"; | |
3962 | return 1; | |
3963 | } | |
4b3d6eb1 | 3964 | aColorScale->SetBreadth (aBreadth.IntegerValue()); |
b4b2ecca | 3965 | } |
3966 | else if (aFlag == "-height" | |
3967 | || aFlag == "-h") | |
3968 | { | |
3969 | if (anArgIter + 1 >= theArgNb) | |
3970 | { | |
3971 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
3972 | return 1; | |
3973 | } | |
3974 | ||
4b3d6eb1 | 3975 | const TCollection_AsciiString aHeight (theArgVec[++anArgIter]); |
3976 | if (!aHeight.IsIntegerValue()) | |
b4b2ecca | 3977 | { |
3978 | std::cout << "Error: a width should be an integer value!\n"; | |
3979 | return 1; | |
3980 | } | |
4b3d6eb1 | 3981 | aColorScale->SetHeight (aHeight.IntegerValue()); |
71215351 | 3982 | } |
3983 | else if (aFlag == "-color") | |
3984 | { | |
4b3d6eb1 | 3985 | if (aColorScale->GetColorType() != Aspect_TOCSD_USER) |
71215351 | 3986 | { |
3987 | std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n"; | |
3988 | return 1; | |
3989 | } | |
4b3d6eb1 | 3990 | else if (anArgIter + 2 >= theArgNb) |
71215351 | 3991 | { |
4b3d6eb1 | 3992 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; |
3993 | return 1; | |
71215351 | 3994 | } |
3995 | ||
4b3d6eb1 | 3996 | const TCollection_AsciiString anInd (theArgVec[++anArgIter]); |
71215351 | 3997 | if (!anInd.IsIntegerValue()) |
3998 | { | |
3999 | std::cout << "Error: Index value should be integer!\n"; | |
4000 | return 1; | |
4001 | } | |
4b3d6eb1 | 4002 | const Standard_Integer anIndex = anInd.IntegerValue(); |
4003 | if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals()) | |
71215351 | 4004 | { |
4b3d6eb1 | 4005 | std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() <<"!\n"; |
71215351 | 4006 | return 1; |
4007 | } | |
4008 | ||
4b3d6eb1 | 4009 | Quantity_Color aColor; |
4010 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1), | |
4011 | theArgVec + (anArgIter + 1), | |
4012 | aColor); | |
4013 | if (aNbParsed == 0) | |
71215351 | 4014 | { |
4b3d6eb1 | 4015 | std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; |
71215351 | 4016 | return 1; |
4017 | } | |
4b3d6eb1 | 4018 | aColorScale->SetIntervalColor (aColor, anIndex); |
4019 | aColorScale->SetColorType (Aspect_TOCSD_USER); | |
4020 | anArgIter += aNbParsed; | |
71215351 | 4021 | } |
4022 | else if (aFlag == "-label") | |
4023 | { | |
4b3d6eb1 | 4024 | if (aColorScale->GetColorType() != Aspect_TOCSD_USER) |
71215351 | 4025 | { |
4026 | std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n"; | |
4027 | return 1; | |
4028 | } | |
4029 | else if (anArgIter + 2 >= theArgNb) | |
4030 | { | |
4031 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
4032 | return 1; | |
4033 | } | |
4034 | ||
4035 | Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]); | |
4b3d6eb1 | 4036 | if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1) |
71215351 | 4037 | { |
4b3d6eb1 | 4038 | std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() + 1 <<"!\n"; |
71215351 | 4039 | return 1; |
4040 | } | |
4041 | ||
4042 | TCollection_ExtendedString aText (theArgVec[anArgIter + 2]); | |
4b3d6eb1 | 4043 | aColorScale->SetLabel (aText, anIndex); |
4044 | aColorScale->SetLabelType (Aspect_TOCSD_USER); | |
71215351 | 4045 | anArgIter += 2; |
4046 | } | |
4b3d6eb1 | 4047 | else if (aFlag == "-labelat" |
4048 | || aFlag == "-labat" | |
4049 | || aFlag == "-labelatborder" | |
4050 | || aFlag == "-labatborder" | |
4051 | || aFlag == "-labelatcenter" | |
4052 | || aFlag == "-labatcenter") | |
71215351 | 4053 | { |
4b3d6eb1 | 4054 | Standard_Boolean toEnable = Standard_True; |
4055 | if (aFlag == "-labelat" | |
4056 | || aFlag == "-labat") | |
71215351 | 4057 | { |
4b3d6eb1 | 4058 | Standard_Integer aLabAtBorder = -1; |
4059 | if (++anArgIter >= theArgNb) | |
71215351 | 4060 | { |
4b3d6eb1 | 4061 | TCollection_AsciiString anAtBorder (theArgVec[anArgIter]); |
4062 | anAtBorder.LowerCase(); | |
4063 | if (anAtBorder == "border") | |
71215351 | 4064 | { |
4b3d6eb1 | 4065 | aLabAtBorder = 1; |
71215351 | 4066 | } |
4b3d6eb1 | 4067 | else if (anAtBorder == "center") |
71215351 | 4068 | { |
4b3d6eb1 | 4069 | aLabAtBorder = 0; |
71215351 | 4070 | } |
71215351 | 4071 | } |
4b3d6eb1 | 4072 | if (aLabAtBorder == -1) |
4073 | { | |
4074 | std::cout << "Syntax error at argument '" << anArg << "'!\n"; | |
4075 | return 1; | |
4076 | } | |
4077 | toEnable = (aLabAtBorder == 1); | |
4078 | } | |
4079 | else if (anArgIter + 1 < theArgNb | |
4080 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
4081 | { | |
4082 | ++anArgIter; | |
71215351 | 4083 | } |
4b3d6eb1 | 4084 | aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter" |
4085 | || aFlag == "-labatcenter" | |
4086 | ? !toEnable | |
4087 | : toEnable); | |
4088 | } | |
4089 | else if (aFlag == "-colors") | |
4090 | { | |
4091 | Aspect_SequenceOfColor aSeq; | |
4092 | for (;;) | |
4093 | { | |
4094 | Quantity_Color aColor; | |
4095 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1), | |
4096 | theArgVec + (anArgIter + 1), | |
4097 | aColor); | |
4098 | if (aNbParsed == 0) | |
4099 | { | |
4100 | break; | |
4101 | } | |
4102 | anArgIter += aNbParsed; | |
4103 | aSeq.Append (aColor); | |
4104 | } | |
4105 | if (aSeq.Length() != aColorScale->GetNumberOfIntervals()) | |
71215351 | 4106 | { |
4107 | std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the " | |
4b3d6eb1 | 4108 | << aColorScale->GetNumberOfIntervals() << " intervals\n"; |
71215351 | 4109 | return 1; |
4110 | } | |
4111 | ||
4b3d6eb1 | 4112 | aColorScale->SetColors (aSeq); |
4113 | aColorScale->SetColorType (Aspect_TOCSD_USER); | |
71215351 | 4114 | } |
4b3d6eb1 | 4115 | else if (aFlag == "-labels" |
4116 | || aFlag == "-freelabels") | |
71215351 | 4117 | { |
4b3d6eb1 | 4118 | if (anArgIter + 1 >= theArgNb) |
4119 | { | |
4120 | std::cout << "Syntax error at argument '" << anArg << "'!\n"; | |
4121 | return 1; | |
4122 | } | |
4123 | ||
4124 | Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder() | |
4125 | ? aColorScale->GetNumberOfIntervals() + 1 | |
4126 | : aColorScale->GetNumberOfIntervals(); | |
4127 | if (aFlag == "-freelabels") | |
4128 | { | |
4129 | ++anArgIter; | |
4130 | aNbLabels = Draw::Atoi (theArgVec[anArgIter]); | |
4131 | } | |
4132 | if (anArgIter + aNbLabels >= theArgNb) | |
71215351 | 4133 | { |
4b3d6eb1 | 4134 | std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n"; |
71215351 | 4135 | return 1; |
4136 | } | |
4137 | ||
4138 | TColStd_SequenceOfExtendedString aSeq; | |
4b3d6eb1 | 4139 | for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter) |
71215351 | 4140 | { |
4b3d6eb1 | 4141 | aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter])); |
71215351 | 4142 | } |
4b3d6eb1 | 4143 | aColorScale->SetLabels (aSeq); |
4144 | aColorScale->SetLabelType (Aspect_TOCSD_USER); | |
71215351 | 4145 | } |
4146 | else if (aFlag == "-title") | |
4147 | { | |
4148 | if (anArgIter + 1 >= theArgNb) | |
4149 | { | |
4150 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
4151 | return 1; | |
4152 | } | |
4153 | ||
4154 | Standard_Boolean isTwoArgs = Standard_False; | |
4155 | if (anArgIter + 2 < theArgNb) | |
4156 | { | |
4157 | TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]); | |
4158 | aSecondArg.LowerCase(); | |
4b3d6eb1 | 4159 | Standard_DISABLE_DEPRECATION_WARNINGS |
71215351 | 4160 | if (aSecondArg == "none") |
4161 | { | |
4b3d6eb1 | 4162 | aColorScale->SetTitlePosition (Aspect_TOCSP_NONE); |
71215351 | 4163 | isTwoArgs = Standard_True; |
4164 | } | |
4165 | else if (aSecondArg == "left") | |
4166 | { | |
4b3d6eb1 | 4167 | aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT); |
71215351 | 4168 | isTwoArgs = Standard_True; |
4169 | } | |
4170 | else if (aSecondArg == "right") | |
4171 | { | |
4b3d6eb1 | 4172 | aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT); |
71215351 | 4173 | isTwoArgs = Standard_True; |
4174 | } | |
4175 | else if (aSecondArg == "center") | |
4176 | { | |
4b3d6eb1 | 4177 | aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER); |
71215351 | 4178 | isTwoArgs = Standard_True; |
4179 | } | |
4b3d6eb1 | 4180 | Standard_ENABLE_DEPRECATION_WARNINGS |
71215351 | 4181 | } |
4182 | ||
4b3d6eb1 | 4183 | aColorScale->SetTitle (theArgVec[anArgIter + 1]); |
71215351 | 4184 | if (isTwoArgs) |
4185 | { | |
4186 | anArgIter += 1; | |
4187 | } | |
4188 | anArgIter += 1; | |
4189 | } | |
4190 | else if (aFlag == "-demoversion" | |
4191 | || aFlag == "-demo") | |
4192 | { | |
4b3d6eb1 | 4193 | aColorScale->SetPosition (0, 0); |
4194 | aColorScale->SetTextHeight (16); | |
4195 | aColorScale->SetRange (0.0, 100.0); | |
4196 | aColorScale->SetNumberOfIntervals (10); | |
4197 | aColorScale->SetBreadth (0); | |
4198 | aColorScale->SetHeight (0); | |
4199 | aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT); | |
4200 | aColorScale->SetColorType (Aspect_TOCSD_AUTO); | |
4201 | aColorScale->SetLabelType (Aspect_TOCSD_AUTO); | |
71215351 | 4202 | } |
d5514578 | 4203 | else if (aFlag == "-findcolor") |
4204 | { | |
4205 | if (anArgIter + 1 >= theArgNb) | |
4206 | { | |
4207 | std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n"; | |
4208 | return 1; | |
4209 | } | |
4210 | ||
4211 | TCollection_AsciiString anArg1 (theArgVec[++anArgIter]); | |
4212 | ||
4213 | if (!anArg1.IsRealValue()) | |
4214 | { | |
4215 | std::cout << "Error: the value should be real!\n"; | |
4216 | return 1; | |
4217 | } | |
4218 | ||
4219 | Quantity_Color aColor; | |
4b3d6eb1 | 4220 | aColorScale->FindColor (anArg1.RealValue(), aColor); |
d5514578 | 4221 | theDI << Quantity_Color::StringName (aColor.Name()); |
4222 | return 0; | |
4223 | } | |
71215351 | 4224 | else |
4225 | { | |
4226 | std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n"; | |
4227 | return 1; | |
4228 | } | |
4229 | } | |
4b3d6eb1 | 4230 | |
4231 | Standard_Integer aWinWidth = 0, aWinHeight = 0; | |
4232 | aView->Window()->Size (aWinWidth, aWinHeight); | |
4233 | if (aColorScale->GetBreadth() == 0) | |
b4b2ecca | 4234 | { |
4b3d6eb1 | 4235 | aColorScale->SetBreadth (aWinWidth); |
b4b2ecca | 4236 | } |
4b3d6eb1 | 4237 | if (aColorScale->GetHeight() == 0) |
4238 | { | |
4239 | aColorScale->SetHeight (aWinHeight); | |
4240 | } | |
4241 | aColorScale->SetToUpdate(); | |
4242 | ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True); | |
7fd59977 | 4243 | return 0; |
4244 | } | |
4245 | ||
4246 | //============================================================================== | |
4247 | //function : VGraduatedTrihedron | |
a79f67f8 | 4248 | //purpose : Displays or hides a graduated trihedron |
7fd59977 | 4249 | //============================================================================== |
a79f67f8 | 4250 | static Standard_Boolean GetColor (const TCollection_AsciiString& theValue, |
4251 | Quantity_Color& theColor) | |
13a22457 | 4252 | { |
a79f67f8 | 4253 | Quantity_NameOfColor aColorName; |
4254 | TCollection_AsciiString aVal = theValue; | |
4255 | aVal.UpperCase(); | |
4256 | if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName)) | |
13a22457 | 4257 | { |
a79f67f8 | 4258 | return Standard_False; |
13a22457 | 4259 | } |
a79f67f8 | 4260 | theColor = Quantity_Color (aColorName); |
4261 | return Standard_True; | |
13a22457 S |
4262 | } |
4263 | ||
a79f67f8 | 4264 | static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs) |
7fd59977 | 4265 | { |
a79f67f8 | 4266 | if (theArgNum < 2) |
13a22457 | 4267 | { |
a79f67f8 | 4268 | std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help" |
4269 | << theArgs[0] <<"' for more information.\n"; | |
4270 | return 1; //TCL_ERROR | |
13a22457 | 4271 | } |
7fd59977 | 4272 | |
a79f67f8 | 4273 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs; |
4274 | TCollection_AsciiString aParseKey; | |
4275 | for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt) | |
4276 | { | |
4277 | TCollection_AsciiString anArg (theArgs [anArgIt]); | |
4278 | ||
4279 | if (anArg.Value (1) == '-' && !anArg.IsRealValue()) | |
4280 | { | |
4281 | aParseKey = anArg; | |
4282 | aParseKey.Remove (1); | |
4283 | aParseKey.LowerCase(); | |
4284 | aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString); | |
4285 | continue; | |
4286 | } | |
13a22457 | 4287 | |
a79f67f8 | 4288 | if (aParseKey.IsEmpty()) |
4289 | { | |
4290 | continue; | |
4291 | } | |
4292 | ||
4293 | aMapOfArgs(aParseKey)->Append (anArg); | |
4294 | } | |
4295 | ||
4296 | // Check parameters | |
4297 | for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs); | |
4298 | aMapIt.More(); aMapIt.Next()) | |
7fd59977 | 4299 | { |
a79f67f8 | 4300 | const TCollection_AsciiString& aKey = aMapIt.Key(); |
4301 | const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value(); | |
4302 | ||
4303 | // Bool key, without arguments | |
4304 | if ((aKey.IsEqual ("on") || aKey.IsEqual ("off")) | |
4305 | && anArgs->IsEmpty()) | |
4306 | { | |
4307 | continue; | |
4308 | } | |
4309 | ||
4310 | // One argument | |
4311 | if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname")) | |
4312 | && anArgs->Length() == 1) | |
4313 | { | |
4314 | continue; | |
4315 | } | |
4316 | ||
4317 | // On/off arguments | |
4318 | if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname") | |
4319 | || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks") | |
536d98e2 | 4320 | || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues") |
4321 | || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes")) | |
a79f67f8 | 4322 | && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off"))) |
4323 | { | |
4324 | continue; | |
4325 | } | |
4326 | ||
4327 | // One string argument | |
4328 | if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor") | |
4329 | || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor")) | |
4330 | && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue()) | |
4331 | { | |
4332 | continue; | |
4333 | } | |
4334 | ||
4335 | // One integer argument | |
4336 | if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks") | |
4337 | || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength") | |
4338 | || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset") | |
4339 | || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset")) | |
4340 | && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue()) | |
4341 | { | |
4342 | continue; | |
4343 | } | |
4344 | ||
4345 | // One real argument | |
4346 | if ( aKey.IsEqual ("arrowlength") | |
4347 | && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue())) | |
4348 | { | |
4349 | continue; | |
4350 | } | |
4351 | ||
4352 | // Two string arguments | |
4353 | if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont")) | |
4354 | && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue()) | |
13a22457 | 4355 | { |
a79f67f8 | 4356 | continue; |
13a22457 | 4357 | } |
a79f67f8 | 4358 | |
4359 | TCollection_AsciiString aLowerKey; | |
4360 | aLowerKey = "-"; | |
4361 | aLowerKey += aKey; | |
4362 | aLowerKey.LowerCase(); | |
4363 | std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n"; | |
4364 | std::cout << "Type help for more information.\n"; | |
4365 | return 1; | |
7fd59977 | 4366 | } |
4367 | ||
a79f67f8 | 4368 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); |
4369 | if (anAISContext.IsNull()) | |
4370 | { | |
586db386 | 4371 | std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n"; |
a79f67f8 | 4372 | return 1; |
4373 | } | |
7fd59977 | 4374 | |
a79f67f8 | 4375 | Standard_Boolean toDisplay = Standard_True; |
4376 | Quantity_Color aColor; | |
4377 | Graphic3d_GraduatedTrihedron aTrihedronData; | |
4378 | // Process parameters | |
4379 | Handle(TColStd_HSequenceOfAsciiString) aValues; | |
4380 | if (aMapOfArgs.Find ("off", aValues)) | |
7fd59977 | 4381 | { |
a79f67f8 | 4382 | toDisplay = Standard_False; |
4383 | } | |
13a22457 | 4384 | |
a79f67f8 | 4385 | // AXES NAMES |
4386 | if (aMapOfArgs.Find ("xname", aValues)) | |
4387 | { | |
4388 | aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1)); | |
4389 | } | |
4390 | if (aMapOfArgs.Find ("yname", aValues)) | |
4391 | { | |
4392 | aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1)); | |
4393 | } | |
4394 | if (aMapOfArgs.Find ("zname", aValues)) | |
4395 | { | |
4396 | aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1)); | |
4397 | } | |
4398 | if (aMapOfArgs.Find ("xdrawname", aValues)) | |
4399 | { | |
536d98e2 | 4400 | aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4401 | } |
4402 | if (aMapOfArgs.Find ("ydrawname", aValues)) | |
4403 | { | |
536d98e2 | 4404 | aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4405 | } |
4406 | if (aMapOfArgs.Find ("zdrawname", aValues)) | |
4407 | { | |
536d98e2 | 4408 | aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4409 | } |
4410 | if (aMapOfArgs.Find ("xnameoffset", aValues)) | |
4411 | { | |
4412 | aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); | |
4413 | } | |
4414 | if (aMapOfArgs.Find ("ynameoffset", aValues)) | |
4415 | { | |
4416 | aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); | |
4417 | } | |
4418 | if (aMapOfArgs.Find ("znameoffset", aValues)) | |
4419 | { | |
4420 | aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); | |
4421 | } | |
13a22457 | 4422 | |
a79f67f8 | 4423 | // COLORS |
4424 | if (aMapOfArgs.Find ("xnamecolor", aValues)) | |
4425 | { | |
4426 | if (!GetColor (aValues->Value(1), aColor)) | |
13a22457 | 4427 | { |
a79f67f8 | 4428 | std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n"; |
4429 | return 1; | |
13a22457 | 4430 | } |
a79f67f8 | 4431 | aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor); |
4432 | } | |
4433 | if (aMapOfArgs.Find ("ynamecolor", aValues)) | |
4434 | { | |
4435 | if (!GetColor (aValues->Value(1), aColor)) | |
13a22457 | 4436 | { |
a79f67f8 | 4437 | std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n"; |
4438 | return 1; | |
4439 | } | |
4440 | aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor); | |
4441 | } | |
4442 | if (aMapOfArgs.Find ("znamecolor", aValues)) | |
4443 | { | |
4444 | if (!GetColor (aValues->Value(1), aColor)) | |
4445 | { | |
4446 | std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n"; | |
4447 | return 1; | |
4448 | } | |
4449 | aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor); | |
4450 | } | |
4451 | if (aMapOfArgs.Find ("xcolor", aValues)) | |
4452 | { | |
4453 | if (!GetColor (aValues->Value(1), aColor)) | |
4454 | { | |
4455 | std::cout << theArgs[0] << "error: -xcolor wrong color name.\n"; | |
4456 | return 1; | |
4457 | } | |
4458 | aTrihedronData.ChangeXAxisAspect().SetColor (aColor); | |
4459 | } | |
4460 | if (aMapOfArgs.Find ("ycolor", aValues)) | |
4461 | { | |
4462 | if (!GetColor (aValues->Value(1), aColor)) | |
4463 | { | |
4464 | std::cout << theArgs[0] << "error: -ycolor wrong color name.\n"; | |
4465 | return 1; | |
4466 | } | |
4467 | aTrihedronData.ChangeYAxisAspect().SetColor (aColor); | |
4468 | } | |
4469 | if (aMapOfArgs.Find ("zcolor", aValues)) | |
4470 | { | |
4471 | if (!GetColor (aValues->Value(1), aColor)) | |
4472 | { | |
4473 | std::cout << theArgs[0] << "error: -zcolor wrong color name.\n"; | |
4474 | return 1; | |
4475 | } | |
4476 | aTrihedronData.ChangeZAxisAspect().SetColor (aColor); | |
4477 | } | |
4478 | ||
4479 | // TICKMARKS | |
4480 | if (aMapOfArgs.Find ("xticks", aValues)) | |
4481 | { | |
536d98e2 | 4482 | aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4483 | } |
4484 | if (aMapOfArgs.Find ("yticks", aValues)) | |
4485 | { | |
536d98e2 | 4486 | aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4487 | } |
4488 | if (aMapOfArgs.Find ("zticks", aValues)) | |
4489 | { | |
536d98e2 | 4490 | aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4491 | } |
4492 | if (aMapOfArgs.Find ("xticklength", aValues)) | |
4493 | { | |
536d98e2 | 4494 | aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4495 | } |
4496 | if (aMapOfArgs.Find ("yticklength", aValues)) | |
4497 | { | |
536d98e2 | 4498 | aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4499 | } |
4500 | if (aMapOfArgs.Find ("zticklength", aValues)) | |
4501 | { | |
536d98e2 | 4502 | aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); |
a79f67f8 | 4503 | } |
4504 | if (aMapOfArgs.Find ("xdrawticks", aValues)) | |
4505 | { | |
536d98e2 | 4506 | aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4507 | } |
4508 | if (aMapOfArgs.Find ("ydrawticks", aValues)) | |
4509 | { | |
536d98e2 | 4510 | aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4511 | } |
4512 | if (aMapOfArgs.Find ("zdrawticks", aValues)) | |
4513 | { | |
536d98e2 | 4514 | aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4515 | } |
4516 | ||
4517 | // VALUES | |
4518 | if (aMapOfArgs.Find ("xdrawvalues", aValues)) | |
4519 | { | |
536d98e2 | 4520 | aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4521 | } |
4522 | if (aMapOfArgs.Find ("ydrawvalues", aValues)) | |
4523 | { | |
536d98e2 | 4524 | aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4525 | } |
4526 | if (aMapOfArgs.Find ("zdrawvalues", aValues)) | |
4527 | { | |
536d98e2 | 4528 | aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); |
a79f67f8 | 4529 | } |
4530 | if (aMapOfArgs.Find ("xvaluesoffset", aValues)) | |
4531 | { | |
4532 | aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); | |
4533 | } | |
4534 | if (aMapOfArgs.Find ("yvaluesoffset", aValues)) | |
4535 | { | |
4536 | aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); | |
4537 | } | |
4538 | if (aMapOfArgs.Find ("zvaluesoffset", aValues)) | |
4539 | { | |
4540 | aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); | |
4541 | } | |
4542 | ||
4543 | // ARROWS | |
4544 | if (aMapOfArgs.Find ("arrowlength", aValues)) | |
4545 | { | |
536d98e2 | 4546 | aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue()); |
a79f67f8 | 4547 | } |
4548 | ||
4549 | // FONTS | |
4550 | if (aMapOfArgs.Find ("namefont", aValues)) | |
4551 | { | |
4552 | aTrihedronData.SetNamesFont (aValues->Value(1)); | |
4553 | } | |
4554 | if (aMapOfArgs.Find ("valuesfont", aValues)) | |
4555 | { | |
4556 | aTrihedronData.SetValuesFont (aValues->Value(1)); | |
4557 | } | |
4558 | ||
536d98e2 | 4559 | if (aMapOfArgs.Find ("drawgrid", aValues)) |
4560 | { | |
4561 | aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on")); | |
4562 | } | |
4563 | if (aMapOfArgs.Find ("drawaxes", aValues)) | |
4564 | { | |
4565 | aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on")); | |
4566 | } | |
4567 | ||
a79f67f8 | 4568 | // The final step: display of erase trihedron |
4569 | if (toDisplay) | |
4570 | { | |
4571 | ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData); | |
13a22457 | 4572 | } |
7fd59977 | 4573 | else |
a79f67f8 | 4574 | { |
4575 | ViewerTest::CurrentView()->GraduatedTrihedronErase(); | |
4576 | } | |
7fd59977 | 4577 | |
4578 | ViewerTest::GetAISContext()->UpdateCurrentViewer(); | |
a79f67f8 | 4579 | ViewerTest::CurrentView()->Redraw(); |
13a22457 | 4580 | |
7fd59977 | 4581 | return 0; |
4582 | } | |
4583 | ||
3bffef55 | 4584 | //============================================================================== |
4585 | //function : VTile | |
4586 | //purpose : | |
4587 | //============================================================================== | |
4588 | static int VTile (Draw_Interpretor& theDI, | |
4589 | Standard_Integer theArgNb, | |
4590 | const char** theArgVec) | |
4591 | { | |
4592 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4593 | if (aView.IsNull()) | |
4594 | { | |
4595 | std::cerr << "Error: no active viewer.\n"; | |
4596 | return 1; | |
4597 | } | |
4598 | ||
4599 | Graphic3d_CameraTile aTile = aView->Camera()->Tile(); | |
4600 | if (theArgNb < 2) | |
4601 | { | |
4602 | theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n" | |
4603 | << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n" | |
4604 | << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n"; | |
4605 | return 0; | |
4606 | } | |
4607 | ||
4608 | aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y()); | |
4609 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
4610 | { | |
4611 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
4612 | anArg.LowerCase(); | |
4613 | if (anArg == "-lowerleft" | |
4614 | || anArg == "-upperleft") | |
4615 | { | |
4616 | if (anArgIter + 3 < theArgNb) | |
4617 | { | |
4618 | std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n"; | |
4619 | return 1; | |
4620 | } | |
4621 | aTile.IsTopDown = (anArg == "-upperleft") == Standard_True; | |
4622 | aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]); | |
4623 | aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]); | |
4624 | } | |
4625 | else if (anArg == "-total" | |
4626 | || anArg == "-totalsize" | |
4627 | || anArg == "-viewsize") | |
4628 | { | |
4629 | if (anArgIter + 3 < theArgNb) | |
4630 | { | |
4631 | std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n"; | |
4632 | return 1; | |
4633 | } | |
4634 | aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]); | |
4635 | aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]); | |
4636 | if (aTile.TotalSize.x() < 1 | |
4637 | || aTile.TotalSize.y() < 1) | |
4638 | { | |
4639 | std::cerr << "Error: total size is incorrect.\n"; | |
4640 | return 1; | |
4641 | } | |
4642 | } | |
4643 | else if (anArg == "-tilesize") | |
4644 | { | |
4645 | if (anArgIter + 3 < theArgNb) | |
4646 | { | |
4647 | std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n"; | |
4648 | return 1; | |
4649 | } | |
4650 | ||
4651 | aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]); | |
4652 | aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]); | |
4653 | if (aTile.TileSize.x() < 1 | |
4654 | || aTile.TileSize.y() < 1) | |
4655 | { | |
4656 | std::cerr << "Error: tile size is incorrect.\n"; | |
4657 | return 1; | |
4658 | } | |
4659 | } | |
4660 | else if (anArg == "-unset") | |
4661 | { | |
4662 | aView->Camera()->SetTile (Graphic3d_CameraTile()); | |
4663 | aView->Redraw(); | |
4664 | return 0; | |
4665 | } | |
4666 | } | |
4667 | ||
4668 | if (aTile.TileSize.x() < 1 | |
4669 | || aTile.TileSize.y() < 1) | |
4670 | { | |
4671 | std::cerr << "Error: tile size is undefined.\n"; | |
4672 | return 1; | |
4673 | } | |
4674 | else if (aTile.TotalSize.x() < 1 | |
4675 | || aTile.TotalSize.y() < 1) | |
4676 | { | |
4677 | std::cerr << "Error: total size is undefined.\n"; | |
4678 | return 1; | |
4679 | } | |
4680 | ||
4681 | aView->Camera()->SetTile (aTile); | |
4682 | aView->Redraw(); | |
4683 | return 0; | |
4684 | } | |
4685 | ||
7c3ef2f7 | 4686 | //! Format ZLayer ID. |
4687 | inline const char* formZLayerId (const Standard_Integer theLayerId) | |
4688 | { | |
4689 | switch (theLayerId) | |
4690 | { | |
4691 | case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]"; | |
4692 | case Graphic3d_ZLayerId_Default: return "[DEFAULT]"; | |
4693 | case Graphic3d_ZLayerId_Top: return "[TOP]"; | |
4694 | case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]"; | |
4695 | case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]"; | |
4696 | case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]"; | |
4697 | } | |
4698 | return ""; | |
4699 | } | |
4700 | ||
4701 | //! Print the ZLayer information. | |
4702 | inline void printZLayerInfo (Draw_Interpretor& theDI, | |
4703 | const Graphic3d_ZLayerSettings& theLayer) | |
4704 | { | |
4705 | if (!theLayer.Name().IsEmpty()) | |
4706 | { | |
4707 | theDI << " Name: " << theLayer.Name() << "\n"; | |
4708 | } | |
4709 | if (theLayer.IsImmediate()) | |
4710 | { | |
4711 | theDI << " Immediate: TRUE\n"; | |
4712 | } | |
4713 | theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n"; | |
4ecf34cc | 4714 | theDI << " Culling distance: " << theLayer.CullingDistance() << "\n"; |
4715 | theDI << " Culling size: " << theLayer.CullingSize() << "\n"; | |
7c3ef2f7 | 4716 | theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n"; |
4717 | theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n"; | |
4718 | theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n"; | |
4719 | if (theLayer.PolygonOffset().Mode != Aspect_POM_None) | |
4720 | { | |
4721 | theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n"; | |
4722 | } | |
4723 | } | |
4724 | ||
59f45b7c | 4725 | //============================================================================== |
4726 | //function : VZLayer | |
4727 | //purpose : Test z layer operations for v3d viewer | |
4728 | //============================================================================== | |
7c3ef2f7 | 4729 | static int VZLayer (Draw_Interpretor& theDI, |
4730 | Standard_Integer theArgNb, | |
4731 | const char** theArgVec) | |
59f45b7c | 4732 | { |
7c3ef2f7 | 4733 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); |
59f45b7c | 4734 | if (aContextAIS.IsNull()) |
4735 | { | |
7c3ef2f7 | 4736 | std::cout << "No active viewer!\n"; |
59f45b7c | 4737 | return 1; |
4738 | } | |
4739 | ||
4740 | const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer(); | |
7c3ef2f7 | 4741 | if (theArgNb < 2) |
59f45b7c | 4742 | { |
7c3ef2f7 | 4743 | TColStd_SequenceOfInteger aLayers; |
4744 | aViewer->GetAllZLayers (aLayers); | |
4745 | for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next()) | |
4746 | { | |
4747 | theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n"; | |
4748 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value()); | |
4749 | printZLayerInfo (theDI, aSettings); | |
4750 | } | |
59f45b7c | 4751 | return 1; |
4752 | } | |
4753 | ||
7c3ef2f7 | 4754 | Standard_Integer anArgIter = 1; |
4755 | Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN; | |
4756 | ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView()); | |
4757 | if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter])) | |
59f45b7c | 4758 | { |
7c3ef2f7 | 4759 | ++anArgIter; |
4760 | } | |
59f45b7c | 4761 | |
7c3ef2f7 | 4762 | TCollection_AsciiString aFirstArg (theArgVec[anArgIter]); |
4763 | if (aFirstArg.IsIntegerValue()) | |
4764 | { | |
4765 | ++anArgIter; | |
4766 | aLayerId = aFirstArg.IntegerValue(); | |
59f45b7c | 4767 | } |
7c3ef2f7 | 4768 | else |
59f45b7c | 4769 | { |
7c3ef2f7 | 4770 | aFirstArg.LowerCase(); |
4771 | if (aFirstArg == "default" | |
4772 | || aFirstArg == "def") | |
59f45b7c | 4773 | { |
7c3ef2f7 | 4774 | aLayerId = Graphic3d_ZLayerId_Default; |
4775 | ++anArgIter; | |
59f45b7c | 4776 | } |
7c3ef2f7 | 4777 | else if (aFirstArg == "top") |
59f45b7c | 4778 | { |
7c3ef2f7 | 4779 | aLayerId = Graphic3d_ZLayerId_Top; |
4780 | ++anArgIter; | |
59f45b7c | 4781 | } |
7c3ef2f7 | 4782 | else if (aFirstArg == "topmost") |
a1954302 | 4783 | { |
7c3ef2f7 | 4784 | aLayerId = Graphic3d_ZLayerId_Topmost; |
4785 | ++anArgIter; | |
a1954302 | 4786 | } |
7c3ef2f7 | 4787 | else if (aFirstArg == "overlay" |
4788 | || aFirstArg == "toposd") | |
59f45b7c | 4789 | { |
7c3ef2f7 | 4790 | aLayerId = Graphic3d_ZLayerId_TopOSD; |
4791 | ++anArgIter; | |
59f45b7c | 4792 | } |
7c3ef2f7 | 4793 | else if (aFirstArg == "underlay" |
4794 | || aFirstArg == "botosd") | |
c5751993 | 4795 | { |
7c3ef2f7 | 4796 | aLayerId = Graphic3d_ZLayerId_BotOSD; |
4797 | ++anArgIter; | |
c5751993 | 4798 | } |
7c3ef2f7 | 4799 | else |
c5751993 | 4800 | { |
7c3ef2f7 | 4801 | TColStd_SequenceOfInteger aLayers; |
4802 | aViewer->GetAllZLayers (aLayers); | |
4803 | for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next()) | |
4804 | { | |
4805 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value()); | |
4806 | if (TCollection_AsciiString::IsSameString (aSettings.Name(), aFirstArg, Standard_False)) | |
4807 | { | |
4808 | aLayerId = aLayeriter.Value(); | |
4809 | ++anArgIter; | |
4810 | break; | |
4811 | } | |
4812 | } | |
c5751993 | 4813 | } |
7c3ef2f7 | 4814 | } |
c5751993 | 4815 | |
7c3ef2f7 | 4816 | for (; anArgIter < theArgNb; ++anArgIter) |
4817 | { | |
4818 | // perform operation | |
4819 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
4820 | anArg.LowerCase(); | |
4821 | if (anUpdateTool.parseRedrawMode (anArg)) | |
c5751993 | 4822 | { |
7c3ef2f7 | 4823 | // |
c5751993 | 4824 | } |
7c3ef2f7 | 4825 | else if (anArg == "-add" |
4826 | || anArg == "add") | |
c5751993 | 4827 | { |
7c3ef2f7 | 4828 | aLayerId = Graphic3d_ZLayerId_UNKNOWN; |
4829 | if (!aViewer->AddZLayer (aLayerId)) | |
4830 | { | |
4831 | std::cout << "Error: can not add a new z layer!\n"; | |
4832 | return 0; | |
4833 | } | |
4834 | ||
4835 | theDI << aLayerId; | |
c5751993 | 4836 | } |
7c3ef2f7 | 4837 | else if (anArg == "-del" |
4838 | || anArg == "-delete" | |
4839 | || anArg == "del") | |
c5751993 | 4840 | { |
7c3ef2f7 | 4841 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) |
4842 | { | |
4843 | if (++anArgIter >= theArgNb) | |
4844 | { | |
4845 | std::cout << "Syntax error: id of z layer to remove is missing\n"; | |
4846 | return 1; | |
4847 | } | |
4848 | ||
4849 | aLayerId = Draw::Atoi (theArgVec[anArgIter]); | |
4850 | } | |
4851 | ||
4852 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN | |
4853 | || aLayerId == Graphic3d_ZLayerId_Default | |
4854 | || aLayerId == Graphic3d_ZLayerId_Top | |
4855 | || aLayerId == Graphic3d_ZLayerId_Topmost | |
4856 | || aLayerId == Graphic3d_ZLayerId_TopOSD | |
4857 | || aLayerId == Graphic3d_ZLayerId_BotOSD) | |
4858 | { | |
4859 | std::cout << "Syntax error: standard Z layer can not be removed\n"; | |
4860 | return 1; | |
4861 | } | |
4862 | ||
4863 | // move all object displayed in removing layer to default layer | |
4864 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); | |
4865 | anObjIter.More(); anObjIter.Next()) | |
4866 | { | |
8f521168 | 4867 | const Handle(AIS_InteractiveObject)& aPrs = anObjIter.Key1(); |
7c3ef2f7 | 4868 | if (aPrs.IsNull() |
4869 | || aPrs->ZLayer() != aLayerId) | |
4870 | { | |
4871 | continue; | |
4872 | } | |
4873 | aPrs->SetZLayer (Graphic3d_ZLayerId_Default); | |
4874 | } | |
4875 | ||
4876 | if (!aViewer->RemoveZLayer (aLayerId)) | |
4877 | { | |
4878 | std::cout << "Z layer can not be removed!\n"; | |
4879 | } | |
4880 | else | |
4881 | { | |
4882 | theDI << aLayerId << " "; | |
4883 | } | |
c5751993 | 4884 | } |
7c3ef2f7 | 4885 | else if (anArg == "-get" |
4886 | || anArg == "get") | |
c5751993 | 4887 | { |
7c3ef2f7 | 4888 | TColStd_SequenceOfInteger aLayers; |
4889 | aViewer->GetAllZLayers (aLayers); | |
4890 | for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next()) | |
4891 | { | |
4892 | theDI << aLayeriter.Value() << " "; | |
4893 | } | |
4894 | ||
4895 | theDI << "\n"; | |
c5751993 | 4896 | } |
7c3ef2f7 | 4897 | else if (anArg == "-name") |
c5751993 | 4898 | { |
7c3ef2f7 | 4899 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) |
c5751993 | 4900 | { |
7c3ef2f7 | 4901 | std::cout << "Syntax error: id of Z layer is missing\n"; |
c5751993 | 4902 | return 1; |
4903 | } | |
4904 | ||
7c3ef2f7 | 4905 | if (++anArgIter >= theArgNb) |
4906 | { | |
4907 | std::cout << "Syntax error: name is missing\n"; | |
4908 | return 1; | |
4909 | } | |
c5751993 | 4910 | |
7c3ef2f7 | 4911 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); |
4912 | aSettings.SetName (theArgVec[anArgIter]); | |
4913 | aViewer->SetZLayerSettings (aLayerId, aSettings); | |
c5751993 | 4914 | } |
7c3ef2f7 | 4915 | else if (anArg == "-origin") |
c5751993 | 4916 | { |
7c3ef2f7 | 4917 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) |
4918 | { | |
4919 | std::cout << "Syntax error: id of Z layer is missing\n"; | |
4920 | return 1; | |
4921 | } | |
4922 | ||
4923 | if (anArgIter + 2 >= theArgNb) | |
4924 | { | |
4925 | std::cout << "Syntax error: origin coordinates are missing\n"; | |
4926 | return 1; | |
4927 | } | |
4928 | ||
4929 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); | |
4930 | gp_XYZ anOrigin; | |
4931 | anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1])); | |
4932 | anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2])); | |
4933 | anOrigin.SetZ (0.0); | |
4934 | if (anArgIter + 3 < theArgNb) | |
4935 | { | |
4936 | anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3])); | |
4937 | anArgIter += 3; | |
4938 | } | |
4939 | else | |
4940 | { | |
4941 | anArgIter += 2; | |
4942 | } | |
4943 | aSettings.SetOrigin (anOrigin); | |
4944 | aViewer->SetZLayerSettings (aLayerId, aSettings); | |
c5751993 | 4945 | } |
4ecf34cc | 4946 | else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN |
4947 | && anArgIter + 1 < theArgNb | |
4948 | && (anArg == "-cullingdistance" | |
4949 | || anArg == "-cullingdist" | |
4950 | || anArg == "-culldistance" | |
4951 | || anArg == "-culldist" | |
4952 | || anArg == "-distcull" | |
4953 | || anArg == "-distculling" | |
4954 | || anArg == "-distanceculling")) | |
4955 | { | |
4956 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); | |
4957 | const Standard_Real aDist = Draw::Atof (theArgVec[++anArgIter]); | |
4958 | aSettings.SetCullingDistance (aDist); | |
4959 | aViewer->SetZLayerSettings (aLayerId, aSettings); | |
4960 | } | |
4961 | else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN | |
4962 | && anArgIter + 1 < theArgNb | |
4963 | && (anArg == "-cullingsize" | |
4964 | || anArg == "-cullsize" | |
4965 | || anArg == "-sizecull" | |
4966 | || anArg == "-sizeculling")) | |
4967 | { | |
4968 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); | |
4969 | const Standard_Real aSize = Draw::Atof (theArgVec[++anArgIter]); | |
4970 | aSettings.SetCullingSize (aSize); | |
4971 | aViewer->SetZLayerSettings (aLayerId, aSettings); | |
4972 | } | |
7c3ef2f7 | 4973 | else if (anArg == "-settings" |
4974 | || anArg == "settings") | |
c5751993 | 4975 | { |
7c3ef2f7 | 4976 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) |
4977 | { | |
4978 | if (++anArgIter >= theArgNb) | |
4979 | { | |
4980 | std::cout << "Syntax error: id of Z layer is missing\n"; | |
4981 | return 1; | |
4982 | } | |
4983 | ||
4984 | aLayerId = Draw::Atoi (theArgVec[anArgIter]); | |
4985 | } | |
4986 | ||
4987 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); | |
4988 | printZLayerInfo (theDI, aSettings); | |
c5751993 | 4989 | } |
7c3ef2f7 | 4990 | else if (anArg == "-enable" |
4991 | || anArg == "enable" | |
4992 | || anArg == "-disable" | |
4993 | || anArg == "disable") | |
83da37b1 | 4994 | { |
7c3ef2f7 | 4995 | const Standard_Boolean toEnable = anArg == "-enable" |
4996 | || anArg == "enable"; | |
4997 | if (++anArgIter >= theArgNb) | |
4998 | { | |
4999 | std::cout << "Syntax error: option name is missing\n"; | |
5000 | return 1; | |
5001 | } | |
c5751993 | 5002 | |
7c3ef2f7 | 5003 | TCollection_AsciiString aSubOp (theArgVec[anArgIter]); |
5004 | aSubOp.LowerCase(); | |
5005 | if (aLayerId == Graphic3d_ZLayerId_UNKNOWN) | |
5006 | { | |
5007 | if (++anArgIter >= theArgNb) | |
5008 | { | |
5009 | std::cout << "Syntax error: id of Z layer is missing\n"; | |
5010 | return 1; | |
5011 | } | |
c5751993 | 5012 | |
7c3ef2f7 | 5013 | aLayerId = Draw::Atoi (theArgVec[anArgIter]); |
5014 | } | |
c5751993 | 5015 | |
7c3ef2f7 | 5016 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId); |
5017 | if (aSubOp == "depthtest" | |
5018 | || aSubOp == "test") | |
5019 | { | |
5020 | aSettings.SetEnableDepthTest (toEnable); | |
5021 | } | |
5022 | else if (aSubOp == "depthwrite" | |
5023 | || aSubOp == "write") | |
5024 | { | |
5025 | aSettings.SetEnableDepthWrite (toEnable); | |
5026 | } | |
5027 | else if (aSubOp == "depthclear" | |
5028 | || aSubOp == "clear") | |
5029 | { | |
5030 | aSettings.SetClearDepth (toEnable); | |
5031 | } | |
5032 | else if (aSubOp == "depthoffset" | |
5033 | || aSubOp == "offset") | |
5034 | { | |
5035 | Graphic3d_PolygonOffset aParams; | |
5036 | aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None; | |
5037 | if (toEnable) | |
5038 | { | |
5039 | if (anArgIter + 2 >= theArgNb) | |
5040 | { | |
5041 | std::cout << "Syntax error: factor and units values for depth offset are missing\n"; | |
5042 | return 1; | |
5043 | } | |
c5751993 | 5044 | |
7c3ef2f7 | 5045 | aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter])); |
5046 | aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter])); | |
5047 | } | |
5048 | aSettings.SetPolygonOffset (aParams); | |
5049 | } | |
5050 | else if (aSubOp == "positiveoffset" | |
5051 | || aSubOp == "poffset") | |
5052 | { | |
5053 | if (toEnable) | |
5054 | { | |
5055 | aSettings.SetDepthOffsetPositive(); | |
5056 | } | |
5057 | else | |
5058 | { | |
5059 | aSettings.SetPolygonOffset (Graphic3d_PolygonOffset()); | |
5060 | } | |
5061 | } | |
5062 | else if (aSubOp == "negativeoffset" | |
5063 | || aSubOp == "noffset") | |
5064 | { | |
5065 | if (toEnable) | |
5066 | { | |
5067 | aSettings.SetDepthOffsetNegative(); | |
5068 | } | |
5069 | else | |
5070 | { | |
5071 | aSettings.SetPolygonOffset(Graphic3d_PolygonOffset()); | |
5072 | } | |
5073 | } | |
5074 | else if (aSubOp == "textureenv") | |
5075 | { | |
5076 | aSettings.SetEnvironmentTexture (toEnable); | |
5077 | } | |
5078 | ||
5079 | aViewer->SetZLayerSettings (aLayerId, aSettings); | |
c5751993 | 5080 | } |
7c3ef2f7 | 5081 | else |
83da37b1 | 5082 | { |
7c3ef2f7 | 5083 | std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n"; |
5084 | return 1; | |
83da37b1 | 5085 | } |
59f45b7c | 5086 | } |
5087 | ||
5088 | return 0; | |
5089 | } | |
5090 | ||
c357e426 | 5091 | // The interactive presentation of 2d layer item |
5092 | // for "vlayerline" command it provides a presentation of | |
5093 | // line with user-defined linewidth, linetype and transparency. | |
61b0191c | 5094 | class V3d_LineItem : public AIS_InteractiveObject |
20637bd2 | 5095 | { |
5096 | public: | |
5097 | // CASCADE RTTI | |
92efcf78 | 5098 | DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject) |
4fe56619 | 5099 | |
20637bd2 | 5100 | // constructor |
5101 | Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1, | |
5102 | Standard_Real X2, Standard_Real Y2, | |
20637bd2 | 5103 | Aspect_TypeOfLine theType = Aspect_TOL_SOLID, |
5104 | Standard_Real theWidth = 0.5, | |
5105 | Standard_Real theTransp = 1.0); | |
5106 | ||
61b0191c | 5107 | private: |
5108 | ||
5109 | void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, | |
5110 | const Handle(Prs3d_Presentation)& thePresentation, | |
79104795 | 5111 | const Standard_Integer theMode) Standard_OVERRIDE; |
61b0191c | 5112 | |
5113 | void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/, | |
79104795 | 5114 | const Standard_Integer /*aMode*/) Standard_OVERRIDE |
5115 | {} | |
20637bd2 | 5116 | |
5117 | private: | |
5118 | ||
5119 | Standard_Real myX1, myY1, myX2, myY2; | |
eafb234b | 5120 | Aspect_TypeOfLine myType; |
20637bd2 | 5121 | Standard_Real myWidth; |
20637bd2 | 5122 | }; |
5123 | ||
20637bd2 | 5124 | // default constructor for line item |
4fe56619 | 5125 | V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1, |
20637bd2 | 5126 | Standard_Real X2, Standard_Real Y2, |
20637bd2 | 5127 | Aspect_TypeOfLine theType, |
5128 | Standard_Real theWidth, | |
5129 | Standard_Real theTransp) : | |
61b0191c | 5130 | myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), |
5131 | myType(theType), myWidth(theWidth) | |
20637bd2 | 5132 | { |
61b0191c | 5133 | SetTransparency (1-theTransp); |
20637bd2 | 5134 | } |
5135 | ||
5136 | // render line | |
61b0191c | 5137 | void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/, |
5138 | const Handle(Prs3d_Presentation)& thePresentation, | |
5139 | const Standard_Integer /*theMode*/) | |
20637bd2 | 5140 | { |
61b0191c | 5141 | thePresentation->Clear(); |
5142 | Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB); | |
5143 | Standard_Integer aWidth, aHeight; | |
5144 | ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight); | |
5145 | Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation); | |
5146 | Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5); | |
5147 | aPrim->AddVertex(myX1, aHeight-myY1, 0.); | |
5148 | aPrim->AddVertex(myX2, aHeight-myY2, 0.); | |
5149 | Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth); | |
5150 | aGroup->SetPrimitivesAspect (anAspect->Aspect()); | |
5151 | aGroup->AddPrimitiveArray (aPrim); | |
20637bd2 | 5152 | } |
5153 | ||
5154 | //============================================================================= | |
5155 | //function : VLayerLine | |
5156 | //purpose : Draws line in the v3d view layer with given attributes: linetype, | |
5157 | // : linewidth, transparency coefficient | |
5158 | //============================================================================ | |
5159 | static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
5160 | { | |
5161 | // get the active view | |
5162 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5163 | if (aView.IsNull()) | |
5164 | { | |
5165 | di << "Call vinit before!\n"; | |
5166 | return 1; | |
5167 | } | |
5168 | else if (argc < 5) | |
5169 | { | |
5170 | di << "Use: " << argv[0]; | |
5171 | di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n"; | |
5172 | di << " linetype : { 0 | 1 | 2 | 3 } \n"; | |
5173 | di << " 0 - solid \n"; | |
5174 | di << " 1 - dashed \n"; | |
5175 | di << " 2 - dot \n"; | |
5176 | di << " 3 - dashdot\n"; | |
5177 | di << " transparency : { 0.0 - 1.0 } \n"; | |
5178 | di << " 0.0 - transparent\n"; | |
5179 | di << " 1.0 - visible \n"; | |
5180 | return 1; | |
5181 | } | |
5182 | ||
61b0191c | 5183 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
20637bd2 | 5184 | // get the input params |
91322f44 | 5185 | Standard_Real X1 = Draw::Atof(argv[1]); |
5186 | Standard_Real Y1 = Draw::Atof(argv[2]); | |
5187 | Standard_Real X2 = Draw::Atof(argv[3]); | |
5188 | Standard_Real Y2 = Draw::Atof(argv[4]); | |
20637bd2 | 5189 | |
3a4a3962 | 5190 | Standard_Real aWidth = 0.5; |
5191 | Standard_Real aTransparency = 1.0; | |
20637bd2 | 5192 | |
5193 | // has width | |
5194 | if (argc > 5) | |
91322f44 | 5195 | aWidth = Draw::Atof(argv[5]); |
20637bd2 | 5196 | |
3a4a3962 | 5197 | // select appropriate line type |
5198 | Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID; | |
5199 | if (argc > 6 | |
5200 | && !ViewerTest::ParseLineType (argv[6], aLineType)) | |
5201 | { | |
5202 | std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n"; | |
5203 | return 1; | |
5204 | } | |
20637bd2 | 5205 | |
5206 | // has transparency | |
5207 | if (argc > 7) | |
5208 | { | |
91322f44 | 5209 | aTransparency = Draw::Atof(argv[7]); |
4fe56619 | 5210 | if (aTransparency < 0 || aTransparency > 1.0) |
20637bd2 | 5211 | aTransparency = 1.0; |
5212 | } | |
5213 | ||
61b0191c | 5214 | static Handle (V3d_LineItem) aLine; |
5215 | if (!aLine.IsNull()) | |
25289ec1 | 5216 | { |
0577ae8c | 5217 | aContext->Erase (aLine, Standard_False); |
25289ec1 | 5218 | } |
61b0191c | 5219 | aLine = new V3d_LineItem (X1, Y1, X2, Y2, |
5220 | aLineType, aWidth, | |
5221 | aTransparency); | |
25289ec1 | 5222 | |
778cd667 | 5223 | aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER)); |
61b0191c | 5224 | aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD); |
5225 | aLine->SetToUpdate(); | |
5226 | aContext->Display (aLine, Standard_True); | |
25289ec1 | 5227 | |
5228 | return 0; | |
5229 | } | |
5230 | ||
61b0191c | 5231 | |
2bd4c032 | 5232 | //============================================================================== |
5233 | //function : VGrid | |
5234 | //purpose : | |
5235 | //============================================================================== | |
5236 | ||
35e08fe8 | 5237 | static int VGrid (Draw_Interpretor& /*theDI*/, |
2bd4c032 | 5238 | Standard_Integer theArgNb, |
5239 | const char** theArgVec) | |
5240 | { | |
5241 | // get the active view | |
5242 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5243 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
5244 | if (aView.IsNull() || aViewer.IsNull()) | |
5245 | { | |
5246 | std::cerr << "No active view. Please call vinit.\n"; | |
5247 | return 1; | |
5248 | } | |
5249 | ||
5250 | Aspect_GridType aType = aViewer->GridType(); | |
5251 | Aspect_GridDrawMode aMode = aViewer->GridDrawMode(); | |
224f48fa | 5252 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
2bd4c032 | 5253 | Standard_Integer anIter = 1; |
5254 | for (; anIter < theArgNb; ++anIter) | |
5255 | { | |
5256 | const char* aValue = theArgVec[anIter]; | |
224f48fa | 5257 | if (anUpdateTool.parseRedrawMode (aValue)) |
5258 | { | |
5259 | continue; | |
5260 | } | |
5261 | else if (*aValue == 'r') | |
2bd4c032 | 5262 | { |
5263 | aType = Aspect_GT_Rectangular; | |
5264 | } | |
5265 | else if (*aValue == 'c') | |
5266 | { | |
5267 | aType = Aspect_GT_Circular; | |
5268 | } | |
5269 | else if (*aValue == 'l') | |
5270 | { | |
5271 | aMode = Aspect_GDM_Lines; | |
5272 | } | |
5273 | else if (*aValue == 'p') | |
5274 | { | |
5275 | aMode = Aspect_GDM_Points; | |
5276 | } | |
5277 | else if (strcmp (aValue, "off" ) == 0) | |
5278 | { | |
5279 | aViewer->DeactivateGrid(); | |
5280 | return 0; | |
5281 | } | |
5282 | else | |
5283 | { | |
5284 | break; | |
5285 | } | |
5286 | } | |
5287 | ||
5288 | Standard_Integer aTail = (theArgNb - anIter); | |
5289 | if (aTail == 0) | |
5290 | { | |
5291 | aViewer->ActivateGrid (aType, aMode); | |
5292 | return 0; | |
5293 | } | |
5294 | else if (aTail != 2 && aTail != 5) | |
5295 | { | |
5296 | std::cerr << "Incorrect arguments number! Usage:\n" | |
5297 | << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n"; | |
5298 | return 1; | |
5299 | } | |
5300 | ||
ee2be2a8 | 5301 | Standard_Real anOriginX, anOriginY, aRotAngle; |
2bd4c032 | 5302 | if (aType == Aspect_GT_Rectangular) |
5303 | { | |
ee2be2a8 | 5304 | Standard_Real aRStepX, aRStepY; |
2bd4c032 | 5305 | aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle); |
5306 | ||
91322f44 | 5307 | anOriginX = Draw::Atof (theArgVec[anIter++]); |
5308 | anOriginY = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 5309 | if (aTail == 5) |
5310 | { | |
91322f44 | 5311 | aRStepX = Draw::Atof (theArgVec[anIter++]); |
5312 | aRStepY = Draw::Atof (theArgVec[anIter++]); | |
5313 | aRotAngle = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 5314 | } |
5315 | aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle); | |
5316 | aViewer->ActivateGrid (aType, aMode); | |
5317 | } | |
5318 | else if (aType == Aspect_GT_Circular) | |
5319 | { | |
ee2be2a8 | 5320 | Standard_Real aRadiusStep; |
2bd4c032 | 5321 | Standard_Integer aDivisionNumber; |
5322 | aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle); | |
5323 | ||
91322f44 | 5324 | anOriginX = Draw::Atof (theArgVec[anIter++]); |
5325 | anOriginY = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 5326 | if (aTail == 5) |
5327 | { | |
91322f44 | 5328 | aRadiusStep = Draw::Atof (theArgVec[anIter++]); |
5329 | aDivisionNumber = Draw::Atoi (theArgVec[anIter++]); | |
5330 | aRotAngle = Draw::Atof (theArgVec[anIter++]); | |
2bd4c032 | 5331 | } |
5332 | ||
5333 | aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle); | |
5334 | aViewer->ActivateGrid (aType, aMode); | |
5335 | } | |
5336 | ||
5337 | return 0; | |
5338 | } | |
5339 | ||
c40b7d58 | 5340 | //============================================================================== |
5341 | //function : VPriviledgedPlane | |
5342 | //purpose : | |
5343 | //============================================================================== | |
5344 | ||
5345 | static int VPriviledgedPlane (Draw_Interpretor& theDI, | |
5346 | Standard_Integer theArgNb, | |
5347 | const char** theArgVec) | |
5348 | { | |
5349 | if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10) | |
5350 | { | |
5351 | std::cerr << "Error: wrong number of arguments! See usage:\n"; | |
5352 | theDI.PrintHelp (theArgVec[0]); | |
5353 | return 1; | |
5354 | } | |
5355 | ||
5356 | // get the active viewer | |
5357 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
5358 | if (aViewer.IsNull()) | |
5359 | { | |
5360 | std::cerr << "Error: no active viewer. Please call vinit.\n"; | |
5361 | return 1; | |
5362 | } | |
5363 | ||
5364 | if (theArgNb == 1) | |
5365 | { | |
5366 | gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane(); | |
5367 | const gp_Pnt& anOrig = aPriviledgedPlane.Location(); | |
5368 | const gp_Dir& aNorm = aPriviledgedPlane.Direction(); | |
5369 | const gp_Dir& aXDir = aPriviledgedPlane.XDirection(); | |
5370 | theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " " | |
5371 | << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " " | |
5372 | << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n"; | |
5373 | return 0; | |
5374 | } | |
5375 | ||
5376 | Standard_Integer anArgIdx = 1; | |
5377 | Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]); | |
5378 | Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]); | |
5379 | Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]); | |
5380 | Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]); | |
5381 | Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]); | |
5382 | Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]); | |
5383 | ||
5384 | gp_Ax3 aPriviledgedPlane; | |
5385 | gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ); | |
5386 | gp_Dir aNorm (aNormX, aNormY, aNormZ); | |
5387 | if (theArgNb > 7) | |
5388 | { | |
5389 | Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]); | |
5390 | Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]); | |
5391 | Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]); | |
5392 | gp_Dir aXDir (aXDirX, aXDirY, aXDirZ); | |
5393 | aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir); | |
5394 | } | |
5395 | else | |
5396 | { | |
5397 | aPriviledgedPlane = gp_Ax3 (anOrig, aNorm); | |
5398 | } | |
5399 | ||
5400 | aViewer->SetPrivilegedPlane (aPriviledgedPlane); | |
5401 | ||
5402 | return 0; | |
5403 | } | |
5404 | ||
f25b82d6 | 5405 | //============================================================================== |
5406 | //function : VConvert | |
5407 | //purpose : | |
5408 | //============================================================================== | |
5409 | ||
5410 | static int VConvert (Draw_Interpretor& theDI, | |
5411 | Standard_Integer theArgNb, | |
5412 | const char** theArgVec) | |
5413 | { | |
5414 | // get the active view | |
5415 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5416 | if (aView.IsNull()) | |
5417 | { | |
c40b7d58 | 5418 | std::cerr << "Error: no active view. Please call vinit.\n"; |
f25b82d6 | 5419 | return 1; |
5420 | } | |
5421 | ||
5422 | enum { Model, Ray, View, Window, Grid } aMode = Model; | |
5423 | ||
5424 | // access coordinate arguments | |
5425 | TColStd_SequenceOfReal aCoord; | |
5426 | Standard_Integer anArgIdx = 1; | |
5427 | for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx) | |
5428 | { | |
5429 | TCollection_AsciiString anArg (theArgVec[anArgIdx]); | |
5430 | if (!anArg.IsRealValue()) | |
5431 | { | |
5432 | break; | |
5433 | } | |
5434 | aCoord.Append (anArg.RealValue()); | |
5435 | } | |
5436 | ||
5437 | // non-numeric argument too early | |
5438 | if (aCoord.IsEmpty()) | |
5439 | { | |
5440 | std::cerr << "Error: wrong number of arguments! See usage:\n"; | |
5441 | theDI.PrintHelp (theArgVec[0]); | |
5442 | return 1; | |
5443 | } | |
5444 | ||
5445 | // collect all other arguments and options | |
5446 | for (; anArgIdx < theArgNb; ++anArgIdx) | |
5447 | { | |
5448 | TCollection_AsciiString anArg (theArgVec[anArgIdx]); | |
5449 | anArg.LowerCase(); | |
5450 | if (anArg == "window") aMode = Window; | |
5451 | else if (anArg == "view") aMode = View; | |
5452 | else if (anArg == "grid") aMode = Grid; | |
5453 | else if (anArg == "ray") aMode = Ray; | |
5454 | else | |
5455 | { | |
5456 | std::cerr << "Error: wrong argument " << anArg << "! See usage:\n"; | |
5457 | theDI.PrintHelp (theArgVec[0]); | |
5458 | return 1; | |
5459 | } | |
5460 | } | |
5461 | ||
5462 | // complete input checks | |
5463 | if ((aCoord.Length() == 1 && theArgNb > 3) || | |
5464 | (aCoord.Length() == 2 && theArgNb > 4) || | |
5465 | (aCoord.Length() == 3 && theArgNb > 5)) | |
5466 | { | |
5467 | std::cerr << "Error: wrong number of arguments! See usage:\n"; | |
5468 | theDI.PrintHelp (theArgVec[0]); | |
5469 | return 1; | |
5470 | } | |
5471 | ||
5472 | Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; | |
5473 | Standard_Integer aXYp[2] = {0, 0}; | |
5474 | ||
5475 | // convert one-dimensional coordinate | |
5476 | if (aCoord.Length() == 1) | |
5477 | { | |
5478 | switch (aMode) | |
5479 | { | |
ee2be2a8 | 5480 | case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0; |
5481 | case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0; | |
f25b82d6 | 5482 | default: |
5483 | std::cerr << "Error: wrong arguments! See usage:\n"; | |
5484 | theDI.PrintHelp (theArgVec[0]); | |
5485 | return 1; | |
5486 | } | |
5487 | } | |
5488 | ||
5489 | // convert 2D coordinates from projection or view reference space | |
5490 | if (aCoord.Length() == 2) | |
5491 | { | |
5492 | switch (aMode) | |
5493 | { | |
5494 | case Model : | |
5495 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]); | |
5496 | theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n"; | |
5497 | return 0; | |
5498 | ||
5499 | case View : | |
5500 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]); | |
5501 | theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n"; | |
5502 | return 0; | |
5503 | ||
5504 | case Window : | |
ee2be2a8 | 5505 | aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]); |
f25b82d6 | 5506 | theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n"; |
5507 | return 0; | |
5508 | ||
5509 | case Grid : | |
5510 | aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]); | |
5511 | aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]); | |
5512 | theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n"; | |
5513 | return 0; | |
5514 | ||
5515 | case Ray : | |
5516 | aView->ConvertWithProj ((Standard_Integer) aCoord (1), | |
5517 | (Standard_Integer) aCoord (2), | |
5518 | aXYZ[0], aXYZ[1], aXYZ[2], | |
5519 | aXYZ[3], aXYZ[4], aXYZ[5]); | |
5520 | theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n"; | |
5521 | return 0; | |
5522 | ||
5523 | default: | |
5524 | std::cerr << "Error: wrong arguments! See usage:\n"; | |
5525 | theDI.PrintHelp (theArgVec[0]); | |
5526 | return 1; | |
5527 | } | |
5528 | } | |
5529 | ||
5530 | // convert 3D coordinates from view reference space | |
5531 | else if (aCoord.Length() == 3) | |
5532 | { | |
5533 | switch (aMode) | |
5534 | { | |
5535 | case Window : | |
5536 | aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]); | |
5537 | theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n"; | |
5538 | return 0; | |
5539 | ||
5540 | case Grid : | |
5541 | aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]); | |
5542 | theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n"; | |
5543 | return 0; | |
5544 | ||
5545 | default: | |
5546 | std::cerr << "Error: wrong arguments! See usage:\n"; | |
5547 | theDI.PrintHelp (theArgVec[0]); | |
5548 | return 1; | |
5549 | } | |
5550 | } | |
5551 | ||
5552 | return 0; | |
5553 | } | |
5554 | ||
208e6839 | 5555 | //============================================================================== |
5556 | //function : VFps | |
5557 | //purpose : | |
5558 | //============================================================================== | |
5559 | ||
5560 | static int VFps (Draw_Interpretor& theDI, | |
5561 | Standard_Integer theArgNb, | |
5562 | const char** theArgVec) | |
5563 | { | |
5564 | // get the active view | |
5565 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5566 | if (aView.IsNull()) | |
5567 | { | |
5568 | std::cerr << "No active view. Please call vinit.\n"; | |
5569 | return 1; | |
5570 | } | |
5571 | ||
e084dbbc | 5572 | Standard_Integer aFramesNb = -1; |
5573 | Standard_Real aDuration = -1.0; | |
5574 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
208e6839 | 5575 | { |
e084dbbc | 5576 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
5577 | anArg.LowerCase(); | |
5578 | if (aDuration < 0.0 | |
5579 | && anArgIter + 1 < theArgNb | |
5580 | && (anArg == "-duration" | |
5581 | || anArg == "-dur" | |
5582 | || anArg == "-time")) | |
5583 | { | |
5584 | aDuration = Draw::Atof (theArgVec[++anArgIter]); | |
5585 | } | |
5586 | else if (aFramesNb < 0 | |
5587 | && anArg.IsIntegerValue()) | |
5588 | { | |
5589 | aFramesNb = anArg.IntegerValue(); | |
5590 | if (aFramesNb <= 0) | |
5591 | { | |
5592 | std::cerr << "Syntax error at '" << anArg << "'\n"; | |
5593 | return 1; | |
5594 | } | |
5595 | } | |
5596 | else | |
5597 | { | |
5598 | std::cerr << "Syntax error at '" << anArg << "'\n"; | |
5599 | return 1; | |
5600 | } | |
5601 | } | |
5602 | if (aFramesNb < 0 && aDuration < 0.0) | |
5603 | { | |
5604 | aFramesNb = 100; | |
208e6839 | 5605 | } |
5606 | ||
5607 | // the time is meaningless for first call | |
5608 | // due to async OpenGl rendering | |
5609 | aView->Redraw(); | |
5610 | ||
5611 | // redraw view in loop to estimate average values | |
5612 | OSD_Timer aTimer; | |
5613 | aTimer.Start(); | |
e084dbbc | 5614 | Standard_Integer aFrameIter = 1; |
5615 | for (;; ++aFrameIter) | |
208e6839 | 5616 | { |
5617 | aView->Redraw(); | |
e084dbbc | 5618 | if ((aFramesNb > 0 |
5619 | && aFrameIter >= aFramesNb) | |
5620 | || (aDuration > 0.0 | |
5621 | && aTimer.ElapsedTime() >= aDuration)) | |
5622 | { | |
5623 | break; | |
5624 | } | |
208e6839 | 5625 | } |
5626 | aTimer.Stop(); | |
5627 | Standard_Real aCpu; | |
5628 | const Standard_Real aTime = aTimer.ElapsedTime(); | |
5629 | aTimer.OSD_Chronometer::Show (aCpu); | |
5630 | ||
e084dbbc | 5631 | const Standard_Real aFpsAver = Standard_Real(aFrameIter) / aTime; |
5632 | const Standard_Real aCpuAver = aCpu / Standard_Real(aFrameIter); | |
208e6839 | 5633 | |
5634 | // return statistics | |
5635 | theDI << "FPS: " << aFpsAver << "\n" | |
5636 | << "CPU: " << (1000.0 * aCpuAver) << " msec\n"; | |
5637 | ||
8c820969 | 5638 | // compute additional statistics in ray-tracing mode |
e084dbbc | 5639 | const Graphic3d_RenderingParams& aParams = aView->RenderingParams(); |
8c820969 | 5640 | if (aParams.Method == Graphic3d_RM_RAYTRACING) |
5641 | { | |
e084dbbc | 5642 | Graphic3d_Vec2i aWinSize (0, 0); |
5643 | aView->Window()->Size (aWinSize.x(), aWinSize.y()); | |
8c820969 | 5644 | |
5645 | // 1 shadow ray and 1 secondary ray pew each bounce | |
e084dbbc | 5646 | const Standard_Real aMRays = aWinSize.x() * aWinSize.y() * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f; |
8c820969 | 5647 | theDI << "MRays/sec (upper bound): " << aMRays << "\n"; |
5648 | } | |
5649 | ||
208e6839 | 5650 | return 0; |
5651 | } | |
5652 | ||
84e84755 | 5653 | //! Auxiliary function for parsing glsl dump level argument. |
5654 | static Standard_Boolean parseGlslSourceFlag (Standard_CString theArg, | |
5655 | OpenGl_ShaderProgramDumpLevel& theGlslDumpLevel) | |
5656 | { | |
5657 | TCollection_AsciiString aTypeStr (theArg); | |
5658 | aTypeStr.LowerCase(); | |
5659 | if (aTypeStr == "off" | |
5660 | || aTypeStr == "0") | |
5661 | { | |
5662 | theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off; | |
5663 | } | |
5664 | else if (aTypeStr == "short") | |
5665 | { | |
5666 | theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Short; | |
5667 | } | |
5668 | else if (aTypeStr == "full" | |
5669 | || aTypeStr == "1") | |
5670 | { | |
5671 | theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Full; | |
5672 | } | |
5673 | else | |
5674 | { | |
5675 | return Standard_False; | |
5676 | } | |
5677 | return Standard_True; | |
5678 | } | |
5679 | ||
58655684 | 5680 | //============================================================================== |
5681 | //function : VGlDebug | |
5682 | //purpose : | |
5683 | //============================================================================== | |
5684 | ||
5685 | static int VGlDebug (Draw_Interpretor& theDI, | |
5686 | Standard_Integer theArgNb, | |
5687 | const char** theArgVec) | |
5688 | { | |
aaf512f1 | 5689 | Handle(OpenGl_GraphicDriver) aDriver; |
5690 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
5691 | if (!aView.IsNull()) | |
5692 | { | |
5693 | aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver()); | |
5694 | } | |
c87535af | 5695 | OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps; |
5696 | OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL; | |
5697 | ||
58655684 | 5698 | if (theArgNb < 2) |
5699 | { | |
c87535af | 5700 | TCollection_AsciiString aDebActive, aSyncActive; |
5701 | if (aCaps == NULL) | |
58655684 | 5702 | { |
c87535af | 5703 | aCaps = aDefCaps; |
5704 | } | |
5705 | else | |
5706 | { | |
5707 | Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS), | |
5708 | "GL_ARB_debug_output"); | |
5709 | aDebActive = isActive ? " (active)" : " (inactive)"; | |
5710 | if (isActive) | |
5711 | { | |
5712 | // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB | |
5713 | aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)"; | |
5714 | } | |
58655684 | 5715 | } |
5716 | ||
84e84755 | 5717 | TCollection_AsciiString aGlslCodeDebugStatus = TCollection_AsciiString() |
5718 | + "glslSourceCode: " | |
5719 | + (aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Off | |
5720 | ? "Off" | |
5721 | : aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Short | |
5722 | ? "Short" | |
5723 | : "Full") | |
5724 | + "\n"; | |
5725 | theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n" | |
5726 | << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n" | |
5727 | << "glslWarn: " << (aCaps->glslWarnings ? "1" : "0") << "\n" | |
5728 | << aGlslCodeDebugStatus | |
5729 | << "extraMsg: " << (aCaps->suppressExtraMsg ? "0" : "1") << "\n"; | |
58655684 | 5730 | return 0; |
5731 | } | |
5732 | ||
c87535af | 5733 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
aaf512f1 | 5734 | { |
c87535af | 5735 | Standard_CString anArg = theArgVec[anArgIter]; |
5736 | TCollection_AsciiString anArgCase (anArg); | |
5737 | anArgCase.LowerCase(); | |
5738 | Standard_Boolean toEnableDebug = Standard_True; | |
5739 | if (anArgCase == "-glsl" | |
5740 | || anArgCase == "-glslwarn" | |
5741 | || anArgCase == "-glslwarns" | |
5742 | || anArgCase == "-glslwarnings") | |
5743 | { | |
5744 | Standard_Boolean toShowWarns = Standard_True; | |
5745 | if (++anArgIter < theArgNb | |
a5565a3c | 5746 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns)) |
c87535af | 5747 | { |
5748 | --anArgIter; | |
5749 | } | |
5750 | aDefCaps->glslWarnings = toShowWarns; | |
5751 | if (aCaps != NULL) | |
5752 | { | |
5753 | aCaps->glslWarnings = toShowWarns; | |
5754 | } | |
5755 | } | |
5756 | else if (anArgCase == "-extra" | |
5757 | || anArgCase == "-extramsg" | |
5758 | || anArgCase == "-extramessages") | |
5759 | { | |
5760 | Standard_Boolean toShow = Standard_True; | |
5761 | if (++anArgIter < theArgNb | |
a5565a3c | 5762 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow)) |
c87535af | 5763 | { |
5764 | --anArgIter; | |
5765 | } | |
5766 | aDefCaps->suppressExtraMsg = !toShow; | |
5767 | if (aCaps != NULL) | |
5768 | { | |
5769 | aCaps->suppressExtraMsg = !toShow; | |
5770 | } | |
5771 | } | |
5772 | else if (anArgCase == "-noextra" | |
5773 | || anArgCase == "-noextramsg" | |
5774 | || anArgCase == "-noextramessages") | |
5775 | { | |
5776 | Standard_Boolean toSuppress = Standard_True; | |
5777 | if (++anArgIter < theArgNb | |
a5565a3c | 5778 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress)) |
c87535af | 5779 | { |
5780 | --anArgIter; | |
5781 | } | |
5782 | aDefCaps->suppressExtraMsg = toSuppress; | |
5783 | if (aCaps != NULL) | |
5784 | { | |
5785 | aCaps->suppressExtraMsg = toSuppress; | |
5786 | } | |
5787 | } | |
5788 | else if (anArgCase == "-sync") | |
5789 | { | |
5790 | Standard_Boolean toSync = Standard_True; | |
5791 | if (++anArgIter < theArgNb | |
a5565a3c | 5792 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync)) |
c87535af | 5793 | { |
5794 | --anArgIter; | |
5795 | } | |
5796 | aDefCaps->contextSyncDebug = toSync; | |
5797 | if (toSync) | |
5798 | { | |
5799 | aDefCaps->contextDebug = Standard_True; | |
5800 | } | |
5801 | } | |
84e84755 | 5802 | else if (anArgCase == "-glslsourcecode" |
5803 | || anArgCase == "-glslcode") | |
5804 | { | |
5805 | OpenGl_ShaderProgramDumpLevel aGslsDumpLevel = OpenGl_ShaderProgramDumpLevel_Full; | |
5806 | if (++anArgIter < theArgNb | |
5807 | && !parseGlslSourceFlag (theArgVec[anArgIter], aGslsDumpLevel)) | |
5808 | { | |
5809 | --anArgIter; | |
5810 | } | |
5811 | aDefCaps->glslDumpLevel = aGslsDumpLevel; | |
5812 | if (aCaps != NULL) | |
5813 | { | |
5814 | aCaps->glslDumpLevel = aGslsDumpLevel; | |
5815 | } | |
5816 | } | |
c87535af | 5817 | else if (anArgCase == "-debug") |
5818 | { | |
5819 | if (++anArgIter < theArgNb | |
a5565a3c | 5820 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug)) |
c87535af | 5821 | { |
5822 | --anArgIter; | |
5823 | } | |
5824 | aDefCaps->contextDebug = toEnableDebug; | |
5825 | } | |
a5565a3c | 5826 | else if (ViewerTest::ParseOnOff (anArg, toEnableDebug) |
c87535af | 5827 | && (anArgIter + 1 == theArgNb)) |
5828 | { | |
5829 | // simple alias to turn on almost everything | |
5830 | aDefCaps->contextDebug = toEnableDebug; | |
5831 | aDefCaps->contextSyncDebug = toEnableDebug; | |
5832 | aDefCaps->glslWarnings = toEnableDebug; | |
3b4c6945 | 5833 | if (!toEnableDebug) |
5834 | { | |
5835 | aDefCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off; | |
5836 | } | |
84e84755 | 5837 | aDefCaps->suppressExtraMsg = !toEnableDebug; |
5838 | if (aCaps != NULL) | |
5839 | { | |
5840 | aCaps->contextDebug = toEnableDebug; | |
5841 | aCaps->contextSyncDebug = toEnableDebug; | |
5842 | aCaps->glslWarnings = toEnableDebug; | |
3b4c6945 | 5843 | if (!toEnableDebug) |
5844 | { | |
5845 | aCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off; | |
5846 | } | |
84e84755 | 5847 | aCaps->suppressExtraMsg = !toEnableDebug; |
5848 | } | |
c87535af | 5849 | } |
5850 | else | |
5851 | { | |
5852 | std::cout << "Error: wrong syntax at '" << anArg << "'\n"; | |
5853 | return 1; | |
5854 | } | |
aaf512f1 | 5855 | } |
5856 | ||
58655684 | 5857 | return 0; |
5858 | } | |
208e6839 | 5859 | |
5860 | //============================================================================== | |
5861 | //function : VVbo | |
5862 | //purpose : | |
5863 | //============================================================================== | |
5864 | ||
58655684 | 5865 | static int VVbo (Draw_Interpretor& theDI, |
208e6839 | 5866 | Standard_Integer theArgNb, |
5867 | const char** theArgVec) | |
5868 | { | |
58655684 | 5869 | const Standard_Boolean toSet = (theArgNb > 1); |
5870 | const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1; | |
5871 | if (toSet) | |
208e6839 | 5872 | { |
58655684 | 5873 | ViewerTest_myDefaultCaps.vboDisable = toUseVbo; |
208e6839 | 5874 | } |
5875 | ||
58655684 | 5876 | // get the context |
5877 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
5878 | if (aContextAIS.IsNull()) | |
208e6839 | 5879 | { |
58655684 | 5880 | if (!toSet) |
5881 | { | |
5882 | std::cerr << "No active view!\n"; | |
5883 | } | |
208e6839 | 5884 | return 1; |
5885 | } | |
58655684 | 5886 | Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver()); |
5887 | if (!aDriver.IsNull()) | |
208e6839 | 5888 | { |
58655684 | 5889 | if (!toSet) |
5890 | { | |
5891 | theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n"; | |
5892 | } | |
5893 | else | |
5894 | { | |
5895 | aDriver->ChangeOptions().vboDisable = toUseVbo; | |
5896 | } | |
208e6839 | 5897 | } |
5898 | ||
208e6839 | 5899 | return 0; |
5900 | } | |
5901 | ||
a577aaab | 5902 | //============================================================================== |
5903 | //function : VCaps | |
5904 | //purpose : | |
5905 | //============================================================================== | |
5906 | ||
5907 | static int VCaps (Draw_Interpretor& theDI, | |
5908 | Standard_Integer theArgNb, | |
5909 | const char** theArgVec) | |
5910 | { | |
5911 | OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps; | |
5912 | Handle(OpenGl_GraphicDriver) aDriver; | |
8625ef7e | 5913 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
5914 | if (!aContext.IsNull()) | |
a577aaab | 5915 | { |
8625ef7e | 5916 | aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver()); |
a577aaab | 5917 | aCaps = &aDriver->ChangeOptions(); |
5918 | } | |
5919 | ||
5920 | if (theArgNb < 2) | |
5921 | { | |
5922 | theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n"; | |
5923 | theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n"; | |
abe46077 | 5924 | theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n"; |
8625ef7e | 5925 | theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n"; |
2a332745 | 5926 | theDI << "PolygonMode: " << (aCaps->usePolygonMode ? "1" : "0") << "\n"; |
f978241f | 5927 | theDI << "VSync: " << aCaps->swapInterval << "\n"; |
4e1523ef | 5928 | theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n"; |
f978241f | 5929 | theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n"; |
56689b27 | 5930 | theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n"; |
a577aaab | 5931 | return 0; |
5932 | } | |
5933 | ||
8625ef7e | 5934 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); |
a577aaab | 5935 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
5936 | { | |
8625ef7e | 5937 | Standard_CString anArg = theArgVec[anArgIter]; |
5938 | TCollection_AsciiString anArgCase (anArg); | |
5939 | anArgCase.LowerCase(); | |
5940 | if (anUpdateTool.parseRedrawMode (anArg)) | |
5941 | { | |
5942 | continue; | |
5943 | } | |
f978241f | 5944 | else if (anArgCase == "-vsync" |
5945 | || anArgCase == "-swapinterval") | |
5946 | { | |
5947 | Standard_Boolean toEnable = Standard_True; | |
5948 | if (++anArgIter < theArgNb | |
a5565a3c | 5949 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
f978241f | 5950 | { |
5951 | --anArgIter; | |
5952 | } | |
5953 | aCaps->swapInterval = toEnable; | |
5954 | } | |
8625ef7e | 5955 | else if (anArgCase == "-ffp") |
5956 | { | |
5957 | Standard_Boolean toEnable = Standard_True; | |
5958 | if (++anArgIter < theArgNb | |
a5565a3c | 5959 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 5960 | { |
5961 | --anArgIter; | |
5962 | } | |
5963 | aCaps->ffpEnable = toEnable; | |
5964 | } | |
2a332745 | 5965 | else if (anArgCase == "-polygonmode") |
5966 | { | |
5967 | Standard_Boolean toEnable = Standard_True; | |
5968 | if (++anArgIter < theArgNb | |
5969 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
5970 | { | |
5971 | --anArgIter; | |
5972 | } | |
5973 | aCaps->usePolygonMode = toEnable; | |
5974 | } | |
8625ef7e | 5975 | else if (anArgCase == "-vbo") |
a577aaab | 5976 | { |
8625ef7e | 5977 | Standard_Boolean toEnable = Standard_True; |
5978 | if (++anArgIter < theArgNb | |
a5565a3c | 5979 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 5980 | { |
5981 | --anArgIter; | |
5982 | } | |
5983 | aCaps->vboDisable = !toEnable; | |
a577aaab | 5984 | } |
8625ef7e | 5985 | else if (anArgCase == "-sprite" |
5986 | || anArgCase == "-sprites") | |
a577aaab | 5987 | { |
8625ef7e | 5988 | Standard_Boolean toEnable = Standard_True; |
5989 | if (++anArgIter < theArgNb | |
a5565a3c | 5990 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 5991 | { |
5992 | --anArgIter; | |
5993 | } | |
5994 | aCaps->pntSpritesDisable = !toEnable; | |
a577aaab | 5995 | } |
8625ef7e | 5996 | else if (anArgCase == "-softmode") |
abe46077 | 5997 | { |
8625ef7e | 5998 | Standard_Boolean toEnable = Standard_True; |
5999 | if (++anArgIter < theArgNb | |
a5565a3c | 6000 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 6001 | { |
6002 | --anArgIter; | |
6003 | } | |
6004 | aCaps->contextNoAccel = toEnable; | |
6005 | } | |
56689b27 | 6006 | else if (anArgCase == "-winbuffer" |
6007 | || anArgCase == "-windowbuffer" | |
6008 | || anArgCase == "-usewinbuffer" | |
6009 | || anArgCase == "-usewindowbuffer" | |
6010 | || anArgCase == "-usesystembuffer") | |
6011 | { | |
6012 | Standard_Boolean toEnable = Standard_True; | |
6013 | if (++anArgIter < theArgNb | |
6014 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
6015 | { | |
6016 | --anArgIter; | |
6017 | } | |
6018 | aCaps->useSystemBuffer = toEnable; | |
6019 | } | |
8625ef7e | 6020 | else if (anArgCase == "-accel" |
6021 | || anArgCase == "-acceleration") | |
6022 | { | |
6023 | Standard_Boolean toEnable = Standard_True; | |
6024 | if (++anArgIter < theArgNb | |
a5565a3c | 6025 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8625ef7e | 6026 | { |
6027 | --anArgIter; | |
6028 | } | |
6029 | aCaps->contextNoAccel = !toEnable; | |
abe46077 | 6030 | } |
4e1523ef | 6031 | else if (anArgCase == "-compat" |
6032 | || anArgCase == "-compatprofile" | |
6033 | || anArgCase == "-compatible" | |
6034 | || anArgCase == "-compatibleprofile") | |
6035 | { | |
6036 | Standard_Boolean toEnable = Standard_True; | |
6037 | if (++anArgIter < theArgNb | |
a5565a3c | 6038 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
4e1523ef | 6039 | { |
6040 | --anArgIter; | |
6041 | } | |
6042 | aCaps->contextCompatible = toEnable; | |
6043 | if (!aCaps->contextCompatible) | |
6044 | { | |
6045 | aCaps->ffpEnable = Standard_False; | |
6046 | } | |
6047 | } | |
6048 | else if (anArgCase == "-core" | |
6049 | || anArgCase == "-coreprofile") | |
6050 | { | |
6051 | Standard_Boolean toEnable = Standard_True; | |
6052 | if (++anArgIter < theArgNb | |
a5565a3c | 6053 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
4e1523ef | 6054 | { |
6055 | --anArgIter; | |
6056 | } | |
6057 | aCaps->contextCompatible = !toEnable; | |
6058 | if (!aCaps->contextCompatible) | |
6059 | { | |
6060 | aCaps->ffpEnable = Standard_False; | |
6061 | } | |
6062 | } | |
f978241f | 6063 | else if (anArgCase == "-stereo" |
6064 | || anArgCase == "-quadbuffer") | |
6065 | { | |
6066 | Standard_Boolean toEnable = Standard_True; | |
6067 | if (++anArgIter < theArgNb | |
a5565a3c | 6068 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
f978241f | 6069 | { |
6070 | --anArgIter; | |
6071 | } | |
6072 | aCaps->contextStereo = toEnable; | |
6073 | } | |
a577aaab | 6074 | else |
6075 | { | |
8625ef7e | 6076 | std::cout << "Error: unknown argument '" << anArg << "'\n"; |
6077 | return 1; | |
a577aaab | 6078 | } |
6079 | } | |
6080 | if (aCaps != &ViewerTest_myDefaultCaps) | |
6081 | { | |
6082 | ViewerTest_myDefaultCaps = *aCaps; | |
6083 | } | |
6084 | return 0; | |
6085 | } | |
6086 | ||
f0430952 | 6087 | //============================================================================== |
6088 | //function : VMemGpu | |
6089 | //purpose : | |
6090 | //============================================================================== | |
6091 | ||
6092 | static int VMemGpu (Draw_Interpretor& theDI, | |
6093 | Standard_Integer theArgNb, | |
6094 | const char** theArgVec) | |
6095 | { | |
6096 | // get the context | |
6097 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
6098 | if (aContextAIS.IsNull()) | |
6099 | { | |
6100 | std::cerr << "No active view. Please call vinit.\n"; | |
6101 | return 1; | |
6102 | } | |
6103 | ||
dc3fe572 | 6104 | Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver(); |
f0430952 | 6105 | if (aDriver.IsNull()) |
6106 | { | |
6107 | std::cerr << "Graphic driver not available.\n"; | |
6108 | return 1; | |
6109 | } | |
6110 | ||
6111 | Standard_Size aFreeBytes = 0; | |
6112 | TCollection_AsciiString anInfo; | |
6113 | if (!aDriver->MemoryInfo (aFreeBytes, anInfo)) | |
6114 | { | |
6115 | std::cerr << "Information not available.\n"; | |
6116 | return 1; | |
6117 | } | |
6118 | ||
6119 | if (theArgNb > 1 && *theArgVec[1] == 'f') | |
6120 | { | |
6121 | theDI << Standard_Real (aFreeBytes); | |
6122 | } | |
6123 | else | |
6124 | { | |
6125 | theDI << anInfo; | |
6126 | } | |
6127 | ||
6128 | return 0; | |
6129 | } | |
6130 | ||
85e096c3 | 6131 | // ============================================================================== |
6132 | // function : VReadPixel | |
6133 | // purpose : | |
6134 | // ============================================================================== | |
6135 | static int VReadPixel (Draw_Interpretor& theDI, | |
6136 | Standard_Integer theArgNb, | |
6137 | const char** theArgVec) | |
6138 | { | |
6139 | // get the active view | |
6140 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6141 | if (aView.IsNull()) | |
6142 | { | |
6143 | std::cerr << "No active view. Please call vinit.\n"; | |
6144 | return 1; | |
6145 | } | |
6146 | else if (theArgNb < 3) | |
6147 | { | |
6148 | std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n"; | |
6149 | return 1; | |
6150 | } | |
6151 | ||
dc858f4c | 6152 | Image_Format aFormat = Image_Format_RGBA; |
6153 | Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA; | |
692613e5 | 6154 | |
85e096c3 | 6155 | Standard_Integer aWidth, aHeight; |
6156 | aView->Window()->Size (aWidth, aHeight); | |
91322f44 | 6157 | const Standard_Integer anX = Draw::Atoi (theArgVec[1]); |
6158 | const Standard_Integer anY = Draw::Atoi (theArgVec[2]); | |
85e096c3 | 6159 | if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight) |
6160 | { | |
6161 | std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n"; | |
6162 | return 1; | |
6163 | } | |
6164 | ||
6165 | Standard_Boolean toShowName = Standard_False; | |
6166 | Standard_Boolean toShowHls = Standard_False; | |
6167 | for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter) | |
6168 | { | |
dc858f4c | 6169 | TCollection_AsciiString aParam (theArgVec[anIter]); |
6170 | aParam.LowerCase(); | |
6171 | if (aParam == "rgb") | |
85e096c3 | 6172 | { |
dc858f4c | 6173 | aFormat = Image_Format_RGB; |
692613e5 | 6174 | aBufferType = Graphic3d_BT_RGB; |
85e096c3 | 6175 | } |
dc858f4c | 6176 | else if (aParam == "hls") |
85e096c3 | 6177 | { |
dc858f4c | 6178 | aFormat = Image_Format_RGB; |
692613e5 | 6179 | aBufferType = Graphic3d_BT_RGB; |
85e096c3 | 6180 | toShowHls = Standard_True; |
6181 | } | |
dc858f4c | 6182 | else if (aParam == "rgbf") |
85e096c3 | 6183 | { |
dc858f4c | 6184 | aFormat = Image_Format_RGBF; |
692613e5 | 6185 | aBufferType = Graphic3d_BT_RGB; |
85e096c3 | 6186 | } |
dc858f4c | 6187 | else if (aParam == "rgba") |
85e096c3 | 6188 | { |
dc858f4c | 6189 | aFormat = Image_Format_RGBA; |
692613e5 | 6190 | aBufferType = Graphic3d_BT_RGBA; |
85e096c3 | 6191 | } |
dc858f4c | 6192 | else if (aParam == "rgbaf") |
85e096c3 | 6193 | { |
dc858f4c | 6194 | aFormat = Image_Format_RGBAF; |
692613e5 | 6195 | aBufferType = Graphic3d_BT_RGBA; |
85e096c3 | 6196 | } |
dc858f4c | 6197 | else if (aParam == "depth") |
85e096c3 | 6198 | { |
dc858f4c | 6199 | aFormat = Image_Format_GrayF; |
692613e5 | 6200 | aBufferType = Graphic3d_BT_Depth; |
85e096c3 | 6201 | } |
dc858f4c | 6202 | else if (aParam == "name") |
85e096c3 | 6203 | { |
6204 | toShowName = Standard_True; | |
6205 | } | |
6206 | } | |
6207 | ||
692613e5 | 6208 | Image_PixMap anImage; |
6209 | if (!anImage.InitTrash (aFormat, aWidth, aHeight)) | |
6210 | { | |
6211 | std::cerr << "Image allocation failed\n"; | |
6212 | return 1; | |
6213 | } | |
6214 | else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType)) | |
85e096c3 | 6215 | { |
6216 | std::cerr << "Image dump failed\n"; | |
6217 | return 1; | |
6218 | } | |
6219 | ||
68beaa3c | 6220 | // redirect possible warning messages that could have been added by ToPixMap |
6221 | // into the Tcl interpretor (via DefaultMessenger) to cout, so that they do not | |
6222 | // contaminate result of the command | |
6223 | Standard_CString aWarnLog = theDI.Result(); | |
6224 | if (aWarnLog != NULL && aWarnLog[0] != '\0') | |
6225 | { | |
6226 | std::cout << aWarnLog << std::endl; | |
6227 | } | |
6228 | theDI.Reset(); | |
6229 | ||
e958a649 | 6230 | Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY); |
85e096c3 | 6231 | if (toShowName) |
6232 | { | |
692613e5 | 6233 | if (aBufferType == Graphic3d_BT_RGBA) |
85e096c3 | 6234 | { |
e958a649 | 6235 | theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha(); |
85e096c3 | 6236 | } |
6237 | else | |
6238 | { | |
e958a649 | 6239 | theDI << Quantity_Color::StringName (aColor.GetRGB().Name()); |
85e096c3 | 6240 | } |
6241 | } | |
6242 | else | |
6243 | { | |
6244 | switch (aBufferType) | |
6245 | { | |
6246 | default: | |
692613e5 | 6247 | case Graphic3d_BT_RGB: |
85e096c3 | 6248 | { |
6249 | if (toShowHls) | |
6250 | { | |
e958a649 | 6251 | theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation(); |
85e096c3 | 6252 | } |
6253 | else | |
6254 | { | |
e958a649 | 6255 | theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue(); |
85e096c3 | 6256 | } |
6257 | break; | |
6258 | } | |
692613e5 | 6259 | case Graphic3d_BT_RGBA: |
85e096c3 | 6260 | { |
e958a649 | 6261 | theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue() << " " << aColor.Alpha(); |
85e096c3 | 6262 | break; |
6263 | } | |
692613e5 | 6264 | case Graphic3d_BT_Depth: |
85e096c3 | 6265 | { |
e958a649 | 6266 | theDI << aColor.GetRGB().Red(); |
85e096c3 | 6267 | break; |
6268 | } | |
6269 | } | |
6270 | } | |
6271 | ||
6272 | return 0; | |
6273 | } | |
6274 | ||
fd3f6bd0 | 6275 | //! Auxiliary presentation for an image plane. |
6276 | class ViewerTest_ImagePrs : public AIS_InteractiveObject | |
6277 | { | |
6278 | public: | |
6279 | //! Main constructor. | |
6280 | ViewerTest_ImagePrs (const Handle(Image_PixMap)& theImage, | |
6281 | const Standard_Real theWidth, | |
6282 | const Standard_Real theHeight, | |
6283 | const TCollection_AsciiString& theLabel) | |
6284 | : myLabel (theLabel), myWidth (theWidth), myHeight(theHeight) | |
6285 | { | |
6286 | SetDisplayMode (0); | |
6287 | SetHilightMode (1); | |
6288 | myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost); | |
6289 | { | |
6290 | myDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); | |
6291 | const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect(); | |
6292 | Graphic3d_MaterialAspect aMat; | |
6293 | aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC); | |
6294 | aMat.SetAmbient (1.0); | |
6295 | aMat.SetDiffuse (1.0); | |
6296 | aMat.SetSpecular (1.0); | |
6297 | aMat.SetEmissive (1.0); | |
6298 | aMat.SetReflectionModeOn (Graphic3d_TOR_AMBIENT); | |
6299 | aMat.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE); | |
6300 | aMat.SetReflectionModeOn (Graphic3d_TOR_SPECULAR); | |
6301 | aMat.SetReflectionModeOn (Graphic3d_TOR_EMISSION); | |
6302 | aMat.SetAmbientColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB)); | |
6303 | aMat.SetDiffuseColor (Quantity_Color (1.0, 1.0, 1.0, Quantity_TOC_RGB)); | |
6304 | aMat.SetSpecularColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB)); | |
6305 | aMat.SetEmissiveColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB)); | |
6306 | aFillAspect->SetFrontMaterial (aMat); | |
6307 | aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage)); | |
6308 | aFillAspect->SetTextureMapOn(); | |
6309 | } | |
6310 | { | |
6311 | Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect(); | |
6312 | aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER); | |
6313 | aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER); | |
6314 | myDrawer->SetTextAspect (aTextAspect); | |
6315 | } | |
6316 | { | |
6317 | const gp_Dir aNorm (0.0, 0.0, 1.0); | |
6318 | myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true); | |
6319 | myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0)); | |
6320 | myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0)); | |
6321 | myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0)); | |
6322 | myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0)); | |
6323 | myTris->AddEdge (1); | |
6324 | myTris->AddEdge (2); | |
6325 | myTris->AddEdge (3); | |
6326 | myTris->AddEdge (3); | |
6327 | myTris->AddEdge (2); | |
6328 | myTris->AddEdge (4); | |
6329 | ||
6330 | myRect = new Graphic3d_ArrayOfPolylines (4); | |
6331 | myRect->AddVertex (myTris->Vertice (1)); | |
6332 | myRect->AddVertex (myTris->Vertice (3)); | |
6333 | myRect->AddVertex (myTris->Vertice (4)); | |
6334 | myRect->AddVertex (myTris->Vertice (2)); | |
6335 | } | |
6336 | } | |
6337 | ||
6338 | //! Returns TRUE for accepted display modes. | |
6339 | virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; } | |
6340 | ||
6341 | //! Compute presentation. | |
6342 | virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& , const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) Standard_OVERRIDE | |
6343 | { | |
6344 | switch (theMode) | |
6345 | { | |
6346 | case 0: | |
6347 | { | |
6348 | Handle(Graphic3d_Group) aGroup = thePrs->NewGroup(); | |
6349 | aGroup->AddPrimitiveArray (myTris); | |
6350 | aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect()); | |
6351 | aGroup->AddPrimitiveArray (myRect); | |
6352 | aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect()); | |
6353 | return; | |
6354 | } | |
6355 | case 1: | |
6356 | { | |
6357 | Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0)); | |
6358 | Handle(Graphic3d_Group) aGroup = thePrs->NewGroup(); | |
6359 | aGroup->AddPrimitiveArray (myRect); | |
6360 | aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect()); | |
6361 | return; | |
6362 | } | |
6363 | } | |
6364 | } | |
6365 | ||
6366 | //! Compute selection. | |
6367 | virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE | |
6368 | { | |
6369 | if (theMode == 0) | |
6370 | { | |
6371 | Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5); | |
6372 | Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner); | |
6373 | aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location()); | |
6374 | theSel->Add (aSensitive); | |
6375 | } | |
6376 | } | |
6377 | ||
6378 | private: | |
6379 | Handle(Graphic3d_ArrayOfTriangles) myTris; | |
6380 | Handle(Graphic3d_ArrayOfPolylines) myRect; | |
6381 | TCollection_AsciiString myLabel; | |
6382 | Standard_Real myWidth; | |
6383 | Standard_Real myHeight; | |
6384 | }; | |
6385 | ||
692613e5 | 6386 | //============================================================================== |
6387 | //function : VDiffImage | |
6388 | //purpose : The draw-command compares two images. | |
6389 | //============================================================================== | |
6390 | ||
6391 | static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) | |
6392 | { | |
fd3f6bd0 | 6393 | if (theArgNb < 3) |
692613e5 | 6394 | { |
fd3f6bd0 | 6395 | std::cout << "Syntax error: not enough arguments.\n"; |
692613e5 | 6396 | return 1; |
6397 | } | |
6398 | ||
fd3f6bd0 | 6399 | Standard_Integer anArgIter = 1; |
6400 | TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]); | |
6401 | TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]); | |
6402 | TCollection_AsciiString aDiffImagePath; | |
6403 | Standard_Real aTolColor = -1.0; | |
6404 | Standard_Integer toBlackWhite = -1; | |
6405 | Standard_Integer isBorderFilterOn = -1; | |
6406 | Standard_Boolean isOldSyntax = Standard_False; | |
6407 | TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff; | |
6408 | for (; anArgIter < theArgNb; ++anArgIter) | |
6409 | { | |
6410 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
6411 | anArg.LowerCase(); | |
6412 | if (anArgIter + 1 < theArgNb | |
6413 | && (anArg == "-toleranceofcolor" | |
6414 | || anArg == "-tolerancecolor" | |
6415 | || anArg == "-tolerance" | |
6416 | || anArg == "-toler")) | |
6417 | { | |
6418 | aTolColor = Atof (theArgVec[++anArgIter]); | |
6419 | if (aTolColor < 0.0 || aTolColor > 1.0) | |
6420 | { | |
6421 | std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n"; | |
6422 | return 1; | |
6423 | } | |
6424 | } | |
6425 | else if (anArg == "-blackwhite") | |
6426 | { | |
6427 | Standard_Boolean toEnable = Standard_True; | |
6428 | if (anArgIter + 1 < theArgNb | |
6429 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
6430 | { | |
6431 | ++anArgIter; | |
6432 | } | |
6433 | toBlackWhite = toEnable ? 1 : 0; | |
6434 | } | |
6435 | else if (anArg == "-borderfilter") | |
6436 | { | |
6437 | Standard_Boolean toEnable = Standard_True; | |
6438 | if (anArgIter + 1 < theArgNb | |
6439 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
6440 | { | |
6441 | ++anArgIter; | |
6442 | } | |
6443 | isBorderFilterOn = toEnable ? 1 : 0; | |
6444 | } | |
6445 | else if (anArg == "-exitonclose") | |
6446 | { | |
6447 | Draw_ToExitOnCloseView = true; | |
6448 | if (anArgIter + 1 < theArgNb | |
6449 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToExitOnCloseView)) | |
6450 | { | |
6451 | ++anArgIter; | |
6452 | } | |
6453 | } | |
6454 | else if (anArg == "-closeonescape" | |
6455 | || anArg == "-closeonesc") | |
6456 | { | |
6457 | Draw_ToCloseViewOnEsc = true; | |
6458 | if (anArgIter + 1 < theArgNb | |
6459 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToCloseViewOnEsc)) | |
6460 | { | |
6461 | ++anArgIter; | |
6462 | } | |
6463 | } | |
6464 | else if (anArgIter + 3 < theArgNb | |
6465 | && anArg == "-display") | |
6466 | { | |
6467 | aViewName = theArgVec[++anArgIter]; | |
6468 | aPrsNameRef = theArgVec[++anArgIter]; | |
6469 | aPrsNameNew = theArgVec[++anArgIter]; | |
6470 | if (anArgIter + 1 < theArgNb | |
6471 | && *theArgVec[anArgIter + 1] != '-') | |
6472 | { | |
6473 | aPrsNameDiff = theArgVec[++anArgIter]; | |
6474 | } | |
6475 | } | |
6476 | else if (aTolColor < 0.0 | |
6477 | && anArg.IsRealValue()) | |
6478 | { | |
6479 | isOldSyntax = Standard_True; | |
6480 | aTolColor = anArg.RealValue(); | |
6481 | if (aTolColor < 0.0 || aTolColor > 1.0) | |
6482 | { | |
6483 | std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n"; | |
6484 | return 1; | |
6485 | } | |
6486 | } | |
6487 | else if (isOldSyntax | |
6488 | && toBlackWhite == -1 | |
6489 | && (anArg == "0" || anArg == "1")) | |
6490 | { | |
6491 | toBlackWhite = anArg == "1" ? 1 : 0; | |
6492 | } | |
6493 | else if (isOldSyntax | |
6494 | && isBorderFilterOn == -1 | |
6495 | && (anArg == "0" || anArg == "1")) | |
6496 | { | |
6497 | isBorderFilterOn = anArg == "1" ? 1 : 0; | |
6498 | } | |
6499 | else if (aDiffImagePath.IsEmpty()) | |
6500 | { | |
6501 | aDiffImagePath = theArgVec[anArgIter]; | |
6502 | } | |
6503 | else | |
6504 | { | |
6505 | std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n"; | |
6506 | return 1; | |
6507 | } | |
6508 | } | |
692613e5 | 6509 | |
fd3f6bd0 | 6510 | Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap(); |
6511 | Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap(); | |
6512 | if (!anImgRef->Load (anImgPathRef)) | |
6513 | { | |
6514 | std::cout << "Error: image file '" << anImgPathRef << "' cannot be read\n"; | |
6515 | return 1; | |
6516 | } | |
6517 | if (!anImgNew->Load (anImgPathNew)) | |
6518 | { | |
6519 | std::cout << "Error: image file '" << anImgPathNew << "' cannot be read\n"; | |
6520 | return 1; | |
6521 | } | |
692613e5 | 6522 | |
6523 | // compare the images | |
6524 | Image_Diff aComparer; | |
fd3f6bd0 | 6525 | Standard_Integer aDiffColorsNb = -1; |
6526 | if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1)) | |
692613e5 | 6527 | { |
fd3f6bd0 | 6528 | aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0); |
6529 | aComparer.SetBorderFilterOn (isBorderFilterOn == 1); | |
6530 | aDiffColorsNb = aComparer.Compare(); | |
6531 | theDI << aDiffColorsNb << "\n"; | |
692613e5 | 6532 | } |
6533 | ||
692613e5 | 6534 | // save image of difference |
fd3f6bd0 | 6535 | Handle(Image_AlienPixMap) aDiff; |
6536 | if (aDiffColorsNb > 0 | |
6537 | && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty())) | |
6538 | { | |
6539 | aDiff = new Image_AlienPixMap(); | |
6540 | if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY())) | |
6541 | { | |
6542 | std::cout << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY() << "\n"; | |
6543 | return 1; | |
6544 | } | |
6545 | aComparer.SaveDiffImage (*aDiff); | |
6546 | if (!aDiffImagePath.IsEmpty() | |
6547 | && !aDiff->Save (aDiffImagePath)) | |
6548 | { | |
6549 | std::cout << "Error: diff image file '" << aDiffImagePath << "' cannot be written\n"; | |
6550 | return 1; | |
6551 | } | |
6552 | } | |
6553 | ||
6554 | if (aViewName.IsEmpty()) | |
6555 | { | |
6556 | return 0; | |
6557 | } | |
6558 | ||
6559 | ViewerTest_Names aViewNames (aViewName); | |
6560 | if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName())) | |
6561 | { | |
6562 | TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName(); | |
6563 | theDI.Eval (aCommand.ToCString()); | |
6564 | } | |
6565 | ||
6566 | Standard_Integer aPxLeft = 0; | |
6567 | Standard_Integer aPxTop = 0; | |
6568 | Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2); | |
6569 | Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty() | |
6570 | ? int(anImgRef->SizeY() * 2) | |
6571 | : int(anImgRef->SizeY()); | |
6572 | TCollection_AsciiString aDisplayName; | |
9e04ccdc | 6573 | TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aWinSizeX, aWinSizeY, |
6574 | aViewName, aDisplayName); | |
fd3f6bd0 | 6575 | |
6576 | Standard_Real aRatio = anImgRef->Ratio(); | |
6577 | Standard_Real aSizeX = 1.0; | |
6578 | Standard_Real aSizeY = aSizeX / aRatio; | |
692613e5 | 6579 | { |
fd3f6bd0 | 6580 | OSD_Path aPath (anImgPathRef); |
6581 | TCollection_AsciiString aLabelRef; | |
6582 | if (!aPath.Name().IsEmpty()) | |
6583 | { | |
6584 | aLabelRef = aPath.Name() + aPath.Extension(); | |
6585 | } | |
6586 | aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY()); | |
6587 | ||
6588 | Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef); | |
6589 | gp_Trsf aTrsfRef; | |
6590 | aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0)); | |
6591 | anImgRefPrs->SetLocalTransformation (aTrsfRef); | |
6592 | ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true); | |
692613e5 | 6593 | } |
fd3f6bd0 | 6594 | { |
6595 | OSD_Path aPath (anImgPathNew); | |
6596 | TCollection_AsciiString aLabelNew; | |
6597 | if (!aPath.Name().IsEmpty()) | |
6598 | { | |
6599 | aLabelNew = aPath.Name() + aPath.Extension(); | |
6600 | } | |
6601 | aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY()); | |
692613e5 | 6602 | |
fd3f6bd0 | 6603 | Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew); |
6604 | gp_Trsf aTrsfRef; | |
6605 | aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0)); | |
6606 | anImgNewPrs->SetLocalTransformation (aTrsfRef); | |
6607 | ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true); | |
6608 | } | |
6609 | Handle(ViewerTest_ImagePrs) anImgDiffPrs; | |
6610 | if (!aDiff.IsNull()) | |
6611 | { | |
6612 | anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels"); | |
6613 | gp_Trsf aTrsfDiff; | |
6614 | aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0)); | |
6615 | anImgDiffPrs->SetLocalTransformation (aTrsfDiff); | |
6616 | } | |
6617 | if (!aPrsNameDiff.IsEmpty()) | |
6618 | { | |
6619 | ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true); | |
6620 | } | |
6621 | ViewerTest::CurrentView()->SetProj (V3d_Zpos); | |
6622 | ViewerTest::CurrentView()->FitAll(); | |
692613e5 | 6623 | return 0; |
6624 | } | |
6625 | ||
4754e164 | 6626 | //======================================================================= |
6627 | //function : VSelect | |
6628 | //purpose : Emulates different types of selection by mouse: | |
6629 | // 1) single click selection | |
6630 | // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2) | |
6631 | // 3) selection with polygon having corners at | |
dc3fe572 | 6632 | // pixel positions (x1,y1),...,(xn,yn) |
4754e164 | 6633 | // 4) any of these selections with shift button pressed |
6634 | //======================================================================= | |
6635 | static Standard_Integer VSelect (Draw_Interpretor& di, | |
6636 | Standard_Integer argc, | |
6637 | const char ** argv) | |
6638 | { | |
dc3fe572 | 6639 | if(argc < 3) |
4754e164 | 6640 | { |
586db386 | 6641 | di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]\n"; |
4754e164 | 6642 | return 1; |
6643 | } | |
6644 | ||
6645 | Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext(); | |
dc3fe572 | 6646 | if(myAIScontext.IsNull()) |
4754e164 | 6647 | { |
6648 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
6649 | return 1; | |
6650 | } | |
2157d6ac | 6651 | |
6652 | const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1)); | |
6653 | Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1; | |
6654 | TCollection_AsciiString anArg; | |
6655 | anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2]; | |
6656 | anArg.LowerCase(); | |
6657 | if (anArg == "-allowoverlap") | |
6658 | { | |
6659 | Standard_Boolean isValidated = isShiftSelection ? argc == 8 | |
6660 | : argc == 7; | |
6661 | if (!isValidated) | |
6662 | { | |
6663 | di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection"; | |
6664 | return 1; | |
6665 | } | |
6666 | ||
6667 | Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]); | |
dde68833 | 6668 | myAIScontext->MainSelector()->AllowOverlapDetection (isToAllow != 0); |
2157d6ac | 6669 | aCoordsNb -= 2; |
6670 | } | |
6671 | ||
4754e164 | 6672 | Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager(); |
6673 | aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2])); | |
2157d6ac | 6674 | if(aCoordsNb == 2) |
4754e164 | 6675 | { |
6676 | if(isShiftSelection) | |
6677 | aCurrentEventManager->ShiftSelect(); | |
6678 | else | |
6679 | aCurrentEventManager->Select(); | |
6680 | } | |
2157d6ac | 6681 | else if(aCoordsNb == 4) |
4754e164 | 6682 | { |
6683 | if(isShiftSelection) | |
2157d6ac | 6684 | aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False); |
4754e164 | 6685 | else |
2157d6ac | 6686 | aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False); |
4754e164 | 6687 | } |
6688 | else | |
6689 | { | |
2157d6ac | 6690 | TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2); |
4754e164 | 6691 | |
2157d6ac | 6692 | for(Standard_Integer i=1;i<=aCoordsNb / 2;++i) |
4754e164 | 6693 | aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i]))); |
6694 | ||
6695 | if(isShiftSelection) | |
6696 | aCurrentEventManager->ShiftSelect(aPolyline); | |
6697 | else | |
6698 | aCurrentEventManager->Select(aPolyline); | |
6699 | } | |
6700 | return 0; | |
6701 | } | |
6702 | ||
6703 | //======================================================================= | |
6704 | //function : VMoveTo | |
dc3fe572 | 6705 | //purpose : Emulates cursor movement to defined pixel position |
4754e164 | 6706 | //======================================================================= |
1e756cb9 | 6707 | static Standard_Integer VMoveTo (Draw_Interpretor& theDI, |
8a590580 | 6708 | Standard_Integer theNbArgs, |
6709 | const char** theArgVec) | |
4754e164 | 6710 | { |
8a590580 | 6711 | const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext(); |
6712 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); | |
6713 | if (aContext.IsNull()) | |
4754e164 | 6714 | { |
8a590580 | 6715 | std::cout << "Error: no active View\n"; |
4754e164 | 6716 | return 1; |
6717 | } | |
6718 | ||
8a590580 | 6719 | Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast()); |
6720 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) | |
4754e164 | 6721 | { |
8a590580 | 6722 | TCollection_AsciiString anArgStr (theArgVec[anArgIter]); |
6723 | anArgStr.LowerCase(); | |
6724 | if (anArgStr == "-reset" | |
6725 | || anArgStr == "-clear") | |
6726 | { | |
6727 | if (anArgIter + 1 < theNbArgs) | |
6728 | { | |
6729 | std::cout << "Syntax error at '" << theArgVec[anArgIter + 1] << "'\n"; | |
6730 | return 1; | |
6731 | } | |
6732 | ||
6733 | const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive() | |
6734 | && aContext->CurrentViewer()->GridEcho(); | |
6735 | if (toEchoGrid) | |
6736 | { | |
6737 | aContext->CurrentViewer()->HideGridEcho (aView); | |
6738 | } | |
6739 | if (aContext->ClearDetected() || toEchoGrid) | |
6740 | { | |
6741 | aContext->CurrentViewer()->RedrawImmediate(); | |
6742 | } | |
6743 | return 0; | |
6744 | } | |
6745 | else if (aMousePos.x() == IntegerLast() | |
6746 | && anArgStr.IsIntegerValue()) | |
6747 | { | |
6748 | aMousePos.x() = anArgStr.IntegerValue(); | |
6749 | } | |
6750 | else if (aMousePos.y() == IntegerLast() | |
6751 | && anArgStr.IsIntegerValue()) | |
6752 | { | |
6753 | aMousePos.y() = anArgStr.IntegerValue(); | |
6754 | } | |
6755 | else | |
6756 | { | |
6757 | std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n"; | |
6758 | return 1; | |
6759 | } | |
6760 | } | |
6761 | ||
6762 | if (aMousePos.x() == IntegerLast() | |
6763 | || aMousePos.y() == IntegerLast()) | |
6764 | { | |
6765 | std::cout << "Syntax error: wrong number of arguments\n"; | |
4754e164 | 6766 | return 1; |
6767 | } | |
8a590580 | 6768 | |
6769 | ViewerTest::CurrentEventManager()->MoveTo (aMousePos.x(), aMousePos.y()); | |
1e756cb9 | 6770 | gp_Pnt aTopPnt (RealLast(), RealLast(), RealLast()); |
6771 | const Handle(SelectMgr_EntityOwner)& aDetOwner = aContext->DetectedOwner(); | |
6772 | for (Standard_Integer aDetIter = 1; aDetIter <= aContext->MainSelector()->NbPicked(); ++aDetIter) | |
6773 | { | |
6774 | if (aContext->MainSelector()->Picked (aDetIter) == aDetOwner) | |
6775 | { | |
6776 | aTopPnt = aContext->MainSelector()->PickedPoint (aDetIter); | |
6777 | break; | |
6778 | } | |
6779 | } | |
6780 | theDI << aTopPnt.X() << " " << aTopPnt.Y() << " " << aTopPnt.Z(); | |
4754e164 | 6781 | return 0; |
6782 | } | |
6783 | ||
1beb58d7 | 6784 | namespace |
6785 | { | |
6786 | //! Global map storing all animations registered in ViewerTest. | |
6787 | static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap; | |
6788 | ||
6789 | //! The animation calling the Draw Harness command. | |
6790 | class ViewerTest_AnimationProc : public AIS_Animation | |
6791 | { | |
6792 | public: | |
6793 | ||
6794 | //! Main constructor. | |
6795 | ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName, | |
6796 | Draw_Interpretor* theDI, | |
6797 | const TCollection_AsciiString& theCommand) | |
6798 | : AIS_Animation (theAnimationName), | |
6799 | myDrawInter(theDI), | |
6800 | myCommand (theCommand) | |
6801 | { | |
6802 | // | |
6803 | } | |
6804 | ||
6805 | protected: | |
6806 | ||
6807 | //! Evaluate the command. | |
6808 | virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE | |
6809 | { | |
6810 | TCollection_AsciiString aCmd = myCommand; | |
6811 | replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts)); | |
6812 | replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts)); | |
6813 | replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts)); | |
6814 | replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized)); | |
6815 | replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized)); | |
6816 | myDrawInter->Eval (aCmd.ToCString()); | |
6817 | } | |
6818 | ||
6819 | //! Find the keyword in the command and replace it with value. | |
6820 | //! @return the position of the keyword to pass value | |
6821 | void replace (TCollection_AsciiString& theCmd, | |
6822 | const TCollection_AsciiString& theKey, | |
6823 | const TCollection_AsciiString& theVal) | |
6824 | { | |
6825 | TCollection_AsciiString aCmd (theCmd); | |
6826 | aCmd.LowerCase(); | |
6827 | const Standard_Integer aPos = aCmd.Search (theKey); | |
6828 | if (aPos == -1) | |
6829 | { | |
6830 | return; | |
6831 | } | |
6832 | ||
6833 | TCollection_AsciiString aPart1, aPart2; | |
6834 | Standard_Integer aPart1To = aPos - 1; | |
6835 | if (aPart1To >= 1 | |
6836 | && aPart1To <= theCmd.Length()) | |
6837 | { | |
6838 | aPart1 = theCmd.SubString (1, aPart1To); | |
6839 | } | |
6840 | ||
6841 | Standard_Integer aPart2From = aPos + theKey.Length(); | |
6842 | if (aPart2From >= 1 | |
6843 | && aPart2From <= theCmd.Length()) | |
6844 | { | |
6845 | aPart2 = theCmd.SubString (aPart2From, theCmd.Length()); | |
6846 | } | |
6847 | ||
6848 | theCmd = aPart1 + theVal + aPart2; | |
6849 | } | |
6850 | ||
6851 | protected: | |
6852 | ||
6853 | Draw_Interpretor* myDrawInter; | |
6854 | TCollection_AsciiString myCommand; | |
6855 | ||
6856 | }; | |
6857 | ||
6858 | //! Replace the animation with the new one. | |
6859 | static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation, | |
6860 | Handle(AIS_Animation)& theAnimation, | |
6861 | const Handle(AIS_Animation)& theAnimationNew) | |
6862 | { | |
6863 | theAnimationNew->CopyFrom (theAnimation); | |
6864 | if (!theParentAnimation.IsNull()) | |
6865 | { | |
6866 | theParentAnimation->Replace (theAnimation, theAnimationNew); | |
6867 | } | |
6868 | else | |
6869 | { | |
6870 | ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name()); | |
6871 | ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew); | |
6872 | } | |
6873 | theAnimation = theAnimationNew; | |
6874 | } | |
6875 | ||
6876 | //! Parse the point. | |
6877 | static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt) | |
6878 | { | |
6879 | const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] }; | |
6880 | if (!anXYZ[0].IsRealValue() | |
6881 | || !anXYZ[1].IsRealValue() | |
6882 | || !anXYZ[2].IsRealValue()) | |
6883 | { | |
6884 | return Standard_False; | |
6885 | } | |
6886 | ||
6887 | thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue()); | |
6888 | return Standard_True; | |
6889 | } | |
6890 | ||
6891 | //! Parse the quaternion. | |
6892 | static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot) | |
6893 | { | |
6894 | const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]}; | |
6895 | if (!anXYZW[0].IsRealValue() | |
6896 | || !anXYZW[1].IsRealValue() | |
6897 | || !anXYZW[2].IsRealValue() | |
6898 | || !anXYZW[3].IsRealValue()) | |
6899 | { | |
6900 | return Standard_False; | |
6901 | } | |
6902 | ||
6903 | theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue()); | |
6904 | return Standard_True; | |
6905 | } | |
6906 | ||
08f8a185 | 6907 | //! Auxiliary class for flipping image upside-down. |
6908 | class ImageFlipper | |
6909 | { | |
6910 | public: | |
6911 | ||
6912 | //! Empty constructor. | |
6913 | ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {} | |
6914 | ||
6915 | //! Perform flipping. | |
6916 | Standard_Boolean FlipY (Image_PixMap& theImage) | |
6917 | { | |
6918 | if (theImage.IsEmpty() | |
6919 | || theImage.SizeX() == 0 | |
6920 | || theImage.SizeY() == 0) | |
6921 | { | |
6922 | return Standard_False; | |
6923 | } | |
6924 | ||
6925 | const Standard_Size aRowSize = theImage.SizeRowBytes(); | |
6926 | if (myTmp.Size() < aRowSize | |
6927 | && !myTmp.Allocate (aRowSize)) | |
6928 | { | |
6929 | return Standard_False; | |
6930 | } | |
6931 | ||
6932 | // for odd height middle row should be left as is | |
6933 | Standard_Size aNbRowsHalf = theImage.SizeY() / 2; | |
6934 | for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB) | |
6935 | { | |
6936 | Standard_Byte* aTop = theImage.ChangeRow (aRowT); | |
6937 | Standard_Byte* aBot = theImage.ChangeRow (aRowB); | |
6938 | memcpy (myTmp.ChangeData(), aTop, aRowSize); | |
6939 | memcpy (aTop, aBot, aRowSize); | |
6940 | memcpy (aBot, myTmp.Data(), aRowSize); | |
6941 | } | |
6942 | return Standard_True; | |
6943 | } | |
6944 | ||
6945 | private: | |
6946 | NCollection_Buffer myTmp; | |
6947 | }; | |
6948 | ||
1beb58d7 | 6949 | } |
6950 | ||
197ac94e | 6951 | //================================================================================================= |
4754e164 | 6952 | //function : VViewParams |
dc3fe572 | 6953 | //purpose : Gets or sets AIS View characteristics |
197ac94e | 6954 | //================================================================================================= |
6955 | static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
4754e164 | 6956 | { |
1beb58d7 | 6957 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
6958 | if (aView.IsNull()) | |
4754e164 | 6959 | { |
197ac94e | 6960 | std::cout << theArgVec[0] << ": please initialize or activate view.\n"; |
4754e164 | 6961 | return 1; |
6962 | } | |
197ac94e | 6963 | |
1beb58d7 | 6964 | Standard_Boolean toSetProj = Standard_False; |
6965 | Standard_Boolean toSetUp = Standard_False; | |
6966 | Standard_Boolean toSetAt = Standard_False; | |
6967 | Standard_Boolean toSetEye = Standard_False; | |
6968 | Standard_Boolean toSetScale = Standard_False; | |
6969 | Standard_Boolean toSetSize = Standard_False; | |
6970 | Standard_Boolean toSetCenter2d = Standard_False; | |
ee2be2a8 | 6971 | Standard_Real aViewScale = aView->Scale(); |
6972 | Standard_Real aViewSize = 1.0; | |
1beb58d7 | 6973 | Graphic3d_Vec2i aCenter2d; |
6974 | gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye; | |
6975 | aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3)); | |
6976 | aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3)); | |
6977 | aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3)); | |
6978 | aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3)); | |
197ac94e | 6979 | if (theArgsNb == 1) |
4754e164 | 6980 | { |
197ac94e | 6981 | // print all of the available view parameters |
1beb58d7 | 6982 | char aText[4096]; |
6983 | Sprintf (aText, | |
6984 | "Scale: %g\n" | |
6985 | "Proj: %12g %12g %12g\n" | |
6986 | "Up: %12g %12g %12g\n" | |
6987 | "At: %12g %12g %12g\n" | |
6988 | "Eye: %12g %12g %12g\n", | |
6989 | aViewScale, | |
6990 | aViewProj.X(), aViewProj.Y(), aViewProj.Z(), | |
6991 | aViewUp.X(), aViewUp.Y(), aViewUp.Z(), | |
6992 | aViewAt.X(), aViewAt.Y(), aViewAt.Z(), | |
6993 | aViewEye.X(), aViewEye.Y(), aViewEye.Z()); | |
6994 | theDi << aText; | |
197ac94e | 6995 | return 0; |
4754e164 | 6996 | } |
197ac94e | 6997 | |
1beb58d7 | 6998 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
6999 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
197ac94e | 7000 | { |
1beb58d7 | 7001 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
7002 | anArg.LowerCase(); | |
7003 | if (anUpdateTool.parseRedrawMode (anArg)) | |
197ac94e | 7004 | { |
197ac94e | 7005 | continue; |
7006 | } | |
1beb58d7 | 7007 | else if (anArg == "-cmd" |
7008 | || anArg == "-command" | |
7009 | || anArg == "-args") | |
7010 | { | |
7011 | char aText[4096]; | |
7012 | Sprintf (aText, | |
7013 | "-scale %g " | |
7014 | "-proj %g %g %g " | |
7015 | "-up %g %g %g " | |
7016 | "-at %g %g %g\n", | |
7017 | aViewScale, | |
7018 | aViewProj.X(), aViewProj.Y(), aViewProj.Z(), | |
7019 | aViewUp.X(), aViewUp.Y(), aViewUp.Z(), | |
7020 | aViewAt.X(), aViewAt.Y(), aViewAt.Z()); | |
7021 | theDi << aText; | |
7022 | } | |
7023 | else if (anArg == "-scale" | |
7024 | || anArg == "-size") | |
7025 | { | |
7026 | if (anArgIter + 1 < theArgsNb | |
7027 | && *theArgVec[anArgIter + 1] != '-') | |
7028 | { | |
7029 | const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]); | |
7030 | if (aValueArg.IsRealValue()) | |
7031 | { | |
7032 | ++anArgIter; | |
7033 | if (anArg == "-scale") | |
7034 | { | |
7035 | toSetScale = Standard_True; | |
7036 | aViewScale = aValueArg.RealValue(); | |
7037 | } | |
7038 | else if (anArg == "-size") | |
7039 | { | |
7040 | toSetSize = Standard_True; | |
7041 | aViewSize = aValueArg.RealValue(); | |
7042 | } | |
7043 | continue; | |
7044 | } | |
7045 | } | |
7046 | if (anArg == "-scale") | |
7047 | { | |
7048 | theDi << "Scale: " << aView->Scale() << "\n"; | |
7049 | } | |
7050 | else if (anArg == "-size") | |
7051 | { | |
7052 | Graphic3d_Vec2d aSizeXY; | |
7053 | aView->Size (aSizeXY.x(), aSizeXY.y()); | |
7054 | theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n"; | |
7055 | } | |
7056 | } | |
7057 | else if (anArg == "-eye" | |
7058 | || anArg == "-at" | |
7059 | || anArg == "-up" | |
7060 | || anArg == "-proj") | |
7061 | { | |
7062 | if (anArgIter + 3 < theArgsNb) | |
7063 | { | |
7064 | gp_XYZ anXYZ; | |
7065 | if (parseXYZ (theArgVec + anArgIter + 1, anXYZ)) | |
7066 | { | |
7067 | anArgIter += 3; | |
7068 | if (anArg == "-eye") | |
7069 | { | |
7070 | toSetEye = Standard_True; | |
7071 | aViewEye = anXYZ; | |
7072 | } | |
7073 | else if (anArg == "-at") | |
7074 | { | |
7075 | toSetAt = Standard_True; | |
7076 | aViewAt = anXYZ; | |
7077 | } | |
7078 | else if (anArg == "-up") | |
7079 | { | |
7080 | toSetUp = Standard_True; | |
7081 | aViewUp = anXYZ; | |
7082 | } | |
7083 | else if (anArg == "-proj") | |
7084 | { | |
7085 | toSetProj = Standard_True; | |
7086 | aViewProj = anXYZ; | |
7087 | } | |
7088 | continue; | |
7089 | } | |
7090 | } | |
197ac94e | 7091 | |
1beb58d7 | 7092 | if (anArg == "-eye") |
7093 | { | |
7094 | theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n"; | |
7095 | } | |
7096 | else if (anArg == "-at") | |
7097 | { | |
7098 | theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n"; | |
7099 | } | |
7100 | else if (anArg == "-up") | |
7101 | { | |
7102 | theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n"; | |
7103 | } | |
7104 | else if (anArg == "-proj") | |
7105 | { | |
7106 | theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n"; | |
7107 | } | |
7108 | } | |
7109 | else if (anArg == "-center") | |
3dfe95cd | 7110 | { |
1beb58d7 | 7111 | if (anArgIter + 2 < theArgsNb) |
7112 | { | |
7113 | const TCollection_AsciiString anX (theArgVec[anArgIter + 1]); | |
7114 | const TCollection_AsciiString anY (theArgVec[anArgIter + 2]); | |
7115 | if (anX.IsIntegerValue() | |
7116 | && anY.IsIntegerValue()) | |
7117 | { | |
7118 | toSetCenter2d = Standard_True; | |
7119 | aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()); | |
7120 | } | |
7121 | } | |
7122 | } | |
7123 | else | |
7124 | { | |
7125 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
3dfe95cd | 7126 | return 1; |
7127 | } | |
1beb58d7 | 7128 | } |
3dfe95cd | 7129 | |
1beb58d7 | 7130 | // change view parameters in proper order |
7131 | if (toSetScale) | |
7132 | { | |
7133 | aView->SetScale (aViewScale); | |
7134 | } | |
7135 | if (toSetSize) | |
7136 | { | |
7137 | aView->SetSize (aViewSize); | |
7138 | } | |
7139 | if (toSetEye) | |
7140 | { | |
7141 | aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z()); | |
7142 | } | |
7143 | if (toSetAt) | |
7144 | { | |
7145 | aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z()); | |
7146 | } | |
7147 | if (toSetProj) | |
7148 | { | |
7149 | aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z()); | |
7150 | } | |
7151 | if (toSetUp) | |
7152 | { | |
7153 | aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z()); | |
7154 | } | |
7155 | if (toSetCenter2d) | |
7156 | { | |
7157 | aView->SetCenter (aCenter2d.x(), aCenter2d.y()); | |
197ac94e | 7158 | } |
7159 | ||
1beb58d7 | 7160 | return 0; |
7161 | } | |
197ac94e | 7162 | |
2e93433e | 7163 | //============================================================================== |
7164 | //function : V2DMode | |
7165 | //purpose : | |
7166 | //============================================================================== | |
7167 | static Standard_Integer V2DMode (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec) | |
7168 | { | |
7169 | bool is2dMode = true; | |
7170 | Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()); | |
7171 | if (aV3dView.IsNull()) | |
7172 | { | |
7173 | std::cout << "Error: no active view.\n"; | |
7174 | return 1; | |
7175 | } | |
7176 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
7177 | { | |
7178 | const TCollection_AsciiString anArg = theArgVec[anArgIt]; | |
7179 | TCollection_AsciiString anArgCase = anArg; | |
7180 | anArgCase.LowerCase(); | |
7181 | if (anArgIt + 1 < theArgsNb | |
7182 | && anArgCase == "-name") | |
7183 | { | |
7184 | ViewerTest_Names aViewNames (theArgVec[++anArgIt]); | |
7185 | TCollection_AsciiString aViewName = aViewNames.GetViewName(); | |
7186 | if (!ViewerTest_myViews.IsBound1 (aViewName)) | |
7187 | { | |
7188 | std::cout << "Syntax error: unknown view '" << theArgVec[anArgIt - 1] << "'.\n"; | |
7189 | return 1; | |
7190 | } | |
7191 | aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest_myViews.Find1 (aViewName)); | |
7192 | } | |
7193 | else if (anArgCase == "-mode") | |
7194 | { | |
7195 | if (anArgIt + 1 < theArgsNb | |
7196 | && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], is2dMode)) | |
7197 | { | |
7198 | ++anArgIt; | |
7199 | } | |
7200 | } | |
7201 | else if (ViewerTest::ParseOnOff (theArgVec[anArgIt], is2dMode)) | |
7202 | { | |
7203 | // | |
7204 | } | |
7205 | else | |
7206 | { | |
7207 | std::cout << "Syntax error: unknown argument " << anArg << ".\n"; | |
7208 | return 1; | |
7209 | } | |
7210 | } | |
7211 | ||
7212 | aV3dView->SetView2DMode (is2dMode); | |
7213 | return 0; | |
7214 | } | |
7215 | ||
1beb58d7 | 7216 | //============================================================================== |
7217 | //function : VAnimation | |
7218 | //purpose : | |
7219 | //============================================================================== | |
7220 | static Standard_Integer VAnimation (Draw_Interpretor& theDI, | |
7221 | Standard_Integer theArgNb, | |
7222 | const char** theArgVec) | |
7223 | { | |
7224 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
7225 | if (theArgNb < 2) | |
4754e164 | 7226 | { |
1beb58d7 | 7227 | for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator |
7228 | anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next()) | |
7229 | { | |
7230 | theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n"; | |
197ac94e | 7231 | } |
1beb58d7 | 7232 | return 0; |
7233 | } | |
7234 | if (aCtx.IsNull()) | |
7235 | { | |
7236 | std::cout << "Error: no active view\n"; | |
7237 | return 1; | |
4754e164 | 7238 | } |
197ac94e | 7239 | |
1beb58d7 | 7240 | Standard_Integer anArgIter = 1; |
7241 | TCollection_AsciiString aNameArg (theArgVec[anArgIter++]); | |
7242 | if (aNameArg.IsEmpty()) | |
7243 | { | |
7244 | std::cout << "Syntax error: animation name is not defined.\n"; | |
7245 | return 1; | |
7246 | } | |
7247 | ||
7248 | TCollection_AsciiString aNameArgLower = aNameArg; | |
7249 | aNameArgLower.LowerCase(); | |
7250 | if (aNameArgLower == "-reset" | |
7251 | || aNameArgLower == "-clear") | |
7252 | { | |
7253 | ViewerTest_AnimationTimelineMap.Clear(); | |
7254 | return 0; | |
7255 | } | |
7256 | else if (aNameArg.Value (1) == '-') | |
7257 | { | |
7258 | std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n"; | |
7259 | return 1; | |
7260 | } | |
197ac94e | 7261 | |
1beb58d7 | 7262 | const char* aNameSplitter = "/"; |
7263 | Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter); | |
7264 | if (aSplitPos == -1) | |
197ac94e | 7265 | { |
1beb58d7 | 7266 | aNameSplitter = "."; |
7267 | aSplitPos = aNameArg.Search (aNameSplitter); | |
7268 | } | |
7269 | ||
7270 | // find existing or create a new animation by specified name within syntax "parent.child". | |
7271 | Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation; | |
7272 | for (; !aNameArg.IsEmpty();) | |
7273 | { | |
7274 | TCollection_AsciiString aNameParent; | |
7275 | if (aSplitPos != -1) | |
197ac94e | 7276 | { |
1beb58d7 | 7277 | if (aSplitPos == aNameArg.Length()) |
7278 | { | |
7279 | std::cout << "Syntax error: animation name is not defined.\n"; | |
7280 | return 1; | |
7281 | } | |
7282 | ||
7283 | aNameParent = aNameArg.SubString ( 1, aSplitPos - 1); | |
7284 | aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length()); | |
7285 | ||
7286 | aSplitPos = aNameArg.Search (aNameSplitter); | |
197ac94e | 7287 | } |
7288 | else | |
7289 | { | |
1beb58d7 | 7290 | aNameParent = aNameArg; |
7291 | aNameArg.Clear(); | |
197ac94e | 7292 | } |
1beb58d7 | 7293 | |
7294 | if (anAnimation.IsNull()) | |
3dfe95cd | 7295 | { |
1beb58d7 | 7296 | if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation)) |
7297 | { | |
7298 | anAnimation = new AIS_Animation (aNameParent); | |
7299 | ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation); | |
7300 | } | |
7301 | aRootAnimation = anAnimation; | |
3dfe95cd | 7302 | } |
7303 | else | |
7304 | { | |
1beb58d7 | 7305 | aParentAnimation = anAnimation; |
7306 | anAnimation = aParentAnimation->Find (aNameParent); | |
7307 | if (anAnimation.IsNull()) | |
7308 | { | |
7309 | anAnimation = new AIS_Animation (aNameParent); | |
7310 | aParentAnimation->Add (anAnimation); | |
7311 | } | |
3dfe95cd | 7312 | } |
7313 | } | |
1beb58d7 | 7314 | |
7315 | if (anArgIter >= theArgNb) | |
197ac94e | 7316 | { |
1beb58d7 | 7317 | // just print the list of children |
7318 | for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next()) | |
197ac94e | 7319 | { |
1beb58d7 | 7320 | theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n"; |
197ac94e | 7321 | } |
1beb58d7 | 7322 | return 0; |
197ac94e | 7323 | } |
1beb58d7 | 7324 | |
bf7b2ceb | 7325 | // animation parameters |
1beb58d7 | 7326 | Standard_Boolean toPlay = Standard_False; |
7327 | Standard_Real aPlaySpeed = 1.0; | |
7328 | Standard_Real aPlayStartTime = anAnimation->StartPts(); | |
7329 | Standard_Real aPlayDuration = anAnimation->Duration(); | |
1beb58d7 | 7330 | Standard_Boolean isFreeCamera = Standard_False; |
7331 | Standard_Boolean isLockLoop = Standard_False; | |
08f8a185 | 7332 | |
7333 | // video recording parameters | |
7334 | TCollection_AsciiString aRecFile; | |
7335 | Image_VideoParams aRecParams; | |
7336 | ||
1beb58d7 | 7337 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
7338 | for (; anArgIter < theArgNb; ++anArgIter) | |
197ac94e | 7339 | { |
1beb58d7 | 7340 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
7341 | anArg.LowerCase(); | |
bf7b2ceb | 7342 | // general options |
1beb58d7 | 7343 | if (anArg == "-reset" |
7344 | || anArg == "-clear") | |
197ac94e | 7345 | { |
1beb58d7 | 7346 | anAnimation->Clear(); |
7347 | } | |
7348 | else if (anArg == "-remove" | |
7349 | || anArg == "-del" | |
7350 | || anArg == "-delete") | |
7351 | { | |
7352 | if (!aParentAnimation.IsNull()) | |
7353 | { | |
7354 | ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name()); | |
7355 | } | |
7356 | else | |
7357 | { | |
7358 | aParentAnimation->Remove (anAnimation); | |
7359 | } | |
7360 | } | |
bf7b2ceb | 7361 | // playback options |
1beb58d7 | 7362 | else if (anArg == "-play") |
7363 | { | |
7364 | toPlay = Standard_True; | |
7365 | if (++anArgIter < theArgNb) | |
7366 | { | |
7367 | if (*theArgVec[anArgIter] == '-') | |
7368 | { | |
7369 | --anArgIter; | |
7370 | continue; | |
7371 | } | |
7372 | aPlayStartTime = Draw::Atof (theArgVec[anArgIter]); | |
7373 | ||
7374 | if (++anArgIter < theArgNb) | |
7375 | { | |
7376 | if (*theArgVec[anArgIter] == '-') | |
7377 | { | |
7378 | --anArgIter; | |
7379 | continue; | |
7380 | } | |
7381 | aPlayDuration = Draw::Atof (theArgVec[anArgIter]); | |
7382 | } | |
7383 | } | |
7384 | } | |
7385 | else if (anArg == "-resume") | |
7386 | { | |
7387 | toPlay = Standard_True; | |
7388 | aPlayStartTime = anAnimation->ElapsedTime(); | |
7389 | if (++anArgIter < theArgNb) | |
7390 | { | |
7391 | if (*theArgVec[anArgIter] == '-') | |
7392 | { | |
7393 | --anArgIter; | |
7394 | continue; | |
7395 | } | |
7396 | ||
7397 | aPlayDuration = Draw::Atof (theArgVec[anArgIter]); | |
7398 | } | |
7399 | } | |
7400 | else if (anArg == "-playspeed" | |
7401 | || anArg == "-speed") | |
7402 | { | |
7403 | if (++anArgIter >= theArgNb) | |
7404 | { | |
7405 | std::cout << "Syntax error at " << anArg << ".\n"; | |
7406 | return 1; | |
7407 | } | |
7408 | aPlaySpeed = Draw::Atof (theArgVec[anArgIter]); | |
7409 | } | |
7410 | else if (anArg == "-lock" | |
7411 | || anArg == "-lockloop" | |
7412 | || anArg == "-playlockloop") | |
7413 | { | |
7414 | isLockLoop = Standard_True; | |
7415 | } | |
7416 | else if (anArg == "-freecamera" | |
7417 | || anArg == "-playfreecamera" | |
7418 | || anArg == "-freelook") | |
7419 | { | |
7420 | isFreeCamera = Standard_True; | |
7421 | } | |
08f8a185 | 7422 | // video recodring options |
7423 | else if (anArg == "-rec" | |
7424 | || anArg == "-record") | |
7425 | { | |
7426 | if (++anArgIter >= theArgNb) | |
7427 | { | |
7428 | std::cout << "Syntax error at " << anArg << ".\n"; | |
7429 | return 1; | |
7430 | } | |
7431 | ||
7432 | aRecFile = theArgVec[anArgIter]; | |
7433 | if (aRecParams.FpsNum <= 0) | |
7434 | { | |
7435 | aRecParams.FpsNum = 24; | |
7436 | } | |
7437 | ||
7438 | if (anArgIter + 2 < theArgNb | |
7439 | && *theArgVec[anArgIter + 1] != '-' | |
7440 | && *theArgVec[anArgIter + 2] != '-') | |
7441 | { | |
7442 | TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]); | |
7443 | TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]); | |
7444 | if (aWidthArg .IsIntegerValue() | |
7445 | && aHeightArg.IsIntegerValue()) | |
7446 | { | |
7447 | aRecParams.Width = aWidthArg .IntegerValue(); | |
7448 | aRecParams.Height = aHeightArg.IntegerValue(); | |
7449 | anArgIter += 2; | |
7450 | } | |
7451 | } | |
7452 | } | |
1beb58d7 | 7453 | else if (anArg == "-fps") |
7454 | { | |
7455 | if (++anArgIter >= theArgNb) | |
7456 | { | |
7457 | std::cout << "Syntax error at " << anArg << ".\n"; | |
7458 | return 1; | |
7459 | } | |
bf7b2ceb | 7460 | |
7461 | TCollection_AsciiString aFpsArg (theArgVec[anArgIter]); | |
7462 | Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length()); | |
7463 | if (aSplitIndex == 0) | |
7464 | { | |
08f8a185 | 7465 | aRecParams.FpsNum = aFpsArg.IntegerValue(); |
bf7b2ceb | 7466 | } |
7467 | else | |
7468 | { | |
7469 | const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex); | |
7470 | aFpsArg.Split (aFpsArg.Length() - 1); | |
7471 | const TCollection_AsciiString aNumStr = aFpsArg; | |
08f8a185 | 7472 | aRecParams.FpsNum = aNumStr.IntegerValue(); |
7473 | aRecParams.FpsDen = aDenStr.IntegerValue(); | |
7474 | if (aRecParams.FpsDen < 1) | |
bf7b2ceb | 7475 | { |
7476 | std::cout << "Syntax error at " << anArg << ".\n"; | |
7477 | return 1; | |
7478 | } | |
7479 | } | |
1beb58d7 | 7480 | } |
08f8a185 | 7481 | else if (anArg == "-format") |
7482 | { | |
7483 | if (++anArgIter >= theArgNb) | |
7484 | { | |
7485 | std::cout << "Syntax error at " << anArg << ".\n"; | |
7486 | return 1; | |
7487 | } | |
7488 | aRecParams.Format = theArgVec[anArgIter]; | |
7489 | } | |
7490 | else if (anArg == "-pix_fmt" | |
7491 | || anArg == "-pixfmt" | |
7492 | || anArg == "-pixelformat") | |
7493 | { | |
7494 | if (++anArgIter >= theArgNb) | |
7495 | { | |
7496 | std::cout << "Syntax error at " << anArg << ".\n"; | |
7497 | return 1; | |
7498 | } | |
7499 | aRecParams.PixelFormat = theArgVec[anArgIter]; | |
7500 | } | |
7501 | else if (anArg == "-codec" | |
7502 | || anArg == "-vcodec" | |
7503 | || anArg == "-videocodec") | |
7504 | { | |
7505 | if (++anArgIter >= theArgNb) | |
7506 | { | |
7507 | std::cout << "Syntax error at " << anArg << ".\n"; | |
7508 | return 1; | |
7509 | } | |
7510 | aRecParams.VideoCodec = theArgVec[anArgIter]; | |
7511 | } | |
7512 | else if (anArg == "-crf" | |
7513 | || anArg == "-preset" | |
7514 | || anArg == "-qp") | |
7515 | { | |
7516 | const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length()); | |
7517 | if (++anArgIter >= theArgNb) | |
7518 | { | |
7519 | std::cout << "Syntax error at " << anArg << ".\n"; | |
7520 | return 1; | |
7521 | } | |
7522 | ||
7523 | aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]); | |
7524 | } | |
bf7b2ceb | 7525 | // animation definition options |
1beb58d7 | 7526 | else if (anArg == "-start" |
7527 | || anArg == "-starttime" | |
7528 | || anArg == "-startpts") | |
7529 | { | |
7530 | if (++anArgIter >= theArgNb) | |
7531 | { | |
7532 | std::cout << "Syntax error at " << anArg << ".\n"; | |
7533 | return 1; | |
7534 | } | |
7535 | ||
7536 | anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter])); | |
7537 | aRootAnimation->UpdateTotalDuration(); | |
7538 | } | |
7539 | else if (anArg == "-end" | |
7540 | || anArg == "-endtime" | |
7541 | || anArg == "-endpts") | |
7542 | { | |
7543 | if (++anArgIter >= theArgNb) | |
7544 | { | |
7545 | std::cout << "Syntax error at " << anArg << ".\n"; | |
7546 | return 1; | |
7547 | } | |
7548 | ||
7549 | anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts()); | |
7550 | aRootAnimation->UpdateTotalDuration(); | |
7551 | } | |
7552 | else if (anArg == "-dur" | |
7553 | || anArg == "-duration") | |
7554 | { | |
7555 | if (++anArgIter >= theArgNb) | |
7556 | { | |
7557 | std::cout << "Syntax error at " << anArg << ".\n"; | |
7558 | return 1; | |
7559 | } | |
7560 | ||
7561 | anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter])); | |
7562 | aRootAnimation->UpdateTotalDuration(); | |
7563 | } | |
7564 | else if (anArg == "-command" | |
7565 | || anArg == "-cmd" | |
7566 | || anArg == "-invoke" | |
7567 | || anArg == "-eval" | |
7568 | || anArg == "-proc") | |
7569 | { | |
7570 | if (++anArgIter >= theArgNb) | |
7571 | { | |
7572 | std::cout << "Syntax error at " << anArg << ".\n"; | |
7573 | return 1; | |
7574 | } | |
7575 | ||
7576 | Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]); | |
7577 | replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation); | |
7578 | } | |
7579 | else if (anArg == "-objecttrsf" | |
7580 | || anArg == "-objectransformation" | |
7581 | || anArg == "-objtransformation" | |
7582 | || anArg == "-objtrsf" | |
7583 | || anArg == "-object" | |
7584 | || anArg == "-obj") | |
7585 | { | |
7586 | if (++anArgIter >= theArgNb) | |
7587 | { | |
7588 | std::cout << "Syntax error at " << anArg << ".\n"; | |
7589 | return 1; | |
7590 | } | |
7591 | ||
7592 | TCollection_AsciiString anObjName (theArgVec[anArgIter]); | |
7593 | const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS(); | |
8f521168 | 7594 | Handle(AIS_InteractiveObject) anObject; |
7595 | if (!aMapOfAIS.Find2 (anObjName, anObject)) | |
1beb58d7 | 7596 | { |
7597 | std::cout << "Syntax error: wrong object name at " << anArg << "\n"; | |
7598 | return 1; | |
7599 | } | |
7600 | ||
1beb58d7 | 7601 | gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() }; |
7602 | gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() }; | |
7603 | gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() }; | |
7604 | Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() }; | |
7605 | Standard_Boolean isTrsfSet = Standard_False; | |
7606 | Standard_Integer aTrsfArgIter = anArgIter + 1; | |
7607 | for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter) | |
7608 | { | |
7609 | TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]); | |
7610 | aTrsfArg.LowerCase(); | |
7611 | const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1; | |
7612 | if (aTrsfArg.StartsWith ("-rotation") | |
7613 | || aTrsfArg.StartsWith ("-rot")) | |
7614 | { | |
7615 | isTrsfSet = Standard_True; | |
7616 | if (aTrsfArgIter + 4 >= theArgNb | |
7617 | || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex])) | |
7618 | { | |
7619 | std::cout << "Syntax error at " << aTrsfArg << ".\n"; | |
7620 | return 1; | |
7621 | } | |
7622 | aTrsfArgIter += 4; | |
7623 | } | |
7624 | else if (aTrsfArg.StartsWith ("-location") | |
7625 | || aTrsfArg.StartsWith ("-loc")) | |
7626 | { | |
7627 | isTrsfSet = Standard_True; | |
7628 | if (aTrsfArgIter + 3 >= theArgNb | |
7629 | || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex])) | |
7630 | { | |
7631 | std::cout << "Syntax error at " << aTrsfArg << ".\n"; | |
7632 | return 1; | |
7633 | } | |
7634 | aTrsfArgIter += 3; | |
7635 | } | |
7636 | else if (aTrsfArg.StartsWith ("-scale")) | |
7637 | { | |
7638 | isTrsfSet = Standard_True; | |
7639 | if (++aTrsfArgIter >= theArgNb) | |
7640 | { | |
7641 | std::cout << "Syntax error at " << aTrsfArg << ".\n"; | |
7642 | return 1; | |
7643 | } | |
7644 | ||
7645 | const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]); | |
7646 | if (!aScaleStr.IsRealValue()) | |
7647 | { | |
7648 | std::cout << "Syntax error at " << aTrsfArg << ".\n"; | |
7649 | return 1; | |
7650 | } | |
7651 | aScales[anIndex] = aScaleStr.RealValue(); | |
7652 | } | |
7653 | else | |
7654 | { | |
7655 | anArgIter = aTrsfArgIter - 1; | |
7656 | break; | |
7657 | } | |
7658 | } | |
7659 | if (!isTrsfSet) | |
7660 | { | |
7661 | std::cout << "Syntax error at " << anArg << ".\n"; | |
7662 | return 1; | |
7663 | } | |
7664 | else if (aTrsfArgIter >= theArgNb) | |
7665 | { | |
7666 | anArgIter = theArgNb; | |
7667 | } | |
7668 | ||
7669 | aTrsfs[0].SetRotation (aRotQuats[0]); | |
7670 | aTrsfs[1].SetRotation (aRotQuats[1]); | |
7671 | aTrsfs[0].SetTranslationPart (aLocPnts[0]); | |
7672 | aTrsfs[1].SetTranslationPart (aLocPnts[1]); | |
7673 | aTrsfs[0].SetScaleFactor (aScales[0]); | |
7674 | aTrsfs[1].SetScaleFactor (aScales[1]); | |
7675 | ||
7676 | Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]); | |
7677 | replaceAnimation (aParentAnimation, anAnimation, anObjAnimation); | |
7678 | } | |
7679 | else if (anArg == "-viewtrsf" | |
7680 | || anArg == "-view") | |
7681 | { | |
7682 | Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation); | |
7683 | if (aCamAnimation.IsNull()) | |
7684 | { | |
7685 | aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView); | |
7686 | replaceAnimation (aParentAnimation, anAnimation, aCamAnimation); | |
7687 | } | |
7688 | ||
7689 | Handle(Graphic3d_Camera) aCams[2] = | |
7690 | { | |
7691 | new Graphic3d_Camera (aCamAnimation->View()->Camera()), | |
7692 | new Graphic3d_Camera (aCamAnimation->View()->Camera()) | |
7693 | }; | |
7694 | ||
7695 | Standard_Boolean isTrsfSet = Standard_False; | |
7696 | Standard_Integer aViewArgIter = anArgIter + 1; | |
7697 | for (; aViewArgIter < theArgNb; ++aViewArgIter) | |
7698 | { | |
7699 | TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]); | |
7700 | aViewArg.LowerCase(); | |
7701 | const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1; | |
7702 | if (aViewArg.StartsWith ("-scale")) | |
7703 | { | |
7704 | isTrsfSet = Standard_True; | |
7705 | if (++aViewArgIter >= theArgNb) | |
7706 | { | |
7707 | std::cout << "Syntax error at " << anArg << ".\n"; | |
7708 | return 1; | |
7709 | } | |
7710 | ||
7711 | const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]); | |
7712 | if (!aScaleStr.IsRealValue()) | |
7713 | { | |
7714 | std::cout << "Syntax error at " << aViewArg << ".\n"; | |
7715 | return 1; | |
7716 | } | |
7717 | Standard_Real aScale = aScaleStr.RealValue(); | |
7718 | aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale; | |
7719 | aCams[anIndex]->SetScale (aScale); | |
7720 | } | |
7721 | else if (aViewArg.StartsWith ("-eye") | |
7722 | || aViewArg.StartsWith ("-center") | |
7723 | || aViewArg.StartsWith ("-at") | |
7724 | || aViewArg.StartsWith ("-up")) | |
7725 | { | |
7726 | isTrsfSet = Standard_True; | |
7727 | gp_XYZ anXYZ; | |
7728 | if (aViewArgIter + 3 >= theArgNb | |
7729 | || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ)) | |
7730 | { | |
7731 | std::cout << "Syntax error at " << aViewArg << ".\n"; | |
7732 | return 1; | |
7733 | } | |
7734 | aViewArgIter += 3; | |
7735 | ||
7736 | if (aViewArg.StartsWith ("-eye")) | |
7737 | { | |
7738 | aCams[anIndex]->SetEye (anXYZ); | |
7739 | } | |
7740 | else if (aViewArg.StartsWith ("-center") | |
7741 | || aViewArg.StartsWith ("-at")) | |
7742 | { | |
7743 | aCams[anIndex]->SetCenter (anXYZ); | |
7744 | } | |
7745 | else if (aViewArg.StartsWith ("-up")) | |
7746 | { | |
7747 | aCams[anIndex]->SetUp (anXYZ); | |
7748 | } | |
7749 | } | |
7750 | else | |
7751 | { | |
7752 | anArgIter = aViewArgIter - 1; | |
7753 | break; | |
7754 | } | |
7755 | } | |
7756 | if (!isTrsfSet) | |
7757 | { | |
7758 | std::cout << "Syntax error at " << anArg << ".\n"; | |
7759 | return 1; | |
7760 | } | |
7761 | else if (aViewArgIter >= theArgNb) | |
7762 | { | |
7763 | anArgIter = theArgNb; | |
7764 | } | |
7765 | ||
7766 | aCamAnimation->SetCameraStart(aCams[0]); | |
7767 | aCamAnimation->SetCameraEnd (aCams[1]); | |
197ac94e | 7768 | } |
7769 | else | |
7770 | { | |
1beb58d7 | 7771 | std::cout << "Syntax error at " << anArg << ".\n"; |
7772 | return 1; | |
197ac94e | 7773 | } |
7774 | } | |
1beb58d7 | 7775 | |
08f8a185 | 7776 | if (!toPlay && aRecFile.IsEmpty()) |
197ac94e | 7777 | { |
1beb58d7 | 7778 | return 0; |
7779 | } | |
7780 | ||
7781 | // Start animation timeline and process frame updating. | |
7782 | TheIsAnimating = Standard_True; | |
7783 | const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False); | |
7784 | Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera()); | |
bf7b2ceb | 7785 | anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0); |
1beb58d7 | 7786 | if (isFreeCamera) |
7787 | { | |
7788 | aView->Camera()->Copy (aCameraBack); | |
7789 | } | |
7790 | ||
7791 | const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration; | |
08f8a185 | 7792 | if (aRecParams.FpsNum <= 0) |
1beb58d7 | 7793 | { |
7794 | while (!anAnimation->IsStopped()) | |
197ac94e | 7795 | { |
1beb58d7 | 7796 | aCameraBack->Copy (aView->Camera()); |
7797 | const Standard_Real aPts = anAnimation->UpdateTimer(); | |
7798 | if (isFreeCamera) | |
7799 | { | |
7800 | aView->Camera()->Copy (aCameraBack); | |
7801 | } | |
7802 | ||
7803 | if (aPts >= anUpperPts) | |
7804 | { | |
7805 | anAnimation->Pause(); | |
7806 | break; | |
7807 | } | |
7808 | ||
7809 | if (aView->IsInvalidated()) | |
7810 | { | |
7811 | aView->Redraw(); | |
7812 | } | |
7813 | else | |
7814 | { | |
7815 | aView->RedrawImmediate(); | |
7816 | } | |
7817 | ||
7818 | if (!isLockLoop) | |
7819 | { | |
7820 | // handle user events | |
7821 | theDI.Eval ("after 1 set waiter 1"); | |
7822 | theDI.Eval ("vwait waiter"); | |
7823 | } | |
7824 | if (!TheIsAnimating) | |
7825 | { | |
7826 | anAnimation->Pause(); | |
7827 | theDI << aPts; | |
7828 | break; | |
7829 | } | |
7830 | } | |
7831 | ||
7832 | if (aView->IsInvalidated()) | |
7833 | { | |
7834 | aView->Redraw(); | |
197ac94e | 7835 | } |
7836 | else | |
7837 | { | |
1beb58d7 | 7838 | aView->RedrawImmediate(); |
197ac94e | 7839 | } |
7840 | } | |
1beb58d7 | 7841 | else |
197ac94e | 7842 | { |
bf7b2ceb | 7843 | OSD_Timer aPerfTimer; |
7844 | aPerfTimer.Start(); | |
1beb58d7 | 7845 | |
08f8a185 | 7846 | Handle(Image_VideoRecorder) aRecorder; |
7847 | ImageFlipper aFlipper; | |
7848 | Handle(Draw_ProgressIndicator) aProgress; | |
7849 | if (!aRecFile.IsEmpty()) | |
7850 | { | |
7851 | if (aRecParams.Width <= 0 | |
7852 | || aRecParams.Height <= 0) | |
7853 | { | |
7854 | aView->Window()->Size (aRecParams.Width, aRecParams.Height); | |
7855 | } | |
7856 | ||
7857 | aRecorder = new Image_VideoRecorder(); | |
7858 | if (!aRecorder->Open (aRecFile.ToCString(), aRecParams)) | |
7859 | { | |
7860 | std::cout << "Error: failed to open video file for recording\n"; | |
7861 | return 0; | |
7862 | } | |
7863 | ||
7864 | aProgress = new Draw_ProgressIndicator (theDI, 1); | |
7865 | } | |
7866 | ||
1beb58d7 | 7867 | // Manage frame-rated animation here |
7868 | Standard_Real aPts = aPlayStartTime; | |
bf7b2ceb | 7869 | int64_t aNbFrames = 0; |
08f8a185 | 7870 | Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1); |
7871 | Standard_Integer aSecondsProgress = 0; | |
7872 | for (; aPts <= anUpperPts && aPSentry.More();) | |
197ac94e | 7873 | { |
08f8a185 | 7874 | const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames)); |
bf7b2ceb | 7875 | aPts = aPlayStartTime + aRecPts; |
7876 | ++aNbFrames; | |
1beb58d7 | 7877 | if (!anAnimation->Update (aPts)) |
7878 | { | |
7879 | break; | |
7880 | } | |
7881 | ||
08f8a185 | 7882 | if (!aRecorder.IsNull()) |
7883 | { | |
7884 | V3d_ImageDumpOptions aDumpParams; | |
7885 | aDumpParams.Width = aRecParams.Width; | |
7886 | aDumpParams.Height = aRecParams.Height; | |
7887 | aDumpParams.BufferType = Graphic3d_BT_RGBA; | |
7888 | aDumpParams.StereoOptions = V3d_SDO_MONO; | |
7889 | aDumpParams.ToAdjustAspect = Standard_True; | |
7890 | if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams)) | |
7891 | { | |
7892 | std::cout << "Error: view dump is failed!\n"; | |
7893 | return 0; | |
7894 | } | |
7895 | aFlipper.FlipY (aRecorder->ChangeFrame()); | |
7896 | if (!aRecorder->PushFrame()) | |
7897 | { | |
7898 | return 0; | |
7899 | } | |
7900 | } | |
7901 | else | |
7902 | { | |
7903 | aView->Redraw(); | |
7904 | } | |
7905 | ||
7906 | while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed)) | |
7907 | { | |
7908 | aPSentry.Next(); | |
7909 | ++aSecondsProgress; | |
7910 | } | |
197ac94e | 7911 | } |
bf7b2ceb | 7912 | |
7913 | aPerfTimer.Stop(); | |
1beb58d7 | 7914 | anAnimation->Stop(); |
bf7b2ceb | 7915 | const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime(); |
7916 | theDI << "Average FPS: " << aRecFps << "\n" | |
7917 | << "Nb. Frames: " << Standard_Real(aNbFrames); | |
7918 | ||
7919 | aView->Redraw(); | |
197ac94e | 7920 | } |
7921 | ||
1beb58d7 | 7922 | aView->SetImmediateUpdate (wasImmediateUpdate); |
7923 | TheIsAnimating = Standard_False; | |
4754e164 | 7924 | return 0; |
7925 | } | |
7926 | ||
1beb58d7 | 7927 | |
4754e164 | 7928 | //======================================================================= |
7929 | //function : VChangeSelected | |
dc3fe572 | 7930 | //purpose : Adds the shape to selection or remove one from it |
4754e164 | 7931 | //======================================================================= |
7932 | static Standard_Integer VChangeSelected (Draw_Interpretor& di, | |
7933 | Standard_Integer argc, | |
7934 | const char ** argv) | |
7935 | { | |
7936 | if(argc != 2) | |
7937 | { | |
7938 | di<<"Usage : " << argv[0] << " shape \n"; | |
7939 | return 1; | |
7940 | } | |
7941 | //get AIS_Shape: | |
4754e164 | 7942 | TCollection_AsciiString aName(argv[1]); |
7943 | Handle(AIS_InteractiveObject) anAISObject; | |
8f521168 | 7944 | if (!GetMapOfAIS().Find2 (aName, anAISObject) |
7945 | || anAISObject.IsNull()) | |
4754e164 | 7946 | { |
7947 | di<<"Use 'vdisplay' before"; | |
7948 | return 1; | |
7949 | } | |
4754e164 | 7950 | |
8f521168 | 7951 | ViewerTest::GetAISContext()->AddOrRemoveSelected(anAISObject, Standard_True); |
4754e164 | 7952 | return 0; |
7953 | } | |
7954 | ||
4754e164 | 7955 | //======================================================================= |
7956 | //function : VNbSelected | |
dc3fe572 | 7957 | //purpose : Returns number of selected objects |
4754e164 | 7958 | //======================================================================= |
7959 | static Standard_Integer VNbSelected (Draw_Interpretor& di, | |
7960 | Standard_Integer argc, | |
7961 | const char ** argv) | |
7962 | { | |
7963 | if(argc != 1) | |
7964 | { | |
7965 | di << "Usage : " << argv[0] << "\n"; | |
7966 | return 1; | |
7967 | } | |
7968 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
7969 | if(aContext.IsNull()) | |
7970 | { | |
7971 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
7972 | return 1; | |
7973 | } | |
7974 | di << aContext->NbSelected() << "\n"; | |
7975 | return 0; | |
7976 | } | |
7977 | ||
4754e164 | 7978 | //======================================================================= |
7979 | //function : VPurgeDisplay | |
dc3fe572 | 7980 | //purpose : Switches altialiasing on or off |
4754e164 | 7981 | //======================================================================= |
7982 | static Standard_Integer VPurgeDisplay (Draw_Interpretor& di, | |
7983 | Standard_Integer argc, | |
7984 | const char ** argv) | |
7985 | { | |
eb4320f2 | 7986 | if (argc > 1) |
4754e164 | 7987 | { |
eb4320f2 | 7988 | di << "Usage : " << argv[0] << "\n"; |
4754e164 | 7989 | return 1; |
7990 | } | |
4754e164 | 7991 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
7992 | if (aContext.IsNull()) | |
7993 | { | |
7994 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
7995 | return 1; | |
7996 | } | |
404c8936 | 7997 | |
eb4320f2 | 7998 | di << aContext->PurgeDisplay() << "\n"; |
4754e164 | 7999 | return 0; |
8000 | } | |
8001 | ||
8002 | //======================================================================= | |
8003 | //function : VSetViewSize | |
8004 | //purpose : | |
8005 | //======================================================================= | |
8006 | static Standard_Integer VSetViewSize (Draw_Interpretor& di, | |
8007 | Standard_Integer argc, | |
8008 | const char ** argv) | |
8009 | { | |
8010 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
8011 | if(aContext.IsNull()) | |
8012 | { | |
8013 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
8014 | return 1; | |
8015 | } | |
8016 | if(argc != 2) | |
8017 | { | |
8018 | di<<"Usage : " << argv[0] << " Size\n"; | |
8019 | return 1; | |
8020 | } | |
6b62b2da | 8021 | Standard_Real aSize = Draw::Atof (argv[1]); |
4754e164 | 8022 | if (aSize <= 0.) |
8023 | { | |
8024 | di<<"Bad Size value : " << aSize << "\n"; | |
8025 | return 1; | |
8026 | } | |
8027 | ||
8028 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
8029 | aView->SetSize(aSize); | |
8030 | return 0; | |
8031 | } | |
8032 | ||
8033 | //======================================================================= | |
8034 | //function : VMoveView | |
8035 | //purpose : | |
8036 | //======================================================================= | |
8037 | static Standard_Integer VMoveView (Draw_Interpretor& di, | |
8038 | Standard_Integer argc, | |
8039 | const char ** argv) | |
8040 | { | |
8041 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
8042 | if(aContext.IsNull()) | |
8043 | { | |
8044 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
8045 | return 1; | |
8046 | } | |
8047 | if(argc < 4 || argc > 5) | |
8048 | { | |
8049 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; | |
8050 | return 1; | |
8051 | } | |
6b62b2da | 8052 | Standard_Real Dx = Draw::Atof (argv[1]); |
8053 | Standard_Real Dy = Draw::Atof (argv[2]); | |
8054 | Standard_Real Dz = Draw::Atof (argv[3]); | |
4754e164 | 8055 | Standard_Boolean aStart = Standard_True; |
8056 | if (argc == 5) | |
8057 | { | |
6b62b2da | 8058 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 8059 | } |
8060 | ||
8061 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
8062 | aView->Move(Dx,Dy,Dz,aStart); | |
8063 | return 0; | |
8064 | } | |
8065 | ||
8066 | //======================================================================= | |
8067 | //function : VTranslateView | |
8068 | //purpose : | |
8069 | //======================================================================= | |
8070 | static Standard_Integer VTranslateView (Draw_Interpretor& di, | |
8071 | Standard_Integer argc, | |
8072 | const char ** argv) | |
8073 | { | |
8074 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
8075 | if(aContext.IsNull()) | |
8076 | { | |
8077 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
8078 | return 1; | |
8079 | } | |
8080 | if(argc < 4 || argc > 5) | |
8081 | { | |
8082 | di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n"; | |
8083 | return 1; | |
8084 | } | |
6b62b2da | 8085 | Standard_Real Dx = Draw::Atof (argv[1]); |
8086 | Standard_Real Dy = Draw::Atof (argv[2]); | |
8087 | Standard_Real Dz = Draw::Atof (argv[3]); | |
4754e164 | 8088 | Standard_Boolean aStart = Standard_True; |
dc3fe572 | 8089 | if (argc == 5) |
4754e164 | 8090 | { |
6b62b2da | 8091 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 8092 | } |
8093 | ||
8094 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
8095 | aView->Translate(Dx,Dy,Dz,aStart); | |
8096 | return 0; | |
8097 | } | |
8098 | ||
8099 | //======================================================================= | |
8100 | //function : VTurnView | |
8101 | //purpose : | |
8102 | //======================================================================= | |
8103 | static Standard_Integer VTurnView (Draw_Interpretor& di, | |
8104 | Standard_Integer argc, | |
8105 | const char ** argv) | |
8106 | { | |
8107 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
8108 | if(aContext.IsNull()) { | |
8109 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
8110 | return 1; | |
8111 | } | |
8112 | if(argc < 4 || argc > 5){ | |
8113 | di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n"; | |
8114 | return 1; | |
8115 | } | |
6b62b2da | 8116 | Standard_Real Ax = Draw::Atof (argv[1]); |
8117 | Standard_Real Ay = Draw::Atof (argv[2]); | |
8118 | Standard_Real Az = Draw::Atof (argv[3]); | |
4754e164 | 8119 | Standard_Boolean aStart = Standard_True; |
dc3fe572 | 8120 | if (argc == 5) |
4754e164 | 8121 | { |
6b62b2da | 8122 | aStart = (Draw::Atoi (argv[4]) > 0); |
4754e164 | 8123 | } |
8124 | ||
8125 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
8126 | aView->Turn(Ax,Ay,Az,aStart); | |
8127 | return 0; | |
8128 | } | |
8129 | ||
269294d6 | 8130 | //============================================================================== |
8131 | //function : VTextureEnv | |
8132 | //purpose : ENables or disables environment mapping | |
8133 | //============================================================================== | |
8134 | class OCC_TextureEnv : public Graphic3d_TextureEnv | |
8135 | { | |
8136 | public: | |
8137 | OCC_TextureEnv(const Standard_CString FileName); | |
8138 | OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName); | |
8139 | void SetTextureParameters(const Standard_Boolean theRepeatFlag, | |
8140 | const Standard_Boolean theModulateFlag, | |
8141 | const Graphic3d_TypeOfTextureFilter theFilter, | |
8142 | const Standard_ShortReal theXScale, | |
8143 | const Standard_ShortReal theYScale, | |
8144 | const Standard_ShortReal theXShift, | |
8145 | const Standard_ShortReal theYShift, | |
8146 | const Standard_ShortReal theAngle); | |
68858c7d | 8147 | DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv) |
269294d6 | 8148 | }; |
a3f6f591 | 8149 | DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv) |
ec357c5c | 8150 | |
269294d6 | 8151 | OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName) |
8152 | : Graphic3d_TextureEnv(theFileName) | |
8153 | { | |
8154 | } | |
8155 | ||
8156 | OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId) | |
8157 | : Graphic3d_TextureEnv(theTexId) | |
8158 | { | |
8159 | } | |
8160 | ||
8161 | void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag, | |
8162 | const Standard_Boolean theModulateFlag, | |
8163 | const Graphic3d_TypeOfTextureFilter theFilter, | |
8164 | const Standard_ShortReal theXScale, | |
8165 | const Standard_ShortReal theYScale, | |
8166 | const Standard_ShortReal theXShift, | |
8167 | const Standard_ShortReal theYShift, | |
8168 | const Standard_ShortReal theAngle) | |
8169 | { | |
8170 | myParams->SetRepeat (theRepeatFlag); | |
8171 | myParams->SetModulate (theModulateFlag); | |
8172 | myParams->SetFilter (theFilter); | |
8173 | myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale)); | |
8174 | myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift)); | |
8175 | myParams->SetRotation (theAngle); | |
8176 | } | |
8177 | ||
35e08fe8 | 8178 | static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec) |
269294d6 | 8179 | { |
8180 | // get the active view | |
8181 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
8182 | if (aView.IsNull()) | |
8183 | { | |
8184 | std::cerr << "No active view. Please call vinit.\n"; | |
8185 | return 1; | |
8186 | } | |
8187 | ||
8188 | // Checking the input arguments | |
8189 | Standard_Boolean anEnableFlag = Standard_False; | |
8190 | Standard_Boolean isOk = theArgNb >= 2; | |
8191 | if (isOk) | |
8192 | { | |
8193 | TCollection_AsciiString anEnableOpt(theArgVec[1]); | |
8194 | anEnableFlag = anEnableOpt.IsEqual("on"); | |
8195 | isOk = anEnableFlag || anEnableOpt.IsEqual("off"); | |
8196 | } | |
8197 | if (anEnableFlag) | |
8198 | { | |
8199 | isOk = (theArgNb == 3 || theArgNb == 11); | |
8200 | if (isOk) | |
8201 | { | |
8202 | TCollection_AsciiString aTextureOpt(theArgVec[2]); | |
8203 | isOk = (!aTextureOpt.IsIntegerValue() || | |
8204 | (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN)); | |
8205 | ||
8206 | if (isOk && theArgNb == 11) | |
8207 | { | |
8208 | TCollection_AsciiString aRepeatOpt (theArgVec[3]), | |
8209 | aModulateOpt(theArgVec[4]), | |
8210 | aFilterOpt (theArgVec[5]), | |
8211 | aSScaleOpt (theArgVec[6]), | |
8212 | aTScaleOpt (theArgVec[7]), | |
8213 | aSTransOpt (theArgVec[8]), | |
8214 | aTTransOpt (theArgVec[9]), | |
8215 | anAngleOpt (theArgVec[10]); | |
8216 | isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) && | |
8217 | (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) && | |
8218 | (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) && | |
8219 | aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() && | |
8220 | aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() && | |
8221 | anAngleOpt.IsRealValue()); | |
8222 | } | |
8223 | } | |
8224 | } | |
8225 | ||
8226 | if (!isOk) | |
8227 | { | |
8228 | std::cerr << "Usage :" << std::endl; | |
8229 | std::cerr << theArgVec[0] << " off" << std::endl; | |
8230 | 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; | |
8231 | return 1; | |
8232 | } | |
8233 | ||
8234 | if (anEnableFlag) | |
8235 | { | |
8236 | TCollection_AsciiString aTextureOpt(theArgVec[2]); | |
8237 | Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ? | |
8238 | new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) : | |
8239 | new OCC_TextureEnv(theArgVec[2]); | |
8240 | ||
8241 | if (theArgNb == 11) | |
8242 | { | |
8243 | TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]); | |
8244 | aTexEnv->SetTextureParameters( | |
8245 | aRepeatOpt. IsEqual("repeat"), | |
8246 | aModulateOpt.IsEqual("modulate"), | |
8247 | aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST : | |
8248 | aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR : | |
8249 | Graphic3d_TOTF_TRILINEAR, | |
8250 | (Standard_ShortReal)Draw::Atof(theArgVec[6]), | |
8251 | (Standard_ShortReal)Draw::Atof(theArgVec[7]), | |
8252 | (Standard_ShortReal)Draw::Atof(theArgVec[8]), | |
8253 | (Standard_ShortReal)Draw::Atof(theArgVec[9]), | |
8254 | (Standard_ShortReal)Draw::Atof(theArgVec[10]) | |
8255 | ); | |
8256 | } | |
8257 | aView->SetTextureEnv(aTexEnv); | |
269294d6 | 8258 | } |
8259 | else // Disabling environment mapping | |
8260 | { | |
269294d6 | 8261 | Handle(Graphic3d_TextureEnv) aTexture; |
8262 | aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data | |
8263 | } | |
8264 | ||
8265 | aView->Redraw(); | |
8266 | return 0; | |
8267 | } | |
8268 | ||
3e05329c | 8269 | namespace |
8270 | { | |
8271 | typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes; | |
8272 | ||
8273 | //! Remove registered clipping plane from all views and objects. | |
8274 | static void removePlane (MapOfPlanes& theRegPlanes, | |
8275 | const TCollection_AsciiString& theName) | |
8276 | { | |
8277 | Handle(Graphic3d_ClipPlane) aClipPlane; | |
8278 | if (!theRegPlanes.Find (theName, aClipPlane)) | |
8279 | { | |
8280 | std::cout << "Warning: no such plane.\n"; | |
8281 | return; | |
8282 | } | |
8283 | ||
8284 | theRegPlanes.UnBind (theName); | |
8285 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS()); | |
8286 | anIObjIt.More(); anIObjIt.Next()) | |
8287 | { | |
8f521168 | 8288 | const Handle(AIS_InteractiveObject)& aPrs = anIObjIt.Key1(); |
3e05329c | 8289 | aPrs->RemoveClipPlane (aClipPlane); |
8290 | } | |
8291 | ||
8292 | for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews); | |
8293 | aViewIt.More(); aViewIt.Next()) | |
8294 | { | |
8295 | const Handle(V3d_View)& aView = aViewIt.Key2(); | |
8296 | aView->RemoveClipPlane(aClipPlane); | |
8297 | } | |
8298 | ||
8299 | ViewerTest::RedrawAllViews(); | |
8300 | } | |
8301 | } | |
8302 | ||
4269bd1b | 8303 | //=============================================================================================== |
8304 | //function : VClipPlane | |
8305 | //purpose : | |
8306 | //=============================================================================================== | |
8307 | static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
8308 | { | |
8309 | // use short-cut for created clip planes map of created (or "registered by name") clip planes | |
4269bd1b | 8310 | static MapOfPlanes aRegPlanes; |
8311 | ||
8312 | if (theArgsNb < 2) | |
8313 | { | |
3e05329c | 8314 | for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next()) |
8315 | { | |
8316 | theDi << aPlaneIter.Key() << " "; | |
8317 | } | |
8318 | return 0; | |
4269bd1b | 8319 | } |
8320 | ||
8321 | TCollection_AsciiString aCommand (theArgVec[1]); | |
3e05329c | 8322 | aCommand.LowerCase(); |
8323 | const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView(); | |
8324 | if (anActiveView.IsNull()) | |
8325 | { | |
8326 | std::cout << "Error: no active view.\n"; | |
8327 | return 1; | |
8328 | } | |
4269bd1b | 8329 | |
8330 | // print maximum number of planes for current viewer | |
3e05329c | 8331 | if (aCommand == "-maxplanes" |
8332 | || aCommand == "maxplanes") | |
4269bd1b | 8333 | { |
3e05329c | 8334 | theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit() |
8335 | << " plane slots provided by driver.\n"; | |
4269bd1b | 8336 | return 0; |
8337 | } | |
8338 | ||
8339 | // create / delete plane instance | |
3e05329c | 8340 | if (aCommand == "-create" |
8341 | || aCommand == "create" | |
8342 | || aCommand == "-delete" | |
8343 | || aCommand == "delete" | |
8344 | || aCommand == "-clone" | |
8345 | || aCommand == "clone") | |
4269bd1b | 8346 | { |
8347 | if (theArgsNb < 3) | |
8348 | { | |
3e05329c | 8349 | std::cout << "Syntax error: plane name is required.\n"; |
4269bd1b | 8350 | return 1; |
8351 | } | |
8352 | ||
3e05329c | 8353 | Standard_Boolean toCreate = aCommand == "-create" |
8354 | || aCommand == "create"; | |
8355 | Standard_Boolean toClone = aCommand == "-clone" | |
8356 | || aCommand == "clone"; | |
8357 | Standard_Boolean toDelete = aCommand == "-delete" | |
8358 | || aCommand == "delete"; | |
4269bd1b | 8359 | TCollection_AsciiString aPlane (theArgVec[2]); |
8360 | ||
8361 | if (toCreate) | |
8362 | { | |
8363 | if (aRegPlanes.IsBound (aPlane)) | |
8364 | { | |
3e05329c | 8365 | std::cout << "Warning: existing plane has been overridden.\n"; |
8366 | toDelete = true; | |
8367 | } | |
8368 | else | |
8369 | { | |
8370 | aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane()); | |
8371 | return 0; | |
4269bd1b | 8372 | } |
4269bd1b | 8373 | } |
8374 | else if (toClone) // toClone | |
8375 | { | |
8376 | if (!aRegPlanes.IsBound (aPlane)) | |
8377 | { | |
3e05329c | 8378 | std::cout << "Error: no such plane.\n"; |
4269bd1b | 8379 | return 1; |
8380 | } | |
3e05329c | 8381 | else if (theArgsNb < 4) |
4269bd1b | 8382 | { |
3e05329c | 8383 | std::cout << "Syntax error: enter name for new plane.\n"; |
4269bd1b | 8384 | return 1; |
8385 | } | |
8386 | ||
8387 | TCollection_AsciiString aClone (theArgVec[3]); | |
8388 | if (aRegPlanes.IsBound (aClone)) | |
8389 | { | |
3e05329c | 8390 | std::cout << "Error: plane name is in use.\n"; |
4269bd1b | 8391 | return 1; |
8392 | } | |
8393 | ||
8394 | const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane); | |
8395 | ||
8396 | aRegPlanes.Bind (aClone, aClipPlane->Clone()); | |
3e05329c | 8397 | return 0; |
4269bd1b | 8398 | } |
4269bd1b | 8399 | |
3e05329c | 8400 | if (toDelete) |
8401 | { | |
8402 | if (aPlane == "ALL" | |
8403 | || aPlane == "all" | |
8404 | || aPlane == "*") | |
4269bd1b | 8405 | { |
3e05329c | 8406 | for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();) |
8407 | { | |
8408 | aPlane = aPlaneIter.Key(); | |
8409 | removePlane (aRegPlanes, aPlane); | |
8410 | aPlaneIter = MapOfPlanes::Iterator (aRegPlanes); | |
8411 | } | |
4269bd1b | 8412 | } |
3e05329c | 8413 | else |
4269bd1b | 8414 | { |
3e05329c | 8415 | removePlane (aRegPlanes, aPlane); |
4269bd1b | 8416 | } |
4269bd1b | 8417 | } |
8418 | ||
3e05329c | 8419 | if (toCreate) |
8420 | { | |
8421 | aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane()); | |
8422 | } | |
4269bd1b | 8423 | return 0; |
8424 | } | |
8425 | ||
8426 | // set / unset plane command | |
3e05329c | 8427 | if (aCommand == "set" |
8428 | || aCommand == "unset") | |
4269bd1b | 8429 | { |
3e05329c | 8430 | if (theArgsNb < 5) |
4269bd1b | 8431 | { |
3e05329c | 8432 | std::cout << "Syntax error: need more arguments.\n"; |
4269bd1b | 8433 | return 1; |
8434 | } | |
8435 | ||
3e05329c | 8436 | // redirect to new syntax |
8437 | NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1); | |
8438 | anArgVec.SetValue (1, theArgVec[0]); | |
8439 | anArgVec.SetValue (2, theArgVec[2]); | |
8440 | anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset"); | |
8441 | for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt) | |
4269bd1b | 8442 | { |
3e05329c | 8443 | anArgVec.SetValue (anIt, theArgVec[anIt]); |
4269bd1b | 8444 | } |
8445 | ||
3e05329c | 8446 | return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst()); |
4269bd1b | 8447 | } |
8448 | ||
8449 | // change plane command | |
3e05329c | 8450 | TCollection_AsciiString aPlaneName; |
8451 | Handle(Graphic3d_ClipPlane) aClipPlane; | |
8452 | Standard_Integer anArgIter = 0; | |
8453 | if (aCommand == "-change" | |
8454 | || aCommand == "change") | |
4269bd1b | 8455 | { |
3e05329c | 8456 | // old syntax support |
8457 | if (theArgsNb < 3) | |
4269bd1b | 8458 | { |
3e05329c | 8459 | std::cout << "Syntax error: need more arguments.\n"; |
4269bd1b | 8460 | return 1; |
8461 | } | |
8462 | ||
3e05329c | 8463 | anArgIter = 3; |
8464 | aPlaneName = theArgVec[2]; | |
8465 | if (!aRegPlanes.Find (aPlaneName, aClipPlane)) | |
4269bd1b | 8466 | { |
3e05329c | 8467 | std::cout << "Error: no such plane '" << aPlaneName << "'.\n"; |
4269bd1b | 8468 | return 1; |
8469 | } | |
3e05329c | 8470 | } |
8471 | else if (aRegPlanes.Find (theArgVec[1], aClipPlane)) | |
8472 | { | |
8473 | anArgIter = 2; | |
8474 | aPlaneName = theArgVec[1]; | |
8475 | } | |
8476 | else | |
8477 | { | |
8478 | anArgIter = 2; | |
8479 | aPlaneName = theArgVec[1]; | |
8480 | aClipPlane = new Graphic3d_ClipPlane(); | |
8481 | aRegPlanes.Bind (aPlaneName, aClipPlane); | |
8482 | theDi << "Created new plane " << aPlaneName << ".\n"; | |
8483 | } | |
4269bd1b | 8484 | |
3e05329c | 8485 | if (theArgsNb - anArgIter < 1) |
8486 | { | |
8487 | std::cout << "Syntax error: need more arguments.\n"; | |
8488 | return 1; | |
8489 | } | |
4269bd1b | 8490 | |
3e05329c | 8491 | for (; anArgIter < theArgsNb; ++anArgIter) |
8492 | { | |
8493 | const char** aChangeArgs = theArgVec + anArgIter; | |
8494 | Standard_Integer aNbChangeArgs = theArgsNb - anArgIter; | |
8495 | TCollection_AsciiString aChangeArg (aChangeArgs[0]); | |
8496 | aChangeArg.LowerCase(); | |
4269bd1b | 8497 | |
3e05329c | 8498 | Standard_Boolean toEnable = Standard_True; |
8499 | if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable)) | |
4269bd1b | 8500 | { |
3e05329c | 8501 | aClipPlane->SetOn (toEnable); |
4269bd1b | 8502 | } |
25c35042 | 8503 | else if (aChangeArg.StartsWith ("-equation") |
8504 | || aChangeArg.StartsWith ("equation")) | |
4269bd1b | 8505 | { |
3e05329c | 8506 | if (aNbChangeArgs < 5) |
4269bd1b | 8507 | { |
3e05329c | 8508 | std::cout << "Syntax error: need more arguments.\n"; |
4269bd1b | 8509 | return 1; |
8510 | } | |
8511 | ||
25c35042 | 8512 | Standard_Integer aSubIndex = 1; |
8513 | Standard_Integer aPrefixLen = 8 + (aChangeArg.Value (1) == '-' ? 1 : 0); | |
8514 | if (aPrefixLen < aChangeArg.Length()) | |
8515 | { | |
8516 | TCollection_AsciiString aSubStr = aChangeArg.SubString (aPrefixLen + 1, aChangeArg.Length()); | |
8517 | if (!aSubStr.IsIntegerValue() | |
8518 | || aSubStr.IntegerValue() <= 0) | |
8519 | { | |
8520 | std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n"; | |
8521 | return 1; | |
8522 | } | |
8523 | aSubIndex = aSubStr.IntegerValue(); | |
8524 | } | |
8525 | ||
8526 | Standard_Real aCoeffA = Draw::Atof (aChangeArgs[1]); | |
8527 | Standard_Real aCoeffB = Draw::Atof (aChangeArgs[2]); | |
8528 | Standard_Real aCoeffC = Draw::Atof (aChangeArgs[3]); | |
8529 | Standard_Real aCoeffD = Draw::Atof (aChangeArgs[4]); | |
8530 | Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane; | |
8531 | for (Standard_Integer aSubPlaneIter = 1; aSubPlaneIter < aSubIndex; ++aSubPlaneIter) | |
8532 | { | |
8533 | if (aSubPln->ChainNextPlane().IsNull()) | |
8534 | { | |
8535 | aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln)); | |
8536 | } | |
8537 | aSubPln = aSubPln->ChainNextPlane(); | |
8538 | } | |
8539 | aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)()); | |
8540 | aSubPln->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD)); | |
3e05329c | 8541 | anArgIter += 4; |
4269bd1b | 8542 | } |
25c35042 | 8543 | else if ((aChangeArg == "-boxinterior" |
8544 | || aChangeArg == "-boxint" | |
8545 | || aChangeArg == "-box") | |
8546 | && aNbChangeArgs >= 7) | |
8547 | { | |
8548 | Graphic3d_BndBox3d aBndBox; | |
8549 | aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[1]), Draw::Atof (aChangeArgs[2]), Draw::Atof (aChangeArgs[3]))); | |
8550 | aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[4]), Draw::Atof (aChangeArgs[5]), Draw::Atof (aChangeArgs[6]))); | |
8551 | anArgIter += 6; | |
8552 | ||
8553 | Standard_Integer aNbSubPlanes = 6; | |
8554 | const Graphic3d_Vec3d aDirArray[6] = | |
8555 | { | |
8556 | Graphic3d_Vec3d (-1, 0, 0), | |
8557 | Graphic3d_Vec3d ( 1, 0, 0), | |
8558 | Graphic3d_Vec3d ( 0,-1, 0), | |
8559 | Graphic3d_Vec3d ( 0, 1, 0), | |
8560 | Graphic3d_Vec3d ( 0, 0,-1), | |
8561 | Graphic3d_Vec3d ( 0, 0, 1), | |
8562 | }; | |
8563 | Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane; | |
8564 | for (Standard_Integer aSubPlaneIter = 0; aSubPlaneIter < aNbSubPlanes; ++aSubPlaneIter) | |
8565 | { | |
8566 | const Graphic3d_Vec3d& aDir = aDirArray[aSubPlaneIter]; | |
8567 | const Standard_Real aW = -aDir.Dot ((aSubPlaneIter % 2 == 1) ? aBndBox.CornerMax() : aBndBox.CornerMin()); | |
8568 | aSubPln->SetEquation (gp_Pln (aDir.x(), aDir.y(), aDir.z(), aW)); | |
8569 | if (aSubPlaneIter + 1 == aNbSubPlanes) | |
8570 | { | |
8571 | aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)()); | |
8572 | } | |
8573 | else | |
8574 | { | |
8575 | aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln)); | |
8576 | } | |
8577 | aSubPln = aSubPln->ChainNextPlane(); | |
8578 | } | |
8579 | } | |
3e05329c | 8580 | else if (aChangeArg == "-capping" |
8581 | || aChangeArg == "capping") | |
4269bd1b | 8582 | { |
3e05329c | 8583 | if (aNbChangeArgs < 2) |
4269bd1b | 8584 | { |
3e05329c | 8585 | std::cout << "Syntax error: need more arguments.\n"; |
4269bd1b | 8586 | return 1; |
8587 | } | |
8588 | ||
3e05329c | 8589 | if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) |
4269bd1b | 8590 | { |
3e05329c | 8591 | aClipPlane->SetCapping (toEnable); |
8592 | anArgIter += 1; | |
8593 | } | |
8594 | else | |
8595 | { | |
8596 | // just skip otherwise (old syntax) | |
8597 | } | |
8598 | } | |
8599 | else if (aChangeArg == "-useobjectmaterial" | |
8600 | || aChangeArg == "-useobjectmat" | |
8601 | || aChangeArg == "-useobjmat" | |
8602 | || aChangeArg == "-useobjmaterial") | |
8603 | { | |
8604 | if (aNbChangeArgs < 2) | |
8605 | { | |
8606 | std::cout << "Syntax error: need more arguments.\n"; | |
4269bd1b | 8607 | return 1; |
8608 | } | |
8609 | ||
3e05329c | 8610 | if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) |
4269bd1b | 8611 | { |
3e05329c | 8612 | aClipPlane->SetUseObjectMaterial (toEnable == Standard_True); |
8613 | anArgIter += 1; | |
4269bd1b | 8614 | } |
3e05329c | 8615 | } |
8616 | else if (aChangeArg == "-useobjecttexture" | |
8617 | || aChangeArg == "-useobjecttex" | |
8618 | || aChangeArg == "-useobjtexture" | |
8619 | || aChangeArg == "-useobjtex") | |
8620 | { | |
8621 | if (aNbChangeArgs < 2) | |
4269bd1b | 8622 | { |
3e05329c | 8623 | std::cout << "Syntax error: need more arguments.\n"; |
8624 | return 1; | |
8625 | } | |
4269bd1b | 8626 | |
3e05329c | 8627 | if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) |
8628 | { | |
8629 | aClipPlane->SetUseObjectTexture (toEnable == Standard_True); | |
8630 | anArgIter += 1; | |
8631 | } | |
8632 | } | |
8633 | else if (aChangeArg == "-useobjectshader" | |
8634 | || aChangeArg == "-useobjshader") | |
8635 | { | |
8636 | if (aNbChangeArgs < 2) | |
8637 | { | |
8638 | std::cout << "Syntax error: need more arguments.\n"; | |
8639 | return 1; | |
8640 | } | |
4269bd1b | 8641 | |
3e05329c | 8642 | if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable)) |
8643 | { | |
8644 | aClipPlane->SetUseObjectShader (toEnable == Standard_True); | |
8645 | anArgIter += 1; | |
4269bd1b | 8646 | } |
3e05329c | 8647 | } |
8648 | else if (aChangeArg == "-color" | |
8649 | || aChangeArg == "color") | |
8650 | { | |
8651 | Quantity_Color aColor; | |
8652 | Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1, | |
8653 | aChangeArgs + 1, | |
8654 | aColor); | |
8655 | if (aNbParsed == 0) | |
4269bd1b | 8656 | { |
3e05329c | 8657 | std::cout << "Syntax error: need more arguments.\n"; |
8658 | return 1; | |
8659 | } | |
4269bd1b | 8660 | |
3e05329c | 8661 | Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial(); |
8662 | aMat.SetAmbientColor (aColor); | |
8663 | aMat.SetDiffuseColor (aColor); | |
8664 | aClipPlane->SetCappingMaterial (aMat); | |
8665 | anArgIter += aNbParsed; | |
8666 | } | |
1b661a81 | 8667 | else if ((aChangeArg == "-transparency" |
8668 | || aChangeArg == "-transp") | |
8669 | && aNbChangeArgs >= 2) | |
8670 | { | |
8671 | TCollection_AsciiString aValStr (aChangeArgs[1]); | |
8672 | Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect(); | |
8673 | if (aValStr.IsRealValue()) | |
8674 | { | |
8675 | Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial(); | |
8676 | aMat.SetTransparency ((float )aValStr.RealValue()); | |
8677 | anAspect->SetAlphaMode (Graphic3d_AlphaMode_BlendAuto); | |
8678 | aClipPlane->SetCappingMaterial (aMat); | |
8679 | } | |
8680 | else | |
8681 | { | |
8682 | aValStr.LowerCase(); | |
8683 | Graphic3d_AlphaMode aMode = Graphic3d_AlphaMode_BlendAuto; | |
8684 | if (aValStr == "opaque") | |
8685 | { | |
8686 | aMode = Graphic3d_AlphaMode_Opaque; | |
8687 | } | |
8688 | else if (aValStr == "mask") | |
8689 | { | |
8690 | aMode = Graphic3d_AlphaMode_Mask; | |
8691 | } | |
8692 | else if (aValStr == "blend") | |
8693 | { | |
8694 | aMode = Graphic3d_AlphaMode_Blend; | |
8695 | } | |
8696 | else if (aValStr == "blendauto") | |
8697 | { | |
8698 | aMode = Graphic3d_AlphaMode_BlendAuto; | |
8699 | } | |
8700 | else | |
8701 | { | |
8702 | std::cout << "Syntax error at '" << aValStr << "'\n"; | |
8703 | return 1; | |
8704 | } | |
8705 | anAspect->SetAlphaMode (aMode); | |
8706 | aClipPlane->SetCappingAspect (anAspect); | |
8707 | } | |
8708 | anArgIter += 1; | |
8709 | } | |
3e05329c | 8710 | else if (aChangeArg == "-texname" |
8711 | || aChangeArg == "texname") | |
8712 | { | |
8713 | if (aNbChangeArgs < 2) | |
8714 | { | |
8715 | std::cout << "Syntax error: need more arguments.\n"; | |
8716 | return 1; | |
8717 | } | |
4269bd1b | 8718 | |
3e05329c | 8719 | TCollection_AsciiString aTextureName (aChangeArgs[1]); |
8720 | Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName); | |
8721 | if (!aTexture->IsDone()) | |
8722 | { | |
8723 | aClipPlane->SetCappingTexture (NULL); | |
4269bd1b | 8724 | } |
3e05329c | 8725 | else |
4269bd1b | 8726 | { |
3e05329c | 8727 | aTexture->EnableModulate(); |
8728 | aTexture->EnableRepeat(); | |
8729 | aClipPlane->SetCappingTexture (aTexture); | |
8730 | } | |
8731 | anArgIter += 1; | |
8732 | } | |
8733 | else if (aChangeArg == "-texscale" | |
8734 | || aChangeArg == "texscale") | |
8735 | { | |
8736 | if (aClipPlane->CappingTexture().IsNull()) | |
8737 | { | |
8738 | std::cout << "Error: no texture is set.\n"; | |
8739 | return 1; | |
8740 | } | |
4269bd1b | 8741 | |
3e05329c | 8742 | if (aNbChangeArgs < 3) |
8743 | { | |
8744 | std::cout << "Syntax error: need more arguments.\n"; | |
8745 | return 1; | |
8746 | } | |
4269bd1b | 8747 | |
3e05329c | 8748 | Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); |
8749 | Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]); | |
8750 | aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy)); | |
8751 | anArgIter += 2; | |
8752 | } | |
8753 | else if (aChangeArg == "-texorigin" | |
8754 | || aChangeArg == "texorigin") // texture origin | |
8755 | { | |
8756 | if (aClipPlane->CappingTexture().IsNull()) | |
8757 | { | |
8758 | std::cout << "Error: no texture is set.\n"; | |
8759 | return 1; | |
8760 | } | |
4269bd1b | 8761 | |
3e05329c | 8762 | if (aNbChangeArgs < 3) |
8763 | { | |
8764 | std::cout << "Syntax error: need more arguments.\n"; | |
8765 | return 1; | |
4269bd1b | 8766 | } |
3e05329c | 8767 | |
8768 | Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); | |
8769 | Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]); | |
8770 | ||
8771 | aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy)); | |
8772 | anArgIter += 2; | |
8773 | } | |
8774 | else if (aChangeArg == "-texrotate" | |
8775 | || aChangeArg == "texrotate") // texture rotation | |
8776 | { | |
8777 | if (aClipPlane->CappingTexture().IsNull()) | |
4269bd1b | 8778 | { |
3e05329c | 8779 | std::cout << "Error: no texture is set.\n"; |
8780 | return 1; | |
8781 | } | |
4269bd1b | 8782 | |
3e05329c | 8783 | if (aNbChangeArgs < 2) |
8784 | { | |
8785 | std::cout << "Syntax error: need more arguments.\n"; | |
8786 | return 1; | |
8787 | } | |
4269bd1b | 8788 | |
3e05329c | 8789 | Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]); |
8790 | aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot); | |
8791 | anArgIter += 1; | |
8792 | } | |
8793 | else if (aChangeArg == "-hatch" | |
8794 | || aChangeArg == "hatch") | |
8795 | { | |
8796 | if (aNbChangeArgs < 2) | |
8797 | { | |
8798 | std::cout << "Syntax error: need more arguments.\n"; | |
8799 | return 1; | |
8800 | } | |
4269bd1b | 8801 | |
3e05329c | 8802 | TCollection_AsciiString aHatchStr (aChangeArgs[1]); |
8803 | aHatchStr.LowerCase(); | |
8804 | if (aHatchStr == "on") | |
8805 | { | |
8806 | aClipPlane->SetCappingHatchOn(); | |
8807 | } | |
8808 | else if (aHatchStr == "off") | |
8809 | { | |
8810 | aClipPlane->SetCappingHatchOff(); | |
4269bd1b | 8811 | } |
3e05329c | 8812 | else |
4269bd1b | 8813 | { |
3e05329c | 8814 | aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1])); |
8815 | } | |
8816 | anArgIter += 1; | |
8817 | } | |
8818 | else if (aChangeArg == "-delete" | |
8819 | || aChangeArg == "delete") | |
8820 | { | |
8821 | removePlane (aRegPlanes, aPlaneName); | |
8822 | return 0; | |
8823 | } | |
8824 | else if (aChangeArg == "-set" | |
32ca7711 | 8825 | || aChangeArg == "-unset" |
8826 | || aChangeArg == "-setoverrideglobal") | |
3e05329c | 8827 | { |
8828 | // set / unset plane command | |
32ca7711 | 8829 | const Standard_Boolean toSet = aChangeArg.StartsWith ("-set"); |
8830 | const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal"; | |
3e05329c | 8831 | Standard_Integer anIt = 1; |
8832 | for (; anIt < aNbChangeArgs; ++anIt) | |
8833 | { | |
8834 | TCollection_AsciiString anEntityName (aChangeArgs[anIt]); | |
8835 | if (anEntityName.IsEmpty() | |
8836 | || anEntityName.Value (1) == '-') | |
4269bd1b | 8837 | { |
3e05329c | 8838 | break; |
4269bd1b | 8839 | } |
32ca7711 | 8840 | else if (!toOverrideGlobal |
8841 | && ViewerTest_myViews.IsBound1 (anEntityName)) | |
4269bd1b | 8842 | { |
3e05329c | 8843 | Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName); |
8844 | if (toSet) | |
8845 | { | |
8846 | aView->AddClipPlane (aClipPlane); | |
8847 | } | |
8848 | else | |
8849 | { | |
8850 | aView->RemoveClipPlane (aClipPlane); | |
8851 | } | |
8852 | continue; | |
4269bd1b | 8853 | } |
3e05329c | 8854 | else if (GetMapOfAIS().IsBound2 (anEntityName)) |
4269bd1b | 8855 | { |
8f521168 | 8856 | Handle(AIS_InteractiveObject) aIObj = GetMapOfAIS().Find2 (anEntityName); |
3e05329c | 8857 | if (toSet) |
8858 | { | |
8859 | aIObj->AddClipPlane (aClipPlane); | |
8860 | } | |
8861 | else | |
8862 | { | |
8863 | aIObj->RemoveClipPlane (aClipPlane); | |
8864 | } | |
32ca7711 | 8865 | if (!aIObj->ClipPlanes().IsNull()) |
8866 | { | |
8867 | aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal); | |
8868 | } | |
4269bd1b | 8869 | } |
3e05329c | 8870 | else |
4269bd1b | 8871 | { |
3e05329c | 8872 | std::cout << "Error: object/view '" << anEntityName << "' is not found!\n"; |
8873 | return 1; | |
4269bd1b | 8874 | } |
3e05329c | 8875 | } |
8876 | ||
8877 | if (anIt == 1) | |
8878 | { | |
8879 | // apply to active view | |
8880 | if (toSet) | |
4269bd1b | 8881 | { |
3e05329c | 8882 | anActiveView->AddClipPlane (aClipPlane); |
4269bd1b | 8883 | } |
8884 | else | |
8885 | { | |
3e05329c | 8886 | anActiveView->RemoveClipPlane (aClipPlane); |
4269bd1b | 8887 | } |
8888 | } | |
3e05329c | 8889 | else |
8890 | { | |
8891 | anArgIter = anArgIter + anIt - 1; | |
8892 | } | |
8893 | } | |
8894 | else | |
8895 | { | |
8896 | std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n"; | |
8897 | return 1; | |
4269bd1b | 8898 | } |
4269bd1b | 8899 | } |
8900 | ||
3e05329c | 8901 | ViewerTest::RedrawAllViews(); |
8902 | return 0; | |
4269bd1b | 8903 | } |
8904 | ||
b5ac8292 | 8905 | //=============================================================================================== |
8906 | //function : VZRange | |
8907 | //purpose : | |
8908 | //=============================================================================================== | |
8909 | static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
8910 | { | |
197ac94e | 8911 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
8912 | ||
8913 | if (aCurrentView.IsNull()) | |
b5ac8292 | 8914 | { |
197ac94e | 8915 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; |
b5ac8292 | 8916 | return 1; |
8917 | } | |
8918 | ||
197ac94e | 8919 | Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera(); |
b5ac8292 | 8920 | |
8921 | if (theArgsNb < 2) | |
8922 | { | |
8923 | theDi << "ZNear: " << aCamera->ZNear() << "\n"; | |
8924 | theDi << "ZFar: " << aCamera->ZFar() << "\n"; | |
8925 | return 0; | |
8926 | } | |
8927 | ||
8928 | if (theArgsNb == 3) | |
8929 | { | |
6b62b2da | 8930 | Standard_Real aNewZNear = Draw::Atof (theArgVec[1]); |
8931 | Standard_Real aNewZFar = Draw::Atof (theArgVec[2]); | |
197ac94e | 8932 | |
8933 | if (aNewZNear >= aNewZFar) | |
8934 | { | |
8935 | std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n"; | |
8936 | return 1; | |
8937 | } | |
8938 | ||
8939 | if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0)) | |
8940 | { | |
8941 | std::cout << theArgVec[0] << ": invalid arguments: "; | |
8942 | std::cout << "znear, zfar should be positive for perspective camera.\n"; | |
8943 | return 1; | |
8944 | } | |
8945 | ||
8946 | aCamera->SetZRange (aNewZNear, aNewZFar); | |
b5ac8292 | 8947 | } |
8948 | else | |
8949 | { | |
197ac94e | 8950 | std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n"; |
b5ac8292 | 8951 | return 1; |
8952 | } | |
8953 | ||
197ac94e | 8954 | aCurrentView->Redraw(); |
8955 | ||
b5ac8292 | 8956 | return 0; |
8957 | } | |
8958 | ||
8959 | //=============================================================================================== | |
8960 | //function : VAutoZFit | |
8961 | //purpose : | |
8962 | //=============================================================================================== | |
8963 | static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) | |
8964 | { | |
197ac94e | 8965 | const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView(); |
8966 | ||
8967 | if (aCurrentView.IsNull()) | |
b5ac8292 | 8968 | { |
197ac94e | 8969 | std::cout << theArgVec[0] << ": Call vinit before this command, please.\n"; |
b5ac8292 | 8970 | return 1; |
8971 | } | |
8972 | ||
c357e426 | 8973 | Standard_Real aScale = aCurrentView->AutoZFitScaleFactor(); |
197ac94e | 8974 | |
8975 | if (theArgsNb > 3) | |
b5ac8292 | 8976 | { |
197ac94e | 8977 | std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n"; |
8978 | return 1; | |
b5ac8292 | 8979 | } |
8980 | ||
197ac94e | 8981 | if (theArgsNb < 2) |
b5ac8292 | 8982 | { |
586db386 | 8983 | theDi << "Auto z-fit mode: \n" |
c357e426 | 8984 | << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n" |
197ac94e | 8985 | << "Scale: " << aScale << "\n"; |
8986 | return 0; | |
b5ac8292 | 8987 | } |
197ac94e | 8988 | |
8989 | Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1; | |
8990 | ||
8991 | if (theArgsNb >= 3) | |
b5ac8292 | 8992 | { |
197ac94e | 8993 | aScale = Draw::Atoi (theArgVec[2]); |
b5ac8292 | 8994 | } |
8995 | ||
c357e426 | 8996 | aCurrentView->SetAutoZFitMode (isOn, aScale); |
8997 | aCurrentView->AutoZFit(); | |
197ac94e | 8998 | aCurrentView->Redraw(); |
8999 | ||
b5ac8292 | 9000 | return 0; |
9001 | } | |
9002 | ||
6b62b2da | 9003 | //! Auxiliary function to print projection type |
9004 | inline const char* projTypeName (Graphic3d_Camera::Projection theProjType) | |
9005 | { | |
9006 | switch (theProjType) | |
9007 | { | |
9008 | case Graphic3d_Camera::Projection_Orthographic: return "orthographic"; | |
9009 | case Graphic3d_Camera::Projection_Perspective: return "perspective"; | |
9010 | case Graphic3d_Camera::Projection_Stereo: return "stereoscopic"; | |
9011 | case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye"; | |
9012 | case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye"; | |
9013 | } | |
9014 | return "UNKNOWN"; | |
9015 | } | |
9016 | ||
b5ac8292 | 9017 | //=============================================================================================== |
6b62b2da | 9018 | //function : VCamera |
b5ac8292 | 9019 | //purpose : |
9020 | //=============================================================================================== | |
6b62b2da | 9021 | static int VCamera (Draw_Interpretor& theDI, |
9022 | Standard_Integer theArgsNb, | |
9023 | const char** theArgVec) | |
b5ac8292 | 9024 | { |
6b62b2da | 9025 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
9026 | if (aView.IsNull()) | |
b5ac8292 | 9027 | { |
6b62b2da | 9028 | std::cout << "Error: no active view.\n"; |
b5ac8292 | 9029 | return 1; |
9030 | } | |
9031 | ||
6b62b2da | 9032 | Handle(Graphic3d_Camera) aCamera = aView->Camera(); |
9033 | if (theArgsNb < 2) | |
b5ac8292 | 9034 | { |
6b62b2da | 9035 | theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n"; |
9036 | theDI << "FOVy: " << aCamera->FOVy() << "\n"; | |
9037 | theDI << "Distance: " << aCamera->Distance() << "\n"; | |
9038 | theDI << "IOD: " << aCamera->IOD() << "\n"; | |
9039 | theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n"; | |
9040 | theDI << "ZFocus: " << aCamera->ZFocus() << "\n"; | |
9041 | theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n"; | |
9042 | return 0; | |
b5ac8292 | 9043 | } |
9044 | ||
30a1b24e | 9045 | TCollection_AsciiString aPrsName; |
6b62b2da | 9046 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) |
b5ac8292 | 9047 | { |
6b62b2da | 9048 | Standard_CString anArg = theArgVec[anArgIter]; |
9049 | TCollection_AsciiString anArgCase (anArg); | |
9050 | anArgCase.LowerCase(); | |
9051 | if (anArgCase == "-proj" | |
9052 | || anArgCase == "-projection" | |
9053 | || anArgCase == "-projtype" | |
9054 | || anArgCase == "-projectiontype") | |
9055 | { | |
9056 | theDI << projTypeName (aCamera->ProjectionType()) << " "; | |
9057 | } | |
9058 | else if (anArgCase == "-ortho" | |
9059 | || anArgCase == "-orthographic") | |
b5ac8292 | 9060 | { |
9061 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic); | |
6b62b2da | 9062 | } |
9063 | else if (anArgCase == "-persp" | |
9064 | || anArgCase == "-perspective" | |
9065 | || anArgCase == "-perspmono" | |
9066 | || anArgCase == "-perspectivemono" | |
9067 | || anArgCase == "-mono") | |
b5ac8292 | 9068 | { |
9069 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective); | |
9070 | } | |
6b62b2da | 9071 | else if (anArgCase == "-stereo" |
9072 | || anArgCase == "-stereoscopic" | |
9073 | || anArgCase == "-perspstereo" | |
9074 | || anArgCase == "-perspectivestereo") | |
9075 | { | |
9076 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo); | |
9077 | } | |
9078 | else if (anArgCase == "-left" | |
9079 | || anArgCase == "-lefteye" | |
9080 | || anArgCase == "-monoleft" | |
9081 | || anArgCase == "-monolefteye" | |
9082 | || anArgCase == "-perpsleft" | |
9083 | || anArgCase == "-perpslefteye") | |
b5ac8292 | 9084 | { |
9085 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye); | |
9086 | } | |
6b62b2da | 9087 | else if (anArgCase == "-right" |
9088 | || anArgCase == "-righteye" | |
9089 | || anArgCase == "-monoright" | |
9090 | || anArgCase == "-monorighteye" | |
9091 | || anArgCase == "-perpsright") | |
b5ac8292 | 9092 | { |
9093 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye); | |
9094 | } | |
6b62b2da | 9095 | else if (anArgCase == "-dist" |
9096 | || anArgCase == "-distance") | |
b5ac8292 | 9097 | { |
6b62b2da | 9098 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
9099 | if (anArgValue != NULL | |
9100 | && *anArgValue != '-') | |
9101 | { | |
9102 | ++anArgIter; | |
9103 | aCamera->SetDistance (Draw::Atof (anArgValue)); | |
9104 | continue; | |
9105 | } | |
9106 | theDI << aCamera->Distance() << " "; | |
b5ac8292 | 9107 | } |
6b62b2da | 9108 | else if (anArgCase == "-iod") |
b5ac8292 | 9109 | { |
6b62b2da | 9110 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
9111 | if (anArgValue != NULL | |
9112 | && *anArgValue != '-') | |
9113 | { | |
9114 | ++anArgIter; | |
9115 | aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue)); | |
9116 | continue; | |
9117 | } | |
9118 | theDI << aCamera->IOD() << " "; | |
b5ac8292 | 9119 | } |
6b62b2da | 9120 | else if (anArgCase == "-iodtype") |
b5ac8292 | 9121 | { |
6b62b2da | 9122 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : ""; |
9123 | TCollection_AsciiString anValueCase (anArgValue); | |
9124 | anValueCase.LowerCase(); | |
9125 | if (anValueCase == "abs" | |
9126 | || anValueCase == "absolute") | |
9127 | { | |
9128 | ++anArgIter; | |
9129 | aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD()); | |
9130 | continue; | |
9131 | } | |
9132 | else if (anValueCase == "rel" | |
9133 | || anValueCase == "relative") | |
9134 | { | |
9135 | ++anArgIter; | |
9136 | aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD()); | |
9137 | continue; | |
9138 | } | |
9139 | else if (*anArgValue != '-') | |
9140 | { | |
9141 | std::cout << "Error: unknown IOD type '" << anArgValue << "'\n"; | |
9142 | return 1; | |
9143 | } | |
9144 | switch (aCamera->GetIODType()) | |
9145 | { | |
9146 | case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break; | |
9147 | case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break; | |
9148 | } | |
b5ac8292 | 9149 | } |
6b62b2da | 9150 | else if (anArgCase == "-zfocus") |
b5ac8292 | 9151 | { |
6b62b2da | 9152 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
9153 | if (anArgValue != NULL | |
9154 | && *anArgValue != '-') | |
9155 | { | |
9156 | ++anArgIter; | |
9157 | aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue)); | |
9158 | continue; | |
9159 | } | |
9160 | theDI << aCamera->ZFocus() << " "; | |
b5ac8292 | 9161 | } |
6b62b2da | 9162 | else if (anArgCase == "-zfocustype") |
b5ac8292 | 9163 | { |
6b62b2da | 9164 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : ""; |
9165 | TCollection_AsciiString anValueCase (anArgValue); | |
9166 | anValueCase.LowerCase(); | |
9167 | if (anValueCase == "abs" | |
9168 | || anValueCase == "absolute") | |
9169 | { | |
9170 | ++anArgIter; | |
9171 | aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus()); | |
9172 | continue; | |
9173 | } | |
9174 | else if (anValueCase == "rel" | |
9175 | || anValueCase == "relative") | |
9176 | { | |
9177 | ++anArgIter; | |
9178 | aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus()); | |
9179 | continue; | |
9180 | } | |
9181 | else if (*anArgValue != '-') | |
9182 | { | |
9183 | std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n"; | |
9184 | return 1; | |
9185 | } | |
9186 | switch (aCamera->ZFocusType()) | |
9187 | { | |
9188 | case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break; | |
9189 | case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break; | |
9190 | } | |
9191 | } | |
9192 | else if (anArgCase == "-fov" | |
9193 | || anArgCase == "-fovy") | |
b5ac8292 | 9194 | { |
6b62b2da | 9195 | Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL; |
9196 | if (anArgValue != NULL | |
9197 | && *anArgValue != '-') | |
9198 | { | |
9199 | ++anArgIter; | |
9200 | aCamera->SetFOVy (Draw::Atof (anArgValue)); | |
9201 | continue; | |
9202 | } | |
9203 | theDI << aCamera->FOVy() << " "; | |
b5ac8292 | 9204 | } |
30a1b24e | 9205 | else if (aPrsName.IsEmpty() |
9206 | && !anArgCase.StartsWith ("-")) | |
9207 | { | |
9208 | aPrsName = anArg; | |
9209 | } | |
b5ac8292 | 9210 | else |
9211 | { | |
6b62b2da | 9212 | std::cout << "Error: unknown argument '" << anArg << "'\n"; |
b5ac8292 | 9213 | return 1; |
9214 | } | |
9215 | } | |
b5ac8292 | 9216 | |
30a1b24e | 9217 | if (aPrsName.IsEmpty() |
9218 | || theArgsNb > 2) | |
9219 | { | |
9220 | aView->AutoZFit(); | |
9221 | aView->Redraw(); | |
9222 | } | |
9223 | ||
9224 | if (!aPrsName.IsEmpty()) | |
9225 | { | |
9226 | Handle(AIS_CameraFrustum) aCameraFrustum; | |
9227 | if (GetMapOfAIS().IsBound2 (aPrsName)) | |
9228 | { | |
9229 | // find existing object | |
9230 | aCameraFrustum = Handle(AIS_CameraFrustum)::DownCast (GetMapOfAIS().Find2 (theArgVec[1])); | |
9231 | if (aCameraFrustum.IsNull()) | |
9232 | { | |
9233 | std::cout << "Error: object '" << aPrsName << "'is already defined and is not a camera frustum!\n"; | |
9234 | return 1; | |
9235 | } | |
9236 | } | |
9237 | ||
9238 | if (aCameraFrustum.IsNull()) | |
9239 | { | |
9240 | aCameraFrustum = new AIS_CameraFrustum(); | |
9241 | } | |
9242 | else | |
9243 | { | |
9244 | // not include displayed object of old camera frustum in the new one. | |
9245 | ViewerTest::GetAISContext()->Erase (aCameraFrustum, false); | |
9246 | aView->ZFitAll(); | |
9247 | } | |
9248 | aCameraFrustum->SetCameraFrustum (aView->Camera()); | |
9249 | ||
9250 | ViewerTest::Display (aPrsName, aCameraFrustum); | |
9251 | } | |
b5ac8292 | 9252 | |
9253 | return 0; | |
9254 | } | |
9255 | ||
f978241f | 9256 | //! Parse stereo output mode |
9257 | inline Standard_Boolean parseStereoMode (Standard_CString theArg, | |
9258 | Graphic3d_StereoMode& theMode) | |
9259 | { | |
9260 | TCollection_AsciiString aFlag (theArg); | |
9261 | aFlag.LowerCase(); | |
9262 | if (aFlag == "quadbuffer") | |
9263 | { | |
9264 | theMode = Graphic3d_StereoMode_QuadBuffer; | |
9265 | } | |
9266 | else if (aFlag == "anaglyph") | |
9267 | { | |
9268 | theMode = Graphic3d_StereoMode_Anaglyph; | |
9269 | } | |
9270 | else if (aFlag == "row" | |
9271 | || aFlag == "rowinterlaced") | |
9272 | { | |
9273 | theMode = Graphic3d_StereoMode_RowInterlaced; | |
9274 | } | |
9275 | else if (aFlag == "col" | |
9276 | || aFlag == "colinterlaced" | |
9277 | || aFlag == "columninterlaced") | |
9278 | { | |
9279 | theMode = Graphic3d_StereoMode_ColumnInterlaced; | |
9280 | } | |
9281 | else if (aFlag == "chess" | |
9282 | || aFlag == "chessboard") | |
9283 | { | |
9284 | theMode = Graphic3d_StereoMode_ChessBoard; | |
9285 | } | |
9286 | else if (aFlag == "sbs" | |
9287 | || aFlag == "sidebyside") | |
9288 | { | |
9289 | theMode = Graphic3d_StereoMode_SideBySide; | |
9290 | } | |
9291 | else if (aFlag == "ou" | |
9292 | || aFlag == "overunder") | |
9293 | { | |
9294 | theMode = Graphic3d_StereoMode_OverUnder; | |
9295 | } | |
9296 | else if (aFlag == "pageflip" | |
9297 | || aFlag == "softpageflip") | |
9298 | { | |
9299 | theMode = Graphic3d_StereoMode_SoftPageFlip; | |
9300 | } | |
9301 | else | |
9302 | { | |
9303 | return Standard_False; | |
9304 | } | |
9305 | return Standard_True; | |
9306 | } | |
9307 | ||
9308 | //! Parse anaglyph filter | |
9309 | inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg, | |
9310 | Graphic3d_RenderingParams::Anaglyph& theFilter) | |
9311 | { | |
9312 | TCollection_AsciiString aFlag (theArg); | |
9313 | aFlag.LowerCase(); | |
9314 | if (aFlag == "redcyansimple") | |
9315 | { | |
9316 | theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple; | |
9317 | } | |
9318 | else if (aFlag == "redcyan" | |
9319 | || aFlag == "redcyanoptimized") | |
9320 | { | |
9321 | theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized; | |
9322 | } | |
9323 | else if (aFlag == "yellowbluesimple") | |
9324 | { | |
9325 | theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple; | |
9326 | } | |
9327 | else if (aFlag == "yellowblue" | |
9328 | || aFlag == "yellowblueoptimized") | |
9329 | { | |
9330 | theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized; | |
9331 | } | |
9332 | else if (aFlag == "greenmagenta" | |
9333 | || aFlag == "greenmagentasimple") | |
9334 | { | |
9335 | theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple; | |
9336 | } | |
9337 | else | |
9338 | { | |
9339 | return Standard_False; | |
9340 | } | |
9341 | return Standard_True; | |
9342 | } | |
9343 | ||
b5ac8292 | 9344 | //============================================================================== |
9345 | //function : VStereo | |
9346 | //purpose : | |
9347 | //============================================================================== | |
9348 | ||
9349 | static int VStereo (Draw_Interpretor& theDI, | |
9350 | Standard_Integer theArgNb, | |
9351 | const char** theArgVec) | |
9352 | { | |
f978241f | 9353 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
b5ac8292 | 9354 | if (theArgNb < 2) |
9355 | { | |
b5ac8292 | 9356 | if (aView.IsNull()) |
9357 | { | |
f978241f | 9358 | std::cout << "Error: no active viewer!\n"; |
b5ac8292 | 9359 | return 0; |
9360 | } | |
9361 | ||
9362 | Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo; | |
9363 | theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n"; | |
bf02aa7d | 9364 | if (isActive) |
9365 | { | |
9366 | TCollection_AsciiString aMode; | |
9367 | switch (aView->RenderingParams().StereoMode) | |
9368 | { | |
9369 | case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break; | |
9370 | case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break; | |
9371 | case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break; | |
9372 | case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break; | |
9373 | case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break; | |
9374 | case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break; | |
9375 | case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break; | |
9376 | case Graphic3d_StereoMode_Anaglyph : | |
9377 | aMode = "anaglyph"; | |
9378 | switch (aView->RenderingParams().AnaglyphFilter) | |
9379 | { | |
9380 | case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break; | |
9381 | case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break; | |
9382 | case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break; | |
9383 | case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break; | |
9384 | case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break; | |
9385 | default: break; | |
9386 | } | |
9387 | default: break; | |
9388 | } | |
9389 | theDI << "Mode " << aMode << "\n"; | |
9390 | } | |
b5ac8292 | 9391 | return 0; |
9392 | } | |
9393 | ||
f978241f | 9394 | Handle(Graphic3d_Camera) aCamera; |
9395 | Graphic3d_RenderingParams* aParams = NULL; | |
9396 | Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer; | |
9397 | if (!aView.IsNull()) | |
9398 | { | |
9399 | aParams = &aView->ChangeRenderingParams(); | |
9400 | aMode = aParams->StereoMode; | |
9401 | aCamera = aView->Camera(); | |
9402 | } | |
9403 | ||
9404 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); | |
9405 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
9406 | { | |
9407 | Standard_CString anArg = theArgVec[anArgIter]; | |
9408 | TCollection_AsciiString aFlag (anArg); | |
9409 | aFlag.LowerCase(); | |
9410 | if (anUpdateTool.parseRedrawMode (aFlag)) | |
9411 | { | |
9412 | continue; | |
9413 | } | |
9414 | else if (aFlag == "0" | |
9415 | || aFlag == "off") | |
9416 | { | |
9417 | if (++anArgIter < theArgNb) | |
9418 | { | |
9419 | std::cout << "Error: wrong number of arguments!\n"; | |
9420 | return 1; | |
9421 | } | |
9422 | ||
9423 | if (!aCamera.IsNull() | |
9424 | && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo) | |
9425 | { | |
9426 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective); | |
9427 | } | |
9428 | ViewerTest_myDefaultCaps.contextStereo = Standard_False; | |
9429 | return 0; | |
9430 | } | |
9431 | else if (aFlag == "1" | |
9432 | || aFlag == "on") | |
9433 | { | |
9434 | if (++anArgIter < theArgNb) | |
9435 | { | |
9436 | std::cout << "Error: wrong number of arguments!\n"; | |
9437 | return 1; | |
9438 | } | |
9439 | ||
9440 | if (!aCamera.IsNull()) | |
9441 | { | |
9442 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo); | |
9443 | } | |
9444 | ViewerTest_myDefaultCaps.contextStereo = Standard_True; | |
9445 | return 0; | |
9446 | } | |
9447 | else if (aFlag == "-reverse" | |
9448 | || aFlag == "-reversed" | |
9449 | || aFlag == "-swap") | |
9450 | { | |
9451 | Standard_Boolean toEnable = Standard_True; | |
9452 | if (++anArgIter < theArgNb | |
a5565a3c | 9453 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
f978241f | 9454 | { |
9455 | --anArgIter; | |
9456 | } | |
9457 | aParams->ToReverseStereo = toEnable; | |
9458 | } | |
9459 | else if (aFlag == "-noreverse" | |
9460 | || aFlag == "-noswap") | |
9461 | { | |
9462 | Standard_Boolean toDisable = Standard_True; | |
9463 | if (++anArgIter < theArgNb | |
a5565a3c | 9464 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable)) |
f978241f | 9465 | { |
9466 | --anArgIter; | |
9467 | } | |
9468 | aParams->ToReverseStereo = !toDisable; | |
9469 | } | |
9470 | else if (aFlag == "-mode" | |
9471 | || aFlag == "-stereomode") | |
9472 | { | |
9473 | if (++anArgIter >= theArgNb | |
9474 | || !parseStereoMode (theArgVec[anArgIter], aMode)) | |
9475 | { | |
9476 | std::cout << "Error: syntax error at '" << anArg << "'\n"; | |
9477 | return 1; | |
9478 | } | |
9479 | ||
9480 | if (aMode == Graphic3d_StereoMode_QuadBuffer) | |
9481 | { | |
9482 | ViewerTest_myDefaultCaps.contextStereo = Standard_True; | |
9483 | } | |
9484 | } | |
9485 | else if (aFlag == "-anaglyph" | |
9486 | || aFlag == "-anaglyphfilter") | |
9487 | { | |
9488 | Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple; | |
9489 | if (++anArgIter >= theArgNb | |
9490 | || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter)) | |
9491 | { | |
9492 | std::cout << "Error: syntax error at '" << anArg << "'\n"; | |
9493 | return 1; | |
9494 | } | |
9495 | ||
9496 | aMode = Graphic3d_StereoMode_Anaglyph; | |
9497 | aParams->AnaglyphFilter = aFilter; | |
9498 | } | |
9499 | else if (parseStereoMode (anArg, aMode)) // short syntax | |
9500 | { | |
9501 | if (aMode == Graphic3d_StereoMode_QuadBuffer) | |
9502 | { | |
9503 | ViewerTest_myDefaultCaps.contextStereo = Standard_True; | |
9504 | } | |
9505 | } | |
9506 | else | |
9507 | { | |
9508 | std::cout << "Error: syntax error at '" << anArg << "'\n"; | |
9509 | return 1; | |
9510 | } | |
9511 | } | |
9512 | ||
9513 | if (!aView.IsNull()) | |
9514 | { | |
9515 | aParams->StereoMode = aMode; | |
9516 | aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo); | |
9517 | } | |
b5ac8292 | 9518 | return 0; |
9519 | } | |
9520 | ||
392ac980 | 9521 | //=============================================================================================== |
9522 | //function : VDefaults | |
9523 | //purpose : | |
9524 | //=============================================================================================== | |
9525 | static int VDefaults (Draw_Interpretor& theDi, | |
9526 | Standard_Integer theArgsNb, | |
9527 | const char** theArgVec) | |
9528 | { | |
9529 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); | |
9530 | if (aCtx.IsNull()) | |
9531 | { | |
9532 | std::cerr << "No active viewer!\n"; | |
9533 | return 1; | |
9534 | } | |
9535 | ||
9536 | Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer(); | |
9537 | if (theArgsNb < 2) | |
9538 | { | |
9539 | if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE) | |
9540 | { | |
9541 | theDi << "DeflType: relative\n" | |
9542 | << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n"; | |
9543 | } | |
9544 | else | |
9545 | { | |
9546 | theDi << "DeflType: absolute\n" | |
9547 | << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n"; | |
9548 | } | |
9549 | theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n"; | |
4c513386 | 9550 | theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n"; |
392ac980 | 9551 | return 0; |
9552 | } | |
9553 | ||
9554 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
9555 | { | |
9556 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
4c513386 | 9557 | anArg.UpperCase(); |
9558 | if (anArg == "-ABSDEFL" | |
9559 | || anArg == "-ABSOLUTEDEFLECTION" | |
9560 | || anArg == "-DEFL" | |
9561 | || anArg == "-DEFLECTION") | |
392ac980 | 9562 | { |
4c513386 | 9563 | if (++anArgIter >= theArgsNb) |
9564 | { | |
9565 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
9566 | return 1; | |
9567 | } | |
392ac980 | 9568 | aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE); |
4c513386 | 9569 | aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter])); |
392ac980 | 9570 | } |
4c513386 | 9571 | else if (anArg == "-RELDEFL" |
9572 | || anArg == "-RELATIVEDEFLECTION" | |
9573 | || anArg == "-DEVCOEFF" | |
9574 | || anArg == "-DEVIATIONCOEFF" | |
9575 | || anArg == "-DEVIATIONCOEFFICIENT") | |
392ac980 | 9576 | { |
4c513386 | 9577 | if (++anArgIter >= theArgsNb) |
9578 | { | |
9579 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
9580 | return 1; | |
9581 | } | |
392ac980 | 9582 | aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE); |
4c513386 | 9583 | aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter])); |
392ac980 | 9584 | } |
4c513386 | 9585 | else if (anArg == "-ANGDEFL" |
9586 | || anArg == "-ANGULARDEFL" | |
9587 | || anArg == "-ANGULARDEFLECTION") | |
392ac980 | 9588 | { |
4c513386 | 9589 | if (++anArgIter >= theArgsNb) |
9590 | { | |
9591 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
9592 | return 1; | |
9593 | } | |
392ac980 | 9594 | // currently HLRDeviationAngle is used instead of DeviationAngle in most places |
4c513386 | 9595 | aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0); |
9596 | } | |
385c43e7 | 9597 | else if (anArg == "-AUTOTR" |
9598 | || anArg == "-AUTOTRIANG" | |
9599 | || anArg == "-AUTOTRIANGULATION") | |
4c513386 | 9600 | { |
9601 | if (++anArgIter >= theArgsNb) | |
9602 | { | |
9603 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
9604 | return 1; | |
9605 | } | |
9606 | TCollection_AsciiString aValue (theArgVec[anArgIter]); | |
9607 | aValue.LowerCase(); | |
9608 | if (aValue == "on" | |
9609 | || aValue == "1") | |
9610 | { | |
9611 | aDefParams->SetAutoTriangulation (Standard_True); | |
9612 | } | |
9613 | else if (aValue == "off" | |
9614 | || aValue == "0") | |
9615 | { | |
9616 | aDefParams->SetAutoTriangulation (Standard_False); | |
9617 | } | |
392ac980 | 9618 | } |
9619 | else | |
9620 | { | |
9621 | std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n"; | |
9622 | } | |
9623 | } | |
9624 | ||
9625 | return 0; | |
9626 | } | |
9627 | ||
12381341 | 9628 | //! Auxiliary method |
9629 | inline void addLight (const Handle(V3d_Light)& theLightNew, | |
992ed6b3 | 9630 | const Graphic3d_ZLayerId theLayer, |
12381341 | 9631 | const Standard_Boolean theIsGlobal) |
9632 | { | |
9633 | if (theLightNew.IsNull()) | |
9634 | { | |
9635 | return; | |
9636 | } | |
9637 | ||
992ed6b3 | 9638 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); |
9639 | if (theLayer == Graphic3d_ZLayerId_UNKNOWN) | |
12381341 | 9640 | { |
992ed6b3 | 9641 | aViewer->AddLight (theLightNew); |
9642 | if (theIsGlobal) | |
9643 | { | |
9644 | aViewer->SetLightOn (theLightNew); | |
9645 | } | |
9646 | else | |
9647 | { | |
9648 | ViewerTest::CurrentView()->SetLightOn (theLightNew); | |
9649 | } | |
12381341 | 9650 | } |
9651 | else | |
9652 | { | |
992ed6b3 | 9653 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer); |
9654 | if (aSettings.Lights().IsNull()) | |
9655 | { | |
9656 | aSettings.SetLights (new Graphic3d_LightSet()); | |
9657 | } | |
9658 | aSettings.Lights()->Add (theLightNew); | |
9659 | aViewer->SetZLayerSettings (theLayer, aSettings); | |
12381341 | 9660 | } |
9661 | } | |
9662 | ||
9663 | //! Auxiliary method | |
9664 | inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext) | |
9665 | { | |
9666 | TCollection_AsciiString anArgNextCase (theArgNext); | |
9667 | anArgNextCase.UpperCase(); | |
9668 | if (anArgNextCase.Length() > 5 | |
9669 | && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT")) | |
9670 | { | |
9671 | return theArgNext.SubString (6, theArgNext.Length()).IntegerValue(); | |
9672 | } | |
9673 | else | |
9674 | { | |
9675 | return theArgNext.IntegerValue(); | |
9676 | } | |
9677 | } | |
9678 | ||
9679 | //=============================================================================================== | |
9680 | //function : VLight | |
9681 | //purpose : | |
9682 | //=============================================================================================== | |
9683 | static int VLight (Draw_Interpretor& theDi, | |
9684 | Standard_Integer theArgsNb, | |
9685 | const char** theArgVec) | |
9686 | { | |
9687 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
9688 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
9689 | if (aView.IsNull() | |
9690 | || aViewer.IsNull()) | |
9691 | { | |
9692 | std::cerr << "No active viewer!\n"; | |
9693 | return 1; | |
9694 | } | |
9695 | ||
ee2be2a8 | 9696 | Standard_Real anXYZ[3] = {}; |
9697 | Standard_Real anAtten[2] = {}; | |
12381341 | 9698 | if (theArgsNb < 2) |
9699 | { | |
9700 | // print lights info | |
9701 | Standard_Integer aLightId = 0; | |
6a24c6de | 9702 | for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId) |
12381341 | 9703 | { |
6a24c6de | 9704 | Handle(V3d_Light) aLight = aLightIter.Value(); |
12381341 | 9705 | const Quantity_Color aColor = aLight->Color(); |
992ed6b3 | 9706 | theDi << "Light #" << aLightId |
9707 | << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "") | |
9708 | << " [" << aLight->GetId() << "]" << "\n"; | |
12381341 | 9709 | switch (aLight->Type()) |
9710 | { | |
9711 | case V3d_AMBIENT: | |
9712 | { | |
189f85a3 | 9713 | theDi << " Type: Ambient\n"; |
9714 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
12381341 | 9715 | break; |
9716 | } | |
9717 | case V3d_DIRECTIONAL: | |
9718 | { | |
189f85a3 | 9719 | theDi << " Type: Directional\n"; |
9720 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
9721 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
9722 | theDi << " Smoothness: " << aLight->Smoothness() << "\n"; | |
992ed6b3 | 9723 | aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]); |
9724 | theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
12381341 | 9725 | break; |
9726 | } | |
9727 | case V3d_POSITIONAL: | |
9728 | { | |
189f85a3 | 9729 | theDi << " Type: Positional\n"; |
9730 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
9731 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
9732 | theDi << " Smoothness: " << aLight->Smoothness() << "\n"; | |
992ed6b3 | 9733 | aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]); |
9734 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
9735 | aLight->Attenuation (anAtten[0], anAtten[1]); | |
9736 | theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n"; | |
12381341 | 9737 | break; |
9738 | } | |
9739 | case V3d_SPOT: | |
9740 | { | |
189f85a3 | 9741 | theDi << " Type: Spot\n"; |
9742 | theDi << " Intensity: " << aLight->Intensity() << "\n"; | |
9743 | theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"; | |
992ed6b3 | 9744 | aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]); |
9745 | theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
9746 | aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]); | |
9747 | theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n"; | |
9748 | aLight->Attenuation (anAtten[0], anAtten[1]); | |
9749 | theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n"; | |
9750 | theDi << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n"; | |
9751 | theDi << " Exponent: " << aLight->Concentration() << "\n"; | |
12381341 | 9752 | break; |
9753 | } | |
9754 | default: | |
9755 | { | |
189f85a3 | 9756 | theDi << " Type: UNKNOWN\n"; |
12381341 | 9757 | break; |
9758 | } | |
9759 | } | |
992ed6b3 | 9760 | theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n"; |
12381341 | 9761 | } |
9762 | } | |
9763 | ||
9764 | Handle(V3d_Light) aLightNew; | |
9765 | Handle(V3d_Light) aLightOld; | |
992ed6b3 | 9766 | Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN; |
12381341 | 9767 | Standard_Boolean isGlobal = Standard_True; |
9768 | Standard_Boolean toCreate = Standard_False; | |
761d8807 | 9769 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
12381341 | 9770 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) |
9771 | { | |
992ed6b3 | 9772 | Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew; |
12381341 | 9773 | |
9774 | TCollection_AsciiString aName, aValue; | |
9775 | const TCollection_AsciiString anArg (theArgVec[anArgIt]); | |
9776 | TCollection_AsciiString anArgCase (anArg); | |
9777 | anArgCase.UpperCase(); | |
761d8807 | 9778 | if (anUpdateTool.parseRedrawMode (anArg)) |
9779 | { | |
9780 | continue; | |
9781 | } | |
9782 | ||
12381341 | 9783 | if (anArgCase.IsEqual ("NEW") |
9784 | || anArgCase.IsEqual ("ADD") | |
992ed6b3 | 9785 | || anArgCase.IsEqual ("CREATE") |
9786 | || anArgCase.IsEqual ("-NEW") | |
9787 | || anArgCase.IsEqual ("-ADD") | |
9788 | || anArgCase.IsEqual ("-CREATE")) | |
12381341 | 9789 | { |
9790 | toCreate = Standard_True; | |
9791 | } | |
992ed6b3 | 9792 | else if (anArgCase.IsEqual ("-LAYER") |
9793 | || anArgCase.IsEqual ("-ZLAYER")) | |
9794 | { | |
9795 | if (++anArgIt >= theArgsNb) | |
9796 | { | |
9797 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
9798 | return 1; | |
9799 | } | |
9800 | ||
9801 | TCollection_AsciiString aValStr (theArgVec[anArgIt]); | |
9802 | aValStr.LowerCase(); | |
9803 | if (aValStr == "default" | |
9804 | || aValStr == "def") | |
9805 | { | |
9806 | aLayer = Graphic3d_ZLayerId_Default; | |
9807 | } | |
9808 | else if (aValStr == "top") | |
9809 | { | |
9810 | aLayer = Graphic3d_ZLayerId_Top; | |
9811 | } | |
9812 | else if (aValStr == "topmost") | |
9813 | { | |
9814 | aLayer = Graphic3d_ZLayerId_Topmost; | |
9815 | } | |
9816 | else if (aValStr == "toposd" | |
9817 | || aValStr == "osd") | |
9818 | { | |
9819 | aLayer = Graphic3d_ZLayerId_TopOSD; | |
9820 | } | |
9821 | else if (aValStr == "botosd" | |
9822 | || aValStr == "bottom") | |
9823 | { | |
9824 | aLayer = Graphic3d_ZLayerId_BotOSD; | |
9825 | } | |
9826 | else if (aValStr.IsIntegerValue()) | |
9827 | { | |
9828 | aLayer = Draw::Atoi (theArgVec[anArgIt]); | |
9829 | } | |
9830 | else | |
9831 | { | |
9832 | std::cout << "Wrong syntax at argument '" << anArg << "'!\n"; | |
9833 | return 1; | |
9834 | } | |
9835 | } | |
12381341 | 9836 | else if (anArgCase.IsEqual ("GLOB") |
992ed6b3 | 9837 | || anArgCase.IsEqual ("GLOBAL") |
9838 | || anArgCase.IsEqual ("-GLOB") | |
9839 | || anArgCase.IsEqual ("-GLOBAL")) | |
12381341 | 9840 | { |
9841 | isGlobal = Standard_True; | |
9842 | } | |
9843 | else if (anArgCase.IsEqual ("LOC") | |
992ed6b3 | 9844 | || anArgCase.IsEqual ("LOCAL") |
9845 | || anArgCase.IsEqual ("-LOC") | |
9846 | || anArgCase.IsEqual ("-LOCAL")) | |
12381341 | 9847 | { |
9848 | isGlobal = Standard_False; | |
9849 | } | |
4fe9ad57 | 9850 | else if (anArgCase.IsEqual ("DEF") |
992ed6b3 | 9851 | || anArgCase.IsEqual ("DEFAULTS") |
9852 | || anArgCase.IsEqual ("-DEF") | |
9853 | || anArgCase.IsEqual ("-DEFAULTS")) | |
4fe9ad57 | 9854 | { |
9855 | toCreate = Standard_False; | |
9856 | aViewer->SetDefaultLights(); | |
9857 | } | |
9858 | else if (anArgCase.IsEqual ("CLR") | |
992ed6b3 | 9859 | || anArgCase.IsEqual ("CLEAR") |
9860 | || anArgCase.IsEqual ("-CLR") | |
9861 | || anArgCase.IsEqual ("-CLEAR")) | |
4fe9ad57 | 9862 | { |
9863 | toCreate = Standard_False; | |
992ed6b3 | 9864 | |
9865 | TColStd_SequenceOfInteger aLayers; | |
9866 | aViewer->GetAllZLayers (aLayers); | |
9867 | for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next()) | |
4fe9ad57 | 9868 | { |
992ed6b3 | 9869 | if (aLayeriter.Value() == aLayer |
9870 | || aLayer == Graphic3d_ZLayerId_UNKNOWN) | |
9871 | { | |
9872 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value()); | |
9873 | aSettings.SetLights (Handle(Graphic3d_LightSet)()); | |
9874 | aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings); | |
9875 | if (aLayer != Graphic3d_ZLayerId_UNKNOWN) | |
9876 | { | |
9877 | break; | |
9878 | } | |
9879 | } | |
9880 | } | |
9881 | ||
9882 | if (aLayer == Graphic3d_ZLayerId_UNKNOWN) | |
9883 | { | |
9884 | for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();) | |
9885 | { | |
9886 | Handle(V3d_Light) aLight = aLightIter.Value(); | |
9887 | aViewer->DelLight (aLight); | |
9888 | aLightIter = aView->ActiveLightIterator(); | |
9889 | } | |
4fe9ad57 | 9890 | } |
9891 | } | |
12381341 | 9892 | else if (anArgCase.IsEqual ("AMB") |
9893 | || anArgCase.IsEqual ("AMBIENT") | |
9894 | || anArgCase.IsEqual ("AMBLIGHT")) | |
9895 | { | |
12381341 | 9896 | if (!toCreate) |
9897 | { | |
9898 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
9899 | return 1; | |
9900 | } | |
992ed6b3 | 9901 | |
9902 | addLight (aLightNew, aLayer, isGlobal); | |
12381341 | 9903 | toCreate = Standard_False; |
992ed6b3 | 9904 | aLightNew = new V3d_AmbientLight(); |
12381341 | 9905 | } |
9906 | else if (anArgCase.IsEqual ("DIRECTIONAL") | |
9907 | || anArgCase.IsEqual ("DIRLIGHT")) | |
9908 | { | |
12381341 | 9909 | if (!toCreate) |
9910 | { | |
9911 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
9912 | return 1; | |
9913 | } | |
992ed6b3 | 9914 | |
9915 | addLight (aLightNew, aLayer, isGlobal); | |
12381341 | 9916 | toCreate = Standard_False; |
992ed6b3 | 9917 | aLightNew = new V3d_DirectionalLight(); |
12381341 | 9918 | } |
9919 | else if (anArgCase.IsEqual ("SPOT") | |
9920 | || anArgCase.IsEqual ("SPOTLIGHT")) | |
9921 | { | |
12381341 | 9922 | if (!toCreate) |
9923 | { | |
9924 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
9925 | return 1; | |
9926 | } | |
992ed6b3 | 9927 | |
9928 | addLight (aLightNew, aLayer, isGlobal); | |
12381341 | 9929 | toCreate = Standard_False; |
992ed6b3 | 9930 | aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0)); |
12381341 | 9931 | } |
9932 | else if (anArgCase.IsEqual ("POSLIGHT") | |
9933 | || anArgCase.IsEqual ("POSITIONAL")) | |
9934 | { | |
12381341 | 9935 | if (!toCreate) |
9936 | { | |
9937 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
9938 | return 1; | |
9939 | } | |
992ed6b3 | 9940 | |
9941 | addLight (aLightNew, aLayer, isGlobal); | |
12381341 | 9942 | toCreate = Standard_False; |
992ed6b3 | 9943 | aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0)); |
12381341 | 9944 | } |
992ed6b3 | 9945 | else if (anArgCase.IsEqual ("CHANGE") |
9946 | || anArgCase.IsEqual ("-CHANGE")) | |
12381341 | 9947 | { |
12381341 | 9948 | if (++anArgIt >= theArgsNb) |
9949 | { | |
9950 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
9951 | return 1; | |
9952 | } | |
9953 | ||
992ed6b3 | 9954 | addLight (aLightNew, aLayer, isGlobal); |
9955 | aLightNew.Nullify(); | |
12381341 | 9956 | const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]); |
9957 | Standard_Integer aLightIt = 0; | |
6a24c6de | 9958 | for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt) |
12381341 | 9959 | { |
9960 | if (aLightIt == aLightId) | |
9961 | { | |
6a24c6de | 9962 | aLightOld = aLightIter.Value(); |
12381341 | 9963 | break; |
9964 | } | |
9965 | } | |
9966 | ||
9967 | if (aLightOld.IsNull()) | |
9968 | { | |
9969 | std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n"; | |
9970 | return 1; | |
9971 | } | |
9972 | } | |
9973 | else if (anArgCase.IsEqual ("DEL") | |
992ed6b3 | 9974 | || anArgCase.IsEqual ("DELETE") |
9975 | || anArgCase.IsEqual ("-DEL") | |
9976 | || anArgCase.IsEqual ("-DELETE")) | |
12381341 | 9977 | { |
9978 | Handle(V3d_Light) aLightDel; | |
9979 | if (++anArgIt >= theArgsNb) | |
9980 | { | |
9981 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
9982 | return 1; | |
9983 | } | |
9984 | ||
9985 | const TCollection_AsciiString anArgNext (theArgVec[anArgIt]); | |
9986 | const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]); | |
9987 | Standard_Integer aLightIt = 0; | |
6a24c6de | 9988 | for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt) |
12381341 | 9989 | { |
6a24c6de | 9990 | aLightDel = aLightIter.Value(); |
12381341 | 9991 | if (aLightIt == aLightDelId) |
9992 | { | |
9993 | break; | |
9994 | } | |
9995 | } | |
992ed6b3 | 9996 | if (aLightDel.IsNull()) |
9997 | { | |
9998 | continue; | |
9999 | } | |
10000 | ||
10001 | TColStd_SequenceOfInteger aLayers; | |
10002 | aViewer->GetAllZLayers (aLayers); | |
10003 | for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next()) | |
10004 | { | |
10005 | if (aLayeriter.Value() == aLayer | |
10006 | || aLayer == Graphic3d_ZLayerId_UNKNOWN) | |
10007 | { | |
10008 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value()); | |
10009 | if (!aSettings.Lights().IsNull()) | |
10010 | { | |
10011 | aSettings.Lights()->Remove (aLightDel); | |
10012 | if (aSettings.Lights()->IsEmpty()) | |
10013 | { | |
10014 | aSettings.SetLights (Handle(Graphic3d_LightSet)()); | |
10015 | } | |
10016 | } | |
10017 | aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings); | |
10018 | if (aLayer != Graphic3d_ZLayerId_UNKNOWN) | |
10019 | { | |
10020 | break; | |
10021 | } | |
10022 | } | |
10023 | } | |
10024 | ||
10025 | if (aLayer == Graphic3d_ZLayerId_UNKNOWN) | |
12381341 | 10026 | { |
10027 | aViewer->DelLight (aLightDel); | |
10028 | } | |
10029 | } | |
10030 | else if (anArgCase.IsEqual ("COLOR") | |
992ed6b3 | 10031 | || anArgCase.IsEqual ("COLOUR") |
10032 | || anArgCase.IsEqual ("-COLOR") | |
10033 | || anArgCase.IsEqual ("-COLOUR")) | |
12381341 | 10034 | { |
992ed6b3 | 10035 | if (++anArgIt >= theArgsNb |
10036 | || aLightCurr.IsNull()) | |
12381341 | 10037 | { |
10038 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10039 | return 1; | |
10040 | } | |
10041 | ||
10042 | TCollection_AsciiString anArgNext (theArgVec[anArgIt]); | |
10043 | anArgNext.UpperCase(); | |
10044 | const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString()); | |
992ed6b3 | 10045 | aLightCurr->SetColor (aColor); |
12381341 | 10046 | } |
10047 | else if (anArgCase.IsEqual ("POS") | |
992ed6b3 | 10048 | || anArgCase.IsEqual ("POSITION") |
10049 | || anArgCase.IsEqual ("-POS") | |
10050 | || anArgCase.IsEqual ("-POSITION")) | |
12381341 | 10051 | { |
992ed6b3 | 10052 | if ((anArgIt + 3) >= theArgsNb |
10053 | || aLightCurr.IsNull() | |
10054 | || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL | |
10055 | && aLightCurr->Type() != Graphic3d_TOLS_SPOT)) | |
12381341 | 10056 | { |
10057 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10058 | return 1; | |
10059 | } | |
10060 | ||
10061 | anXYZ[0] = Atof (theArgVec[++anArgIt]); | |
10062 | anXYZ[1] = Atof (theArgVec[++anArgIt]); | |
10063 | anXYZ[2] = Atof (theArgVec[++anArgIt]); | |
992ed6b3 | 10064 | aLightCurr->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]); |
12381341 | 10065 | } |
10066 | else if (anArgCase.IsEqual ("DIR") | |
992ed6b3 | 10067 | || anArgCase.IsEqual ("DIRECTION") |
10068 | || anArgCase.IsEqual ("-DIR") | |
10069 | || anArgCase.IsEqual ("-DIRECTION")) | |
12381341 | 10070 | { |
992ed6b3 | 10071 | if ((anArgIt + 3) >= theArgsNb |
10072 | || aLightCurr.IsNull() | |
10073 | || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL | |
10074 | && aLightCurr->Type() != Graphic3d_TOLS_SPOT)) | |
12381341 | 10075 | { |
10076 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10077 | return 1; | |
10078 | } | |
10079 | ||
10080 | anXYZ[0] = Atof (theArgVec[++anArgIt]); | |
10081 | anXYZ[1] = Atof (theArgVec[++anArgIt]); | |
10082 | anXYZ[2] = Atof (theArgVec[++anArgIt]); | |
992ed6b3 | 10083 | aLightCurr->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]); |
12381341 | 10084 | } |
189f85a3 | 10085 | else if (anArgCase.IsEqual ("SM") |
992ed6b3 | 10086 | || anArgCase.IsEqual ("SMOOTHNESS") |
10087 | || anArgCase.IsEqual ("-SM") | |
10088 | || anArgCase.IsEqual ("-SMOOTHNESS")) | |
189f85a3 | 10089 | { |
992ed6b3 | 10090 | if (++anArgIt >= theArgsNb |
10091 | || aLightCurr.IsNull()) | |
189f85a3 | 10092 | { |
10093 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10094 | return 1; | |
10095 | } | |
10096 | ||
992ed6b3 | 10097 | Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]); |
10098 | if (Abs (aSmoothness) <= ShortRealEpsilon()) | |
189f85a3 | 10099 | { |
10100 | aLightCurr->SetIntensity (1.f); | |
10101 | } | |
992ed6b3 | 10102 | else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon()) |
189f85a3 | 10103 | { |
10104 | aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f); | |
10105 | } | |
10106 | else | |
10107 | { | |
10108 | Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness()); | |
10109 | aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio)); | |
10110 | } | |
10111 | ||
992ed6b3 | 10112 | if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL) |
189f85a3 | 10113 | { |
992ed6b3 | 10114 | aLightCurr->SetSmoothRadius (aSmoothness); |
189f85a3 | 10115 | } |
992ed6b3 | 10116 | else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL) |
189f85a3 | 10117 | { |
992ed6b3 | 10118 | aLightCurr->SetSmoothAngle (aSmoothness); |
189f85a3 | 10119 | } |
10120 | } | |
10121 | else if (anArgCase.IsEqual ("INT") | |
992ed6b3 | 10122 | || anArgCase.IsEqual ("INTENSITY") |
10123 | || anArgCase.IsEqual ("-INT") | |
10124 | || anArgCase.IsEqual ("-INTENSITY")) | |
189f85a3 | 10125 | { |
992ed6b3 | 10126 | if (++anArgIt >= theArgsNb |
10127 | || aLightCurr.IsNull()) | |
189f85a3 | 10128 | { |
10129 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10130 | return 1; | |
10131 | } | |
10132 | ||
992ed6b3 | 10133 | Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]); |
10134 | aLightCurr->SetIntensity (aIntensity); | |
189f85a3 | 10135 | } |
4fe9ad57 | 10136 | else if (anArgCase.IsEqual ("ANG") |
992ed6b3 | 10137 | || anArgCase.IsEqual ("ANGLE") |
10138 | || anArgCase.IsEqual ("-ANG") | |
10139 | || anArgCase.IsEqual ("-ANGLE")) | |
4fe9ad57 | 10140 | { |
992ed6b3 | 10141 | if (++anArgIt >= theArgsNb |
10142 | || aLightCurr.IsNull() | |
10143 | || aLightCurr->Type() != Graphic3d_TOLS_SPOT) | |
4fe9ad57 | 10144 | { |
10145 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10146 | return 1; | |
10147 | } | |
10148 | ||
992ed6b3 | 10149 | Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]); |
10150 | aLightCurr->SetAngle (Standard_ShortReal (anAngle / 180.0 * M_PI)); | |
4fe9ad57 | 10151 | } |
12381341 | 10152 | else if (anArgCase.IsEqual ("CONSTATTEN") |
992ed6b3 | 10153 | || anArgCase.IsEqual ("CONSTATTENUATION") |
10154 | || anArgCase.IsEqual ("-CONSTATTEN") | |
10155 | || anArgCase.IsEqual ("-CONSTATTENUATION")) | |
12381341 | 10156 | { |
992ed6b3 | 10157 | if (++anArgIt >= theArgsNb |
10158 | || aLightCurr.IsNull() | |
10159 | || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL | |
10160 | && aLightCurr->Type() != Graphic3d_TOLS_SPOT)) | |
12381341 | 10161 | { |
10162 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10163 | return 1; | |
10164 | } | |
10165 | ||
992ed6b3 | 10166 | aLightCurr->Attenuation (anAtten[0], anAtten[1]); |
10167 | anAtten[0] = Atof (theArgVec[anArgIt]); | |
10168 | aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]); | |
12381341 | 10169 | } |
10170 | else if (anArgCase.IsEqual ("LINATTEN") | |
10171 | || anArgCase.IsEqual ("LINEARATTEN") | |
992ed6b3 | 10172 | || anArgCase.IsEqual ("LINEARATTENUATION") |
10173 | || anArgCase.IsEqual ("-LINATTEN") | |
10174 | || anArgCase.IsEqual ("-LINEARATTEN") | |
10175 | || anArgCase.IsEqual ("-LINEARATTENUATION")) | |
12381341 | 10176 | { |
992ed6b3 | 10177 | if (++anArgIt >= theArgsNb |
10178 | || aLightCurr.IsNull() | |
10179 | || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL | |
10180 | && aLightCurr->Type() != Graphic3d_TOLS_SPOT)) | |
12381341 | 10181 | { |
10182 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10183 | return 1; | |
10184 | } | |
10185 | ||
992ed6b3 | 10186 | aLightCurr->Attenuation (anAtten[0], anAtten[1]); |
10187 | anAtten[1] = Atof (theArgVec[anArgIt]); | |
10188 | aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]); | |
12381341 | 10189 | } |
10190 | else if (anArgCase.IsEqual ("EXP") | |
10191 | || anArgCase.IsEqual ("EXPONENT") | |
10192 | || anArgCase.IsEqual ("SPOTEXP") | |
992ed6b3 | 10193 | || anArgCase.IsEqual ("SPOTEXPONENT") |
10194 | || anArgCase.IsEqual ("-EXP") | |
10195 | || anArgCase.IsEqual ("-EXPONENT") | |
10196 | || anArgCase.IsEqual ("-SPOTEXP") | |
10197 | || anArgCase.IsEqual ("-SPOTEXPONENT")) | |
12381341 | 10198 | { |
992ed6b3 | 10199 | if (++anArgIt >= theArgsNb |
10200 | || aLightCurr.IsNull() | |
10201 | || aLightCurr->Type() != Graphic3d_TOLS_SPOT) | |
12381341 | 10202 | { |
10203 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10204 | return 1; | |
10205 | } | |
10206 | ||
992ed6b3 | 10207 | aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt])); |
12381341 | 10208 | } |
10209 | else if (anArgCase.IsEqual ("HEAD") | |
992ed6b3 | 10210 | || anArgCase.IsEqual ("HEADLIGHT") |
10211 | || anArgCase.IsEqual ("-HEAD") | |
10212 | || anArgCase.IsEqual ("-HEADLIGHT")) | |
12381341 | 10213 | { |
992ed6b3 | 10214 | if (aLightCurr.IsNull() |
10215 | || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT) | |
12381341 | 10216 | { |
10217 | std::cerr << "Wrong syntax at argument '" << anArg << "'!\n"; | |
10218 | return 1; | |
10219 | } | |
10220 | ||
992ed6b3 | 10221 | Standard_Boolean isHeadLight = Standard_True; |
10222 | if (anArgIt + 1 < theArgsNb | |
10223 | && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight)) | |
12381341 | 10224 | { |
992ed6b3 | 10225 | ++anArgIt; |
12381341 | 10226 | } |
992ed6b3 | 10227 | aLightCurr->SetHeadlight (isHeadLight); |
12381341 | 10228 | } |
10229 | else | |
10230 | { | |
10231 | std::cerr << "Warning: unknown argument '" << anArg << "'\n"; | |
10232 | } | |
10233 | } | |
10234 | ||
992ed6b3 | 10235 | addLight (aLightNew, aLayer, isGlobal); |
12381341 | 10236 | return 0; |
10237 | } | |
10238 | ||
15669413 | 10239 | //! Read Graphic3d_RenderingParams::PerfCounters flag. |
10240 | static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue, | |
10241 | Standard_Boolean& theToReset, | |
10242 | Graphic3d_RenderingParams::PerfCounters& theFlagsRem, | |
10243 | Graphic3d_RenderingParams::PerfCounters& theFlagsAdd) | |
10244 | { | |
10245 | Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE; | |
10246 | TCollection_AsciiString aVal = theValue; | |
10247 | Standard_Boolean toReverse = Standard_False; | |
10248 | if (aVal == "none") | |
10249 | { | |
10250 | theToReset = Standard_True; | |
10251 | return Standard_True; | |
10252 | } | |
10253 | else if (aVal.StartsWith ("-")) | |
10254 | { | |
10255 | toReverse = Standard_True; | |
10256 | aVal = aVal.SubString (2, aVal.Length()); | |
10257 | } | |
10258 | else if (aVal.StartsWith ("no")) | |
10259 | { | |
10260 | toReverse = Standard_True; | |
10261 | aVal = aVal.SubString (3, aVal.Length()); | |
10262 | } | |
10263 | else if (aVal.StartsWith ("+")) | |
10264 | { | |
10265 | aVal = aVal.SubString (2, aVal.Length()); | |
10266 | } | |
10267 | else | |
10268 | { | |
10269 | theToReset = Standard_True; | |
10270 | } | |
10271 | ||
10272 | if ( aVal == "fps" | |
10273 | || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate; | |
10274 | else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU; | |
10275 | else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers; | |
10276 | else if (aVal == "structs" | |
10277 | || aVal == "structures" | |
10278 | || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures; | |
10279 | else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups; | |
10280 | else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays; | |
10281 | else if (aVal == "tris" | |
10282 | || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles; | |
10283 | else if (aVal == "pnts" | |
10284 | || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points; | |
10285 | else if (aVal == "mem" | |
10286 | || aVal == "gpumem" | |
10287 | || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem; | |
5e30547b | 10288 | else if (aVal == "skipimmediate" |
10289 | || aVal == "noimmediate") aFlag = Graphic3d_RenderingParams::PerfCounters_SkipImmediate; | |
10290 | else if (aVal == "frametime" | |
10291 | || aVal == "frametimers" | |
10292 | || aVal == "time") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameTime; | |
15669413 | 10293 | else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic; |
10294 | else if (aVal == "extended" | |
10295 | || aVal == "verbose" | |
10296 | || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended; | |
5e30547b | 10297 | else if (aVal == "full" |
10298 | || aVal == "all") aFlag = Graphic3d_RenderingParams::PerfCounters_All; | |
15669413 | 10299 | else |
10300 | { | |
10301 | return Standard_False; | |
10302 | } | |
10303 | ||
10304 | if (toReverse) | |
10305 | { | |
10306 | theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag); | |
10307 | } | |
10308 | else | |
10309 | { | |
10310 | theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag); | |
10311 | } | |
10312 | return Standard_True; | |
10313 | } | |
10314 | ||
10315 | //! Read Graphic3d_RenderingParams::PerfCounters flags. | |
10316 | static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue, | |
10317 | Graphic3d_RenderingParams::PerfCounters& theFlags) | |
10318 | { | |
10319 | TCollection_AsciiString aValue = theValue; | |
10320 | Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE; | |
10321 | Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE; | |
10322 | Standard_Boolean toReset = Standard_False; | |
10323 | for (;;) | |
10324 | { | |
10325 | Standard_Integer aSplitPos = aValue.Search ("|"); | |
10326 | if (aSplitPos <= 0) | |
10327 | { | |
10328 | if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd)) | |
10329 | { | |
10330 | return Standard_False; | |
10331 | } | |
10332 | if (toReset) | |
10333 | { | |
10334 | theFlags = Graphic3d_RenderingParams::PerfCounters_NONE; | |
10335 | } | |
10336 | theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd); | |
10337 | theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem); | |
10338 | return Standard_True; | |
10339 | } | |
10340 | ||
10341 | if (aSplitPos > 1) | |
10342 | { | |
10343 | TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1); | |
10344 | if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd)) | |
10345 | { | |
10346 | return Standard_False; | |
10347 | } | |
10348 | } | |
10349 | aValue = aValue.SubString (aSplitPos + 1, aValue.Length()); | |
10350 | } | |
10351 | } | |
10352 | ||
e276548b | 10353 | //======================================================================= |
bc8c79bb | 10354 | //function : VRenderParams |
10355 | //purpose : Enables/disables rendering features | |
e276548b | 10356 | //======================================================================= |
10357 | ||
bc8c79bb | 10358 | static Standard_Integer VRenderParams (Draw_Interpretor& theDI, |
10359 | Standard_Integer theArgNb, | |
10360 | const char** theArgVec) | |
e276548b | 10361 | { |
7ae4a307 | 10362 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
10363 | if (aView.IsNull()) | |
e276548b | 10364 | { |
bc8c79bb | 10365 | std::cerr << "Error: no active viewer!\n"; |
e276548b | 10366 | return 1; |
10367 | } | |
bc8c79bb | 10368 | |
10369 | Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams(); | |
6b62b2da | 10370 | TCollection_AsciiString aCmdName (theArgVec[0]); |
10371 | aCmdName.LowerCase(); | |
10372 | if (aCmdName == "vraytrace") | |
10373 | { | |
10374 | if (theArgNb == 1) | |
10375 | { | |
10376 | theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " "; | |
10377 | return 0; | |
10378 | } | |
10379 | else if (theArgNb == 2) | |
10380 | { | |
10381 | TCollection_AsciiString aValue (theArgVec[1]); | |
10382 | aValue.LowerCase(); | |
10383 | if (aValue == "on" | |
10384 | || aValue == "1") | |
10385 | { | |
10386 | aParams.Method = Graphic3d_RM_RAYTRACING; | |
10387 | aView->Redraw(); | |
10388 | return 0; | |
10389 | } | |
10390 | else if (aValue == "off" | |
10391 | || aValue == "0") | |
10392 | { | |
10393 | aParams.Method = Graphic3d_RM_RASTERIZATION; | |
10394 | aView->Redraw(); | |
10395 | return 0; | |
10396 | } | |
10397 | else | |
10398 | { | |
10399 | std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n"; | |
10400 | return 1; | |
10401 | } | |
10402 | } | |
10403 | else | |
10404 | { | |
10405 | std::cout << "Error: wrong number of arguments\n"; | |
10406 | return 1; | |
10407 | } | |
10408 | } | |
bc8c79bb | 10409 | |
10410 | if (theArgNb < 2) | |
e276548b | 10411 | { |
bc8c79bb | 10412 | theDI << "renderMode: "; |
10413 | switch (aParams.Method) | |
10414 | { | |
10415 | case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break; | |
10416 | case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break; | |
10417 | } | |
10418 | theDI << "\n"; | |
a1073ae2 | 10419 | theDI << "transparency: "; |
10420 | switch (aParams.TransparencyMethod) | |
10421 | { | |
10422 | case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break; | |
10423 | case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: " | |
10424 | << TCollection_AsciiString (aParams.OitDepthFactor); break; | |
10425 | } | |
10426 | theDI << "\n"; | |
b4327ba8 | 10427 | theDI << "msaa: " << aParams.NbMsaaSamples << "\n"; |
56689b27 | 10428 | theDI << "rendScale: " << aParams.RenderResolutionScale << "\n"; |
b4327ba8 | 10429 | theDI << "rayDepth: " << aParams.RaytracingDepth << "\n"; |
10430 | theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n"; | |
10431 | theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n"; | |
10432 | theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n"; | |
10433 | theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n"; | |
10434 | theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n"; | |
10435 | theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n"; | |
10436 | theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n"; | |
10437 | theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n"; | |
10438 | theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n"; | |
b09447ed | 10439 | theDI << "max radiance: " << aParams.RadianceClampingValue << "\n"; |
4eaaf9d8 | 10440 | theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n"; |
66d1cdc6 | 10441 | theDI << "tile size (iss):" << aParams.RayTracingTileSize << "x" << aParams.RayTracingTileSize << "\n"; |
8625ef7e | 10442 | theDI << "shadingModel: "; |
10443 | switch (aView->ShadingModel()) | |
10444 | { | |
dc89236f | 10445 | case Graphic3d_TOSM_DEFAULT: theDI << "default"; break; |
10446 | case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break; | |
10447 | case Graphic3d_TOSM_FACET: theDI << "flat"; break; | |
10448 | case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break; | |
10449 | case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break; | |
8625ef7e | 10450 | } |
15669413 | 10451 | { |
10452 | theDI << "perfCounters:"; | |
10453 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0) | |
10454 | { | |
10455 | theDI << " fps"; | |
10456 | } | |
10457 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0) | |
10458 | { | |
10459 | theDI << " cpu"; | |
10460 | } | |
10461 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0) | |
10462 | { | |
10463 | theDI << " structs"; | |
10464 | } | |
10465 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0) | |
10466 | { | |
10467 | theDI << " groups"; | |
10468 | } | |
10469 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0) | |
10470 | { | |
10471 | theDI << " arrays"; | |
10472 | } | |
10473 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0) | |
10474 | { | |
10475 | theDI << " tris"; | |
10476 | } | |
10477 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0) | |
10478 | { | |
10479 | theDI << " pnts"; | |
10480 | } | |
10481 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0) | |
10482 | { | |
10483 | theDI << " gpumem"; | |
10484 | } | |
5e30547b | 10485 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameTime) != 0) |
10486 | { | |
10487 | theDI << " frameTime"; | |
10488 | } | |
10489 | if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_SkipImmediate) != 0) | |
10490 | { | |
10491 | theDI << " skipimmediate"; | |
10492 | } | |
15669413 | 10493 | if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE) |
10494 | { | |
10495 | theDI << " none"; | |
10496 | } | |
10497 | theDI << "\n"; | |
10498 | } | |
f88457e6 | 10499 | theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n"; |
c40eb6b9 | 10500 | theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n"; |
0e3025bc | 10501 | theDI << "frustum culling: " << (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On ? "on" : |
10502 | aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off ? "off" : | |
10503 | "noUpdate") << "\n"; | |
8625ef7e | 10504 | theDI << "\n"; |
bc8c79bb | 10505 | return 0; |
e276548b | 10506 | } |
10507 | ||
bc8c79bb | 10508 | Standard_Boolean toPrint = Standard_False; |
8625ef7e | 10509 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); |
e276548b | 10510 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
10511 | { | |
bc8c79bb | 10512 | Standard_CString anArg (theArgVec[anArgIter]); |
10513 | TCollection_AsciiString aFlag (anArg); | |
10514 | aFlag.LowerCase(); | |
8625ef7e | 10515 | if (anUpdateTool.parseRedrawMode (aFlag)) |
10516 | { | |
10517 | continue; | |
10518 | } | |
10519 | else if (aFlag == "-echo" | |
10520 | || aFlag == "-print") | |
e276548b | 10521 | { |
bc8c79bb | 10522 | toPrint = Standard_True; |
8625ef7e | 10523 | anUpdateTool.Invalidate(); |
e276548b | 10524 | } |
bc8c79bb | 10525 | else if (aFlag == "-mode" |
10526 | || aFlag == "-rendermode" | |
10527 | || aFlag == "-render_mode") | |
e276548b | 10528 | { |
bc8c79bb | 10529 | if (toPrint) |
10530 | { | |
10531 | switch (aParams.Method) | |
10532 | { | |
10533 | case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break; | |
10534 | case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break; | |
10535 | } | |
10536 | continue; | |
10537 | } | |
e276548b | 10538 | else |
bc8c79bb | 10539 | { |
10540 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
10541 | return 1; | |
10542 | } | |
10543 | } | |
10544 | else if (aFlag == "-ray" | |
10545 | || aFlag == "-raytrace") | |
10546 | { | |
10547 | if (toPrint) | |
10548 | { | |
10549 | theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " "; | |
10550 | continue; | |
10551 | } | |
10552 | ||
10553 | aParams.Method = Graphic3d_RM_RAYTRACING; | |
e276548b | 10554 | } |
bc8c79bb | 10555 | else if (aFlag == "-rast" |
10556 | || aFlag == "-raster" | |
10557 | || aFlag == "-rasterization") | |
e276548b | 10558 | { |
bc8c79bb | 10559 | if (toPrint) |
10560 | { | |
10561 | theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " "; | |
10562 | continue; | |
10563 | } | |
10564 | ||
10565 | aParams.Method = Graphic3d_RM_RASTERIZATION; | |
10566 | } | |
3c4b62a4 | 10567 | else if (aFlag == "-msaa") |
10568 | { | |
10569 | if (toPrint) | |
10570 | { | |
10571 | theDI << aParams.NbMsaaSamples << " "; | |
10572 | continue; | |
10573 | } | |
10574 | else if (++anArgIter >= theArgNb) | |
10575 | { | |
10576 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
10577 | return 1; | |
10578 | } | |
10579 | ||
10580 | const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]); | |
10581 | if (aNbSamples < 0) | |
10582 | { | |
10583 | std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n"; | |
10584 | return 1; | |
10585 | } | |
10586 | else | |
10587 | { | |
10588 | aParams.NbMsaaSamples = aNbSamples; | |
10589 | } | |
10590 | } | |
2a332745 | 10591 | else if (aFlag == "-linefeather" |
10592 | || aFlag == "-edgefeather" | |
10593 | || aFlag == "-feather") | |
10594 | { | |
10595 | if (toPrint) | |
10596 | { | |
10597 | theDI << " " << aParams.LineFeather << " "; | |
10598 | continue; | |
10599 | } | |
10600 | else if (++anArgIter >= theArgNb) | |
10601 | { | |
10602 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
10603 | return 1; | |
10604 | } | |
10605 | ||
10606 | TCollection_AsciiString aParam = theArgVec[anArgIter]; | |
10607 | const Standard_ShortReal aFeather = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]); | |
10608 | if (aFeather <= 0.0f) | |
10609 | { | |
10610 | std::cerr << "Error: invalid value of line width feather " << aFeather << ". Should be > 0\n"; | |
10611 | return 1; | |
10612 | } | |
10613 | aParams.LineFeather = aFeather; | |
10614 | } | |
a1073ae2 | 10615 | else if (aFlag == "-oit") |
10616 | { | |
10617 | if (toPrint) | |
10618 | { | |
10619 | if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT) | |
10620 | { | |
10621 | theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " "; | |
10622 | } | |
10623 | else | |
10624 | { | |
10625 | theDI << "off" << " "; | |
10626 | } | |
10627 | continue; | |
10628 | } | |
10629 | else if (++anArgIter >= theArgNb) | |
10630 | { | |
10631 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
10632 | return 1; | |
10633 | } | |
10634 | ||
10635 | TCollection_AsciiString aParam = theArgVec[anArgIter]; | |
10636 | aParam.LowerCase(); | |
10637 | if (aParam.IsRealValue()) | |
10638 | { | |
10639 | const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]); | |
10640 | if (aWeight < 0.f || aWeight > 1.f) | |
10641 | { | |
10642 | std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n"; | |
10643 | return 1; | |
10644 | } | |
10645 | ||
10646 | aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT; | |
10647 | aParams.OitDepthFactor = aWeight; | |
10648 | } | |
10649 | else if (aParam == "off") | |
10650 | { | |
10651 | aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED; | |
10652 | } | |
10653 | else | |
10654 | { | |
10655 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
10656 | return 1; | |
10657 | } | |
10658 | } | |
f88457e6 | 10659 | else if (aFlag == "-depthprepass") |
10660 | { | |
10661 | if (toPrint) | |
10662 | { | |
10663 | theDI << (aParams.ToEnableDepthPrepass ? "on " : "off "); | |
10664 | continue; | |
10665 | } | |
10666 | aParams.ToEnableDepthPrepass = Standard_True; | |
10667 | if (anArgIter + 1 < theArgNb | |
10668 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass)) | |
10669 | { | |
10670 | ++anArgIter; | |
10671 | } | |
10672 | } | |
c40eb6b9 | 10673 | else if (aFlag == "-samplealphatocoverage" |
10674 | || aFlag == "-alphatocoverage") | |
10675 | { | |
10676 | if (toPrint) | |
10677 | { | |
10678 | theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off "); | |
10679 | continue; | |
10680 | } | |
10681 | aParams.ToEnableAlphaToCoverage = Standard_True; | |
10682 | if (anArgIter + 1 < theArgNb | |
10683 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage)) | |
10684 | { | |
10685 | ++anArgIter; | |
10686 | } | |
10687 | } | |
56689b27 | 10688 | else if (aFlag == "-rendscale" |
10689 | || aFlag == "-renderscale" | |
10690 | || aFlag == "-renderresolutionscale") | |
10691 | { | |
10692 | if (toPrint) | |
10693 | { | |
10694 | theDI << aParams.RenderResolutionScale << " "; | |
10695 | continue; | |
10696 | } | |
10697 | else if (++anArgIter >= theArgNb) | |
10698 | { | |
10699 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
10700 | return 1; | |
10701 | } | |
10702 | ||
10703 | const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]); | |
10704 | if (aScale < 0.01) | |
10705 | { | |
10706 | std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n"; | |
10707 | return 1; | |
10708 | } | |
10709 | else | |
10710 | { | |
10711 | aParams.RenderResolutionScale = Standard_ShortReal(aScale); | |
10712 | } | |
10713 | } | |
bc8c79bb | 10714 | else if (aFlag == "-raydepth" |
10715 | || aFlag == "-ray_depth") | |
10716 | { | |
10717 | if (toPrint) | |
10718 | { | |
10719 | theDI << aParams.RaytracingDepth << " "; | |
10720 | continue; | |
10721 | } | |
10722 | else if (++anArgIter >= theArgNb) | |
10723 | { | |
10724 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
10725 | return 1; | |
10726 | } | |
10727 | ||
10728 | const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]); | |
189f85a3 | 10729 | |
10730 | // We allow RaytracingDepth be more than 10 in case of GI enabled | |
10731 | if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled)) | |
bc8c79bb | 10732 | { |
10733 | std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n"; | |
10734 | return 1; | |
10735 | } | |
e276548b | 10736 | else |
bc8c79bb | 10737 | { |
10738 | aParams.RaytracingDepth = aDepth; | |
10739 | } | |
10740 | } | |
10741 | else if (aFlag == "-shad" | |
10742 | || aFlag == "-shadows") | |
10743 | { | |
10744 | if (toPrint) | |
10745 | { | |
10746 | theDI << (aParams.IsShadowEnabled ? "on" : "off") << " "; | |
10747 | continue; | |
10748 | } | |
10749 | ||
10750 | Standard_Boolean toEnable = Standard_True; | |
10751 | if (++anArgIter < theArgNb | |
a5565a3c | 10752 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 10753 | { |
10754 | --anArgIter; | |
10755 | } | |
10756 | aParams.IsShadowEnabled = toEnable; | |
10757 | } | |
10758 | else if (aFlag == "-refl" | |
10759 | || aFlag == "-reflections") | |
10760 | { | |
10761 | if (toPrint) | |
10762 | { | |
10763 | theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " "; | |
10764 | continue; | |
10765 | } | |
10766 | ||
10767 | Standard_Boolean toEnable = Standard_True; | |
10768 | if (++anArgIter < theArgNb | |
a5565a3c | 10769 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 10770 | { |
10771 | --anArgIter; | |
10772 | } | |
10773 | aParams.IsReflectionEnabled = toEnable; | |
10774 | } | |
10775 | else if (aFlag == "-fsaa") | |
10776 | { | |
10777 | if (toPrint) | |
10778 | { | |
10779 | theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " "; | |
10780 | continue; | |
10781 | } | |
10782 | ||
10783 | Standard_Boolean toEnable = Standard_True; | |
10784 | if (++anArgIter < theArgNb | |
a5565a3c | 10785 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 10786 | { |
10787 | --anArgIter; | |
10788 | } | |
10789 | aParams.IsAntialiasingEnabled = toEnable; | |
10790 | } | |
10791 | else if (aFlag == "-gleam") | |
10792 | { | |
10793 | if (toPrint) | |
10794 | { | |
10795 | theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " "; | |
10796 | continue; | |
10797 | } | |
10798 | ||
10799 | Standard_Boolean toEnable = Standard_True; | |
10800 | if (++anArgIter < theArgNb | |
a5565a3c | 10801 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
bc8c79bb | 10802 | { |
10803 | --anArgIter; | |
10804 | } | |
10805 | aParams.IsTransparentShadowEnabled = toEnable; | |
e276548b | 10806 | } |
189f85a3 | 10807 | else if (aFlag == "-gi") |
10808 | { | |
10809 | if (toPrint) | |
10810 | { | |
10811 | theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " "; | |
10812 | continue; | |
10813 | } | |
10814 | ||
10815 | Standard_Boolean toEnable = Standard_True; | |
10816 | if (++anArgIter < theArgNb | |
a5565a3c | 10817 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
189f85a3 | 10818 | { |
10819 | --anArgIter; | |
10820 | } | |
10821 | aParams.IsGlobalIlluminationEnabled = toEnable; | |
10822 | if (!toEnable) | |
10823 | { | |
10824 | aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10); | |
10825 | } | |
10826 | } | |
8c820969 | 10827 | else if (aFlag == "-blockedrng" |
10828 | || aFlag == "-brng") | |
10829 | { | |
10830 | if (toPrint) | |
10831 | { | |
10832 | theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " "; | |
10833 | continue; | |
10834 | } | |
10835 | ||
10836 | Standard_Boolean toEnable = Standard_True; | |
10837 | if (++anArgIter < theArgNb | |
a5565a3c | 10838 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
8c820969 | 10839 | { |
10840 | --anArgIter; | |
10841 | } | |
10842 | aParams.CoherentPathTracingMode = toEnable; | |
10843 | } | |
b09447ed | 10844 | else if (aFlag == "-maxrad") |
10845 | { | |
10846 | if (toPrint) | |
10847 | { | |
10848 | theDI << aParams.RadianceClampingValue << " "; | |
10849 | continue; | |
10850 | } | |
10851 | else if (++anArgIter >= theArgNb) | |
10852 | { | |
10853 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
10854 | return 1; | |
10855 | } | |
10856 | ||
10857 | const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter]; | |
10858 | if (!aMaxRadStr.IsRealValue()) | |
10859 | { | |
10860 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
10861 | return 1; | |
10862 | } | |
10863 | ||
10864 | const Standard_Real aMaxRadiance = aMaxRadStr.RealValue(); | |
10865 | if (aMaxRadiance <= 0.0) | |
10866 | { | |
10867 | std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n"; | |
10868 | return 1; | |
10869 | } | |
10870 | else | |
10871 | { | |
10872 | aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance); | |
10873 | } | |
10874 | } | |
3a9b5dc8 | 10875 | else if (aFlag == "-iss") |
10876 | { | |
10877 | if (toPrint) | |
10878 | { | |
10879 | theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " "; | |
10880 | continue; | |
10881 | } | |
10882 | ||
10883 | Standard_Boolean toEnable = Standard_True; | |
10884 | if (++anArgIter < theArgNb | |
10885 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
10886 | { | |
10887 | --anArgIter; | |
10888 | } | |
10889 | aParams.AdaptiveScreenSampling = toEnable; | |
10890 | } | |
e084dbbc | 10891 | else if (aFlag == "-issatomic") |
10892 | { | |
10893 | if (toPrint) | |
10894 | { | |
10895 | theDI << (aParams.AdaptiveScreenSamplingAtomic ? "on" : "off") << " "; | |
10896 | continue; | |
10897 | } | |
10898 | ||
10899 | Standard_Boolean toEnable = Standard_True; | |
10900 | if (++anArgIter < theArgNb | |
10901 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
10902 | { | |
10903 | --anArgIter; | |
10904 | } | |
10905 | aParams.AdaptiveScreenSamplingAtomic = toEnable; | |
10906 | } | |
3a9b5dc8 | 10907 | else if (aFlag == "-issd") |
10908 | { | |
10909 | if (toPrint) | |
10910 | { | |
10911 | theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " "; | |
10912 | continue; | |
10913 | } | |
10914 | ||
10915 | Standard_Boolean toEnable = Standard_True; | |
10916 | if (++anArgIter < theArgNb | |
10917 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
10918 | { | |
10919 | --anArgIter; | |
10920 | } | |
10921 | aParams.ShowSamplingTiles = toEnable; | |
10922 | } | |
66d1cdc6 | 10923 | else if (aFlag == "-tilesize") |
10924 | { | |
10925 | if (toPrint) | |
10926 | { | |
10927 | theDI << aParams.RayTracingTileSize << " "; | |
10928 | continue; | |
10929 | } | |
10930 | else if (++anArgIter >= theArgNb) | |
10931 | { | |
10932 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
10933 | return 1; | |
10934 | } | |
10935 | ||
10936 | const Standard_Integer aTileSize = Draw::Atoi (theArgVec[anArgIter]); | |
10937 | if (aTileSize < 1) | |
10938 | { | |
10939 | std::cerr << "Error: invalid size of ISS tile " << aTileSize << ".\n"; | |
10940 | return 1; | |
10941 | } | |
10942 | aParams.RayTracingTileSize = aTileSize; | |
10943 | } | |
4eaaf9d8 | 10944 | else if (aFlag == "-nbtiles") |
10945 | { | |
10946 | if (toPrint) | |
10947 | { | |
10948 | theDI << aParams.NbRayTracingTiles << " "; | |
10949 | continue; | |
10950 | } | |
10951 | else if (++anArgIter >= theArgNb) | |
10952 | { | |
10953 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
10954 | return 1; | |
10955 | } | |
10956 | ||
10957 | const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]); | |
66d1cdc6 | 10958 | if (aNbTiles < -1) |
4eaaf9d8 | 10959 | { |
10960 | std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n"; | |
4eaaf9d8 | 10961 | return 1; |
10962 | } | |
66d1cdc6 | 10963 | else if (aNbTiles > 0 |
10964 | && (aNbTiles < 64 | |
10965 | || aNbTiles > 1024)) | |
4eaaf9d8 | 10966 | { |
66d1cdc6 | 10967 | std::cerr << "Warning: suboptimal number of ISS tiles " << aNbTiles << ". Recommended range: [64, 1024].\n"; |
4eaaf9d8 | 10968 | } |
66d1cdc6 | 10969 | aParams.NbRayTracingTiles = aNbTiles; |
4eaaf9d8 | 10970 | } |
189f85a3 | 10971 | else if (aFlag == "-env") |
10972 | { | |
10973 | if (toPrint) | |
10974 | { | |
10975 | theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " "; | |
10976 | continue; | |
10977 | } | |
10978 | ||
10979 | Standard_Boolean toEnable = Standard_True; | |
10980 | if (++anArgIter < theArgNb | |
a5565a3c | 10981 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) |
189f85a3 | 10982 | { |
10983 | --anArgIter; | |
10984 | } | |
10985 | aParams.UseEnvironmentMapBackground = toEnable; | |
10986 | } | |
b4327ba8 | 10987 | else if (aFlag == "-twoside") |
10988 | { | |
10989 | if (toPrint) | |
10990 | { | |
10991 | theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " "; | |
10992 | continue; | |
10993 | } | |
10994 | ||
10995 | Standard_Boolean toEnable = Standard_True; | |
10996 | if (++anArgIter < theArgNb | |
10997 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
10998 | { | |
10999 | --anArgIter; | |
11000 | } | |
11001 | aParams.TwoSidedBsdfModels = toEnable; | |
11002 | } | |
8625ef7e | 11003 | else if (aFlag == "-shademodel" |
11004 | || aFlag == "-shadingmodel" | |
11005 | || aFlag == "-shading") | |
11006 | { | |
11007 | if (toPrint) | |
11008 | { | |
11009 | switch (aView->ShadingModel()) | |
11010 | { | |
dc89236f | 11011 | case Graphic3d_TOSM_DEFAULT: theDI << "default"; break; |
11012 | case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break; | |
11013 | case Graphic3d_TOSM_FACET: theDI << "flat "; break; | |
11014 | case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break; | |
11015 | case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break; | |
8625ef7e | 11016 | } |
11017 | continue; | |
11018 | } | |
11019 | ||
11020 | if (++anArgIter >= theArgNb) | |
11021 | { | |
11022 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11023 | } | |
11024 | ||
dc89236f | 11025 | Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT; |
11026 | if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel) | |
11027 | && aModel != Graphic3d_TOSM_DEFAULT) | |
8625ef7e | 11028 | { |
dc89236f | 11029 | aView->SetShadingModel (aModel); |
8625ef7e | 11030 | } |
11031 | else | |
11032 | { | |
dc89236f | 11033 | std::cout << "Error: unknown shading model '" << theArgVec[anArgIter] << "'\n"; |
8625ef7e | 11034 | return 1; |
11035 | } | |
11036 | } | |
4b1c8733 | 11037 | else if (aFlag == "-resolution") |
11038 | { | |
11039 | if (++anArgIter >= theArgNb) | |
11040 | { | |
11041 | std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11042 | return 1; | |
11043 | } | |
11044 | ||
11045 | TCollection_AsciiString aResolution (theArgVec[anArgIter]); | |
11046 | if (aResolution.IsIntegerValue()) | |
11047 | { | |
11048 | aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString())); | |
11049 | } | |
11050 | else | |
11051 | { | |
11052 | std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n"; | |
11053 | return 1; | |
11054 | } | |
11055 | } | |
d877e610 | 11056 | else if (aFlag == "-rebuildglsl" |
11057 | || aFlag == "-rebuild") | |
11058 | { | |
11059 | if (toPrint) | |
11060 | { | |
11061 | theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " "; | |
11062 | continue; | |
11063 | } | |
11064 | ||
11065 | Standard_Boolean toEnable = Standard_True; | |
11066 | if (++anArgIter < theArgNb | |
11067 | && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) | |
11068 | { | |
11069 | --anArgIter; | |
11070 | } | |
11071 | aParams.RebuildRayTracingShaders = toEnable; | |
11072 | } | |
b27ab03d | 11073 | else if (aFlag == "-focal") |
11074 | { | |
11075 | if (++anArgIter >= theArgNb) | |
11076 | { | |
11077 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11078 | return 1; | |
11079 | } | |
11080 | ||
11081 | TCollection_AsciiString aParam (theArgVec[anArgIter]); | |
11082 | if (aParam.IsRealValue()) | |
11083 | { | |
11084 | float aFocalDist = static_cast<float> (aParam.RealValue()); | |
11085 | if (aFocalDist < 0) | |
11086 | { | |
11087 | std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n"; | |
11088 | return 1; | |
11089 | } | |
11090 | aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist; | |
11091 | } | |
11092 | else | |
11093 | { | |
11094 | std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n"; | |
11095 | return 1; | |
11096 | } | |
11097 | } | |
11098 | else if (aFlag == "-aperture") | |
11099 | { | |
11100 | if (++anArgIter >= theArgNb) | |
11101 | { | |
11102 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11103 | return 1; | |
11104 | } | |
11105 | ||
11106 | TCollection_AsciiString aParam(theArgVec[anArgIter]); | |
11107 | if (aParam.IsRealValue()) | |
11108 | { | |
11109 | float aApertureSize = static_cast<float> (aParam.RealValue()); | |
11110 | if (aApertureSize < 0) | |
11111 | { | |
11112 | std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n"; | |
11113 | return 1; | |
11114 | } | |
11115 | aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize; | |
11116 | } | |
11117 | else | |
11118 | { | |
11119 | std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n"; | |
11120 | return 1; | |
11121 | } | |
11122 | } | |
eb85ed36 | 11123 | else if (aFlag == "-exposure") |
11124 | { | |
11125 | if (++anArgIter >= theArgNb) | |
11126 | { | |
11127 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11128 | return 1; | |
11129 | } | |
11130 | ||
11131 | TCollection_AsciiString anExposure (theArgVec[anArgIter]); | |
11132 | if (anExposure.IsRealValue()) | |
11133 | { | |
11134 | aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue()); | |
11135 | } | |
11136 | else | |
11137 | { | |
11138 | std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n"; | |
11139 | return 1; | |
11140 | } | |
11141 | } | |
11142 | else if (aFlag == "-whitepoint") | |
11143 | { | |
11144 | if (++anArgIter >= theArgNb) | |
11145 | { | |
11146 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11147 | return 1; | |
11148 | } | |
11149 | ||
11150 | TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]); | |
11151 | if (aWhitePoint.IsRealValue()) | |
11152 | { | |
11153 | aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue()); | |
11154 | } | |
11155 | else | |
11156 | { | |
11157 | std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n"; | |
11158 | return 1; | |
11159 | } | |
11160 | } | |
11161 | else if (aFlag == "-tonemapping") | |
11162 | { | |
11163 | if (++anArgIter >= theArgNb) | |
11164 | { | |
11165 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11166 | return 1; | |
11167 | } | |
11168 | ||
11169 | TCollection_AsciiString aMode (theArgVec[anArgIter]); | |
11170 | aMode.LowerCase(); | |
11171 | ||
11172 | if (aMode == "disabled") | |
11173 | { | |
11174 | aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled; | |
11175 | } | |
11176 | else if (aMode == "filmic") | |
11177 | { | |
11178 | aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic; | |
11179 | } | |
11180 | else | |
11181 | { | |
11182 | std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n"; | |
11183 | return 1; | |
11184 | } | |
11185 | } | |
15669413 | 11186 | else if (aFlag == "-performancestats" |
11187 | || aFlag == "-performancecounters" | |
11188 | || aFlag == "-perfstats" | |
11189 | || aFlag == "-perfcounters" | |
11190 | || aFlag == "-stats") | |
11191 | { | |
11192 | if (++anArgIter >= theArgNb) | |
11193 | { | |
11194 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11195 | return 1; | |
11196 | } | |
11197 | ||
11198 | TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]); | |
11199 | aFlagsStr.LowerCase(); | |
11200 | Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats; | |
11201 | if (!convertToPerfStatsFlags (aFlagsStr, aFlags)) | |
11202 | { | |
11203 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11204 | return 1; | |
11205 | } | |
11206 | aView->ChangeRenderingParams().CollectedStats = aFlags; | |
11207 | aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE; | |
11208 | } | |
11209 | else if (aFlag == "-perfupdateinterval" | |
11210 | || aFlag == "-statsupdateinterval") | |
11211 | { | |
11212 | if (++anArgIter >= theArgNb) | |
11213 | { | |
11214 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11215 | return 1; | |
11216 | } | |
11217 | aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]); | |
11218 | } | |
5e30547b | 11219 | else if (aFlag == "-perfchart" |
11220 | || aFlag == "-statschart") | |
11221 | { | |
11222 | if (++anArgIter >= theArgNb) | |
11223 | { | |
11224 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11225 | return 1; | |
11226 | } | |
11227 | aView->ChangeRenderingParams().StatsNbFrames = Draw::Atoi (theArgVec[anArgIter]); | |
11228 | } | |
11229 | else if (aFlag == "-perfchartmax" | |
11230 | || aFlag == "-statschartmax") | |
11231 | { | |
11232 | if (++anArgIter >= theArgNb) | |
11233 | { | |
11234 | std::cout << "Error: wrong syntax at argument '" << anArg << "'\n"; | |
11235 | return 1; | |
11236 | } | |
11237 | aView->ChangeRenderingParams().StatsMaxChartTime = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]); | |
11238 | } | |
0e3025bc | 11239 | else if (aFlag == "-frustumculling" |
11240 | || aFlag == "-culling") | |
11241 | { | |
11242 | if (toPrint) | |
11243 | { | |
11244 | theDI << ((aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On) ? "on" : | |
11245 | (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off) ? "off" : | |
11246 | "noUpdate") << " "; | |
11247 | continue; | |
11248 | } | |
11249 | ||
11250 | Graphic3d_RenderingParams::FrustumCulling aState = Graphic3d_RenderingParams::FrustumCulling_On; | |
11251 | if (++anArgIter < theArgNb) | |
11252 | { | |
11253 | TCollection_AsciiString aStateStr(theArgVec[anArgIter]); | |
11254 | aStateStr.LowerCase(); | |
11255 | bool toEnable = true; | |
11256 | if (ViewerTest::ParseOnOff (aStateStr.ToCString(), toEnable)) | |
11257 | { | |
11258 | aState = toEnable ? Graphic3d_RenderingParams::FrustumCulling_On : Graphic3d_RenderingParams::FrustumCulling_Off; | |
11259 | } | |
11260 | else if (aStateStr == "noupdate" | |
11261 | || aStateStr == "freeze") | |
11262 | { | |
11263 | aState = Graphic3d_RenderingParams::FrustumCulling_NoUpdate; | |
11264 | } | |
11265 | else | |
11266 | { | |
11267 | --anArgIter; | |
11268 | } | |
11269 | } | |
11270 | aParams.FrustumCullingState = aState; | |
11271 | } | |
e276548b | 11272 | else |
11273 | { | |
bc8c79bb | 11274 | std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n"; |
11275 | return 1; | |
e276548b | 11276 | } |
11277 | } | |
189f85a3 | 11278 | |
11279 | return 0; | |
11280 | } | |
11281 | ||
79b544e6 | 11282 | //======================================================================= |
11283 | //function : searchInfo | |
11284 | //purpose : | |
11285 | //======================================================================= | |
11286 | inline TCollection_AsciiString searchInfo (const TColStd_IndexedDataMapOfStringString& theDict, | |
11287 | const TCollection_AsciiString& theKey) | |
11288 | { | |
11289 | for (TColStd_IndexedDataMapOfStringString::Iterator anIter (theDict); anIter.More(); anIter.Next()) | |
11290 | { | |
11291 | if (TCollection_AsciiString::IsSameString (anIter.Key(), theKey, Standard_False)) | |
11292 | { | |
11293 | return anIter.Value(); | |
11294 | } | |
11295 | } | |
11296 | return TCollection_AsciiString(); | |
11297 | } | |
11298 | ||
11299 | //======================================================================= | |
11300 | //function : VStatProfiler | |
11301 | //purpose : | |
11302 | //======================================================================= | |
11303 | static Standard_Integer VStatProfiler (Draw_Interpretor& theDI, | |
11304 | Standard_Integer theArgNb, | |
11305 | const char** theArgVec) | |
11306 | { | |
11307 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
11308 | if (aView.IsNull()) | |
11309 | { | |
11310 | std::cerr << "Error: no active viewer!\n"; | |
11311 | return 1; | |
11312 | } | |
11313 | ||
11314 | Standard_Boolean toRedraw = Standard_True; | |
11315 | Graphic3d_RenderingParams::PerfCounters aPrevCounters = aView->ChangeRenderingParams().CollectedStats; | |
11316 | Standard_ShortReal aPrevUpdInterval = aView->ChangeRenderingParams().StatsUpdateInterval; | |
11317 | Graphic3d_RenderingParams::PerfCounters aRenderParams = Graphic3d_RenderingParams::PerfCounters_NONE; | |
11318 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
11319 | { | |
11320 | Standard_CString anArg (theArgVec[anArgIter]); | |
11321 | TCollection_AsciiString aFlag (anArg); | |
11322 | aFlag.LowerCase(); | |
11323 | if (aFlag == "-noredraw") | |
11324 | { | |
11325 | toRedraw = Standard_False; | |
11326 | } | |
11327 | else | |
11328 | { | |
11329 | Graphic3d_RenderingParams::PerfCounters aParam = Graphic3d_RenderingParams::PerfCounters_NONE; | |
11330 | if (aFlag == "fps") aParam = Graphic3d_RenderingParams::PerfCounters_FrameRate; | |
11331 | else if (aFlag == "cpu") aParam = Graphic3d_RenderingParams::PerfCounters_CPU; | |
11332 | else if (aFlag == "alllayers" | |
11333 | || aFlag == "layers") aParam = Graphic3d_RenderingParams::PerfCounters_Layers; | |
11334 | else if (aFlag == "allstructs" | |
11335 | || aFlag == "structs") aParam = Graphic3d_RenderingParams::PerfCounters_Structures; | |
11336 | else if (aFlag == "groups") aParam = Graphic3d_RenderingParams::PerfCounters_Groups; | |
11337 | else if (aFlag == "allarrays" | |
11338 | || aFlag == "fillarrays" | |
11339 | || aFlag == "linearrays" | |
11340 | || aFlag == "pointarrays" | |
11341 | || aFlag == "textarrays") aParam = Graphic3d_RenderingParams::PerfCounters_GroupArrays; | |
11342 | else if (aFlag == "triangles") aParam = Graphic3d_RenderingParams::PerfCounters_Triangles; | |
11343 | else if (aFlag == "points") aParam = Graphic3d_RenderingParams::PerfCounters_Points; | |
11344 | else if (aFlag == "geommem" | |
11345 | || aFlag == "texturemem" | |
11346 | || aFlag == "framemem") aParam = Graphic3d_RenderingParams::PerfCounters_EstimMem; | |
11347 | else if (aFlag == "elapsedframe" | |
11348 | || aFlag == "cpuframeaverage" | |
11349 | || aFlag == "cpupickingaverage" | |
11350 | || aFlag == "cpucullingaverage" | |
11351 | || aFlag == "cpudynaverage" | |
11352 | || aFlag == "cpuframemax" | |
11353 | || aFlag == "cpupickingmax" | |
11354 | || aFlag == "cpucullingmax" | |
11355 | || aFlag == "cpudynmax") aParam = Graphic3d_RenderingParams::PerfCounters_FrameTime; | |
11356 | else | |
11357 | { | |
11358 | std::cerr << "Unknown argument '" << theArgVec[anArgIter] << "'!\n"; | |
11359 | continue; | |
11360 | } | |
11361 | ||
11362 | aRenderParams = Graphic3d_RenderingParams::PerfCounters (aRenderParams | aParam); | |
11363 | } | |
11364 | } | |
11365 | ||
11366 | if (aRenderParams != Graphic3d_RenderingParams::PerfCounters_NONE) | |
11367 | { | |
11368 | aView->ChangeRenderingParams().CollectedStats = | |
11369 | Graphic3d_RenderingParams::PerfCounters (aView->RenderingParams().CollectedStats | aRenderParams); | |
11370 | ||
11371 | if (toRedraw) | |
11372 | { | |
11373 | aView->ChangeRenderingParams().StatsUpdateInterval = -1; | |
11374 | aView->Redraw(); | |
11375 | aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval; | |
11376 | } | |
11377 | ||
11378 | TColStd_IndexedDataMapOfStringString aDict; | |
11379 | aView->StatisticInformation (aDict); | |
11380 | ||
11381 | aView->ChangeRenderingParams().CollectedStats = aPrevCounters; | |
11382 | ||
11383 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
11384 | { | |
11385 | Standard_CString anArg(theArgVec[anArgIter]); | |
11386 | TCollection_AsciiString aFlag(anArg); | |
11387 | aFlag.LowerCase(); | |
11388 | if (aFlag == "fps") | |
11389 | { | |
11390 | theDI << searchInfo (aDict, "FPS") << " "; | |
11391 | } | |
11392 | else if (aFlag == "cpu") | |
11393 | { | |
11394 | theDI << searchInfo (aDict, "CPU FPS") << " "; | |
11395 | } | |
11396 | else if (aFlag == "alllayers") | |
11397 | { | |
11398 | theDI << searchInfo (aDict, "Layers") << " "; | |
11399 | } | |
11400 | else if (aFlag == "layers") | |
11401 | { | |
11402 | theDI << searchInfo (aDict, "Rendered layers") << " "; | |
11403 | } | |
11404 | else if (aFlag == "allstructs") | |
11405 | { | |
11406 | theDI << searchInfo (aDict, "Structs") << " "; | |
11407 | } | |
11408 | else if (aFlag == "structs") | |
11409 | { | |
11410 | theDI << searchInfo (aDict, "Rendered structs") << " "; | |
11411 | } | |
11412 | else if (aFlag == "groups") | |
11413 | { | |
11414 | theDI << searchInfo (aDict, "Rendered groups") << " "; | |
11415 | } | |
11416 | else if (aFlag == "allarrays") | |
11417 | { | |
11418 | theDI << searchInfo (aDict, "Rendered arrays") << " "; | |
11419 | } | |
11420 | else if (aFlag == "fillarrays") | |
11421 | { | |
11422 | theDI << searchInfo (aDict, "Rendered [fill] arrays") << " "; | |
11423 | } | |
11424 | else if (aFlag == "linearrays") | |
11425 | { | |
11426 | theDI << searchInfo (aDict, "Rendered [line] arrays") << " "; | |
11427 | } | |
11428 | else if (aFlag == "pointarrays") | |
11429 | { | |
11430 | theDI << searchInfo (aDict, "Rendered [point] arrays") << " "; | |
11431 | } | |
11432 | else if (aFlag == "textarrays") | |
11433 | { | |
11434 | theDI << searchInfo (aDict, "Rendered [text] arrays") << " "; | |
11435 | } | |
11436 | else if (aFlag == "triangles") | |
11437 | { | |
11438 | theDI << searchInfo (aDict, "Rendered triangles") << " "; | |
11439 | } | |
11440 | else if (aFlag == "points") | |
11441 | { | |
11442 | theDI << searchInfo (aDict, "Rendered points") << " "; | |
11443 | } | |
11444 | else if (aFlag == "geommem") | |
11445 | { | |
11446 | theDI << searchInfo (aDict, "GPU Memory [geometry]") << " "; | |
11447 | } | |
11448 | else if (aFlag == "texturemem") | |
11449 | { | |
11450 | theDI << searchInfo (aDict, "GPU Memory [textures]") << " "; | |
11451 | } | |
11452 | else if (aFlag == "framemem") | |
11453 | { | |
11454 | theDI << searchInfo (aDict, "GPU Memory [frames]") << " "; | |
11455 | } | |
11456 | else if (aFlag == "elapsedframe") | |
11457 | { | |
11458 | theDI << searchInfo (aDict, "Elapsed Frame (average)") << " "; | |
11459 | } | |
11460 | else if (aFlag == "cpuframe_average") | |
11461 | { | |
11462 | theDI << searchInfo (aDict, "CPU Frame (average)") << " "; | |
11463 | } | |
11464 | else if (aFlag == "cpupicking_average") | |
11465 | { | |
11466 | theDI << searchInfo (aDict, "CPU Picking (average)") << " "; | |
11467 | } | |
11468 | else if (aFlag == "cpuculling_average") | |
11469 | { | |
11470 | theDI << searchInfo (aDict, "CPU Culling (average)") << " "; | |
11471 | } | |
11472 | else if (aFlag == "cpudyn_average") | |
11473 | { | |
11474 | theDI << searchInfo (aDict, "CPU Dynamics (average)") << " "; | |
11475 | } | |
11476 | else if (aFlag == "cpuframe_max") | |
11477 | { | |
11478 | theDI << searchInfo (aDict, "CPU Frame (max)") << " "; | |
11479 | } | |
11480 | else if (aFlag == "cpupicking_max") | |
11481 | { | |
11482 | theDI << searchInfo (aDict, "CPU Picking (max)") << " "; | |
11483 | } | |
11484 | else if (aFlag == "cpuculling_max") | |
11485 | { | |
11486 | theDI << searchInfo (aDict, "CPU Culling (max)") << " "; | |
11487 | } | |
11488 | else if (aFlag == "cpudyn_max") | |
11489 | { | |
11490 | theDI << searchInfo (aDict, "CPU Dynamics (max)") << " "; | |
11491 | } | |
11492 | } | |
11493 | } | |
11494 | else | |
11495 | { | |
11496 | if (toRedraw) | |
11497 | { | |
11498 | aView->ChangeRenderingParams().StatsUpdateInterval = -1; | |
11499 | aView->Redraw(); | |
11500 | aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval; | |
11501 | } | |
11502 | theDI << "Statistic info:\n" << aView->StatisticInformation(); | |
11503 | } | |
11504 | return 0; | |
11505 | } | |
11506 | ||
189f85a3 | 11507 | //======================================================================= |
11508 | //function : VProgressiveMode | |
11509 | //purpose : | |
11510 | //======================================================================= | |
11511 | #if defined(_WIN32) | |
11512 | static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/, | |
11513 | Standard_Integer /*theNbArgs*/, | |
11514 | const char** /*theArgs*/) | |
11515 | { | |
11516 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
11517 | if (aView.IsNull()) | |
11518 | { | |
11519 | std::cerr << "Error: no active viewer!\n"; | |
11520 | return 1; | |
11521 | } | |
11522 | ||
11523 | std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl; | |
11524 | ||
11525 | for (;;) | |
11526 | { | |
11527 | aView->Redraw(); | |
11528 | ||
11529 | Standard_Boolean toExit = Standard_False; | |
11530 | ||
11531 | MSG aMsg; | |
ad03c234 | 11532 | while (PeekMessageW (&aMsg, NULL, 0, 0, PM_REMOVE)) |
189f85a3 | 11533 | { |
11534 | if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b)) | |
11535 | { | |
11536 | toExit = Standard_True; | |
11537 | } | |
11538 | ||
11539 | TranslateMessage (&aMsg); | |
ad03c234 | 11540 | DispatchMessageW (&aMsg); |
189f85a3 | 11541 | } |
11542 | ||
11543 | if (toExit) | |
11544 | { | |
11545 | break; | |
11546 | } | |
11547 | } | |
11548 | ||
e276548b | 11549 | return 0; |
11550 | } | |
189f85a3 | 11551 | #endif |
e276548b | 11552 | |
0717ddc1 | 11553 | //======================================================================= |
11554 | //function : VXRotate | |
11555 | //purpose : | |
11556 | //======================================================================= | |
11557 | static Standard_Integer VXRotate (Draw_Interpretor& di, | |
11558 | Standard_Integer argc, | |
11559 | const char ** argv) | |
11560 | { | |
11561 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
11562 | if (aContext.IsNull()) | |
11563 | { | |
586db386 | 11564 | di << argv[0] << "ERROR : use 'vinit' command before \n"; |
0717ddc1 | 11565 | return 1; |
11566 | } | |
11567 | ||
11568 | if (argc != 3) | |
11569 | { | |
586db386 | 11570 | di << "ERROR : Usage : " << argv[0] << " name angle\n"; |
0717ddc1 | 11571 | return 1; |
11572 | } | |
11573 | ||
11574 | TCollection_AsciiString aName (argv[1]); | |
11575 | Standard_Real anAngle = Draw::Atof (argv[2]); | |
11576 | ||
11577 | // find object | |
11578 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
11579 | Handle(AIS_InteractiveObject) anIObj; | |
8f521168 | 11580 | if (!aMap.Find2 (aName, anIObj)) |
0717ddc1 | 11581 | { |
586db386 | 11582 | di << "Use 'vdisplay' before\n"; |
0717ddc1 | 11583 | return 1; |
11584 | } | |
0717ddc1 | 11585 | |
8f521168 | 11586 | gp_Trsf aTransform; |
11587 | aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle); | |
11588 | aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart()); | |
0717ddc1 | 11589 | |
8f521168 | 11590 | aContext->SetLocation (anIObj, aTransform); |
11591 | aContext->UpdateCurrentViewer(); | |
0717ddc1 | 11592 | return 0; |
11593 | } | |
11594 | ||
625e1958 | 11595 | //=============================================================================================== |
11596 | //class : ViewerTest_AISManipulator | |
11597 | //purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances | |
11598 | //=============================================================================================== | |
11599 | DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator) | |
11600 | ||
11601 | class ViewerTest_AISManipulator : public AIS_Manipulator | |
11602 | { | |
11603 | public: | |
11604 | ||
11605 | ViewerTest_AISManipulator() : AIS_Manipulator() | |
11606 | { | |
11607 | GetMapOfAISManipulators().Add (this); | |
11608 | } | |
11609 | ||
11610 | virtual ~ViewerTest_AISManipulator() | |
11611 | { | |
11612 | GetMapOfAISManipulators().Remove (this); | |
11613 | } | |
11614 | ||
11615 | DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator) | |
11616 | }; | |
11617 | ||
11618 | IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator) | |
11619 | IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator) | |
11620 | ||
11621 | //=============================================================================================== | |
11622 | //function : VManipulator | |
11623 | //purpose : | |
11624 | //=============================================================================================== | |
11625 | static int VManipulator (Draw_Interpretor& theDi, | |
11626 | Standard_Integer theArgsNb, | |
11627 | const char** theArgVec) | |
11628 | { | |
11629 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
11630 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
11631 | ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False); | |
11632 | if (aView.IsNull() | |
11633 | || aViewer.IsNull()) | |
11634 | { | |
11635 | std::cerr << "No active viewer!\n"; | |
11636 | return 1; | |
11637 | } | |
11638 | ||
11639 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView()); | |
11640 | Standard_Integer anArgIter = 1; | |
11641 | for (; anArgIter < theArgsNb; ++anArgIter) | |
11642 | { | |
11643 | anUpdateTool.parseRedrawMode (theArgVec[anArgIter]); | |
11644 | } | |
11645 | ||
11646 | ViewerTest_CmdParser aCmd; | |
11647 | aCmd.AddDescription ("Manages manipulator for interactive objects:"); | |
11648 | aCmd.AddOption ("attach", "... object - attach manipulator to an object"); | |
11649 | aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching"); | |
11650 | aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching "); | |
11651 | aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching "); | |
11652 | aCmd.AddOption ("detach", "... - detach manipulator"); | |
11653 | ||
11654 | aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation"); | |
11655 | aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation"); | |
11656 | aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation"); | |
11657 | ||
11658 | aCmd.AddOption ("move", "... x y z - move object"); | |
11659 | aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object"); | |
11660 | aCmd.AddOption ("scale", "... factor - scale object"); | |
11661 | ||
11662 | aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection"); | |
11663 | aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform"); | |
11664 | aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform"); | |
11665 | aCmd.AddOption ("gap", "... value - set gap between sub-parts"); | |
11666 | aCmd.AddOption ("part", "... axis mode {0|1} - set visual part"); | |
11667 | aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator"); | |
11668 | aCmd.AddOption ("size", "... size - set size of manipulator"); | |
11669 | aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence"); | |
11670 | ||
11671 | aCmd.Parse (theArgsNb, theArgVec); | |
11672 | ||
11673 | if (aCmd.HasOption ("help")) | |
11674 | { | |
11675 | theDi.PrintHelp (theArgVec[0]); | |
11676 | return 0; | |
11677 | } | |
11678 | ||
11679 | ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS(); | |
11680 | ||
11681 | TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str()); | |
11682 | ||
11683 | if (aName.IsEmpty()) | |
11684 | { | |
11685 | std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n"; | |
11686 | return 1; | |
11687 | } | |
11688 | ||
11689 | // ---------------------------------- | |
11690 | // detach existing manipulator object | |
11691 | // ---------------------------------- | |
11692 | ||
11693 | if (aCmd.HasOption ("detach")) | |
11694 | { | |
11695 | if (!aMapAIS.IsBound2 (aName)) | |
11696 | { | |
11697 | std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n"; | |
11698 | return 1; | |
11699 | } | |
11700 | ||
11701 | Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName)); | |
11702 | if (aManipulator.IsNull()) | |
11703 | { | |
11704 | std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n"; | |
11705 | return 1; | |
11706 | } | |
11707 | ||
11708 | aManipulator->Detach(); | |
11709 | aMapAIS.UnBind2 (aName); | |
0577ae8c | 11710 | ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True); |
625e1958 | 11711 | |
11712 | return 0; | |
11713 | } | |
11714 | ||
11715 | // ----------------------------------------------- | |
11716 | // find or create manipulator if it does not exist | |
11717 | // ----------------------------------------------- | |
11718 | ||
11719 | Handle(AIS_Manipulator) aManipulator; | |
11720 | if (!aMapAIS.IsBound2 (aName)) | |
11721 | { | |
11722 | std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n"; | |
11723 | ||
11724 | aManipulator = new ViewerTest_AISManipulator(); | |
11725 | aMapAIS.Bind (aManipulator, aName); | |
11726 | } | |
11727 | else | |
11728 | { | |
11729 | aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName)); | |
11730 | if (aManipulator.IsNull()) | |
11731 | { | |
11732 | std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n"; | |
11733 | return 1; | |
11734 | } | |
11735 | } | |
11736 | ||
11737 | // ----------------------------------------- | |
11738 | // change properties of manipulator instance | |
11739 | // ----------------------------------------- | |
11740 | ||
11741 | if (aCmd.HasOption ("autoActivate", 1, Standard_True)) | |
11742 | { | |
11743 | aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate")); | |
11744 | } | |
11745 | if (aCmd.HasOption ("followTranslation", 1, Standard_True)) | |
11746 | { | |
11747 | aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation")); | |
11748 | } | |
11749 | if (aCmd.HasOption ("followRotation", 1, Standard_True)) | |
11750 | { | |
11751 | aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation")); | |
11752 | } | |
11753 | if (aCmd.HasOption ("gap", 1, Standard_True)) | |
11754 | { | |
11755 | aManipulator->SetGap (aCmd.ArgFloat ("gap")); | |
11756 | } | |
11757 | if (aCmd.HasOption ("part", 3, Standard_True)) | |
11758 | { | |
11759 | Standard_Integer anAxis = aCmd.ArgInt ("part", 0); | |
11760 | Standard_Integer aMode = aCmd.ArgInt ("part", 1); | |
11761 | Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2); | |
11762 | if (aMode < 1 || aMode > 3) | |
11763 | { | |
11764 | std::cerr << theArgVec[0] << " error: mode value should be in range [1, 3].\n"; | |
11765 | return 1; | |
11766 | } | |
11767 | ||
11768 | aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff); | |
11769 | } | |
11770 | if (aCmd.HasOption ("pos", 3, Standard_True)) | |
11771 | { | |
11772 | gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0); | |
11773 | gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction(); | |
11774 | gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection(); | |
11775 | ||
11776 | aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir)); | |
11777 | } | |
11778 | if (aCmd.HasOption ("size", 1, Standard_True)) | |
11779 | { | |
11780 | aManipulator->SetSize (aCmd.ArgFloat ("size")); | |
11781 | } | |
11782 | if (aCmd.HasOption ("zoomable", 1, Standard_True)) | |
11783 | { | |
11784 | aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable")); | |
11785 | ||
11786 | if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator)) | |
11787 | { | |
11788 | ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False); | |
11789 | ViewerTest::GetAISContext()->Display (aManipulator, Standard_False); | |
11790 | } | |
11791 | } | |
11792 | ||
11793 | // --------------------------------------------------- | |
11794 | // attach, detach or access manipulator from an object | |
11795 | // --------------------------------------------------- | |
11796 | ||
11797 | if (aCmd.HasOption ("attach")) | |
11798 | { | |
11799 | // Find an object and attach manipulator to it | |
11800 | if (!aCmd.HasOption ("attach", 1, Standard_True)) | |
11801 | { | |
11802 | return 1; | |
11803 | } | |
11804 | ||
11805 | TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str()); | |
8f521168 | 11806 | Handle(AIS_InteractiveObject) anObject; |
11807 | if (!aMapAIS.Find2 (anObjName, anObject)) | |
625e1958 | 11808 | { |
11809 | std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n"; | |
11810 | return 1; | |
11811 | } | |
11812 | ||
8f521168 | 11813 | for (ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators()); anIt.More(); anIt.Next()) |
625e1958 | 11814 | { |
11815 | if (anIt.Value()->IsAttached() | |
11816 | && anIt.Value()->Object() == anObject) | |
11817 | { | |
11818 | std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n"; | |
11819 | return 1; | |
11820 | } | |
11821 | } | |
11822 | ||
11823 | AIS_Manipulator::OptionsForAttach anOptions; | |
11824 | if (aCmd.HasOption ("adjustPosition", 1, Standard_True)) | |
11825 | { | |
11826 | anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition")); | |
11827 | } | |
11828 | if (aCmd.HasOption ("adjustSize", 1, Standard_True)) | |
11829 | { | |
11830 | anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize")); | |
11831 | } | |
11832 | if (aCmd.HasOption ("enableModes", 1, Standard_True)) | |
11833 | { | |
11834 | anOptions.SetEnableModes (aCmd.ArgBool ("enableModes")); | |
11835 | } | |
11836 | ||
11837 | aManipulator->Attach (anObject, anOptions); | |
11838 | } | |
11839 | ||
11840 | // -------------------------------------- | |
11841 | // apply transformation using manipulator | |
11842 | // -------------------------------------- | |
11843 | ||
11844 | if (aCmd.HasOption ("startTransform", 2, Standard_True)) | |
11845 | { | |
11846 | aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView()); | |
11847 | } | |
11848 | if (aCmd.HasOption ("transform", 2, Standard_True)) | |
11849 | { | |
11850 | aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView()); | |
11851 | } | |
11852 | if (aCmd.HasOption ("stopTransform")) | |
11853 | { | |
11854 | Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort"); | |
11855 | ||
11856 | aManipulator->StopTransform (toApply); | |
11857 | } | |
11858 | ||
11859 | gp_Trsf aT; | |
11860 | if (aCmd.HasOption ("move", 3, Standard_True)) | |
11861 | { | |
11862 | aT.SetTranslationPart (aCmd.ArgVec ("move")); | |
11863 | } | |
11864 | if (aCmd.HasOption ("rotate", 7, Standard_True)) | |
11865 | { | |
11866 | aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6)); | |
11867 | } | |
11868 | if (aCmd.HasOption ("scale", 1)) | |
11869 | { | |
11870 | aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale")); | |
11871 | } | |
11872 | ||
11873 | if (aT.Form() != gp_Identity) | |
11874 | { | |
11875 | aManipulator->Transform (aT); | |
11876 | } | |
11877 | ||
0577ae8c | 11878 | ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True); |
625e1958 | 11879 | |
11880 | return 0; | |
11881 | } | |
11882 | ||
8e5fb5ea | 11883 | //=============================================================================================== |
11884 | //function : VSelectionProperties | |
11885 | //purpose : | |
11886 | //=============================================================================================== | |
11887 | static int VSelectionProperties (Draw_Interpretor& theDi, | |
11888 | Standard_Integer theArgsNb, | |
11889 | const char** theArgVec) | |
11890 | { | |
11891 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); | |
11892 | if (aCtx.IsNull()) | |
11893 | { | |
11894 | std::cerr << "No active viewer!\n"; | |
11895 | return 1; | |
11896 | } | |
11897 | ||
be3d8cbc | 11898 | if (TCollection_AsciiString (theArgVec[0]) == "vhighlightselected") |
11899 | { | |
11900 | // handle obsolete alias | |
11901 | bool toEnable = true; | |
11902 | if (theArgsNb < 2) | |
11903 | { | |
11904 | theDi << (aCtx->ToHilightSelected() ? "on" : "off"); | |
11905 | return 0; | |
11906 | } | |
11907 | else if (theArgsNb != 2 | |
11908 | || !ViewerTest::ParseOnOff (theArgVec[1], toEnable)) | |
11909 | { | |
11910 | std::cout << "Syntax error: wrong number of parameters."; | |
11911 | return 1; | |
11912 | } | |
11913 | if (toEnable != aCtx->ToHilightSelected()) | |
11914 | { | |
11915 | aCtx->ClearDetected(); | |
11916 | aCtx->SetToHilightSelected (toEnable); | |
11917 | } | |
11918 | return 0; | |
11919 | } | |
11920 | ||
f838dac4 | 11921 | Standard_Boolean toPrint = theArgsNb == 1; |
11922 | Standard_Boolean toRedraw = Standard_False; | |
11923 | Standard_Integer anArgIter = 1; | |
11924 | Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None; | |
11925 | if (anArgIter < theArgsNb) | |
11926 | { | |
11927 | TCollection_AsciiString anArgFirst (theArgVec[anArgIter]); | |
11928 | anArgFirst.LowerCase(); | |
11929 | ++anArgIter; | |
11930 | if (anArgFirst == "dynhighlight" | |
11931 | || anArgFirst == "dynhilight" | |
11932 | || anArgFirst == "dynamichighlight" | |
11933 | || anArgFirst == "dynamichilight") | |
11934 | { | |
11935 | aType = Prs3d_TypeOfHighlight_Dynamic; | |
11936 | } | |
11937 | else if (anArgFirst == "localdynhighlight" | |
11938 | || anArgFirst == "localdynhilight" | |
11939 | || anArgFirst == "localdynamichighlight" | |
11940 | || anArgFirst == "localdynamichilight") | |
11941 | { | |
11942 | aType = Prs3d_TypeOfHighlight_LocalDynamic; | |
11943 | } | |
11944 | else if (anArgFirst == "selhighlight" | |
11945 | || anArgFirst == "selhilight" | |
11946 | || anArgFirst == "selectedhighlight" | |
11947 | || anArgFirst == "selectedhilight") | |
11948 | { | |
11949 | aType = Prs3d_TypeOfHighlight_Selected; | |
11950 | } | |
11951 | else if (anArgFirst == "localselhighlight" | |
11952 | || anArgFirst == "localselhilight" | |
11953 | || anArgFirst == "localselectedhighlight" | |
11954 | || anArgFirst == "localselectedhilight") | |
11955 | { | |
11956 | aType = Prs3d_TypeOfHighlight_LocalSelected; | |
11957 | } | |
11958 | else | |
11959 | { | |
11960 | --anArgIter; | |
11961 | } | |
11962 | } | |
11963 | for (; anArgIter < theArgsNb; ++anArgIter) | |
11964 | { | |
11965 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
11966 | anArg.LowerCase(); | |
11967 | if (anArg == "-help") | |
11968 | { | |
11969 | theDi.PrintHelp (theArgVec[0]); | |
11970 | return 0; | |
11971 | } | |
11972 | else if (anArg == "-print") | |
11973 | { | |
11974 | toPrint = Standard_True; | |
11975 | } | |
11976 | else if (anArg == "-autoactivate") | |
11977 | { | |
11978 | Standard_Boolean toEnable = Standard_True; | |
11979 | if (anArgIter + 1 < theArgsNb | |
11980 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
11981 | { | |
11982 | ++anArgIter; | |
11983 | } | |
11984 | aCtx->SetAutoActivateSelection (toEnable); | |
11985 | } | |
be3d8cbc | 11986 | else if (anArg == "-automatichighlight" |
11987 | || anArg == "-automatichilight" | |
11988 | || anArg == "-autohighlight" | |
11989 | || anArg == "-autohilight") | |
11990 | { | |
11991 | Standard_Boolean toEnable = Standard_True; | |
11992 | if (anArgIter + 1 < theArgsNb | |
11993 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
11994 | { | |
11995 | ++anArgIter; | |
11996 | } | |
11997 | aCtx->ClearSelected (false); | |
11998 | aCtx->ClearDetected(); | |
11999 | aCtx->SetAutomaticHilight (toEnable); | |
12000 | toRedraw = true; | |
12001 | } | |
12002 | else if (anArg == "-highlightselected" | |
12003 | || anArg == "-hilightselected") | |
12004 | { | |
12005 | Standard_Boolean toEnable = Standard_True; | |
12006 | if (anArgIter + 1 < theArgsNb | |
12007 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
12008 | { | |
12009 | ++anArgIter; | |
12010 | } | |
12011 | aCtx->ClearDetected(); | |
12012 | aCtx->SetToHilightSelected (toEnable); | |
12013 | toRedraw = true; | |
12014 | } | |
14c4193d | 12015 | else if (anArg == "-pickstrategy" |
12016 | || anArg == "-pickingstrategy") | |
12017 | { | |
12018 | if (++anArgIter >= theArgsNb) | |
12019 | { | |
12020 | std::cout << "Syntax error: type of highlighting is undefined\n"; | |
12021 | return 1; | |
12022 | } | |
12023 | ||
12024 | SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable; | |
12025 | TCollection_AsciiString aVal (theArgVec[anArgIter]); | |
12026 | aVal.LowerCase(); | |
12027 | if (aVal == "first" | |
12028 | || aVal == "firstaccepted" | |
12029 | || aVal == "firstacceptable") | |
12030 | { | |
12031 | aStrategy = SelectMgr_PickingStrategy_FirstAcceptable; | |
12032 | } | |
12033 | else if (aVal == "topmost" | |
12034 | || aVal == "onlyTopmost") | |
12035 | { | |
12036 | aStrategy = SelectMgr_PickingStrategy_OnlyTopmost; | |
12037 | } | |
12038 | else | |
12039 | { | |
12040 | std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n"; | |
12041 | return 1; | |
12042 | } | |
12043 | ||
12044 | aCtx->SetPickingStrategy (aStrategy); | |
12045 | } | |
f838dac4 | 12046 | else if (anArg == "-pixtol" |
12047 | && anArgIter + 1 < theArgsNb) | |
12048 | { | |
12049 | aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter])); | |
12050 | } | |
12051 | else if ((anArg == "-mode" | |
12052 | || anArg == "-dispmode") | |
12053 | && anArgIter + 1 < theArgsNb) | |
12054 | { | |
12055 | if (aType == Prs3d_TypeOfHighlight_None) | |
12056 | { | |
12057 | std::cout << "Syntax error: type of highlighting is undefined\n"; | |
12058 | return 1; | |
12059 | } | |
8e5fb5ea | 12060 | |
f838dac4 | 12061 | const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]); |
12062 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); | |
12063 | aStyle->SetDisplayMode (aDispMode); | |
12064 | toRedraw = Standard_True; | |
12065 | } | |
12066 | else if (anArg == "-layer" | |
12067 | && anArgIter + 1 < theArgsNb) | |
12068 | { | |
12069 | if (aType == Prs3d_TypeOfHighlight_None) | |
12070 | { | |
12071 | std::cout << "Syntax error: type of highlighting is undefined\n"; | |
12072 | return 1; | |
12073 | } | |
8e5fb5ea | 12074 | |
f838dac4 | 12075 | const Standard_Integer aNewLayer = Draw::Atoi (theArgVec[++anArgIter]); |
12076 | if (aNewLayer != Graphic3d_ZLayerId_UNKNOWN) | |
12077 | { | |
12078 | TColStd_SequenceOfInteger aLayers; | |
12079 | aCtx->CurrentViewer()->GetAllZLayers (aLayers); | |
12080 | if (std::find (aLayers.begin(), aLayers.end(), aNewLayer) == aLayers.end()) | |
12081 | { | |
12082 | std::cout << "Syntax error: Layer " << aNewLayer << " is undefined\n"; | |
12083 | return 1; | |
12084 | } | |
12085 | } | |
8e5fb5ea | 12086 | |
f838dac4 | 12087 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); |
12088 | aStyle->SetZLayer (aNewLayer); | |
12089 | toRedraw = Standard_True; | |
12090 | } | |
12091 | else if (anArg == "-hicolor" | |
12092 | || anArg == "-selcolor" | |
12093 | || anArg == "-color") | |
12094 | { | |
12095 | if (anArg.StartsWith ("-hi")) | |
12096 | { | |
12097 | aType = Prs3d_TypeOfHighlight_Dynamic; | |
12098 | } | |
12099 | else if (anArg.StartsWith ("-sel")) | |
12100 | { | |
12101 | aType = Prs3d_TypeOfHighlight_Selected; | |
12102 | } | |
12103 | else if (aType == Prs3d_TypeOfHighlight_None) | |
12104 | { | |
12105 | std::cout << "Syntax error: type of highlighting is undefined\n"; | |
12106 | return 1; | |
12107 | } | |
8e5fb5ea | 12108 | |
f838dac4 | 12109 | Quantity_Color aColor; |
12110 | Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1, | |
12111 | theArgVec + anArgIter + 1, | |
12112 | aColor); | |
12113 | if (aNbParsed == 0) | |
12114 | { | |
12115 | std::cout << "Syntax error: need more arguments.\n"; | |
12116 | return 1; | |
12117 | } | |
12118 | anArgIter += aNbParsed; | |
8e5fb5ea | 12119 | |
f838dac4 | 12120 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); |
12121 | aStyle->SetColor (aColor); | |
12122 | toRedraw = Standard_True; | |
12123 | } | |
12124 | else if ((anArg == "-transp" | |
12125 | || anArg == "-transparency" | |
12126 | || anArg == "-hitransp" | |
12127 | || anArg == "-seltransp" | |
12128 | || anArg == "-hitransplocal" | |
12129 | || anArg == "-seltransplocal") | |
12130 | && anArgIter + 1 < theArgsNb) | |
12131 | { | |
12132 | if (anArg.StartsWith ("-hi")) | |
12133 | { | |
12134 | aType = Prs3d_TypeOfHighlight_Dynamic; | |
12135 | } | |
12136 | else if (anArg.StartsWith ("-sel")) | |
12137 | { | |
12138 | aType = Prs3d_TypeOfHighlight_Selected; | |
12139 | } | |
12140 | else if (aType == Prs3d_TypeOfHighlight_None) | |
12141 | { | |
12142 | std::cout << "Syntax error: type of highlighting is undefined\n"; | |
12143 | return 1; | |
12144 | } | |
8e5fb5ea | 12145 | |
f838dac4 | 12146 | const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]); |
12147 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); | |
12148 | aStyle->SetTransparency ((Standard_ShortReal )aTransp); | |
12149 | toRedraw = Standard_True; | |
12150 | } | |
12151 | else if ((anArg == "-mat" | |
12152 | || anArg == "-material") | |
12153 | && anArgIter + 1 < theArgsNb) | |
12154 | { | |
12155 | if (aType == Prs3d_TypeOfHighlight_None) | |
12156 | { | |
12157 | std::cout << "Syntax error: type of highlighting is undefined\n"; | |
12158 | return 1; | |
12159 | } | |
8e5fb5ea | 12160 | |
f838dac4 | 12161 | const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType); |
12162 | Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]); | |
12163 | if (aMatName != Graphic3d_NOM_DEFAULT) | |
12164 | { | |
12165 | ++anArgIter; | |
12166 | Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d(); | |
12167 | *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect(); | |
12168 | Graphic3d_MaterialAspect aMat (aMatName); | |
12169 | aMat.SetColor (aStyle->Color()); | |
12170 | aMat.SetTransparency (aStyle->Transparency()); | |
12171 | anAspect->SetFrontMaterial (aMat); | |
12172 | anAspect->SetInteriorColor (aStyle->Color()); | |
12173 | aStyle->SetBasicFillAreaAspect (anAspect); | |
12174 | } | |
12175 | else | |
12176 | { | |
12177 | aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)()); | |
12178 | } | |
12179 | toRedraw = Standard_True; | |
12180 | } | |
12181 | else | |
12182 | { | |
12183 | std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n"; | |
12184 | } | |
8e5fb5ea | 12185 | } |
12186 | ||
f838dac4 | 12187 | if (toPrint) |
8e5fb5ea | 12188 | { |
f838dac4 | 12189 | const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle(); |
12190 | const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle(); | |
8e5fb5ea | 12191 | theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n"; |
be3d8cbc | 12192 | theDi << "Auto-highlight : " << (aCtx->AutomaticHilight() ? "On" : "Off") << "\n"; |
12193 | theDi << "Highlight selected : " << (aCtx->ToHilightSelected() ? "On" : "Off") << "\n"; | |
8e5fb5ea | 12194 | theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n"; |
f838dac4 | 12195 | theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n"; |
12196 | theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n"; | |
12197 | theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n"; | |
12198 | theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n"; | |
12199 | theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n"; | |
12200 | theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n"; | |
12201 | theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n"; | |
12202 | theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n"; | |
8e5fb5ea | 12203 | } |
12204 | ||
12205 | if (aCtx->NbSelected() != 0 && toRedraw) | |
12206 | { | |
12207 | aCtx->HilightSelected (Standard_True); | |
12208 | } | |
12209 | ||
12210 | return 0; | |
12211 | } | |
12212 | ||
decdee7d | 12213 | //=============================================================================================== |
12214 | //function : VDumpSelectionImage | |
12215 | //purpose : | |
12216 | //=============================================================================================== | |
12217 | static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/, | |
12218 | Standard_Integer theArgsNb, | |
12219 | const char** theArgVec) | |
12220 | { | |
12221 | if (theArgsNb < 2) | |
12222 | { | |
12223 | std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n"; | |
12224 | return 1; | |
12225 | } | |
12226 | ||
12227 | const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext(); | |
12228 | if (aContext.IsNull()) | |
12229 | { | |
12230 | std::cout << "Error: no active view.\n"; | |
12231 | return 1; | |
12232 | } | |
12233 | ||
12234 | TCollection_AsciiString aFile; | |
12235 | StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth; | |
dc858f4c | 12236 | Image_Format anImgFormat = Image_Format_BGR; |
decdee7d | 12237 | Standard_Integer aPickedIndex = 1; |
12238 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
12239 | { | |
12240 | TCollection_AsciiString aParam (theArgVec[anArgIter]); | |
12241 | aParam.LowerCase(); | |
12242 | if (aParam == "-type") | |
12243 | { | |
12244 | if (++anArgIter >= theArgsNb) | |
12245 | { | |
12246 | std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n"; | |
12247 | return 1; | |
12248 | } | |
12249 | ||
12250 | TCollection_AsciiString aValue (theArgVec[anArgIter]); | |
12251 | aValue.LowerCase(); | |
12252 | if (aValue == "depth" | |
12253 | || aValue == "normdepth" | |
12254 | || aValue == "normalizeddepth") | |
12255 | { | |
12256 | aType = StdSelect_TypeOfSelectionImage_NormalizedDepth; | |
dc858f4c | 12257 | anImgFormat = Image_Format_GrayF; |
decdee7d | 12258 | } |
12259 | if (aValue == "depthinverted" | |
12260 | || aValue == "normdepthinverted" | |
12261 | || aValue == "normalizeddepthinverted" | |
12262 | || aValue == "inverted") | |
12263 | { | |
12264 | aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted; | |
dc858f4c | 12265 | anImgFormat = Image_Format_GrayF; |
decdee7d | 12266 | } |
12267 | else if (aValue == "unnormdepth" | |
12268 | || aValue == "unnormalizeddepth") | |
12269 | { | |
12270 | aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth; | |
dc858f4c | 12271 | anImgFormat = Image_Format_GrayF; |
decdee7d | 12272 | } |
12273 | else if (aValue == "objectcolor" | |
12274 | || aValue == "object" | |
12275 | || aValue == "color") | |
12276 | { | |
12277 | aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject; | |
12278 | } | |
12279 | else if (aValue == "entitycolor" | |
12280 | || aValue == "entity") | |
12281 | { | |
12282 | aType = StdSelect_TypeOfSelectionImage_ColoredEntity; | |
12283 | } | |
12284 | else if (aValue == "ownercolor" | |
12285 | || aValue == "owner") | |
12286 | { | |
12287 | aType = StdSelect_TypeOfSelectionImage_ColoredOwner; | |
12288 | } | |
12289 | else if (aValue == "selectionmodecolor" | |
12290 | || aValue == "selectionmode" | |
12291 | || aValue == "selmodecolor" | |
12292 | || aValue == "selmode") | |
12293 | { | |
12294 | aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode; | |
12295 | } | |
12296 | } | |
12297 | else if (aParam == "-picked" | |
12298 | || aParam == "-pickeddepth" | |
12299 | || aParam == "-pickedindex") | |
12300 | { | |
12301 | if (++anArgIter >= theArgsNb) | |
12302 | { | |
12303 | std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n"; | |
12304 | return 1; | |
12305 | } | |
12306 | ||
12307 | aPickedIndex = Draw::Atoi (theArgVec[anArgIter]); | |
12308 | } | |
12309 | else if (aFile.IsEmpty()) | |
12310 | { | |
12311 | aFile = theArgVec[anArgIter]; | |
12312 | } | |
12313 | else | |
12314 | { | |
12315 | std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n"; | |
12316 | return 1; | |
12317 | } | |
12318 | } | |
12319 | if (aFile.IsEmpty()) | |
12320 | { | |
12321 | std::cout << "Syntax error: image file name is missing.\n"; | |
12322 | return 1; | |
12323 | } | |
12324 | ||
12325 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); | |
12326 | Standard_Integer aWidth = 0, aHeight = 0; | |
12327 | aView->Window()->Size (aWidth, aHeight); | |
12328 | ||
12329 | Image_AlienPixMap aPixMap; | |
12330 | if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight)) | |
12331 | { | |
12332 | std::cout << "Error: can't allocate image.\n"; | |
12333 | return 1; | |
12334 | } | |
12335 | if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex)) | |
12336 | { | |
12337 | std::cout << "Error: can't generate selection image.\n"; | |
12338 | return 1; | |
12339 | } | |
12340 | if (!aPixMap.Save (aFile)) | |
12341 | { | |
12342 | std::cout << "Error: can't save selection image.\n"; | |
12343 | return 0; | |
12344 | } | |
12345 | return 0; | |
12346 | } | |
12347 | ||
7fd59977 | 12348 | //======================================================================= |
12349 | //function : ViewerCommands | |
12350 | //purpose : | |
12351 | //======================================================================= | |
12352 | ||
12353 | void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) | |
12354 | { | |
12355 | ||
12356 | const char *group = "ZeViewer"; | |
18d715bd | 12357 | theCommands.Add("vinit", |
fd3f6bd0 | 12358 | "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]" |
2e93433e | 12359 | "\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]" |
fd3f6bd0 | 12360 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
12361 | "\n\t\t: [-display displayName]" | |
12362 | #endif | |
12363 | "\n\t\t: Creates new View window with specified name viewName." | |
12364 | "\n\t\t: By default the new view is created in the viewer and in" | |
12365 | "\n\t\t: graphic driver shared with active view." | |
12366 | "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}" | |
12367 | "\n\t\t: If driverName isn't specified the driver will be shared with active view." | |
12368 | "\n\t\t: If viewerName isn't specified the viewer will be shared with active view." | |
12369 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
12370 | "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]" | |
12371 | "\n\t\t: Display name will be used within creation of graphic driver, when specified." | |
18d715bd | 12372 | #endif |
fd3f6bd0 | 12373 | "\n\t\t: -left, -top pixel position of left top corner of the window." |
12374 | "\n\t\t: -width, -height width and heigth of window respectively." | |
9e04ccdc | 12375 | "\n\t\t: -cloneActive floag to copy camera and dimensions of active view." |
fd3f6bd0 | 12376 | "\n\t\t: -exitOnClose when specified, closing the view will exit application." |
12377 | "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape." | |
2e93433e | 12378 | "\n\t\t: -2d_mode when on, view will not react on rotate scene events" |
fd3f6bd0 | 12379 | "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.", |
7fd59977 | 12380 | __FILE__,VInit,group); |
18d715bd | 12381 | theCommands.Add("vclose" , |
d0cc1cb7 | 12382 | "[view_id [keep_context=0|1]]\n" |
18d715bd | 12383 | "or vclose ALL - to remove all created views\n" |
12384 | " - removes view(viewer window) defined by its view_id.\n" | |
12385 | " - keep_context: by default 0; if 1 and the last view is deleted" | |
12386 | " the current context is not removed.", | |
12387 | __FILE__,VClose,group); | |
12388 | theCommands.Add("vactivate" , | |
e084dbbc | 12389 | "vactivate view_id [-noUpdate]" |
18d715bd | 12390 | " - activates view(viewer window) defined by its view_id", |
12391 | __FILE__,VActivate,group); | |
12392 | theCommands.Add("vviewlist", | |
12393 | "vviewlist [format={tree, long}]" | |
12394 | " - prints current list of views per viewer and graphic_driver ID shared between viewers" | |
12395 | " - format: format of result output, if tree the output is a tree view;" | |
12396 | "otherwise it's a list of full view names. By default format = tree", | |
12397 | __FILE__,VViewList,group); | |
7fd59977 | 12398 | theCommands.Add("vhelp" , |
12399 | "vhelp : display help on the viewer commands", | |
12400 | __FILE__,VHelp,group); | |
12401 | theCommands.Add("vtop" , | |
27af3052 | 12402 | "vtop or <T> : Top view. Orientation +X+Y" , |
7fd59977 | 12403 | __FILE__,VTop,group); |
44b8f2d6 | 12404 | theCommands.Add("vbottom" , |
27af3052 | 12405 | "vbottom : Bottom view. Orientation +X-Y" , |
44b8f2d6 | 12406 | __FILE__,VBottom,group); |
12407 | theCommands.Add("vleft" , | |
27af3052 | 12408 | "vleft : Left view. Orientation -Y+Z" , |
44b8f2d6 | 12409 | __FILE__,VLeft,group); |
12410 | theCommands.Add("vright" , | |
27af3052 | 12411 | "vright : Right view. Orientation +Y+Z" , |
44b8f2d6 | 12412 | __FILE__,VRight,group); |
7fd59977 | 12413 | theCommands.Add("vaxo" , |
27af3052 | 12414 | " vaxo or <A> : Axonometric view. Orientation +X-Y+Z", |
7fd59977 | 12415 | __FILE__,VAxo,group); |
44b8f2d6 | 12416 | theCommands.Add("vfront" , |
27af3052 | 12417 | "vfront : Front view. Orientation +X+Z" , |
44b8f2d6 | 12418 | __FILE__,VFront,group); |
12419 | theCommands.Add("vback" , | |
27af3052 | 12420 | "vback : Back view. Orientation -X+Z" , |
44b8f2d6 | 12421 | __FILE__,VBack,group); |
7fd59977 | 12422 | theCommands.Add("vpick" , |
12423 | "vpick : vpick X Y Z [shape subshape] ( all variables as string )", | |
12424 | VPick,group); | |
1beb58d7 | 12425 | theCommands.Add("vfit", |
12426 | "vfit or <F> [-selected] [-noupdate]" | |
b586500b | 12427 | "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects", |
7fd59977 | 12428 | __FILE__,VFit,group); |
6262a303 | 12429 | theCommands.Add ("vfitarea", |
12430 | "vfitarea x1 y1 x2 y2" | |
12431 | "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2" | |
12432 | "\n\t\t: Fit view to show area located between two points" | |
12433 | "\n\t\t: given in world 2D or 3D corrdinates.", | |
12434 | __FILE__, VFitArea, group); | |
197ac94e | 12435 | theCommands.Add ("vzfit", "vzfit [scale]\n" |
12436 | " Matches Z near, Z far view volume planes to the displayed objects.\n" | |
12437 | " \"scale\" - specifies factor to scale computed z range.\n", | |
12438 | __FILE__, VZFit, group); | |
7fd59977 | 12439 | theCommands.Add("vrepaint", |
56689b27 | 12440 | "vrepaint [-immediate]" |
12441 | "\n\t\t: force redraw", | |
7fd59977 | 12442 | __FILE__,VRepaint,group); |
12443 | theCommands.Add("vclear", | |
faea8b40 | 12444 | "vclear : vclear" |
12445 | "\n\t\t: remove all the object from the viewer", | |
7fd59977 | 12446 | __FILE__,VClear,group); |
12447 | theCommands.Add("vsetbg", | |
12448 | "vsetbg : vsetbg imagefile [filltype] : Load image as background", | |
12449 | __FILE__,VSetBg,group); | |
f8b2ed36 | 12450 | theCommands.Add("vsetbgmode", |
12451 | "vsetbgmode : vsetbgmode filltype : Change background image fill type", | |
12452 | __FILE__,VSetBgMode,group); | |
7fd59977 | 12453 | theCommands.Add("vsetgradientbg", |
f8b2ed36 | 12454 | "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background", |
7fd59977 | 12455 | __FILE__,VSetGradientBg,group); |
f8b2ed36 | 12456 | theCommands.Add("vsetgrbgmode", |
12457 | "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type", | |
12458 | __FILE__,VSetGradientBgMode,group); | |
12459 | theCommands.Add("vsetcolorbg", | |
12460 | "vsetcolorbg : vsetcolorbg r g b : Set background color", | |
12461 | __FILE__,VSetColorBg,group); | |
f42753ed | 12462 | theCommands.Add("vsetdefaultbg", |
12463 | "vsetdefaultbg r g b\n" | |
12464 | "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode" | |
12465 | "\n\t\t: Set default viewer background fill color (flat/gradient).", | |
12466 | __FILE__,VSetDefaultBg,group); | |
7fd59977 | 12467 | theCommands.Add("vscale", |
12468 | "vscale : vscale X Y Z", | |
12469 | __FILE__,VScale,group); | |
12470 | theCommands.Add("vzbufftrihedron", | |
536d98e2 | 12471 | "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]" |
12472 | "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]" | |
12473 | "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]" | |
12474 | "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]" | |
12475 | "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]" | |
12476 | "\n\t\t: Displays a trihedron", | |
12477 | __FILE__,VZBuffTrihedron,group); | |
7fd59977 | 12478 | theCommands.Add("vrotate", |
4af098ba | 12479 | "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]" |
12480 | "\n : Option -mouseStart starts rotation according to the mouse position" | |
12481 | "\n : Option -mouseMove continues rotation with angle computed" | |
12482 | "\n : from last and new mouse position." | |
12483 | "\n : vrotate AX AY AZ [X Y Z]", | |
7fd59977 | 12484 | __FILE__,VRotate,group); |
12485 | theCommands.Add("vzoom", | |
12486 | "vzoom : vzoom coef", | |
12487 | __FILE__,VZoom,group); | |
12488 | theCommands.Add("vpan", | |
12489 | "vpan : vpan dx dy", | |
12490 | __FILE__,VPan,group); | |
7fd59977 | 12491 | theCommands.Add("vcolorscale", |
4b3d6eb1 | 12492 | "vcolorscale name [-noupdate|-update] [-demo]" |
12493 | "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]" | |
12494 | "\n\t\t: [-font HeightFont=20]" | |
12495 | "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]" | |
12496 | "\n\t\t: [-smoothTransition {on|off}=off]" | |
12497 | "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]" | |
12498 | "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]" | |
12499 | "\n\t\t: [-textpos {left|right|center|none}=right]" | |
12500 | "\n\t\t: [-labelAtBorder {on|off}=on]" | |
12501 | "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]" | |
12502 | "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]" | |
12503 | "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]" | |
12504 | "\n\t\t: [-xy Left=0 Bottom=0]" | |
12505 | "\n\t\t: -demo - displays a color scale with demonstratio values" | |
12506 | "\n\t\t: -colors - set colors for all intervals" | |
12507 | "\n\t\t: -color - set color for specific interval" | |
12508 | "\n\t\t: -textpos - horizontal label position relative to color scale bar" | |
12509 | "\n\t\t: -labelAtBorder - vertical label position relative to color interval;" | |
12510 | "\n\t\t: at border means the value inbetween neighbor intervals," | |
12511 | "\n\t\t: at center means the center value within current interval" | |
12512 | "\n\t\t: -labels - set labels for all intervals" | |
12513 | "\n\t\t: -freeLabels - same as -labels but does not require" | |
12514 | "\n\t\t: matching the number of intervals" | |
12515 | "\n\t\t: -label - set label for specific interval" | |
12516 | "\n\t\t: -title - set title" | |
12517 | "\n\t\t: -reversed - setup smooth color transition between intervals" | |
12518 | "\n\t\t: -smoothTransition - swap colorscale direction" | |
12519 | "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values" | |
12520 | __FILE__, VColorScale, group); | |
7fd59977 | 12521 | theCommands.Add("vgraduatedtrihedron", |
a79f67f8 | 12522 | "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n" |
12523 | "\t[-namefont Name] [-valuesfont Name]\n" | |
12524 | "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n" | |
12525 | "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]" | |
12526 | "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n" | |
12527 | "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n" | |
12528 | "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]" | |
12529 | "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n" | |
12530 | "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n" | |
12531 | "\t[-xticks Number] [-yticks Number] [-zticks Number]\n" | |
12532 | "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n" | |
536d98e2 | 12533 | "\t[-drawgrid on/off] [-drawaxes on/off]\n" |
a79f67f8 | 12534 | " - Displays or erases graduated trihedron" |
12535 | " - xname, yname, zname - names of axes, default: X, Y, Z\n" | |
12536 | " - namefont - font of axes names. Default: Arial\n" | |
12537 | " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n" | |
12538 | " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n" | |
12539 | " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n" | |
12540 | " - valuesfont - font of axes values. Default: Arial\n" | |
12541 | " - xcolor, ycolor, zcolor - color of axis and values\n" | |
12542 | " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n" | |
12543 | " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n", | |
7fd59977 | 12544 | __FILE__,VGraduatedTrihedron,group); |
3bffef55 | 12545 | theCommands.Add("vtile" , |
12546 | "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]" | |
12547 | "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)." | |
12548 | "\n\t\t: -totalSize the size of virtual bigger viewport" | |
12549 | "\n\t\t: -tileSize tile size (the view size will be used if omitted)" | |
12550 | "\n\t\t: -lowerLeft tile offset as lower left corner" | |
12551 | "\n\t\t: -upperLeft tile offset as upper left corner", | |
12552 | __FILE__, VTile, group); | |
59f45b7c | 12553 | theCommands.Add("vzlayer", |
7c3ef2f7 | 12554 | "vzlayer [layerId]" |
12555 | "\n\t\t: [-add|-delete|-get|-settings]" | |
4ecf34cc | 12556 | "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]" |
7c3ef2f7 | 12557 | "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]" |
12558 | "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv}]" | |
12559 | "\n\t\t: ZLayer list management:" | |
12560 | "\n\t\t: -add add new z layer to viewer and print its id" | |
12561 | "\n\t\t: -delete delete z layer" | |
12562 | "\n\t\t: -get print sequence of z layers" | |
12563 | "\n\t\t: -settings print status of z layer settings" | |
12564 | "\n\t\t: -disable disables given setting" | |
12565 | "\n\t\t: -enable enables given setting", | |
59f45b7c | 12566 | __FILE__,VZLayer,group); |
20637bd2 | 12567 | theCommands.Add("vlayerline", |
12568 | "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]", | |
12569 | __FILE__,VLayerLine,group); | |
2bd4c032 | 12570 | theCommands.Add ("vgrid", |
12571 | "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]" | |
12572 | " : Mode - rectangular or circular" | |
12573 | " : Type - lines or points", | |
12574 | __FILE__, VGrid, group); | |
c40b7d58 | 12575 | theCommands.Add ("vpriviledgedplane", |
12576 | "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]" | |
12577 | "\n\t\t: Ox, Oy, Oz - plane origin" | |
12578 | "\n\t\t: Nx, Ny, Nz - plane normal direction" | |
12579 | "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction" | |
12580 | "\n\t\t: Sets or prints viewer's priviledged plane geometry.", | |
12581 | __FILE__, VPriviledgedPlane, group); | |
f25b82d6 | 12582 | theCommands.Add ("vconvert", |
12583 | "vconvert v [Mode={window|view}]" | |
12584 | "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]" | |
12585 | "\n\t\t: vconvert x y z [Mode={window|grid}]" | |
12586 | "\n\t\t: window - convert to window coordinates, pixels" | |
12587 | "\n\t\t: view - convert to view projection plane" | |
12588 | "\n\t\t: grid - convert to model coordinates, given on grid" | |
12589 | "\n\t\t: ray - convert projection ray to model coordiantes" | |
12590 | "\n\t\t: - vconvert v window : convert view to window;" | |
12591 | "\n\t\t: - vconvert v view : convert window to view;" | |
12592 | "\n\t\t: - vconvert x y window : convert view to window;" | |
12593 | "\n\t\t: - vconvert x y view : convert window to view;" | |
12594 | "\n\t\t: - vconvert x y : convert window to model;" | |
12595 | "\n\t\t: - vconvert x y grid : convert window to model using grid;" | |
12596 | "\n\t\t: - vconvert x y ray : convert window projection line to model;" | |
12597 | "\n\t\t: - vconvert x y z window : convert model to window;" | |
12598 | "\n\t\t: - vconvert x y z grid : convert view to model using grid;" | |
12599 | "\n\t\t: Converts the given coordinates to window/view/model space.", | |
12600 | __FILE__, VConvert, group); | |
208e6839 | 12601 | theCommands.Add ("vfps", |
e084dbbc | 12602 | "vfps [framesNb=100] [-duration seconds] : estimate average frame rate for active view", |
208e6839 | 12603 | __FILE__, VFps, group); |
58655684 | 12604 | theCommands.Add ("vgldebug", |
c87535af | 12605 | "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]" |
84e84755 | 12606 | "\n\t\t: [-glslCode {off|short|full}] [-extraMsg {0|1}] [{0|1}]" |
c87535af | 12607 | "\n\t\t: Request debug GL context. Should be called BEFORE vinit." |
12608 | "\n\t\t: Debug context can be requested only on Windows" | |
12609 | "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!" | |
12610 | "\n\t\t: -sync - request synchronized debug GL context" | |
12611 | "\n\t\t: -glslWarn - log GLSL compiler/linker warnings," | |
12612 | "\n\t\t: which are suppressed by default," | |
84e84755 | 12613 | "\n\t\t: -glslCode - log GLSL program source code," |
12614 | "\n\t\t: which are suppressed by default," | |
c87535af | 12615 | "\n\t\t: -extraMsg - log extra diagnostic messages from GL context," |
12616 | "\n\t\t: which are suppressed by default", | |
58655684 | 12617 | __FILE__, VGlDebug, group); |
208e6839 | 12618 | theCommands.Add ("vvbo", |
58655684 | 12619 | "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects", |
208e6839 | 12620 | __FILE__, VVbo, group); |
b5ac8292 | 12621 | theCommands.Add ("vstereo", |
f978241f | 12622 | "vstereo [0|1] [-mode Mode] [-reverse {0|1}]" |
12623 | "\n\t\t: [-anaglyph Filter]" | |
12624 | "\n\t\t: Control stereo output mode. Available modes for -mode:" | |
12625 | "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo," | |
12626 | "\n\t\t: requires driver support." | |
12627 | "\n\t\t: Should be called BEFORE vinit!" | |
12628 | "\n\t\t: anaglyph - Anaglyph glasses" | |
12629 | "\n\t\t: rowInterlaced - row-interlaced display" | |
12630 | "\n\t\t: columnInterlaced - column-interlaced display" | |
12631 | "\n\t\t: chessBoard - chess-board output" | |
12632 | "\n\t\t: sideBySide - horizontal pair" | |
12633 | "\n\t\t: overUnder - vertical pair" | |
12634 | "\n\t\t: Available Anaglyph filters for -anaglyph:" | |
12635 | "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple," | |
12636 | "\n\t\t: greenMagentaSimple", | |
b5ac8292 | 12637 | __FILE__, VStereo, group); |
a577aaab | 12638 | theCommands.Add ("vcaps", |
2a332745 | 12639 | "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}] [-polygonMode {0|1}]" |
1dfe71a6 | 12640 | "\n\t\t: [-compatibleProfile {0|1}]" |
56689b27 | 12641 | "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]" |
f978241f | 12642 | "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]" |
8625ef7e | 12643 | "\n\t\t: [-softMode {0|1}] [-noupdate|-update]" |
12644 | "\n\t\t: Modify particular graphic driver options:" | |
12645 | "\n\t\t: FFP - use fixed-function pipeline instead of" | |
12646 | "\n\t\t: built-in GLSL programs" | |
4e1523ef | 12647 | "\n\t\t: (requires compatible profile)" |
2a332745 | 12648 | "\n\t\t: polygonMode - use Polygon Mode instead of built-in GLSL programs" |
8625ef7e | 12649 | "\n\t\t: VBO - use Vertex Buffer Object (copy vertex" |
12650 | "\n\t\t: arrays to GPU memory)" | |
12651 | "\n\t\t: sprite - use textured sprites instead of bitmaps" | |
f978241f | 12652 | "\n\t\t: vsync - switch VSync on or off" |
56689b27 | 12653 | "\n\t\t: winBuffer - allow using window buffer for rendering" |
4e1523ef | 12654 | "\n\t\t: Context creation options:" |
12655 | "\n\t\t: softMode - software OpenGL implementation" | |
12656 | "\n\t\t: compatibleProfile - backward-compatible profile" | |
f978241f | 12657 | "\n\t\t: quadbuffer - QuadBuffer" |
8625ef7e | 12658 | "\n\t\t: Unlike vrenderparams, these parameters control alternative" |
12659 | "\n\t\t: rendering paths producing the same visual result when" | |
12660 | "\n\t\t: possible." | |
12661 | "\n\t\t: Command is intended for testing old hardware compatibility.", | |
a577aaab | 12662 | __FILE__, VCaps, group); |
f0430952 | 12663 | theCommands.Add ("vmemgpu", |
12664 | "vmemgpu [f]: print system-dependent GPU memory information if available;" | |
12665 | " with f option returns free memory in bytes", | |
12666 | __FILE__, VMemGpu, group); | |
85e096c3 | 12667 | theCommands.Add ("vreadpixel", |
12668 | "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]" | |
12669 | " : Read pixel value for active view", | |
12670 | __FILE__, VReadPixel, group); | |
692613e5 | 12671 | theCommands.Add("diffimage", |
fd3f6bd0 | 12672 | "diffimage imageFile1 imageFile2 [diffImageFile]" |
12673 | "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]" | |
12674 | "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]" | |
12675 | "\n\t\t: Compare two images by content and generate difference image." | |
12676 | "\n\t\t: When -exitOnClose is specified, closing the view will exit application." | |
12677 | "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.", | |
692613e5 | 12678 | __FILE__, VDiffImage, group); |
4754e164 | 12679 | theCommands.Add ("vselect", |
2157d6ac | 12680 | "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n" |
4754e164 | 12681 | "- emulates different types of selection:\n" |
12682 | "- 1) single click selection\n" | |
12683 | "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n" | |
12684 | "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n" | |
faea8b40 | 12685 | "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n" |
12686 | " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n" | |
12687 | " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. " | |
2157d6ac | 12688 | " (partial inclusion - overlap - is not allowed by default)\n" |
12689 | "- 5) any of these selections with shift button pressed", | |
4754e164 | 12690 | __FILE__, VSelect, group); |
12691 | theCommands.Add ("vmoveto", | |
8a590580 | 12692 | "vmoveto [x y] [-reset]" |
12693 | "\n\t\t: Emulates cursor movement to pixel position (x,y)." | |
12694 | "\n\t\t: -reset resets current highlighting", | |
4754e164 | 12695 | __FILE__, VMoveTo, group); |
1beb58d7 | 12696 | theCommands.Add ("vviewparams", |
12697 | "vviewparams [-args] [-scale [s]]" | |
12698 | "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]" | |
12699 | "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]" | |
12700 | "\n\t\t: Manage current view parameters or prints all" | |
12701 | "\n\t\t: current values when called without argument." | |
12702 | "\n\t\t: -scale [s] prints or sets viewport relative scale" | |
12703 | "\n\t\t: -eye [x y z] prints or sets eye location" | |
12704 | "\n\t\t: -at [x y z] prints or sets center of look" | |
12705 | "\n\t\t: -up [x y z] prints or sets direction of up vector" | |
12706 | "\n\t\t: -proj [x y z] prints or sets direction of look" | |
12707 | "\n\t\t: -center x y sets location of center of the screen in pixels" | |
12708 | "\n\t\t: -size [sx] prints viewport projection width and height sizes" | |
12709 | "\n\t\t: or changes the size of its maximum dimension" | |
12710 | "\n\t\t: -args prints vviewparams arguments for restoring current view", | |
197ac94e | 12711 | __FILE__, VViewParams, group); |
1beb58d7 | 12712 | |
2e93433e | 12713 | theCommands.Add("v2dmode", |
12714 | "v2dmode [-name viewName] [-mode {-on|-off}=-on]" | |
12715 | "\n\t\t: name - name of existing view, if not defined, the active view is changed" | |
12716 | "\n\t\t: mode - switches On/Off rotation mode" | |
12717 | "\n\t\t: Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:" | |
12718 | "\n\t\t: - rotation of the view by 3rd mouse button with Ctrl active" | |
12719 | "\n\t\t: - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right" | |
12720 | "\n\t\t: View camera position might be changed only by commands.", | |
12721 | __FILE__, V2DMode, group); | |
12722 | ||
1beb58d7 | 12723 | theCommands.Add("vanimation", "Alias for vanim", |
12724 | __FILE__, VAnimation, group); | |
12725 | ||
12726 | theCommands.Add("vanim", | |
12727 | "List existing animations:" | |
12728 | "\n\t\t: vanim" | |
12729 | "\n\t\t: Animation playback:" | |
12730 | "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]" | |
12731 | "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]" | |
12732 | "\n\t\t: -speed playback speed (1.0 is normal speed)" | |
12733 | "\n\t\t: -freeLook skip camera animations" | |
12734 | "\n\t\t: -lockLoop disable any interactions" | |
12735 | "\n\t\t:" | |
12736 | "\n\t\t: Animation definition:" | |
12737 | "\n\t\t: vanim Name/sub/name [-clear] [-delete]" | |
12738 | "\n\t\t: [start TimeSec] [duration TimeSec]" | |
12739 | "\n\t\t:" | |
12740 | "\n\t\t: Animation name defined in path-style (anim/name or anim.name)" | |
12741 | "\n\t\t: specifies nested animations." | |
12742 | "\n\t\t: There is no syntax to explicitly add new animation," | |
12743 | "\n\t\t: and all non-existing animations within the name will be" | |
12744 | "\n\t\t: implicitly created on first use (including parents)." | |
12745 | "\n\t\t:" | |
12746 | "\n\t\t: Each animation might define the SINGLE action (see below)," | |
12747 | "\n\t\t: like camera transition, object transformation or custom callback." | |
12748 | "\n\t\t: Child animations can be used for defining concurrent actions." | |
12749 | "\n\t\t:" | |
12750 | "\n\t\t: Camera animation:" | |
12751 | "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]" | |
12752 | "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]" | |
12753 | "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]" | |
12754 | "\n\t\t: [-scale1 Scale] [-scale2 Scale]" | |
12755 | "\n\t\t: -eyeX camera Eye positions pair (start and end)" | |
12756 | "\n\t\t: -atX camera Center positions pair" | |
12757 | "\n\t\t: -upX camera Up directions pair" | |
12758 | "\n\t\t: -scaleX camera Scale factors pair" | |
12759 | "\n\t\t: Object animation:" | |
12760 | "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]" | |
12761 | "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]" | |
12762 | "\n\t\t: [-scale1 Scale] [-scale2 Scale]" | |
12763 | "\n\t\t: -locX object Location points pair (translation)" | |
12764 | "\n\t\t: -rotX object Orientations pair (quaternions)" | |
12765 | "\n\t\t: -scaleX object Scale factors pair (quaternions)" | |
12766 | "\n\t\t: Custom callback:" | |
12767 | "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\"" | |
12768 | "\n\t\t: %Pts overall animation presentation timestamp" | |
12769 | "\n\t\t: %LocalPts local animation timestamp" | |
12770 | "\n\t\t: %Normalized local animation normalized value in range 0..1" | |
08f8a185 | 12771 | "\n\t\t:" |
12772 | "\n\t\t: Video recording:" | |
12773 | "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]" | |
12774 | "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]" | |
12775 | "\n\t\t: [-crf Value] [-preset Preset]" | |
12776 | "\n\t\t: -fps video framerate" | |
12777 | "\n\t\t: -format file format, container (matroska, etc.)" | |
12778 | "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)" | |
12779 | "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)" | |
12780 | "\n\t\t: -crf constant rate factor (specific to codec)" | |
12781 | "\n\t\t: -preset codec parameters preset (specific to codec)" | |
1beb58d7 | 12782 | __FILE__, VAnimation, group); |
12783 | ||
4754e164 | 12784 | theCommands.Add("vchangeselected", |
dc3fe572 | 12785 | "vchangeselected shape" |
4754e164 | 12786 | "- adds to shape to selection or remove one from it", |
12787 | __FILE__, VChangeSelected, group); | |
4754e164 | 12788 | theCommands.Add ("vnbselected", |
faea8b40 | 12789 | "vnbselected" |
12790 | "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group); | |
6b62b2da | 12791 | theCommands.Add ("vcamera", |
30a1b24e | 12792 | "vcamera [PrsName] [-ortho] [-projtype]" |
6b62b2da | 12793 | "\n\t\t: [-persp]" |
12794 | "\n\t\t: [-fovy [Angle]] [-distance [Distance]]" | |
12795 | "\n\t\t: [-stereo] [-leftEye] [-rightEye]" | |
12796 | "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]" | |
12797 | "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]" | |
30a1b24e | 12798 | "\n\t\t: Manages camera parameters." |
12799 | "\n\t\t: Displays frustum when presntation name PrsName is specified." | |
6b62b2da | 12800 | "\n\t\t: Prints current value when option called without argument." |
12801 | "\n\t\t: Orthographic camera:" | |
12802 | "\n\t\t: -ortho activate orthographic projection" | |
12803 | "\n\t\t: Perspective camera:" | |
12804 | "\n\t\t: -persp activate perspective projection (mono)" | |
12805 | "\n\t\t: -fovy field of view in y axis, in degrees" | |
12806 | "\n\t\t: -distance distance of eye from camera center" | |
12807 | "\n\t\t: Stereoscopic camera:" | |
12808 | "\n\t\t: -stereo perspective projection (stereo)" | |
12809 | "\n\t\t: -leftEye perspective projection (left eye)" | |
12810 | "\n\t\t: -rightEye perspective projection (right eye)" | |
12811 | "\n\t\t: -iod intraocular distance value" | |
12812 | "\n\t\t: -iodType distance type, absolute or relative" | |
12813 | "\n\t\t: -zfocus stereographic focus value" | |
12814 | "\n\t\t: -zfocusType focus type, absolute or relative", | |
12815 | __FILE__, VCamera, group); | |
b5ac8292 | 12816 | theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n" |
197ac94e | 12817 | "- vautozfit [on={1|0}] [scale]\n" |
12818 | " Prints or changes parameters of automatic z-fit mode:\n" | |
12819 | " \"on\" - turns automatic z-fit on or off\n" | |
12820 | " \"scale\" - specifies factor to scale computed z range.\n", | |
12821 | __FILE__, VAutoZFit, group); | |
b5ac8292 | 12822 | theCommands.Add ("vzrange", "command to manually access znear and zfar values\n" |
12823 | " vzrange - without parameters shows current values\n" | |
12824 | " vzrange [znear] [zfar] - applies provided values to view", | |
12825 | __FILE__,VZRange, group); | |
4754e164 | 12826 | theCommands.Add ("vpurgedisplay", |
eb4320f2 | 12827 | "vpurgedisplay" |
4754e164 | 12828 | "- removes structures which don't belong to objects displayed in neutral point", |
12829 | __FILE__, VPurgeDisplay, group); | |
12830 | theCommands.Add("vsetviewsize", | |
12831 | "vsetviewsize size", | |
12832 | __FILE__,VSetViewSize,group); | |
12833 | theCommands.Add("vmoveview", | |
12834 | "vmoveview Dx Dy Dz [Start = 1|0]", | |
12835 | __FILE__,VMoveView,group); | |
12836 | theCommands.Add("vtranslateview", | |
12837 | "vtranslateview Dx Dy Dz [Start = 1|0)]", | |
12838 | __FILE__,VTranslateView,group); | |
12839 | theCommands.Add("vturnview", | |
12840 | "vturnview Ax Ay Az [Start = 1|0]", | |
12841 | __FILE__,VTurnView,group); | |
269294d6 | 12842 | theCommands.Add("vtextureenv", |
12843 | "Enables or disables environment mapping in the 3D view, loading the texture from the given standard " | |
12844 | "or user-defined file and optionally applying texture mapping parameters\n" | |
12845 | " Usage:\n" | |
12846 | " vtextureenv off - disables environment mapping\n" | |
12847 | " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n" | |
12848 | " std_texture = (0..7)\n" | |
12849 | " rep = {clamp|repeat}\n" | |
12850 | " mod = {decal|modulate}\n" | |
12851 | " flt = {nearest|bilinear|trilinear}\n" | |
12852 | " ss, st - scale factors for s and t texture coordinates\n" | |
12853 | " ts, tt - translation for s and t texture coordinates\n" | |
12854 | " rot - texture rotation angle in degrees", | |
12855 | __FILE__, VTextureEnv, group); | |
1eeef710 | 12856 | theCommands.Add("vhlr", |
12857 | "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]" | |
12858 | "\n\t\t: Hidden Line Removal algorithm." | |
12859 | "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones" | |
12860 | "\n\t\t: -algoType type of HLR algorithm.\n", | |
0a768f56 | 12861 | __FILE__,VHLR,group); |
1eeef710 | 12862 | theCommands.Add("vhlrtype", |
12863 | "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]" | |
12864 | "\n\t\t: Changes the type of HLR algorithm using for shapes:" | |
12865 | "\n\t\t: 'algo' - exact HLR algorithm is applied" | |
12866 | "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied" | |
12867 | "\n\t\t: If shapes are not given - option is applied to all shapes in the view", | |
0a768f56 | 12868 | __FILE__,VHLRType,group); |
3e05329c | 12869 | theCommands.Add("vclipplane", |
12870 | "vclipplane planeName [{0|1}]" | |
25c35042 | 12871 | "\n\t\t: [-equation1 A B C D]" |
12872 | "\n\t\t: [-equation2 A B C D]" | |
12873 | "\n\t\t: [-boxInterior MinX MinY MinZ MaxX MaxY MaxZ]" | |
32ca7711 | 12874 | "\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]" |
3e05329c | 12875 | "\n\t\t: [-maxPlanes]" |
12876 | "\n\t\t: [-capping {0|1}]" | |
1b661a81 | 12877 | "\n\t\t: [-color R G B] [-transparency Value] [-hatch {on|off|ID}]" |
3e05329c | 12878 | "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]" |
12879 | "\n\t\t: [-texRotate Angle]" | |
12880 | "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]" | |
12881 | "\n\t\t: [-useObjShader {0|1}]" | |
12882 | "\n\t\t: Clipping planes management:" | |
12883 | "\n\t\t: -maxPlanes print plane limit for view" | |
12884 | "\n\t\t: -delete delete plane with given name" | |
12885 | "\n\t\t: {off|on|0|1} turn clipping on/off" | |
12886 | "\n\t\t: -set|-unset set/unset plane for Object or View list;" | |
12887 | "\n\t\t: applied to active View when list is omitted" | |
12888 | "\n\t\t: -equation A B C D change plane equation" | |
12889 | "\n\t\t: -clone SourcePlane NewPlane clone the plane definition." | |
12890 | "\n\t\t: Capping options:" | |
12891 | "\n\t\t: -capping {off|on|0|1} turn capping on/off" | |
12892 | "\n\t\t: -color R G B set capping color" | |
1b661a81 | 12893 | "\n\t\t: -transparency Value set capping transparency 0..1" |
3e05329c | 12894 | "\n\t\t: -texName Texture set capping texture" |
12895 | "\n\t\t: -texScale SX SY set capping tex scale" | |
12896 | "\n\t\t: -texOrigin TX TY set capping tex origin" | |
12897 | "\n\t\t: -texRotate Angle set capping tex rotation" | |
12898 | "\n\t\t: -hatch {on|off|ID} set capping hatching mask" | |
12899 | "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object" | |
12900 | "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object" | |
12901 | "\n\t\t: -useObjShader {off|on|0|1} use shader program of object", | |
12902 | __FILE__, VClipPlane, group); | |
392ac980 | 12903 | theCommands.Add("vdefaults", |
4c513386 | 12904 | "vdefaults [-absDefl value]" |
12905 | "\n\t\t: [-devCoeff value]" | |
12906 | "\n\t\t: [-angDefl value]" | |
12907 | "\n\t\t: [-autoTriang {off/on | 0/1}]" | |
12908 | , __FILE__, VDefaults, group); | |
12381341 | 12909 | theCommands.Add("vlight", |
816d03ee | 12910 | "tool to manage light sources, without arguments shows list of lights." |
12911 | "\n Main commands: " | |
992ed6b3 | 12912 | "\n '-clear' to clear lights" |
12913 | "\n '-{def}aults' to load deafault lights" | |
12914 | "\n '-add' <type> to add any light source" | |
816d03ee | 12915 | "\n where <type> is one of {amb}ient|directional|{spot}light|positional" |
12916 | "\n 'change' <lightId> to edit light source with specified lightId" | |
12917 | "\n\n In addition to 'add' and 'change' commands you can use light parameters:" | |
992ed6b3 | 12918 | "\n -layer Id" |
12919 | "\n -{pos}ition X Y Z" | |
12920 | "\n -{dir}ection X Y Z (for directional light or for spotlight)" | |
12921 | "\n -color colorName" | |
12922 | "\n -{head}light 0|1" | |
12923 | "\n -{sm}oothness value" | |
12924 | "\n -{int}ensity value" | |
12925 | "\n -{constAtten}uation value" | |
12926 | "\n -{linearAtten}uation value" | |
12927 | "\n -angle angleDeg" | |
12928 | "\n -{spotexp}onent value" | |
12929 | "\n -local|-global" | |
12930 | "\n\n example: vlight -add positional -head 1 -pos 0 1 1 -color red" | |
12931 | "\n example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2", | |
12381341 | 12932 | __FILE__, VLight, group); |
6b62b2da | 12933 | theCommands.Add("vraytrace", |
12934 | "vraytrace [0|1]" | |
189f85a3 | 12935 | "\n\t\t: Turns on/off ray-tracing renderer." |
6b62b2da | 12936 | "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'." |
12937 | "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.", | |
12938 | __FILE__, VRenderParams, group); | |
bc8c79bb | 12939 | theCommands.Add("vrenderparams", |
12940 | "\n Manages rendering parameters: " | |
a1073ae2 | 12941 | "\n '-raster' Disables GPU ray-tracing" |
12942 | "\n '-msaa 0..4' Specifies number of samples for MSAA" | |
2a332745 | 12943 | "\n '-lineFeather > 0' Sets line feather factor" |
a1073ae2 | 12944 | "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor" |
f88457e6 | 12945 | "\n '-depthPrePass on|off' Enables/disables depth pre-pass" |
c40eb6b9 | 12946 | "\n '-alphatocoverage on|off' Enables/disables alpha to coverage (needs MSAA)" |
a1073ae2 | 12947 | "\n '-rendScale value Rendering resolution scale factor" |
12948 | "\n '-rayTrace' Enables GPU ray-tracing" | |
12949 | "\n '-rayDepth 0..10' Defines maximum ray-tracing depth" | |
12950 | "\n '-shadows on|off' Enables/disables shadows rendering" | |
12951 | "\n '-reflections on|off' Enables/disables specular reflections" | |
12952 | "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing" | |
12953 | "\n '-gleam on|off' Enables/disables transparency shadow effects" | |
12954 | "\n '-gi on|off' Enables/disables global illumination effects" | |
12955 | "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)" | |
12956 | "\n '-env on|off' Enables/disables environment map background" | |
12957 | "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)" | |
12958 | "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)" | |
12959 | "\n '-issd on|off' Shows screen sampling distribution in ISS mode" | |
12960 | "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)" | |
66d1cdc6 | 12961 | "\n '-tileSize 1..4096' Specifies size of screen tiles in ISS mode (32 by default)" |
12962 | "\n '-nbtiles 64..1024' Specifies number of screen tiles per Redraw in ISS mode (256 by default)" | |
a1073ae2 | 12963 | "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)" |
12964 | "\n '-shadingModel model' Controls shading model from enumeration" | |
12965 | "\n color, flat, gouraud, phong" | |
12966 | "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size" | |
b27ab03d | 12967 | "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)" |
12968 | "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect" | |
eb85ed36 | 12969 | "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)" |
12970 | "\n '-whitepoint value' White point value for filmic tone mapping" | |
12971 | "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)" | |
5e30547b | 12972 | "\n '-perfCounters none|fps|cpu|layers|structures|groups|arrays|triagles|points" |
12973 | "\n ' |gpuMem|frameTime|basic|extended|full|nofps|skipImmediate'" | |
15669413 | 12974 | "\n Show/hide performance counters (flags can be combined)" |
12975 | "\n '-perfUpdateInterval nbSeconds' Performance counters update interval" | |
5e30547b | 12976 | "\n '-perfChart nbFrames' Show frame timers chart limited by specified number of frames" |
12977 | "\n '-perfChartMax seconds' Maximum time in seconds with the chart" | |
0e3025bc | 12978 | "\n '-frustumCulling on|off|noupdate' Enable/disable objects frustum clipping or" |
12979 | "\n set state to check structures culled previously." | |
8625ef7e | 12980 | "\n Unlike vcaps, these parameters dramatically change visual properties." |
12981 | "\n Command is intended to control presentation quality depending on" | |
12982 | "\n hardware capabilities and performance.", | |
bc8c79bb | 12983 | __FILE__, VRenderParams, group); |
79b544e6 | 12984 | theCommands.Add("vstatprofiler", |
12985 | "\n vstatprofiler [fps|cpu|allLayers|layers|allstructures|structures|groups" | |
12986 | "\n |allArrays|fillArrays|lineArrays|pointArrays|textArrays" | |
12987 | "\n |triagles|points|geomMem|textureMem|frameMem" | |
12988 | "\n |elapsedFrame|cpuFrameAverage|cpuPickingAverage|cpuCullingAverage|cpuDynAverage" | |
12989 | "\n |cpuFrameMax|cpuPickingMax|cpuCullingMax|cpuDynMax]" | |
12990 | "\n [-noredraw]" | |
12991 | "\n\t\t: Prints rendering statistics." | |
12992 | "\n\t\t: If there are some parameters - print corresponding statistic counters values," | |
12993 | "\n\t\t: else - print all performance counters set previously." | |
12994 | "\n\t\t: '-noredraw' Flag to avoid additional redraw call and use already collected values.\n", | |
12995 | __FILE__, VStatProfiler, group); | |
49e1a5c7 | 12996 | theCommands.Add ("vplace", |
12997 | "vplace dx dy" | |
12998 | "\n\t\t: Places the point (in pixels) at the center of the window", | |
12999 | __FILE__, VPlace, group); | |
0717ddc1 | 13000 | theCommands.Add("vxrotate", |
13001 | "vxrotate", | |
13002 | __FILE__,VXRotate,group); | |
13003 | ||
625e1958 | 13004 | theCommands.Add("vmanipulator", |
13005 | "\n vmanipulator Name [-attach AISObject | -detach | ...]" | |
13006 | "\n tool to create and manage AIS manipulators." | |
13007 | "\n Options: " | |
13008 | "\n '-attach AISObject' attach manipulator to AISObject" | |
13009 | "\n '-adjustPosition {0|1}' adjust position when attaching" | |
13010 | "\n '-adjustSize {0|1}' adjust size when attaching" | |
13011 | "\n '-enableModes {0|1}' enable modes when attaching" | |
13012 | "\n '-detach' detach manipulator" | |
13013 | "\n '-startTransform mouse_x mouse_y' - invoke start of transformation" | |
13014 | "\n '-transform mouse_x mouse_y' - invoke transformation" | |
13015 | "\n '-stopTransform [abort]' - invoke stop of transformation" | |
13016 | "\n '-move x y z' - move attached object" | |
13017 | "\n '-rotate x y z dx dy dz angle' - rotate attached object" | |
13018 | "\n '-scale factor' - scale attached object" | |
13019 | "\n '-autoActivate {0|1}' - set activation on detection" | |
13020 | "\n '-followTranslation {0|1}' - set following translation transform" | |
13021 | "\n '-followRotation {0|1}' - set following rotation transform" | |
13022 | "\n '-gap value' - set gap between sub-parts" | |
13023 | "\n '-part axis mode {0|1}' - set visual part" | |
13024 | "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator" | |
13025 | "\n '-size value' - set size of manipulator" | |
13026 | "\n '-zoomable {0|1}' - set zoom persistence", | |
13027 | __FILE__, VManipulator, group); | |
13028 | ||
8e5fb5ea | 13029 | theCommands.Add("vselprops", |
f838dac4 | 13030 | "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]" |
8e5fb5ea | 13031 | "\n Customizes selection and dynamic highlight parameters for the whole interactive context:" |
13032 | "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode" | |
be3d8cbc | 13033 | "\n -autoHighlight {0|1} : disables|enables automatic highlighting in 3D Viewer" |
13034 | "\n -highlightSelected {0|1}: disables|enables highlighting of detected object in selected state" | |
14c4193d | 13035 | "\n -pickStrategy {first|topmost} : defines picking strategy" |
13036 | "\n 'first' to pick first acceptable (default)" | |
13037 | "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)" | |
8e5fb5ea | 13038 | "\n -pixTol value : sets up pixel tolerance" |
f838dac4 | 13039 | "\n -dispMode dispMode : sets display mode for highlighting" |
13040 | "\n -layer ZLayer : sets ZLayer for highlighting" | |
13041 | "\n -color {name|r g b} : sets highlight color" | |
13042 | "\n -transp value : sets transparency coefficient for highlight" | |
13043 | "\n -material material : sets highlight material" | |
8e5fb5ea | 13044 | "\n -print : prints current state of all mentioned parameters", |
13045 | __FILE__, VSelectionProperties, group); | |
be3d8cbc | 13046 | theCommands.Add ("vhighlightselected", |
13047 | "vhighlightselected [0|1]: alias for vselprops -highlightSelected.\n", | |
13048 | __FILE__, VSelectionProperties, group); | |
8e5fb5ea | 13049 | |
decdee7d | 13050 | theCommands.Add ("vseldump", |
13051 | "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1" | |
13052 | "\n\t\t: Generate an image based on detection results:" | |
13053 | "\n\t\t: depth normalized depth values" | |
13054 | "\n\t\t: unnormDepth unnormalized depth values" | |
13055 | "\n\t\t: object color of detected object" | |
13056 | "\n\t\t: owner color of detected owner" | |
13057 | "\n\t\t: selMode color of selection mode" | |
13058 | "\n\t\t: entity color of etected entity", | |
13059 | __FILE__, VDumpSelectionImage, group); | |
13060 | ||
189f85a3 | 13061 | #if defined(_WIN32) |
13062 | theCommands.Add("vprogressive", | |
13063 | "vprogressive", | |
13064 | __FILE__, VProgressiveMode, group); | |
13065 | #endif | |
7fd59977 | 13066 | } |