1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
21 #include <ViewerTest.hxx>
23 #include <AIS_AnimationCamera.hxx>
24 #include <AIS_AnimationObject.hxx>
25 #include <AIS_Axis.hxx>
26 #include <AIS_CameraFrustum.hxx>
27 #include <AIS_ColorScale.hxx>
28 #include <AIS_InteractiveContext.hxx>
29 #include <AIS_LightSource.hxx>
30 #include <AIS_ListOfInteractive.hxx>
31 #include <AIS_ListIteratorOfListOfInteractive.hxx>
32 #include <AIS_Manipulator.hxx>
33 #include <AIS_ViewCube.hxx>
34 #include <AIS_Shape.hxx>
35 #include <AIS_Point.hxx>
36 #include <Aspect_DisplayConnection.hxx>
37 #include <Aspect_Grid.hxx>
38 #include <Aspect_TypeOfLine.hxx>
40 #include <Draw_Appli.hxx>
41 #include <Draw_Interpretor.hxx>
42 #include <Draw_ProgressIndicator.hxx>
46 #include <Geom_Axis2Placement.hxx>
47 #include <Geom_CartesianPoint.hxx>
48 #include <Graphic3d_ArrayOfPolylines.hxx>
49 #include <Graphic3d_AspectFillArea3d.hxx>
50 #include <Graphic3d_AspectMarker3d.hxx>
51 #include <Graphic3d_ClipPlane.hxx>
52 #include <Graphic3d_CubeMapPacked.hxx>
53 #include <Graphic3d_CubeMapSeparate.hxx>
54 #include <Graphic3d_GraduatedTrihedron.hxx>
55 #include <Graphic3d_GraphicDriver.hxx>
56 #include <Graphic3d_GraphicDriverFactory.hxx>
57 #include <Graphic3d_NameOfTextureEnv.hxx>
58 #include <Graphic3d_Texture2Dmanual.hxx>
59 #include <Graphic3d_TextureEnv.hxx>
60 #include <Graphic3d_TextureParams.hxx>
61 #include <Graphic3d_TypeOfTextureFilter.hxx>
62 #include <Image_AlienPixMap.hxx>
63 #include <Image_Diff.hxx>
64 #include <Image_VideoRecorder.hxx>
65 #include <Message.hxx>
66 #include <Message_ProgressScope.hxx>
67 #include <Message_ProgressRange.hxx>
68 #include <NCollection_DataMap.hxx>
69 #include <NCollection_List.hxx>
70 #include <NCollection_LocalArray.hxx>
71 #include <NCollection_Vector.hxx>
73 #include <OSD_Parallel.hxx>
74 #include <OSD_Timer.hxx>
75 #include <Prs3d_ShadingAspect.hxx>
76 #include <Prs3d_DatumAspect.hxx>
77 #include <Prs3d_Drawer.hxx>
78 #include <Prs3d_LineAspect.hxx>
79 #include <Prs3d_Text.hxx>
80 #include <Select3D_SensitivePrimitiveArray.hxx>
81 #include <TColStd_HSequenceOfAsciiString.hxx>
82 #include <TColStd_SequenceOfInteger.hxx>
83 #include <TColStd_HSequenceOfReal.hxx>
84 #include <TColgp_Array1OfPnt2d.hxx>
85 #include <TColStd_MapOfAsciiString.hxx>
86 #include <ViewerTest_AutoUpdater.hxx>
87 #include <ViewerTest_ContinuousRedrawer.hxx>
88 #include <ViewerTest_EventManager.hxx>
89 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
90 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
91 #include <ViewerTest_CmdParser.hxx>
92 #include <ViewerTest_V3dView.hxx>
93 #include <V3d_AmbientLight.hxx>
94 #include <V3d_DirectionalLight.hxx>
95 #include <V3d_PositionalLight.hxx>
96 #include <V3d_SpotLight.hxx>
97 #include <V3d_Trihedron.hxx>
98 #include <V3d_Viewer.hxx>
99 #include <UnitsAPI.hxx>
106 #include <WNT_WClass.hxx>
107 #include <WNT_Window.hxx>
108 #include <WNT_HIDSpaceMouse.hxx>
109 #elif defined(HAVE_XLIB)
110 #include <Xw_Window.hxx>
111 #include <X11/Xlib.h>
112 #include <X11/Xutil.h>
113 #elif defined(__APPLE__)
114 #include <Cocoa_Window.hxx>
115 #elif defined(__EMSCRIPTEN__)
116 #include <Wasm_Window.hxx>
117 #include <emscripten/emscripten.h>
119 #include <Aspect_NeutralWindow.hxx>
122 //==============================================================================
123 // VIEWER GLOBAL VARIABLES
124 //==============================================================================
126 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
127 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
129 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
130 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
133 typedef WNT_Window ViewerTest_Window;
134 #elif defined(HAVE_XLIB)
135 typedef Xw_Window ViewerTest_Window;
136 static void VProcessEvents(ClientData,int);
137 #elif defined(__APPLE__)
138 typedef Cocoa_Window ViewerTest_Window;
139 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
140 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
141 #elif defined(__EMSCRIPTEN__)
142 typedef Wasm_Window ViewerTest_Window;
144 typedef Aspect_NeutralWindow ViewerTest_Window;
147 #if defined(__EMSCRIPTEN__)
148 //! Return DOM id of default WebGL canvas from Module.canvas.
149 EM_JS(char*, occJSModuleCanvasId, (), {
150 const aCanvasId = Module.canvas.id;
151 const aNbBytes = lengthBytesUTF8 (aCanvasId) + 1;
152 const aStrPtr = Module._malloc (aNbBytes);
153 stringToUTF8 (aCanvasId, aStrPtr, aNbBytes);
157 //! Return DOM id of default WebGL canvas from Module.canvas.
158 static TCollection_AsciiString getModuleCanvasId()
160 char* aRawId = occJSModuleCanvasId();
161 TCollection_AsciiString anId (aRawId != NULL ? aRawId : "");
167 static Handle(ViewerTest_Window)& VT_GetWindow()
169 static Handle(ViewerTest_Window) aWindow;
173 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
175 static Handle(Aspect_DisplayConnection) aDisplayConnection;
176 return aDisplayConnection;
179 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
181 GetDisplayConnection() = theDisplayConnection;
184 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
185 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
186 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
190 Quantity_Color FlatColor;
191 Quantity_Color GradientColor1;
192 Quantity_Color GradientColor2;
193 Aspect_GradientFillMethod FillMethod;
195 //! Sets the gradient filling for a background in a default viewer.
196 void SetDefaultGradient()
198 for (NCollection_DoubleMap<TCollection_AsciiString, Handle (AIS_InteractiveContext)>::Iterator aCtxIter (ViewerTest_myContexts);
199 aCtxIter.More(); aCtxIter.Next())
201 const Handle (V3d_Viewer)& aViewer = aCtxIter.Value()->CurrentViewer();
202 aViewer->SetDefaultBgGradientColors (GradientColor1, GradientColor2, FillMethod);
206 //! Sets the color used for filling a background in a default viewer.
207 void SetDefaultColor()
209 for (NCollection_DoubleMap<TCollection_AsciiString, Handle (AIS_InteractiveContext)>::Iterator aCtxIter (ViewerTest_myContexts);
210 aCtxIter.More(); aCtxIter.Next())
212 const Handle (V3d_Viewer)& aViewer = aCtxIter.Value()->CurrentViewer();
213 aViewer->SetDefaultBackgroundColor (FlatColor);
217 } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GradientFillMethod_None };
219 //==============================================================================
220 // EVENT GLOBAL VARIABLES
221 //==============================================================================
224 static LRESULT WINAPI AdvViewerWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
227 //==============================================================================
230 //==============================================================================
232 const Handle(WNT_WClass)& ViewerTest::WClass()
234 static Handle(WNT_WClass) theWClass;
236 if (theWClass.IsNull())
238 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
239 CS_VREDRAW | CS_HREDRAW, 0, 0,
240 ::LoadCursor (NULL, IDC_ARROW));
246 //==============================================================================
247 //function : CreateName
248 //purpose : Create numerical name for new object in theMap
249 //==============================================================================
250 template <typename ObjectType>
251 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
252 const TCollection_AsciiString& theDefaultString)
254 if (theObjectMap.IsEmpty())
255 return theDefaultString + TCollection_AsciiString(1);
257 Standard_Integer aNextKey = 1;
258 Standard_Boolean isFound = Standard_False;
261 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
262 // Look for objects with default names
263 if (theObjectMap.IsBound1(aStringKey))
268 isFound = Standard_True;
271 return theDefaultString + TCollection_AsciiString(aNextKey);
274 //==============================================================================
275 //structure : ViewerTest_Names
276 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
277 //==============================================================================
278 struct ViewerTest_Names
281 TCollection_AsciiString myDriverName;
282 TCollection_AsciiString myViewerName;
283 TCollection_AsciiString myViewName;
287 const TCollection_AsciiString& GetDriverName () const
291 void SetDriverName (const TCollection_AsciiString& theDriverName)
293 myDriverName = theDriverName;
295 const TCollection_AsciiString& GetViewerName () const
299 void SetViewerName (const TCollection_AsciiString& theViewerName)
301 myViewerName = theViewerName;
303 const TCollection_AsciiString& GetViewName () const
307 void SetViewName (const TCollection_AsciiString& theViewName)
309 myViewName = theViewName;
312 //===========================================================================
313 //function : Constructor for ViewerTest_Names
314 //purpose : Get view, viewer, driver names from custom string
315 //===========================================================================
317 ViewerTest_Names (const TCollection_AsciiString& theInputString)
319 TCollection_AsciiString aName(theInputString);
320 if (theInputString.IsEmpty())
322 // Get current configuration
323 if (ViewerTest_myDrivers.IsEmpty())
324 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
325 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
327 myDriverName = ViewerTest_myDrivers.Find2
328 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
330 if(ViewerTest_myContexts.IsEmpty())
332 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
333 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
337 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
340 myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
344 // There is at least view name
345 Standard_Integer aParserNumber = 0;
346 for (Standard_Integer i = 0; i < 3; ++i)
348 Standard_Integer aParserPos = aName.SearchFromEnd("/");
352 aName.Split(aParserPos-1);
357 if (aParserNumber == 0)
360 if (!ViewerTest::GetAISContext().IsNull())
362 myDriverName = ViewerTest_myDrivers.Find2
363 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
364 myViewerName = ViewerTest_myContexts.Find2
365 (ViewerTest::GetAISContext());
369 // There is no opened contexts here, need to create names for viewer and driver
370 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
371 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
373 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
374 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
376 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
378 else if (aParserNumber == 1)
380 // Here is viewerName/viewName
381 if (!ViewerTest::GetAISContext().IsNull())
382 myDriverName = ViewerTest_myDrivers.Find2
383 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
386 // There is no opened contexts here, need to create name for driver
387 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
388 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
390 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
392 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
396 //Here is driverName/viewerName/viewName
397 myDriverName = TCollection_AsciiString(aName);
399 TCollection_AsciiString aViewerName(theInputString);
400 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
401 myViewerName = TCollection_AsciiString(aViewerName);
403 myViewName = TCollection_AsciiString(theInputString);
409 //==============================================================================
410 //function : FindContextByView
411 //purpose : Find AIS_InteractiveContext by View
412 //==============================================================================
414 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
416 Handle(AIS_InteractiveContext) anAISContext;
418 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
419 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
421 if (anIter.Value()->CurrentViewer() == theView->Viewer())
422 return anIter.Key2();
427 //==============================================================================
428 //function : IsWindowOverlapped
429 //purpose : Check if theWindow overlapp another view
430 //==============================================================================
432 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
433 const Standard_Integer thePxTop,
434 const Standard_Integer thePxRight,
435 const Standard_Integer thePxBottom,
436 TCollection_AsciiString& theViewId)
438 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
439 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
441 Standard_Integer aTop = 0,
445 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
446 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
447 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
448 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
449 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
451 theViewId = anIter.Key1();
452 return Standard_True;
455 return Standard_False;
458 // Workaround: to create and delete non-orthographic views outside ViewerTest
459 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
461 ViewerTest_myViews.UnBind1 (theName);
464 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
465 const Handle(V3d_View)& theView)
467 ViewerTest_myViews.Bind (theName, theView);
470 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
472 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
475 //==============================================================================
476 //function : ViewerInit
477 //purpose : Create the window viewer and initialize all the global variable
478 //==============================================================================
480 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
481 const Standard_Integer thePxTop,
482 const Standard_Integer thePxWidth,
483 const Standard_Integer thePxHeight,
484 const TCollection_AsciiString& theViewName,
485 const TCollection_AsciiString& theDisplayName,
486 const Handle(V3d_View)& theViewToClone,
487 const Standard_Boolean theIsVirtual)
489 // Default position and dimension of the viewer window.
490 // Note that left top corner is set to be sufficiently small to have
491 // window fit in the small screens (actual for remote desktops, see #23003).
492 // The position corresponds to the window's client area, thus some
493 // gap is added for window frame to be visible.
494 Standard_Integer aPxLeft = 20, aPxTop = 40;
495 Standard_Integer aPxWidth = 409, aPxHeight = 409;
496 Standard_Boolean isDefViewSize = Standard_True;
497 Standard_Boolean toCreateViewer = Standard_False;
498 const Standard_Boolean isVirtual = Draw_VirtualWindows || theIsVirtual;
499 if (!theViewToClone.IsNull())
501 theViewToClone->Window()->Size (aPxWidth, aPxHeight);
502 isDefViewSize = Standard_False;
503 #if !defined(__EMSCRIPTEN__)
504 (void )isDefViewSize;
508 Handle(Graphic3d_GraphicDriverFactory) aFactory = Graphic3d_GraphicDriverFactory::DefaultDriverFactory();
509 if (aFactory.IsNull())
511 Draw::GetInterpretor().Eval ("pload OPENGL");
512 aFactory = Graphic3d_GraphicDriverFactory::DefaultDriverFactory();
513 if (aFactory.IsNull())
515 Draw::GetInterpretor().Eval ("pload GLES");
516 aFactory = Graphic3d_GraphicDriverFactory::DefaultDriverFactory();
517 if (aFactory.IsNull())
519 throw Standard_ProgramError("Error: no graphic driver factory found");
524 Handle(Graphic3d_GraphicDriver) aGraphicDriver;
525 ViewerTest_Names aViewNames(theViewName);
526 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
528 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
541 isDefViewSize = Standard_False;
542 aPxWidth = thePxWidth;
544 if (thePxHeight != 0)
546 isDefViewSize = Standard_False;
547 aPxHeight = thePxHeight;
550 // Get graphic driver (create it or get from another view)
551 const bool isNewDriver = !ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName());
554 // Get connection string
555 #if defined(HAVE_XLIB)
556 if (!theDisplayName.IsEmpty())
558 SetDisplayConnection (new Aspect_DisplayConnection (theDisplayName));
562 Aspect_XDisplay* aDispX = NULL;
563 // create dedicated display connection instead of reusing Tk connection
564 // so that to proceed events independently through VProcessEvents()/ViewerMainLoop() callbacks
565 /*Draw_Interpretor& aCommands = Draw::GetInterpretor();
566 Tcl_Interp* aTclInterp = aCommands.Interp();
567 Tk_Window aMainWindow = Tk_MainWindow (aTclInterp);
568 aDispX = aMainWindow != NULL ? Tk_Display (aMainWindow) : NULL;*/
569 SetDisplayConnection (new Aspect_DisplayConnection (aDispX));
572 (void)theDisplayName; // avoid warning on unused argument
573 SetDisplayConnection (new Aspect_DisplayConnection ());
576 aGraphicDriver = aFactory->CreateDriver (GetDisplayConnection());
579 // don't waste the time waiting for VSync when window is not displayed on the screen
580 aGraphicDriver->SetVerticalSync (false);
583 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
584 toCreateViewer = Standard_True;
588 aGraphicDriver = ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName());
591 //Dispose the window if input parameters are default
592 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
594 Standard_Integer aTop = 0,
601 // Get screen resolution
604 GetClientRect(GetDesktopWindow(), &aWindowSize);
605 aScreenHeight = aWindowSize.bottom;
606 aScreenWidth = aWindowSize.right;
607 #elif defined(HAVE_XLIB)
608 ::Display* aDispX = (::Display* )GetDisplayConnection()->GetDisplayAspect();
609 Screen* aScreen = DefaultScreenOfDisplay(aDispX);
610 aScreenWidth = WidthOfScreen(aScreen);
611 aScreenHeight = HeightOfScreen(aScreen);
612 #elif defined(__APPLE__)
613 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
618 TCollection_AsciiString anOverlappedViewId("");
620 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
622 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
624 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
625 && aRight + 2*aPxWidth + 40 > aScreenWidth)
627 if (aBottom + aPxHeight + 40 > aScreenHeight)
634 aPxTop = aBottom + 40;
637 aPxLeft = aRight + 20;
642 TCollection_AsciiString aTitle("3D View - ");
643 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
645 // Change name of current active window
646 if (const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView())
648 aCurrentView->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (aCurrentView));
652 Handle(V3d_Viewer) a3DViewer;
653 // If it's the single view, we first look for empty context
654 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
656 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
657 anIter(ViewerTest_myContexts);
659 ViewerTest::SetAISContext (anIter.Value());
660 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
662 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
664 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
665 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
667 else if (a3DViewer.IsNull())
669 toCreateViewer = Standard_True;
670 a3DViewer = new V3d_Viewer(aGraphicDriver);
671 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
672 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
673 ViewerTest_DefaultBackground.GradientColor2,
674 ViewerTest_DefaultBackground.FillMethod);
678 if (ViewerTest::GetAISContext().IsNull() ||
679 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
681 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
682 ViewerTest::SetAISContext (aContext);
683 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
687 ViewerTest::ResetEventManager();
692 VT_GetWindow() = new WNT_Window (aTitle.ToCString(), WClass(),
693 isVirtual ? WS_POPUP : WS_OVERLAPPEDWINDOW,
697 VT_GetWindow()->RegisterRawInputDevices (WNT_Window::RawInputMask_SpaceMouse);
698 #elif defined(HAVE_XLIB)
699 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
702 aPxWidth, aPxHeight);
703 #elif defined(__APPLE__)
704 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
706 aPxWidth, aPxHeight);
707 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
708 #elif defined(__EMSCRIPTEN__)
709 // current EGL implementation in Emscripten supports only one global WebGL canvas returned by Module.canvas property;
710 // the code should be revised for handling multiple canvas elements (which is technically also possible)
711 TCollection_AsciiString aCanvasId = getModuleCanvasId();
712 if (!aCanvasId.IsEmpty())
714 aCanvasId = TCollection_AsciiString("#") + aCanvasId;
717 VT_GetWindow() = new Wasm_Window (aCanvasId);
718 Graphic3d_Vec2i aRealSize;
719 VT_GetWindow()->Size (aRealSize.x(), aRealSize.y());
720 if (!isDefViewSize || (aRealSize.x() <= 0 && aRealSize.y() <= 0))
722 // Wasm_Window wraps an existing HTML element without creating a new one.
723 // Keep size defined on a web page instead of defaulting to 409x409 (as in case of other platform),
724 // but resize canvas if vinit has been called with explicitly specified dimensions.
725 VT_GetWindow()->SetSizeLogical (Graphic3d_Vec2d (aPxWidth, aPxHeight));
729 VT_GetWindow() = new Aspect_NeutralWindow();
730 VT_GetWindow()->SetSize (aPxWidth, aPxHeight);
732 VT_GetWindow()->SetVirtual (isVirtual);
735 Handle(V3d_View) aView;
736 if (!theViewToClone.IsNull())
738 aView = new ViewerTest_V3dView (a3DViewer, theViewToClone);
742 aView = new ViewerTest_V3dView (a3DViewer, a3DViewer->DefaultTypeOfView());
745 aView->SetWindow (VT_GetWindow());
746 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
748 ViewerTest::CurrentView(aView);
749 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
751 // Setup for X11 or NT
752 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
753 ViewerTest_EventManager::SetupWindowCallbacks (VT_GetWindow());
755 // Set parameters for V3d_View and V3d_Viewer
756 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
757 aV3dView->SetComputedMode(Standard_False);
759 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
762 a3DViewer->SetDefaultLights();
763 a3DViewer->SetLightOn();
766 #if defined(HAVE_XLIB)
769 ::Display* aDispX = (::Display* )GetDisplayConnection()->GetDisplayAspect();
770 Tcl_CreateFileHandler (XConnectionNumber (aDispX), TCL_READABLE, VProcessEvents, (ClientData )aDispX);
774 VT_GetWindow()->Map();
776 // Set the handle of created view in the event manager
777 ViewerTest::ResetEventManager();
779 ViewerTest::CurrentView()->Redraw();
784 return aViewNames.GetViewName();
787 //==============================================================================
788 //function : RedrawAllViews
789 //purpose : Redraw all created views
790 //==============================================================================
791 void ViewerTest::RedrawAllViews()
793 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
794 for (; aViewIt.More(); aViewIt.Next())
796 const Handle(V3d_View)& aView = aViewIt.Key2();
801 //==============================================================================
804 //==============================================================================
805 static int VDriver (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
809 theDi << "Registered: ";
810 for (Graphic3d_GraphicDriverFactoryList::Iterator aFactoryIter (Graphic3d_GraphicDriverFactory::DriverFactories());
811 aFactoryIter.More(); aFactoryIter.Next())
813 const Handle(Graphic3d_GraphicDriverFactory)& aFactory = aFactoryIter.Value();
814 theDi << aFactory->Name() << " ";
818 theDi << "Default: ";
819 if (Handle(Graphic3d_GraphicDriverFactory) aFactory = Graphic3d_GraphicDriverFactory::DefaultDriverFactory())
821 theDi << aFactory->Name();
830 TCollection_AsciiString aNewActive;
832 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
834 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
835 anArgCase.LowerCase();
836 if (anArgCase == "-list")
838 for (Graphic3d_GraphicDriverFactoryList::Iterator aFactoryIter (Graphic3d_GraphicDriverFactory::DriverFactories());
839 aFactoryIter.More(); aFactoryIter.Next())
841 const Handle(Graphic3d_GraphicDriverFactory)& aFactory = aFactoryIter.Value();
842 theDi << aFactory->Name() << " ";
845 else if ((anArgCase == "-default"
846 || anArgCase == "-load")
847 && aNewActive.IsEmpty())
849 toLoad = (anArgCase == "-load");
850 if (anArgIter + 1 < theArgsNb)
852 aNewActive = theArgVec[++anArgIter];
856 theDi << "Syntax error at '" << theArgVec[anArgIter] << "'";
861 if (Handle(Graphic3d_GraphicDriverFactory) aFactory = Graphic3d_GraphicDriverFactory::DefaultDriverFactory())
863 theDi << aFactory->Name();
871 else if (aNewActive.IsEmpty())
873 aNewActive = theArgVec[anArgIter];
877 theDi << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'";
882 if (!aNewActive.IsEmpty())
884 const TCollection_AsciiString aNameCopy = aNewActive;
885 if (TCollection_AsciiString::IsSameString (aNewActive, "gl", false)
886 || TCollection_AsciiString::IsSameString (aNewActive, "opengl", false)
887 || TCollection_AsciiString::IsSameString (aNewActive, "tkopengl", false))
889 aNewActive = "tkopengl";
891 else if (TCollection_AsciiString::IsSameString (aNewActive, "gles", false)
892 || TCollection_AsciiString::IsSameString (aNewActive, "opengles", false)
893 || TCollection_AsciiString::IsSameString (aNewActive, "tkopengles", false))
895 aNewActive = "tkopengles";
897 else if (TCollection_AsciiString::IsSameString (aNewActive, "d3d", false)
898 || TCollection_AsciiString::IsSameString (aNewActive, "d3dhost", false)
899 || TCollection_AsciiString::IsSameString (aNewActive, "tkd3dhost", false))
901 aNewActive = "tkd3dhost";
906 if (aNewActive == "tkopengl")
908 Draw::GetInterpretor().Eval ("pload OPENGL");
910 else if (aNewActive == "tkopengles")
912 Draw::GetInterpretor().Eval ("pload GLES");
914 else if (aNewActive == "tkd3dhost")
916 Draw::GetInterpretor().Eval ("pload D3DHOST");
920 theDi << "Syntax error: unable to load plugin for unknown driver factory '" << aNameCopy << "'";
925 bool isFound = false;
926 for (Graphic3d_GraphicDriverFactoryList::Iterator aFactoryIter (Graphic3d_GraphicDriverFactory::DriverFactories());
927 aFactoryIter.More(); aFactoryIter.Next())
929 Handle(Graphic3d_GraphicDriverFactory) aFactory = aFactoryIter.Value();
930 if (TCollection_AsciiString::IsSameString (aFactory->Name(), aNewActive, false))
932 Graphic3d_GraphicDriverFactory::RegisterFactory (aFactory, true);
940 theDi << "Syntax error: driver factory '" << aNameCopy << "' not found";
948 //==============================================================================
950 //purpose : Create the window viewer and initialize all the global variable
951 // Use Tcl_CreateFileHandler on UNIX to catch the X11 Viewer event
952 //==============================================================================
953 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
955 TCollection_AsciiString aViewName, aDisplayName;
956 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
957 Standard_Boolean isVirtual = false;
958 Handle(V3d_View) aCopyFrom;
959 TCollection_AsciiString aName, aValue;
960 int is2dMode = -1, aDpiAware = -1;
961 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
963 const TCollection_AsciiString anArg = theArgVec[anArgIt];
964 TCollection_AsciiString anArgCase = anArg;
965 anArgCase.LowerCase();
966 if (anArgIt + 1 < theArgsNb
967 && anArgCase == "-name")
969 aViewName = theArgVec[++anArgIt];
971 else if (anArgIt + 1 < theArgsNb
972 && (anArgCase == "-left"
973 || anArgCase == "-l"))
975 aPxLeft = Draw::Atoi (theArgVec[++anArgIt]);
977 else if (anArgIt + 1 < theArgsNb
978 && (anArgCase == "-top"
979 || anArgCase == "-t"))
981 aPxTop = Draw::Atoi (theArgVec[++anArgIt]);
983 else if (anArgIt + 1 < theArgsNb
984 && (anArgCase == "-width"
985 || anArgCase == "-w"))
987 aPxWidth = Draw::Atoi (theArgVec[++anArgIt]);
989 else if (anArgIt + 1 < theArgsNb
990 && (anArgCase == "-height"
991 || anArgCase == "-h"))
993 aPxHeight = Draw::Atoi (theArgVec[++anArgIt]);
995 else if (anArgCase == "-virtual"
996 || anArgCase == "-offscreen")
999 if (anArgIt + 1 < theArgsNb
1000 && Draw::ParseOnOff (theArgVec[anArgIt + 1], isVirtual))
1005 else if (anArgCase == "-exitonclose")
1007 ViewerTest_EventManager::ToExitOnCloseView() = true;
1008 if (anArgIt + 1 < theArgsNb
1009 && Draw::ParseOnOff (theArgVec[anArgIt + 1], ViewerTest_EventManager::ToExitOnCloseView()))
1014 else if (anArgCase == "-closeonescape"
1015 || anArgCase == "-closeonesc")
1017 ViewerTest_EventManager::ToCloseViewOnEscape() = true;
1018 if (anArgIt + 1 < theArgsNb
1019 && Draw::ParseOnOff (theArgVec[anArgIt + 1], ViewerTest_EventManager::ToCloseViewOnEscape()))
1024 else if (anArgCase == "-2d_mode"
1025 || anArgCase == "-2dmode"
1026 || anArgCase == "-2d")
1028 bool toEnable = true;
1029 if (anArgIt + 1 < theArgsNb
1030 && Draw::ParseOnOff (theArgVec[anArgIt + 1], toEnable))
1034 is2dMode = toEnable ? 1 : 0;
1036 else if (anArgIt + 1 < theArgsNb
1037 && (anArgCase == "-disp"
1038 || anArgCase == "-display"))
1040 aDisplayName = theArgVec[++anArgIt];
1042 else if (anArgCase == "-dpiaware")
1044 aDpiAware = Draw::ParseOnOffIterator (theArgsNb, theArgVec, anArgIt) ? 1 : 0;
1046 else if (!ViewerTest::CurrentView().IsNull()
1047 && aCopyFrom.IsNull()
1048 && (anArgCase == "-copy"
1049 || anArgCase == "-clone"
1050 || anArgCase == "-cloneactive"
1051 || anArgCase == "-cloneactiveview"))
1053 aCopyFrom = ViewerTest::CurrentView();
1056 else if (ViewerTest::SplitParameter (anArg, aName, aValue))
1059 if (aName == "name")
1063 else if (aName == "l"
1066 aPxLeft = aValue.IntegerValue();
1068 else if (aName == "t"
1071 aPxTop = aValue.IntegerValue();
1073 else if (aName == "disp"
1074 || aName == "display")
1076 aDisplayName = aValue;
1078 else if (aName == "w"
1079 || aName == "width")
1081 aPxWidth = aValue.IntegerValue();
1083 else if (aName == "h"
1084 || aName == "height")
1086 aPxHeight = aValue.IntegerValue();
1090 Message::SendFail() << "Syntax error: unknown argument " << anArg;
1094 else if (aViewName.IsEmpty())
1100 Message::SendFail() << "Syntax error: unknown argument " << anArg;
1106 if (aDpiAware != -1)
1108 typedef void* (WINAPI *SetThreadDpiAwarenessContext_t)(void*);
1109 if (HMODULE aUser32Module = GetModuleHandleW (L"User32"))
1111 SetThreadDpiAwarenessContext_t aSetDpiAware = (SetThreadDpiAwarenessContext_t )GetProcAddress (aUser32Module, "SetThreadDpiAwarenessContext");
1114 // DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
1115 if (aSetDpiAware ((void* )-4) == NULL)
1117 // DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE for older systems
1118 if (aSetDpiAware ((void* )-3) == NULL)
1120 Message::SendFail() << "Error: unable to enable DPI awareness";
1126 // DPI_AWARENESS_CONTEXT_UNAWARE
1127 if (aSetDpiAware ((void* )-1) == NULL)
1129 Message::SendFail() << "Error: unable to disable DPI awareness";
1136 #if !defined(HAVE_XLIB)
1137 if (!aDisplayName.IsEmpty())
1139 aDisplayName.Clear();
1140 Message::SendWarning() << "Warning: display parameter will be ignored.\n";
1145 ViewerTest_Names aViewNames (aViewName);
1146 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
1148 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
1149 theDi.Eval (aCommand.ToCString());
1152 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
1157 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
1158 aViewName, aDisplayName, aCopyFrom, isVirtual);
1161 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
1167 //! Parse HLR algo type.
1168 static Standard_Boolean parseHlrAlgoType (const char* theName,
1169 Prs3d_TypeOfHLR& theType)
1171 TCollection_AsciiString aName (theName);
1173 if (aName == "polyalgo")
1175 theType = Prs3d_TOH_PolyAlgo;
1177 else if (aName == "algo")
1179 theType = Prs3d_TOH_Algo;
1183 return Standard_False;
1185 return Standard_True;
1188 //==============================================================================
1190 //purpose : hidden lines removal algorithm
1191 //==============================================================================
1193 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1195 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1196 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1199 Message::SendFail ("Error: no active viewer");
1203 Standard_Boolean hasHlrOnArg = Standard_False;
1204 Standard_Boolean hasShowHiddenArg = Standard_False;
1205 Standard_Boolean isHLROn = Standard_False;
1206 Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
1207 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1208 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1209 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
1211 TCollection_AsciiString anArg (argv[anArgIter]);
1213 if (anUpdateTool.parseRedrawMode (anArg))
1217 else if (anArg == "-showhidden"
1218 && anArgIter + 1 < argc
1219 && Draw::ParseOnOff (argv[anArgIter + 1], toShowHidden))
1222 hasShowHiddenArg = Standard_True;
1225 else if ((anArg == "-type"
1227 || anArg == "-algotype")
1228 && anArgIter + 1 < argc
1229 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1234 else if (!hasHlrOnArg
1235 && Draw::ParseOnOff (argv[anArgIter], isHLROn))
1237 hasHlrOnArg = Standard_True;
1241 else if (!hasShowHiddenArg
1242 && Draw::ParseOnOff(argv[anArgIter], toShowHidden))
1244 hasShowHiddenArg = Standard_True;
1249 Message::SendFail() << "Syntax error at '" << argv[anArgIter] << "'";
1255 di << "HLR: " << aView->ComputedMode() << "\n";
1256 di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
1258 switch (aCtx->DefaultDrawer()->TypeOfHLR())
1260 case Prs3d_TOH_NotSet: di << "NotSet\n"; break;
1261 case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
1262 case Prs3d_TOH_Algo: di << "Algo\n"; break;
1264 anUpdateTool.Invalidate();
1268 Standard_Boolean toRecompute = Standard_False;
1269 if (aTypeOfHLR != Prs3d_TOH_NotSet
1270 && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
1272 toRecompute = Standard_True;
1273 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1275 if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
1277 toRecompute = Standard_True;
1280 aCtx->DefaultDrawer()->EnableDrawHiddenLine();
1284 aCtx->DefaultDrawer()->DisableDrawHiddenLine();
1289 if (aView->ComputedMode() && isHLROn && toRecompute)
1291 AIS_ListOfInteractive aListOfShapes;
1292 aCtx->DisplayedObjects (aListOfShapes);
1293 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
1295 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
1297 aCtx->Redisplay (aShape, Standard_False);
1302 aView->SetComputedMode (isHLROn);
1306 //==============================================================================
1307 //function : VHLRType
1308 //purpose : change type of using HLR algorithm
1309 //==============================================================================
1311 static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1313 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1314 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1317 Message::SendFail ("Error: no active viewer");
1321 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1322 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1323 AIS_ListOfInteractive aListOfShapes;
1324 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
1326 TCollection_AsciiString anArg (argv[anArgIter]);
1328 if (anUpdateTool.parseRedrawMode (anArg))
1332 else if ((anArg == "-type"
1334 || anArg == "-algotype")
1335 && anArgIter + 1 < argc
1336 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1342 else if (aTypeOfHLR == Prs3d_TOH_NotSet
1343 && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
1349 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
1350 TCollection_AsciiString aName (argv[anArgIter]);
1351 if (!aMap.IsBound2 (aName))
1353 Message::SendFail() << "Syntax error: Wrong shape name '" << aName << "'";
1357 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
1358 if (aShape.IsNull())
1360 Message::SendFail() << "Syntax error: '" << aName << "' is not a shape presentation";
1363 aListOfShapes.Append (aShape);
1367 if (aTypeOfHLR == Prs3d_TOH_NotSet)
1369 Message::SendFail ("Syntax error: wrong number of arguments");
1373 const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
1376 aCtx->DisplayedObjects (aListOfShapes);
1377 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1380 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
1382 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1383 if (aShape.IsNull())
1388 const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
1389 && aView->ComputedMode();
1391 || aShape->TypeOfHLR() != aTypeOfHLR)
1393 aShape->SetTypeOfHLR (aTypeOfHLR);
1397 aCtx->Redisplay (aShape, Standard_False);
1403 //==============================================================================
1404 //function : FindViewIdByWindowHandle
1405 //purpose : Find theView Id in the map of views by window handle
1406 //==============================================================================
1407 #if defined(_WIN32) || defined(HAVE_XLIB)
1408 static TCollection_AsciiString FindViewIdByWindowHandle (Aspect_Drawable theWindowHandle)
1410 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
1411 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1413 Aspect_Drawable aWindowHandle = anIter.Value()->Window()->NativeHandle();
1414 if (aWindowHandle == theWindowHandle)
1415 return anIter.Key1();
1417 return TCollection_AsciiString("");
1421 //! Make the view active
1422 void ActivateView (const TCollection_AsciiString& theViewName,
1423 Standard_Boolean theToUpdate = Standard_True)
1425 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1431 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1432 if (!anAISContext.IsNull())
1434 if (const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView())
1436 aCurrentView->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (aCurrentView));
1439 ViewerTest::CurrentView (aView);
1440 ViewerTest::SetAISContext (anAISContext);
1441 aView->Window()->SetTitle (TCollection_AsciiString("3D View - ") + theViewName + "(*)");
1442 VT_GetWindow() = Handle(ViewerTest_Window)::DownCast(ViewerTest::CurrentView()->Window());
1443 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1446 ViewerTest::CurrentView()->Redraw();
1451 //==============================================================================
1452 //function : RemoveView
1454 //==============================================================================
1455 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1456 const Standard_Boolean theToRemoveContext)
1458 if (!ViewerTest_myViews.IsBound2 (theView))
1463 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1464 RemoveView (aViewName, theToRemoveContext);
1467 //==============================================================================
1468 //function : RemoveView
1469 //purpose : Close and remove view from display, clear maps if necessary
1470 //==============================================================================
1471 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1473 if (!ViewerTest_myViews.IsBound1(theViewName))
1475 Message::SendFail() << "Wrong view name";
1479 // Activate another view if it's active now
1480 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1482 if (ViewerTest_myViews.Extent() > 1)
1484 TCollection_AsciiString aNewViewName;
1485 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1486 anIter.More(); anIter.Next())
1488 if (anIter.Key1() != theViewName)
1490 aNewViewName = anIter.Key1();
1494 ActivateView (aNewViewName);
1498 VT_GetWindow().Nullify();
1499 ViewerTest::CurrentView (Handle(V3d_View)());
1500 if (isContextRemoved)
1502 Handle(AIS_InteractiveContext) anEmptyContext;
1503 ViewerTest::SetAISContext(anEmptyContext);
1509 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1510 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1511 ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance();
1512 aRedrawer.Stop (aView);
1514 // Remove view resources
1515 ViewerTest_myViews.UnBind1(theViewName);
1516 aView->Window()->Unmap();
1519 #if defined(HAVE_XLIB)
1520 XFlush ((::Display* )GetDisplayConnection()->GetDisplayAspect());
1523 // Keep context opened only if the closed view is last to avoid
1524 // unused empty contexts
1525 if (!aCurrentContext.IsNull())
1527 // Check if there are more defined views in the viewer
1528 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1)
1529 && aCurrentContext->CurrentViewer()->DefinedViews().IsEmpty())
1531 // Remove driver if there is no viewers that use it
1532 Standard_Boolean isRemoveDriver = Standard_True;
1533 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1534 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1536 if (aCurrentContext != anIter.Key2() &&
1537 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1539 isRemoveDriver = Standard_False;
1544 aCurrentContext->RemoveAll (Standard_False);
1547 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1548 #if defined(HAVE_XLIB)
1549 Tcl_DeleteFileHandler (XConnectionNumber ((::Display* )aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplayAspect()));
1553 ViewerTest_myContexts.UnBind2(aCurrentContext);
1556 Message::SendInfo() << "3D View - " << theViewName << " was deleted.\n";
1557 if (ViewerTest_EventManager::ToExitOnCloseView())
1559 Draw_Interprete ("exit");
1563 //==============================================================================
1565 //purpose : Remove the view defined by its name
1566 //==============================================================================
1568 static int VClose (Draw_Interpretor& /*theDi*/,
1569 Standard_Integer theArgsNb,
1570 const char** theArgVec)
1572 NCollection_List<TCollection_AsciiString> aViewList;
1575 TCollection_AsciiString anArg (theArgVec[1]);
1577 if (anArg.IsEqual ("ALL")
1578 || anArg.IsEqual ("*"))
1580 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1581 anIter.More(); anIter.Next())
1583 aViewList.Append (anIter.Key1());
1585 if (aViewList.IsEmpty())
1587 std::cout << "No view to close\n";
1593 ViewerTest_Names aViewName (theArgVec[1]);
1594 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1596 Message::SendFail() << "Error: the view with name '" << theArgVec[1] << "' does not exist";
1599 aViewList.Append (aViewName.GetViewName());
1604 // close active view
1605 if (ViewerTest::CurrentView().IsNull())
1607 Message::SendFail ("Error: no active view");
1610 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1613 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1614 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1615 anIter.More(); anIter.Next())
1617 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1623 //==============================================================================
1624 //function : VActivate
1625 //purpose : Activate the view defined by its ID
1626 //==============================================================================
1628 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1632 theDi.Eval("vviewlist");
1636 TCollection_AsciiString aNameString;
1637 Standard_Boolean toUpdate = Standard_True;
1638 Standard_Boolean toActivate = Standard_True;
1639 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
1641 TCollection_AsciiString anArg (theArgVec[anArgIter]);
1644 && anArg == "-noupdate")
1646 toUpdate = Standard_False;
1649 && aNameString.IsEmpty()
1652 ViewerTest::CurrentView()->Window()->SetTitle (TCollection_AsciiString ("3D View - ") + ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1653 VT_GetWindow().Nullify();
1654 ViewerTest::CurrentView (Handle(V3d_View)());
1655 ViewerTest::ResetEventManager();
1656 theDi << theArgVec[0] << ": all views are inactive\n";
1657 toActivate = Standard_False;
1660 && aNameString.IsEmpty())
1662 aNameString = theArgVec[anArgIter];
1666 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
1675 else if (aNameString.IsEmpty())
1677 Message::SendFail ("Syntax error: wrong number of arguments");
1681 // Check if this view exists in the viewer with the driver
1682 ViewerTest_Names aViewNames (aNameString);
1683 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1685 theDi << "Syntax error: wrong view name '" << aNameString << "'\n";
1689 // Check if it is active already
1690 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1692 theDi << theArgVec[0] << ": the view is active already\n";
1696 ActivateView (aViewNames.GetViewName(), toUpdate);
1700 //==============================================================================
1701 //function : VViewList
1702 //purpose : Print current list of views per viewer and graphic driver ID
1703 // shared between viewers
1704 //==============================================================================
1706 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1710 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1711 << "Usage: " << theArgVec[0] << " name";
1714 if (ViewerTest_myContexts.Size() < 1)
1717 Standard_Boolean isTreeView =
1718 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1722 theDi << theArgVec[0] <<":\n";
1725 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers);
1726 aDriverIter.More(); aDriverIter.Next())
1729 theDi << aDriverIter.Key1() << ":\n";
1731 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1732 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1734 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1738 TCollection_AsciiString aContextName(aContextIter.Key1());
1739 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
1742 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews);
1743 aViewIter.More(); aViewIter.Next())
1745 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1747 TCollection_AsciiString aViewName(aViewIter.Key1());
1750 if (aViewIter.Value() == ViewerTest::CurrentView())
1751 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
1753 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1757 theDi << aViewName << " ";
1767 //==============================================================================
1768 //function : GetMousePosition
1770 //==============================================================================
1771 void ViewerTest::GetMousePosition (Standard_Integer& theX,
1772 Standard_Integer& theY)
1774 if (Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager())
1776 theX = aViewCtrl->LastMousePosition().x();
1777 theY = aViewCtrl->LastMousePosition().y();
1781 //==============================================================================
1782 //function : VViewProj
1783 //purpose : Switch view projection
1784 //==============================================================================
1785 static int VViewProj (Draw_Interpretor& ,
1786 Standard_Integer theNbArgs,
1787 const char** theArgVec)
1789 static Standard_Boolean isYup = Standard_False;
1790 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
1793 Message::SendFail ("Error: no active viewer");
1797 TCollection_AsciiString aCmdName (theArgVec[0]);
1798 Standard_Boolean isGeneralCmd = Standard_False;
1799 if (aCmdName == "vfront")
1801 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Front : V3d_TypeOfOrientation_Zup_Front, isYup);
1803 else if (aCmdName == "vback")
1805 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Back : V3d_TypeOfOrientation_Zup_Back, isYup);
1807 else if (aCmdName == "vtop")
1809 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Top : V3d_TypeOfOrientation_Zup_Top, isYup);
1811 else if (aCmdName == "vbottom")
1813 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Bottom : V3d_TypeOfOrientation_Zup_Bottom, isYup);
1815 else if (aCmdName == "vleft")
1817 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Left : V3d_TypeOfOrientation_Zup_Left, isYup);
1819 else if (aCmdName == "vright")
1821 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Right : V3d_TypeOfOrientation_Zup_Right, isYup);
1823 else if (aCmdName == "vaxo")
1825 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoRight : V3d_TypeOfOrientation_Zup_AxoRight, isYup);
1829 isGeneralCmd = Standard_True;
1830 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
1832 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
1833 anArgCase.LowerCase();
1834 if (anArgCase == "-zup")
1836 isYup = Standard_False;
1838 else if (anArgCase == "-yup")
1840 isYup = Standard_True;
1842 else if (anArgCase == "-front"
1843 || anArgCase == "front"
1844 || anArgCase == "-f"
1845 || anArgCase == "f")
1847 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Front : V3d_TypeOfOrientation_Zup_Front, isYup);
1849 else if (anArgCase == "-back"
1850 || anArgCase == "back"
1851 || anArgCase == "-b"
1852 || anArgCase == "b")
1854 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Back : V3d_TypeOfOrientation_Zup_Back, isYup);
1856 else if (anArgCase == "-top"
1857 || anArgCase == "top"
1858 || anArgCase == "-t"
1859 || anArgCase == "t")
1861 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Top : V3d_TypeOfOrientation_Zup_Top, isYup);
1863 else if (anArgCase == "-bottom"
1864 || anArgCase == "bottom"
1865 || anArgCase == "-bot"
1866 || anArgCase == "bot"
1867 || anArgCase == "-b"
1868 || anArgCase == "b")
1870 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Bottom : V3d_TypeOfOrientation_Zup_Bottom, isYup);
1872 else if (anArgCase == "-left"
1873 || anArgCase == "left"
1874 || anArgCase == "-l"
1875 || anArgCase == "l")
1877 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Left : V3d_TypeOfOrientation_Zup_Left, isYup);
1879 else if (anArgCase == "-right"
1880 || anArgCase == "right"
1881 || anArgCase == "-r"
1882 || anArgCase == "r")
1884 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_Right : V3d_TypeOfOrientation_Zup_Right, isYup);
1886 else if (anArgCase == "-axoleft"
1887 || anArgCase == "-leftaxo"
1888 || anArgCase == "axoleft"
1889 || anArgCase == "leftaxo")
1891 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoLeft : V3d_TypeOfOrientation_Zup_AxoLeft, isYup);
1893 else if (anArgCase == "-axo"
1894 || anArgCase == "axo"
1895 || anArgCase == "-a"
1897 || anArgCase == "-axoright"
1898 || anArgCase == "-rightaxo"
1899 || anArgCase == "axoright"
1900 || anArgCase == "rightaxo")
1902 aView->SetProj (isYup ? V3d_TypeOfOrientation_Yup_AxoRight : V3d_TypeOfOrientation_Zup_AxoRight, isYup);
1904 else if (anArgCase == "+x")
1906 aView->SetProj (V3d_Xpos, isYup);
1908 else if (anArgCase == "-x")
1910 aView->SetProj (V3d_Xneg, isYup);
1912 else if (anArgCase == "+y")
1914 aView->SetProj (V3d_Ypos, isYup);
1916 else if (anArgCase == "-y")
1918 aView->SetProj (V3d_Yneg, isYup);
1920 else if (anArgCase == "+z")
1922 aView->SetProj (V3d_Zpos, isYup);
1924 else if (anArgCase == "-z")
1926 aView->SetProj (V3d_Zneg, isYup);
1928 else if (anArgCase == "+x+y+z")
1930 aView->SetProj (V3d_XposYposZpos, isYup);
1932 else if (anArgCase == "+x+y-z")
1934 aView->SetProj (V3d_XposYposZneg, isYup);
1936 else if (anArgCase == "+x-y+z")
1938 aView->SetProj (V3d_XposYnegZpos, isYup);
1940 else if (anArgCase == "+x-y-z")
1942 aView->SetProj (V3d_XposYnegZneg, isYup);
1944 else if (anArgCase == "-x+y+z")
1946 aView->SetProj (V3d_XnegYposZpos, isYup);
1948 else if (anArgCase == "-x+y-z")
1950 aView->SetProj (V3d_XnegYposZneg, isYup);
1952 else if (anArgCase == "-x-y+z")
1954 aView->SetProj (V3d_XnegYnegZpos, isYup);
1956 else if (anArgCase == "-x-y-z")
1958 aView->SetProj (V3d_XnegYnegZneg, isYup);
1960 else if (anArgCase == "+x+y")
1962 aView->SetProj (V3d_XposYpos, isYup);
1964 else if (anArgCase == "+x-y")
1966 aView->SetProj (V3d_XposYneg, isYup);
1968 else if (anArgCase == "-x+y")
1970 aView->SetProj (V3d_XnegYpos, isYup);
1972 else if (anArgCase == "-x-y")
1974 aView->SetProj (V3d_XnegYneg, isYup);
1976 else if (anArgCase == "+x+z")
1978 aView->SetProj (V3d_XposZpos, isYup);
1980 else if (anArgCase == "+x-z")
1982 aView->SetProj (V3d_XposZneg, isYup);
1984 else if (anArgCase == "-x+z")
1986 aView->SetProj (V3d_XnegZpos, isYup);
1988 else if (anArgCase == "-x-z")
1990 aView->SetProj (V3d_XnegZneg, isYup);
1992 else if (anArgCase == "+y+z")
1994 aView->SetProj (V3d_YposZpos, isYup);
1996 else if (anArgCase == "+y-z")
1998 aView->SetProj (V3d_YposZneg, isYup);
2000 else if (anArgCase == "-y+z")
2002 aView->SetProj (V3d_YnegZpos, isYup);
2004 else if (anArgCase == "-y-z")
2006 aView->SetProj (V3d_YnegZneg, isYup);
2008 else if (anArgIter + 1 < theNbArgs
2009 && anArgCase == "-frame"
2010 && TCollection_AsciiString (theArgVec[anArgIter + 1]).Length() == 4)
2012 TCollection_AsciiString aFrameDef (theArgVec[++anArgIter]);
2013 aFrameDef.LowerCase();
2014 gp_Dir aRight, anUp;
2015 if (aFrameDef.Value (2) == aFrameDef.Value (4))
2017 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
2021 if (aFrameDef.Value (2) == 'x')
2023 aRight = aFrameDef.Value (1) == '+' ? gp::DX() : -gp::DX();
2025 else if (aFrameDef.Value (2) == 'y')
2027 aRight = aFrameDef.Value (1) == '+' ? gp::DY() : -gp::DY();
2029 else if (aFrameDef.Value (2) == 'z')
2031 aRight = aFrameDef.Value (1) == '+' ? gp::DZ() : -gp::DZ();
2035 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
2039 if (aFrameDef.Value (4) == 'x')
2041 anUp = aFrameDef.Value (3) == '+' ? gp::DX() : -gp::DX();
2043 else if (aFrameDef.Value (4) == 'y')
2045 anUp = aFrameDef.Value (3) == '+' ? gp::DY() : -gp::DY();
2047 else if (aFrameDef.Value (4) == 'z')
2049 anUp = aFrameDef.Value (3) == '+' ? gp::DZ() : -gp::DZ();
2053 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
2057 const Handle(Graphic3d_Camera)& aCamera = aView->Camera();
2058 const gp_Pnt anOriginVCS = aCamera->ConvertWorld2View (gp::Origin());
2059 const gp_Dir aDir = anUp.Crossed (aRight);
2060 aCamera->SetCenter (gp_Pnt (0, 0, 0));
2061 aCamera->SetDirection (aDir);
2062 aCamera->SetUp (anUp);
2063 aCamera->OrthogonalizeUp();
2065 aView->Panning (anOriginVCS.X(), anOriginVCS.Y());
2070 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
2079 Message::SendFail ("Syntax error: wrong number of arguments");
2085 //==============================================================================
2087 //purpose : Dsiplay help on viewer Keyboead and mouse commands
2088 //Draw arg : No args
2089 //==============================================================================
2091 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
2093 di << "=========================\n";
2094 di << "F : FitAll\n";
2095 di << "T : TopView\n";
2096 di << "B : BottomView\n";
2097 di << "R : RightView\n";
2098 di << "L : LeftView\n";
2099 di << "Backspace : AxonometricView\n";
2101 di << "=========================\n";
2102 di << "W, S : Fly forward/backward\n";
2103 di << "A, D : Slide left/right\n";
2104 di << "Q, E : Bank left/right\n";
2105 di << "-, + : Change flying speed\n";
2106 di << "Arrows : look left/right/up/down\n";
2107 di << "Arrows+Shift : slide left/right/up/down\n";
2109 di << "=========================\n";
2110 di << "S + Ctrl : Shading\n";
2111 di << "W + Ctrl : Wireframe\n";
2112 di << "H : HiddenLineRemoval\n";
2113 di << "U : Unset display mode\n";
2114 di << "Delete : Remove selection from viewer\n";
2116 di << "=========================\n";
2117 di << "Selection mode \n";
2118 di << "0 : Shape\n";
2119 di << "1 : Vertex\n";
2123 di << "5 : Shell\n";
2124 di << "6 : Solid\n";
2125 di << "7 : Compound\n";
2127 di << "=========================\n";
2128 di << "< : Hilight next detected\n";
2129 di << "> : Hilight previous detected\n";
2136 static LRESULT WINAPI AdvViewerWindowProc (HWND theWinHandle,
2141 if (ViewerTest_myViews.IsEmpty())
2143 return DefWindowProcW (theWinHandle, theMsg, wParam, lParam);
2150 // Delete view from map of views
2151 ViewerTest::RemoveView (FindViewIdByWindowHandle (theWinHandle));
2156 if (LOWORD(wParam) == WA_CLICKACTIVE
2157 || LOWORD(wParam) == WA_ACTIVE
2158 || ViewerTest::CurrentView().IsNull())
2160 // Activate inactive window
2161 if (VT_GetWindow().IsNull()
2162 || (HWND )VT_GetWindow()->HWindow() != theWinHandle)
2164 ActivateView (FindViewIdByWindowHandle (theWinHandle));
2171 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2173 && !VT_GetWindow().IsNull())
2176 aMsg.hwnd = theWinHandle;
2177 aMsg.message = theMsg;
2178 aMsg.wParam = wParam;
2179 aMsg.lParam = lParam;
2180 if (VT_GetWindow()->ProcessMessage (*ViewerTest::CurrentEventManager(), aMsg))
2187 return DefWindowProcW (theWinHandle, theMsg, wParam, lParam);
2190 //==============================================================================
2191 //function : ViewerMainLoop
2192 //purpose : Get a Event on the view and dispatch it
2193 //==============================================================================
2195 int ViewerMainLoop (Standard_Integer theNbArgs, const char** theArgVec)
2197 Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager();
2198 if (aViewCtrl.IsNull()
2204 aViewCtrl->StartPickPoint (theArgVec[1], theArgVec[2], theArgVec[3]);
2206 std::cout << "Start picking\n";
2210 while (aViewCtrl->ToPickPoint())
2212 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2213 if (GetMessageW (&aMsg, NULL, 0, 0))
2215 TranslateMessage (&aMsg);
2216 DispatchMessageW (&aMsg);
2220 std::cout << "Picking done\n";
2224 #elif defined(HAVE_XLIB)
2226 int ViewerMainLoop (Standard_Integer theNbArgs, const char** theArgVec)
2228 static XEvent aReport;
2229 const Standard_Boolean toPick = theNbArgs > 0;
2232 if (ViewerTest::CurrentEventManager().IsNull())
2236 ViewerTest::CurrentEventManager()->StartPickPoint (theArgVec[1], theArgVec[2], theArgVec[3]);
2239 Display* aDisplay = (Display* )GetDisplayConnection()->GetDisplayAspect();
2240 XNextEvent (aDisplay, &aReport);
2242 // Handle event for the chosen display connection
2243 switch (aReport.type)
2247 if ((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2250 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2251 return toPick ? 0 : 1;
2257 // Activate inactive view
2258 Window aWindow = !VT_GetWindow().IsNull() ? VT_GetWindow()->XWindow() : 0;
2259 if (aWindow != aReport.xfocus.window)
2261 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2267 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2269 && !VT_GetWindow().IsNull())
2271 VT_GetWindow()->ProcessMessage (*ViewerTest::CurrentEventManager(), aReport);
2276 return (!toPick || ViewerTest::CurrentEventManager()->ToPickPoint()) ? 1 : 0;
2279 //==============================================================================
2280 //function : VProcessEvents
2281 //purpose : manage the event in the Viewer window (see Tcl_CreateFileHandler())
2282 //==============================================================================
2283 static void VProcessEvents (ClientData theDispX, int)
2285 Display* aDispX = (Display* )theDispX;
2286 Handle(Aspect_DisplayConnection) aDispConn;
2287 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2288 aDriverIter (ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
2290 const Handle(Aspect_DisplayConnection)& aDispConnTmp = aDriverIter.Key2()->GetDisplayConnection();
2291 if ((Display* )aDispConnTmp->GetDisplayAspect() == aDispX)
2293 aDispConn = aDispConnTmp;
2297 if (aDispConn.IsNull())
2299 Message::SendFail ("Error: ViewerTest is unable processing messages for unknown X Display");
2303 // process new events in queue
2304 SetDisplayConnection (aDispConn);
2306 for (int aNbEventsMax = XPending (aDispX), anEventIter (0);;)
2308 const int anEventResult = ViewerMainLoop (0, NULL);
2309 if (anEventResult == 0)
2314 aNbRemain = XPending (aDispX);
2315 if (++anEventIter >= aNbEventsMax
2322 // Listening X events through Tcl_CreateFileHandler() callback is fragile,
2323 // it is possible that new events will arrive to queue before the end of this callback
2324 // so that either this callback should go into an infinite loop (blocking processing of other events)
2325 // or to keep unprocessed events till the next queue update (which can arrive not soon).
2326 // Sending a dummy event in this case is a simple workaround (still, it is possible that new event will be queued in-between).
2330 memset (&aDummyEvent, 0, sizeof(aDummyEvent));
2331 aDummyEvent.type = ClientMessage;
2332 aDummyEvent.xclient.format = 32;
2333 XSendEvent (aDispX, InputFocus, False, 0, &aDummyEvent);
2337 if (const Handle(AIS_InteractiveContext)& anActiveCtx = ViewerTest::GetAISContext())
2339 SetDisplayConnection (anActiveCtx->CurrentViewer()->Driver()->GetDisplayConnection());
2342 #elif !defined(__APPLE__)
2343 // =======================================================================
2344 // function : ViewerMainLoop
2346 // =======================================================================
2347 int ViewerMainLoop (Standard_Integer , const char** )
2354 //==============================================================================
2357 //==============================================================================
2359 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
2361 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2364 Message::SendFail ("Error: no active viewer");
2368 Standard_Boolean toFit = Standard_True;
2369 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2370 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2372 TCollection_AsciiString anArg (theArgv[anArgIter]);
2374 if (anUpdateTool.parseRedrawMode (anArg))
2378 else if (anArg == "-selected")
2380 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
2381 toFit = Standard_False;
2385 Message::SendFail() << "Syntax error at '" << anArg << "'";
2391 aView->FitAll (0.01, Standard_False);
2396 //=======================================================================
2397 //function : VFitArea
2398 //purpose : Fit view to show area located between two points
2399 // : given in world 2D or 3D coordinates.
2400 //=======================================================================
2401 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2403 Handle(V3d_View) aView = ViewerTest::CurrentView();
2406 Message::SendFail ("Error: No active viewer");
2411 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2412 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2416 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2417 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2418 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2419 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2421 else if (theArgNb == 7)
2423 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2424 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2425 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2426 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2427 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2428 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2432 Message::SendFail ("Syntax error: Invalid number of arguments");
2433 theDI.PrintHelp(theArgVec[0]);
2437 // Convert model coordinates to view space
2438 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2439 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2440 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2442 // Determine fit area
2443 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2444 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2446 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2448 if (aDiagonal < Precision::Confusion())
2450 Message::SendFail ("Error: view area is too small");
2454 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2458 //==============================================================================
2460 //purpose : ZFitall, no DRAW arguments
2461 //Draw arg : No args
2462 //==============================================================================
2463 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2465 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2467 if (aCurrentView.IsNull())
2469 Message::SendFail ("Error: no active viewer");
2475 aCurrentView->ZFitAll();
2476 aCurrentView->Redraw();
2480 Standard_Real aScale = 1.0;
2484 aScale = Draw::Atoi (theArgVec[1]);
2487 aCurrentView->ZFitAll (aScale);
2488 aCurrentView->Redraw();
2493 //==============================================================================
2494 //function : VRepaint
2496 //==============================================================================
2497 static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
2499 Handle(V3d_View) aView = ViewerTest::CurrentView();
2502 Message::SendFail ("Error: no active viewer");
2506 Standard_Boolean isImmediateUpdate = Standard_False;
2507 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2509 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2511 if (anArg == "-immediate"
2514 isImmediateUpdate = Standard_True;
2515 if (anArgIter + 1 < theArgNb
2516 && Draw::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
2521 else if (anArg == "-continuous"
2524 || anArg == "-framerate")
2526 Standard_Real aFps = -1.0;
2527 if (anArgIter + 1 < theArgNb
2528 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsRealValue (Standard_True))
2530 aFps = Draw::Atof (theArgVec[++anArgIter]);
2533 ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance();
2534 ViewerTest::CurrentEventManager()->SetContinuousRedraw (false);
2537 aRedrawer.Start (aView, aFps);
2539 else if (aFps < 0.0)
2541 if (ViewerTest::GetViewerFromContext()->ActiveViews().Extent() == 1)
2544 ViewerTest::CurrentEventManager()->SetContinuousRedraw (true);
2545 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
2548 aRedrawer.Start (aView, aFps);
2557 Message::SendFail() << "Syntax error at '" << anArg << "'";
2562 if (isImmediateUpdate)
2564 aView->RedrawImmediate();
2573 //==============================================================================
2575 //purpose : Remove all the object from the viewer
2576 //Draw arg : No args
2577 //==============================================================================
2579 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2581 Handle(V3d_View) V = ViewerTest::CurrentView();
2583 ViewerTest::Clear();
2587 //==============================================================================
2590 //==============================================================================
2592 static int VPick (Draw_Interpretor& ,
2593 Standard_Integer theNbArgs,
2594 const char** theArgVec)
2596 if (ViewerTest::CurrentView().IsNull())
2603 Message::SendFail ("Syntax error: wrong number of arguments");
2607 while (ViewerMainLoop (theNbArgs, theArgVec))
2615 //! Parse image fill method.
2616 static bool parseImageMode (const TCollection_AsciiString& theName,
2617 Aspect_FillMethod& theMode)
2619 TCollection_AsciiString aName = theName;
2621 if (aName == "none")
2623 theMode = Aspect_FM_NONE;
2625 else if (aName == "centered")
2627 theMode = Aspect_FM_CENTERED;
2629 else if (aName == "tiled")
2631 theMode = Aspect_FM_TILED;
2633 else if (aName == "stretch")
2635 theMode = Aspect_FM_STRETCH;
2644 //! Parse gradient fill method.
2645 static bool parseGradientMode (const TCollection_AsciiString& theName,
2646 Aspect_GradientFillMethod& theMode)
2648 TCollection_AsciiString aName = theName;
2650 if (aName == "none")
2652 theMode = Aspect_GradientFillMethod_None;
2654 else if (aName == "hor"
2655 || aName == "horizontal")
2657 theMode = Aspect_GradientFillMethod_Horizontal;
2659 else if (aName == "ver"
2661 || aName == "vertical")
2663 theMode = Aspect_GradientFillMethod_Vertical;
2665 else if (aName == "diag"
2666 || aName == "diagonal"
2668 || aName == "diagonal1")
2670 theMode = Aspect_GradientFillMethod_Diagonal1;
2672 else if (aName == "diag2"
2673 || aName == "diagonal2")
2675 theMode = Aspect_GradientFillMethod_Diagonal2;
2677 else if (aName == "corner1")
2679 theMode = Aspect_GradientFillMethod_Corner1;
2681 else if (aName == "corner2")
2683 theMode = Aspect_GradientFillMethod_Corner2;
2685 else if (aName == "corner3")
2687 theMode = Aspect_GradientFillMethod_Corner3;
2689 else if (aName == "corner4")
2691 theMode = Aspect_GradientFillMethod_Corner4;
2693 else if (aName == "ellip"
2694 || aName == "elliptical")
2696 theMode = Aspect_GradientFillMethod_Elliptical;
2705 //==============================================================================
2706 //function : VBackground
2708 //==============================================================================
2709 static int VBackground (Draw_Interpretor& theDI,
2710 Standard_Integer theNbArgs,
2711 const char** theArgVec)
2715 theDI << "Syntax error: wrong number of arguments";
2719 const TCollection_AsciiString aCmdName (theArgVec[0]);
2720 bool isDefault = aCmdName == "vsetdefaultbg";
2721 Standard_Integer aNbColors = 0;
2722 Quantity_ColorRGBA aColors[2];
2724 Aspect_GradientFillMethod aGradientMode = Aspect_GradientFillMethod_None;
2725 bool hasGradientMode = false;
2727 TCollection_AsciiString anImagePath;
2728 Aspect_FillMethod anImageMode = Aspect_FM_CENTERED;
2729 bool hasImageMode = false;
2731 bool isSkydomeBg = false;
2732 Aspect_SkydomeBackground aSkydomeAspect;
2734 NCollection_Sequence<TCollection_AsciiString> aCubeMapSeq;
2735 Graphic3d_CubeMapOrder aCubeOrder = Graphic3d_CubeMapOrder::Default();
2736 bool isCubeZInverted = false;
2741 Handle(V3d_View) aView = ViewerTest::CurrentView();
2742 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
2743 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
2745 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2747 if (anUpdateTool.parseRedrawMode (anArg))
2751 else if (anArg == "-default"
2756 else if (anArgIter + 1 < theNbArgs
2757 && (anArg == "-imagefile"
2758 || anArg == "-imgfile"
2759 || anArg == "-image"
2760 || anArg == "-img"))
2762 anImagePath = theArgVec[++anArgIter];
2764 else if (anArg == "-skydome"
2769 else if (anArgIter + 3 < theNbArgs
2771 && anArg == "-sundir")
2773 float aX = (float) Draw::Atof (theArgVec[++anArgIter]);
2774 float aY = (float) Draw::Atof (theArgVec[++anArgIter]);
2775 float aZ = (float) Draw::Atof (theArgVec[++anArgIter]);
2776 aSkydomeAspect.SetSunDirection (gp_Dir(aX, aY, aZ));
2778 else if (anArgIter + 1 < theNbArgs
2780 && anArg == "-cloud")
2782 float aCloudy = (float) Draw::Atof (theArgVec[++anArgIter]);
2783 aSkydomeAspect.SetCloudiness (aCloudy);
2785 else if (anArgIter + 1 < theNbArgs
2787 && anArg == "-time")
2789 float aTime = (float) Draw::Atof (theArgVec[++anArgIter]);
2790 aSkydomeAspect.SetTimeParameter (aTime);
2792 else if (anArgIter + 1 < theNbArgs
2796 float aFoggy = (float) Draw::Atof (theArgVec[++anArgIter]);
2797 aSkydomeAspect.SetFogginess (aFoggy);
2799 else if (anArgIter + 1 < theNbArgs
2801 && anArg == "-size")
2803 Standard_Integer aSize = Draw::Atoi (theArgVec[++anArgIter]);
2804 aSkydomeAspect.SetSize (aSize);
2806 else if (anArgIter + 1 < theNbArgs
2807 && aCubeMapSeq.IsEmpty()
2808 && (anArg == "-cubemap"
2812 aCubeMapSeq.Append (theArgVec[++anArgIter]);
2813 for (Standard_Integer aCubeSideIter = 1; anArgIter + aCubeSideIter < theNbArgs; ++aCubeSideIter)
2815 TCollection_AsciiString aSideArg (theArgVec[anArgIter + aCubeSideIter]);
2816 if (!aSideArg.IsEmpty()
2817 && aSideArg.Value (1) == '-')
2822 aCubeMapSeq.Append (aSideArg);
2823 if (aCubeMapSeq.Size() == 6)
2830 if (aCubeMapSeq.Size() > 1
2831 && aCubeMapSeq.Size() < 6)
2833 aCubeMapSeq.Remove (2, aCubeMapSeq.Size());
2836 else if (anArgIter + 6 < theNbArgs
2837 && anArg == "-order")
2839 for (Standard_Integer aCubeSideIter = 0; aCubeSideIter < 6; ++aCubeSideIter)
2841 Standard_Integer aSideArg = 0;
2842 if (!Draw::ParseInteger (theArgVec[anArgIter + aCubeSideIter + 1], aSideArg)
2846 theDI << "Syntax error at '" << theArgVec[anArgIter] << "'";
2849 aCubeOrder.Set ((Graphic3d_CubeMapSide )aCubeSideIter, (unsigned char )aSideArg);
2851 if (!aCubeOrder.IsValid())
2853 theDI << "Syntax error at '" << theArgVec[anArgIter] << "'";
2858 else if (anArg == "-invertedz"
2859 || anArg == "-noinvertedz"
2861 || anArg == "-noinvz")
2863 isCubeZInverted = Draw::ParseOnOffNoIterator (theNbArgs, theArgVec, anArgIter);
2865 else if (anArg == "-pbrenv"
2866 || anArg == "-nopbrenv"
2868 || anArg == "-noibl")
2870 toUseIBL = !anArg.StartsWith ("-no") ? 1 : 0;
2871 if (anArgIter + 1 < theNbArgs)
2873 TCollection_AsciiString anIblArg (theArgVec[anArgIter + 1]);
2874 anIblArg.LowerCase();
2875 if (anIblArg == "keep"
2876 || anIblArg == "-1")
2881 else if (anIblArg == "ibl"
2883 || anIblArg == "on")
2885 toUseIBL = !anArg.StartsWith ("-no") ? 1 : 0;
2888 else if (anIblArg == "noibl"
2890 || anIblArg == "off")
2892 toUseIBL = !anArg.StartsWith ("-no") ? 0 : 1;
2897 else if (anArg == "-srgb"
2898 || anArg == "-nosrgb")
2900 isSRgb = Draw::ParseOnOffNoIterator (theNbArgs, theArgVec, anArgIter);
2902 else if (aNbColors < 2
2903 && (anArg == "-color"
2904 || anArg == "-col"))
2906 Standard_Integer aNbParsed = Draw::ParseColor (theNbArgs - (anArgIter + 1),
2907 theArgVec + (anArgIter + 1),
2908 aColors[aNbColors].ChangeRGB());
2911 theDI << "Syntax error at '" << theArgVec[anArgIter] << "'";
2914 anArgIter += aNbParsed;
2917 else if (anArgIter + 1 < theNbArgs
2918 && (anArg == "-gradientmode"
2919 || anArg == "-gradmode"
2920 || anArg == "-gradmd"
2921 || anArg == "-grmode"
2922 || anArg == "-grmd")
2923 && parseGradientMode (theArgVec[anArgIter + 1], aGradientMode))
2926 hasGradientMode = true;
2928 else if (anArgIter + 1 < theNbArgs
2929 && (anArg == "-imagemode"
2930 || anArg == "-imgmode"
2931 || anArg == "-imagemd"
2932 || anArg == "-imgmd")
2933 && parseImageMode (theArgVec[anArgIter + 1], anImageMode))
2936 hasImageMode = true;
2938 else if (aNbColors == 0
2939 && anArgIter + 2 < theNbArgs
2940 && (anArg == "-gradient"
2944 Standard_Integer aNbParsed1 = Draw::ParseColor (theNbArgs - (anArgIter + 1),
2945 theArgVec + (anArgIter + 1),
2946 aColors[aNbColors].ChangeRGB());
2947 anArgIter += aNbParsed1;
2949 if (aNbParsed1 == 0)
2951 theDI << "Syntax error at '" << theArgVec[anArgIter] << "'";
2954 Standard_Integer aNbParsed2 = Draw::ParseColor (theNbArgs - (anArgIter + 1),
2955 theArgVec + (anArgIter + 1),
2956 aColors[aNbColors].ChangeRGB());
2957 anArgIter += aNbParsed2;
2959 if (aNbParsed2 == 0)
2961 theDI << "Syntax error at '" << theArgVec[anArgIter] << "'";
2965 else if (parseGradientMode (theArgVec[anArgIter], aGradientMode))
2967 hasGradientMode = true;
2969 else if (aNbColors < 2
2970 && (Quantity_ColorRGBA::ColorFromName(theArgVec[anArgIter], aColors[aNbColors])
2971 || Quantity_ColorRGBA::ColorFromHex (theArgVec[anArgIter], aColors[aNbColors])))
2975 else if (anImagePath.IsEmpty()
2978 && aCubeMapSeq.IsEmpty())
2980 anImagePath = theArgVec[anArgIter];
2984 theDI << "Syntax error at '" << theArgVec[anArgIter] << "'";
2992 theDI << "Error: no active viewer";
2997 && !hasGradientMode)
2999 theDI << "Syntax error at '-default'";
3007 ViewerTest_DefaultBackground.GradientColor1 = Quantity_Color();
3008 ViewerTest_DefaultBackground.GradientColor2 = Quantity_Color();
3009 ViewerTest_DefaultBackground.FillMethod = Aspect_GradientFillMethod_None;
3010 ViewerTest_DefaultBackground.FlatColor = aColors[0].GetRGB();
3011 ViewerTest_DefaultBackground.SetDefaultGradient();
3012 ViewerTest_DefaultBackground.SetDefaultColor();
3016 aView->SetBgGradientStyle (hasGradientMode ? aGradientMode : Aspect_GradientFillMethod_None);
3017 aView->SetBackgroundColor (aColors[0].GetRGB());
3020 aView->SetBackgroundCubeMap (Handle(Graphic3d_CubeMap)(), true);
3024 else if (aNbColors == 2)
3028 ViewerTest_DefaultBackground.GradientColor1 = aColors[0].GetRGB();
3029 ViewerTest_DefaultBackground.GradientColor2 = aColors[1].GetRGB();
3030 if (hasGradientMode)
3032 ViewerTest_DefaultBackground.FillMethod = aGradientMode;
3034 else if (ViewerTest_DefaultBackground.FillMethod == Aspect_GradientFillMethod_None)
3036 ViewerTest_DefaultBackground.FillMethod = Aspect_GradientFillMethod_Vertical;
3038 ViewerTest_DefaultBackground.SetDefaultGradient();
3042 if (!hasGradientMode)
3044 aGradientMode = aView->GradientBackground().BgGradientFillMethod();
3045 if (aGradientMode == Aspect_GradientFillMethod_None)
3047 aGradientMode = Aspect_GradientFillMethod_Vertical;
3050 aView->SetBgGradientColors (aColors[0].GetRGB(), aColors[1].GetRGB(), aGradientMode);
3053 aView->SetBackgroundCubeMap (Handle(Graphic3d_CubeMap)(), true);
3057 else if (hasGradientMode)
3061 ViewerTest_DefaultBackground.FillMethod = aGradientMode;
3062 ViewerTest_DefaultBackground.SetDefaultGradient();
3066 aView->SetBgGradientStyle (aGradientMode);
3070 if (!anImagePath.IsEmpty())
3072 Handle(Graphic3d_Texture2D) aTextureMap = new Graphic3d_Texture2Dmanual (anImagePath);
3073 aTextureMap->DisableModulate();
3074 aTextureMap->SetColorMap (isSRgb);
3075 if (!aTextureMap->IsDone())
3077 theDI << "Syntax error at '" << anImagePath << "'";
3080 aView->SetBackgroundImage (aTextureMap, anImageMode);
3082 else if (hasImageMode)
3084 aView->SetBgImageStyle (anImageMode);
3089 aView->SetBackgroundSkydome (aSkydomeAspect, toUseIBL != -1);
3092 if (!aCubeMapSeq.IsEmpty())
3094 Handle(Graphic3d_CubeMap) aCubeMap;
3095 if (aCubeMapSeq.Size() == 1)
3097 aCubeMap = new Graphic3d_CubeMapPacked (aCubeMapSeq.First(), aCubeOrder.Validated());
3101 NCollection_Array1<TCollection_AsciiString> aCubeMapArr (0, 5);
3102 Standard_Integer aCubeSide = 0;
3103 for (NCollection_Sequence<TCollection_AsciiString>::Iterator aFileIter (aCubeMapSeq); aFileIter.More(); aFileIter.Next(), ++aCubeSide)
3105 aCubeMapArr[aCubeSide] = aFileIter.Value();
3107 aCubeMap = new Graphic3d_CubeMapSeparate (aCubeMapArr);
3110 aCubeMap->SetZInversion (isCubeZInverted);
3111 aCubeMap->SetColorMap (isSRgb);
3113 aCubeMap->GetParams()->SetFilter (Graphic3d_TOTF_BILINEAR);
3114 aCubeMap->GetParams()->SetRepeat (false);
3115 aCubeMap->GetParams()->SetTextureUnit (Graphic3d_TextureUnit_EnvMap);
3117 aView->SetBackgroundCubeMap (aCubeMap, toUseIBL != -1);
3122 aView->SetImageBasedLighting (toUseIBL == 1);
3128 //==============================================================================
3130 //purpose : View Scaling
3131 //==============================================================================
3133 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3135 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3136 if ( V3dView.IsNull() ) return 1;
3139 di << argv[0] << "Invalid number of arguments\n";
3142 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
3145 //==============================================================================
3146 //function : VZBuffTrihedron
3148 //==============================================================================
3150 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
3151 Standard_Integer theArgNb,
3152 const char** theArgVec)
3154 Handle(V3d_View) aView = ViewerTest::CurrentView();
3157 Message::SendFail ("Error: no active viewer");
3161 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
3163 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
3164 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
3165 Quantity_Color aLabelsColorX = Quantity_NOC_WHITE;
3166 Quantity_Color aLabelsColorY = Quantity_NOC_WHITE;
3167 Quantity_Color aLabelsColorZ = Quantity_NOC_WHITE;
3168 Quantity_Color anArrowColorX = Quantity_NOC_RED;
3169 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
3170 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
3171 Standard_Real aScale = 0.1;
3172 Standard_Real aSizeRatio = 0.8;
3173 Standard_Real anArrowDiam = 0.05;
3174 Standard_Integer aNbFacets = 12;
3175 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3177 Standard_CString anArg = theArgVec[anArgIter];
3178 TCollection_AsciiString aFlag (anArg);
3180 if (anUpdateTool.parseRedrawMode (aFlag))
3184 else if (aFlag == "-on")
3188 else if (aFlag == "-off")
3190 aView->TriedronErase();
3193 else if (aFlag == "-pos"
3194 || aFlag == "-position"
3195 || aFlag == "-corner")
3197 if (++anArgIter >= theArgNb)
3199 Message::SendFail() << "Error: wrong syntax at '" << anArg << "'";
3203 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3204 aPosName.LowerCase();
3205 if (aPosName == "center")
3207 aPosition = Aspect_TOTP_CENTER;
3209 else if (aPosName == "left_lower"
3210 || aPosName == "lower_left"
3211 || aPosName == "leftlower"
3212 || aPosName == "lowerleft")
3214 aPosition = Aspect_TOTP_LEFT_LOWER;
3216 else if (aPosName == "left_upper"
3217 || aPosName == "upper_left"
3218 || aPosName == "leftupper"
3219 || aPosName == "upperleft")
3221 aPosition = Aspect_TOTP_LEFT_UPPER;
3223 else if (aPosName == "right_lower"
3224 || aPosName == "lower_right"
3225 || aPosName == "rightlower"
3226 || aPosName == "lowerright")
3228 aPosition = Aspect_TOTP_RIGHT_LOWER;
3230 else if (aPosName == "right_upper"
3231 || aPosName == "upper_right"
3232 || aPosName == "rightupper"
3233 || aPosName == "upperright")
3235 aPosition = Aspect_TOTP_RIGHT_UPPER;
3239 Message::SendFail() << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'";
3243 else if (aFlag == "-type")
3245 if (++anArgIter >= theArgNb)
3247 Message::SendFail() << "Error: wrong syntax at '" << anArg << "'";
3251 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3252 aTypeName.LowerCase();
3253 if (aTypeName == "wireframe"
3254 || aTypeName == "wire")
3256 aVisType = V3d_WIREFRAME;
3258 else if (aTypeName == "zbuffer"
3259 || aTypeName == "shaded")
3261 aVisType = V3d_ZBUFFER;
3265 Message::SendFail() << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'";
3268 else if (aFlag == "-scale")
3270 if (++anArgIter >= theArgNb)
3272 Message::SendFail() << "Error: wrong syntax at '" << anArg << "'";
3276 aScale = Draw::Atof (theArgVec[anArgIter]);
3278 else if (aFlag == "-size"
3279 || aFlag == "-sizeratio")
3281 if (++anArgIter >= theArgNb)
3283 Message::SendFail() << "Error: wrong syntax at '" << anArg << "'";
3287 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3289 else if (aFlag == "-arrowdiam"
3290 || aFlag == "-arrowdiameter")
3292 if (++anArgIter >= theArgNb)
3294 Message::SendFail() << "Error: wrong syntax at '" << anArg << "'";
3298 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3300 else if (aFlag == "-nbfacets")
3302 if (++anArgIter >= theArgNb)
3304 Message::SendFail() << "Error: wrong syntax at '" << anArg << "'";
3308 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3310 else if (aFlag == "-colorlabel"
3311 || aFlag == "-colorlabels"
3312 || aFlag == "-colorlabelx"
3313 || aFlag == "-colorlabely"
3314 || aFlag == "-colorlabelz"
3315 || aFlag == "-colorarrowx"
3316 || aFlag == "-colorarrowy"
3317 || aFlag == "-colorarrowz")
3319 Quantity_Color aColor;
3320 Standard_Integer aNbParsed = Draw::ParseColor (theArgNb - anArgIter - 1,
3321 theArgVec + anArgIter + 1,
3325 Message::SendFail() << "Error: wrong syntax at '" << anArg << "'";
3329 if (aFlag == "-colorarrowx")
3331 anArrowColorX = aColor;
3333 else if (aFlag == "-colorarrowy")
3335 anArrowColorY = aColor;
3337 else if (aFlag == "-colorarrowz")
3339 anArrowColorZ = aColor;
3341 else if (aFlag == "-colorlabelx")
3343 aLabelsColorX = aColor;
3345 else if (aFlag == "-colorlabely")
3347 aLabelsColorY = aColor;
3349 else if (aFlag == "-colorlabelz")
3351 aLabelsColorZ = aColor;
3355 aLabelsColorZ = aLabelsColorY = aLabelsColorX = aColor;
3357 anArgIter += aNbParsed;
3361 Message::SendFail() << "Error: wrong syntax at '" << anArg << "'";
3366 const Handle(V3d_Trihedron)& aTrihedron = aView->Trihedron();
3367 aTrihedron->SetArrowsColor (anArrowColorX, anArrowColorY, anArrowColorZ);
3368 aTrihedron->SetLabelsColor (aLabelsColorX, aLabelsColorY, aLabelsColorZ);
3369 aTrihedron->SetSizeRatio (aSizeRatio);
3370 aTrihedron->SetNbFacets (aNbFacets);
3371 aTrihedron->SetArrowDiameter(anArrowDiam);
3372 aTrihedron->SetScale (aScale);
3373 aTrihedron->SetPosition (aPosition);
3374 aTrihedron->SetWireframe (aVisType == V3d_WIREFRAME);
3375 aTrihedron->Display (aView);
3381 //==============================================================================
3382 //function : VRotate
3383 //purpose : Camera Rotating
3384 //==============================================================================
3386 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3388 Handle(V3d_View) aView = ViewerTest::CurrentView();
3391 Message::SendFail ("Error: no active viewer");
3395 Standard_Boolean hasFlags = Standard_False;
3396 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3398 Standard_CString anArg (theArgVec[anArgIter]);
3399 TCollection_AsciiString aFlag (anArg);
3401 if (aFlag == "-mousestart"
3402 || aFlag == "-mousefrom")
3404 hasFlags = Standard_True;
3405 if (anArgIter + 2 >= theArgNb)
3407 Message::SendFail() << "Error: wrong syntax at '" << anArg << "'";
3411 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3412 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3413 aView->StartRotation (anX, anY);
3415 else if (aFlag == "-mousemove")
3417 hasFlags = Standard_True;
3418 if (anArgIter + 2 >= theArgNb)
3420 Message::SendFail() << "Error: wrong syntax at '" << anArg << "'";
3424 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3425 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3426 aView->Rotation (anX, anY);
3428 else if (theArgNb != 4
3431 Message::SendFail() << "Error: wrong syntax at '" << anArg << "'";
3440 else if (theArgNb == 4)
3442 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3443 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3444 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3445 aView->Rotate (anAX, anAY, anAZ);
3448 else if (theArgNb == 7)
3450 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3451 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3452 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3454 Standard_Real anX = Draw::Atof (theArgVec[4]);
3455 Standard_Real anY = Draw::Atof (theArgVec[5]);
3456 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3458 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3462 Message::SendFail ("Error: Invalid number of arguments");
3466 //==============================================================================
3468 //purpose : View zoom in / out (relative to current zoom)
3469 //==============================================================================
3471 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3472 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3473 if ( V3dView.IsNull() ) {
3478 Standard_Real coef = Draw::Atof(argv[1]);
3479 if ( coef <= 0.0 ) {
3480 di << argv[1] << "Invalid value\n";
3483 V3dView->SetZoom( Draw::Atof(argv[1]) );
3486 di << argv[0] << " Invalid number of arguments\n";
3491 //==============================================================================
3493 //purpose : View panning (in pixels)
3494 //==============================================================================
3496 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3497 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3498 if ( V3dView.IsNull() ) return 1;
3501 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
3504 di << argv[0] << " Invalid number of arguments\n";
3509 //==============================================================================
3511 //purpose : Place the point (in pixels) at the center of the window
3512 //==============================================================================
3513 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3515 Handle(V3d_View) aView = ViewerTest::CurrentView();
3518 Message::SendFail ("Error: no active viewer");
3524 Message::SendFail ("Syntax error: wrong number of arguments");
3528 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3533 static int VColorScale (Draw_Interpretor& theDI,
3534 Standard_Integer theArgNb,
3535 const char** theArgVec)
3537 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3538 Handle(V3d_View) aView = ViewerTest::CurrentView();
3539 if (aContext.IsNull())
3541 Message::SendFail ("Error: no active viewer");
3546 Message::SendFail() << "Error: wrong syntax at command '" << theArgVec[0] << "'";
3550 Handle(AIS_ColorScale) aColorScale;
3551 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
3553 // find existing object
3554 aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
3555 if (aColorScale.IsNull())
3557 Message::SendFail() << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale";
3564 if (aColorScale.IsNull())
3566 Message::SendFail() << "Syntax error: colorscale with a given name does not exist";
3570 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
3571 << "Min range: " << aColorScale->GetMin() << "\n"
3572 << "Max range: " << aColorScale->GetMax() << "\n"
3573 << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n"
3574 << "Text height: " << aColorScale->GetTextHeight() << "\n"
3575 << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n"
3576 << "Color scale title: " << aColorScale->GetTitle() << "\n"
3577 << "Label position: ";
3578 switch (aColorScale->GetLabelPosition())
3580 case Aspect_TOCSP_NONE:
3583 case Aspect_TOCSP_LEFT:
3586 case Aspect_TOCSP_RIGHT:
3589 case Aspect_TOCSP_CENTER:
3590 theDI << "Center\n";
3596 if (aColorScale.IsNull())
3598 aColorScale = new AIS_ColorScale();
3599 aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
3600 aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
3603 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
3604 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
3606 Standard_CString anArg = theArgVec[anArgIter];
3607 TCollection_AsciiString aFlag (anArg);
3609 if (anUpdateTool.parseRedrawMode (aFlag))
3613 else if (aFlag == "-range")
3615 if (anArgIter + 3 >= theArgNb)
3617 Message::SendFail() << "Error: wrong syntax at argument '" << anArg << "'";
3621 const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]);
3622 const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]);
3623 const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]);
3624 if (!aRangeMin.IsRealValue (Standard_True)
3625 || !aRangeMax.IsRealValue (Standard_True))
3627 Message::SendFail ("Syntax error: the range values should be real");
3630 else if (!aNbIntervals.IsIntegerValue())
3632 Message::SendFail ("Syntax error: the number of intervals should be integer");
3636 aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue());
3637 aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue());
3639 else if (aFlag == "-font")
3641 if (anArgIter + 1 >= theArgNb)
3643 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
3646 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
3647 if (!aFontArg.IsIntegerValue())
3649 Message::SendFail ("Syntax error: HeightFont value should be integer");
3653 aColorScale->SetTextHeight (aFontArg.IntegerValue());
3656 else if (aFlag == "-textpos")
3658 if (anArgIter + 1 >= theArgNb)
3660 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
3664 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
3665 aTextPosArg.LowerCase();
3666 Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE;
3667 if (aTextPosArg == "none")
3669 aLabPosition = Aspect_TOCSP_NONE;
3671 else if (aTextPosArg == "left")
3673 aLabPosition = Aspect_TOCSP_LEFT;
3675 else if (aTextPosArg == "right")
3677 aLabPosition = Aspect_TOCSP_RIGHT;
3679 else if (aTextPosArg == "center")
3681 aLabPosition = Aspect_TOCSP_CENTER;
3685 Message::SendFail() << "Syntax error: unknown position '" << aTextPosArg << "'";
3688 aColorScale->SetLabelPosition (aLabPosition);
3690 else if (aFlag == "-logarithmic"
3693 if (anArgIter + 1 >= theArgNb)
3695 Message::SendFail() << "Synta error at argument '" << anArg << "'";
3699 Standard_Boolean IsLog;
3700 if (!Draw::ParseOnOff(theArgVec[++anArgIter], IsLog))
3702 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
3705 aColorScale->SetLogarithmic (IsLog);
3707 else if (aFlag == "-huerange"
3710 if (anArgIter + 2 >= theArgNb)
3712 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
3716 const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]);
3717 const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]);
3718 aColorScale->SetHueRange (aHueMin, aHueMax);
3720 else if (aFlag == "-colorrange")
3722 Quantity_Color aColorMin, aColorMax;
3723 Standard_Integer aNbParsed1 = Draw::ParseColor (theArgNb - (anArgIter + 1),
3724 theArgVec + (anArgIter + 1),
3726 anArgIter += aNbParsed1;
3727 Standard_Integer aNbParsed2 = Draw::ParseColor (theArgNb - (anArgIter + 1),
3728 theArgVec + (anArgIter + 1),
3730 anArgIter += aNbParsed2;
3734 Message::SendFail() << "Error: wrong syntax at '" << anArg << "'";
3738 aColorScale->SetColorRange (aColorMin, aColorMax);
3740 else if (aFlag == "-reversed"
3741 || aFlag == "-inverted"
3742 || aFlag == "-topdown"
3743 || aFlag == "-bottomup")
3745 Standard_Boolean toEnable = Standard_True;
3746 if (anArgIter + 1 < theArgNb
3747 && Draw::ParseOnOff(theArgVec[anArgIter + 1], toEnable))
3751 aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable);
3753 else if (aFlag == "-smooth"
3754 || aFlag == "-smoothtransition")
3756 Standard_Boolean toEnable = Standard_True;
3757 if (anArgIter + 1 < theArgNb
3758 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
3762 aColorScale->SetSmoothTransition (toEnable);
3764 else if (aFlag == "-xy")
3766 if (anArgIter + 2 >= theArgNb)
3768 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
3772 const TCollection_AsciiString anX (theArgVec[++anArgIter]);
3773 const TCollection_AsciiString anY (theArgVec[++anArgIter]);
3774 if (!anX.IsIntegerValue()
3775 || !anY.IsIntegerValue())
3777 Message::SendFail ("Syntax error: coordinates should be integer values");
3781 aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue());
3783 else if (aFlag == "-width"
3785 || aFlag == "-breadth")
3787 if (anArgIter + 1 >= theArgNb)
3789 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
3793 const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]);
3794 if (!aBreadth.IsIntegerValue())
3796 Message::SendFail ("Syntax error: a width should be an integer value");
3799 aColorScale->SetBreadth (aBreadth.IntegerValue());
3801 else if (aFlag == "-height"
3804 if (anArgIter + 1 >= theArgNb)
3806 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
3810 const TCollection_AsciiString aHeight (theArgVec[++anArgIter]);
3811 if (!aHeight.IsIntegerValue())
3813 Message::SendFail ("Syntax error: a width should be an integer value");
3816 aColorScale->SetHeight (aHeight.IntegerValue());
3818 else if (aFlag == "-color")
3820 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
3822 Message::SendFail ("Syntax error: wrong color type. Call -colors before to set user-specified colors");
3825 else if (anArgIter + 2 >= theArgNb)
3827 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
3831 const TCollection_AsciiString anInd (theArgVec[++anArgIter]);
3832 if (!anInd.IsIntegerValue())
3834 Message::SendFail ("Syntax error: Index value should be integer");
3837 const Standard_Integer anIndex = anInd.IntegerValue();
3838 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals())
3840 Message::SendFail() << "Syntax error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals();
3844 Quantity_Color aColor;
3845 Standard_Integer aNbParsed = Draw::ParseColor (theArgNb - (anArgIter + 1),
3846 theArgVec + (anArgIter + 1),
3850 Message::SendFail() << "Error: wrong syntax at '" << anArg << "'";
3853 aColorScale->SetIntervalColor (aColor, anIndex);
3854 aColorScale->SetColorType (Aspect_TOCSD_USER);
3855 anArgIter += aNbParsed;
3857 else if (aFlag == "-label")
3859 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
3861 Message::SendFail ("Syntax error: wrong label type. Call -labels before to set user-specified labels");
3864 else if (anArgIter + 2 >= theArgNb)
3866 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
3870 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
3871 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1)
3873 Message::SendFail() << "Syntax error: Index value should be within range 1.." << (aColorScale->GetNumberOfIntervals() + 1);
3877 TCollection_ExtendedString aText (theArgVec[anArgIter + 2], Standard_True);
3878 aColorScale->SetLabel (aText, anIndex);
3879 aColorScale->SetLabelType (Aspect_TOCSD_USER);
3882 else if (aFlag == "-labelat"
3883 || aFlag == "-labat"
3884 || aFlag == "-labelatborder"
3885 || aFlag == "-labatborder"
3886 || aFlag == "-labelatcenter"
3887 || aFlag == "-labatcenter")
3889 Standard_Boolean toEnable = Standard_True;
3890 if (aFlag == "-labelat"
3891 || aFlag == "-labat")
3893 Standard_Integer aLabAtBorder = -1;
3894 if (++anArgIter >= theArgNb)
3896 TCollection_AsciiString anAtBorder (theArgVec[anArgIter]);
3897 anAtBorder.LowerCase();
3898 if (anAtBorder == "border")
3902 else if (anAtBorder == "center")
3907 if (aLabAtBorder == -1)
3909 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
3912 toEnable = (aLabAtBorder == 1);
3914 else if (anArgIter + 1 < theArgNb
3915 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
3919 aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter"
3920 || aFlag == "-labatcenter"
3924 else if (aFlag == "-colors")
3926 Aspect_SequenceOfColor aSeq;
3929 Quantity_Color aColor;
3930 Standard_Integer aNbParsed = Draw::ParseColor (theArgNb - (anArgIter + 1),
3931 theArgVec + (anArgIter + 1),
3937 anArgIter += aNbParsed;
3938 aSeq.Append (aColor);
3940 if (aSeq.Length() != aColorScale->GetNumberOfIntervals())
3942 Message::SendFail() << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3943 << aColorScale->GetNumberOfIntervals() << " intervals";
3947 aColorScale->SetColors (aSeq);
3948 aColorScale->SetColorType (Aspect_TOCSD_USER);
3950 else if (aFlag == "-uniform")
3952 const Standard_Real aLightness = Draw::Atof (theArgVec[++anArgIter]);
3953 const Standard_Real aHueStart = Draw::Atof (theArgVec[++anArgIter]);
3954 const Standard_Real aHueEnd = Draw::Atof (theArgVec[++anArgIter]);
3955 aColorScale->SetUniformColors (aLightness, aHueStart, aHueEnd);
3956 aColorScale->SetColorType (Aspect_TOCSD_USER);
3958 else if (aFlag == "-labels"
3959 || aFlag == "-freelabels")
3961 if (anArgIter + 1 >= theArgNb)
3963 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
3967 Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder()
3968 ? aColorScale->GetNumberOfIntervals() + 1
3969 : aColorScale->GetNumberOfIntervals();
3970 if (aFlag == "-freelabels")
3973 aNbLabels = Draw::Atoi (theArgVec[anArgIter]);
3975 if (anArgIter + aNbLabels >= theArgNb)
3977 Message::SendFail() << "Syntax error: not enough arguments. " << aNbLabels << " text labels are expected";
3981 TColStd_SequenceOfExtendedString aSeq;
3982 for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter)
3984 aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter], Standard_True));
3986 aColorScale->SetLabels (aSeq);
3987 aColorScale->SetLabelType (Aspect_TOCSD_USER);
3989 else if (aFlag == "-title")
3991 if (anArgIter + 1 >= theArgNb)
3993 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
3997 Standard_Boolean isTwoArgs = Standard_False;
3998 if (anArgIter + 2 < theArgNb)
4000 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
4001 aSecondArg.LowerCase();
4002 Standard_DISABLE_DEPRECATION_WARNINGS
4003 if (aSecondArg == "none")
4005 aColorScale->SetTitlePosition (Aspect_TOCSP_NONE);
4006 isTwoArgs = Standard_True;
4008 else if (aSecondArg == "left")
4010 aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT);
4011 isTwoArgs = Standard_True;
4013 else if (aSecondArg == "right")
4015 aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT);
4016 isTwoArgs = Standard_True;
4018 else if (aSecondArg == "center")
4020 aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER);
4021 isTwoArgs = Standard_True;
4023 Standard_ENABLE_DEPRECATION_WARNINGS
4026 TCollection_ExtendedString aTitle(theArgVec[anArgIter + 1], Standard_True);
4027 aColorScale->SetTitle (aTitle);
4034 else if (aFlag == "-demoversion"
4035 || aFlag == "-demo")
4037 aColorScale->SetPosition (0, 0);
4038 aColorScale->SetTextHeight (16);
4039 aColorScale->SetRange (0.0, 100.0);
4040 aColorScale->SetNumberOfIntervals (10);
4041 aColorScale->SetBreadth (0);
4042 aColorScale->SetHeight (0);
4043 aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT);
4044 aColorScale->SetColorType (Aspect_TOCSD_AUTO);
4045 aColorScale->SetLabelType (Aspect_TOCSD_AUTO);
4047 else if (aFlag == "-findcolor")
4049 if (anArgIter + 1 >= theArgNb)
4051 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
4055 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
4057 if (!anArg1.IsRealValue (Standard_True))
4059 Message::SendFail ("Syntax error: the value should be real");
4063 Quantity_Color aColor;
4064 aColorScale->FindColor (anArg1.RealValue(), aColor);
4065 theDI << Quantity_Color::StringName (aColor.Name());
4070 Message::SendFail() << "Syntax error at " << anArg << " - unknown argument";
4075 Standard_Integer aWinWidth = 0, aWinHeight = 0;
4076 aView->Window()->Size (aWinWidth, aWinHeight);
4077 if (aColorScale->GetBreadth() == 0)
4079 aColorScale->SetBreadth (aWinWidth);
4081 if (aColorScale->GetHeight() == 0)
4083 aColorScale->SetHeight (aWinHeight);
4085 aColorScale->SetToUpdate();
4086 ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True);
4090 //==============================================================================
4091 //function : VGraduatedTrihedron
4092 //purpose : Displays or hides a graduated trihedron
4093 //==============================================================================
4094 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
4095 Quantity_Color& theColor)
4097 Quantity_NameOfColor aColorName;
4098 TCollection_AsciiString aVal = theValue;
4100 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
4102 return Standard_False;
4104 theColor = Quantity_Color (aColorName);
4105 return Standard_True;
4108 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
4112 Message::SendFail() << "Syntax error: wrong number of parameters. Type 'help"
4113 << theArgs[0] <<"' for more information";
4117 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
4118 TCollection_AsciiString aParseKey;
4119 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
4121 TCollection_AsciiString anArg (theArgs [anArgIt]);
4123 if (anArg.Value (1) == '-' && !anArg.IsRealValue (Standard_True))
4126 aParseKey.Remove (1);
4127 aParseKey.LowerCase();
4128 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
4132 if (aParseKey.IsEmpty())
4137 aMapOfArgs(aParseKey)->Append (anArg);
4141 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
4142 aMapIt.More(); aMapIt.Next())
4144 const TCollection_AsciiString& aKey = aMapIt.Key();
4145 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
4147 // Bool key, without arguments
4148 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
4149 && anArgs->IsEmpty())
4155 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
4156 && anArgs->Length() == 1)
4162 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
4163 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
4164 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
4165 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
4166 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
4171 // One string argument
4172 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
4173 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
4174 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue (Standard_True))
4179 // One integer argument
4180 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
4181 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
4182 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
4183 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
4184 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
4189 // One real argument
4190 if ( aKey.IsEqual ("arrowlength")
4191 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue (Standard_True)))
4196 // Two string arguments
4197 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
4198 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue (Standard_True))
4203 TCollection_AsciiString aLowerKey;
4206 aLowerKey.LowerCase();
4207 Message::SendFail() << "Syntax error: " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n"
4208 << "Type help for more information";
4212 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4213 if (anAISContext.IsNull())
4215 Message::SendFail ("Error: no active viewer");
4219 Standard_Boolean toDisplay = Standard_True;
4220 Quantity_Color aColor;
4221 Graphic3d_GraduatedTrihedron aTrihedronData;
4222 // Process parameters
4223 Handle(TColStd_HSequenceOfAsciiString) aValues;
4224 if (aMapOfArgs.Find ("off", aValues))
4226 toDisplay = Standard_False;
4230 if (aMapOfArgs.Find ("xname", aValues))
4232 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
4234 if (aMapOfArgs.Find ("yname", aValues))
4236 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
4238 if (aMapOfArgs.Find ("zname", aValues))
4240 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
4242 if (aMapOfArgs.Find ("xdrawname", aValues))
4244 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4246 if (aMapOfArgs.Find ("ydrawname", aValues))
4248 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4250 if (aMapOfArgs.Find ("zdrawname", aValues))
4252 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4254 if (aMapOfArgs.Find ("xnameoffset", aValues))
4256 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4258 if (aMapOfArgs.Find ("ynameoffset", aValues))
4260 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4262 if (aMapOfArgs.Find ("znameoffset", aValues))
4264 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4268 if (aMapOfArgs.Find ("xnamecolor", aValues))
4270 if (!GetColor (aValues->Value(1), aColor))
4272 Message::SendFail ("Syntax error: -xnamecolor wrong color name");
4275 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
4277 if (aMapOfArgs.Find ("ynamecolor", aValues))
4279 if (!GetColor (aValues->Value(1), aColor))
4281 Message::SendFail ("Syntax error: -ynamecolor wrong color name");
4284 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
4286 if (aMapOfArgs.Find ("znamecolor", aValues))
4288 if (!GetColor (aValues->Value(1), aColor))
4290 Message::SendFail ("Syntax error: -znamecolor wrong color name");
4293 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
4295 if (aMapOfArgs.Find ("xcolor", aValues))
4297 if (!GetColor (aValues->Value(1), aColor))
4299 Message::SendFail ("Syntax error: -xcolor wrong color name");
4302 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
4304 if (aMapOfArgs.Find ("ycolor", aValues))
4306 if (!GetColor (aValues->Value(1), aColor))
4308 Message::SendFail ("Syntax error: -ycolor wrong color name");
4311 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
4313 if (aMapOfArgs.Find ("zcolor", aValues))
4315 if (!GetColor (aValues->Value(1), aColor))
4317 Message::SendFail ("Syntax error: -zcolor wrong color name");
4320 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
4324 if (aMapOfArgs.Find ("xticks", aValues))
4326 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4328 if (aMapOfArgs.Find ("yticks", aValues))
4330 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4332 if (aMapOfArgs.Find ("zticks", aValues))
4334 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4336 if (aMapOfArgs.Find ("xticklength", aValues))
4338 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4340 if (aMapOfArgs.Find ("yticklength", aValues))
4342 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4344 if (aMapOfArgs.Find ("zticklength", aValues))
4346 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4348 if (aMapOfArgs.Find ("xdrawticks", aValues))
4350 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4352 if (aMapOfArgs.Find ("ydrawticks", aValues))
4354 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4356 if (aMapOfArgs.Find ("zdrawticks", aValues))
4358 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4362 if (aMapOfArgs.Find ("xdrawvalues", aValues))
4364 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4366 if (aMapOfArgs.Find ("ydrawvalues", aValues))
4368 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4370 if (aMapOfArgs.Find ("zdrawvalues", aValues))
4372 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4374 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
4376 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4378 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
4380 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4382 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
4384 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4388 if (aMapOfArgs.Find ("arrowlength", aValues))
4390 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
4394 if (aMapOfArgs.Find ("namefont", aValues))
4396 aTrihedronData.SetNamesFont (aValues->Value(1));
4398 if (aMapOfArgs.Find ("valuesfont", aValues))
4400 aTrihedronData.SetValuesFont (aValues->Value(1));
4403 if (aMapOfArgs.Find ("drawgrid", aValues))
4405 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
4407 if (aMapOfArgs.Find ("drawaxes", aValues))
4409 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
4412 // The final step: display of erase trihedron
4415 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
4419 ViewerTest::CurrentView()->GraduatedTrihedronErase();
4422 ViewerTest::GetAISContext()->UpdateCurrentViewer();
4423 ViewerTest::CurrentView()->Redraw();
4428 //==============================================================================
4431 //==============================================================================
4432 static int VTile (Draw_Interpretor& theDI,
4433 Standard_Integer theArgNb,
4434 const char** theArgVec)
4436 Handle(V3d_View) aView = ViewerTest::CurrentView();
4439 Message::SendFail ("Error: no active viewer");
4443 Graphic3d_CameraTile aTile = aView->Camera()->Tile();
4446 theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
4447 << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n"
4448 << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n";
4452 aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
4453 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4455 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4457 if (anArg == "-lowerleft"
4458 || anArg == "-upperleft")
4460 if (anArgIter + 3 < theArgNb)
4462 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
4465 aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
4466 aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4467 aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4469 else if (anArg == "-total"
4470 || anArg == "-totalsize"
4471 || anArg == "-viewsize")
4473 if (anArgIter + 3 < theArgNb)
4475 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
4478 aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4479 aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4480 if (aTile.TotalSize.x() < 1
4481 || aTile.TotalSize.y() < 1)
4483 Message::SendFail ("Error: total size is incorrect");
4487 else if (anArg == "-tilesize")
4489 if (anArgIter + 3 < theArgNb)
4491 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
4495 aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4496 aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4497 if (aTile.TileSize.x() < 1
4498 || aTile.TileSize.y() < 1)
4500 Message::SendFail ("Error: tile size is incorrect");
4504 else if (anArg == "-unset")
4506 aView->Camera()->SetTile (Graphic3d_CameraTile());
4512 if (aTile.TileSize.x() < 1
4513 || aTile.TileSize.y() < 1)
4515 Message::SendFail ("Error: tile size is undefined");
4518 else if (aTile.TotalSize.x() < 1
4519 || aTile.TotalSize.y() < 1)
4521 Message::SendFail ("Error: total size is undefined");
4525 aView->Camera()->SetTile (aTile);
4530 //! Format ZLayer ID.
4531 inline const char* formZLayerId (const Standard_Integer theLayerId)
4535 case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]";
4536 case Graphic3d_ZLayerId_Default: return "[DEFAULT]";
4537 case Graphic3d_ZLayerId_Top: return "[TOP]";
4538 case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]";
4539 case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]";
4540 case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]";
4545 //! Print the ZLayer information.
4546 inline void printZLayerInfo (Draw_Interpretor& theDI,
4547 const Graphic3d_ZLayerSettings& theLayer)
4549 if (!theLayer.Name().IsEmpty())
4551 theDI << " Name: " << theLayer.Name() << "\n";
4553 if (theLayer.IsImmediate())
4555 theDI << " Immediate: TRUE\n";
4557 theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n";
4558 theDI << " Culling distance: " << theLayer.CullingDistance() << "\n";
4559 theDI << " Culling size: " << theLayer.CullingSize() << "\n";
4560 theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n";
4561 theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n";
4562 theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n";
4563 if (theLayer.PolygonOffset().Mode != Aspect_POM_None)
4565 theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n";
4569 //==============================================================================
4570 //function : VZLayer
4571 //purpose : Test z layer operations for v3d viewer
4572 //==============================================================================
4573 static int VZLayer (Draw_Interpretor& theDI,
4574 Standard_Integer theArgNb,
4575 const char** theArgVec)
4577 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4578 if (aContextAIS.IsNull())
4580 Message::SendFail ("Error: no active viewer");
4584 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
4587 TColStd_SequenceOfInteger aLayers;
4588 aViewer->GetAllZLayers (aLayers);
4589 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4591 theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n";
4592 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4593 printZLayerInfo (theDI, aSettings);
4598 Standard_Integer anArgIter = 1;
4599 Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4600 ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView());
4601 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
4607 TCollection_AsciiString aFirstArg (theArgVec[anArgIter]);
4608 if (aFirstArg.IsIntegerValue())
4611 aLayerId = aFirstArg.IntegerValue();
4615 if (ViewerTest::ParseZLayerName (aFirstArg.ToCString(), aLayerId))
4622 Graphic3d_ZLayerId anOtherLayerId = Graphic3d_ZLayerId_UNKNOWN;
4623 for (; anArgIter < theArgNb; ++anArgIter)
4625 // perform operation
4626 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4628 if (anUpdateTool.parseRedrawMode (anArg))
4632 else if (anArg == "-add"
4635 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4636 if (!aViewer->AddZLayer (aLayerId))
4638 Message::SendFail ("Error: can not add a new z layer");
4644 else if (anArg == "-insertbefore"
4645 && anArgIter + 1 < theArgNb
4646 && ViewerTest::ParseZLayer (theArgVec[anArgIter + 1], anOtherLayerId))
4649 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4650 if (!aViewer->InsertLayerBefore (aLayerId, Graphic3d_ZLayerSettings(), anOtherLayerId))
4652 Message::SendFail ("Error: can not add a new z layer");
4658 else if (anArg == "-insertafter"
4659 && anArgIter + 1 < theArgNb
4660 && ViewerTest::ParseZLayer (theArgVec[anArgIter + 1], anOtherLayerId))
4663 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4664 if (!aViewer->InsertLayerAfter (aLayerId, Graphic3d_ZLayerSettings(), anOtherLayerId))
4666 Message::SendFail ("Error: can not add a new z layer");
4672 else if (anArg == "-del"
4673 || anArg == "-delete"
4676 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4678 if (++anArgIter >= theArgNb)
4680 Message::SendFail ("Syntax error: id of z layer to remove is missing");
4684 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4687 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN
4688 || aLayerId == Graphic3d_ZLayerId_Default
4689 || aLayerId == Graphic3d_ZLayerId_Top
4690 || aLayerId == Graphic3d_ZLayerId_Topmost
4691 || aLayerId == Graphic3d_ZLayerId_TopOSD
4692 || aLayerId == Graphic3d_ZLayerId_BotOSD)
4694 Message::SendFail ("Syntax error: standard Z layer can not be removed");
4698 // move all object displayed in removing layer to default layer
4699 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4700 anObjIter.More(); anObjIter.Next())
4702 const Handle(AIS_InteractiveObject)& aPrs = anObjIter.Key1();
4704 || aPrs->ZLayer() != aLayerId)
4708 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4711 if (!aViewer->RemoveZLayer (aLayerId))
4713 Message::SendFail ("Z layer can not be removed");
4717 theDI << aLayerId << " ";
4720 else if (anArg == "-get"
4723 TColStd_SequenceOfInteger aLayers;
4724 aViewer->GetAllZLayers (aLayers);
4725 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4727 theDI << aLayeriter.Value() << " ";
4732 else if (anArg == "-name")
4734 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4736 Message::SendFail ("Syntax error: id of Z layer is missing");
4740 if (++anArgIter >= theArgNb)
4742 Message::SendFail ("Syntax error: name is missing");
4746 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4747 aSettings.SetName (theArgVec[anArgIter]);
4748 aViewer->SetZLayerSettings (aLayerId, aSettings);
4750 else if (anArg == "-origin")
4752 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4754 Message::SendFail ("Syntax error: id of Z layer is missing");
4758 if (anArgIter + 2 >= theArgNb)
4760 Message::SendFail ("Syntax error: origin coordinates are missing");
4764 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4766 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1]));
4767 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2]));
4768 anOrigin.SetZ (0.0);
4769 if (anArgIter + 3 < theArgNb)
4771 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3]));
4778 aSettings.SetOrigin (anOrigin);
4779 aViewer->SetZLayerSettings (aLayerId, aSettings);
4781 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
4782 && anArgIter + 1 < theArgNb
4783 && (anArg == "-cullingdistance"
4784 || anArg == "-cullingdist"
4785 || anArg == "-culldistance"
4786 || anArg == "-culldist"
4787 || anArg == "-distcull"
4788 || anArg == "-distculling"
4789 || anArg == "-distanceculling"))
4791 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4792 const Standard_Real aDist = Draw::Atof (theArgVec[++anArgIter]);
4793 aSettings.SetCullingDistance (aDist);
4794 aViewer->SetZLayerSettings (aLayerId, aSettings);
4796 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
4797 && anArgIter + 1 < theArgNb
4798 && (anArg == "-cullingsize"
4799 || anArg == "-cullsize"
4800 || anArg == "-sizecull"
4801 || anArg == "-sizeculling"))
4803 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4804 const Standard_Real aSize = Draw::Atof (theArgVec[++anArgIter]);
4805 aSettings.SetCullingSize (aSize);
4806 aViewer->SetZLayerSettings (aLayerId, aSettings);
4808 else if (anArg == "-settings"
4809 || anArg == "settings")
4811 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4813 if (++anArgIter >= theArgNb)
4815 Message::SendFail ("Syntax error: id of Z layer is missing");
4819 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4822 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4823 printZLayerInfo (theDI, aSettings);
4825 else if (anArg == "-enable"
4826 || anArg == "enable"
4827 || anArg == "-disable"
4828 || anArg == "disable")
4830 const Standard_Boolean toEnable = anArg == "-enable"
4831 || anArg == "enable";
4832 if (++anArgIter >= theArgNb)
4834 Message::SendFail ("Syntax error: option name is missing");
4838 TCollection_AsciiString aSubOp (theArgVec[anArgIter]);
4840 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4842 if (++anArgIter >= theArgNb)
4844 Message::SendFail ("Syntax error: id of Z layer is missing");
4848 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4851 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4852 if (aSubOp == "depthtest"
4853 || aSubOp == "test")
4855 aSettings.SetEnableDepthTest (toEnable);
4857 else if (aSubOp == "depthwrite"
4858 || aSubOp == "write")
4860 aSettings.SetEnableDepthWrite (toEnable);
4862 else if (aSubOp == "depthclear"
4863 || aSubOp == "clear")
4865 aSettings.SetClearDepth (toEnable);
4867 else if (aSubOp == "depthoffset"
4868 || aSubOp == "offset")
4870 Graphic3d_PolygonOffset aParams;
4871 aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None;
4874 if (anArgIter + 2 >= theArgNb)
4876 Message::SendFail ("Syntax error: factor and units values for depth offset are missing");
4880 aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
4881 aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
4883 aSettings.SetPolygonOffset (aParams);
4885 else if (aSubOp == "positiveoffset"
4886 || aSubOp == "poffset")
4890 aSettings.SetDepthOffsetPositive();
4894 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
4897 else if (aSubOp == "negativeoffset"
4898 || aSubOp == "noffset")
4902 aSettings.SetDepthOffsetNegative();
4906 aSettings.SetPolygonOffset(Graphic3d_PolygonOffset());
4909 else if (aSubOp == "textureenv")
4911 aSettings.SetEnvironmentTexture (toEnable);
4913 else if (aSubOp == "raytracing")
4915 aSettings.SetRaytracable (toEnable);
4918 aViewer->SetZLayerSettings (aLayerId, aSettings);
4922 Message::SendFail() << "Syntax error: unknown option " << theArgVec[anArgIter];
4930 // The interactive presentation of 2d layer item
4931 // for "vlayerline" command it provides a presentation of
4932 // line with user-defined linewidth, linetype and transparency.
4933 class V3d_LineItem : public AIS_InteractiveObject
4937 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
4940 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4941 Standard_Real X2, Standard_Real Y2,
4942 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
4943 Standard_Real theWidth = 0.5,
4944 Standard_Real theTransp = 1.0);
4948 virtual void Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
4949 const Handle(Prs3d_Presentation)& thePrs,
4950 const Standard_Integer theMode) Standard_OVERRIDE;
4952 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& ,
4953 const Standard_Integer ) Standard_OVERRIDE
4958 Standard_Real myX1, myY1, myX2, myY2;
4959 Aspect_TypeOfLine myType;
4960 Standard_Real myWidth;
4963 // default constructor for line item
4964 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4965 Standard_Real X2, Standard_Real Y2,
4966 Aspect_TypeOfLine theType,
4967 Standard_Real theWidth,
4968 Standard_Real theTransp) :
4969 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
4970 myType(theType), myWidth(theWidth)
4972 SetTransparency (1-theTransp);
4976 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager)& ,
4977 const Handle(Prs3d_Presentation)& thePresentation,
4978 const Standard_Integer )
4980 thePresentation->Clear();
4981 Quantity_Color aColor (Quantity_NOC_RED);
4982 Standard_Integer aWidth, aHeight;
4983 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
4984 Handle(Graphic3d_Group) aGroup = thePresentation->CurrentGroup();
4985 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
4986 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
4987 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
4988 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
4989 aGroup->SetPrimitivesAspect (anAspect->Aspect());
4990 aGroup->AddPrimitiveArray (aPrim);
4993 //=============================================================================
4994 //function : VLayerLine
4995 //purpose : Draws line in the v3d view layer with given attributes: linetype,
4996 // : linewidth, transparency coefficient
4997 //============================================================================
4998 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5000 // get the active view
5001 Handle(V3d_View) aView = ViewerTest::CurrentView();
5004 di << "Call vinit before!\n";
5009 di << "Use: " << argv[0];
5010 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
5011 di << " linetype : { 0 | 1 | 2 | 3 } \n";
5012 di << " 0 - solid \n";
5013 di << " 1 - dashed \n";
5014 di << " 2 - dot \n";
5015 di << " 3 - dashdot\n";
5016 di << " transparency : { 0.0 - 1.0 } \n";
5017 di << " 0.0 - transparent\n";
5018 di << " 1.0 - visible \n";
5022 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5023 // get the input params
5024 Standard_Real X1 = Draw::Atof(argv[1]);
5025 Standard_Real Y1 = Draw::Atof(argv[2]);
5026 Standard_Real X2 = Draw::Atof(argv[3]);
5027 Standard_Real Y2 = Draw::Atof(argv[4]);
5029 Standard_Real aWidth = 0.5;
5030 Standard_Real aTransparency = 1.0;
5034 aWidth = Draw::Atof(argv[5]);
5036 // select appropriate line type
5037 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
5039 && !ViewerTest::ParseLineType (argv[6], aLineType))
5041 Message::SendFail() << "Syntax error: unknown line type '" << argv[6] << "'";
5048 aTransparency = Draw::Atof(argv[7]);
5049 if (aTransparency < 0 || aTransparency > 1.0)
5050 aTransparency = 1.0;
5053 static Handle (V3d_LineItem) aLine;
5054 if (!aLine.IsNull())
5056 aContext->Erase (aLine, Standard_False);
5058 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
5062 aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
5063 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
5064 aLine->SetToUpdate();
5065 aContext->Display (aLine, Standard_True);
5071 //==============================================================================
5074 //==============================================================================
5076 static int VGrid (Draw_Interpretor& /*theDI*/,
5077 Standard_Integer theArgNb,
5078 const char** theArgVec)
5080 Handle(V3d_View) aView = ViewerTest::CurrentView();
5081 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5082 if (aView.IsNull() || aViewer.IsNull())
5084 Message::SendFail ("Error: no active viewer");
5088 Aspect_GridType aType = aViewer->GridType();
5089 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
5090 Graphic3d_Vec2d aNewOriginXY, aNewStepXY, aNewSizeXY;
5091 Standard_Real aNewRotAngle = 0.0, aNewZOffset = 0.0;
5092 bool hasOrigin = false, hasStep = false, hasRotAngle = false, hasSize = false, hasZOffset = false;
5093 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
5094 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5096 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5098 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5102 else if (anArgIter + 1 < theArgNb
5103 && anArg == "-type")
5105 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
5106 anArgNext.LowerCase();
5107 if (anArgNext == "r"
5108 || anArgNext == "rect"
5109 || anArgNext == "rectangular")
5111 aType = Aspect_GT_Rectangular;
5113 else if (anArgNext == "c"
5114 || anArgNext == "circ"
5115 || anArgNext == "circular")
5117 aType = Aspect_GT_Circular;
5121 Message::SendFail() << "Syntax error at '" << anArgNext << "'";
5125 else if (anArgIter + 1 < theArgNb
5126 && anArg == "-mode")
5128 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
5129 anArgNext.LowerCase();
5130 if (anArgNext == "l"
5131 || anArgNext == "line"
5132 || anArgNext == "lines")
5134 aMode = Aspect_GDM_Lines;
5136 else if (anArgNext == "p"
5137 || anArgNext == "point"
5138 || anArgNext == "points")
5140 aMode = Aspect_GDM_Points;
5144 Message::SendFail() << "Syntax error at '" << anArgNext << "'";
5148 else if (anArgIter + 2 < theArgNb
5149 && (anArg == "-origin"
5150 || anArg == "-orig"))
5153 aNewOriginXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
5154 Draw::Atof (theArgVec[anArgIter + 2]));
5157 else if (anArgIter + 2 < theArgNb
5158 && anArg == "-step")
5161 aNewStepXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
5162 Draw::Atof (theArgVec[anArgIter + 2]));
5163 if (aNewStepXY.x() <= 0.0
5164 || aNewStepXY.y() <= 0.0)
5166 Message::SendFail() << "Syntax error: wrong step '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'";
5171 else if (anArgIter + 1 < theArgNb
5172 && (anArg == "-angle"
5173 || anArg == "-rotangle"
5174 || anArg == "-rotationangle"))
5177 aNewRotAngle = Draw::Atof (theArgVec[++anArgIter]);
5179 else if (anArgIter + 1 < theArgNb
5180 && (anArg == "-zoffset"
5184 aNewZOffset = Draw::Atof (theArgVec[++anArgIter]);
5186 else if (anArgIter + 1 < theArgNb
5187 && anArg == "-radius")
5191 aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter]), 0.0);
5192 if (aNewStepXY.x() <= 0.0)
5194 Message::SendFail() << "Syntax error: wrong size '" << theArgVec[anArgIter] << "'";
5198 else if (anArgIter + 2 < theArgNb
5199 && anArg == "-size")
5202 aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
5203 Draw::Atof (theArgVec[anArgIter + 2]));
5204 if (aNewStepXY.x() <= 0.0
5205 || aNewStepXY.y() <= 0.0)
5207 Message::SendFail() << "Syntax error: wrong size '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'";
5212 else if (anArg == "r"
5214 || anArg == "rectangular")
5216 aType = Aspect_GT_Rectangular;
5218 else if (anArg == "c"
5220 || anArg == "circular")
5222 aType = Aspect_GT_Circular;
5224 else if (anArg == "l"
5226 || anArg == "lines")
5228 aMode = Aspect_GDM_Lines;
5230 else if (anArg == "p"
5232 || anArg == "points")
5234 aMode = Aspect_GDM_Points;
5236 else if (anArgIter + 1 >= theArgNb
5239 aViewer->DeactivateGrid();
5244 Message::SendFail() << "Syntax error at '" << anArg << "'";
5249 if (aType == Aspect_GT_Rectangular)
5251 Graphic3d_Vec2d anOrigXY, aStepXY;
5252 Standard_Real aRotAngle = 0.0;
5253 aViewer->RectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle);
5256 anOrigXY = aNewOriginXY;
5260 aStepXY = aNewStepXY;
5264 aRotAngle = aNewRotAngle;
5266 aViewer->SetRectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle);
5267 if (hasSize || hasZOffset)
5269 Graphic3d_Vec3d aSize;
5270 aViewer->RectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z());
5273 aSize.x() = aNewSizeXY.x();
5274 aSize.y() = aNewSizeXY.y();
5278 aSize.z() = aNewZOffset;
5280 aViewer->SetRectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z());
5283 else if (aType == Aspect_GT_Circular)
5285 Graphic3d_Vec2d anOrigXY;
5286 Standard_Real aRadiusStep;
5287 Standard_Integer aDivisionNumber;
5288 Standard_Real aRotAngle = 0.0;
5289 aViewer->CircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle);
5292 anOrigXY = aNewOriginXY;
5296 aRadiusStep = aNewStepXY[0];
5297 aDivisionNumber = (int )aNewStepXY[1];
5298 if (aDivisionNumber < 1)
5300 Message::SendFail() << "Syntax error: invalid division number '" << aNewStepXY[1] << "'";
5306 aRotAngle = aNewRotAngle;
5309 aViewer->SetCircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle);
5310 if (hasSize || hasZOffset)
5312 Standard_Real aRadius = 0.0, aZOffset = 0.0;
5313 aViewer->CircularGridGraphicValues (aRadius, aZOffset);
5316 aRadius = aNewSizeXY.x();
5317 if (aNewSizeXY.y() != 0.0)
5319 Message::SendFail ("Syntax error: circular size should be specified as radius");
5325 aZOffset = aNewZOffset;
5327 aViewer->SetCircularGridGraphicValues (aRadius, aZOffset);
5330 aViewer->ActivateGrid (aType, aMode);
5334 //==============================================================================
5335 //function : VPriviledgedPlane
5337 //==============================================================================
5339 static int VPriviledgedPlane (Draw_Interpretor& theDI,
5340 Standard_Integer theArgNb,
5341 const char** theArgVec)
5343 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
5345 Message::SendFail ("Error: wrong number of arguments! See usage:");
5346 theDI.PrintHelp (theArgVec[0]);
5350 // get the active viewer
5351 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5352 if (aViewer.IsNull())
5354 Message::SendFail ("Error: no active viewer");
5360 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
5361 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
5362 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
5363 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
5364 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
5365 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
5366 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
5370 Standard_Integer anArgIdx = 1;
5371 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
5372 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
5373 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
5374 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
5375 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
5376 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
5378 gp_Ax3 aPriviledgedPlane;
5379 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
5380 gp_Dir aNorm (aNormX, aNormY, aNormZ);
5383 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
5384 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
5385 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
5386 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
5387 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
5391 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
5394 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
5399 //==============================================================================
5400 //function : VConvert
5402 //==============================================================================
5404 static int VConvert (Draw_Interpretor& theDI,
5405 Standard_Integer theArgNb,
5406 const char** theArgVec)
5408 // get the active view
5409 Handle(V3d_View) aView = ViewerTest::CurrentView();
5412 Message::SendFail ("Error: no active viewer");
5416 enum { Model, Ray, View, Window, Grid } aMode = Model;
5418 // access coordinate arguments
5419 TColStd_SequenceOfReal aCoord;
5420 Standard_Integer anArgIdx = 1;
5421 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
5423 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5424 if (!anArg.IsRealValue (Standard_True))
5428 aCoord.Append (anArg.RealValue());
5431 // non-numeric argument too early
5432 if (aCoord.IsEmpty())
5434 Message::SendFail ("Error: wrong number of arguments! See usage:");
5435 theDI.PrintHelp (theArgVec[0]);
5439 // collect all other arguments and options
5440 for (; anArgIdx < theArgNb; ++anArgIdx)
5442 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5444 if (anArg == "window") aMode = Window;
5445 else if (anArg == "view") aMode = View;
5446 else if (anArg == "grid") aMode = Grid;
5447 else if (anArg == "ray") aMode = Ray;
5450 Message::SendFail() << "Error: wrong argument " << anArg << "! See usage:";
5451 theDI.PrintHelp (theArgVec[0]);
5456 // complete input checks
5457 if ((aCoord.Length() == 1 && theArgNb > 3) ||
5458 (aCoord.Length() == 2 && theArgNb > 4) ||
5459 (aCoord.Length() == 3 && theArgNb > 5))
5461 Message::SendFail ("Error: wrong number of arguments! See usage:");
5462 theDI.PrintHelp (theArgVec[0]);
5466 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
5467 Standard_Integer aXYp[2] = {0, 0};
5469 // convert one-dimensional coordinate
5470 if (aCoord.Length() == 1)
5474 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0;
5475 case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0;
5477 Message::SendFail ("Error: wrong arguments! See usage:");
5478 theDI.PrintHelp (theArgVec[0]);
5483 // convert 2D coordinates from projection or view reference space
5484 if (aCoord.Length() == 2)
5489 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5490 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5494 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5495 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5499 aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]);
5500 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5504 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5505 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5506 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5510 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5511 (Standard_Integer) aCoord (2),
5512 aXYZ[0], aXYZ[1], aXYZ[2],
5513 aXYZ[3], aXYZ[4], aXYZ[5]);
5514 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5518 Message::SendFail ("Error: wrong arguments! See usage:");
5519 theDI.PrintHelp (theArgVec[0]);
5524 // convert 3D coordinates from view reference space
5525 else if (aCoord.Length() == 3)
5530 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5531 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5535 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5536 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5540 Message::SendFail ("Error: wrong arguments! See usage:");
5541 theDI.PrintHelp (theArgVec[0]);
5549 //==============================================================================
5552 //==============================================================================
5554 static int VFps (Draw_Interpretor& theDI,
5555 Standard_Integer theArgNb,
5556 const char** theArgVec)
5558 // get the active view
5559 Handle(V3d_View) aView = ViewerTest::CurrentView();
5562 Message::SendFail ("Error: no active viewer");
5566 Standard_Integer aFramesNb = -1;
5567 Standard_Real aDuration = -1.0;
5568 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5570 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5573 && anArgIter + 1 < theArgNb
5574 && (anArg == "-duration"
5576 || anArg == "-time"))
5578 aDuration = Draw::Atof (theArgVec[++anArgIter]);
5580 else if (aFramesNb < 0
5581 && anArg.IsIntegerValue())
5583 aFramesNb = anArg.IntegerValue();
5586 Message::SendFail() << "Syntax error at '" << anArg << "'";
5592 Message::SendFail() << "Syntax error at '" << anArg << "'";
5596 if (aFramesNb < 0 && aDuration < 0.0)
5601 // the time is meaningless for first call
5602 // due to async OpenGl rendering
5605 // redraw view in loop to estimate average values
5608 Standard_Integer aFrameIter = 1;
5609 for (;; ++aFrameIter)
5613 && aFrameIter >= aFramesNb)
5615 && aTimer.ElapsedTime() >= aDuration))
5622 const Standard_Real aTime = aTimer.ElapsedTime();
5623 aTimer.OSD_Chronometer::Show (aCpu);
5625 const Standard_Real aFpsAver = Standard_Real(aFrameIter) / aTime;
5626 const Standard_Real aCpuAver = aCpu / Standard_Real(aFrameIter);
5628 // return statistics
5629 theDI << "FPS: " << aFpsAver << "\n"
5630 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5632 // compute additional statistics in ray-tracing mode
5633 const Graphic3d_RenderingParams& aParams = aView->RenderingParams();
5634 if (aParams.Method == Graphic3d_RM_RAYTRACING)
5636 Graphic3d_Vec2i aWinSize (0, 0);
5637 aView->Window()->Size (aWinSize.x(), aWinSize.y());
5639 // 1 shadow ray and 1 secondary ray pew each bounce
5640 const Standard_Real aMRays = aWinSize.x() * aWinSize.y() * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
5641 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
5648 //==============================================================================
5649 //function : VMemGpu
5651 //==============================================================================
5653 static int VMemGpu (Draw_Interpretor& theDI,
5654 Standard_Integer theArgNb,
5655 const char** theArgVec)
5658 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5659 if (aContextAIS.IsNull())
5661 Message::SendFail ("Error: no active viewer");
5665 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
5666 if (aDriver.IsNull())
5668 Message::SendFail ("Error: graphic driver not available");
5672 Standard_Size aFreeBytes = 0;
5673 TCollection_AsciiString anInfo;
5674 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
5676 Message::SendFail ("Error: information not available");
5680 if (theArgNb > 1 && *theArgVec[1] == 'f')
5682 theDI << Standard_Real (aFreeBytes);
5692 // ==============================================================================
5693 // function : VReadPixel
5695 // ==============================================================================
5696 static int VReadPixel (Draw_Interpretor& theDI,
5697 Standard_Integer theArgNb,
5698 const char** theArgVec)
5700 // get the active view
5701 Handle(V3d_View) aView = ViewerTest::CurrentView();
5704 Message::SendFail ("Error: no active viewer");
5707 else if (theArgNb < 3)
5709 Message::SendFail() << "Syntax error: wrong number of arguments.\n"
5710 << "Usage: " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]";
5714 Image_Format aFormat = Image_Format_RGBA;
5715 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
5717 Standard_Integer aWidth, aHeight;
5718 aView->Window()->Size (aWidth, aHeight);
5719 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
5720 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
5721 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
5723 Message::SendFail() << "Error: pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")";
5727 bool toShowName = false, toShowHls = false, toShowHex = false, toShow_sRGB = false;
5728 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
5730 TCollection_AsciiString aParam (theArgVec[anIter]);
5732 if (aParam == "-rgb"
5734 || aParam == "-srgb"
5735 || aParam == "srgb")
5737 aFormat = Image_Format_RGB;
5738 aBufferType = Graphic3d_BT_RGB;
5739 toShow_sRGB = aParam == "-srgb" || aParam == "srgb";
5741 else if (aParam == "-hls"
5744 aFormat = Image_Format_RGB;
5745 aBufferType = Graphic3d_BT_RGB;
5746 toShowHls = Standard_True;
5748 else if (aParam == "-rgbf"
5749 || aParam == "rgbf")
5751 aFormat = Image_Format_RGBF;
5752 aBufferType = Graphic3d_BT_RGB;
5754 else if (aParam == "-rgba"
5756 || aParam == "-srgba"
5757 || aParam == "srgba")
5759 aFormat = Image_Format_RGBA;
5760 aBufferType = Graphic3d_BT_RGBA;
5761 toShow_sRGB = aParam == "-srgba" || aParam == "srgba";
5763 else if (aParam == "-rgbaf"
5764 || aParam == "rgbaf")
5766 aFormat = Image_Format_RGBAF;
5767 aBufferType = Graphic3d_BT_RGBA;
5769 else if (aParam == "-depth"
5770 || aParam == "depth")
5772 aFormat = Image_Format_GrayF;
5773 aBufferType = Graphic3d_BT_Depth;
5775 else if (aParam == "-name"
5776 || aParam == "name")
5778 toShowName = Standard_True;
5780 else if (aParam == "-hex"
5783 toShowHex = Standard_True;
5787 Message::SendFail() << "Syntax error at '" << aParam << "'";
5792 Image_PixMap anImage;
5793 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
5795 Message::SendFail ("Error: image allocation failed");
5798 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
5800 Message::SendFail ("Error: image dump failed");
5804 // redirect possible warning messages that could have been added by ToPixMap
5805 // into the Tcl interpretor (via DefaultMessenger) to cout, so that they do not
5806 // contaminate result of the command
5807 Standard_CString aWarnLog = theDI.Result();
5808 if (aWarnLog != NULL && aWarnLog[0] != '\0')
5810 std::cout << aWarnLog << std::endl;
5814 Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY, true);
5817 if (aBufferType == Graphic3d_BT_RGBA)
5819 theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha();
5823 theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
5828 if (aBufferType == Graphic3d_BT_RGBA)
5830 theDI << Quantity_ColorRGBA::ColorToHex (aColor);
5834 theDI << Quantity_Color::ColorToHex (aColor.GetRGB());
5839 switch (aBufferType)
5842 case Graphic3d_BT_RGB:
5846 theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation();
5848 else if (toShow_sRGB)
5850 const Graphic3d_Vec4 aColor_sRGB = Quantity_ColorRGBA::Convert_LinearRGB_To_sRGB ((Graphic3d_Vec4 )aColor);
5851 theDI << aColor_sRGB.r() << " " << aColor_sRGB.g() << " " << aColor_sRGB.b();
5855 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue();
5859 case Graphic3d_BT_RGBA:
5861 const Graphic3d_Vec4 aVec4 = toShow_sRGB ? Quantity_ColorRGBA::Convert_LinearRGB_To_sRGB ((Graphic3d_Vec4 )aColor) : (Graphic3d_Vec4 )aColor;
5862 theDI << aVec4.r() << " " << aVec4.g() << " " << aVec4.b() << " " << aVec4.a();
5865 case Graphic3d_BT_Depth:
5867 theDI << aColor.GetRGB().Red();
5876 //! Auxiliary presentation for an image plane.
5877 class ViewerTest_ImagePrs : public AIS_InteractiveObject
5880 //! Main constructor.
5881 ViewerTest_ImagePrs (const Handle(Image_PixMap)& theImage,
5882 const Standard_Real theWidth,
5883 const Standard_Real theHeight,
5884 const TCollection_AsciiString& theLabel)
5885 : myLabel (theLabel), myWidth (theWidth), myHeight(theHeight)
5889 myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost);
5891 myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
5892 const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect();
5893 Graphic3d_MaterialAspect aMat;
5894 aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC);
5895 aMat.SetAmbientColor (Quantity_NOC_BLACK);
5896 aMat.SetDiffuseColor (Quantity_NOC_WHITE);
5897 aMat.SetSpecularColor (Quantity_NOC_BLACK);
5898 aMat.SetEmissiveColor (Quantity_NOC_BLACK);
5899 aFillAspect->SetFrontMaterial (aMat);
5900 aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage));
5901 aFillAspect->SetTextureMapOn();
5904 Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect();
5905 aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER);
5906 aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER);
5907 myDrawer->SetTextAspect (aTextAspect);
5910 const gp_Dir aNorm (0.0, 0.0, 1.0);
5911 myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true);
5912 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0));
5913 myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0));
5914 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0));
5915 myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0));
5916 myTris->AddEdge (1);
5917 myTris->AddEdge (2);
5918 myTris->AddEdge (3);
5919 myTris->AddEdge (3);
5920 myTris->AddEdge (2);
5921 myTris->AddEdge (4);
5923 myRect = new Graphic3d_ArrayOfPolylines (4);
5924 myRect->AddVertex (myTris->Vertice (1));
5925 myRect->AddVertex (myTris->Vertice (3));
5926 myRect->AddVertex (myTris->Vertice (4));
5927 myRect->AddVertex (myTris->Vertice (2));
5931 //! Returns TRUE for accepted display modes.
5932 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; }
5934 //! Compute presentation.
5935 virtual void Compute (const Handle(PrsMgr_PresentationManager)& ,
5936 const Handle(Prs3d_Presentation)& thePrs,
5937 const Standard_Integer theMode) Standard_OVERRIDE
5943 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
5944 aGroup->AddPrimitiveArray (myTris);
5945 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
5946 aGroup->AddPrimitiveArray (myRect);
5947 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
5952 Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0));
5953 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
5954 aGroup->AddPrimitiveArray (myRect);
5955 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
5961 //! Compute selection.
5962 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE
5966 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5);
5967 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner);
5968 aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location());
5969 theSel->Add (aSensitive);
5974 Handle(Graphic3d_ArrayOfTriangles) myTris;
5975 Handle(Graphic3d_ArrayOfPolylines) myRect;
5976 TCollection_AsciiString myLabel;
5977 Standard_Real myWidth;
5978 Standard_Real myHeight;
5981 //==============================================================================
5982 //function : VDiffImage
5983 //purpose : The draw-command compares two images.
5984 //==============================================================================
5986 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
5990 Message::SendFail ("Syntax error: not enough arguments");
5994 Standard_Integer anArgIter = 1;
5995 TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]);
5996 TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]);
5997 TCollection_AsciiString aDiffImagePath;
5998 Standard_Real aTolColor = -1.0;
5999 Standard_Integer toBlackWhite = -1;
6000 Standard_Integer isBorderFilterOn = -1;
6001 Standard_Boolean isOldSyntax = Standard_False;
6002 TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff;
6003 for (; anArgIter < theArgNb; ++anArgIter)
6005 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6007 if (anArgIter + 1 < theArgNb
6008 && (anArg == "-toleranceofcolor"
6009 || anArg == "-tolerancecolor"
6010 || anArg == "-tolerance"
6011 || anArg == "-toler"))
6013 aTolColor = Atof (theArgVec[++anArgIter]);
6014 if (aTolColor < 0.0 || aTolColor > 1.0)
6016 Message::SendFail() << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'";
6020 else if (anArg == "-blackwhite")
6022 Standard_Boolean toEnable = Standard_True;
6023 if (anArgIter + 1 < theArgNb
6024 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6028 toBlackWhite = toEnable ? 1 : 0;
6030 else if (anArg == "-borderfilter")
6032 Standard_Boolean toEnable = Standard_True;
6033 if (anArgIter + 1 < theArgNb
6034 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6038 isBorderFilterOn = toEnable ? 1 : 0;
6040 else if (anArg == "-exitonclose")
6042 ViewerTest_EventManager::ToExitOnCloseView() = true;
6043 if (anArgIter + 1 < theArgNb
6044 && Draw::ParseOnOff (theArgVec[anArgIter + 1], ViewerTest_EventManager::ToExitOnCloseView()))
6049 else if (anArg == "-closeonescape"
6050 || anArg == "-closeonesc")
6052 ViewerTest_EventManager::ToCloseViewOnEscape() = true;
6053 if (anArgIter + 1 < theArgNb
6054 && Draw::ParseOnOff (theArgVec[anArgIter + 1], ViewerTest_EventManager::ToCloseViewOnEscape()))
6059 else if (anArgIter + 3 < theArgNb
6060 && anArg == "-display")
6062 aViewName = theArgVec[++anArgIter];
6063 aPrsNameRef = theArgVec[++anArgIter];
6064 aPrsNameNew = theArgVec[++anArgIter];
6065 if (anArgIter + 1 < theArgNb
6066 && *theArgVec[anArgIter + 1] != '-')
6068 aPrsNameDiff = theArgVec[++anArgIter];
6071 else if (aTolColor < 0.0
6072 && anArg.IsRealValue (Standard_True))
6074 isOldSyntax = Standard_True;
6075 aTolColor = anArg.RealValue();
6076 if (aTolColor < 0.0 || aTolColor > 1.0)
6078 Message::SendFail() << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'";
6082 else if (isOldSyntax
6083 && toBlackWhite == -1
6084 && (anArg == "0" || anArg == "1"))
6086 toBlackWhite = anArg == "1" ? 1 : 0;
6088 else if (isOldSyntax
6089 && isBorderFilterOn == -1
6090 && (anArg == "0" || anArg == "1"))
6092 isBorderFilterOn = anArg == "1" ? 1 : 0;
6094 else if (aDiffImagePath.IsEmpty())
6096 aDiffImagePath = theArgVec[anArgIter];
6100 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
6105 Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap();
6106 Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap();
6107 if (!anImgRef->Load (anImgPathRef))
6109 Message::SendFail() << "Error: image file '" << anImgPathRef << "' cannot be read";
6112 if (!anImgNew->Load (anImgPathNew))
6114 Message::SendFail() << "Error: image file '" << anImgPathNew << "' cannot be read";
6118 // compare the images
6119 Image_Diff aComparer;
6120 Standard_Integer aDiffColorsNb = -1;
6121 if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1))
6123 aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0);
6124 aComparer.SetBorderFilterOn (isBorderFilterOn == 1);
6125 aDiffColorsNb = aComparer.Compare();
6126 theDI << aDiffColorsNb << "\n";
6129 // save image of difference
6130 Handle(Image_AlienPixMap) aDiff;
6131 if (aDiffColorsNb > 0
6132 && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty()))
6134 aDiff = new Image_AlienPixMap();
6135 if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY()))
6137 Message::SendFail() << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY();
6140 aComparer.SaveDiffImage (*aDiff);
6141 if (!aDiffImagePath.IsEmpty()
6142 && !aDiff->Save (aDiffImagePath))
6144 Message::SendFail() << "Error: diff image file '" << aDiffImagePath << "' cannot be written";
6149 if (aViewName.IsEmpty())
6154 ViewerTest_Names aViewNames (aViewName);
6155 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
6157 TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName();
6158 theDI.Eval (aCommand.ToCString());
6161 Standard_Integer aPxLeft = 0;
6162 Standard_Integer aPxTop = 0;
6163 Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2);
6164 Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty()
6165 ? int(anImgRef->SizeY() * 2)
6166 : int(anImgRef->SizeY());
6167 TCollection_AsciiString aDisplayName;
6168 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aWinSizeX, aWinSizeY,
6169 aViewName, aDisplayName);
6171 Standard_Real aRatio = anImgRef->Ratio();
6172 Standard_Real aSizeX = 1.0;
6173 Standard_Real aSizeY = aSizeX / aRatio;
6175 OSD_Path aPath (anImgPathRef);
6176 TCollection_AsciiString aLabelRef;
6177 if (!aPath.Name().IsEmpty())
6179 aLabelRef = aPath.Name() + aPath.Extension();
6181 aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY());
6183 Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef);
6185 aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0));
6186 anImgRefPrs->SetLocalTransformation (aTrsfRef);
6187 ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true);
6190 OSD_Path aPath (anImgPathNew);
6191 TCollection_AsciiString aLabelNew;
6192 if (!aPath.Name().IsEmpty())
6194 aLabelNew = aPath.Name() + aPath.Extension();
6196 aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY());
6198 Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew);
6200 aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0));
6201 anImgNewPrs->SetLocalTransformation (aTrsfRef);
6202 ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true);
6204 Handle(ViewerTest_ImagePrs) anImgDiffPrs;
6205 if (!aDiff.IsNull())
6207 anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels");
6209 aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0));
6210 anImgDiffPrs->SetLocalTransformation (aTrsfDiff);
6212 if (!aPrsNameDiff.IsEmpty())
6214 ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true);
6216 ViewerTest::CurrentView()->SetProj (V3d_Zpos);
6217 ViewerTest::CurrentView()->FitAll();
6221 //=======================================================================
6222 //function : VSelect
6223 //purpose : Emulates different types of selection by mouse:
6224 // 1) single click selection
6225 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
6226 // 3) selection with polygon having corners at
6227 // pixel positions (x1,y1),...,(xn,yn)
6228 // 4) any of these selections with shift button pressed
6229 //=======================================================================
6230 static Standard_Integer VSelect (Draw_Interpretor& ,
6231 Standard_Integer theNbArgs,
6232 const char** theArgVec)
6234 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
6237 Message::SendFail ("Error: no active viewer");
6241 NCollection_Sequence<Graphic3d_Vec2i> aPnts;
6242 bool toAllowOverlap = false;
6243 AIS_SelectionScheme aSelScheme = AIS_SelectionScheme_Replace;
6244 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
6246 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6248 if (anArg == "-allowoverlap")
6250 toAllowOverlap = true;
6251 if (anArgIter + 1 < theNbArgs
6252 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toAllowOverlap))
6257 else if (anArg == "-replace")
6259 aSelScheme = AIS_SelectionScheme_Replace;
6261 else if (anArg == "-replaceextra")
6263 aSelScheme = AIS_SelectionScheme_ReplaceExtra;
6265 else if (anArg == "-xor"
6266 || anArg == "-shift")
6268 aSelScheme = AIS_SelectionScheme_XOR;
6270 else if (anArg == "-add")
6272 aSelScheme = AIS_SelectionScheme_Add;
6274 else if (anArg == "-remove")
6276 aSelScheme = AIS_SelectionScheme_Remove;
6278 else if (anArgIter + 1 < theNbArgs
6279 && anArg.IsIntegerValue()
6280 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue())
6282 const TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
6283 aPnts.Append (Graphic3d_Vec2i (anArg.IntegerValue(), anArgNext.IntegerValue()));
6285 else if (anArgIter + 1 == theNbArgs
6286 && anArg.IsIntegerValue())
6288 if (anArg.IntegerValue() == 1)
6290 aSelScheme = AIS_SelectionScheme_XOR;
6295 Message::SendFail() << "Syntax error at '" << anArg << "'";
6302 aCtx->MainSelector()->AllowOverlapDetection (toAllowOverlap);
6305 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
6306 if (aPnts.IsEmpty())
6308 aCtx->SelectDetected (aSelScheme);
6309 aCtx->CurrentViewer()->Invalidate();
6311 else if (aPnts.Length() == 2)
6314 && aPnts.First().y() < aPnts.Last().y())
6316 std::swap (aPnts.ChangeFirst(), aPnts.ChangeLast());
6318 else if (!toAllowOverlap
6319 && aPnts.First().y() > aPnts.Last().y())
6321 std::swap (aPnts.ChangeFirst(), aPnts.ChangeLast());
6324 aCurrentEventManager->SelectInViewer (aPnts, aSelScheme);
6328 aCurrentEventManager->SelectInViewer (aPnts, aSelScheme);
6330 aCurrentEventManager->FlushViewEvents (aCtx, ViewerTest::CurrentView(), true);
6334 //=======================================================================
6335 //function : VMoveTo
6336 //purpose : Emulates cursor movement to defined pixel position
6337 //=======================================================================
6338 static Standard_Integer VMoveTo (Draw_Interpretor& theDI,
6339 Standard_Integer theNbArgs,
6340 const char** theArgVec)
6342 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
6343 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
6344 if (aContext.IsNull())
6346 Message::SendFail ("Error: no active viewer");
6350 Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast());
6351 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
6353 TCollection_AsciiString anArgStr (theArgVec[anArgIter]);
6354 anArgStr.LowerCase();
6355 if (anArgStr == "-reset"
6356 || anArgStr == "-clear")
6358 if (anArgIter + 1 < theNbArgs)
6360 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter + 1] << "'";
6364 const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->IsGridActive()
6365 && aContext->CurrentViewer()->GridEcho();
6368 aContext->CurrentViewer()->HideGridEcho (aView);
6370 if (aContext->ClearDetected() || toEchoGrid)
6372 aContext->CurrentViewer()->RedrawImmediate();
6376 else if (aMousePos.x() == IntegerLast()
6377 && anArgStr.IsIntegerValue())
6379 aMousePos.x() = anArgStr.IntegerValue();
6381 else if (aMousePos.y() == IntegerLast()
6382 && anArgStr.IsIntegerValue())
6384 aMousePos.y() = anArgStr.IntegerValue();
6388 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
6393 if (aMousePos.x() == IntegerLast()
6394 || aMousePos.y() == IntegerLast())
6396 Message::SendFail ("Syntax error: wrong number of arguments");
6400 ViewerTest::CurrentEventManager()->ResetPreviousMoveTo();
6401 ViewerTest::CurrentEventManager()->UpdateMousePosition (aMousePos, Aspect_VKeyMouse_NONE, Aspect_VKeyFlags_NONE, false);
6402 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true);
6404 gp_Pnt aTopPnt (RealLast(), RealLast(), RealLast());
6405 const Handle(SelectMgr_EntityOwner)& aDetOwner = aContext->DetectedOwner();
6406 for (Standard_Integer aDetIter = 1; aDetIter <= aContext->MainSelector()->NbPicked(); ++aDetIter)
6408 if (aContext->MainSelector()->Picked (aDetIter) == aDetOwner)
6410 aTopPnt = aContext->MainSelector()->PickedPoint (aDetIter);
6414 theDI << aTopPnt.X() << " " << aTopPnt.Y() << " " << aTopPnt.Z();
6418 //=======================================================================
6419 //function : VSelectByAxis
6421 //=======================================================================
6422 static Standard_Integer VSelectByAxis (Draw_Interpretor& theDI,
6423 Standard_Integer theNbArgs,
6424 const char** theArgVec)
6426 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
6427 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
6428 if (aContext.IsNull())
6430 Message::SendFail ("Error: no active viewer");
6434 TCollection_AsciiString aName;
6435 gp_XYZ anAxisLocation(RealLast(), RealLast(), RealLast());
6436 gp_XYZ anAxisDirection(RealLast(), RealLast(), RealLast());
6437 Standard_Boolean isOnlyTop = true;
6438 Standard_Boolean toShowNormal = false;
6439 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
6441 TCollection_AsciiString anArgStr (theArgVec[anArgIter]);
6442 anArgStr.LowerCase();
6443 if (anArgStr == "-display")
6445 if (anArgIter + 1 >= theNbArgs)
6447 Message::SendFail() << "Syntax error at argument '" << anArgStr << "'";
6450 aName = theArgVec[++anArgIter];
6452 else if (anArgStr == "-onlytop")
6455 if (anArgIter + 1 < theNbArgs
6456 && Draw::ParseOnOff (theArgVec[anArgIter + 1], isOnlyTop))
6461 else if (anArgStr == "-shownormal")
6463 toShowNormal = true;
6464 if (anArgIter + 1 < theNbArgs
6465 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toShowNormal))
6470 else if (Precision::IsInfinite(anAxisLocation.X())
6471 && anArgStr.IsRealValue())
6473 anAxisLocation.SetX (anArgStr.RealValue());
6475 else if (Precision::IsInfinite(anAxisLocation.Y())
6476 && anArgStr.IsRealValue())
6478 anAxisLocation.SetY (anArgStr.RealValue());
6480 else if (Precision::IsInfinite(anAxisLocation.Z())
6481 && anArgStr.IsRealValue())
6483 anAxisLocation.SetZ (anArgStr.RealValue());
6485 else if (Precision::IsInfinite(anAxisDirection.X())
6486 && anArgStr.IsRealValue())
6488 anAxisDirection.SetX (anArgStr.RealValue());
6490 else if (Precision::IsInfinite(anAxisDirection.Y())
6491 && anArgStr.IsRealValue())
6493 anAxisDirection.SetY (anArgStr.RealValue());
6495 else if (Precision::IsInfinite(anAxisDirection.Z())
6496 && anArgStr.IsRealValue())
6498 anAxisDirection.SetZ (anArgStr.RealValue());
6502 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
6507 if (Precision::IsInfinite (anAxisLocation.X()) ||
6508 Precision::IsInfinite (anAxisLocation.Y()) ||
6509 Precision::IsInfinite (anAxisLocation.Z()) ||
6510 Precision::IsInfinite (anAxisDirection.X()) ||
6511 Precision::IsInfinite (anAxisDirection.Y()) ||
6512 Precision::IsInfinite (anAxisDirection.Z()))
6514 Message::SendFail() << "Invalid axis location and direction";
6518 gp_Ax1 anAxis(anAxisLocation, anAxisDirection);
6520 if (!ViewerTest::CurrentEventManager()->PickAxis (aTopPnt, aContext, aView, anAxis))
6522 theDI << "There are no any intersections with this axis.";
6525 NCollection_Sequence<gp_Pnt> aPoints;
6526 NCollection_Sequence<Graphic3d_Vec3> aNormals;
6527 NCollection_Sequence<Standard_Real> aNormalLengths;
6528 for (Standard_Integer aPickIter = 1; aPickIter <= aContext->MainSelector()->NbPicked(); ++aPickIter)
6530 const SelectMgr_SortCriterion& aPickedData = aContext->MainSelector()->PickedData (aPickIter);
6531 aPoints.Append (aPickedData.Point);
6532 aNormals.Append (aPickedData.Normal);
6533 Standard_Real aNormalLength = 1.0;
6534 if (!aPickedData.Entity.IsNull())
6536 aNormalLength = 0.2 * aPickedData.Entity->BoundingBox().Size().maxComp();
6538 aNormalLengths.Append (aNormalLength);
6540 if (!aName.IsEmpty())
6542 Standard_Boolean wasAuto = aContext->GetAutoActivateSelection();
6543 aContext->SetAutoActivateSelection (false);
6546 Quantity_Color anAxisColor = Quantity_NOC_GREEN;
6547 Handle(Geom_Axis2Placement) anAx2Axis =
6548 new Geom_Axis2Placement (gp_Ax2(anAxisLocation, anAxisDirection));
6549 Handle(AIS_Axis) anAISAxis = new AIS_Axis (gp_Ax1 (anAxisLocation, anAxisDirection));
6550 anAISAxis->SetColor (anAxisColor);
6551 ViewerTest::Display (TCollection_AsciiString (aName) + "_axis", anAISAxis, false);
6553 // Display axis start point
6554 Handle(AIS_Point) anAISStartPnt = new AIS_Point (new Geom_CartesianPoint (anAxisLocation));
6555 anAISStartPnt->SetMarker (Aspect_TOM_O);
6556 anAISStartPnt->SetColor (anAxisColor);
6557 ViewerTest::Display (TCollection_AsciiString(aName) + "_start", anAISStartPnt, false);
6559 Standard_Integer anIndex = 0;
6560 for (NCollection_Sequence<gp_Pnt>::Iterator aPntIter(aPoints); aPntIter.More(); aPntIter.Next(), anIndex++)
6562 const gp_Pnt& aPoint = aPntIter.Value();
6564 // Display normals in intersection points
6567 const Graphic3d_Vec3& aNormal = aNormals.Value (anIndex + 1);
6568 Standard_Real aNormalLength = aNormalLengths.Value (anIndex + 1);
6569 if (aNormal.SquareModulus() > ShortRealEpsilon())
6571 gp_Dir aNormalDir ((Standard_Real)aNormal.x(), (Standard_Real)aNormal.y(), (Standard_Real)aNormal.z());
6572 Handle(AIS_Axis) anAISNormal = new AIS_Axis (gp_Ax1 (aPoint, aNormalDir), aNormalLength);
6573 anAISNormal->SetColor (Quantity_NOC_BLUE);
6574 anAISNormal->SetInfiniteState (false);
6575 ViewerTest::Display (TCollection_AsciiString(aName) + "_normal_" + anIndex, anAISNormal, false);
6579 // Display intersection points
6580 Handle(Geom_CartesianPoint) anIntersectPnt = new Geom_CartesianPoint (aPoint);
6581 Handle(AIS_Point) anAISIntersectPoint = new AIS_Point (anIntersectPnt);
6582 anAISIntersectPoint->SetMarker (Aspect_TOM_PLUS);
6583 anAISIntersectPoint->SetColor (Quantity_NOC_RED);
6584 ViewerTest::Display (TCollection_AsciiString(aName) + "_intersect_" + anIndex, anAISIntersectPoint, true);
6587 aContext->SetAutoActivateSelection (wasAuto);
6590 Standard_Integer anIndex = 0;
6591 for (NCollection_Sequence<gp_Pnt>::Iterator anIter(aPoints); anIter.More(); anIter.Next(), anIndex++)
6593 const gp_Pnt& aPnt = anIter.Value();
6594 theDI << aPnt.X() << " " << aPnt.Y() << " " << aPnt.Z() << "\n";
6601 //! Global map storing all animations registered in ViewerTest.
6602 static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap;
6604 //! The animation calling the Draw Harness command.
6605 class ViewerTest_AnimationProc : public AIS_Animation
6607 DEFINE_STANDARD_RTTI_INLINE(ViewerTest_AnimationProc, AIS_Animation)
6610 //! Main constructor.
6611 ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName,
6612 Draw_Interpretor* theDI,
6613 const TCollection_AsciiString& theCommand)
6614 : AIS_Animation (theAnimationName),
6616 myCommand (theCommand)
6623 //! Evaluate the command.
6624 virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE
6626 TCollection_AsciiString aCmd = myCommand;
6627 replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts));
6628 replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts));
6629 replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts));
6630 replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized));
6631 replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized));
6632 myDrawInter->Eval (aCmd.ToCString());
6635 //! Find the keyword in the command and replace it with value.
6636 //! @return the position of the keyword to pass value
6637 void replace (TCollection_AsciiString& theCmd,
6638 const TCollection_AsciiString& theKey,
6639 const TCollection_AsciiString& theVal)
6641 TCollection_AsciiString aCmd (theCmd);
6643 const Standard_Integer aPos = aCmd.Search (theKey);
6649 TCollection_AsciiString aPart1, aPart2;
6650 Standard_Integer aPart1To = aPos - 1;
6652 && aPart1To <= theCmd.Length())
6654 aPart1 = theCmd.SubString (1, aPart1To);
6657 Standard_Integer aPart2From = aPos + theKey.Length();
6659 && aPart2From <= theCmd.Length())
6661 aPart2 = theCmd.SubString (aPart2From, theCmd.Length());
6664 theCmd = aPart1 + theVal + aPart2;
6669 Draw_Interpretor* myDrawInter;
6670 TCollection_AsciiString myCommand;
6674 //! Auxiliary animation holder.
6675 class ViewerTest_AnimationHolder : public AIS_AnimationCamera
6677 DEFINE_STANDARD_RTTI_INLINE(ViewerTest_AnimationHolder, AIS_AnimationCamera)
6679 ViewerTest_AnimationHolder (const Handle(AIS_Animation)& theAnim,
6680 const Handle(V3d_View)& theView,
6681 const Standard_Boolean theIsFreeView)
6682 : AIS_AnimationCamera ("ViewerTest_AnimationHolder", Handle(V3d_View)())
6684 if (theAnim->Timer().IsNull())
6686 theAnim->SetTimer (new Media_Timer());
6688 myTimer = theAnim->Timer();
6692 myCamStart = new Graphic3d_Camera (theView->Camera());
6698 virtual void StartTimer (const Standard_Real theStartPts,
6699 const Standard_Real thePlaySpeed,
6700 const Standard_Boolean theToUpdate,
6701 const Standard_Boolean theToStopTimer) Standard_OVERRIDE
6703 base_type::StartTimer (theStartPts, thePlaySpeed, theToUpdate, theToStopTimer);
6710 //! Pause animation.
6711 virtual void Pause() Standard_OVERRIDE
6713 myState = AnimationState_Paused;
6714 // default implementation would stop all children,
6715 // but we want to keep wrapped animation paused
6716 myAnimations.First()->Pause();
6721 virtual void Stop() Standard_OVERRIDE
6727 //! Process one step of the animation according to the input time progress, including all children.
6728 virtual void updateWithChildren (const AIS_AnimationProgress& thePosition) Standard_OVERRIDE
6730 Handle(V3d_View) aView = myView;
6732 && !myCamStart.IsNull())
6734 myCamStart->Copy (aView->Camera());
6736 base_type::updateWithChildren (thePosition);
6738 && !myCamStart.IsNull())
6740 aView->Camera()->Copy (myCamStart);
6744 void abortPlayback()
6746 if (!myView.IsNull())
6753 //! Replace the animation with the new one.
6754 static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation,
6755 Handle(AIS_Animation)& theAnimation,
6756 const Handle(AIS_Animation)& theAnimationNew)
6758 theAnimationNew->CopyFrom (theAnimation);
6759 if (!theParentAnimation.IsNull())
6761 theParentAnimation->Replace (theAnimation, theAnimationNew);
6765 ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name());
6766 ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew);
6768 theAnimation = theAnimationNew;
6771 //! Parse the point.
6772 static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
6774 const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
6775 if (!anXYZ[0].IsRealValue (Standard_True)
6776 || !anXYZ[1].IsRealValue (Standard_True)
6777 || !anXYZ[2].IsRealValue (Standard_True))
6779 return Standard_False;
6782 thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue());
6783 return Standard_True;
6786 //! Parse the quaternion.
6787 static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
6789 const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
6790 if (!anXYZW[0].IsRealValue (Standard_True)
6791 || !anXYZW[1].IsRealValue (Standard_True)
6792 || !anXYZW[2].IsRealValue (Standard_True)
6793 || !anXYZW[3].IsRealValue (Standard_True))
6795 return Standard_False;
6798 theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue());
6799 return Standard_True;
6802 //! Auxiliary class for flipping image upside-down.
6807 //! Empty constructor.
6808 ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {}
6810 //! Perform flipping.
6811 Standard_Boolean FlipY (Image_PixMap& theImage)
6813 if (theImage.IsEmpty()
6814 || theImage.SizeX() == 0
6815 || theImage.SizeY() == 0)
6817 return Standard_False;
6820 const Standard_Size aRowSize = theImage.SizeRowBytes();
6821 if (myTmp.Size() < aRowSize
6822 && !myTmp.Allocate (aRowSize))
6824 return Standard_False;
6827 // for odd height middle row should be left as is
6828 Standard_Size aNbRowsHalf = theImage.SizeY() / 2;
6829 for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB)
6831 Standard_Byte* aTop = theImage.ChangeRow (aRowT);
6832 Standard_Byte* aBot = theImage.ChangeRow (aRowB);
6833 memcpy (myTmp.ChangeData(), aTop, aRowSize);
6834 memcpy (aTop, aBot, aRowSize);
6835 memcpy (aBot, myTmp.Data(), aRowSize);
6837 return Standard_True;
6841 NCollection_Buffer myTmp;
6846 //=================================================================================================
6847 //function : VViewParams
6848 //purpose : Gets or sets AIS View characteristics
6849 //=================================================================================================
6850 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6852 Handle(V3d_View) aView = ViewerTest::CurrentView();
6855 Message::SendFail ("Error: no active viewer");
6859 Standard_Boolean toSetProj = Standard_False;
6860 Standard_Boolean toSetUp = Standard_False;
6861 Standard_Boolean toSetAt = Standard_False;
6862 Standard_Boolean toSetEye = Standard_False;
6863 Standard_Boolean toSetScale = Standard_False;
6864 Standard_Boolean toSetSize = Standard_False;
6865 Standard_Boolean toSetCenter2d = Standard_False;
6866 Standard_Real aViewScale = aView->Scale();
6867 Standard_Real aViewAspect = aView->Camera()->Aspect();
6868 Standard_Real aViewSize = 1.0;
6869 Graphic3d_Vec2i aCenter2d;
6870 gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
6871 aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3));
6872 aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
6873 aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
6874 aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
6875 const Graphic3d_Mat4d& anOrientMat = aView->Camera()->OrientationMatrix();
6876 const Graphic3d_Mat4d& aProjMat = aView->Camera()->ProjectionMatrix();
6879 // print all of the available view parameters
6884 "Proj: %12g %12g %12g\n"
6885 "Up: %12g %12g %12g\n"
6886 "At: %12g %12g %12g\n"
6887 "Eye: %12g %12g %12g\n"
6888 "OrientMat: %12g %12g %12g %12g\n"
6889 " %12g %12g %12g %12g\n"
6890 " %12g %12g %12g %12g\n"
6891 " %12g %12g %12g %12g\n"
6892 "ProjMat: %12g %12g %12g %12g\n"
6893 " %12g %12g %12g %12g\n"
6894 " %12g %12g %12g %12g\n"
6895 " %12g %12g %12g %12g\n",
6896 aViewScale, aViewAspect,
6897 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
6898 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
6899 aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
6900 aViewEye.X(), aViewEye.Y(), aViewEye.Z(),
6901 anOrientMat.GetValue (0, 0), anOrientMat.GetValue (0, 1), anOrientMat.GetValue (0, 2), anOrientMat.GetValue (0, 3),
6902 anOrientMat.GetValue (1, 0), anOrientMat.GetValue (1, 1), anOrientMat.GetValue (1, 2), anOrientMat.GetValue (1, 3),
6903 anOrientMat.GetValue (2, 0), anOrientMat.GetValue (2, 1), anOrientMat.GetValue (2, 2), anOrientMat.GetValue (2, 3),
6904 anOrientMat.GetValue (3, 0), anOrientMat.GetValue (3, 1), anOrientMat.GetValue (3, 2), anOrientMat.GetValue (3, 3),
6905 aProjMat.GetValue (0, 0), aProjMat.GetValue (0, 1), aProjMat.GetValue (0, 2), aProjMat.GetValue (0, 3),
6906 aProjMat.GetValue (1, 0), aProjMat.GetValue (1, 1), aProjMat.GetValue (1, 2), aProjMat.GetValue (1, 3),
6907 aProjMat.GetValue (2, 0), aProjMat.GetValue (2, 1), aProjMat.GetValue (2, 2), aProjMat.GetValue (2, 3),
6908 aProjMat.GetValue (3, 0), aProjMat.GetValue (3, 1), aProjMat.GetValue (3, 2), aProjMat.GetValue (3, 3));
6913 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
6914 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
6916 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6918 if (anUpdateTool.parseRedrawMode (anArg))
6922 else if (anArg == "-cmd"
6923 || anArg == "-command"
6924 || anArg == "-args")
6933 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
6934 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
6935 aViewAt.X(), aViewAt.Y(), aViewAt.Z());
6938 else if (anArg == "-scale"
6939 || anArg == "-size")
6941 if (anArgIter + 1 < theArgsNb
6942 && *theArgVec[anArgIter + 1] != '-')
6944 const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
6945 if (aValueArg.IsRealValue (Standard_True))
6948 if (anArg == "-scale")
6950 toSetScale = Standard_True;
6951 aViewScale = aValueArg.RealValue();
6953 else if (anArg == "-size")
6955 toSetSize = Standard_True;
6956 aViewSize = aValueArg.RealValue();
6961 if (anArg == "-scale")
6963 theDi << "Scale: " << aView->Scale() << "\n";
6965 else if (anArg == "-size")
6967 Graphic3d_Vec2d aSizeXY;
6968 aView->Size (aSizeXY.x(), aSizeXY.y());
6969 theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n";
6972 else if (anArg == "-eye"
6975 || anArg == "-proj")
6977 if (anArgIter + 3 < theArgsNb)
6980 if (parseXYZ (theArgVec + anArgIter + 1, anXYZ))
6983 if (anArg == "-eye")
6985 toSetEye = Standard_True;
6988 else if (anArg == "-at")
6990 toSetAt = Standard_True;
6993 else if (anArg == "-up")
6995 toSetUp = Standard_True;
6998 else if (anArg == "-proj")
7000 toSetProj = Standard_True;
7007 if (anArg == "-eye")
7009 theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n";
7011 else if (anArg == "-at")
7013 theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n";
7015 else if (anArg == "-up")
7017 theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n";
7019 else if (anArg == "-proj")
7021 theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n";
7024 else if (anArg == "-center")
7026 if (anArgIter + 2 < theArgsNb)
7028 const TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
7029 const TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
7030 if (anX.IsIntegerValue()
7031 && anY.IsIntegerValue())
7033 toSetCenter2d = Standard_True;
7034 aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue());
7040 Message::SendFail() << "Syntax error at '" << anArg << "'";
7045 // change view parameters in proper order
7048 aView->SetScale (aViewScale);
7052 aView->SetSize (aViewSize);
7056 aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z());
7060 aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z());
7064 aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z());
7068 aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z());
7072 aView->SetCenter (aCenter2d.x(), aCenter2d.y());
7078 //==============================================================================
7079 //function : V2DMode
7081 //==============================================================================
7082 static Standard_Integer V2DMode (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec)
7084 bool is2dMode = true;
7085 Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView());
7086 if (aV3dView.IsNull())
7088 Message::SendFail ("Error: no active viewer");
7091 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
7093 const TCollection_AsciiString anArg = theArgVec[anArgIt];
7094 TCollection_AsciiString anArgCase = anArg;
7095 anArgCase.LowerCase();
7096 if (anArgIt + 1 < theArgsNb
7097 && anArgCase == "-name")
7099 ViewerTest_Names aViewNames (theArgVec[++anArgIt]);
7100 TCollection_AsciiString aViewName = aViewNames.GetViewName();
7101 if (!ViewerTest_myViews.IsBound1 (aViewName))
7103 Message::SendFail() << "Syntax error: unknown view '" << theArgVec[anArgIt - 1] << "'";
7106 aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest_myViews.Find1 (aViewName));
7108 else if (anArgCase == "-mode")
7110 if (anArgIt + 1 < theArgsNb
7111 && Draw::ParseOnOff (theArgVec[anArgIt + 1], is2dMode))
7116 else if (Draw::ParseOnOff (theArgVec[anArgIt], is2dMode))
7122 Message::SendFail() << "Syntax error: unknown argument " << anArg;
7127 aV3dView->SetView2DMode (is2dMode);
7131 //==============================================================================
7132 //function : VAnimation
7134 //==============================================================================
7135 static Standard_Integer VAnimation (Draw_Interpretor& theDI,
7136 Standard_Integer theArgNb,
7137 const char** theArgVec)
7139 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
7142 for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator
7143 anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next())
7145 theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n";
7151 Message::SendFail ("Error: no active viewer");
7155 Standard_Integer anArgIter = 1;
7156 TCollection_AsciiString aNameArg (theArgVec[anArgIter++]);
7157 if (aNameArg.IsEmpty())
7159 Message::SendFail ("Syntax error: animation name is not defined");
7163 TCollection_AsciiString aNameArgLower = aNameArg;
7164 aNameArgLower.LowerCase();
7165 if (aNameArgLower == "-reset"
7166 || aNameArgLower == "-clear")
7168 ViewerTest_AnimationTimelineMap.Clear();
7171 else if (aNameArg.Value (1) == '-')
7173 Message::SendFail() << "Syntax error: invalid animation name '" << aNameArg << "'";
7177 const char* aNameSplitter = "/";
7178 Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter);
7179 if (aSplitPos == -1)
7181 aNameSplitter = ".";
7182 aSplitPos = aNameArg.Search (aNameSplitter);
7185 // find existing or create a new animation by specified name within syntax "parent.child".
7186 Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation;
7187 for (; !aNameArg.IsEmpty();)
7189 TCollection_AsciiString aNameParent;
7190 if (aSplitPos != -1)
7192 if (aSplitPos == aNameArg.Length())
7194 Message::SendFail ("Syntax error: animation name is not defined");
7198 aNameParent = aNameArg.SubString ( 1, aSplitPos - 1);
7199 aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length());
7201 aSplitPos = aNameArg.Search (aNameSplitter);
7205 aNameParent = aNameArg;
7209 if (anAnimation.IsNull())
7211 if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation))
7213 anAnimation = new AIS_Animation (aNameParent);
7214 ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation);
7216 aRootAnimation = anAnimation;
7220 aParentAnimation = anAnimation;
7221 anAnimation = aParentAnimation->Find (aNameParent);
7222 if (anAnimation.IsNull())
7224 anAnimation = new AIS_Animation (aNameParent);
7225 aParentAnimation->Add (anAnimation);
7229 if (anAnimation.IsNull())
7231 Message::SendFail() << "Syntax error: wrong number of arguments";
7235 if (anArgIter >= theArgNb)
7237 // just print the list of children
7238 for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next())
7240 theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n";
7245 // animation parameters
7246 Standard_Boolean toPlay = Standard_False;
7247 Standard_Real aPlaySpeed = 1.0;
7248 Standard_Real aPlayStartTime = anAnimation->StartPts();
7249 Standard_Real aPlayDuration = anAnimation->Duration();
7250 Standard_Boolean isFreeCamera = Standard_False;
7251 Standard_Boolean toPauseOnClick = Standard_True;
7252 Standard_Boolean isLockLoop = Standard_False;
7254 // video recording parameters
7255 TCollection_AsciiString aRecFile;
7256 Image_VideoParams aRecParams;
7258 Handle(V3d_View) aView = ViewerTest::CurrentView();
7259 for (; anArgIter < theArgNb; ++anArgIter)
7261 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7264 if (anArg == "-reset"
7265 || anArg == "-clear")
7267 anAnimation->Clear();
7269 else if (anArg == "-remove"
7271 || anArg == "-delete")
7273 if (aParentAnimation.IsNull())
7275 ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name());
7279 aParentAnimation->Remove (anAnimation);
7283 else if (anArg == "-play")
7285 toPlay = Standard_True;
7286 if (++anArgIter < theArgNb)
7288 if (*theArgVec[anArgIter] == '-')
7293 aPlayStartTime = Draw::Atof (theArgVec[anArgIter]);
7295 if (++anArgIter < theArgNb)
7297 if (*theArgVec[anArgIter] == '-')
7302 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
7306 else if (anArg == "-resume")
7308 toPlay = Standard_True;
7309 aPlayStartTime = anAnimation->ElapsedTime();
7310 if (++anArgIter < theArgNb)
7312 if (*theArgVec[anArgIter] == '-')
7318 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
7321 else if (anArg == "-pause")
7323 anAnimation->Pause();
7325 else if (anArg == "-stop")
7327 anAnimation->Stop();
7329 else if (anArg == "-playspeed"
7330 || anArg == "-speed")
7332 if (++anArgIter >= theArgNb)
7334 Message::SendFail() << "Syntax error at " << anArg << "";
7337 aPlaySpeed = Draw::Atof (theArgVec[anArgIter]);
7339 else if (anArg == "-lock"
7340 || anArg == "-lockloop"
7341 || anArg == "-playlockloop")
7343 isLockLoop = Draw::ParseOnOffIterator (theArgNb, theArgVec, anArgIter);
7345 else if (anArg == "-freecamera"
7346 || anArg == "-nofreecamera"
7347 || anArg == "-playfreecamera"
7348 || anArg == "-noplayfreecamera"
7349 || anArg == "-freelook"
7350 || anArg == "-nofreelook")
7352 isFreeCamera = Draw::ParseOnOffNoIterator (theArgNb, theArgVec, anArgIter);
7354 else if (anArg == "-pauseonclick"
7355 || anArg == "-nopauseonclick"
7356 || anArg == "-nopause")
7358 toPauseOnClick = Draw::ParseOnOffNoIterator (theArgNb, theArgVec, anArgIter);
7360 // video recodring options
7361 else if (anArg == "-rec"
7362 || anArg == "-record")
7364 if (++anArgIter >= theArgNb)
7366 Message::SendFail() << "Syntax error at " << anArg;
7370 aRecFile = theArgVec[anArgIter];
7371 if (aRecParams.FpsNum <= 0)
7373 aRecParams.FpsNum = 24;
7376 if (anArgIter + 2 < theArgNb
7377 && *theArgVec[anArgIter + 1] != '-'
7378 && *theArgVec[anArgIter + 2] != '-')
7380 TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]);
7381 TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]);
7382 if (aWidthArg .IsIntegerValue()
7383 && aHeightArg.IsIntegerValue())
7385 aRecParams.Width = aWidthArg .IntegerValue();
7386 aRecParams.Height = aHeightArg.IntegerValue();
7391 else if (anArg == "-fps")
7393 if (++anArgIter >= theArgNb)
7395 Message::SendFail() << "Syntax error at " << anArg;
7399 TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
7400 Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
7401 if (aSplitIndex == 0)
7403 aRecParams.FpsNum = aFpsArg.IntegerValue();
7407 const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
7408 aFpsArg.Split (aFpsArg.Length() - 1);
7409 const TCollection_AsciiString aNumStr = aFpsArg;
7410 aRecParams.FpsNum = aNumStr.IntegerValue();
7411 aRecParams.FpsDen = aDenStr.IntegerValue();
7412 if (aRecParams.FpsDen < 1)
7414 Message::SendFail() << "Syntax error at " << anArg;
7419 else if (anArg == "-format")
7421 if (++anArgIter >= theArgNb)
7423 Message::SendFail() << "Syntax error at " << anArg;
7426 aRecParams.Format = theArgVec[anArgIter];
7428 else if (anArg == "-pix_fmt"
7429 || anArg == "-pixfmt"
7430 || anArg == "-pixelformat")
7432 if (++anArgIter >= theArgNb)
7434 Message::SendFail() << "Syntax error at " << anArg;
7437 aRecParams.PixelFormat = theArgVec[anArgIter];
7439 else if (anArg == "-codec"
7440 || anArg == "-vcodec"
7441 || anArg == "-videocodec")
7443 if (++anArgIter >= theArgNb)
7445 Message::SendFail() << "Syntax error at " << anArg;
7448 aRecParams.VideoCodec = theArgVec[anArgIter];
7450 else if (anArg == "-crf"
7451 || anArg == "-preset"
7454 const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length());
7455 if (++anArgIter >= theArgNb)
7457 Message::SendFail() << "Syntax error at " << anArg;
7461 aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]);
7463 // animation definition options
7464 else if (anArg == "-start"
7465 || anArg == "-starttime"
7466 || anArg == "-startpts")
7468 if (++anArgIter >= theArgNb)
7470 Message::SendFail() << "Syntax error at " << anArg;
7474 anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter]));
7475 aRootAnimation->UpdateTotalDuration();
7477 else if (anArg == "-end"
7478 || anArg == "-endtime"
7479 || anArg == "-endpts")
7481 if (++anArgIter >= theArgNb)
7483 Message::SendFail() << "Syntax error at " << anArg;
7487 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts());
7488 aRootAnimation->UpdateTotalDuration();
7490 else if (anArg == "-dur"
7491 || anArg == "-duration")
7493 if (++anArgIter >= theArgNb)
7495 Message::SendFail() << "Syntax error at " << anArg;
7499 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]));
7500 aRootAnimation->UpdateTotalDuration();
7502 else if (anArg == "-command"
7504 || anArg == "-invoke"
7506 || anArg == "-proc")
7508 if (++anArgIter >= theArgNb)
7510 Message::SendFail() << "Syntax error at " << anArg;
7514 Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]);
7515 replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation);
7517 else if (anArg == "-objecttrsf"
7518 || anArg == "-objectransformation"
7519 || anArg == "-objtransformation"
7520 || anArg == "-objtrsf"
7521 || anArg == "-object"
7524 if (++anArgIter >= theArgNb)
7526 Message::SendFail() << "Syntax error at " << anArg;
7530 TCollection_AsciiString anObjName (theArgVec[anArgIter]);
7531 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS();
7532 Handle(AIS_InteractiveObject) anObject;
7533 if (!aMapOfAIS.Find2 (anObjName, anObject))
7535 Message::SendFail() << "Syntax error: wrong object name at " << anArg;
7539 gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() };
7540 gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() };
7541 gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
7542 Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
7543 Standard_Boolean isTrsfSet = Standard_False;
7544 Standard_Integer aTrsfArgIter = anArgIter + 1;
7545 for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
7547 TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]);
7548 aTrsfArg.LowerCase();
7549 const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1;
7550 if (aTrsfArg.StartsWith ("-rotation")
7551 || aTrsfArg.StartsWith ("-rot"))
7553 isTrsfSet = Standard_True;
7554 if (aTrsfArgIter + 4 >= theArgNb
7555 || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex]))
7557 Message::SendFail() << "Syntax error at " << aTrsfArg;
7562 else if (aTrsfArg.StartsWith ("-location")
7563 || aTrsfArg.StartsWith ("-loc"))
7565 isTrsfSet = Standard_True;
7566 if (aTrsfArgIter + 3 >= theArgNb
7567 || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex]))
7569 Message::SendFail() << "Syntax error at " << aTrsfArg;
7574 else if (aTrsfArg.StartsWith ("-scale"))
7576 isTrsfSet = Standard_True;
7577 if (++aTrsfArgIter >= theArgNb)
7579 Message::SendFail() << "Syntax error at " << aTrsfArg;
7583 const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
7584 if (!aScaleStr.IsRealValue (Standard_True))
7586 Message::SendFail() << "Syntax error at " << aTrsfArg;
7589 aScales[anIndex] = aScaleStr.RealValue();
7593 anArgIter = aTrsfArgIter - 1;
7599 Message::SendFail() << "Syntax error at " << anArg;
7602 else if (aTrsfArgIter >= theArgNb)
7604 anArgIter = theArgNb;
7607 aTrsfs[0].SetRotation (aRotQuats[0]);
7608 aTrsfs[1].SetRotation (aRotQuats[1]);
7609 aTrsfs[0].SetTranslationPart (aLocPnts[0]);
7610 aTrsfs[1].SetTranslationPart (aLocPnts[1]);
7611 aTrsfs[0].SetScaleFactor (aScales[0]);
7612 aTrsfs[1].SetScaleFactor (aScales[1]);
7614 Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
7615 replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
7617 else if (anArg == "-viewtrsf"
7618 || anArg == "-view")
7620 Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation);
7621 if (aCamAnimation.IsNull())
7623 aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView);
7624 replaceAnimation (aParentAnimation, anAnimation, aCamAnimation);
7627 Handle(Graphic3d_Camera) aCams[2] =
7629 new Graphic3d_Camera (aCamAnimation->View()->Camera()),
7630 new Graphic3d_Camera (aCamAnimation->View()->Camera())
7633 Standard_Boolean isTrsfSet = Standard_False;
7634 Standard_Integer aViewArgIter = anArgIter + 1;
7635 for (; aViewArgIter < theArgNb; ++aViewArgIter)
7637 TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]);
7638 aViewArg.LowerCase();
7639 const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1;
7640 if (aViewArg.StartsWith ("-scale"))
7642 isTrsfSet = Standard_True;
7643 if (++aViewArgIter >= theArgNb)
7645 Message::SendFail() << "Syntax error at " << anArg;
7649 const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
7650 if (!aScaleStr.IsRealValue (Standard_True))
7652 Message::SendFail() << "Syntax error at " << aViewArg;
7655 Standard_Real aScale = aScaleStr.RealValue();
7656 aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale;
7657 aCams[anIndex]->SetScale (aScale);
7659 else if (aViewArg.StartsWith ("-eye")
7660 || aViewArg.StartsWith ("-center")
7661 || aViewArg.StartsWith ("-at")
7662 || aViewArg.StartsWith ("-up"))
7664 isTrsfSet = Standard_True;
7666 if (aViewArgIter + 3 >= theArgNb
7667 || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ))
7669 Message::SendFail() << "Syntax error at " << aViewArg;
7674 if (aViewArg.StartsWith ("-eye"))
7676 aCams[anIndex]->SetEye (anXYZ);
7678 else if (aViewArg.StartsWith ("-center")
7679 || aViewArg.StartsWith ("-at"))
7681 aCams[anIndex]->SetCenter (anXYZ);
7683 else if (aViewArg.StartsWith ("-up"))
7685 aCams[anIndex]->SetUp (anXYZ);
7690 anArgIter = aViewArgIter - 1;
7696 Message::SendFail() << "Syntax error at " << anArg;
7699 else if (aViewArgIter >= theArgNb)
7701 anArgIter = theArgNb;
7704 aCamAnimation->SetCameraStart(aCams[0]);
7705 aCamAnimation->SetCameraEnd (aCams[1]);
7709 Message::SendFail() << "Syntax error at " << anArg;
7714 ViewerTest::CurrentEventManager()->AbortViewAnimation();
7715 ViewerTest::CurrentEventManager()->SetObjectsAnimation (Handle(AIS_Animation)());
7716 if (!toPlay && aRecFile.IsEmpty())
7721 // Start animation timeline and process frame updating.
7722 if (aRecParams.FpsNum <= 0
7725 Handle(ViewerTest_AnimationHolder) aHolder = new ViewerTest_AnimationHolder (anAnimation, aView, isFreeCamera);
7726 aHolder->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
7727 ViewerTest::CurrentEventManager()->SetPauseObjectsAnimation (toPauseOnClick);
7728 ViewerTest::CurrentEventManager()->SetObjectsAnimation (aHolder);
7729 ViewerTest::CurrentEventManager()->ProcessExpose();
7733 // Perform video recording
7734 const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
7735 const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
7736 anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
7738 OSD_Timer aPerfTimer;
7741 Handle(Image_VideoRecorder) aRecorder;
7742 ImageFlipper aFlipper;
7743 Handle(Draw_ProgressIndicator) aProgress;
7744 if (!aRecFile.IsEmpty())
7746 if (aRecParams.Width <= 0
7747 || aRecParams.Height <= 0)
7749 aView->Window()->Size (aRecParams.Width, aRecParams.Height);
7752 aRecorder = new Image_VideoRecorder();
7753 if (!aRecorder->Open (aRecFile.ToCString(), aRecParams))
7755 Message::SendFail ("Error: failed to open video file for recording");
7759 aProgress = new Draw_ProgressIndicator (theDI, 1);
7762 // Manage frame-rated animation here
7763 Standard_Real aPts = aPlayStartTime;
7764 int64_t aNbFrames = 0;
7765 Message_ProgressScope aPS(Message_ProgressIndicator::Start(aProgress),
7766 "Video recording, sec", Max(1, Standard_Integer(aPlayDuration / aPlaySpeed)));
7767 Standard_Integer aSecondsProgress = 0;
7768 for (; aPts <= anUpperPts && aPS.More();)
7770 Standard_Real aRecPts = 0.0;
7771 if (aRecParams.FpsNum > 0)
7773 aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames));
7777 aRecPts = aPlaySpeed * aPerfTimer.ElapsedTime();
7780 aPts = aPlayStartTime + aRecPts;
7782 if (!anAnimation->Update (aPts))
7787 if (!aRecorder.IsNull())
7789 V3d_ImageDumpOptions aDumpParams;
7790 aDumpParams.Width = aRecParams.Width;
7791 aDumpParams.Height = aRecParams.Height;
7792 aDumpParams.BufferType = Graphic3d_BT_RGBA;
7793 aDumpParams.StereoOptions = V3d_SDO_MONO;
7794 aDumpParams.ToAdjustAspect = Standard_True;
7795 if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams))
7797 Message::SendFail ("Error: view dump is failed");
7800 aFlipper.FlipY (aRecorder->ChangeFrame());
7801 if (!aRecorder->PushFrame())
7811 while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed))
7819 anAnimation->Stop();
7820 const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
7821 theDI << "Average FPS: " << aRecFps << "\n"
7822 << "Nb. Frames: " << Standard_Real(aNbFrames);
7825 aView->SetImmediateUpdate (wasImmediateUpdate);
7830 //=======================================================================
7831 //function : VChangeSelected
7832 //purpose : Adds the shape to selection or remove one from it
7833 //=======================================================================
7834 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
7835 Standard_Integer argc,
7840 di<<"Usage : " << argv[0] << " shape \n";
7844 TCollection_AsciiString aName(argv[1]);
7845 Handle(AIS_InteractiveObject) anAISObject;
7846 if (!GetMapOfAIS().Find2 (aName, anAISObject)
7847 || anAISObject.IsNull())
7849 di<<"Use 'vdisplay' before";
7853 ViewerTest::GetAISContext()->AddOrRemoveSelected(anAISObject, Standard_True);
7857 //=======================================================================
7858 //function : VNbSelected
7859 //purpose : Returns number of selected objects
7860 //=======================================================================
7861 static Standard_Integer VNbSelected (Draw_Interpretor& di,
7862 Standard_Integer argc,
7867 di << "Usage : " << argv[0] << "\n";
7870 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7871 if(aContext.IsNull())
7873 di << "use 'vinit' command before " << argv[0] << "\n";
7876 di << aContext->NbSelected() << "\n";
7880 //=======================================================================
7881 //function : VSetViewSize
7883 //=======================================================================
7884 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
7885 Standard_Integer argc,
7888 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7889 if(aContext.IsNull())
7891 di << "use 'vinit' command before " << argv[0] << "\n";
7896 di<<"Usage : " << argv[0] << " Size\n";
7899 Standard_Real aSize = Draw::Atof (argv[1]);
7902 di<<"Bad Size value : " << aSize << "\n";
7906 Handle(V3d_View) aView = ViewerTest::CurrentView();
7907 aView->SetSize(aSize);
7911 //=======================================================================
7912 //function : VMoveView
7914 //=======================================================================
7915 static Standard_Integer VMoveView (Draw_Interpretor& di,
7916 Standard_Integer argc,
7919 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7920 if(aContext.IsNull())
7922 di << "use 'vinit' command before " << argv[0] << "\n";
7925 if(argc < 4 || argc > 5)
7927 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
7930 Standard_Real Dx = Draw::Atof (argv[1]);
7931 Standard_Real Dy = Draw::Atof (argv[2]);
7932 Standard_Real Dz = Draw::Atof (argv[3]);
7933 Standard_Boolean aStart = Standard_True;
7936 aStart = (Draw::Atoi (argv[4]) > 0);
7939 Handle(V3d_View) aView = ViewerTest::CurrentView();
7940 aView->Move(Dx,Dy,Dz,aStart);
7944 //=======================================================================
7945 //function : VTranslateView
7947 //=======================================================================
7948 static Standard_Integer VTranslateView (Draw_Interpretor& di,
7949 Standard_Integer argc,
7952 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7953 if(aContext.IsNull())
7955 di << "use 'vinit' command before " << argv[0] << "\n";
7958 if(argc < 4 || argc > 5)
7960 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
7963 Standard_Real Dx = Draw::Atof (argv[1]);
7964 Standard_Real Dy = Draw::Atof (argv[2]);
7965 Standard_Real Dz = Draw::Atof (argv[3]);
7966 Standard_Boolean aStart = Standard_True;
7969 aStart = (Draw::Atoi (argv[4]) > 0);
7972 Handle(V3d_View) aView = ViewerTest::CurrentView();
7973 aView->Translate(Dx,Dy,Dz,aStart);
7977 //=======================================================================
7978 //function : VTurnView
7980 //=======================================================================
7981 static Standard_Integer VTurnView (Draw_Interpretor& di,
7982 Standard_Integer argc,
7985 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7986 if(aContext.IsNull()) {
7987 di << "use 'vinit' command before " << argv[0] << "\n";
7990 if(argc < 4 || argc > 5){
7991 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
7994 Standard_Real Ax = Draw::Atof (argv[1]);
7995 Standard_Real Ay = Draw::Atof (argv[2]);
7996 Standard_Real Az = Draw::Atof (argv[3]);
7997 Standard_Boolean aStart = Standard_True;
8000 aStart = (Draw::Atoi (argv[4]) > 0);
8003 Handle(V3d_View) aView = ViewerTest::CurrentView();
8004 aView->Turn(Ax,Ay,Az,aStart);
8008 //==============================================================================
8009 //function : VTextureEnv
8010 //purpose : ENables or disables environment mapping
8011 //==============================================================================
8012 class OCC_TextureEnv : public Graphic3d_TextureEnv
8015 OCC_TextureEnv(const Standard_CString FileName);
8016 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
8017 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
8018 const Standard_Boolean theModulateFlag,
8019 const Graphic3d_TypeOfTextureFilter theFilter,
8020 const Standard_ShortReal theXScale,
8021 const Standard_ShortReal theYScale,
8022 const Standard_ShortReal theXShift,
8023 const Standard_ShortReal theYShift,
8024 const Standard_ShortReal theAngle);
8025 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
8027 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
8029 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
8030 : Graphic3d_TextureEnv(theFileName)
8034 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
8035 : Graphic3d_TextureEnv(theTexId)
8039 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
8040 const Standard_Boolean theModulateFlag,
8041 const Graphic3d_TypeOfTextureFilter theFilter,
8042 const Standard_ShortReal theXScale,
8043 const Standard_ShortReal theYScale,
8044 const Standard_ShortReal theXShift,
8045 const Standard_ShortReal theYShift,
8046 const Standard_ShortReal theAngle)
8048 myParams->SetRepeat (theRepeatFlag);
8049 myParams->SetModulate (theModulateFlag);
8050 myParams->SetFilter (theFilter);
8051 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
8052 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
8053 myParams->SetRotation (theAngle);
8056 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
8058 // get the active view
8059 Handle(V3d_View) aView = ViewerTest::CurrentView();
8062 Message::SendFail ("Error: no active viewer");
8066 // Checking the input arguments
8067 Standard_Boolean anEnableFlag = Standard_False;
8068 Standard_Boolean isOk = theArgNb >= 2;
8071 TCollection_AsciiString anEnableOpt(theArgVec[1]);
8072 anEnableFlag = anEnableOpt.IsEqual("on");
8073 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
8077 isOk = (theArgNb == 3 || theArgNb == 11);
8080 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8081 isOk = (!aTextureOpt.IsIntegerValue() ||
8082 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
8084 if (isOk && theArgNb == 11)
8086 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
8087 aModulateOpt(theArgVec[4]),
8088 aFilterOpt (theArgVec[5]),
8089 aSScaleOpt (theArgVec[6]),
8090 aTScaleOpt (theArgVec[7]),
8091 aSTransOpt (theArgVec[8]),
8092 aTTransOpt (theArgVec[9]),
8093 anAngleOpt (theArgVec[10]);
8094 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
8095 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
8096 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
8097 aSScaleOpt.IsRealValue (Standard_True) && aTScaleOpt.IsRealValue (Standard_True) &&
8098 aSTransOpt.IsRealValue (Standard_True) && aTTransOpt.IsRealValue (Standard_True) &&
8099 anAngleOpt.IsRealValue (Standard_True));
8106 Message::SendFail() << "Usage:\n"
8107 << theArgVec[0] << " off\n"
8108 << 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]";
8114 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8115 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
8116 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
8117 new OCC_TextureEnv(theArgVec[2]);
8121 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
8122 aTexEnv->SetTextureParameters(
8123 aRepeatOpt. IsEqual("repeat"),
8124 aModulateOpt.IsEqual("modulate"),
8125 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
8126 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
8127 Graphic3d_TOTF_TRILINEAR,
8128 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
8129 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
8130 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
8131 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
8132 (Standard_ShortReal)Draw::Atof(theArgVec[10])
8135 aView->SetTextureEnv(aTexEnv);
8137 else // Disabling environment mapping
8139 Handle(Graphic3d_TextureEnv) aTexture;
8140 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
8149 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
8151 //! Remove registered clipping plane from all views and objects.
8152 static void removePlane (MapOfPlanes& theRegPlanes,
8153 const TCollection_AsciiString& theName)
8155 Handle(Graphic3d_ClipPlane) aClipPlane;
8156 if (!theRegPlanes.Find (theName, aClipPlane))
8158 Message::SendWarning ("Warning: no such plane");
8162 theRegPlanes.UnBind (theName);
8163 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
8164 anIObjIt.More(); anIObjIt.Next())
8166 const Handle(AIS_InteractiveObject)& aPrs = anIObjIt.Key1();
8167 aPrs->RemoveClipPlane (aClipPlane);
8170 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
8171 aViewIt.More(); aViewIt.Next())
8173 const Handle(V3d_View)& aView = aViewIt.Key2();
8174 aView->RemoveClipPlane(aClipPlane);
8177 ViewerTest::RedrawAllViews();
8181 //===============================================================================================
8182 //function : VClipPlane
8184 //===============================================================================================
8185 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8187 // use short-cut for created clip planes map of created (or "registered by name") clip planes
8188 static MapOfPlanes aRegPlanes;
8192 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
8194 theDi << aPlaneIter.Key() << " ";
8199 TCollection_AsciiString aCommand (theArgVec[1]);
8200 aCommand.LowerCase();
8201 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
8202 if (anActiveView.IsNull())
8204 Message::SendFail ("Error: no active viewer");
8208 // print maximum number of planes for current viewer
8209 if (aCommand == "-maxplanes"
8210 || aCommand == "maxplanes")
8212 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
8213 << " plane slots provided by driver.\n";
8217 // create / delete plane instance
8218 if (aCommand == "-create"
8219 || aCommand == "create"
8220 || aCommand == "-delete"
8221 || aCommand == "delete"
8222 || aCommand == "-clone"
8223 || aCommand == "clone")
8227 Message::SendFail ("Syntax error: plane name is required");
8231 Standard_Boolean toCreate = aCommand == "-create"
8232 || aCommand == "create";
8233 Standard_Boolean toClone = aCommand == "-clone"
8234 || aCommand == "clone";
8235 Standard_Boolean toDelete = aCommand == "-delete"
8236 || aCommand == "delete";
8237 TCollection_AsciiString aPlane (theArgVec[2]);
8241 if (aRegPlanes.IsBound (aPlane))
8243 std::cout << "Warning: existing plane has been overridden.\n";
8248 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8252 else if (toClone) // toClone
8254 if (!aRegPlanes.IsBound (aPlane))
8256 Message::SendFail ("Error: no such plane");
8259 else if (theArgsNb < 4)
8261 Message::SendFail ("Syntax error: enter name for new plane");
8265 TCollection_AsciiString aClone (theArgVec[3]);
8266 if (aRegPlanes.IsBound (aClone))
8268 Message::SendFail ("Error: plane name is in use");
8272 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
8274 aRegPlanes.Bind (aClone, aClipPlane->Clone());
8284 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
8286 aPlane = aPlaneIter.Key();
8287 removePlane (aRegPlanes, aPlane);
8288 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
8293 removePlane (aRegPlanes, aPlane);
8299 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8304 // set / unset plane command
8305 if (aCommand == "set"
8306 || aCommand == "unset")
8310 Message::SendFail ("Syntax error: need more arguments");
8314 // redirect to new syntax
8315 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
8316 anArgVec.SetValue (1, theArgVec[0]);
8317 anArgVec.SetValue (2, theArgVec[2]);
8318 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
8319 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
8321 anArgVec.SetValue (anIt, theArgVec[anIt]);
8324 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
8327 // change plane command
8328 TCollection_AsciiString aPlaneName;
8329 Handle(Graphic3d_ClipPlane) aClipPlane;
8330 Standard_Integer anArgIter = 0;
8331 if (aCommand == "-change"
8332 || aCommand == "change")
8334 // old syntax support
8337 Message::SendFail ("Syntax error: need more arguments");
8342 aPlaneName = theArgVec[2];
8343 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
8345 Message::SendFail() << "Error: no such plane '" << aPlaneName << "'";
8349 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
8352 aPlaneName = theArgVec[1];
8357 aPlaneName = theArgVec[1];
8358 aClipPlane = new Graphic3d_ClipPlane();
8359 aRegPlanes.Bind (aPlaneName, aClipPlane);
8360 theDi << "Created new plane " << aPlaneName << ".\n";
8363 if (theArgsNb - anArgIter < 1)
8365 Message::SendFail ("Syntax error: need more arguments");
8369 for (; anArgIter < theArgsNb; ++anArgIter)
8371 const char** aChangeArgs = theArgVec + anArgIter;
8372 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
8373 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
8374 aChangeArg.LowerCase();
8376 Standard_Boolean toEnable = Standard_True;
8377 if (Draw::ParseOnOff (aChangeArgs[0], toEnable))
8379 aClipPlane->SetOn (toEnable);
8381 else if (aChangeArg.StartsWith ("-equation")
8382 || aChangeArg.StartsWith ("equation"))
8384 if (aNbChangeArgs < 5)
8386 Message::SendFail ("Syntax error: need more arguments");
8390 Standard_Integer aSubIndex = 1;
8391 Standard_Integer aPrefixLen = 8 + (aChangeArg.Value (1) == '-' ? 1 : 0);
8392 if (aPrefixLen < aChangeArg.Length())
8394 TCollection_AsciiString aSubStr = aChangeArg.SubString (aPrefixLen + 1, aChangeArg.Length());
8395 if (!aSubStr.IsIntegerValue()
8396 || aSubStr.IntegerValue() <= 0)
8398 Message::SendFail() << "Syntax error: unknown argument '" << aChangeArg << "'";
8401 aSubIndex = aSubStr.IntegerValue();
8404 Standard_Real aCoeffA = Draw::Atof (aChangeArgs[1]);
8405 Standard_Real aCoeffB = Draw::Atof (aChangeArgs[2]);
8406 Standard_Real aCoeffC = Draw::Atof (aChangeArgs[3]);
8407 Standard_Real aCoeffD = Draw::Atof (aChangeArgs[4]);
8408 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
8409 for (Standard_Integer aSubPlaneIter = 1; aSubPlaneIter < aSubIndex; ++aSubPlaneIter)
8411 if (aSubPln->ChainNextPlane().IsNull())
8413 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
8415 aSubPln = aSubPln->ChainNextPlane();
8417 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
8418 aSubPln->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
8421 else if ((aChangeArg == "-boxinterior"
8422 || aChangeArg == "-boxint"
8423 || aChangeArg == "-box")
8424 && aNbChangeArgs >= 7)
8426 Graphic3d_BndBox3d aBndBox;
8427 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[1]), Draw::Atof (aChangeArgs[2]), Draw::Atof (aChangeArgs[3])));
8428 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[4]), Draw::Atof (aChangeArgs[5]), Draw::Atof (aChangeArgs[6])));
8431 Standard_Integer aNbSubPlanes = 6;
8432 const Graphic3d_Vec3d aDirArray[6] =
8434 Graphic3d_Vec3d (-1, 0, 0),
8435 Graphic3d_Vec3d ( 1, 0, 0),
8436 Graphic3d_Vec3d ( 0,-1, 0),
8437 Graphic3d_Vec3d ( 0, 1, 0),
8438 Graphic3d_Vec3d ( 0, 0,-1),
8439 Graphic3d_Vec3d ( 0, 0, 1),
8441 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
8442 for (Standard_Integer aSubPlaneIter = 0; aSubPlaneIter < aNbSubPlanes; ++aSubPlaneIter)
8444 const Graphic3d_Vec3d& aDir = aDirArray[aSubPlaneIter];
8445 const Standard_Real aW = -aDir.Dot ((aSubPlaneIter % 2 == 1) ? aBndBox.CornerMax() : aBndBox.CornerMin());
8446 aSubPln->SetEquation (gp_Pln (aDir.x(), aDir.y(), aDir.z(), aW));
8447 if (aSubPlaneIter + 1 == aNbSubPlanes)
8449 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
8453 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
8455 aSubPln = aSubPln->ChainNextPlane();
8458 else if (aChangeArg == "-capping"
8459 || aChangeArg == "capping")
8461 if (aNbChangeArgs < 2)
8463 Message::SendFail ("Syntax error: need more arguments");
8467 if (Draw::ParseOnOff (aChangeArgs[1], toEnable))
8469 aClipPlane->SetCapping (toEnable);
8474 // just skip otherwise (old syntax)
8477 else if (aChangeArg == "-useobjectmaterial"
8478 || aChangeArg == "-useobjectmat"
8479 || aChangeArg == "-useobjmat"
8480 || aChangeArg == "-useobjmaterial")
8482 if (aNbChangeArgs < 2)
8484 Message::SendFail ("Syntax error: need more arguments");
8488 if (Draw::ParseOnOff (aChangeArgs[1], toEnable))
8490 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
8494 else if (aChangeArg == "-useobjecttexture"
8495 || aChangeArg == "-useobjecttex"
8496 || aChangeArg == "-useobjtexture"
8497 || aChangeArg == "-useobjtex")
8499 if (aNbChangeArgs < 2)
8501 Message::SendFail ("Syntax error: need more arguments");
8505 if (Draw::ParseOnOff (aChangeArgs[1], toEnable))
8507 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
8511 else if (aChangeArg == "-useobjectshader"
8512 || aChangeArg == "-useobjshader")
8514 if (aNbChangeArgs < 2)
8516 Message::SendFail ("Syntax error: need more arguments");
8520 if (Draw::ParseOnOff (aChangeArgs[1], toEnable))
8522 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
8526 else if (aChangeArg == "-color"
8527 || aChangeArg == "color")
8529 Quantity_Color aColor;
8530 Standard_Integer aNbParsed = Draw::ParseColor (aNbChangeArgs - 1,
8535 Message::SendFail ("Syntax error: need more arguments");
8538 aClipPlane->SetCappingColor (aColor);
8539 anArgIter += aNbParsed;
8541 else if (aNbChangeArgs >= 1
8542 && (aChangeArg == "-material"
8543 || aChangeArg == "material"))
8546 Graphic3d_NameOfMaterial aMatName;
8547 if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeArgs[1], aMatName))
8549 Message::SendFail() << "Syntax error: unknown material '" << aChangeArgs[1] << "'";
8552 aClipPlane->SetCappingMaterial (aMatName);
8554 else if ((aChangeArg == "-transparency"
8555 || aChangeArg == "-transp")
8556 && aNbChangeArgs >= 2)
8558 TCollection_AsciiString aValStr (aChangeArgs[1]);
8559 Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect();
8560 if (aValStr.IsRealValue (Standard_True))
8562 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
8563 aMat.SetTransparency ((float )aValStr.RealValue());
8564 anAspect->SetAlphaMode (Graphic3d_AlphaMode_BlendAuto);
8565 aClipPlane->SetCappingMaterial (aMat);
8569 aValStr.LowerCase();
8570 Graphic3d_AlphaMode aMode = Graphic3d_AlphaMode_BlendAuto;
8571 if (aValStr == "opaque")
8573 aMode = Graphic3d_AlphaMode_Opaque;
8575 else if (aValStr == "mask")
8577 aMode = Graphic3d_AlphaMode_Mask;
8579 else if (aValStr == "blend")
8581 aMode = Graphic3d_AlphaMode_Blend;
8583 else if (aValStr == "maskblend"
8584 || aValStr == "blendmask")
8586 aMode = Graphic3d_AlphaMode_MaskBlend;
8588 else if (aValStr == "blendauto")
8590 aMode = Graphic3d_AlphaMode_BlendAuto;
8594 Message::SendFail() << "Syntax error at '" << aValStr << "'";
8597 anAspect->SetAlphaMode (aMode);
8598 aClipPlane->SetCappingAspect (anAspect);
8602 else if (aChangeArg == "-texname"
8603 || aChangeArg == "texname")
8605 if (aNbChangeArgs < 2)
8607 Message::SendFail ("Syntax error: need more arguments");
8611 TCollection_AsciiString aTextureName (aChangeArgs[1]);
8612 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
8613 if (!aTexture->IsDone())
8615 aClipPlane->SetCappingTexture (NULL);
8619 aTexture->EnableModulate();
8620 aTexture->EnableRepeat();
8621 aClipPlane->SetCappingTexture (aTexture);
8625 else if (aChangeArg == "-texscale"
8626 || aChangeArg == "texscale")
8628 if (aClipPlane->CappingTexture().IsNull())
8630 Message::SendFail ("Error: no texture is set");
8634 if (aNbChangeArgs < 3)
8636 Message::SendFail ("Syntax error: need more arguments");
8640 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8641 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8642 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
8645 else if (aChangeArg == "-texorigin"
8646 || aChangeArg == "texorigin") // texture origin
8648 if (aClipPlane->CappingTexture().IsNull())
8650 Message::SendFail ("Error: no texture is set");
8654 if (aNbChangeArgs < 3)
8656 Message::SendFail ("Syntax error: need more arguments");
8660 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8661 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8663 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
8666 else if (aChangeArg == "-texrotate"
8667 || aChangeArg == "texrotate") // texture rotation
8669 if (aClipPlane->CappingTexture().IsNull())
8671 Message::SendFail ("Error: no texture is set");
8675 if (aNbChangeArgs < 2)
8677 Message::SendFail ("Syntax error: need more arguments");
8681 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8682 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
8685 else if (aChangeArg == "-hatch"
8686 || aChangeArg == "hatch")
8688 if (aNbChangeArgs < 2)
8690 Message::SendFail ("Syntax error: need more arguments");
8694 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
8695 aHatchStr.LowerCase();
8696 if (aHatchStr == "on")
8698 aClipPlane->SetCappingHatchOn();
8700 else if (aHatchStr == "off")
8702 aClipPlane->SetCappingHatchOff();
8706 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
8710 else if (aChangeArg == "-delete"
8711 || aChangeArg == "delete")
8713 removePlane (aRegPlanes, aPlaneName);
8716 else if (aChangeArg == "-set"
8717 || aChangeArg == "-unset"
8718 || aChangeArg == "-setoverrideglobal")
8720 // set / unset plane command
8721 const Standard_Boolean toSet = aChangeArg.StartsWith ("-set");
8722 const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal";
8723 Standard_Integer anIt = 1;
8724 for (; anIt < aNbChangeArgs; ++anIt)
8726 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
8727 if (anEntityName.IsEmpty()
8728 || anEntityName.Value (1) == '-')
8732 else if (!toOverrideGlobal
8733 && ViewerTest_myViews.IsBound1 (anEntityName))
8735 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
8738 aView->AddClipPlane (aClipPlane);
8742 aView->RemoveClipPlane (aClipPlane);
8746 else if (GetMapOfAIS().IsBound2 (anEntityName))
8748 Handle(AIS_InteractiveObject) aIObj = GetMapOfAIS().Find2 (anEntityName);
8751 aIObj->AddClipPlane (aClipPlane);
8755 aIObj->RemoveClipPlane (aClipPlane);
8757 if (!aIObj->ClipPlanes().IsNull())
8759 aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal);
8764 Message::SendFail() << "Error: object/view '" << anEntityName << "' is not found";
8771 // apply to active view
8774 anActiveView->AddClipPlane (aClipPlane);
8778 anActiveView->RemoveClipPlane (aClipPlane);
8783 anArgIter = anArgIter + anIt - 1;
8788 Message::SendFail() << "Syntax error: unknown argument '" << aChangeArg << "'";
8793 ViewerTest::RedrawAllViews();
8797 //===============================================================================================
8798 //function : VZRange
8800 //===============================================================================================
8801 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8803 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
8805 if (aCurrentView.IsNull())
8807 Message::SendFail ("Error: no active viewer");
8811 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
8815 theDi << "ZNear: " << aCamera->ZNear() << "\n";
8816 theDi << "ZFar: " << aCamera->ZFar() << "\n";
8822 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
8823 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
8825 if (aNewZNear >= aNewZFar)
8827 Message::SendFail ("Syntax error: invalid arguments: znear should be less than zfar");
8831 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
8833 Message::SendFail ("Syntax error: invalid arguments: znear, zfar should be positive for perspective camera");
8837 aCamera->SetZRange (aNewZNear, aNewZFar);
8841 Message::SendFail ("Syntax error: wrong command arguments");
8845 aCurrentView->Redraw();
8850 //===============================================================================================
8851 //function : VAutoZFit
8853 //===============================================================================================
8854 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8856 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
8858 if (aCurrentView.IsNull())
8860 Message::SendFail ("Error: no active viewer");
8864 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
8868 Message::SendFail ("Syntax error: wrong command arguments");
8874 theDi << "Auto z-fit mode: \n"
8875 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
8876 << "Scale: " << aScale << "\n";
8880 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
8884 aScale = Draw::Atoi (theArgVec[2]);
8887 aCurrentView->SetAutoZFitMode (isOn, aScale);
8888 aCurrentView->Redraw();
8892 //! Auxiliary function to print projection type
8893 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
8895 switch (theProjType)
8897 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
8898 case Graphic3d_Camera::Projection_Perspective: return "perspective";
8899 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
8900 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
8901 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
8906 //===============================================================================================
8907 //function : VCamera
8909 //===============================================================================================
8910 static int VCamera (Draw_Interpretor& theDI,
8911 Standard_Integer theArgsNb,
8912 const char** theArgVec)
8914 Handle(V3d_View) aView = ViewerTest::CurrentView();
8917 Message::SendFail ("Error: no active viewer");
8921 Handle(Graphic3d_Camera) aCamera = aView->Camera();
8924 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
8925 theDI << "FOVy: " << aCamera->FOVy() << "\n";
8926 theDI << "FOVx: " << aCamera->FOVx() << "\n";
8927 theDI << "FOV2d: " << aCamera->FOV2d() << "\n";
8928 theDI << "Distance: " << aCamera->Distance() << "\n";
8929 theDI << "IOD: " << aCamera->IOD() << "\n";
8930 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
8931 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
8932 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
8933 theDI << "ZNear: " << aCamera->ZNear() << "\n";
8934 theDI << "ZFar: " << aCamera->ZFar() << "\n";
8938 TCollection_AsciiString aPrsName;
8939 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
8941 Standard_CString anArg = theArgVec[anArgIter];
8942 TCollection_AsciiString anArgCase (anArg);
8943 anArgCase.LowerCase();
8944 if (anArgCase == "-proj"
8945 || anArgCase == "-projection"
8946 || anArgCase == "-projtype"
8947 || anArgCase == "-projectiontype")
8949 theDI << projTypeName (aCamera->ProjectionType()) << " ";
8951 else if (anArgCase == "-ortho"
8952 || anArgCase == "-orthographic")
8954 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
8956 else if (anArgCase == "-persp"
8957 || anArgCase == "-perspective"
8958 || anArgCase == "-perspmono"
8959 || anArgCase == "-perspectivemono"
8960 || anArgCase == "-mono")
8962 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
8964 else if (anArgCase == "-stereo"
8965 || anArgCase == "-stereoscopic"
8966 || anArgCase == "-perspstereo"
8967 || anArgCase == "-perspectivestereo")
8969 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
8971 else if (anArgCase == "-left"
8972 || anArgCase == "-lefteye"
8973 || anArgCase == "-monoleft"
8974 || anArgCase == "-monolefteye"
8975 || anArgCase == "-perpsleft"
8976 || anArgCase == "-perpslefteye")
8978 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
8980 else if (anArgCase == "-right"
8981 || anArgCase == "-righteye"
8982 || anArgCase == "-monoright"
8983 || anArgCase == "-monorighteye"
8984 || anArgCase == "-perpsright")
8986 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
8988 else if (anArgCase == "-dist"
8989 || anArgCase == "-distance")
8991 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8992 if (anArgValue != NULL
8993 && *anArgValue != '-')
8996 aCamera->SetDistance (Draw::Atof (anArgValue));
8999 theDI << aCamera->Distance() << " ";
9001 else if (anArgCase == "-iod")
9003 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9004 if (anArgValue != NULL
9005 && *anArgValue != '-')
9008 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
9011 theDI << aCamera->IOD() << " ";
9013 else if (anArgCase == "-iodtype")
9015 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
9016 TCollection_AsciiString anValueCase (anArgValue);
9017 anValueCase.LowerCase();
9018 if (anValueCase == "abs"
9019 || anValueCase == "absolute")
9022 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
9025 else if (anValueCase == "rel"
9026 || anValueCase == "relative")
9029 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
9032 else if (*anArgValue != '-')
9034 Message::SendFail() << "Error: unknown IOD type '" << anArgValue << "'";
9037 switch (aCamera->GetIODType())
9039 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
9040 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
9043 else if (anArgCase == "-zfocus")
9045 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9046 if (anArgValue != NULL
9047 && *anArgValue != '-')
9050 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
9053 theDI << aCamera->ZFocus() << " ";
9055 else if (anArgCase == "-zfocustype")
9057 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
9058 TCollection_AsciiString anValueCase (anArgValue);
9059 anValueCase.LowerCase();
9060 if (anValueCase == "abs"
9061 || anValueCase == "absolute")
9064 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
9067 else if (anValueCase == "rel"
9068 || anValueCase == "relative")
9071 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
9074 else if (*anArgValue != '-')
9076 Message::SendFail() << "Error: unknown ZFocus type '" << anArgValue << "'";
9079 switch (aCamera->ZFocusType())
9081 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
9082 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
9085 else if (anArgCase == "-lockzup"
9086 || anArgCase == "-turntable")
9088 bool toLockUp = true;
9089 if (++anArgIter < theArgsNb
9090 && !Draw::ParseOnOff (theArgVec[anArgIter], toLockUp))
9094 ViewerTest::CurrentEventManager()->SetLockOrbitZUp (toLockUp);
9096 else if (anArgCase == "-rotationmode"
9097 || anArgCase == "-rotmode")
9099 AIS_RotationMode aRotMode = AIS_RotationMode_BndBoxActive;
9100 TCollection_AsciiString aRotStr ((anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "");
9101 aRotStr.LowerCase();
9102 if (aRotStr == "bndboxactive"
9103 || aRotStr == "active")
9105 aRotMode = AIS_RotationMode_BndBoxActive;
9107 else if (aRotStr == "picklast"
9108 || aRotStr == "pick")
9110 aRotMode = AIS_RotationMode_PickLast;
9112 else if (aRotStr == "pickcenter")
9114 aRotMode = AIS_RotationMode_PickCenter;
9116 else if (aRotStr == "cameraat"
9117 || aRotStr == "cameracenter")
9119 aRotMode = AIS_RotationMode_CameraAt;
9121 else if (aRotStr == "bndboxscene"
9122 || aRotStr == "boxscene")
9124 aRotMode = AIS_RotationMode_BndBoxScene;
9128 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
9132 ViewerTest::CurrentEventManager()->SetRotationMode (aRotMode);
9135 else if (anArgCase == "-navigationmode"
9136 || anArgCase == "-navmode")
9138 AIS_NavigationMode aNavMode = AIS_NavigationMode_Orbit;
9139 TCollection_AsciiString aNavStr ((anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "");
9140 aNavStr.LowerCase();
9141 if (aNavStr == "orbit")
9143 aNavMode = AIS_NavigationMode_Orbit;
9145 else if (aNavStr == "flight"
9147 || aNavStr == "copter"
9148 || aNavStr == "helicopter")
9150 aNavMode = AIS_NavigationMode_FirstPersonFlight;
9152 else if (aNavStr == "walk"
9153 || aNavStr == "shooter")
9155 aNavMode = AIS_NavigationMode_FirstPersonWalk;
9159 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
9163 Handle(ViewerTest_EventManager) aViewMgr = ViewerTest::CurrentEventManager();
9164 aViewMgr->SetNavigationMode (aNavMode);
9165 if (aNavMode == AIS_NavigationMode_Orbit)
9167 aViewMgr->ChangeMouseGestureMap().Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_RotateOrbit);
9171 aViewMgr->ChangeMouseGestureMap().Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_RotateView);
9175 else if (anArgCase == "-fov"
9176 || anArgCase == "-fovy"
9177 || anArgCase == "-fovx"
9178 || anArgCase == "-fov2d")
9180 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9181 if (anArgValue != NULL
9182 && *anArgValue != '-')
9185 if (anArgCase == "-fov2d")
9187 aCamera->SetFOV2d (Draw::Atof (anArgValue));
9189 else if (anArgCase == "-fovx")
9191 aCamera->SetFOVy (Draw::Atof (anArgValue) / aCamera->Aspect());///
9195 aCamera->SetFOVy (Draw::Atof (anArgValue));
9199 if (anArgCase == "-fov2d")
9201 theDI << aCamera->FOV2d() << " ";
9203 else if (anArgCase == "-fovx")
9205 theDI << aCamera->FOVx() << " ";
9209 theDI << aCamera->FOVy() << " ";
9212 else if (anArgIter + 1 < theArgsNb
9213 && anArgCase == "-xrpose")
9215 TCollection_AsciiString anXRArg (theArgVec[++anArgIter]);
9216 anXRArg.LowerCase();
9217 if (anXRArg == "base")
9219 aCamera = aView->View()->BaseXRCamera();
9221 else if (anXRArg == "head")
9223 aCamera = aView->View()->PosedXRCamera();
9227 Message::SendFail() << "Syntax error: unknown XR pose '" << anXRArg << "'";
9230 if (aCamera.IsNull())
9232 Message::SendFail() << "Error: undefined XR pose";
9235 if (aView->AutoZFitMode())
9237 const Bnd_Box aMinMaxBox = aView->View()->MinMaxValues (false);
9238 const Bnd_Box aGraphicBox = aView->View()->MinMaxValues (true);
9239 aCamera->ZFitAll (aView->AutoZFitScaleFactor(), aMinMaxBox, aGraphicBox);
9242 else if (aPrsName.IsEmpty()
9243 && !anArgCase.StartsWith ("-"))
9249 Message::SendFail() << "Error: unknown argument '" << anArg << "'";
9254 if (aPrsName.IsEmpty()
9260 if (!aPrsName.IsEmpty())
9262 Handle(AIS_CameraFrustum) aCameraFrustum;
9263 if (GetMapOfAIS().IsBound2 (aPrsName))
9265 // find existing object
9266 aCameraFrustum = Handle(AIS_CameraFrustum)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
9267 if (aCameraFrustum.IsNull())
9269 Message::SendFail() << "Error: object '" << aPrsName << "'is already defined and is not a camera frustum";
9274 if (aCameraFrustum.IsNull())
9276 aCameraFrustum = new AIS_CameraFrustum();
9280 // not include displayed object of old camera frustum in the new one.
9281 ViewerTest::GetAISContext()->Erase (aCameraFrustum, false);
9284 aCameraFrustum->SetCameraFrustum (aCamera);
9286 ViewerTest::Display (aPrsName, aCameraFrustum);
9292 //! Parse stereo output mode
9293 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
9294 Graphic3d_StereoMode& theMode)
9296 TCollection_AsciiString aFlag (theArg);
9298 if (aFlag == "quadbuffer")
9300 theMode = Graphic3d_StereoMode_QuadBuffer;
9302 else if (aFlag == "anaglyph")
9304 theMode = Graphic3d_StereoMode_Anaglyph;
9306 else if (aFlag == "row"
9307 || aFlag == "rowinterlaced")
9309 theMode = Graphic3d_StereoMode_RowInterlaced;
9311 else if (aFlag == "col"
9312 || aFlag == "colinterlaced"
9313 || aFlag == "columninterlaced")
9315 theMode = Graphic3d_StereoMode_ColumnInterlaced;
9317 else if (aFlag == "chess"
9318 || aFlag == "chessboard")
9320 theMode = Graphic3d_StereoMode_ChessBoard;
9322 else if (aFlag == "sbs"
9323 || aFlag == "sidebyside")
9325 theMode = Graphic3d_StereoMode_SideBySide;
9327 else if (aFlag == "ou"
9328 || aFlag == "overunder")
9330 theMode = Graphic3d_StereoMode_OverUnder;
9332 else if (aFlag == "pageflip"
9333 || aFlag == "softpageflip")
9335 theMode = Graphic3d_StereoMode_SoftPageFlip;
9337 else if (aFlag == "openvr"
9340 theMode = Graphic3d_StereoMode_OpenVR;
9344 return Standard_False;
9346 return Standard_True;
9349 //! Parse anaglyph filter
9350 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
9351 Graphic3d_RenderingParams::Anaglyph& theFilter)
9353 TCollection_AsciiString aFlag (theArg);
9355 if (aFlag == "redcyansimple")
9357 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9359 else if (aFlag == "redcyan"
9360 || aFlag == "redcyanoptimized")
9362 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
9364 else if (aFlag == "yellowbluesimple")
9366 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
9368 else if (aFlag == "yellowblue"
9369 || aFlag == "yellowblueoptimized")
9371 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
9373 else if (aFlag == "greenmagenta"
9374 || aFlag == "greenmagentasimple")
9376 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
9380 return Standard_False;
9382 return Standard_True;
9385 //==============================================================================
9386 //function : VStereo
9388 //==============================================================================
9390 static int VStereo (Draw_Interpretor& theDI,
9391 Standard_Integer theArgNb,
9392 const char** theArgVec)
9394 Handle(V3d_View) aView = ViewerTest::CurrentView();
9397 Message::SendFail ("Error: no active viewer");
9401 Handle(Graphic3d_Camera) aCamera = aView->Camera();
9402 Graphic3d_RenderingParams* aParams = &aView->ChangeRenderingParams();
9405 Standard_Boolean isActive = aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo;
9406 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
9409 TCollection_AsciiString aMode;
9410 switch (aView->RenderingParams().StereoMode)
9412 case Graphic3d_StereoMode_QuadBuffer:
9414 aMode = "quadBuffer";
9417 case Graphic3d_StereoMode_RowInterlaced:
9419 aMode = "rowInterlaced";
9420 if (aView->RenderingParams().ToSmoothInterlacing)
9422 aMode.AssignCat (" (smoothed)");
9426 case Graphic3d_StereoMode_ColumnInterlaced:
9428 aMode = "columnInterlaced";
9429 if (aView->RenderingParams().ToSmoothInterlacing)
9431 aMode.AssignCat (" (smoothed)");
9435 case Graphic3d_StereoMode_ChessBoard:
9437 aMode = "chessBoard";
9438 if (aView->RenderingParams().ToSmoothInterlacing)
9440 aMode.AssignCat (" (smoothed)");
9444 case Graphic3d_StereoMode_SideBySide:
9446 aMode = "sideBySide";
9449 case Graphic3d_StereoMode_OverUnder:
9451 aMode = "overUnder";
9454 case Graphic3d_StereoMode_SoftPageFlip:
9456 aMode = "softPageFlip";
9459 case Graphic3d_StereoMode_OpenVR:
9464 case Graphic3d_StereoMode_Anaglyph:
9467 switch (aView->RenderingParams().AnaglyphFilter)
9469 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
9470 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
9471 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
9472 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
9473 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
9474 case Graphic3d_RenderingParams::Anaglyph_UserDefined : aMode.AssignCat (" (userDefined)"); break;
9478 theDI << "Mode " << aMode << "\n";
9483 Graphic3d_StereoMode aMode = aParams->StereoMode;
9484 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
9485 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
9487 Standard_CString anArg = theArgVec[anArgIter];
9488 TCollection_AsciiString aFlag (anArg);
9490 if (anUpdateTool.parseRedrawMode (aFlag))
9494 else if (aFlag == "0"
9497 if (++anArgIter < theArgNb)
9499 Message::SendFail ("Error: wrong number of arguments");
9503 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
9505 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
9509 else if (aFlag == "1"
9512 if (++anArgIter < theArgNb)
9514 Message::SendFail ("Error: wrong number of arguments");
9518 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9519 if (aParams->StereoMode != Graphic3d_StereoMode_OpenVR)
9524 else if (aFlag == "-reverse"
9525 || aFlag == "-noreverse"
9526 || aFlag == "-reversed"
9528 || aFlag == "-noswap")
9530 aParams->ToReverseStereo = Draw::ParseOnOffNoIterator (theArgNb, theArgVec, anArgIter);
9532 else if (aFlag == "-mode"
9533 || aFlag == "-stereomode")
9535 if (++anArgIter >= theArgNb
9536 || !parseStereoMode (theArgVec[anArgIter], aMode))
9538 Message::SendFail() << "Syntax error at '" << anArg << "'";
9542 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9544 Message::SendInfo() << "Warning: make sure to call 'vcaps -stereo 1' before creating a view";
9547 else if (aFlag == "-anaglyph"
9548 || aFlag == "-anaglyphfilter")
9550 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9551 if (++anArgIter >= theArgNb
9552 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
9554 Message::SendFail() << "Syntax error at '" << anArg << "'";
9558 aMode = Graphic3d_StereoMode_Anaglyph;
9559 aParams->AnaglyphFilter = aFilter;
9561 else if (parseStereoMode (anArg, aMode)) // short syntax
9563 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9565 Message::SendInfo() << "Warning: make sure to call 'vcaps -stereo 1' before creating a view";
9568 else if (anArgIter + 1 < theArgNb
9569 && aFlag == "-hmdfov2d")
9571 aParams->HmdFov2d = (float )Draw::Atof (theArgVec[++anArgIter]);
9572 if (aParams->HmdFov2d < 10.0f
9573 || aParams->HmdFov2d > 180.0f)
9575 Message::SendFail() << "Error: FOV is out of range";
9579 else if (aFlag == "-mirror"
9580 || aFlag == "-mirrorcomposer")
9582 aParams->ToMirrorComposer = Draw::ParseOnOffNoIterator (theArgNb, theArgVec, anArgIter);;
9584 else if (aFlag == "-smooth"
9585 || aFlag == "-nosmooth"
9586 || aFlag == "-smoothinterlacing"
9587 || aFlag == "-nosmoothinterlacing")
9589 aParams->ToSmoothInterlacing = Draw::ParseOnOffNoIterator (theArgNb, theArgVec, anArgIter);
9591 else if (anArgIter + 1 < theArgNb
9592 && (aFlag == "-unitfactor"
9593 || aFlag == "-unitscale"))
9595 aView->View()->SetUnitFactor (Draw::Atof (theArgVec[++anArgIter]));
9599 Message::SendFail() << "Syntax error at '" << anArg << "'";
9604 aParams->StereoMode = aMode;
9605 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9606 if (aParams->StereoMode == Graphic3d_StereoMode_OpenVR)
9608 // initiate implicit continuous rendering
9609 ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true);
9614 //===============================================================================================
9615 //function : VDefaults
9617 //===============================================================================================
9618 static int VDefaults (Draw_Interpretor& theDi,
9619 Standard_Integer theArgsNb,
9620 const char** theArgVec)
9622 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
9625 Message::SendFail ("Error: no active viewer");
9629 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
9632 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
9634 theDi << "DeflType: relative\n"
9635 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
9639 theDi << "DeflType: absolute\n"
9640 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
9642 theDi << "AngularDeflection: " << (180.0 * aDefParams->DeviationAngle() / M_PI) << "\n";
9643 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
9647 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
9649 TCollection_AsciiString anArg (theArgVec[anArgIter]);
9651 if (anArg == "-ABSDEFL"
9652 || anArg == "-ABSOLUTEDEFLECTION"
9654 || anArg == "-DEFLECTION")
9656 if (++anArgIter >= theArgsNb)
9658 Message::SendFail() << "Syntax error at " << anArg;
9661 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
9662 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
9664 else if (anArg == "-RELDEFL"
9665 || anArg == "-RELATIVEDEFLECTION"
9666 || anArg == "-DEVCOEFF"
9667 || anArg == "-DEVIATIONCOEFF"
9668 || anArg == "-DEVIATIONCOEFFICIENT")
9670 if (++anArgIter >= theArgsNb)
9672 Message::SendFail() << "Syntax error at " << anArg;
9675 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
9676 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
9678 else if (anArg == "-ANGDEFL"
9679 || anArg == "-ANGULARDEFL"
9680 || anArg == "-ANGULARDEFLECTION")
9682 if (++anArgIter >= theArgsNb)
9684 Message::SendFail() << "Syntax error at " << anArg;
9687 aDefParams->SetDeviationAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
9689 else if (anArg == "-AUTOTR"
9690 || anArg == "-AUTOTRIANG"
9691 || anArg == "-AUTOTRIANGULATION")
9694 bool toTurnOn = true;
9695 if (anArgIter >= theArgsNb
9696 || !Draw::ParseOnOff (theArgVec[anArgIter], toTurnOn))
9698 Message::SendFail() << "Syntax error at '" << anArg << "'";
9701 aDefParams->SetAutoTriangulation (toTurnOn);
9705 Message::SendFail() << "Syntax error: unknown argument '" << anArg << "'";
9713 //! Parse light source type from string.
9714 static bool parseLightSourceType (const TCollection_AsciiString& theTypeName,
9715 Graphic3d_TypeOfLightSource& theType)
9717 TCollection_AsciiString aType (theTypeName);
9720 || aType == "ambient"
9721 || aType == "amblight")
9723 theType = Graphic3d_TypeOfLightSource_Ambient;
9725 else if (aType == "directional"
9726 || aType == "dirlight")
9728 theType = Graphic3d_TypeOfLightSource_Directional;
9730 else if (aType == "spot"
9731 || aType == "spotlight")
9733 theType = Graphic3d_TypeOfLightSource_Spot;
9735 else if (aType == "poslight"
9736 || aType == "positional"
9740 theType = Graphic3d_TypeOfLightSource_Positional;
9749 //! Find existing light by name or index.
9750 static Handle(V3d_Light) findLightSource (const TCollection_AsciiString& theName)
9752 Handle(V3d_Light) aLight;
9753 Standard_Integer aLightIndex = -1;
9754 Draw::ParseInteger (theName.ToCString(), aLightIndex);
9755 Standard_Integer aLightIt = 0;
9756 Handle(V3d_View) aView = ViewerTest::CurrentView();
9757 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
9759 if (aLightIndex != -1)
9761 if (aLightIt == aLightIndex)
9763 return aLightIter.Value();
9766 else if (aLightIter.Value()->GetId() == theName
9767 || aLightIter.Value()->Name() == theName)
9769 if (!aLight.IsNull())
9771 Message::SendWarning() << "Warning: ambiguous light name '" << theName << "'";
9774 aLight = aLightIter.Value();
9780 //===============================================================================================
9783 //===============================================================================================
9784 static int VLight (Draw_Interpretor& theDi,
9785 Standard_Integer theArgsNb,
9786 const char** theArgVec)
9788 Handle(V3d_View) aView = ViewerTest::CurrentView();
9789 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9790 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
9792 || aViewer.IsNull())
9794 Message::SendFail ("Error: no active viewer");
9800 // print lights info
9801 Standard_Integer aLightId = 0;
9802 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
9804 Handle(V3d_Light) aLight = aLightIter.Value();
9805 const Quantity_Color aColor = aLight->Color();
9806 theDi << "Light #" << aLightId
9807 << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "")
9808 << " [" << aLight->GetId() << "] "
9809 << (aLight->IsEnabled() ? "ON" : "OFF") << "\n";
9810 switch (aLight->Type())
9814 theDi << " Type: Ambient\n"
9815 << " Intensity: " << aLight->Intensity() << "\n";
9818 case V3d_DIRECTIONAL:
9820 theDi << " Type: Directional\n"
9821 << " Intensity: " << aLight->Intensity() << "\n"
9822 << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"
9823 << " CastShadows:" << (aLight->ToCastShadows() ? "TRUE" : "FALSE") << "\n"
9824 << " Smoothness: " << aLight->Smoothness() << "\n"
9825 << " Direction: " << aLight->PackedDirection().x() << " " << aLight->PackedDirection().y() << " " << aLight->PackedDirection().z() << "\n";
9828 case V3d_POSITIONAL:
9830 theDi << " Type: Positional\n"
9831 << " Intensity: " << aLight->Intensity() << "\n"
9832 << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"
9833 << " CastShadows:" << (aLight->ToCastShadows() ? "TRUE" : "FALSE") << "\n"
9834 << " Smoothness: " << aLight->Smoothness() << "\n"
9835 << " Position: " << aLight->Position().X() << " " << aLight->Position().Y() << " " << aLight->Position().Z() << "\n"
9836 << " Atten.: " << aLight->ConstAttenuation() << " " << aLight->LinearAttenuation() << "\n"
9837 << " Range: " << aLight->Range() << "\n";
9842 theDi << " Type: Spot\n"
9843 << " Intensity: " << aLight->Intensity() << "\n"
9844 << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"
9845 << " CastShadows:" << (aLight->ToCastShadows() ? "TRUE" : "FALSE") << "\n"
9846 << " Position: " << aLight->Position().X() << " " << aLight->Position().Y() << " " << aLight->Position().Z() << "\n"
9847 << " Direction: " << aLight->PackedDirection().x() << " " << aLight->PackedDirection().y() << " " << aLight->PackedDirection().z() << "\n"
9848 << " Atten.: " << aLight->ConstAttenuation() << " " << aLight->LinearAttenuation() << "\n"
9849 << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n"
9850 << " Exponent: " << aLight->Concentration() << "\n"
9851 << " Range: " << aLight->Range() << "\n";
9856 theDi << " Type: UNKNOWN\n";
9860 theDi << " Color: " << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n";
9864 Handle(V3d_Light) aLightOld, aLightNew;
9865 Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN;
9866 bool isGlobal = true;
9867 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
9868 Handle(AIS_LightSource) aLightPrs;
9869 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
9871 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
9872 TCollection_AsciiString anArgCase (anArg);
9873 anArgCase.LowerCase();
9874 if (anUpdateTool.parseRedrawMode (anArg))
9878 else if (anArgCase == "-new"
9879 || anArgCase == "-add"
9880 || anArgCase == "-create"
9881 || anArgCase == "-type"
9882 || (anArgCase == "-reset"
9883 && !aLightNew.IsNull())
9884 || (anArgCase == "-defaults"
9885 && !aLightNew.IsNull())
9886 || anArgCase == "add"
9887 || anArgCase == "new"
9888 || anArgCase == "create")
9890 Graphic3d_TypeOfLightSource aType = Graphic3d_TypeOfLightSource_Ambient;
9891 if (anArgCase == "-reset")
9893 aType = aLightNew->Type();
9895 else if (anArgIt + 1 >= theArgsNb
9896 || !parseLightSourceType (theArgVec[++anArgIt], aType))
9898 theDi << "Syntax error at '" << theArgVec[anArgIt] << "'\n";
9902 TCollection_AsciiString aName;
9903 if (!aLightNew.IsNull())
9905 aName = aLightNew->Name();
9909 case Graphic3d_TypeOfLightSource_Ambient:
9911 aLightNew = new V3d_AmbientLight();
9914 case Graphic3d_TypeOfLightSource_Directional:
9916 aLightNew = new V3d_DirectionalLight();
9919 case Graphic3d_TypeOfLightSource_Spot:
9921 aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0));
9924 case Graphic3d_TypeOfLightSource_Positional:
9926 aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0));
9931 if (anArgCase == "-type"
9932 && !aLightOld.IsNull())
9934 aLightNew->CopyFrom (aLightOld);
9936 aLightNew->SetName (aName);
9938 else if ((anArgCase == "-layer"
9939 || anArgCase == "-zlayer")
9940 && anArgIt + 1 < theArgsNb)
9942 if (!ViewerTest::ParseZLayer (theArgVec[++anArgIt], aLayer)
9943 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
9945 Message::SendFail() << "Error: wrong syntax at '" << theArgVec[anArgIt] << "'";
9949 else if (anArgCase == "-glob"
9950 || anArgCase == "-global"
9951 || anArgCase == "-loc"
9952 || anArgCase == "-local")
9954 isGlobal = anArgCase.StartsWith ("-glob");
9956 else if (anArgCase == "-def"
9957 || anArgCase == "-defaults"
9958 || anArgCase == "-reset")
9960 aViewer->SetDefaultLights();
9961 aLightOld.Nullify();
9962 aLightNew.Nullify();
9963 aLightPrs.Nullify();
9965 else if (anArgCase == "-clr"
9966 || anArgCase == "-clear"
9967 || anArgCase == "clear")
9969 TColStd_SequenceOfInteger aLayers;
9970 aViewer->GetAllZLayers (aLayers);
9971 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
9973 if (aLayeriter.Value() == aLayer
9974 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
9976 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
9977 aSettings.SetLights (Handle(Graphic3d_LightSet)());
9978 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
9979 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
9986 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
9988 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
9989 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
9991 Handle(V3d_Light) aLight = aLightIter.Value();
9992 Handle(AIS_InteractiveObject) aPrsObject;
9993 GetMapOfAIS().Find2 (aLight->Name(), aPrsObject);
9994 if (Handle(AIS_LightSource) aLightSourceDel = Handle(AIS_LightSource)::DownCast (aPrsObject))
9996 aCtx->Remove (aLightSourceDel, false);
9997 aMap.UnBind1 (aLightSourceDel);
9999 aViewer->DelLight (aLight);
10000 aLightIter = aView->ActiveLightIterator();
10004 aLightOld.Nullify();
10005 aLightNew.Nullify();
10006 aLightPrs.Nullify();
10008 else if (!aLightNew.IsNull()
10009 && (anArgCase == "-display"
10010 || anArgCase == "-disp"
10011 || anArgCase == "-presentation"
10012 || anArgCase == "-prs"))
10014 TCollection_AsciiString aLightName = aLightNew->Name();
10015 if (anArgIt + 1 < theArgsNb
10016 && theArgVec[anArgIt + 1][0] != '-')
10019 aLightName = theArgVec[++anArgIt];
10020 if (aLightNew->Name() != aLightName)
10022 if (Handle(V3d_Light) anOtherLight = findLightSource (aLightName))
10024 theDi << "Syntax error: light with name '" << aLightName << "' is already defined";
10027 aLightNew->SetName (aLightName);
10030 if (aLightName.IsEmpty())
10032 Message::SendFail() << "Error: nameless light source cannot be displayed";
10035 if (aLightPrs.IsNull())
10037 aLightPrs = new AIS_LightSource (aLightNew);
10039 theDi << aLightName << " ";
10041 else if (!aLightNew.IsNull()
10042 && (anArgCase == "-disable"
10043 || anArgCase == "-disabled"
10044 || anArgCase == "-enable"
10045 || anArgCase == "-enabled"))
10047 bool toEnable = Draw::ParseOnOffIterator (theArgsNb, theArgVec, anArgIt);
10048 if (anArgCase == "-disable"
10049 || anArgCase == "-disabled")
10051 toEnable = !toEnable;
10053 aLightNew->SetEnabled (toEnable);
10055 else if (!aLightNew.IsNull()
10056 && (anArgCase == "-color"
10057 || anArgCase == "-colour"
10058 || anArgCase == "color"))
10060 Quantity_Color aColor;
10061 Standard_Integer aNbParsed = Draw::ParseColor (theArgsNb - anArgIt - 1,
10062 theArgVec + anArgIt + 1,
10064 anArgIt += aNbParsed;
10065 if (aNbParsed == 0)
10067 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
10070 aLightNew->SetColor (aColor);
10072 else if (!aLightNew.IsNull()
10073 && (anArgCase == "-pos"
10074 || anArgCase == "-position"
10075 || anArgCase == "-prsposition"
10076 || anArgCase == "-prspos"
10077 || anArgCase == "pos"
10078 || anArgCase == "position")
10079 && (anArgIt + 3) < theArgsNb)
10082 if (!parseXYZ (theArgVec + anArgIt + 1, aPosXYZ))
10084 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
10089 if (anArgCase == "-prsposition"
10090 || anArgCase == "-prspos")
10092 aLightNew->SetDisplayPosition (aPosXYZ);
10096 if (aLightNew->Type() != Graphic3d_TypeOfLightSource_Positional
10097 && aLightNew->Type() != Graphic3d_TypeOfLightSource_Spot)
10099 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
10103 aLightNew->SetPosition (aPosXYZ);
10106 else if (!aLightNew.IsNull()
10107 && (aLightNew->Type() == Graphic3d_TypeOfLightSource_Directional
10108 || aLightNew->Type() == Graphic3d_TypeOfLightSource_Spot)
10109 && (anArgCase == "-dir"
10110 || anArgCase == "-direction")
10111 && (anArgIt + 3) < theArgsNb)
10114 if (!parseXYZ (theArgVec + anArgIt + 1, aDirXYZ))
10116 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
10121 aLightNew->SetDirection (gp_Dir (aDirXYZ));
10123 else if (!aLightNew.IsNull()
10124 && (anArgCase == "-smoothangle"
10125 || anArgCase == "-smoothradius"
10126 || anArgCase == "-sm"
10127 || anArgCase == "-smoothness")
10128 && anArgIt + 1 < theArgsNb)
10130 Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[++anArgIt]);
10131 if (aLightNew->Type() == Graphic3d_TypeOfLightSource_Directional)
10133 aSmoothness = Standard_ShortReal(aSmoothness * M_PI / 180.0);
10135 if (Abs (aSmoothness) <= ShortRealEpsilon())
10137 aLightNew->SetIntensity (1.f);
10139 else if (Abs (aLightNew->Smoothness()) <= ShortRealEpsilon())
10141 aLightNew->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
10145 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightNew->Smoothness());
10146 aLightNew->SetIntensity (aLightNew->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
10149 if (aLightNew->Type() == Graphic3d_TypeOfLightSource_Positional)
10151 aLightNew->SetSmoothRadius (aSmoothness);
10153 else if (aLightNew->Type() == Graphic3d_TypeOfLightSource_Directional)
10155 aLightNew->SetSmoothAngle (aSmoothness);
10158 else if (!aLightNew.IsNull()
10159 && (anArgCase == "-int"
10160 || anArgCase == "-intensity")
10161 && anArgIt + 1 < theArgsNb)
10163 Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[++anArgIt]);
10164 aLightNew->SetIntensity (aIntensity);
10166 else if (!aLightNew.IsNull()
10167 && aLightNew->Type() == Graphic3d_TypeOfLightSource_Spot
10168 && (anArgCase == "-spotangle"
10169 || anArgCase == "-ang"
10170 || anArgCase == "-angle")
10171 && anArgIt + 1 < theArgsNb)
10173 Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[++anArgIt]);
10174 anAngle = (Standard_ShortReal (anAngle / 180.0 * M_PI));
10175 aLightNew->SetAngle (anAngle);
10177 else if (!aLightNew.IsNull()
10178 && (aLightNew->Type() == Graphic3d_TypeOfLightSource_Positional
10179 || aLightNew->Type() == Graphic3d_TypeOfLightSource_Spot)
10180 && (anArgCase == "-constatten"
10181 || anArgCase == "-constattenuation")
10182 && anArgIt + 1 < theArgsNb)
10184 const Standard_ShortReal aConstAtten = (Standard_ShortReal )Atof (theArgVec[++anArgIt]);
10185 aLightNew->SetAttenuation (aConstAtten, aLightNew->LinearAttenuation());
10187 else if (!aLightNew.IsNull()
10188 && (aLightNew->Type() == Graphic3d_TypeOfLightSource_Positional
10189 || aLightNew->Type() == Graphic3d_TypeOfLightSource_Spot)
10190 && (anArgCase == "-linatten"
10191 || anArgCase == "-linearatten"
10192 || anArgCase == "-linearattenuation")
10193 && anArgIt + 1 < theArgsNb)
10195 const Standard_ShortReal aLinAtten = (Standard_ShortReal )Atof (theArgVec[++anArgIt]);
10196 aLightNew->SetAttenuation (aLightNew->ConstAttenuation(), aLinAtten);
10198 else if (!aLightNew.IsNull()
10199 && aLightNew->Type() == Graphic3d_TypeOfLightSource_Spot
10200 && (anArgCase == "-spotexp"
10201 || anArgCase == "-spotexponent"
10202 || anArgCase == "-exp"
10203 || anArgCase == "-exponent")
10204 && anArgIt + 1 < theArgsNb)
10206 aLightNew->SetConcentration ((Standard_ShortReal )Atof (theArgVec[++anArgIt]));
10208 else if (!aLightNew.IsNull()
10209 && aLightNew->Type() != Graphic3d_TypeOfLightSource_Ambient
10210 && aLightNew->Type() != Graphic3d_TypeOfLightSource_Directional
10211 && anArgCase == "-range"
10212 && anArgIt + 1 < theArgsNb)
10214 Standard_ShortReal aRange ((Standard_ShortReal)Atof (theArgVec[++anArgIt]));
10215 aLightNew->SetRange (aRange);
10217 else if (!aLightNew.IsNull()
10218 && aLightNew->Type() != Graphic3d_TypeOfLightSource_Ambient
10219 && (anArgCase == "-head"
10220 || anArgCase == "-headlight"))
10222 Standard_Boolean isHeadLight = Standard_True;
10223 if (anArgIt + 1 < theArgsNb
10224 && Draw::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight))
10228 aLightNew->SetHeadlight (isHeadLight);
10230 else if (!aLightNew.IsNull()
10231 && anArgCase == "-name"
10232 && anArgIt + 1 < theArgsNb)
10234 const TCollection_AsciiString aName = theArgVec[++anArgIt];
10235 if (aLightNew->Name() == aName)
10240 if (Handle(V3d_Light) anOtherLight = findLightSource (aName))
10242 theDi << "Syntax error: light with name '" << aName << "' is already defined";
10245 aLightNew->SetName (aName);
10247 else if (!aLightPrs.IsNull()
10248 && (anArgCase == "-showzoomable"
10249 || anArgCase == "-prszoomable"
10250 || anArgCase == "-zoomable"))
10252 const bool isZoomable = Draw::ParseOnOffIterator (theArgsNb, theArgVec, anArgIt);
10253 aLightPrs->SetZoomable (isZoomable);
10255 else if (!aLightPrs.IsNull()
10256 && (anArgCase == "-showdraggable"
10257 || anArgCase == "-prsdraggable"
10258 || anArgCase == "-draggable"))
10260 const bool isDraggable = Draw::ParseOnOffIterator (theArgsNb, theArgVec, anArgIt);
10261 aLightPrs->SetDraggable (isDraggable);
10263 else if (!aLightPrs.IsNull()
10264 && (anArgCase == "-showname"
10265 || anArgCase == "-prsname"))
10267 const bool toDisplay = Draw::ParseOnOffIterator (theArgsNb, theArgVec, anArgIt);
10268 aLightPrs->SetDisplayName (toDisplay);
10270 else if (!aLightPrs.IsNull()
10271 && (aLightNew->Type() == Graphic3d_TypeOfLightSource_Spot
10272 || aLightNew->Type() == Graphic3d_TypeOfLightSource_Positional)
10273 && (anArgCase == "-showrange"
10274 || anArgCase == "-prsrange"))
10276 const bool toDisplay = Draw::ParseOnOffIterator (theArgsNb, theArgVec, anArgIt);
10277 aLightPrs->SetDisplayRange (toDisplay);
10279 else if (!aLightPrs.IsNull()
10280 && (anArgCase == "-showsize"
10281 || anArgCase == "-prssize")
10282 && anArgIt + 1 < theArgsNb)
10284 Standard_Real aSize = 0.0;
10285 if (!Draw::ParseReal (theArgVec[++anArgIt], aSize)
10287 || aLightPrs.IsNull())
10289 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
10293 aLightPrs->SetSize (aSize);
10295 else if (!aLightPrs.IsNull()
10296 && (anArgCase == "-dirarcsize"
10297 || anArgCase == "-arcsize"
10298 || anArgCase == "-arc")
10299 && anArgIt + 1 < theArgsNb)
10301 Standard_Integer aSize = 0;
10302 if (!Draw::ParseInteger (theArgVec[anArgIt + 1], aSize)
10304 || aLightPrs->Light()->Type() != Graphic3d_TypeOfLightSource_Directional)
10306 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
10310 aLightPrs->SetArcSize (aSize);
10312 else if (!aLightNew.IsNull()
10313 && aLightNew->Type() != Graphic3d_TypeOfLightSource_Ambient
10314 && (anArgCase == "-castshadow"
10315 || anArgCase == "-castshadows"
10316 || anArgCase == "-shadows"))
10318 bool toCastShadows = true;
10319 if (anArgIt + 1 < theArgsNb
10320 && Draw::ParseOnOff (theArgVec[anArgIt + 1], toCastShadows))
10324 aLightNew->SetCastShadows (toCastShadows);
10326 else if (anArgCase == "-del"
10327 || anArgCase == "-delete"
10328 || anArgCase == "-remove"
10329 || anArgCase == "del"
10330 || anArgCase == "delete"
10331 || anArgCase == "remove")
10333 if (aLightOld.IsNull())
10335 if (!aLightNew.IsNull())
10337 aLightNew.Nullify();
10341 if (++anArgIt >= theArgsNb)
10343 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
10347 const TCollection_AsciiString anOldName (theArgVec[anArgIt]);
10348 aLightOld = findLightSource (anOldName);
10349 if (aLightOld.IsNull())
10351 Message::SendWarning() << "Warning: light '" << anOldName << "' not found";
10356 aLightNew.Nullify();
10357 aLightPrs.Nullify();
10359 else if (anArgCase == "-change"
10360 || anArgCase == "change")
10362 // just skip old syntax
10364 else if (aLightNew.IsNull()
10365 && !anArgCase.StartsWith ("-"))
10367 if (!aLightNew.IsNull())
10372 const TCollection_AsciiString anOldName (theArgVec[anArgIt]);
10373 aLightOld = findLightSource (anOldName);
10374 if (!aLightOld.IsNull())
10376 aLightNew = aLightOld;
10378 Handle(AIS_InteractiveObject) aPrsObject;
10379 GetMapOfAIS().Find2 (aLightOld->Name(), aPrsObject);
10380 aLightPrs = Handle(AIS_LightSource)::DownCast (aPrsObject);
10384 Standard_Integer aLightIndex = -1;
10385 Draw::ParseInteger (anOldName.ToCString(), aLightIndex);
10386 if (aLightIndex != -1)
10388 Message::SendFail() << "Syntax error: light source with index '" << aLightIndex << "' is not found";
10392 aLightNew = new V3d_AmbientLight();
10393 aLightNew->SetName (anOldName);
10398 Message::SendFail() << "Warning: unknown argument '" << anArg << "'";
10403 // delete old light source
10404 if (!aLightOld.IsNull()
10405 && aLightOld != aLightNew)
10407 TColStd_SequenceOfInteger aLayers;
10408 aViewer->GetAllZLayers (aLayers);
10409 for (TColStd_SequenceOfInteger::Iterator aLayerIter (aLayers); aLayerIter.More(); aLayerIter.Next())
10411 if (aLayerIter.Value() == aLayer
10412 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
10414 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerIter.Value());
10415 if (!aSettings.Lights().IsNull())
10417 aSettings.Lights()->Remove (aLightOld);
10418 if (aSettings.Lights()->IsEmpty())
10420 aSettings.SetLights (Handle(Graphic3d_LightSet)());
10423 aViewer->SetZLayerSettings (aLayerIter.Value(), aSettings);
10424 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
10431 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
10433 Handle(AIS_InteractiveObject) aPrsObject;
10434 GetMapOfAIS().Find2 (aLightOld->Name(), aPrsObject);
10435 if (Handle(AIS_LightSource) aLightSourceDel = Handle(AIS_LightSource)::DownCast (aPrsObject))
10437 aCtx->Remove (aLightSourceDel, false);
10438 GetMapOfAIS().UnBind1 (aLightSourceDel);
10440 aViewer->DelLight (aLightOld);
10442 aLightOld.Nullify();
10445 // add new light source
10446 if (!aLightNew.IsNull())
10448 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
10450 aViewer->AddLight (aLightNew);
10453 aViewer->SetLightOn (aLightNew);
10457 aView->SetLightOn (aLightNew);
10462 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayer);
10463 if (aSettings.Lights().IsNull())
10465 aSettings.SetLights (new Graphic3d_LightSet());
10467 aSettings.Lights()->Add (aLightNew);
10468 aViewer->SetZLayerSettings (aLayer, aSettings);
10471 if (!aLightPrs.IsNull())
10473 aLightPrs->SetLight (aLightNew);
10474 ViewerTest::Display (aLightNew->Name(), aLightPrs, false);
10478 // manage presentations
10479 struct LightPrsSort
10481 bool operator() (const Handle(AIS_LightSource)& theLeft,
10482 const Handle(AIS_LightSource)& theRight)
10484 return theLeft->Light()->GetId() < theRight->Light()->GetId();
10488 AIS_ListOfInteractive aPrsList;
10489 aCtx->DisplayedObjects (AIS_KindOfInteractive_LightSource, -1, aPrsList);
10490 if (!aPrsList.IsEmpty())
10492 // update light source presentations
10493 std::vector<Handle(AIS_LightSource)> aLightPrsVec;
10494 for (AIS_ListOfInteractive::Iterator aPrsIter (aPrsList); aPrsIter.More(); aPrsIter.Next())
10496 if (Handle(AIS_LightSource) aLightPrs2 = Handle(AIS_LightSource)::DownCast (aPrsIter.Value()))
10498 aLightPrsVec.push_back (aLightPrs2);
10502 // sort objects by id as AIS_InteractiveContext stores them in unordered map
10503 std::sort (aLightPrsVec.begin(), aLightPrsVec.end(), LightPrsSort());
10505 Standard_Integer aTopStack = 0;
10506 for (std::vector<Handle(AIS_LightSource)>::iterator aPrsIter = aLightPrsVec.begin(); aPrsIter != aLightPrsVec.end(); ++aPrsIter)
10508 Handle(AIS_LightSource) aLightPrs2 = *aPrsIter;
10509 if (!aLightPrs2->TransformPersistence().IsNull()
10510 && aLightPrs2->TransformPersistence()->IsTrihedronOr2d())
10512 const Standard_Integer aPrsSize = (Standard_Integer )aLightPrs2->Size();
10513 aLightPrs2->TransformPersistence()->SetOffset2d (Graphic3d_Vec2i (aTopStack + aPrsSize, aPrsSize));
10514 aTopStack += aPrsSize + aPrsSize / 2;
10516 aCtx->Redisplay (aLightPrs2, false);
10517 aCtx->SetTransformPersistence (aLightPrs2, aLightPrs2->TransformPersistence());
10523 //===============================================================================================
10524 //function : VPBREnvironment
10526 //===============================================================================================
10527 static int VPBREnvironment (Draw_Interpretor&,
10528 Standard_Integer theArgsNb,
10529 const char** theArgVec)
10533 Message::SendFail ("Syntax error: 'vpbrenv' command has only one argument");
10537 Handle(V3d_View) aView = ViewerTest::CurrentView();
10538 if (aView.IsNull())
10540 Message::SendFail ("Error: no active viewer");
10544 TCollection_AsciiString anArg = TCollection_AsciiString (theArgVec[1]);
10547 if (anArg == "-generate"
10548 || anArg == "-gen")
10550 aView->GeneratePBREnvironment (Standard_True);
10552 else if (anArg == "-clear")
10554 aView->ClearPBREnvironment (Standard_True);
10558 Message::SendFail() << "Syntax error: unknown argument [" << theArgVec[1] << "] for 'vpbrenv' command";
10565 //! Read Graphic3d_RenderingParams::PerfCounters flag.
10566 static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue,
10567 Standard_Boolean& theToReset,
10568 Graphic3d_RenderingParams::PerfCounters& theFlagsRem,
10569 Graphic3d_RenderingParams::PerfCounters& theFlagsAdd)
10571 Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE;
10572 TCollection_AsciiString aVal = theValue;
10573 Standard_Boolean toReverse = Standard_False;
10574 if (aVal == "none")
10576 theToReset = Standard_True;
10577 return Standard_True;
10579 else if (aVal.StartsWith ("-"))
10581 toReverse = Standard_True;
10582 aVal = aVal.SubString (2, aVal.Length());
10584 else if (aVal.StartsWith ("no"))
10586 toReverse = Standard_True;
10587 aVal = aVal.SubString (3, aVal.Length());
10589 else if (aVal.StartsWith ("+"))
10591 aVal = aVal.SubString (2, aVal.Length());
10595 theToReset = Standard_True;
10599 || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate;
10600 else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU;
10601 else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers;
10602 else if (aVal == "structs"
10603 || aVal == "structures"
10604 || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures;
10605 else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups;
10606 else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
10607 else if (aVal == "tris"
10608 || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles;
10609 else if (aVal == "pnts"
10610 || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points;
10611 else if (aVal == "lines") aFlag = Graphic3d_RenderingParams::PerfCounters_Lines;
10612 else if (aVal == "mem"
10613 || aVal == "gpumem"
10614 || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem;
10615 else if (aVal == "skipimmediate"
10616 || aVal == "noimmediate") aFlag = Graphic3d_RenderingParams::PerfCounters_SkipImmediate;
10617 else if (aVal == "frametime"
10618 || aVal == "frametimers"
10619 || aVal == "time") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameTime;
10620 else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic;
10621 else if (aVal == "extended"
10622 || aVal == "verbose"
10623 || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended;
10624 else if (aVal == "full"
10625 || aVal == "all") aFlag = Graphic3d_RenderingParams::PerfCounters_All;
10628 return Standard_False;
10633 theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag);
10637 theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag);
10639 return Standard_True;
10642 //! Read Graphic3d_RenderingParams::PerfCounters flags.
10643 static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue,
10644 Graphic3d_RenderingParams::PerfCounters& theFlags)
10646 TCollection_AsciiString aValue = theValue;
10647 Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE;
10648 Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE;
10649 Standard_Boolean toReset = Standard_False;
10652 Standard_Integer aSplitPos = aValue.Search ("|");
10653 if (aSplitPos <= 0)
10655 if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd))
10657 return Standard_False;
10661 theFlags = Graphic3d_RenderingParams::PerfCounters_NONE;
10663 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd);
10664 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem);
10665 return Standard_True;
10670 TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1);
10671 if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd))
10673 return Standard_False;
10676 aValue = aValue.SubString (aSplitPos + 1, aValue.Length());
10680 //=======================================================================
10681 //function : VRenderParams
10682 //purpose : Enables/disables rendering features
10683 //=======================================================================
10685 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
10686 Standard_Integer theArgNb,
10687 const char** theArgVec)
10689 Handle(V3d_View) aView = ViewerTest::CurrentView();
10690 if (aView.IsNull())
10692 Message::SendFail ("Error: no active viewer");
10696 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
10697 TCollection_AsciiString aCmdName (theArgVec[0]);
10698 aCmdName.LowerCase();
10699 if (aCmdName == "vraytrace")
10703 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
10706 else if (theArgNb == 2)
10708 TCollection_AsciiString aValue (theArgVec[1]);
10709 aValue.LowerCase();
10713 aParams.Method = Graphic3d_RM_RAYTRACING;
10717 else if (aValue == "off"
10720 aParams.Method = Graphic3d_RM_RASTERIZATION;
10726 Message::SendFail() << "Syntax error: unknown argument '" << theArgVec[1] << "'";
10732 Message::SendFail ("Syntax error: wrong number of arguments");
10739 theDI << "renderMode: ";
10740 switch (aParams.Method)
10742 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
10743 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
10746 theDI << "transparency: ";
10747 switch (aParams.TransparencyMethod)
10749 case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break;
10750 case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: "
10751 << TCollection_AsciiString (aParams.OitDepthFactor); break;
10752 case Graphic3d_RTM_DEPTH_PEELING_OIT: theDI << "Depth Peeling Order-Independent Transparency, Nb.Layers: "
10753 << TCollection_AsciiString (aParams.NbOitDepthPeelingLayers); break;
10756 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
10757 theDI << "rendScale: " << aParams.RenderResolutionScale << "\n";
10758 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
10759 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
10760 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
10761 theDI << "shadowMapRes: " << aParams.ShadowMapResolution << "\n";
10762 theDI << "shadowMapBias: " << aParams.ShadowMapBias << "\n";
10763 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
10764 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
10765 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
10766 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
10767 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
10768 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
10769 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
10770 theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
10771 theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n";
10772 theDI << "tile size (iss):" << aParams.RayTracingTileSize << "x" << aParams.RayTracingTileSize << "\n";
10773 theDI << "shadingModel: ";
10774 switch (aView->ShadingModel())
10776 case Graphic3d_TypeOfShadingModel_DEFAULT: theDI << "default"; break;
10777 case Graphic3d_TypeOfShadingModel_Unlit: theDI << "unlit"; break;
10778 case Graphic3d_TypeOfShadingModel_PhongFacet: theDI << "flat"; break;
10779 case Graphic3d_TypeOfShadingModel_Gouraud: theDI << "gouraud"; break;
10780 case Graphic3d_TypeOfShadingModel_Phong: theDI << "phong"; break;
10781 case Graphic3d_TypeOfShadingModel_Pbr: theDI << "pbr"; break;
10782 case Graphic3d_TypeOfShadingModel_PbrFacet: theDI << "pbr_facet"; break;
10786 theDI << "perfCounters:";
10787 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0)
10791 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
10795 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
10797 theDI << " structs";
10799 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0)
10801 theDI << " groups";
10803 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0)
10805 theDI << " arrays";
10807 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0)
10811 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Lines) != 0)
10815 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
10819 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0)
10821 theDI << " gpumem";
10823 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameTime) != 0)
10825 theDI << " frameTime";
10827 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_SkipImmediate) != 0)
10829 theDI << " skipimmediate";
10831 if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE)
10837 theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n";
10838 theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n";
10839 theDI << "frustum culling: " << (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On ? "on" :
10840 aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off ? "off" :
10841 "noUpdate") << "\n";
10846 bool toPrint = false, toSyncDefaults = false, toSyncAllViews = false;
10847 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10848 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
10850 Standard_CString anArg (theArgVec[anArgIter]);
10851 TCollection_AsciiString aFlag (anArg);
10853 if (anUpdateTool.parseRedrawMode (aFlag))
10857 else if (aFlag == "-echo"
10858 || aFlag == "-print")
10860 toPrint = Standard_True;
10861 anUpdateTool.Invalidate();
10863 else if (aFlag == "-reset")
10865 aParams = ViewerTest::GetViewerFromContext()->DefaultRenderingParams();
10867 else if (aFlag == "-sync"
10868 && (anArgIter + 1 < theArgNb))
10870 TCollection_AsciiString aSyncFlag (theArgVec[++anArgIter]);
10871 aSyncFlag.LowerCase();
10872 if (aSyncFlag == "default"
10873 || aSyncFlag == "defaults"
10874 || aSyncFlag == "viewer")
10876 toSyncDefaults = true;
10878 else if (aSyncFlag == "allviews"
10879 || aSyncFlag == "views")
10881 toSyncAllViews = true;
10885 Message::SendFail ("Syntax error: unknown parameter to -sync argument");
10889 else if (aFlag == "-mode"
10890 || aFlag == "-rendermode"
10891 || aFlag == "-render_mode")
10895 switch (aParams.Method)
10897 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
10898 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
10904 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
10908 else if (aFlag == "-ray"
10909 || aFlag == "-raytrace")
10913 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
10917 bool isRayTrace = true;
10918 if (anArgIter + 1 < theArgNb
10919 && Draw::ParseOnOff (theArgVec[anArgIter + 1], isRayTrace))
10923 aParams.Method = isRayTrace ? Graphic3d_RM_RAYTRACING : Graphic3d_RM_RASTERIZATION;
10925 else if (aFlag == "-rast"
10926 || aFlag == "-raster"
10927 || aFlag == "-rasterization")
10931 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
10935 bool isRaster = true;
10936 if (anArgIter + 1 < theArgNb
10937 && Draw::ParseOnOff (theArgVec[anArgIter + 1], isRaster))
10941 aParams.Method = isRaster ? Graphic3d_RM_RASTERIZATION : Graphic3d_RM_RAYTRACING;
10943 else if (aFlag == "-msaa")
10947 theDI << aParams.NbMsaaSamples << " ";
10950 else if (++anArgIter >= theArgNb)
10952 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
10956 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
10957 if (aNbSamples < 0)
10959 Message::SendFail() << "Syntax error: invalid number of MSAA samples " << aNbSamples << "";
10964 aParams.NbMsaaSamples = aNbSamples;
10967 else if (aFlag == "-linefeather"
10968 || aFlag == "-edgefeather"
10969 || aFlag == "-feather")
10973 theDI << " " << aParams.LineFeather << " ";
10976 else if (++anArgIter >= theArgNb)
10978 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
10982 TCollection_AsciiString aParam = theArgVec[anArgIter];
10983 const Standard_ShortReal aFeather = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
10984 if (aFeather <= 0.0f)
10986 Message::SendFail() << "Syntax error: invalid value of line width feather " << aFeather << ". Should be > 0";
10989 aParams.LineFeather = aFeather;
10991 else if (aFlag == "-oit")
10995 if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
10997 theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " ";
10999 else if (aParams.TransparencyMethod == Graphic3d_RTM_DEPTH_PEELING_OIT)
11001 theDI << "on, depth peeling layers: " << TCollection_AsciiString (aParams.NbOitDepthPeelingLayers) << " ";
11005 theDI << "off" << " ";
11009 else if (++anArgIter >= theArgNb)
11011 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11015 TCollection_AsciiString aParam = theArgVec[anArgIter];
11016 aParam.LowerCase();
11017 if (aParam == "peeling"
11018 || aParam == "peel")
11020 aParams.TransparencyMethod = Graphic3d_RTM_DEPTH_PEELING_OIT;
11021 if (anArgIter + 1 < theArgNb
11022 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue())
11025 const Standard_Integer aNbLayers = TCollection_AsciiString (theArgVec[anArgIter]).IntegerValue();
11028 Message::SendFail() << "Syntax error: invalid layers number specified for Depth Peeling OIT " << aNbLayers;
11031 aParams.NbOitDepthPeelingLayers = TCollection_AsciiString (theArgVec[anArgIter]).IntegerValue();
11034 else if (aParam == "weighted"
11035 || aParam == "weight")
11037 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
11038 if (anArgIter + 1 < theArgNb
11039 && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsRealValue())
11042 const Standard_ShortReal aWeight = (Standard_ShortReal)TCollection_AsciiString (theArgVec[anArgIter]).RealValue();
11043 if (aWeight < 0.f || aWeight > 1.f)
11045 Message::SendFail() << "Syntax error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]";
11048 aParams.OitDepthFactor = aWeight;
11051 else if (aParam.IsRealValue())
11053 const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
11054 if (aWeight < 0.f || aWeight > 1.f)
11056 Message::SendFail() << "Syntax error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]";
11060 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
11061 aParams.OitDepthFactor = aWeight;
11063 else if (aParam == "off")
11065 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED;
11069 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11073 else if (aFlag == "-fonthinting"
11074 || aFlag == "-fonthint")
11078 if ((aParams.FontHinting & Font_Hinting_Normal) != 0)
11080 theDI << "normal" << " ";
11082 else if ((aParams.FontHinting & Font_Hinting_Normal) != 0)
11084 theDI << "light" << " ";
11088 theDI << "off" << " ";
11092 else if (anArgIter + 1 >= theArgNb)
11094 theDI << "Syntax error at '" << theArgVec[anArgIter] << "'";
11098 TCollection_AsciiString aHintStyle (theArgVec[++anArgIter]);
11099 aHintStyle.LowerCase();
11100 if (aHintStyle == "normal"
11101 || aHintStyle == "on"
11102 || aHintStyle == "1")
11104 aParams.FontHinting = Font_Hinting(aParams.FontHinting & ~Font_Hinting_Light);
11105 aParams.FontHinting = Font_Hinting(aParams.FontHinting | Font_Hinting_Normal);
11107 else if (aHintStyle == "light")
11109 aParams.FontHinting = Font_Hinting(aParams.FontHinting & ~Font_Hinting_Normal);
11110 aParams.FontHinting = Font_Hinting(aParams.FontHinting | Font_Hinting_Light);
11112 else if (aHintStyle == "no"
11113 || aHintStyle == "off"
11114 || aHintStyle == "0")
11116 aParams.FontHinting = Font_Hinting(aParams.FontHinting & ~Font_Hinting_Normal);
11117 aParams.FontHinting = Font_Hinting(aParams.FontHinting & ~Font_Hinting_Light);
11121 theDI << "Syntax error at '" << theArgVec[anArgIter] << "'";
11125 else if (aFlag == "-fontautohinting"
11126 || aFlag == "-fontautohint")
11130 if ((aParams.FontHinting & Font_Hinting_ForceAutohint) != 0)
11132 theDI << "force" << " ";
11134 else if ((aParams.FontHinting & Font_Hinting_NoAutohint) != 0)
11136 theDI << "disallow" << " ";
11140 theDI << "auto" << " ";
11144 else if (anArgIter + 1 >= theArgNb)
11146 theDI << "Syntax error at '" << theArgVec[anArgIter] << "'";
11150 TCollection_AsciiString aHintStyle (theArgVec[++anArgIter]);
11151 aHintStyle.LowerCase();
11152 if (aHintStyle == "force")
11154 aParams.FontHinting = Font_Hinting(aParams.FontHinting & ~Font_Hinting_NoAutohint);
11155 aParams.FontHinting = Font_Hinting(aParams.FontHinting | Font_Hinting_ForceAutohint);
11157 else if (aHintStyle == "disallow"
11158 || aHintStyle == "no")
11160 aParams.FontHinting = Font_Hinting(aParams.FontHinting & ~Font_Hinting_ForceAutohint);
11161 aParams.FontHinting = Font_Hinting(aParams.FontHinting | Font_Hinting_NoAutohint);
11163 else if (aHintStyle == "auto")
11165 aParams.FontHinting = Font_Hinting(aParams.FontHinting & ~Font_Hinting_ForceAutohint);
11166 aParams.FontHinting = Font_Hinting(aParams.FontHinting & ~Font_Hinting_NoAutohint);
11170 theDI << "Syntax error at '" << theArgVec[anArgIter] << "'";
11174 else if (aFlag == "-depthprepass")
11178 theDI << (aParams.ToEnableDepthPrepass ? "on " : "off ");
11181 aParams.ToEnableDepthPrepass = Standard_True;
11182 if (anArgIter + 1 < theArgNb
11183 && Draw::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass))
11188 else if (aFlag == "-samplealphatocoverage"
11189 || aFlag == "-alphatocoverage")
11193 theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off ");
11196 aParams.ToEnableAlphaToCoverage = Standard_True;
11197 if (anArgIter + 1 < theArgNb
11198 && Draw::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage))
11203 else if (aFlag == "-rendscale"
11204 || aFlag == "-renderscale"
11205 || aFlag == "-renderresolutionscale")
11209 theDI << aParams.RenderResolutionScale << " ";
11212 else if (++anArgIter >= theArgNb)
11214 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11218 const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
11221 Message::SendFail() << "Syntax error: invalid rendering resolution scale " << aScale << "";
11226 aParams.RenderResolutionScale = Standard_ShortReal(aScale);
11229 else if (aFlag == "-raydepth"
11230 || aFlag == "-ray_depth")
11234 theDI << aParams.RaytracingDepth << " ";
11237 else if (++anArgIter >= theArgNb)
11239 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11243 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
11245 // We allow RaytracingDepth be more than 10 in case of GI enabled
11246 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
11248 Message::SendFail() << "Syntax error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]";
11253 aParams.RaytracingDepth = aDepth;
11256 else if (aFlag == "-shad"
11257 || aFlag == "-shadows")
11261 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
11265 Standard_Boolean toEnable = Standard_True;
11266 if (++anArgIter < theArgNb
11267 && !Draw::ParseOnOff (theArgVec[anArgIter], toEnable))
11271 aParams.IsShadowEnabled = toEnable;
11273 else if (aFlag == "-shadowmapresolution"
11274 || aFlag == "-shadowmap")
11278 theDI << aParams.ShadowMapResolution << " ";
11281 else if (++anArgIter >= theArgNb)
11283 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11287 aParams.ShadowMapResolution = Draw::Atoi (theArgVec[anArgIter]);
11289 else if (aFlag == "-shadowmapbias")
11293 theDI << aParams.ShadowMapBias << " ";
11296 else if (++anArgIter >= theArgNb)
11298 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11302 aParams.ShadowMapBias = (float )Draw::Atof (theArgVec[anArgIter]);
11304 else if (aFlag == "-refl"
11305 || aFlag == "-reflections")
11309 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
11313 Standard_Boolean toEnable = Standard_True;
11314 if (++anArgIter < theArgNb
11315 && !Draw::ParseOnOff (theArgVec[anArgIter], toEnable))
11319 aParams.IsReflectionEnabled = toEnable;
11321 else if (aFlag == "-fsaa")
11325 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
11329 Standard_Boolean toEnable = Standard_True;
11330 if (++anArgIter < theArgNb
11331 && !Draw::ParseOnOff (theArgVec[anArgIter], toEnable))
11335 aParams.IsAntialiasingEnabled = toEnable;
11337 else if (aFlag == "-gleam")
11341 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
11345 Standard_Boolean toEnable = Standard_True;
11346 if (++anArgIter < theArgNb
11347 && !Draw::ParseOnOff (theArgVec[anArgIter], toEnable))
11351 aParams.IsTransparentShadowEnabled = toEnable;
11353 else if (aFlag == "-gi")
11357 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
11361 Standard_Boolean toEnable = Standard_True;
11362 if (++anArgIter < theArgNb
11363 && !Draw::ParseOnOff (theArgVec[anArgIter], toEnable))
11367 aParams.IsGlobalIlluminationEnabled = toEnable;
11370 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
11373 else if (aFlag == "-blockedrng"
11374 || aFlag == "-brng")
11378 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
11382 Standard_Boolean toEnable = Standard_True;
11383 if (++anArgIter < theArgNb
11384 && !Draw::ParseOnOff (theArgVec[anArgIter], toEnable))
11388 aParams.CoherentPathTracingMode = toEnable;
11390 else if (aFlag == "-maxrad")
11394 theDI << aParams.RadianceClampingValue << " ";
11397 else if (++anArgIter >= theArgNb)
11399 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11403 const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
11404 if (!aMaxRadStr.IsRealValue (Standard_True))
11406 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11410 const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
11411 if (aMaxRadiance <= 0.0)
11413 Message::SendFail() << "Syntax error: invalid radiance clamping value " << aMaxRadiance;
11418 aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
11421 else if (aFlag == "-iss")
11425 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
11429 Standard_Boolean toEnable = Standard_True;
11430 if (++anArgIter < theArgNb
11431 && !Draw::ParseOnOff (theArgVec[anArgIter], toEnable))
11435 aParams.AdaptiveScreenSampling = toEnable;
11437 else if (aFlag == "-issatomic")
11441 theDI << (aParams.AdaptiveScreenSamplingAtomic ? "on" : "off") << " ";
11445 Standard_Boolean toEnable = Standard_True;
11446 if (++anArgIter < theArgNb
11447 && !Draw::ParseOnOff (theArgVec[anArgIter], toEnable))
11451 aParams.AdaptiveScreenSamplingAtomic = toEnable;
11453 else if (aFlag == "-issd")
11457 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
11461 Standard_Boolean toEnable = Standard_True;
11462 if (++anArgIter < theArgNb
11463 && !Draw::ParseOnOff (theArgVec[anArgIter], toEnable))
11467 aParams.ShowSamplingTiles = toEnable;
11469 else if (aFlag == "-tilesize")
11473 theDI << aParams.RayTracingTileSize << " ";
11476 else if (++anArgIter >= theArgNb)
11478 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11482 const Standard_Integer aTileSize = Draw::Atoi (theArgVec[anArgIter]);
11485 Message::SendFail() << "Syntax error: invalid size of ISS tile " << aTileSize;
11488 aParams.RayTracingTileSize = aTileSize;
11490 else if (aFlag == "-nbtiles")
11494 theDI << aParams.NbRayTracingTiles << " ";
11497 else if (++anArgIter >= theArgNb)
11499 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11503 const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]);
11506 Message::SendFail() << "Syntax error: invalid number of ISS tiles " << aNbTiles;
11509 else if (aNbTiles > 0
11511 || aNbTiles > 1024))
11513 Message::SendWarning() << "Warning: suboptimal number of ISS tiles " << aNbTiles << ". Recommended range: [64, 1024].";
11515 aParams.NbRayTracingTiles = aNbTiles;
11517 else if (aFlag == "-env")
11521 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
11525 Standard_Boolean toEnable = Standard_True;
11526 if (++anArgIter < theArgNb
11527 && !Draw::ParseOnOff (theArgVec[anArgIter], toEnable))
11531 aParams.UseEnvironmentMapBackground = toEnable;
11533 else if (aFlag == "-ignorenormalmap")
11537 theDI << (aParams.ToIgnoreNormalMapInRayTracing ? "on" : "off") << " ";
11541 Standard_Boolean toEnable = Standard_True;
11542 if (++anArgIter < theArgNb
11543 && !Draw::ParseOnOff (theArgVec[anArgIter], toEnable))
11547 aParams.ToIgnoreNormalMapInRayTracing = toEnable;
11549 else if (aFlag == "-twoside")
11553 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
11557 Standard_Boolean toEnable = Standard_True;
11558 if (++anArgIter < theArgNb
11559 && !Draw::ParseOnOff (theArgVec[anArgIter], toEnable))
11563 aParams.TwoSidedBsdfModels = toEnable;
11565 else if (aFlag == "-shademodel"
11566 || aFlag == "-shadingmodel"
11567 || aFlag == "-shading")
11571 switch (aView->ShadingModel())
11573 case Graphic3d_TypeOfShadingModel_DEFAULT: theDI << "default"; break;
11574 case Graphic3d_TypeOfShadingModel_Unlit: theDI << "unlit "; break;
11575 case Graphic3d_TypeOfShadingModel_PhongFacet: theDI << "flat "; break;
11576 case Graphic3d_TypeOfShadingModel_Gouraud: theDI << "gouraud "; break;
11577 case Graphic3d_TypeOfShadingModel_Phong: theDI << "phong "; break;
11578 case Graphic3d_TypeOfShadingModel_Pbr: theDI << "pbr"; break;
11579 case Graphic3d_TypeOfShadingModel_PbrFacet: theDI << "pbr_facet"; break;
11584 if (++anArgIter >= theArgNb)
11586 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11589 Graphic3d_TypeOfShadingModel aModel = Graphic3d_TypeOfShadingModel_DEFAULT;
11590 if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel)
11591 && aModel != Graphic3d_TypeOfShadingModel_DEFAULT)
11593 aView->SetShadingModel (aModel);
11597 Message::SendFail() << "Syntax error: unknown shading model '" << theArgVec[anArgIter] << "'";
11601 else if (aFlag == "-pbrenvpow2size"
11602 || aFlag == "-pbrenvp2s"
11603 || aFlag == "-pep2s")
11605 if (++anArgIter >= theArgNb)
11607 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11611 const Standard_Integer aPbrEnvPow2Size = Draw::Atoi (theArgVec[anArgIter]);
11612 if (aPbrEnvPow2Size < 1)
11614 Message::SendFail ("Syntax error: 'Pow2Size' of PBR Environment has to be greater or equal 1");
11617 aParams.PbrEnvPow2Size = aPbrEnvPow2Size;
11619 else if (aFlag == "-pbrenvspecmaplevelsnumber"
11620 || aFlag == "-pbrenvspecmapnblevels"
11621 || aFlag == "-pbrenvspecmaplevels"
11622 || aFlag == "-pbrenvsmln"
11623 || aFlag == "-pesmln")
11625 if (++anArgIter >= theArgNb)
11627 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11631 const Standard_Integer aPbrEnvSpecMapNbLevels = Draw::Atoi (theArgVec[anArgIter]);
11632 if (aPbrEnvSpecMapNbLevels < 2)
11634 Message::SendFail ("Syntax error: 'SpecMapLevelsNumber' of PBR Environment has to be greater or equal 2");
11637 aParams.PbrEnvSpecMapNbLevels = aPbrEnvSpecMapNbLevels;
11639 else if (aFlag == "-pbrenvbakngdiffsamplesnumber"
11640 || aFlag == "-pbrenvbakingdiffsamples"
11641 || aFlag == "-pbrenvbdsn")
11643 if (++anArgIter >= theArgNb)
11645 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11649 const Standard_Integer aPbrEnvBakingDiffNbSamples = Draw::Atoi (theArgVec[anArgIter]);
11650 if (aPbrEnvBakingDiffNbSamples < 1)
11652 Message::SendFail ("Syntax error: 'BakingDiffSamplesNumber' of PBR Environment has to be greater or equal 1");
11655 aParams.PbrEnvBakingDiffNbSamples = aPbrEnvBakingDiffNbSamples;
11657 else if (aFlag == "-pbrenvbakngspecsamplesnumber"
11658 || aFlag == "-pbrenvbakingspecsamples"
11659 || aFlag == "-pbrenvbssn")
11661 if (++anArgIter >= theArgNb)
11663 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11667 const Standard_Integer aPbrEnvBakingSpecNbSamples = Draw::Atoi(theArgVec[anArgIter]);
11668 if (aPbrEnvBakingSpecNbSamples < 1)
11670 Message::SendFail ("Syntax error: 'BakingSpecSamplesNumber' of PBR Environment has to be greater or equal 1");
11673 aParams.PbrEnvBakingSpecNbSamples = aPbrEnvBakingSpecNbSamples;
11675 else if (aFlag == "-pbrenvbakingprobability"
11676 || aFlag == "-pbrenvbp")
11678 if (++anArgIter >= theArgNb)
11680 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11683 const Standard_ShortReal aPbrEnvBakingProbability = static_cast<Standard_ShortReal>(Draw::Atof (theArgVec[anArgIter]));
11684 if (aPbrEnvBakingProbability < 0.f
11685 || aPbrEnvBakingProbability > 1.f)
11687 Message::SendFail ("Syntax error: 'BakingProbability' of PBR Environment has to be in range of [0, 1]");
11690 aParams.PbrEnvBakingProbability = aPbrEnvBakingProbability;
11692 else if (aFlag == "-resolution")
11694 if (++anArgIter >= theArgNb)
11696 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11700 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
11701 if (aResolution.IsIntegerValue())
11703 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
11707 Message::SendFail() << "Syntax error: wrong syntax at argument'" << anArg << "'";
11711 else if (aFlag == "-rebuildglsl"
11712 || aFlag == "-rebuild")
11716 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
11720 Standard_Boolean toEnable = Standard_True;
11721 if (++anArgIter < theArgNb
11722 && !Draw::ParseOnOff (theArgVec[anArgIter], toEnable))
11726 aParams.RebuildRayTracingShaders = toEnable;
11728 else if (aFlag == "-focal")
11730 if (++anArgIter >= theArgNb)
11732 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11736 TCollection_AsciiString aParam (theArgVec[anArgIter]);
11737 if (aParam.IsRealValue (Standard_True))
11739 float aFocalDist = static_cast<float> (aParam.RealValue());
11740 if (aFocalDist < 0)
11742 Message::SendFail() << "Error: parameter can't be negative at argument '" << anArg << "'";
11745 aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist;
11749 Message::SendFail() << "Syntax error at argument'" << anArg << "'";
11753 else if (aFlag == "-aperture")
11755 if (++anArgIter >= theArgNb)
11757 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11761 TCollection_AsciiString aParam(theArgVec[anArgIter]);
11762 if (aParam.IsRealValue (Standard_True))
11764 float aApertureSize = static_cast<float> (aParam.RealValue());
11765 if (aApertureSize < 0)
11767 Message::SendFail() << "Error: parameter can't be negative at argument '" << anArg << "'";
11770 aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize;
11774 Message::SendFail() << "Syntax error at argument'" << anArg << "'";
11778 else if (aFlag == "-exposure")
11780 if (++anArgIter >= theArgNb)
11782 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11786 TCollection_AsciiString anExposure (theArgVec[anArgIter]);
11787 if (anExposure.IsRealValue (Standard_True))
11789 aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
11793 Message::SendFail() << "Syntax error at argument'" << anArg << "'";
11797 else if (aFlag == "-whitepoint")
11799 if (++anArgIter >= theArgNb)
11801 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11805 TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
11806 if (aWhitePoint.IsRealValue (Standard_True))
11808 aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
11812 Message::SendFail() << "Syntax error at argument'" << anArg << "'";
11816 else if (aFlag == "-tonemapping")
11818 if (++anArgIter >= theArgNb)
11820 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11824 TCollection_AsciiString aMode (theArgVec[anArgIter]);
11827 if (aMode == "disabled")
11829 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled;
11831 else if (aMode == "filmic")
11833 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;
11837 Message::SendFail() << "Syntax error at argument'" << anArg << "'";
11841 else if (aFlag == "-performancestats"
11842 || aFlag == "-performancecounters"
11843 || aFlag == "-perfstats"
11844 || aFlag == "-perfcounters"
11845 || aFlag == "-stats")
11847 if (++anArgIter >= theArgNb)
11849 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11853 TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]);
11854 aFlagsStr.LowerCase();
11855 Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats;
11856 if (!convertToPerfStatsFlags (aFlagsStr, aFlags))
11858 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11861 aView->ChangeRenderingParams().CollectedStats = aFlags;
11862 aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE;
11864 else if (aFlag == "-perfupdateinterval"
11865 || aFlag == "-statsupdateinterval")
11867 if (++anArgIter >= theArgNb)
11869 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11872 aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
11874 else if (aFlag == "-perfchart"
11875 || aFlag == "-statschart")
11877 if (++anArgIter >= theArgNb)
11879 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11882 aView->ChangeRenderingParams().StatsNbFrames = Draw::Atoi (theArgVec[anArgIter]);
11884 else if (aFlag == "-perfchartmax"
11885 || aFlag == "-statschartmax")
11887 if (++anArgIter >= theArgNb)
11889 Message::SendFail() << "Syntax error at argument '" << anArg << "'";
11892 aView->ChangeRenderingParams().StatsMaxChartTime = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
11894 else if (aFlag == "-frustumculling"
11895 || aFlag == "-culling")
11899 theDI << ((aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On) ? "on" :
11900 (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off) ? "off" :
11901 "noUpdate") << " ";
11905 Graphic3d_RenderingParams::FrustumCulling aState = Graphic3d_RenderingParams::FrustumCulling_On;
11906 if (++anArgIter < theArgNb)
11908 TCollection_AsciiString aStateStr(theArgVec[anArgIter]);
11909 aStateStr.LowerCase();
11910 bool toEnable = true;
11911 if (Draw::ParseOnOff (aStateStr.ToCString(), toEnable))
11913 aState = toEnable ? Graphic3d_RenderingParams::FrustumCulling_On : Graphic3d_RenderingParams::FrustumCulling_Off;
11915 else if (aStateStr == "noupdate"
11916 || aStateStr == "freeze")
11918 aState = Graphic3d_RenderingParams::FrustumCulling_NoUpdate;
11925 aParams.FrustumCullingState = aState;
11929 Message::SendFail() << "Syntax error: unknown flag '" << anArg << "'";
11934 // set current view parameters as defaults
11935 if (toSyncDefaults)
11937 ViewerTest::GetViewerFromContext()->SetDefaultRenderingParams (aParams);
11939 if (toSyncAllViews)
11941 for (V3d_ListOfViewIterator aViewIter = ViewerTest::GetViewerFromContext()->DefinedViewIterator(); aViewIter.More(); aViewIter.Next())
11943 aViewIter.Value()->ChangeRenderingParams() = aParams;
11949 //=======================================================================
11950 //function : searchInfo
11952 //=======================================================================
11953 inline TCollection_AsciiString searchInfo (const TColStd_IndexedDataMapOfStringString& theDict,
11954 const TCollection_AsciiString& theKey)
11956 for (TColStd_IndexedDataMapOfStringString::Iterator anIter (theDict); anIter.More(); anIter.Next())
11958 if (TCollection_AsciiString::IsSameString (anIter.Key(), theKey, Standard_False))
11960 return anIter.Value();
11963 return TCollection_AsciiString();
11966 //=======================================================================
11967 //function : VStatProfiler
11969 //=======================================================================
11970 static Standard_Integer VStatProfiler (Draw_Interpretor& theDI,
11971 Standard_Integer theArgNb,
11972 const char** theArgVec)
11974 Handle(V3d_View) aView = ViewerTest::CurrentView();
11975 if (aView.IsNull())
11977 Message::SendFail ("Error: no active viewer");
11981 Standard_Boolean toRedraw = Standard_True;
11982 Graphic3d_RenderingParams::PerfCounters aPrevCounters = aView->ChangeRenderingParams().CollectedStats;
11983 Standard_ShortReal aPrevUpdInterval = aView->ChangeRenderingParams().StatsUpdateInterval;
11984 Graphic3d_RenderingParams::PerfCounters aRenderParams = Graphic3d_RenderingParams::PerfCounters_NONE;
11985 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
11987 Standard_CString anArg (theArgVec[anArgIter]);
11988 TCollection_AsciiString aFlag (anArg);
11990 if (aFlag == "-noredraw")
11992 toRedraw = Standard_False;
11996 Graphic3d_RenderingParams::PerfCounters aParam = Graphic3d_RenderingParams::PerfCounters_NONE;
11997 if (aFlag == "fps") aParam = Graphic3d_RenderingParams::PerfCounters_FrameRate;
11998 else if (aFlag == "cpu") aParam = Graphic3d_RenderingParams::PerfCounters_CPU;
11999 else if (aFlag == "alllayers"
12000 || aFlag == "layers") aParam = Graphic3d_RenderingParams::PerfCounters_Layers;
12001 else if (aFlag == "allstructs"
12002 || aFlag == "allstructures"
12003 || aFlag == "structs"
12004 || aFlag == "structures") aParam = Graphic3d_RenderingParams::PerfCounters_Structures;
12005 else if (aFlag == "groups") aParam = Graphic3d_RenderingParams::PerfCounters_Groups;
12006 else if (aFlag == "allarrays"
12007 || aFlag == "fillarrays"
12008 || aFlag == "linearrays"
12009 || aFlag == "pointarrays"
12010 || aFlag == "textarrays") aParam = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
12011 else if (aFlag == "triangles") aParam = Graphic3d_RenderingParams::PerfCounters_Triangles;
12012 else if (aFlag == "lines") aParam = Graphic3d_RenderingParams::PerfCounters_Lines;
12013 else if (aFlag == "points") aParam = Graphic3d_RenderingParams::PerfCounters_Points;
12014 else if (aFlag == "geommem"
12015 || aFlag == "texturemem"
12016 || aFlag == "framemem") aParam = Graphic3d_RenderingParams::PerfCounters_EstimMem;
12017 else if (aFlag == "elapsedframe"
12018 || aFlag == "cpuframeaverage"
12019 || aFlag == "cpupickingaverage"
12020 || aFlag == "cpucullingaverage"
12021 || aFlag == "cpudynaverage"
12022 || aFlag == "cpuframemax"
12023 || aFlag == "cpupickingmax"
12024 || aFlag == "cpucullingmax"
12025 || aFlag == "cpudynmax") aParam = Graphic3d_RenderingParams::PerfCounters_FrameTime;
12028 Message::SendFail() << "Error: unknown argument '" << theArgVec[anArgIter] << "'";
12032 aRenderParams = Graphic3d_RenderingParams::PerfCounters (aRenderParams | aParam);
12036 if (aRenderParams != Graphic3d_RenderingParams::PerfCounters_NONE)
12038 aView->ChangeRenderingParams().CollectedStats =
12039 Graphic3d_RenderingParams::PerfCounters (aView->RenderingParams().CollectedStats | aRenderParams);
12043 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
12045 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
12048 TColStd_IndexedDataMapOfStringString aDict;
12049 aView->StatisticInformation (aDict);
12051 aView->ChangeRenderingParams().CollectedStats = aPrevCounters;
12053 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
12055 Standard_CString anArg(theArgVec[anArgIter]);
12056 TCollection_AsciiString aFlag(anArg);
12058 if (aFlag == "fps")
12060 theDI << searchInfo (aDict, "FPS") << " ";
12062 else if (aFlag == "cpu")
12064 theDI << searchInfo (aDict, "CPU FPS") << " ";
12066 else if (aFlag == "alllayers")
12068 theDI << searchInfo (aDict, "Layers") << " ";
12070 else if (aFlag == "layers")
12072 theDI << searchInfo (aDict, "Rendered layers") << " ";
12074 else if (aFlag == "allstructs"
12075 || aFlag == "allstructures")
12077 theDI << searchInfo (aDict, "Structs") << " ";
12079 else if (aFlag == "structs"
12080 || aFlag == "structures")
12082 TCollection_AsciiString aRend = searchInfo (aDict, "Rendered structs");
12083 if (aRend.IsEmpty()) // all structures rendered
12085 aRend = searchInfo (aDict, "Structs");
12087 theDI << aRend << " ";
12089 else if (aFlag == "groups")
12091 theDI << searchInfo (aDict, "Rendered groups") << " ";
12093 else if (aFlag == "allarrays")
12095 theDI << searchInfo (aDict, "Rendered arrays") << " ";
12097 else if (aFlag == "fillarrays")
12099 theDI << searchInfo (aDict, "Rendered [fill] arrays") << " ";
12101 else if (aFlag == "linearrays")
12103 theDI << searchInfo (aDict, "Rendered [line] arrays") << " ";
12105 else if (aFlag == "pointarrays")
12107 theDI << searchInfo (aDict, "Rendered [point] arrays") << " ";
12109 else if (aFlag == "textarrays")
12111 theDI << searchInfo (aDict, "Rendered [text] arrays") << " ";
12113 else if (aFlag == "triangles")
12115 theDI << searchInfo (aDict, "Rendered triangles") << " ";
12117 else if (aFlag == "points")
12119 theDI << searchInfo (aDict, "Rendered points") << " ";
12121 else if (aFlag == "geommem")
12123 theDI << searchInfo (aDict, "GPU Memory [geometry]") << " ";
12125 else if (aFlag == "texturemem")
12127 theDI << searchInfo (aDict, "GPU Memory [textures]") << " ";
12129 else if (aFlag == "framemem")
12131 theDI << searchInfo (aDict, "GPU Memory [frames]") << " ";
12133 else if (aFlag == "elapsedframe")
12135 theDI << searchInfo (aDict, "Elapsed Frame (average)") << " ";
12137 else if (aFlag == "cpuframe_average")
12139 theDI << searchInfo (aDict, "CPU Frame (average)") << " ";
12141 else if (aFlag == "cpupicking_average")
12143 theDI << searchInfo (aDict, "CPU Picking (average)") << " ";
12145 else if (aFlag == "cpuculling_average")
12147 theDI << searchInfo (aDict, "CPU Culling (average)") << " ";
12149 else if (aFlag == "cpudyn_average")
12151 theDI << searchInfo (aDict, "CPU Dynamics (average)") << " ";
12153 else if (aFlag == "cpuframe_max")
12155 theDI << searchInfo (aDict, "CPU Frame (max)") << " ";
12157 else if (aFlag == "cpupicking_max")
12159 theDI << searchInfo (aDict, "CPU Picking (max)") << " ";
12161 else if (aFlag == "cpuculling_max")
12163 theDI << searchInfo (aDict, "CPU Culling (max)") << " ";
12165 else if (aFlag == "cpudyn_max")
12167 theDI << searchInfo (aDict, "CPU Dynamics (max)") << " ";
12175 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
12177 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
12179 theDI << "Statistic info:\n" << aView->StatisticInformation();
12184 //=======================================================================
12185 //function : VXRotate
12187 //=======================================================================
12188 static Standard_Integer VXRotate (Draw_Interpretor& di,
12189 Standard_Integer argc,
12190 const char ** argv)
12192 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
12193 if (aContext.IsNull())
12195 di << argv[0] << "ERROR : use 'vinit' command before \n";
12201 di << "ERROR : Usage : " << argv[0] << " name angle\n";
12205 TCollection_AsciiString aName (argv[1]);
12206 Standard_Real anAngle = Draw::Atof (argv[2]);
12209 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
12210 Handle(AIS_InteractiveObject) anIObj;
12211 if (!aMap.Find2 (aName, anIObj))
12213 di << "Use 'vdisplay' before\n";
12217 gp_Trsf aTransform;
12218 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
12219 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
12221 aContext->SetLocation (anIObj, aTransform);
12222 aContext->UpdateCurrentViewer();
12228 //! Structure for setting AIS_Manipulator::SetPart() property.
12229 struct ManipAxisModeOnOff
12231 Standard_Integer Axis;
12232 AIS_ManipulatorMode Mode;
12233 Standard_Boolean ToEnable;
12235 ManipAxisModeOnOff() : Axis (-1), Mode (AIS_MM_None), ToEnable (false) {}
12238 enum ManipAjustPosition
12240 ManipAjustPosition_Off,
12241 ManipAjustPosition_Center,
12242 ManipAjustPosition_Location,
12243 ManipAjustPosition_ShapeLocation,
12247 //===============================================================================================
12248 //function : VManipulator
12250 //===============================================================================================
12251 static int VManipulator (Draw_Interpretor& theDi,
12252 Standard_Integer theArgsNb,
12253 const char** theArgVec)
12255 Handle(V3d_View) aCurrentView = ViewerTest::CurrentView();
12256 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
12257 if (aCurrentView.IsNull()
12258 || aViewer.IsNull())
12260 Message::SendFail ("Error: no active viewer");
12264 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
12265 Standard_Integer anArgIter = 1;
12266 Handle(AIS_Manipulator) aManipulator;
12267 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
12268 TCollection_AsciiString aName;
12270 Standard_Integer toAutoActivate = -1, toFollowTranslation = -1, toFollowRotation = -1, toFollowDragging = -1, isZoomable = -1;
12271 Standard_Real aGap = -1.0, aSize = -1.0;
12272 NCollection_Sequence<ManipAxisModeOnOff> aParts;
12273 gp_XYZ aLocation (RealLast(), RealLast(), RealLast()), aVDir, anXDir;
12275 bool toDetach = false;
12276 AIS_Manipulator::OptionsForAttach anAttachOptions;
12277 Handle(AIS_InteractiveObject) anAttachObject;
12278 Handle(V3d_View) aViewAffinity;
12279 ManipAjustPosition anAttachPos = ManipAjustPosition_Off;
12281 Graphic3d_Vec2i aMousePosFrom(IntegerLast(), IntegerLast());
12282 Graphic3d_Vec2i aMousePosTo (IntegerLast(), IntegerLast());
12283 Standard_Integer toStopMouseTransform = -1;
12284 // explicit transformation
12287 Standard_Real aTmpReal = 0.0;
12288 gp_XYZ aRotPnt, aRotAxis;
12289 for (; anArgIter < theArgsNb; ++anArgIter)
12291 TCollection_AsciiString anArg (theArgVec[anArgIter]);
12293 if (anUpdateTool.parseRedrawMode (anArg))
12297 else if (anArg == "-help")
12299 theDi.PrintHelp (theArgVec[0]);
12303 else if (anArg == "-autoactivate"
12304 || anArg == "-noautoactivate")
12306 toAutoActivate = Draw::ParseOnOffNoIterator (theArgsNb, theArgVec, anArgIter) ? 1 : 0;
12308 else if (anArg == "-followtranslation"
12309 || anArg == "-nofollowtranslation")
12311 toFollowTranslation = Draw::ParseOnOffNoIterator (theArgsNb, theArgVec, anArgIter) ? 1 : 0;
12313 else if (anArg == "-followrotation"
12314 || anArg == "-nofollowrotation")
12316 toFollowRotation = Draw::ParseOnOffNoIterator (theArgsNb, theArgVec, anArgIter) ? 1 : 0;
12318 else if (anArg == "-followdragging"
12319 || anArg == "-nofollowdragging")
12321 toFollowDragging = Draw::ParseOnOffNoIterator (theArgsNb, theArgVec, anArgIter) ? 1 : 0;
12323 else if (anArg == "-gap"
12324 && anArgIter + 1 < theArgsNb
12325 && Draw::ParseReal (theArgVec[anArgIter + 1], aGap)
12330 else if (anArg == "-size"
12331 && anArgIter + 1 < theArgsNb
12332 && Draw::ParseReal (theArgVec[anArgIter + 1], aSize)
12337 else if ((anArg == "-part" && anArgIter + 3 < theArgsNb)
12338 || (anArg == "-parts" && anArgIter + 2 < theArgsNb))
12340 ManipAxisModeOnOff aPart;
12341 Standard_Integer aMode = 0;
12342 if (anArg == "-part")
12344 if (!Draw::ParseInteger (theArgVec[++anArgIter], aPart.Axis)
12345 || aPart.Axis < 0 || aPart.Axis > 3)
12347 Message::SendFail() << "Syntax error: -part axis '" << theArgVec[anArgIter] << "' is out of range [1, 3]";
12351 if (!Draw::ParseInteger (theArgVec[++anArgIter], aMode)
12352 || aMode < 1 || aMode > 4)
12354 Message::SendFail() << "Syntax error: -part mode '" << theArgVec[anArgIter] << "' is out of range [1, 4]";
12357 if (!Draw::ParseOnOff (theArgVec[++anArgIter], aPart.ToEnable))
12359 Message::SendFail() << "Syntax error: -part value on/off '" << theArgVec[anArgIter] << "' is incorrect";
12362 aPart.Mode = static_cast<AIS_ManipulatorMode> (aMode);
12363 aParts.Append (aPart);
12365 else if (anArg == "-pos"
12366 && anArgIter + 3 < theArgsNb
12367 && parseXYZ (theArgVec + anArgIter + 1, aLocation))
12370 if (anArgIter + 3 < theArgsNb
12371 && parseXYZ (theArgVec + anArgIter + 1, aVDir)
12372 && aVDir.Modulus() > Precision::Confusion())
12376 if (anArgIter + 3 < theArgsNb
12377 && parseXYZ (theArgVec + anArgIter + 1, anXDir)
12378 && anXDir.Modulus() > Precision::Confusion())
12383 else if (anArg == "-zoomable"
12384 || anArg == "-notzoomable")
12386 isZoomable = Draw::ParseOnOffNoIterator (theArgsNb, theArgVec, anArgIter) ? 1 : 0;
12389 else if (anArg == "-adjustposition"
12390 || anArg == "-noadjustposition")
12392 anAttachPos = ManipAjustPosition_Center;
12393 if (anArgIter + 1 < theArgsNb)
12395 TCollection_AsciiString aPosName (theArgVec[++anArgIter]);
12396 aPosName.LowerCase();
12397 if (aPosName == "0")
12399 anAttachPos = ManipAjustPosition_Off;
12401 else if (aPosName == "1"
12402 || aPosName == "center")
12404 anAttachPos = ManipAjustPosition_Center;
12406 else if (aPosName == "transformation"
12407 || aPosName == "trsf"
12408 || aPosName == "location"
12409 || aPosName == "loc")
12411 anAttachPos = ManipAjustPosition_Location;
12413 else if (aPosName == "shapelocation"
12414 || aPosName == "shapeloc")
12416 anAttachPos = ManipAjustPosition_ShapeLocation;
12423 anAttachOptions.SetAdjustPosition (anAttachPos == ManipAjustPosition_Center);
12425 else if (anArg == "-adjustsize"
12426 || anArg == "-noadjustsize")
12428 anAttachOptions.SetAdjustSize (Draw::ParseOnOffNoIterator (theArgsNb, theArgVec, anArgIter) ? 1 : 0);
12430 else if (anArg == "-enablemodes"
12431 || anArg == "-enablemodes")
12433 anAttachOptions.SetEnableModes (Draw::ParseOnOffNoIterator (theArgsNb, theArgVec, anArgIter) ? 1 : 0);
12436 else if (anArg == "-starttransform"
12437 && anArgIter + 2 < theArgsNb
12438 && Draw::ParseInteger (theArgVec[anArgIter + 1], aMousePosFrom.x())
12439 && Draw::ParseInteger (theArgVec[anArgIter + 2], aMousePosFrom.y()))
12443 else if (anArg == "-transform"
12444 && anArgIter + 2 < theArgsNb
12445 && Draw::ParseInteger (theArgVec[anArgIter + 1], aMousePosTo.x())
12446 && Draw::ParseInteger (theArgVec[anArgIter + 2], aMousePosTo.y()))
12450 else if (anArg == "-stoptransform")
12452 toStopMouseTransform = 1;
12453 if (anArgIter + 1 < theArgsNb
12454 && TCollection_AsciiString::IsSameString (theArgVec[anArgIter + 1], "abort", false))
12457 toStopMouseTransform = 0;
12461 else if (anArg == "-move"
12462 && anArgIter + 3 < theArgsNb
12463 && parseXYZ (theArgVec + anArgIter + 1, aTmpXYZ))
12466 aTrsf.SetTranslationPart (aTmpXYZ);
12468 else if (anArg == "-scale"
12469 && anArgIter + 1 < theArgsNb
12470 && Draw::ParseReal (theArgVec[anArgIter + 1], aTmpReal))
12473 aTrsf.SetScale (gp_Pnt(), aTmpReal);
12475 else if (anArg == "-rotate"
12476 && anArgIter + 7 < theArgsNb
12477 && parseXYZ (theArgVec + anArgIter + 1, aRotPnt)
12478 && parseXYZ (theArgVec + anArgIter + 4, aRotAxis)
12479 && Draw::ParseReal (theArgVec[anArgIter + 7], aTmpReal))
12482 aTrsf.SetRotation (gp_Ax1 (gp_Pnt (aRotPnt), gp_Dir (aRotAxis)), aTmpReal);
12485 else if (anArg == "-detach")
12489 else if (anArg == "-attach"
12490 && anArgIter + 1 < theArgsNb)
12492 TCollection_AsciiString anObjName (theArgVec[++anArgIter]);
12493 if (!aMapAIS.Find2 (anObjName, anAttachObject))
12495 Message::SendFail() << "Syntax error: AIS object '" << anObjName << "' does not exist";
12499 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (aMapAIS); anIter.More(); anIter.Next())
12501 Handle(AIS_Manipulator) aManip = Handle(AIS_Manipulator)::DownCast (anIter.Key1());
12502 if (!aManip.IsNull()
12503 && aManip->IsAttached()
12504 && aManip->Object() == anAttachObject)
12506 Message::SendFail() << "Syntax error: AIS object '" << anObjName << "' already has manipulator";
12511 else if (anArg == "-view"
12512 && anArgIter + 1 < theArgsNb
12513 && aViewAffinity.IsNull())
12515 TCollection_AsciiString aViewString (theArgVec[++anArgIter]);
12516 if (aViewString == "active")
12518 aViewAffinity = ViewerTest::CurrentView();
12520 else // Check view name
12522 ViewerTest_Names aViewNames (aViewString);
12523 if (!ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
12525 Message::SendFail() << "Syntax error: wrong view name '" << aViewString << "'";
12528 aViewAffinity = ViewerTest_myViews.Find1 (aViewNames.GetViewName());
12529 if (aViewAffinity.IsNull())
12531 Message::SendFail() << "Syntax error: cannot find view with name '" << aViewString << "'";
12536 else if (aName.IsEmpty())
12538 aName = theArgVec[anArgIter];
12539 if (!aMapAIS.IsBound2 (aName))
12541 aManipulator = new AIS_Manipulator();
12542 aManipulator->SetModeActivationOnDetection (true);
12543 aMapAIS.Bind (aManipulator, aName);
12547 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
12548 if (aManipulator.IsNull())
12550 Message::SendFail() << "Syntax error: \"" << aName << "\" is not an AIS manipulator";
12557 theDi << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'";
12561 if (aName.IsEmpty())
12563 Message::SendFail ("Syntax error: please specify AIS manipulator's name as the first argument");
12567 && aManipulator.IsNull())
12569 aManipulator = new AIS_Manipulator();
12570 aManipulator->SetModeActivationOnDetection (true);
12571 aMapAIS.Bind (aManipulator, aName);
12574 // -----------------------------------------
12575 // change properties of manipulator instance
12576 // -----------------------------------------
12578 if (toAutoActivate != -1)
12580 aManipulator->SetModeActivationOnDetection (toAutoActivate == 1);
12582 if (toFollowTranslation != -1)
12584 aManipulator->ChangeTransformBehavior().SetFollowTranslation (toFollowTranslation == 1);
12586 if (toFollowRotation != -1)
12588 aManipulator->ChangeTransformBehavior().SetFollowRotation (toFollowRotation == 1);
12590 if (toFollowDragging != -1)
12592 aManipulator->ChangeTransformBehavior().SetFollowDragging (toFollowDragging == 1);
12596 aManipulator->SetGap ((float )aGap);
12599 for (NCollection_Sequence<ManipAxisModeOnOff>::Iterator aPartIter (aParts); aPartIter.More(); aPartIter.Next())
12601 const ManipAxisModeOnOff& aPart = aPartIter.Value();
12602 if (aPart.Axis == -1)
12604 aManipulator->SetPart (aPart.Mode, aPart.ToEnable);
12608 aManipulator->SetPart (aPart.Axis, aPart.Mode, aPart.ToEnable);
12614 aManipulator->SetSize ((float )aSize);
12616 if (isZoomable != -1)
12618 aManipulator->SetZoomPersistence (isZoomable == 0);
12620 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
12622 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
12623 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
12627 // ----------------------------------
12628 // detach existing manipulator object
12629 // ----------------------------------
12633 aManipulator->Detach();
12634 aMapAIS.UnBind2 (aName);
12635 ViewerTest::GetAISContext()->Remove (aManipulator, false);
12638 // ---------------------------------------------------
12639 // attach, detach or access manipulator from an object
12640 // ---------------------------------------------------
12642 if (!anAttachObject.IsNull())
12644 aManipulator->Attach (anAttachObject, anAttachOptions);
12646 if (!aViewAffinity.IsNull())
12648 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
12649 anIter.More(); anIter.Next())
12651 ViewerTest::GetAISContext()->SetViewAffinity (aManipulator, anIter.Value(), false);
12653 ViewerTest::GetAISContext()->SetViewAffinity (aManipulator, aViewAffinity, true);
12656 if (anAttachPos != ManipAjustPosition_Off
12657 && aManipulator->IsAttached()
12658 && (anAttachObject.IsNull() || anAttachPos != ManipAjustPosition_Center))
12660 gp_Ax2 aPosition = gp::XOY();
12661 const gp_Trsf aBaseTrsf = aManipulator->Object()->LocalTransformation();
12662 switch (anAttachPos)
12664 case ManipAjustPosition_Off:
12668 case ManipAjustPosition_Location:
12670 aPosition = gp::XOY().Transformed (aBaseTrsf);
12673 case ManipAjustPosition_ShapeLocation:
12675 if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aManipulator->Object()))
12677 aPosition = gp::XOY().Transformed (aBaseTrsf * aShapePrs->Shape().Location());
12681 Message::SendFail() << "Syntax error: manipulator is not attached to shape";
12686 case ManipAjustPosition_Center:
12689 for (AIS_ManipulatorObjectSequence::Iterator anObjIter (*aManipulator->Objects()); anObjIter.More(); anObjIter.Next())
12692 anObjIter.Value()->BoundingBox (anObjBox);
12693 aBox.Add (anObjBox);
12695 aBox = aBox.FinitePart();
12696 if (!aBox.IsVoid())
12698 const gp_Pnt aCenter = (aBox.CornerMin().XYZ() + aBox.CornerMax().XYZ()) * 0.5;
12699 aPosition.SetLocation (aCenter);
12704 aManipulator->SetPosition (aPosition);
12706 if (!Precision::IsInfinite (aLocation.X()))
12708 if (aVDir.Modulus() <= Precision::Confusion())
12710 aVDir = aManipulator->Position().Direction().XYZ();
12712 if (anXDir.Modulus() <= Precision::Confusion())
12714 anXDir = aManipulator->Position().XDirection().XYZ();
12716 aManipulator->SetPosition (gp_Ax2 (gp_Pnt (aLocation), gp_Dir (aVDir), gp_Dir (anXDir)));
12719 // --------------------------------------
12720 // apply transformation using manipulator
12721 // --------------------------------------
12723 if (aMousePosFrom.x() != IntegerLast())
12725 aManipulator->StartTransform (aMousePosFrom.x(), aMousePosFrom.y(), ViewerTest::CurrentView());
12727 if (aMousePosTo.x() != IntegerLast())
12729 aManipulator->Transform (aMousePosTo.x(), aMousePosTo.y(), ViewerTest::CurrentView());
12731 if (toStopMouseTransform != -1)
12733 aManipulator->StopTransform (toStopMouseTransform == 1);
12736 if (aTrsf.Form() != gp_Identity)
12738 aManipulator->Transform (aTrsf);
12741 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
12743 ViewerTest::GetAISContext()->Redisplay (aManipulator, true);
12748 //===============================================================================================
12749 //function : VSelectionProperties
12751 //===============================================================================================
12752 static int VSelectionProperties (Draw_Interpretor& theDi,
12753 Standard_Integer theArgsNb,
12754 const char** theArgVec)
12756 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
12759 Message::SendFail ("Error: no active viewer");
12763 if (TCollection_AsciiString (theArgVec[0]) == "vhighlightselected")
12765 // handle obsolete alias
12766 bool toEnable = true;
12769 theDi << (aCtx->ToHilightSelected() ? "on" : "off");
12772 else if (theArgsNb != 2
12773 || !Draw::ParseOnOff (theArgVec[1], toEnable))
12775 Message::SendFail ("Syntax error: wrong number of parameters");
12778 if (toEnable != aCtx->ToHilightSelected())
12780 aCtx->ClearDetected();
12781 aCtx->SetToHilightSelected (toEnable);
12786 Standard_Boolean toPrint = theArgsNb == 1;
12787 Standard_Boolean toRedraw = Standard_False;
12788 Standard_Integer anArgIter = 1;
12789 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
12790 if (anArgIter < theArgsNb)
12792 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
12793 anArgFirst.LowerCase();
12795 if (anArgFirst == "dynhighlight"
12796 || anArgFirst == "dynhilight"
12797 || anArgFirst == "dynamichighlight"
12798 || anArgFirst == "dynamichilight")
12800 aType = Prs3d_TypeOfHighlight_Dynamic;
12802 else if (anArgFirst == "localdynhighlight"
12803 || anArgFirst == "localdynhilight"
12804 || anArgFirst == "localdynamichighlight"
12805 || anArgFirst == "localdynamichilight")
12807 aType = Prs3d_TypeOfHighlight_LocalDynamic;
12809 else if (anArgFirst == "selhighlight"
12810 || anArgFirst == "selhilight"
12811 || anArgFirst == "selectedhighlight"
12812 || anArgFirst == "selectedhilight")
12814 aType = Prs3d_TypeOfHighlight_Selected;
12816 else if (anArgFirst == "localselhighlight"
12817 || anArgFirst == "localselhilight"
12818 || anArgFirst == "localselectedhighlight"
12819 || anArgFirst == "localselectedhilight")
12821 aType = Prs3d_TypeOfHighlight_LocalSelected;
12828 for (; anArgIter < theArgsNb; ++anArgIter)
12830 TCollection_AsciiString anArg (theArgVec[anArgIter]);
12832 if (anArg == "-help")
12834 theDi.PrintHelp (theArgVec[0]);
12837 else if (anArg == "-print")
12839 toPrint = Standard_True;
12841 else if (anArg == "-autoactivate")
12843 Standard_Boolean toEnable = Standard_True;
12844 if (anArgIter + 1 < theArgsNb
12845 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12849 aCtx->SetAutoActivateSelection (toEnable);
12851 else if (anArg == "-automatichighlight"
12852 || anArg == "-automatichilight"
12853 || anArg == "-autohighlight"
12854 || anArg == "-autohilight")
12856 Standard_Boolean toEnable = Standard_True;
12857 if (anArgIter + 1 < theArgsNb
12858 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12862 aCtx->ClearSelected (false);
12863 aCtx->ClearDetected();
12864 aCtx->SetAutomaticHilight (toEnable);
12867 else if (anArg == "-highlightselected"
12868 || anArg == "-hilightselected")
12870 Standard_Boolean toEnable = Standard_True;
12871 if (anArgIter + 1 < theArgsNb
12872 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12876 aCtx->ClearDetected();
12877 aCtx->SetToHilightSelected (toEnable);
12880 else if (anArg == "-pickstrategy"
12881 || anArg == "-pickingstrategy")
12883 if (++anArgIter >= theArgsNb)
12885 Message::SendFail ("Syntax error: type of highlighting is undefined");
12889 SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
12890 TCollection_AsciiString aVal (theArgVec[anArgIter]);
12892 if (aVal == "first"
12893 || aVal == "firstaccepted"
12894 || aVal == "firstacceptable")
12896 aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
12898 else if (aVal == "topmost"
12899 || aVal == "onlyTopmost")
12901 aStrategy = SelectMgr_PickingStrategy_OnlyTopmost;
12905 Message::SendFail() << "Syntax error: unknown picking strategy '" << aVal << "'";
12909 aCtx->SetPickingStrategy (aStrategy);
12911 else if (anArg == "-pixtol"
12912 && anArgIter + 1 < theArgsNb)
12914 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
12916 else if (anArg == "-preferclosest")
12918 bool toPreferClosest = true;
12919 if (anArgIter + 1 < theArgsNb
12920 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toPreferClosest))
12924 aCtx->MainSelector()->SetPickClosest (toPreferClosest);
12926 else if ((anArg == "-depthtol"
12927 || anArg == "-depthtolerance")
12928 && anArgIter + 1 < theArgsNb)
12930 TCollection_AsciiString aTolType (theArgVec[++anArgIter]);
12931 aTolType.LowerCase();
12932 if (aTolType == "uniform")
12934 if (anArgIter + 1 >= theArgsNb)
12936 Message::SendFail() << "Syntax error: wrong number of arguments";
12939 aCtx->MainSelector()->SetDepthTolerance (SelectMgr_TypeOfDepthTolerance_Uniform,
12940 Draw::Atof (theArgVec[++anArgIter]));
12942 else if (aTolType == "uniformpx")
12944 if (anArgIter + 1 >= theArgsNb)
12946 Message::SendFail() << "Syntax error: wrong number of arguments";
12949 aCtx->MainSelector()->SetDepthTolerance (SelectMgr_TypeOfDepthTolerance_UniformPixels,
12950 Draw::Atof (theArgVec[++anArgIter]));
12952 else if (aTolType == "sensfactor")
12954 aCtx->MainSelector()->SetDepthTolerance (SelectMgr_TypeOfDepthTolerance_SensitivityFactor, 0.0);
12958 Message::SendFail() << "Syntax error at '" << aTolType << "'";
12962 else if ((anArg == "-mode"
12963 || anArg == "-dispmode")
12964 && anArgIter + 1 < theArgsNb)
12966 if (aType == Prs3d_TypeOfHighlight_None)
12968 Message::SendFail ("Syntax error: type of highlighting is undefined");
12972 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
12973 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12974 aStyle->SetDisplayMode (aDispMode);
12975 toRedraw = Standard_True;
12977 else if (anArg == "-layer"
12978 && anArgIter + 1 < theArgsNb)
12980 if (aType == Prs3d_TypeOfHighlight_None)
12982 Message::SendFail ("Syntax error: type of highlighting is undefined");
12987 Graphic3d_ZLayerId aNewLayer = Graphic3d_ZLayerId_UNKNOWN;
12988 if (!ViewerTest::ParseZLayer (theArgVec[anArgIter], aNewLayer))
12990 Message::SendFail() << "Syntax error at " << theArgVec[anArgIter];
12994 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12995 aStyle->SetZLayer (aNewLayer);
12996 toRedraw = Standard_True;
12998 else if (anArg == "-hicolor"
12999 || anArg == "-selcolor"
13000 || anArg == "-color")
13002 if (anArg.StartsWith ("-hi"))
13004 aType = Prs3d_TypeOfHighlight_Dynamic;
13006 else if (anArg.StartsWith ("-sel"))
13008 aType = Prs3d_TypeOfHighlight_Selected;
13010 else if (aType == Prs3d_TypeOfHighlight_None)
13012 Message::SendFail ("Syntax error: type of highlighting is undefined");
13016 Quantity_Color aColor;
13017 Standard_Integer aNbParsed = Draw::ParseColor (theArgsNb - anArgIter - 1,
13018 theArgVec + anArgIter + 1,
13020 if (aNbParsed == 0)
13022 Message::SendFail ("Syntax error: need more arguments");
13025 anArgIter += aNbParsed;
13027 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13028 aStyle->SetColor (aColor);
13029 toRedraw = Standard_True;
13031 else if ((anArg == "-transp"
13032 || anArg == "-transparency"
13033 || anArg == "-hitransp"
13034 || anArg == "-seltransp"
13035 || anArg == "-hitransplocal"
13036 || anArg == "-seltransplocal")
13037 && anArgIter + 1 < theArgsNb)
13039 if (anArg.StartsWith ("-hi"))
13041 aType = Prs3d_TypeOfHighlight_Dynamic;
13043 else if (anArg.StartsWith ("-sel"))
13045 aType = Prs3d_TypeOfHighlight_Selected;
13047 else if (aType == Prs3d_TypeOfHighlight_None)
13049 Message::SendFail ("Syntax error: type of highlighting is undefined");
13053 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
13054 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13055 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
13056 toRedraw = Standard_True;
13058 else if ((anArg == "-mat"
13059 || anArg == "-material")
13060 && anArgIter + 1 < theArgsNb)
13062 if (aType == Prs3d_TypeOfHighlight_None)
13064 Message::SendFail ("Syntax error: type of highlighting is undefined");
13068 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
13069 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
13070 if (aMatName != Graphic3d_NameOfMaterial_DEFAULT)
13073 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
13074 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
13075 Graphic3d_MaterialAspect aMat (aMatName);
13076 aMat.SetColor (aStyle->Color());
13077 aMat.SetTransparency (aStyle->Transparency());
13078 anAspect->SetFrontMaterial (aMat);
13079 anAspect->SetInteriorColor (aStyle->Color());
13080 aStyle->SetBasicFillAreaAspect (anAspect);
13084 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
13086 toRedraw = Standard_True;
13090 Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
13097 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
13098 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
13099 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
13100 theDi << "Auto-highlight : " << (aCtx->AutomaticHilight() ? "On" : "Off") << "\n";
13101 theDi << "Highlight selected : " << (aCtx->ToHilightSelected() ? "On" : "Off") << "\n";
13102 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
13103 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
13104 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
13105 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
13106 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
13107 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
13108 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
13109 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
13110 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
13113 if (aCtx->NbSelected() != 0 && toRedraw)
13115 aCtx->HilightSelected (Standard_True);
13121 //===============================================================================================
13122 //function : VDumpSelectionImage
13124 //===============================================================================================
13125 static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
13126 Standard_Integer theArgsNb,
13127 const char** theArgVec)
13129 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
13130 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
13131 if (aContext.IsNull())
13133 Message::SendFail ("Error: no active viewer");
13137 TCollection_AsciiString aFile;
13138 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
13139 Handle(Graphic3d_Camera) aCustomCam;
13140 Image_Format anImgFormat = Image_Format_BGR;
13141 Standard_Integer aPickedIndex = 1;
13142 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
13144 TCollection_AsciiString aParam (theArgVec[anArgIter]);
13145 aParam.LowerCase();
13146 if (aParam == "-type")
13148 if (++anArgIter >= theArgsNb)
13150 Message::SendFail ("Syntax error: wrong number parameters of flag '-type'");
13154 TCollection_AsciiString aValue (theArgVec[anArgIter]);
13155 aValue.LowerCase();
13156 if (aValue == "depth"
13157 || aValue == "normdepth"
13158 || aValue == "normalizeddepth")
13160 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
13161 anImgFormat = Image_Format_GrayF;
13163 else if (aValue == "depthinverted"
13164 || aValue == "normdepthinverted"
13165 || aValue == "normalizeddepthinverted"
13166 || aValue == "inverted")
13168 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
13169 anImgFormat = Image_Format_GrayF;
13171 else if (aValue == "unnormdepth"
13172 || aValue == "unnormalizeddepth")
13174 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
13175 anImgFormat = Image_Format_GrayF;
13177 else if (aValue == "objectcolor"
13178 || aValue == "object"
13179 || aValue == "color")
13181 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
13183 else if (aValue == "entitycolor"
13184 || aValue == "entity")
13186 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
13188 else if (aValue == "entitytypecolor"
13189 || aValue == "entitytype")
13191 aType = StdSelect_TypeOfSelectionImage_ColoredEntityType;
13193 else if (aValue == "ownercolor"
13194 || aValue == "owner")
13196 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
13198 else if (aValue == "selectionmodecolor"
13199 || aValue == "selectionmode"
13200 || aValue == "selmodecolor"
13201 || aValue == "selmode")
13203 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
13205 else if (aValue == "surfnormal"
13206 || aValue == "surfacenormal"
13207 || aValue == "normal")
13209 aType = StdSelect_TypeOfSelectionImage_SurfaceNormal;
13213 Message::SendFail() << "Syntax error: unknown type '" << aValue << "'";
13217 else if (aParam == "-picked"
13218 || aParam == "-pickeddepth"
13219 || aParam == "-pickedindex")
13221 if (++anArgIter >= theArgsNb)
13223 Message::SendFail() << "Syntax error: wrong number parameters at '" << aParam << "'";
13227 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
13229 else if (anArgIter + 1 < theArgsNb
13230 && aParam == "-xrpose")
13232 TCollection_AsciiString anXRArg (theArgVec[++anArgIter]);
13233 anXRArg.LowerCase();
13234 if (anXRArg == "base")
13236 aCustomCam = aView->View()->BaseXRCamera();
13238 else if (anXRArg == "head")
13240 aCustomCam = aView->View()->PosedXRCamera();
13244 Message::SendFail() << "Syntax error: unknown XR pose '" << anXRArg << "'";
13247 if (aCustomCam.IsNull())
13249 Message::SendFail() << "Error: undefined XR pose";
13253 else if (aFile.IsEmpty())
13255 aFile = theArgVec[anArgIter];
13259 Message::SendFail() << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'";
13263 if (aFile.IsEmpty())
13265 Message::SendFail ("Syntax error: image file name is missing");
13269 Standard_Integer aWidth = 0, aHeight = 0;
13270 aView->Window()->Size (aWidth, aHeight);
13272 Image_AlienPixMap aPixMap;
13273 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
13275 Message::SendFail ("Error: can't allocate image");
13279 const bool wasImmUpdate = aView->SetImmediateUpdate (false);
13280 Handle(Graphic3d_Camera) aCamBack = aView->Camera();
13281 if (!aCustomCam.IsNull())
13283 aView->SetCamera (aCustomCam);
13285 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
13287 Message::SendFail ("Error: can't generate selection image");
13290 if (!aCustomCam.IsNull())
13292 aView->SetCamera (aCamBack);
13294 aView->SetImmediateUpdate (wasImmUpdate);
13296 if (!aPixMap.Save (aFile))
13298 Message::SendFail ("Error: can't save selection image");
13304 //===============================================================================================
13305 //function : VViewCube
13307 //===============================================================================================
13308 static int VViewCube (Draw_Interpretor& ,
13309 Standard_Integer theNbArgs,
13310 const char** theArgVec)
13312 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
13313 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
13314 if (aContext.IsNull() || aView.IsNull())
13316 Message::SendFail ("Error: no active viewer");
13319 else if (theNbArgs < 2)
13321 Message::SendFail ("Syntax error: wrong number arguments");
13325 Handle(AIS_ViewCube) aViewCube;
13326 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
13327 Quantity_Color aColorRgb;
13328 TCollection_AsciiString aName;
13329 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
13331 TCollection_AsciiString anArg (theArgVec[anArgIter]);
13333 if (anUpdateTool.parseRedrawMode (anArg))
13337 else if (aViewCube.IsNull())
13339 aName = theArgVec[anArgIter];
13340 if (aName.StartsWith ("-"))
13342 Message::SendFail ("Syntax error: object name should be specified");
13345 Handle(AIS_InteractiveObject) aPrs;
13346 GetMapOfAIS().Find2 (aName, aPrs);
13347 aViewCube = Handle(AIS_ViewCube)::DownCast (aPrs);
13348 if (aViewCube.IsNull())
13350 aViewCube = new AIS_ViewCube();
13351 aViewCube->SetBoxColor (Quantity_NOC_GRAY50);
13352 aViewCube->SetViewAnimation (ViewerTest::CurrentEventManager()->ViewAnimation());
13353 aViewCube->SetFixedAnimationLoop (false);
13356 else if (anArg == "-reset")
13358 aViewCube->ResetStyles();
13360 else if (anArg == "-color"
13361 || anArg == "-boxcolor"
13362 || anArg == "-boxsidecolor"
13363 || anArg == "-sidecolor"
13364 || anArg == "-boxedgecolor"
13365 || anArg == "-edgecolor"
13366 || anArg == "-boxcornercolor"
13367 || anArg == "-cornercolor"
13368 || anArg == "-innercolor"
13369 || anArg == "-textcolor"
13370 || anArg == "-xaxistextcolor"
13371 || anArg == "-yaxistextcolor"
13372 || anArg == "-zaxistextcolor")
13374 Standard_Integer aNbParsed = Draw::ParseColor (theNbArgs - anArgIter - 1,
13375 theArgVec + anArgIter + 1,
13377 if (aNbParsed == 0)
13379 Message::SendFail() << "Syntax error at '" << anArg << "'";
13382 anArgIter += aNbParsed;
13383 if (anArg == "-boxcolor")
13385 aViewCube->SetBoxColor (aColorRgb);
13387 else if (anArg == "-boxsidecolor"
13388 || anArg == "-sidecolor")
13390 aViewCube->BoxSideStyle()->SetColor (aColorRgb);
13391 aViewCube->SynchronizeAspects();
13393 else if (anArg == "-boxedgecolor"
13394 || anArg == "-edgecolor")
13396 aViewCube->BoxEdgeStyle()->SetColor (aColorRgb);
13397 aViewCube->SynchronizeAspects();
13399 else if (anArg == "-boxcornercolor"
13400 || anArg == "-cornercolor")
13402 aViewCube->BoxCornerStyle()->SetColor (aColorRgb);
13403 aViewCube->SynchronizeAspects();
13405 else if (anArg == "-innercolor")
13407 aViewCube->SetInnerColor (aColorRgb);
13409 else if (anArg == "-textcolor")
13411 aViewCube->SetTextColor (aColorRgb);
13413 else if (anArg == "-xaxistextcolor"
13414 || anArg == "-yaxistextcolor"
13415 || anArg == "-zaxistextcolor")
13417 Prs3d_DatumParts aDatum = anArg.Value (2) == 'x'
13418 ? Prs3d_DatumParts_XAxis
13419 : (anArg.Value (2) == 'y'
13420 ? Prs3d_DatumParts_YAxis
13421 : Prs3d_DatumParts_ZAxis);
13422 aViewCube->Attributes()->SetOwnDatumAspects();
13423 aViewCube->Attributes()->DatumAspect()->TextAspect (aDatum)->SetColor (aColorRgb);
13427 aViewCube->SetColor (aColorRgb);
13430 else if (anArgIter + 1 < theNbArgs
13431 && (anArg == "-transparency"
13432 || anArg == "-boxtransparency"))
13434 const Standard_Real aValue = Draw::Atof (theArgVec[++anArgIter]);
13435 if (aValue < 0.0 || aValue > 1.0)
13437 Message::SendFail() << "Syntax error: invalid transparency value " << theArgVec[anArgIter];
13441 if (anArg == "-boxtransparency")
13443 aViewCube->SetBoxTransparency (aValue);
13447 aViewCube->SetTransparency (aValue);
13450 else if (anArg == "-axes"
13451 || anArg == "-edges"
13452 || anArg == "-vertices"
13453 || anArg == "-vertexes"
13454 || anArg == "-fixedanimation")
13456 bool toShow = true;
13457 if (anArgIter + 1 < theNbArgs
13458 && Draw::ParseOnOff (theArgVec[anArgIter + 1], toShow))
13462 if (anArg == "-fixedanimation")
13464 aViewCube->SetFixedAnimationLoop (toShow);
13466 else if (anArg == "-axes")
13468 aViewCube->SetDrawAxes (toShow);
13470 else if (anArg == "-edges")
13472 aViewCube->SetDrawEdges (toShow);
13476 aViewCube->SetDrawVertices (toShow);
13479 else if (anArg == "-yup"
13480 || anArg == "-zup")
13483 if (anArgIter + 1 < theNbArgs
13484 && Draw::ParseOnOff (theArgVec[anArgIter + 1], isOn))
13488 if (anArg == "-yup")
13490 aViewCube->SetYup (isOn);
13494 aViewCube->SetYup (!isOn);
13497 else if (anArgIter + 1 < theNbArgs
13498 && anArg == "-font")
13500 aViewCube->SetFont (theArgVec[++anArgIter]);
13502 else if (anArgIter + 1 < theNbArgs
13503 && anArg == "-fontheight")
13505 aViewCube->SetFontHeight (Draw::Atof (theArgVec[++anArgIter]));
13507 else if (anArgIter + 1 < theNbArgs
13508 && (anArg == "-size"
13509 || anArg == "-boxsize"))
13511 aViewCube->SetSize (Draw::Atof (theArgVec[++anArgIter]),
13512 anArg != "-boxsize");
13514 else if (anArgIter + 1 < theNbArgs
13515 && (anArg == "-boxfacet"
13516 || anArg == "-boxfacetextension"
13517 || anArg == "-facetextension"
13518 || anArg == "-extension"))
13520 aViewCube->SetBoxFacetExtension (Draw::Atof (theArgVec[++anArgIter]));
13522 else if (anArgIter + 1 < theNbArgs
13523 && (anArg == "-boxedgegap"
13524 || anArg == "-edgegap"))
13526 aViewCube->SetBoxEdgeGap (Draw::Atof (theArgVec[++anArgIter]));
13528 else if (anArgIter + 1 < theNbArgs
13529 && (anArg == "-boxedgeminsize"
13530 || anArg == "-edgeminsize"))
13532 aViewCube->SetBoxEdgeMinSize (Draw::Atof (theArgVec[++anArgIter]));
13534 else if (anArgIter + 1 < theNbArgs
13535 && (anArg == "-boxcornerminsize"
13536 || anArg == "-cornerminsize"))
13538 aViewCube->SetBoxCornerMinSize (Draw::Atof (theArgVec[++anArgIter]));
13540 else if (anArgIter + 1 < theNbArgs
13541 && anArg == "-axespadding")
13543 aViewCube->SetAxesPadding (Draw::Atof (theArgVec[++anArgIter]));
13545 else if (anArgIter + 1 < theNbArgs
13546 && anArg == "-roundradius")
13548 aViewCube->SetRoundRadius (Draw::Atof (theArgVec[++anArgIter]));
13550 else if (anArgIter + 1 < theNbArgs
13551 && anArg == "-duration")
13553 aViewCube->SetDuration (Draw::Atof (theArgVec[++anArgIter]));
13555 else if (anArgIter + 1 < theNbArgs
13556 && anArg == "-axesradius")
13558 aViewCube->SetAxesRadius (Draw::Atof (theArgVec[++anArgIter]));
13560 else if (anArgIter + 1 < theNbArgs
13561 && anArg == "-axesconeradius")
13563 aViewCube->SetAxesConeRadius (Draw::Atof (theArgVec[++anArgIter]));
13565 else if (anArgIter + 1 < theNbArgs
13566 && anArg == "-axessphereradius")
13568 aViewCube->SetAxesSphereRadius (Draw::Atof (theArgVec[++anArgIter]));
13572 Message::SendFail() << "Syntax error: unknown argument '" << anArg << "'";
13576 if (aViewCube.IsNull())
13578 Message::SendFail ("Syntax error: wrong number of arguments");
13582 ViewerTest::Display (aName, aViewCube, false);
13586 //===============================================================================================
13587 //function : VColorConvert
13589 //===============================================================================================
13590 static int VColorConvert (Draw_Interpretor& theDI, Standard_Integer theNbArgs, const char** theArgVec)
13592 if (theNbArgs != 6)
13594 std::cerr << "Error: command syntax is incorrect, see help" << std::endl;
13598 Standard_Boolean convertFrom = (! strcasecmp (theArgVec[1], "from"));
13599 if (! convertFrom && strcasecmp (theArgVec[1], "to"))
13601 std::cerr << "Error: first argument must be either \"to\" or \"from\"" << std::endl;
13605 const char* aTypeStr = theArgVec[2];
13606 Quantity_TypeOfColor aType = Quantity_TOC_RGB;
13607 if (! strcasecmp (aTypeStr, "srgb"))
13609 aType = Quantity_TOC_sRGB;
13611 else if (! strcasecmp (aTypeStr, "hls"))
13613 aType = Quantity_TOC_HLS;
13615 else if (! strcasecmp (aTypeStr, "lab"))
13617 aType = Quantity_TOC_CIELab;
13619 else if (! strcasecmp (aTypeStr, "lch"))
13621 aType = Quantity_TOC_CIELch;
13625 std::cerr << "Error: unknown colorspace type: " << aTypeStr << std::endl;
13629 double aC1 = Draw::Atof (theArgVec[3]);
13630 double aC2 = Draw::Atof (theArgVec[4]);
13631 double aC3 = Draw::Atof (theArgVec[5]);
13633 Quantity_Color aColor (aC1, aC2, aC3, convertFrom ? aType : Quantity_TOC_RGB);
13634 aColor.Values (aC1, aC2, aC3, convertFrom ? Quantity_TOC_RGB : aType);
13636 // print values with 6 decimal digits
13638 Sprintf (buffer, "%.6f %.6f %.6f", aC1, aC2, aC3);
13644 //===============================================================================================
13645 //function : VColorDiff
13647 //===============================================================================================
13648 static int VColorDiff (Draw_Interpretor& theDI, Standard_Integer theNbArgs, const char** theArgVec)
13650 if (theNbArgs != 7)
13652 std::cerr << "Error: command syntax is incorrect, see help" << std::endl;
13656 double aR1 = Draw::Atof (theArgVec[1]);
13657 double aG1 = Draw::Atof (theArgVec[2]);
13658 double aB1 = Draw::Atof (theArgVec[3]);
13659 double aR2 = Draw::Atof (theArgVec[4]);
13660 double aG2 = Draw::Atof (theArgVec[5]);
13661 double aB2 = Draw::Atof (theArgVec[6]);
13663 Quantity_Color aColor1 (aR1, aG1, aB1, Quantity_TOC_RGB);
13664 Quantity_Color aColor2 (aR2, aG2, aB2, Quantity_TOC_RGB);
13666 theDI << aColor1.DeltaE2000 (aColor2);
13671 //===============================================================================================
13672 //function : VSelBvhBuild
13674 //===============================================================================================
13675 static int VSelBvhBuild (Draw_Interpretor& /*theDI*/, Standard_Integer theNbArgs, const char** theArgVec)
13677 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
13680 Message::SendFail ("Error: no active viewer");
13686 Message::SendFail ("Error: command syntax is incorrect, see help");
13690 Standard_Integer toEnable = -1;
13691 Standard_Integer aThreadsNb = -1;
13692 Standard_Boolean toWait = Standard_False;
13694 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
13696 TCollection_AsciiString anArg (theArgVec[anArgIter]);
13699 if (anArg == "-nbthreads"
13700 && anArgIter + 1 < theNbArgs)
13702 aThreadsNb = Draw::Atoi (theArgVec[++anArgIter]);
13703 if (aThreadsNb < 1)
13705 aThreadsNb = Max (1, OSD_Parallel::NbLogicalProcessors() - 1);
13708 else if (anArg == "-wait")
13710 toWait = Standard_True;
13712 else if (toEnable == -1)
13714 Standard_Boolean toEnableValue = Standard_True;
13715 if (Draw::ParseOnOff (anArg.ToCString(), toEnableValue))
13717 toEnable = toEnableValue ? 1 : 0;
13721 Message::SendFail() << "Syntax error: unknown argument '" << anArg << "'";
13727 Message::SendFail() << "Syntax error: unknown argument '" << anArg << "'";
13732 if (aThreadsNb == -1)
13736 if (toEnable != -1)
13738 aCtx->MainSelector()->SetToPrebuildBVH (toEnable == 1, aThreadsNb);
13742 aCtx->MainSelector()->WaitForBVHBuild();
13748 //=======================================================================
13749 //function : ViewerTest_ExitProc
13751 //=======================================================================
13752 static void ViewerTest_ExitProc (ClientData )
13754 NCollection_List<TCollection_AsciiString> aViewList;
13755 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
13756 anIter.More(); anIter.Next())
13758 aViewList.Append (anIter.Key1());
13761 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (aViewList);
13762 anIter.More(); anIter.Next())
13764 ViewerTest::RemoveView (anIter.Value(), true);
13768 //=======================================================================
13769 //function : ViewerCommands
13771 //=======================================================================
13773 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
13775 static bool TheIsInitialized = false;
13776 if (TheIsInitialized)
13781 TheIsInitialized = true;
13782 // define destruction callback to destroy views in a well-defined order
13783 Tcl_CreateExitHandler (ViewerTest_ExitProc, 0);
13785 const char* aGroup = "AIS Viewer";
13786 const char* aFileName = __FILE__;
13787 auto addCmd = [&](const char* theName, Draw_Interpretor::CommandFunction theFunc, const char* theHelp)
13789 theCommands.Add (theName, theHelp, aFileName, theFunc, aGroup);
13792 addCmd ("vdriver", VDriver, /* [vdriver] */ R"(
13793 vdriver [-list] [-default DriverName] [-load DriverName]
13794 Manages active graphic driver factory.
13795 Prints current active driver when called without arguments.
13796 Makes specified driver active when ActiveName argument is specified.
13797 -list print registered factories
13798 -default define which factory should be used by default (to be used by next vinit call)
13799 -load try loading factory plugin and set it as default one
13800 )" /* [vdriver] */);
13802 addCmd ("vinit", VInit, /* [vinit] */ R"(
13803 vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]
13804 [-exitOnClose] [-closeOnEscape] [-cloneActive] [-virtual {on|off}=off] [-2d_mode {on|off}=off]
13805 [-display displayName] [-dpiAware {on|off}]
13806 Creates new View window with specified name viewName.
13807 By default the new view is created in the viewer and in graphic driver shared with active view.
13808 -name {driverName/viewerName/viewName | viewerName/viewName | viewName}
13809 if driverName isn't specified the driver will be shared with active view;
13810 if viewerName isn't specified the viewer will be shared with active view.
13811 -display HostName.DisplayNumber[:ScreenNumber]
13813 Display name will be used within creation of graphic driver, when specified.
13814 -left, -top pixel position of left top corner of the window.
13815 -width, -height width and height of window respectively.
13816 -cloneActive flag to copy camera and dimensions of active view.
13817 -exitOnClose when specified, closing the view will exit application.
13818 -closeOnEscape when specified, view will be closed on pressing Escape.
13819 -virtual create an offscreen window within interactive session
13820 -2d_mode when on, view will not react on rotate scene events
13821 -dpiAware override dpi aware hint (Windows platform)
13822 Additional commands for operations with views: vclose, vactivate, vviewlist.
13825 addCmd ("vclose", VClose, /* [vclose] */ R"(
13826 vclose [view_id [keep_context=0|1]]
13827 or vclose ALL - to remove all created views
13828 - removes view(viewer window) defined by its view_id.
13829 - keep_context: by default 0; if 1 and the last view is deleted the current context is not removed.
13830 )" /* [vclose] */);
13832 addCmd ("vactivate", VActivate, /* [vactivate] */ R"(
13833 vactivate view_id [-noUpdate]
13834 Activates view(viewer window) defined by its view_id.
13835 )" /* [vactivate] */);
13837 addCmd ("vviewlist", VViewList, /* [vviewlist] */ R"(
13838 vviewlist [format={tree, long}]=tree
13839 Prints current list of views per viewer and graphic_driver ID shared between viewers
13840 - format: format of result output, if tree the output is a tree view;
13841 otherwise it's a list of full view names.
13842 )" /* [vviewlist] */);
13844 addCmd ("vhelp", VHelp, /* [vhelp] */ R"(
13845 vhelp : display help on the viewer commands and list of hotkeys.
13848 addCmd ("vviewproj", VViewProj, /* [vviewproj] */ R"(
13849 vviewproj [top|bottom|left|right|front|back|axoLeft|axoRight]
13850 [+-X+-Y+-Z] [-Zup|-Yup] [-frame +-X+-Y]
13851 Setup view direction
13852 -Yup use Y-up convention instead of Zup (which is default).
13853 +-X+-Y+-Z define direction as combination of DX, DY and DZ;
13854 for example '+Z' will show front of the model,
13855 '-X-Y+Z' will define left axonometric view.
13856 -frame define camera Up and Right directions (regardless Up convention);
13857 for example '+X+Z' will show front of the model with Z-up.
13858 )" /* [vviewproj] */);
13860 addCmd ("vtop", VViewProj, /* [vtop] */ R"(
13861 vtop or <T> : Display top view (+X+Y) in the 3D viewer window.
13864 addCmd ("vbottom", VViewProj, /* [vbottom] */ R"(
13865 vbottom : Display bottom view (+X-Y) in the 3D viewer window.
13866 )" /* [vbottom] */);
13868 addCmd ("vleft", VViewProj, /* [vleft] */ R"(
13869 vleft : Display left view (-Y+Z) in the 3D viewer window.
13872 addCmd ("vright", VViewProj, /* [vright] */ R"(
13873 vright : Display right view (+Y+Z) in the 3D viewer window.
13874 )" /* [vright] */);
13876 addCmd ("vaxo", VViewProj, /* [vaxo] */ R"(
13877 vaxo or <A> : Display axonometric view (+X-Y+Z) in the 3D viewer window.
13880 addCmd ("vfront", VViewProj, /* [vfront] */ R"(
13881 vfront : Display front view (+X+Z) in the 3D viewer window.
13882 )" /* [vfront] */);
13884 addCmd ("vback", VViewProj, /* [vfront] */ R"(
13885 vback : Display back view (-X+Z) in the 3D viewer window.
13888 addCmd ("vpick", VPick, /* [vpick] */ R"(
13889 vpick X Y Z [shape subshape]
13892 addCmd ("vfit", VFit, /* [vfit] */ R"(
13893 vfit or <F> [-selected] [-noupdate]
13894 Fit all / selected. Objects in the view are visualized to occupy the maximum surface.
13897 addCmd ("vfitarea", VFitArea, /* [vfitarea] */ R"(
13898 vfitarea [x1 y1 x2 y2] [x1 y1 z1 x2 y2 z2]
13899 Fit view to show area located between two points
13900 given in world 2D or 3D coordinates.
13901 )" /* [vfitarea] */);
13903 addCmd ("vzfit", VZFit, /* [vzfit] */ R"(
13905 Automatic depth panning.
13906 Matches Z near, Z far view volume planes to the displayed objects.
13907 - "scale" specifies factor to scale computed z range.
13910 addCmd ("vrepaint", VRepaint, /* [vrepaint] */ R"(
13911 vrepaint [-immediate] [-continuous FPS]
13912 Force redraw of active View.
13913 -immediate flag performs redraw of immediate layers only;
13914 -continuous activates/deactivates continuous redraw of active View,
13915 0 means no continuous rendering,
13916 -1 means non-stop redraws,
13917 >0 specifies target framerate.
13918 )" /* [vrepaint] */);
13920 addCmd ("vclear", VClear, /* [vclear] */ R"(
13921 vclear : Remove all the object from the viewer
13922 )" /* [vclear] */);
13924 addCmd ("vbackground", VBackground, /* [vbackground] */ R"(
13925 vbackground [-color Color [-default]]
13926 [-gradient Color1 Color2 [-default]
13927 [-gradientMode {NONE|HORIZONTAL|VERTICAL|DIAG1|DIAG2|CORNER1|CORNER2|CORNER3|ELLIPTICAL}]=VERT]
13928 [-imageFile ImageFile [-imageMode {CENTERED|TILED|STRETCH|NONE}]=CENTERED [-srgb {0|1}]=1]
13929 [-cubemap CubemapFile1 [CubeMapFiles2-5] [-order TilesIndexes1-6] [-invertedz]=0]
13930 [-skydome [-sunDir X Y Z=0 1 0] [-cloud Cloudy=0.2] [-time Time=0.0]
13931 [-fog Haze=0.0] [-size SizePx=512]]
13932 [-pbrEnv {ibl|noibl|keep}]
13933 Changes background or some background settings.
13934 -color sets background color
13935 -gradient sets background gradient starting and ending colors
13936 -gradientMode sets gradient fill method
13937 -default sets background default gradient or color
13938 -imageFile sets filename of image used as background
13939 -imageMode sets image fill type
13940 -cubemap sets environment cubemap as background
13941 -invertedz sets inversion of Z axis for background cubemap rendering; FALSE when unspecified
13942 -pbrEnv sets on/off Image Based Lighting (IBL) from background cubemap for PBR
13943 -srgb prefer sRGB texture format when applicable; TRUE when unspecified"
13944 -order defines order of tiles in one image cubemap
13945 TileIndexi defubes an index in range [0, 5] for i tile of one image packed cubemap
13946 (has no effect in case of multi-image cubemaps).
13947 Skydome background parameters (generated cubemap):
13948 -skydome sets procedurally generated skydome as background
13949 -sunDir sets direction to the sun, direction with negative y component represents moon direction (-x, -y, -z)
13950 -cloud sets cloud intensity (0.0 - clear sky, 1.0 - very high cloudy)
13951 -time might be tweaked to slightly change appearance of clouds
13952 -fog sets mist intensity (0.0 - no mist at all, 1.0 - high mist)
13953 -size sets size in pixels of cubemap side
13954 )" /* [vbackground] */);
13956 addCmd ("vsetbg", VBackground, /* [vsetbg] */ R"(
13957 Alias for 'vbackground -imageFile ImageFile [-imageMode FillType]'.
13958 )" /* [vsetbg] */);
13960 addCmd ("vsetbgmode", VBackground, /* [vsetbgmode] */ R"(
13961 Alias for 'vbackground -imageMode FillType'.
13962 )" /* [vsetbgmode] */);
13964 addCmd ("vsetgradientbg", VBackground, /* [vsetgradientbg] */ R"(
13965 Alias for 'vbackground -gradient Color1 Color2 -gradientMode FillMethod'.
13966 )" /* [vsetgradientbg] */);
13968 addCmd ("vsetgrbgmode", VBackground, /* [vsetgrbgmode] */ R"(
13969 Alias for 'vbackground -gradientMode FillMethod'.
13970 )" /* [vsetgrbgmode] */);
13972 addCmd ("vsetcolorbg", VBackground, /* [vsetcolorbg] */ R"(
13973 Alias for 'vbackground -color Color'.
13974 )" /* [vsetcolorbg] */);
13976 addCmd ("vsetdefaultbg", VBackground, /* [vsetdefaultbg] */ R"(
13977 Alias for 'vbackground -default -gradient Color1 Color2 [-gradientMode FillMethod]'
13978 and for 'vbackground -default -color Color'.
13979 )" /* [vsetdefaultbg] */);
13981 addCmd ("vscale", VScale, /* [vscale] */ R"(
13983 )" /* [vscale] */);
13985 addCmd ("vzbufftrihedron", VZBuffTrihedron, /* [vzbufftrihedron] */ R"(
13986 vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]
13987 [-position center|left_lower|left_upper|right_lower|right_upper]
13988 [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]
13989 [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]
13990 [-nbfacets value=12] [-colorLabels color=WHITE]
13991 [-colorLabelX color] [-colorLabelY color] [-colorLabelZ color]
13992 Displays a trihedron.
13993 )" /* [vzbufftrihedron] */);
13995 addCmd ("vrotate", VRotate, /* [vrotate] */ R"(
13996 vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]
13997 -mouseStart start rotation according to the mouse position;
13998 -mouseMove continue rotation with angle computed
13999 from last and new mouse position.
14000 )" /* [vrotate] */);
14002 addCmd ("vzoom", VZoom, /* [vzoom] */ R"(
14006 addCmd ("vpan", VPan, /* [vpan] */ R"(
14010 addCmd ("vcolorscale", VColorScale, /* [vcolorscale] */ R"(
14011 vcolorscale name [-noupdate|-update] [-demo]
14012 [-range RangeMin=0 RangeMax=1 NbIntervals=10]
14013 [-font HeightFont=20]
14014 [-logarithmic {on|off}=off] [-reversed {on|off}=off]
14015 [-smoothTransition {on|off}=off]
14016 [-hueRange MinAngle=230 MaxAngle=0]
14017 [-colorRange MinColor=BLUE1 MaxColor=RED]
14018 [-textPos {left|right|center|none}=right]
14019 [-labelAtBorder {on|off}=on]
14020 [-colors Color1 Color2 ...] [-color Index Color]
14021 [-labels Label1 Label2 ...] [-label Index Label]
14022 [-freeLabels NbOfLabels Label1 Label2 ...]
14023 [-xy Left=0 Bottom=0]
14024 [-uniform lightness hue_from hue_to]
14025 -demo display a color scale with demonstration values
14026 -colors set colors for all intervals
14027 -color set color for specific interval
14028 -uniform generate colors with the same lightness
14029 -textpos horizontal label position relative to color scale bar
14030 -labelAtBorder vertical label position relative to color interval;
14031 at border means the value inbetween neighbor intervals,
14032 at center means the center value within current interval
14033 -labels set labels for all intervals
14034 -freeLabels same as -labels but does not require
14035 matching the number of intervals
14036 -label set label for specific interval
14038 -reversed setup smooth color transition between intervals
14039 -smoothTransition swap colorscale direction
14040 -hueRange set hue angles corresponding to minimum and maximum values
14041 )" /* [vcolorscale] */);
14043 addCmd ("vgraduatedtrihedron", VGraduatedTrihedron, /* [vgraduatedtrihedron] */ R"(
14044 vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]
14045 [-namefont Name] [-valuesfont Name]
14046 [-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]
14047 [-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]
14048 [-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]
14049 [-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]
14050 [-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]
14051 [-xcolor Color] [-ycolor Color] [-zcolor Color]
14052 [-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]
14053 [-xticks Number] [-yticks Number] [-zticks Number]
14054 [-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]
14055 [-drawgrid on/off] [-drawaxes on/off]
14056 Display or erase graduated trihedron
14057 - xname, yname, zname - names of axes, default: X, Y, Z
14058 - namefont - font of axes names. Default: Arial
14059 - xnameoffset, ynameoffset, znameoffset - offset of name
14060 from values or tickmarks or axis. Default: 30
14061 - xnamecolor, ynamecolor, znamecolor - colors of axes names
14062 - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values
14063 from tickmarks or axis. Default: 10
14064 - valuesfont - font of axes values. Default: Arial
14065 - xcolor, ycolor, zcolor - color of axis and values
14066 - xticks, yticks, xzicks - number of tickmark on axes. Default: 5
14067 - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10
14068 )" /* [vgraduatedtrihedron] */);
14070 addCmd ("vtile", VTile, /* [vtile] */ R"(
14071 vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]
14072 Setup view to draw a tile (a part of virtual bigger viewport).
14073 -totalSize the size of virtual bigger viewport
14074 -tileSize tile size (the view size will be used if omitted)
14075 -lowerLeft tile offset as lower left corner
14076 -upperLeft tile offset as upper left corner
14079 addCmd ("vzlayer", VZLayer, /* [vzlayer] */ R"(
14081 [-add|-delete|-get|-settings] [-insertBefore AnotherLayer] [-insertAfter AnotherLayer]
14082 [-origin X Y Z] [-cullDist Distance] [-cullSize Size]
14083 [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]
14084 [-enable|-disable {positiveOffset|negativeOffset|textureenv|rayTracing}]
14085 ZLayer list management
14086 -add add new z layer to viewer and print its id
14087 -insertBefore add new z layer and insert it before existing one
14088 -insertAfter add new z layer and insert it after existing one
14089 -delete delete z layer
14090 -get print sequence of z layers
14091 -settings print status of z layer settings
14092 -disable disables given setting
14093 -enable enables given setting
14094 )" /* [vzlayer] */);
14096 addCmd ("vlayerline", VLayerLine, /* [vlayerline] */ R"(
14097 vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]
14098 )" /* [vlayerline] */);
14100 addCmd ("vgrid", VGrid, /* [vgrid] */ R"(
14101 vgrid [off] [-type {rect|circ}] [-mode {line|point}] [-origin X Y] [-rotAngle Angle] [-zoffset DZ]
14102 [-step X Y] [-size DX DY]
14103 [-step StepRadius NbDivisions] [-radius Radius]
14106 addCmd ("vpriviledgedplane", VPriviledgedPlane, /* [vpriviledgedplane] */ R"(
14107 vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]
14108 Sets or prints viewer's priviledged plane geometry:
14109 Ox, Oy, Oz - plane origin;
14110 Nx, Ny, Nz - plane normal direction;
14111 Xx, Xy, Xz - plane x-reference axis direction.
14112 )" /* [vpriviledgedplane] */);
14114 addCmd ("vconvert", VConvert, /* [vconvert] */ R"(
14115 vconvert v [Mode={window|view}]
14116 vconvert x y [Mode={window|view|grid|ray}]
14117 vconvert x y z [Mode={window|grid}]
14118 Convert the given coordinates to window/view/model space:
14119 - window - convert to window coordinates, pixels;
14120 - view - convert to view projection plane;
14121 - grid - convert to model coordinates, given on grid;
14122 - ray - convert projection ray to model coordinates.
14123 )" /* [vconvert] */);
14125 addCmd ("vfps", VFps, /* [vfps] */ R"(
14126 vfps [framesNb=100] [-duration seconds] : estimate average frame rate for active view.
14129 addCmd ("vstereo", VStereo, /* [vstereo] */ R"(
14130 vstereo [0|1] [-mode Mode] [-reverse {0|1}]
14131 [-mirrorComposer] [-hmdfov2d AngleDegrees] [-unitFactor MetersFactor]
14132 [-anaglyph Filter] [-smoothInterlacing]
14133 Control stereo output mode. Available modes for -mode:
14134 quadBuffer OpenGL QuadBuffer stereo;
14135 requires driver support;
14136 should be called BEFORE vinit!
14137 anaglyph Anaglyph glasses, filters for -anaglyph:
14138 redCyan, redCyanSimple, yellowBlue, yellowBlueSimple, greenMagentaSimple.
14139 rowInterlaced row-interlaced display
14140 smooth smooth interlaced output for better text readability
14141 columnInterlaced column-interlaced display
14142 chessBoard chess-board output
14143 sideBySide horizontal pair
14144 overUnder vertical pair
14145 openVR OpenVR (HMD), extra options:
14146 -mirrorComposer flag to mirror VR frame in the window (debug);
14147 -unitFactor specifies meters scale factor for mapping VR input.
14148 )" /* [vstereo] */);
14150 addCmd ("vmemgpu", VMemGpu, /* [vmemgpu] */ R"(
14151 vmemgpu [f]: print system-dependent GPU memory information if available;
14152 with f option returns free memory in bytes.
14153 )" /* [vmemgpu] */);
14155 addCmd ("vreadpixel", VReadPixel, /* [vreadpixel] */ R"(
14156 vreadpixel xPixel yPixel [{rgb|rgba|sRGB|sRGBa|depth|hls|rgbf|rgbaf}=rgba] [-name|-hex]
14157 Read pixel value for active view.
14158 )" /* [vreadpixel] */);
14160 addCmd ("diffimage", VDiffImage, /* [diffimage] */ R"(
14161 diffimage imageFile1 imageFile2 [diffImageFile]
14162 [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]
14163 [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]
14164 Compare two images by content and generate difference image.
14165 When -exitOnClose is specified, closing the view will exit application.
14166 When -closeOnEscape is specified, view will be closed on pressing Escape.
14167 )" /* [diffimage] */);
14169 addCmd ("vselect", VSelect, /* [vselect] */ R"(
14170 vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1]
14171 [-replace|-replaceextra|-xor|-add|-remove]
14172 Emulate different types of selection:
14173 1) Single click selection.
14174 2) Selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2).
14175 3) Selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn).
14176 4) -allowoverlap manages overlap and inclusion detection in rectangular and polygonal selection.
14177 If the flag is set to 1, both sensitives that were included completely
14178 and overlapped partially by defined rectangle or polygon will be detected,
14179 otherwise algorithm will chose only fully included sensitives.
14180 Default behavior is to detect only full inclusion
14181 (partial inclusion - overlap - is not allowed by default).
14182 5) Selection scheme replace, replaceextra, xor, add or remove (replace by default).
14183 )" /* [vselect] */);
14185 addCmd ("vmoveto", VMoveTo, /* [vmoveto] */ R"(
14186 vmoveto [x y] [-reset]
14187 Emulate cursor movement to pixel position (x,y).
14188 -reset resets current highlighting.
14189 )" /* [vmoveto] */);
14191 addCmd ("vselaxis", VSelectByAxis, /* [vselaxis] */ R"(
14192 vselaxis x y z dx dy dz [-onlyTop 0|1] [-display Name] [-showNormal 0|1]"
14193 Provides intersection by given axis and print result intersection points.
14194 -onlyTop switches On/Off mode to find only top point or all;
14195 -display Name displays intersecting axis and result intersection points for debug goals;
14196 -showNormal adds displaying of normal in intersection point or not.
14197 )" /* [vselaxis] */);
14199 addCmd ("vviewparams", VViewParams, /* [vviewparams] */ R"(
14200 vviewparams [-args] [-scale [s]]
14201 [-eye [x y z]] [-at [x y z]] [-up [x y z]]
14202 [-proj [x y z]] [-center x y] [-size sx]
14203 Manage current view parameters (camera orientation) or prints all
14204 current values when called without argument.
14205 -scale [s] prints or sets viewport relative scale
14206 -eye [x y z] prints or sets eye location
14207 -at [x y z] prints or sets center of look
14208 -up [x y z] prints or sets direction of up vector
14209 -proj [x y z] prints or sets direction of look
14210 -center x y sets location of center of the screen in pixels
14211 -size [sx] prints viewport projection width and height sizes
14212 or changes the size of its maximum dimension
14213 -args prints vviewparams arguments for restoring current view
14214 )" /* [vviewparams] */);
14216 addCmd ("v2dmode", V2DMode, /* [v2dmode] */ R"(
14217 v2dmode [-name viewName] [-mode {-on|-off}=-on]
14218 name - name of existing view, if not defined, the active view is changed;
14219 mode - switches On/Off rotation mode.
14220 Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:
14221 - rotation of the view by 3rd mouse button with Ctrl active
14222 - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right
14223 View camera position might be changed only by commands.
14224 )" /* [v2dmode] */);
14226 addCmd ("vanimation", VAnimation, /* [vanimation] */ R"(
14228 )" /* [vanimation] */);
14230 addCmd ("vanim", VAnimation, /* [vanim] */ R"(
14231 List existing animations:
14234 Animation playback:
14235 vanim name {-play|-resume|-pause|-stop} [playFrom [playDuration]]
14236 [-speed Coeff] [-freeLook] [-noPauseOnClick] [-lockLoop]
14238 -speed playback speed (1.0 is normal speed)
14239 -freeLook skip camera animations
14240 -noPauseOnClick do not pause animation on mouse click
14241 -lockLoop disable any interactions
14243 Animation definition:
14244 vanim Name/sub/name [-clear] [-delete]
14245 [-start TimeSec] [-duration TimeSec] [-end TimeSec]
14247 Animation name defined in path-style (anim/name or anim.name)
14248 specifies nested animations.
14249 There is no syntax to explicitly add new animation,
14250 and all non-existing animations within the name will be
14251 implicitly created on first use (including parents).
14253 Each animation might define the SINGLE action (see below),
14254 like camera transition, object transformation or custom callback.
14255 Child animations can be used for defining concurrent actions.
14258 vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]
14259 [-at1 X Y Z] [-at2 X Y Z]
14260 [-up1 X Y Z] [-up2 X Y Z]
14261 [-scale1 Scale] [-scale2 Scale]
14262 -eyeX camera Eye positions pair (start and end)
14263 -atX camera Center positions pair
14264 -upX camera Up directions pair
14265 -scaleX camera Scale factors pair
14268 vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]
14269 [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]
14270 [-scale1 Scale] [-scale2 Scale]
14271 -locX object Location points pair (translation)
14272 -rotX object Orientations pair (quaternions)
14273 -scaleX object Scale factors pair (quaternions)
14276 vanim name -invoke "Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN"
14278 %Pts overall animation presentation timestamp
14279 %LocalPts local animation timestamp
14280 %Normalized local animation normalized value in range 0..1
14283 vanim name -record FileName [Width Height] [-fps FrameRate=24]
14284 [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]
14285 [-crf Value] [-preset Preset]
14286 -fps video framerate
14287 -format file format, container (matroska, etc.)
14288 -vcodec video codec identifier (ffv1, mjpeg, etc.)
14289 -pix_fmt image pixel format (yuv420p, rgb24, etc.)
14290 -crf constant rate factor (specific to codec)
14291 -preset codec parameters preset (specific to codec)
14294 addCmd ("vchangeselected", VChangeSelected, /* [vchangeselected] */ R"(
14295 vchangeselected shape : Add shape to selection or remove one from it.
14296 )" /* [vchangeselected] */);
14298 addCmd ("vnbselected", VNbSelected, /* [vnbselected] */ R"(
14299 vnbselected : Returns number of selected objects in the interactive context.
14300 )" /* [vnbselected] */);
14302 addCmd ("vcamera", VCamera, /* [vcamera] */ R"(
14303 vcamera [PrsName] [-ortho] [-projtype]
14305 [-fovy [Angle]] [-distance [Distance]]
14306 [-stereo] [-leftEye] [-rightEye]
14307 [-iod [Distance]] [-iodType [absolute|relative]]
14308 [-zfocus [Value]] [-zfocusType [absolute|relative]]
14309 [-fov2d [Angle]] [-lockZup {0|1}]
14310 [-rotationMode {active|pick|pickCenter|cameraAt|scene}]
14311 [-navigationMode {orbit|walk|flight}]
14312 [-xrPose base|head=base]
14313 Manages camera parameters.
14314 Displays frustum when presentation name PrsName is specified.
14315 Prints current value when option called without argument.
14317 Orthographic camera:
14318 -ortho activate orthographic projection.
14320 Perspective camera:
14321 -persp activate perspective projection (mono);
14322 -fovy field of view in y axis, in degrees;
14323 -fov2d field of view limit for 2d on-screen elements;
14324 -distance distance of eye from camera center;
14325 -lockZup lock Z up (turntable mode);
14326 -rotationMode rotation mode (gravity point);
14327 -navigationMode navigation mode.
14329 Stereoscopic camera:
14330 -stereo perspective projection (stereo);
14331 -leftEye perspective projection (left eye);
14332 -rightEye perspective projection (right eye);
14333 -iod intraocular distance value;
14334 -iodType distance type, absolute or relative;
14335 -zfocus stereographic focus value;
14336 -zfocusType focus type, absolute or relative.
14337 )" /* [vcamera] */);
14339 addCmd ("vautozfit", VAutoZFit, /* [vautozfit] */ R"(
14340 vautozfit [on={1|0}] [scale]
14341 Prints or changes parameters of automatic z-fit mode:
14342 "on" - turns automatic z-fit on or off;
14343 "scale" - specifies factor to scale computed z range.
14344 )" /* [vautozfit] */);
14346 addCmd ("vzrange", VZRange, /* [vzrange] */ R"(
14347 vzrange [znear] [zfar]
14348 Applies provided znear/zfar to view or prints current values.
14349 )" /* [vzrange] */);
14351 addCmd ("vsetviewsize", VSetViewSize, /* [vsetviewsize] */ R"(
14353 )" /* [vsetviewsize] */);
14355 addCmd ("vmoveview", VMoveView, /* [vmoveview] */ R"(
14356 vmoveview Dx Dy Dz [Start = 1|0]
14357 )" /* [vmoveview] */);
14359 addCmd ("vtranslateview", VTranslateView, /* [vtranslateview] */ R"(
14360 vtranslateview Dx Dy Dz [Start = 1|0)]
14361 )" /* [vtranslateview] */);
14363 addCmd ("vturnview", VTurnView, /* [vturnview] */ R"(
14364 vturnview Ax Ay Az [Start = 1|0]
14365 )" /* [vturnview] */);
14367 addCmd ("vtextureenv", VTextureEnv, /* [vtextureenv] */ R"(
14368 vtextureenv {on|off} {image_file}
14369 [{clamp|repeat} {decal|modulate} {nearest|bilinear|trilinear} ss st ts tt rot]
14370 Enables or disables environment mapping in the 3D view, loading the texture from the given standard
14371 or user-defined file and optionally applying texture mapping parameters.
14372 ss, st - scale factors for s and t texture coordinates;
14373 ts, tt - translation for s and t texture coordinates;
14374 rot - texture rotation angle in degrees.
14375 )" /* [vtextureenv] */);
14377 addCmd ("vhlr", VHLR, /* [vhlr] */ R"(
14378 vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]
14379 Hidden Line Removal algorithm.
14380 -showHidden if set ON, hidden lines are drawn as dotted ones;
14381 -algoType type of HLR algorithm:
14382 'algo' - exact HLR algorithm is applied;
14383 'polyAlgo' - polygonal HLR algorithm is applied.
14386 addCmd ("vhlrtype", VHLRType, /* [vhlrtype] */ R"(
14387 vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]
14388 Changes the type of HLR algorithm using for shapes:
14389 'algo' - exact HLR algorithm is applied;
14390 'polyAlgo' - polygonal HLR algorithm is applied.
14391 If shapes are not given - option is applied to all shapes in the view.
14392 )" /* [vhlrtype] */);
14394 addCmd ("vclipplane", VClipPlane, /* [vclipplane] */ R"(
14395 vclipplane planeName [{0|1}]
14396 [-equation1 A B C D]
14397 [-equation2 A B C D]
14398 [-boxInterior MinX MinY MinZ MaxX MaxY MaxZ]
14399 [-set|-unset|-setOverrideGlobal [objects|views]]
14402 [-color R G B] [-transparency Value] [-hatch {on|off|ID}]
14403 [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]
14405 [-useObjMaterial {0|1}] [-useObjTexture {0|1}]
14406 [-useObjShader {0|1}]
14408 Clipping planes management:
14409 -maxPlanes print plane limit for view;
14410 -delete delete plane with given name;
14411 {off|on|0|1} turn clipping on/off;
14412 -set|-unset set/unset plane for Object or View list;
14413 applied to active View when list is omitted;
14414 -equation A B C D change plane equation;
14415 -clone SourcePlane NewPlane clone the plane definition.
14418 -capping {off|on|0|1} turn capping on/off;
14419 -color R G B set capping color;
14420 -transparency Value set capping transparency 0..1;
14421 -texName Texture set capping texture;
14422 -texScale SX SY set capping tex scale;
14423 -texOrigin TX TY set capping tex origin;
14424 -texRotate Angle set capping tex rotation;
14425 -hatch {on|off|ID} set capping hatching mask;
14426 -useObjMaterial {off|on|0|1} use material of clipped object;
14427 -useObjTexture {off|on|0|1} use texture of clipped object;
14428 -useObjShader {off|on|0|1} use shader program of object.
14429 )" /* [vclipplane] */);
14431 addCmd ("vdefaults", VDefaults, /* [vdefaults] */ R"(
14432 vdefaults [-absDefl value] [-devCoeff value] [-angDefl value]
14433 [-autoTriang {off/on | 0/1}]
14434 )" /* [vdefaults] */);
14436 addCmd ("vlight", VLight, /* [vlight] */ R"(
14437 vlight [lightName] [-noupdate]
14438 [-clear|-defaults] [-layer Id] [-local|-global] [-disable|-enable]
14439 [-type {ambient|directional|spotlight|positional}] [-name value]
14440 [-position X Y Z] [-direction X Y Z] [-color colorName] [-intensity value]
14441 [-headlight 0|1] [-castShadows 0|1]
14442 [-range value] [-constAttenuation value] [-linearAttenuation value]
14443 [-spotExponent value] [-spotAngle angleDeg]
14444 [-smoothAngle value] [-smoothRadius value]
14445 [-display] [-showName 1|0] [-showRange 1|0] [-prsZoomable 1|0] [-prsSize Value]
14448 Command manages light sources. Without arguments shows list of lights.
14449 Arguments affecting the list of defined/active lights:
14450 -clear remove all light sources;
14451 -defaults defines two standard light sources;
14452 -reset resets light source parameters to default values;
14453 -type sets type of light source;
14454 -name sets new name to light source;
14455 -global assigns light source to all views (default state);
14456 -local assigns light source to active view;
14457 -zlayer assigns light source to specified Z-Layer.
14459 Ambient light parameters:
14460 -color sets (normalized) light color;
14461 -intensity sets intensity of light source, 1.0 by default;
14462 affects also environment cubemap intensity.
14464 Point light parameters:
14465 -color sets (normalized) light color;
14466 -intensity sets PBR intensity;
14467 -range sets clamping distance;
14468 -constAtten (obsolete) sets constant attenuation factor;
14469 -linearAtten (obsolete) sets linear attenuation factor;
14470 -smoothRadius sets PBR smoothing radius.
14472 Directional light parameters:
14473 -color sets (normalized) light color;
14474 -intensity sets PBR intensity;
14475 -direction sets direction;
14476 -headlight sets headlight flag;
14477 -castShadows enables/disables shadow casting;
14478 -smoothAngle sets PBR smoothing angle (in degrees) within 0..90 range.
14480 Spot light parameters:
14481 -color sets (normalized) light color;
14482 -intensity sets PBR intensity;
14483 -range sets clamping distance;
14484 -position sets position;
14485 -direction sets direction;
14486 -spotAngle sets spotlight angle;
14487 -spotExp sets spotlight exponenta;
14488 -headlight sets headlight flag;
14489 -constAtten (obsolete) sets constant attenuation factor;
14490 -linearAtten (obsolete) sets linear attenuation factor.
14492 Light presentation parameters:
14493 -display adds light source presentation;
14494 -showName shows/hides the name of light source; 1 by default;
14495 -showRange shows/hides the range of spot/positional light source; 1 by default;
14496 -prsZoomable makes light presentation zoomable/non-zoomable;
14497 -prsDraggable makes light presentation draggable/non-draggable;
14498 -prsSize sets light presentation size;
14499 -arcSize sets arc presentation size(in pixels)
14500 for rotation directional light source; 25 by default.
14503 vlight redlight -type POSITIONAL -headlight 1 -pos 0 1 1 -color RED
14504 vlight redlight -delete
14505 )" /* [vlight] */);
14507 addCmd ("vpbrenv", VPBREnvironment, /* [vpbrenv] */ R"(
14508 vpbrenv -clear|-generate
14509 Clears or generates PBR environment map of active view.
14510 -clear clears PBR environment (fills by white color);
14511 -generate generates PBR environment from current background cubemap.
14512 )" /* [vpbrenv] */);
14514 addCmd ("vraytrace", VRenderParams, /* [vraytrace] */ R"(
14515 vraytrace [0|1] : Turns on/off ray-tracing renderer.
14516 'vraytrace 0' alias for 'vrenderparams -raster'.
14517 'vraytrace 1' alias for 'vrenderparams -rayTrace'.
14518 )" /* [vraytrace] */);
14520 addCmd ("vrenderparams", VRenderParams, /* [vrenderparams] */ R"(
14521 Manages rendering parameters, affecting visual appearance, quality and performance.
14522 Should be applied taking into account GPU hardware capabilities and performance.
14525 vrenderparams [-raster] [-shadingModel {unlit|facet|gouraud|phong|pbr|pbr_facet}=gouraud]
14526 [-msaa 0..8=0] [-rendScale scale=1]
14527 [-resolution value=72] [-fontHinting {off|normal|light}=off]
14528 [-fontAutoHinting {auto|force|disallow}=auto]
14529 [-oit {off|weight|peel}] [-oit weighted [depthFactor=0.0]] [-oit peeling [nbLayers=4]]
14530 [-shadows {on|off}=on] [-shadowMapResolution value=1024] [-shadowMapBias value=0.005]
14531 [-depthPrePass {on|off}=off] [-alphaToCoverage {on|off}=on]
14532 [-frustumCulling {on|off|noupdate}=on] [-lineFeather width=1.0]
14533 [-sync {default|views}] [-reset]
14534 -raster Disables GPU ray-tracing.
14535 -shadingModel Controls shading model.
14536 -msaa Specifies number of samples for MSAA.
14537 -rendScale Rendering resolution scale factor (supersampling, alternative to MSAA).
14538 -resolution Sets new pixels density (PPI) used as text scaling factor.
14539 -fontHinting Enables/disables font hinting for better readability on low-resolution screens.
14540 -fontAutoHinting Manages font autohinting.
14541 -lineFeather Sets line feather factor while displaying mesh edges.
14542 -alphaToCoverage Enables/disables alpha to coverage (needs MSAA).
14543 -oit Enables/disables order-independent transparency (OIT) rendering;
14544 off unordered transparency (but opaque objects implicitly draw first);
14545 weighted weight OIT is managed by depth weight factor 0.0..1.0;
14546 peeling depth peeling OIT is managed by number of peeling layers.
14547 -shadows Enables/disables shadows rendering.
14548 -shadowMapResolution Shadow texture map resolution.
14549 -shadowMapBias Shadow map bias.
14550 -depthPrePass Enables/disables depth pre-pass.
14551 -frustumCulling Enables/disables objects frustum clipping or
14552 sets state to check structures culled previously.
14553 -sync Sets active View parameters as Viewer defaults / to other Views.
14554 -reset Resets active View parameters to Viewer defaults.
14556 Diagnostic output (on-screen overlay):
14557 vrenderparams [-perfCounters none|fps|cpu|layers|structures|groups|arrays|triangles|points
14558 |gpuMem|frameTime|basic|extended|full|nofps|skipImmediate]
14559 [-perfUpdateInterval nbSeconds=1] [-perfChart nbFrames=1] [-perfChartMax seconds=0.1]
14560 -perfCounters Show/hide performance counters (flags can be combined).
14561 -perfUpdateInterval Performance counters update interval.
14562 -perfChart Show frame timers chart limited by specified number of frames.
14563 -perfChartMax Maximum time in seconds with the chart.
14565 Ray-Tracing options:
14566 vrenderparams [-rayTrace] [-rayDepth {0..10}=3] [-reflections {on|off}=off]
14567 [-fsaa {on|off}=off] [-gleam {on|off}=off] [-env {on|off}=off]
14568 [-gi {on|off}=off] [-brng {on|off}=off]
14569 [-iss {on|off}=off] [-tileSize {1..4096}=32] [-nbTiles {64..1024}=256]
14570 [-ignoreNormalMap {on|off}=off] [-twoSide {on|off}=off]
14571 [-maxRad {value>0}=30.0]
14572 [-aperture {value>=0}=0.0] [-focal {value>=0.0}=1.0]
14573 [-exposure value=0.0] [-whitePoint value=1.0] [-toneMapping {disabled|filmic}=disabled]
14574 -rayTrace Enables GPU ray-tracing.
14575 -rayDepth Defines maximum ray-tracing depth.
14576 -reflections Enables/disables specular reflections.
14577 -fsaa Enables/disables adaptive anti-aliasing.
14578 -gleam Enables/disables transparency shadow effects.
14579 -gi Enables/disables global illumination effects (Path-Tracing).
14580 -env Enables/disables environment map background.
14581 -ignoreNormalMap Enables/disables normal map ignoring during path tracing.
14582 -twoSide Enables/disables two-sided BSDF models (PT mode).
14583 -iss Enables/disables adaptive screen sampling (PT mode).
14584 -maxRad Value used for clamping radiance estimation (PT mode).
14585 -tileSize Specifies size of screen tiles in ISS mode (32 by default).
14586 -nbTiles Specifies number of screen tiles per Redraw in ISS mode (256 by default).
14587 -aperture Aperture size of perspective camera for depth-of-field effect (0 disables DOF).
14588 -focal Focal distance of perspective camera for depth-of-field effect.
14589 -exposure Exposure value for tone mapping (0.0 value disables the effect).
14590 -whitePoint White point value for filmic tone mapping.
14591 -toneMapping Tone mapping mode (disabled, filmic).
14593 PBR environment baking parameters (advanced/debug):
14594 vrenderparams [-pbrEnvPow2size {power>0}=9] [-pbrEnvSMLN {levels>1}=6] [-pbrEnvBP {0..1}=0.99]
14595 [-pbrEnvBDSN {samples>0}=1024] [-pbrEnvBSSN {samples>0}=256]
14596 -pbrEnvPow2size Controls size of IBL maps (real size can be calculates as 2^pbrenvpow2size).
14597 -pbrEnvSMLN Controls number of mipmap levels used in specular IBL map.
14598 -pbrEnvBDSN Controls number of samples in Monte-Carlo integration during
14599 diffuse IBL map's sherical harmonics calculation.
14600 -pbrEnvBSSN Controls maximum number of samples per mipmap level
14601 in Monte-Carlo integration during specular IBL maps generation.
14602 -pbrEnvBP Controls strength of samples number reducing
14603 during specular IBL maps generation (1 disables reducing).
14606 vrenderparams [-issd {on|off}=off] [-rebuildGlsl on|off]
14607 -issd Shows screen sampling distribution in ISS mode.
14608 -rebuildGlsl Rebuild Ray-Tracing GLSL programs (for debugging).
14609 -brng Enables/disables blocked RNG (fast coherent PT).
14610 )" /* [vrenderparams] */);
14612 addCmd ("vstatprofiler", VStatProfiler, /* [vstatprofiler] */ R"(
14613 vstatprofiler [fps|cpu|allLayers|layers|allstructures|structures|groups
14614 |allArrays|fillArrays|lineArrays|pointArrays|textArrays
14615 |triangles|points|geomMem|textureMem|frameMem
14616 |elapsedFrame|cpuFrameAverage|cpuPickingAverage|cpuCullingAverage|cpuDynAverage
14617 |cpuFrameMax|cpuPickingMax|cpuCullingMax|cpuDynMax]
14619 Prints rendering statistics for specified counters or for all when unspecified.
14620 Set '-noredraw' flag to avoid additional redraw call and use already collected values.
14621 )" /* [vstatprofiler] */);
14623 addCmd ("vplace", VPlace, /* [vplace] */ R"(
14624 vplace dx dy : Places the point (in pixels) at the center of the window
14625 )" /* [vplace] */);
14627 addCmd ("vxrotate", VXRotate, /* [vxrotate] */ R"(
14629 )" /* [vxrotate] */);
14631 addCmd ("vmanipulator", VManipulator, /* [vmanipulator] */ R"(
14632 vmanipulator Name [-attach AISObject | -detach | ...]
14633 Tool to create and manage AIS manipulators.
14635 '-attach AISObject' attach manipulator to AISObject
14636 '-adjustPosition {0|center|location|shapeLocation}' adjust position when attaching
14637 '-adjustSize {0|1}' adjust size when attaching
14638 '-enableModes {0|1}' enable modes when attaching
14639 '-view {active | [name of view]}' display manipulator only in defined view,
14640 by default it is displayed in all views of the current viewer
14641 '-detach' detach manipulator
14642 '-startTransform mouse_x mouse_y' - invoke start of transformation
14643 '-transform mouse_x mouse_y' - invoke transformation
14644 '-stopTransform [abort]' - invoke stop of transformation
14645 '-move x y z' - move attached object
14646 '-rotate x y z dx dy dz angle' - rotate attached object
14647 '-scale factor' - scale attached object
14648 '-autoActivate {0|1}' - set activation on detection
14649 '-followTranslation {0|1}' - set following translation transform
14650 '-followRotation {0|1}' - set following rotation transform
14651 '-followDragging {0|1}' - set following dragging transform
14652 '-gap value' - set gap between sub-parts
14653 '-part axis mode {0|1}' - set visual part
14654 '-parts axis mode {0|1}' - set visual part
14655 '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator
14656 '-size value' - set size of manipulator
14657 '-zoomable {0|1}' - set zoom persistence
14658 )" /* [vmanipulator] */);
14660 addCmd ("vselprops", VSelectionProperties, /* [vselprops] */ R"(
14661 vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]
14662 Customizes selection and dynamic highlight parameters for the whole interactive context:
14663 -autoActivate {0|1} disables|enables default computation
14664 and activation of global selection mode
14665 -autoHighlight {0|1} disables|enables automatic highlighting in 3D Viewer
14666 -highlightSelected {0|1} disables|enables highlighting of detected object in selected state
14667 -pickStrategy {first|topmost} : defines picking strategy
14668 'first' to pick first acceptable (default)
14669 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)
14670 -pixTol value sets up pixel tolerance
14671 -depthTol {uniform|uniformpx} value : sets tolerance for sorting results by depth
14672 -depthTol {sensfactor} use sensitive factor for sorting results by depth
14673 -preferClosest {0|1} sets if depth should take precedence over priority while sorting results
14674 -dispMode dispMode sets display mode for highlighting
14675 -layer ZLayer sets ZLayer for highlighting
14676 -color {name|r g b} sets highlight color
14677 -transp value sets transparency coefficient for highlight
14678 -material material sets highlight material
14679 -print prints current state of all mentioned parameters
14680 )" /* [vselprops] */);
14682 addCmd ("vhighlightselected", VSelectionProperties, /* [vhighlightselected] */ R"(
14683 vhighlightselected [0|1] : alias for vselprops -highlightSelected.
14684 )" /* [vhighlightselected] */);
14686 addCmd ("vseldump", VDumpSelectionImage, /* [vseldump] */ R"(
14687 vseldump file -type {depth|unnormDepth|object|owner|selMode|entity|entityType|surfNormal}=depth
14688 -pickedIndex Index=1
14689 [-xrPose base|head=base]
14690 Generate an image based on detection results:
14691 depth normalized depth values
14692 unnormDepth unnormalized depth values
14693 object color of detected object
14694 owner color of detected owner
14695 selMode color of selection mode
14696 entity color of detected entity
14697 entityType color of detected entity type
14698 surfNormal normal direction values
14699 )" /* [vseldump] */);
14701 addCmd ("vviewcube", VViewCube, /* [vviewcube] */ R"(
14703 Displays interactive view manipulation object. Options:
14704 -reset reset geometric and visual attributes
14705 -size Size adapted size of View Cube
14706 -boxSize Size box size
14707 -axes {0|1} show/hide axes (trihedron)
14708 -edges {0|1} show/hide edges of View Cube
14709 -vertices {0|1} show/hide vertices of View Cube
14710 -Yup {0|1} -Zup {0|1} set Y-up or Z-up view orientation
14711 -color Color color of View Cube
14712 -boxColor Color box color
14713 -boxSideColor Color box sides color
14714 -boxEdgeColor Color box edges color
14715 -boxCornerColor Color box corner color
14716 -textColor Color color of side text of view cube
14717 -innerColor Color inner box color
14718 -transparency Value transparency of object within [0, 1] range
14719 -boxTransparency Value transparency of box within [0, 1] range
14720 -xAxisTextColor Color color of X axis label
14721 -yAxisTextColor Color color of Y axis label
14722 -zAxisTextColor Color color of Z axis label
14723 -font Name font name
14724 -fontHeight Value font height
14725 -boxFacetExtension Value box facet extension
14726 -boxEdgeGap Value gap between box edges and box sides
14727 -boxEdgeMinSize Value minimal box edge size
14728 -boxCornerMinSize Value minimal box corner size
14729 -axesPadding Value padding between box and arrows
14730 -roundRadius Value relative radius of corners of sides within [0.0, 0.5] range
14731 -axesRadius Value radius of axes of the trihedron
14732 -axesConeRadius Value radius of the cone (arrow) of the trihedron
14733 -axesSphereRadius Value radius of the sphere (central point) of trihedron
14734 -fixedAnimation {0|1} uninterruptible animation loop
14735 -duration Seconds animation duration in seconds
14736 )" /* [vviewcube] */);
14738 addCmd ("vcolorconvert", VColorConvert, /* [vcolorconvert] */ R"(
14739 vcolorconvert {from|to} type C1 C2 C2
14740 vcolorconvert from type C1 C2 C2 : Converts color from specified color space to linear RGB
14741 vcolorconvert to type R G B : Converts linear RGB color to specified color space
14742 Type can be sRGB, HLS, Lab, or Lch.
14743 )" /* [vcolorconvert] */);
14745 addCmd ("vcolordiff", VColorDiff, /* [vcolordiff] */ R"(
14746 vcolordiff R1 G1 B1 R2 G2 B2 : returns CIEDE2000 color difference between two RGB colors.
14747 )" /* [vcolordiff] */);
14749 addCmd ("vselbvhbuild", VSelBvhBuild, /* [vselbvhbuild] */ R"(
14750 vselbvhbuild [{0|1}] [-nbThreads value] [-wait]
14751 Turns on/off prebuilding of BVH within background thread(s).
14752 -nbThreads number of threads, 1 by default; if < 1 then used (NbLogicalProcessors - 1);
14753 -wait waits for building all of BVH.
14754 )" /* [vselbvhbuild] */);