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.
17 #include <OpenGl_GlCore20.hxx>
19 #include <AIS_Animation.hxx>
20 #include <AIS_AnimationCamera.hxx>
21 #include <AIS_AnimationObject.hxx>
22 #include <AIS_CameraFrustum.hxx>
23 #include <AIS_ColorScale.hxx>
24 #include <AIS_Manipulator.hxx>
25 #include <AIS_RubberBand.hxx>
26 #include <AIS_Shape.hxx>
27 #include <AIS_InteractiveObject.hxx>
28 #include <AIS_ListOfInteractive.hxx>
29 #include <AIS_ListIteratorOfListOfInteractive.hxx>
30 #include <Aspect_Grid.hxx>
32 #include <Draw_ProgressIndicator.hxx>
33 #include <Graphic3d_ArrayOfPolylines.hxx>
34 #include <Graphic3d_AspectMarker3d.hxx>
35 #include <Graphic3d_NameOfTextureEnv.hxx>
36 #include <Graphic3d_GraduatedTrihedron.hxx>
37 #include <Graphic3d_TextureEnv.hxx>
38 #include <Graphic3d_TextureParams.hxx>
39 #include <Graphic3d_TypeOfTextureFilter.hxx>
40 #include <Graphic3d_AspectFillArea3d.hxx>
41 #include <ViewerTest.hxx>
42 #include <ViewerTest_AutoUpdater.hxx>
43 #include <ViewerTest_EventManager.hxx>
44 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
45 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
46 #include <ViewerTest_CmdParser.hxx>
47 #include <V3d_AmbientLight.hxx>
48 #include <V3d_DirectionalLight.hxx>
49 #include <V3d_PositionalLight.hxx>
50 #include <V3d_SpotLight.hxx>
51 #include <Message_ProgressSentry.hxx>
52 #include <NCollection_DoubleMap.hxx>
53 #include <NCollection_List.hxx>
54 #include <NCollection_Vector.hxx>
55 #include <AIS_InteractiveContext.hxx>
56 #include <Draw_Interpretor.hxx>
58 #include <Draw_Appli.hxx>
59 #include <Image_AlienPixMap.hxx>
60 #include <Image_VideoRecorder.hxx>
61 #include <OpenGl_GraphicDriver.hxx>
62 #include <OSD_Timer.hxx>
63 #include <TColStd_HSequenceOfAsciiString.hxx>
64 #include <TColStd_SequenceOfInteger.hxx>
65 #include <TColStd_HSequenceOfReal.hxx>
66 #include <TColgp_Array1OfPnt2d.hxx>
67 #include <TColStd_MapOfAsciiString.hxx>
68 #include <Aspect_TypeOfLine.hxx>
69 #include <Image_Diff.hxx>
70 #include <Aspect_DisplayConnection.hxx>
74 #include <PrsMgr_PresentableObject.hxx>
75 #include <Graphic3d_ClipPlane.hxx>
76 #include <NCollection_DataMap.hxx>
77 #include <Graphic3d_Texture2Dmanual.hxx>
78 #include <Prs3d_ShadingAspect.hxx>
79 #include <Prs3d_Drawer.hxx>
80 #include <Prs3d_LineAspect.hxx>
81 #include <Prs3d_Root.hxx>
82 #include <Prs3d_Text.hxx>
83 #include <Select3D_SensitivePrimitiveArray.hxx>
92 #include <WNT_WClass.hxx>
93 #include <WNT_Window.hxx>
94 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
95 #include <Cocoa_Window.hxx>
97 #include <Xw_Window.hxx>
98 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
99 #include <X11/Xutil.h>
103 // Auxiliary definitions
104 static const char THE_KEY_DELETE = 127;
105 static const char THE_KEY_ESCAPE = 27;
107 //==============================================================================
108 // VIEWER GLOBAL VARIABLES
109 //==============================================================================
111 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
112 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
114 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
115 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
117 extern int VErase (Draw_Interpretor& theDI,
118 Standard_Integer theArgNb,
119 const char** theArgVec);
122 static Handle(WNT_Window)& VT_GetWindow() {
123 static Handle(WNT_Window) WNTWin;
126 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
127 static Handle(Cocoa_Window)& VT_GetWindow()
129 static Handle(Cocoa_Window) aWindow;
132 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
133 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
134 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
137 static Handle(Xw_Window)& VT_GetWindow(){
138 static Handle(Xw_Window) XWWin;
142 static void VProcessEvents(ClientData,int);
145 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
147 static Handle(Aspect_DisplayConnection) aDisplayConnection;
148 return aDisplayConnection;
151 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
153 GetDisplayConnection() = theDisplayConnection;
156 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
157 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
159 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
161 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
162 if (!aWindow.IsNull())
163 return aWindow->HWindow();
164 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
165 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
166 if (!aWindow.IsNull())
167 return aWindow->XWindow();
169 return aWindowHandle;
173 //! Setting additional flag to store 2D mode of the View to avoid scene rotation by mouse/key events
174 class ViewerTest_V3dView : public V3d_View
176 DEFINE_STANDARD_RTTI_INLINE(ViewerTest_V3dView, V3d_View)
178 //! Initializes the view.
179 ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const V3d_TypeOfView theType = V3d_ORTHOGRAPHIC,
180 bool theIs2dMode = false)
181 : V3d_View (theViewer, theType), myIs2dMode (theIs2dMode) {}
183 //! Initializes the view by copying.
184 ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const Handle(V3d_View)& theView)
185 : V3d_View (theViewer, theView), myIs2dMode (false)
187 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (theView))
189 myIs2dMode = aV3dView->IsViewIn2DMode();
193 //! Returns true if 2D mode is set for the view
194 bool IsViewIn2DMode() const { return myIs2dMode; }
196 //! Sets 2D mode for the view
197 void SetView2DMode (bool the2dMode) { myIs2dMode = the2dMode; }
201 //! Returns true if active view in 2D mode.
202 static bool IsCurrentViewIn2DMode()
204 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
206 return aV3dView->IsViewIn2DMode();
211 //! Set if active view in 2D mode.
212 static void SetCurrentView2DMode (bool theIs2d)
214 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
216 aV3dView->SetView2DMode (theIs2d);
222 Standard_Boolean myIs2dMode; //!< 2D mode flag
226 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
227 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
228 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
229 static OpenGl_Caps ViewerTest_myDefaultCaps;
231 static void OSWindowSetup();
235 Quantity_Color FlatColor;
236 Quantity_Color GradientColor1;
237 Quantity_Color GradientColor2;
238 Aspect_GradientFillMethod FillMethod;
239 } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
241 //==============================================================================
242 // EVENT GLOBAL VARIABLES
243 //==============================================================================
245 static int Start_Rot = 0;
246 Standard_Boolean HasHlrOnBeforeRotation = Standard_False;
247 int X_Motion = 0; // Current cursor position
249 int X_ButtonPress = 0; // Last ButtonPress position
250 int Y_ButtonPress = 0;
251 Standard_Boolean IsDragged = Standard_False;
252 Standard_Boolean DragFirst = Standard_False;
253 Standard_Boolean TheIsAnimating = Standard_False;
254 Standard_Boolean Draw_ToExitOnCloseView = Standard_False;
255 Standard_Boolean Draw_ToCloseViewOnEsc = Standard_False;
258 Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand()
260 static Handle(AIS_RubberBand) aBand;
263 aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0);
264 aBand->SetDisplayMode (0);
269 typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators;
271 Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators()
273 static ViewerTest_MapOfAISManipulators aMap;
277 Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator()
279 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
280 for (; anIt.More(); anIt.Next())
282 if (anIt.Value()->HasActiveMode())
290 //==============================================================================
293 static LRESULT WINAPI ViewerWindowProc(
298 static LRESULT WINAPI AdvViewerWindowProc(
306 //==============================================================================
309 //==============================================================================
311 const Handle(Standard_Transient)& ViewerTest::WClass()
313 static Handle(Standard_Transient) theWClass;
315 if (theWClass.IsNull())
317 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
318 CS_VREDRAW | CS_HREDRAW, 0, 0,
319 ::LoadCursor (NULL, IDC_ARROW));
325 //==============================================================================
326 //function : CreateName
327 //purpose : Create numerical name for new object in theMap
328 //==============================================================================
329 template <typename ObjectType>
330 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
331 const TCollection_AsciiString& theDefaultString)
333 if (theObjectMap.IsEmpty())
334 return theDefaultString + TCollection_AsciiString(1);
336 Standard_Integer aNextKey = 1;
337 Standard_Boolean isFound = Standard_False;
340 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
341 // Look for objects with default names
342 if (theObjectMap.IsBound1(aStringKey))
347 isFound = Standard_True;
350 return theDefaultString + TCollection_AsciiString(aNextKey);
353 //==============================================================================
354 //structure : ViewerTest_Names
355 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
356 //==============================================================================
357 struct ViewerTest_Names
360 TCollection_AsciiString myDriverName;
361 TCollection_AsciiString myViewerName;
362 TCollection_AsciiString myViewName;
366 const TCollection_AsciiString& GetDriverName () const
370 void SetDriverName (const TCollection_AsciiString& theDriverName)
372 myDriverName = theDriverName;
374 const TCollection_AsciiString& GetViewerName () const
378 void SetViewerName (const TCollection_AsciiString& theViewerName)
380 myViewerName = theViewerName;
382 const TCollection_AsciiString& GetViewName () const
386 void SetViewName (const TCollection_AsciiString& theViewName)
388 myViewName = theViewName;
391 //===========================================================================
392 //function : Constructor for ViewerTest_Names
393 //purpose : Get view, viewer, driver names from custom string
394 //===========================================================================
396 ViewerTest_Names (const TCollection_AsciiString& theInputString)
398 TCollection_AsciiString aName(theInputString);
399 if (theInputString.IsEmpty())
401 // Get current configuration
402 if (ViewerTest_myDrivers.IsEmpty())
403 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
404 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
406 myDriverName = ViewerTest_myDrivers.Find2
407 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
409 if(ViewerTest_myContexts.IsEmpty())
411 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
412 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
416 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
419 myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
423 // There is at least view name
424 Standard_Integer aParserNumber = 0;
425 for (Standard_Integer i = 0; i < 3; ++i)
427 Standard_Integer aParserPos = aName.SearchFromEnd("/");
431 aName.Split(aParserPos-1);
436 if (aParserNumber == 0)
439 if (!ViewerTest::GetAISContext().IsNull())
441 myDriverName = ViewerTest_myDrivers.Find2
442 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
443 myViewerName = ViewerTest_myContexts.Find2
444 (ViewerTest::GetAISContext());
448 // There is no opened contexts here, need to create names for viewer and driver
449 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
450 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
452 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
453 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
455 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
457 else if (aParserNumber == 1)
459 // Here is viewerName/viewName
460 if (!ViewerTest::GetAISContext().IsNull())
461 myDriverName = ViewerTest_myDrivers.Find2
462 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
465 // There is no opened contexts here, need to create name for driver
466 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
467 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
469 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
471 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
475 //Here is driverName/viewerName/viewName
476 myDriverName = TCollection_AsciiString(aName);
478 TCollection_AsciiString aViewerName(theInputString);
479 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
480 myViewerName = TCollection_AsciiString(aViewerName);
482 myViewName = TCollection_AsciiString(theInputString);
488 //==============================================================================
489 //function : FindContextByView
490 //purpose : Find AIS_InteractiveContext by View
491 //==============================================================================
493 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
495 Handle(AIS_InteractiveContext) anAISContext;
497 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
498 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
500 if (anIter.Value()->CurrentViewer() == theView->Viewer())
501 return anIter.Key2();
507 //==============================================================================
508 //function : SetWindowTitle
509 //purpose : Set window title
510 //==============================================================================
512 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
513 Standard_CString theTitle)
516 const TCollection_ExtendedString theTitleW (theTitle);
517 SetWindowTextW ((HWND )Handle(WNT_Window)::DownCast(theWindow)->HWindow(), theTitleW.ToWideString());
518 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
519 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
521 if(GetDisplayConnection()->GetDisplay())
524 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
525 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
530 //==============================================================================
531 //function : IsWindowOverlapped
532 //purpose : Check if theWindow overlapp another view
533 //==============================================================================
535 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
536 const Standard_Integer thePxTop,
537 const Standard_Integer thePxRight,
538 const Standard_Integer thePxBottom,
539 TCollection_AsciiString& theViewId)
541 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
542 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
544 Standard_Integer aTop = 0,
548 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
549 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
550 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
551 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
552 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
554 theViewId = anIter.Key1();
555 return Standard_True;
558 return Standard_False;
561 // Workaround: to create and delete non-orthographic views outside ViewerTest
562 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
564 ViewerTest_myViews.UnBind1 (theName);
567 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
568 const Handle(V3d_View)& theView)
570 ViewerTest_myViews.Bind (theName, theView);
573 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
575 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
577 //==============================================================================
578 //function : ViewerInit
579 //purpose : Create the window viewer and initialize all the global variable
580 //==============================================================================
582 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
583 const Standard_Integer thePxTop,
584 const Standard_Integer thePxWidth,
585 const Standard_Integer thePxHeight,
586 const TCollection_AsciiString& theViewName,
587 const TCollection_AsciiString& theDisplayName,
588 const Handle(V3d_View)& theViewToClone)
590 // Default position and dimension of the viewer window.
591 // Note that left top corner is set to be sufficiently small to have
592 // window fit in the small screens (actual for remote desktops, see #23003).
593 // The position corresponds to the window's client area, thus some
594 // gap is added for window frame to be visible.
595 Standard_Integer aPxLeft = 20;
596 Standard_Integer aPxTop = 40;
597 Standard_Integer aPxWidth = 409;
598 Standard_Integer aPxHeight = 409;
599 Standard_Boolean toCreateViewer = Standard_False;
600 if (!theViewToClone.IsNull())
602 theViewToClone->Window()->Size (aPxWidth, aPxHeight);
605 Handle(OpenGl_GraphicDriver) aGraphicDriver;
606 ViewerTest_Names aViewNames(theViewName);
607 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
608 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
615 aPxWidth = thePxWidth;
616 if (thePxHeight != 0)
617 aPxHeight = thePxHeight;
619 // Get graphic driver (create it or get from another view)
620 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
622 // Get connection string
623 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
624 TCollection_AsciiString aDisplayName(theDisplayName);
625 if (!aDisplayName.IsEmpty())
626 SetDisplayConnection (new Aspect_DisplayConnection ());
628 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
630 (void)theDisplayName; // avoid warning on unused argument
631 SetDisplayConnection (new Aspect_DisplayConnection ());
634 if (Draw_VirtualWindows)
636 // don't waste the time waiting for VSync when window is not displayed on the screen
637 ViewerTest_myDefaultCaps.swapInterval = 0;
638 // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
639 //ViewerTest_myDefaultCaps.buffersNoSwap = true;
641 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
642 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
644 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
645 toCreateViewer = Standard_True;
649 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
652 //Dispose the window if input parameters are default
653 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
655 Standard_Integer aTop = 0,
662 // Get screen resolution
663 #if defined(_WIN32) || defined(__WIN32__)
665 GetClientRect(GetDesktopWindow(), &aWindowSize);
666 aScreenHeight = aWindowSize.bottom;
667 aScreenWidth = aWindowSize.right;
668 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
669 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
671 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
672 aScreenWidth = WidthOfScreen(aScreen);
673 aScreenHeight = HeightOfScreen(aScreen);
676 TCollection_AsciiString anOverlappedViewId("");
678 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
680 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
682 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
683 && aRight + 2*aPxWidth + 40 > aScreenWidth)
685 if (aBottom + aPxHeight + 40 > aScreenHeight)
692 aPxTop = aBottom + 40;
695 aPxLeft = aRight + 20;
700 TCollection_AsciiString aTitle("3D View - ");
701 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
703 // Change name of current active window
704 if (!ViewerTest::CurrentView().IsNull())
706 TCollection_AsciiString anActiveWindowTitle("3D View - ");
707 anActiveWindowTitle = anActiveWindowTitle
708 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
709 SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString());
713 Handle(V3d_Viewer) a3DViewer;
714 // If it's the single view, we first look for empty context
715 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
717 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
718 anIter(ViewerTest_myContexts);
720 ViewerTest::SetAISContext (anIter.Value());
721 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
723 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
725 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
726 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
728 else if (a3DViewer.IsNull())
730 toCreateViewer = Standard_True;
731 a3DViewer = new V3d_Viewer(aGraphicDriver);
732 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
733 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
734 ViewerTest_DefaultBackground.GradientColor2,
735 ViewerTest_DefaultBackground.FillMethod);
739 if (ViewerTest::GetAISContext().IsNull() ||
740 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
742 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
743 ViewerTest::SetAISContext (aContext);
744 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
748 ViewerTest::ResetEventManager();
753 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
754 Handle(WNT_WClass)::DownCast (WClass()),
755 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
759 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
760 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
762 aPxWidth, aPxHeight);
763 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
765 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
768 aPxWidth, aPxHeight);
770 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
773 Handle(V3d_View) aView;
774 if (!theViewToClone.IsNull())
776 aView = new ViewerTest_V3dView (a3DViewer, theViewToClone);
780 aView = new ViewerTest_V3dView (a3DViewer, a3DViewer->DefaultTypeOfView());
783 aView->SetWindow (VT_GetWindow());
784 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
786 ViewerTest::CurrentView(aView);
787 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
789 // Setup for X11 or NT
792 // Set parameters for V3d_View and V3d_Viewer
793 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
794 aV3dView->SetComputedMode(Standard_False);
796 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
799 a3DViewer->SetDefaultLights();
800 a3DViewer->SetLightOn();
803 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
804 #if TCL_MAJOR_VERSION < 8
805 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
806 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
808 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
809 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
813 VT_GetWindow()->Map();
815 // Set the handle of created view in the event manager
816 ViewerTest::ResetEventManager();
818 ViewerTest::CurrentView()->Redraw();
823 return aViewNames.GetViewName();
826 //==============================================================================
827 //function : RedrawAllViews
828 //purpose : Redraw all created views
829 //==============================================================================
830 void ViewerTest::RedrawAllViews()
832 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
833 for (; aViewIt.More(); aViewIt.Next())
835 const Handle(V3d_View)& aView = aViewIt.Key2();
840 //==============================================================================
842 //purpose : Create the window viewer and initialize all the global variable
843 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
844 //==============================================================================
846 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
848 TCollection_AsciiString aViewName, aDisplayName;
849 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
850 Handle(V3d_View) aCopyFrom;
851 TCollection_AsciiString aName, aValue;
853 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
855 const TCollection_AsciiString anArg = theArgVec[anArgIt];
856 TCollection_AsciiString anArgCase = anArg;
857 anArgCase.LowerCase();
858 if (anArgIt + 1 < theArgsNb
859 && anArgCase == "-name")
861 aViewName = theArgVec[++anArgIt];
863 else if (anArgIt + 1 < theArgsNb
864 && (anArgCase == "-left"
865 || anArgCase == "-l"))
867 aPxLeft = Draw::Atoi (theArgVec[++anArgIt]);
869 else if (anArgIt + 1 < theArgsNb
870 && (anArgCase == "-top"
871 || anArgCase == "-t"))
873 aPxTop = Draw::Atoi (theArgVec[++anArgIt]);
875 else if (anArgIt + 1 < theArgsNb
876 && (anArgCase == "-width"
877 || anArgCase == "-w"))
879 aPxWidth = Draw::Atoi (theArgVec[++anArgIt]);
881 else if (anArgIt + 1 < theArgsNb
882 && (anArgCase == "-height"
883 || anArgCase == "-h"))
885 aPxHeight = Draw::Atoi (theArgVec[++anArgIt]);
887 else if (anArgCase == "-exitonclose")
889 Draw_ToExitOnCloseView = true;
890 if (anArgIt + 1 < theArgsNb
891 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToExitOnCloseView))
896 else if (anArgCase == "-closeonescape"
897 || anArgCase == "-closeonesc")
899 Draw_ToCloseViewOnEsc = true;
900 if (anArgIt + 1 < theArgsNb
901 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToCloseViewOnEsc))
906 else if (anArgCase == "-2d_mode"
907 || anArgCase == "-2dmode"
908 || anArgCase == "-2d")
910 bool toEnable = true;
911 if (anArgIt + 1 < theArgsNb
912 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], toEnable))
916 is2dMode = toEnable ? 1 : 0;
918 else if (anArgIt + 1 < theArgsNb
919 && (anArgCase == "-disp"
920 || anArgCase == "-display"))
922 aDisplayName = theArgVec[++anArgIt];
924 else if (!ViewerTest::CurrentView().IsNull()
925 && aCopyFrom.IsNull()
926 && (anArgCase == "-copy"
927 || anArgCase == "-clone"
928 || anArgCase == "-cloneactive"
929 || anArgCase == "-cloneactiveview"))
931 aCopyFrom = ViewerTest::CurrentView();
934 else if (ViewerTest::SplitParameter (anArg, aName, aValue))
941 else if (aName == "l"
944 aPxLeft = aValue.IntegerValue();
946 else if (aName == "t"
949 aPxTop = aValue.IntegerValue();
951 else if (aName == "disp"
952 || aName == "display")
954 aDisplayName = aValue;
956 else if (aName == "w"
959 aPxWidth = aValue.IntegerValue();
961 else if (aName == "h"
962 || aName == "height")
964 aPxHeight = aValue.IntegerValue();
968 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
972 else if (aViewName.IsEmpty())
978 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
983 #if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
984 if (!aDisplayName.IsEmpty())
986 aDisplayName.Clear();
987 std::cout << "Warning: display parameter will be ignored.\n";
991 ViewerTest_Names aViewNames (aViewName);
992 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
994 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
995 theDi.Eval (aCommand.ToCString());
998 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
1003 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
1004 aViewName, aDisplayName, aCopyFrom);
1007 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
1013 //! Parse HLR algo type.
1014 static Standard_Boolean parseHlrAlgoType (const char* theName,
1015 Prs3d_TypeOfHLR& theType)
1017 TCollection_AsciiString aName (theName);
1019 if (aName == "polyalgo")
1021 theType = Prs3d_TOH_PolyAlgo;
1023 else if (aName == "algo")
1025 theType = Prs3d_TOH_Algo;
1029 return Standard_False;
1031 return Standard_True;
1034 //==============================================================================
1036 //purpose : hidden lines removal algorithm
1037 //==============================================================================
1039 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1041 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1042 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1045 std::cerr << "Error: No opened viewer!\n";
1049 Standard_Boolean hasHlrOnArg = Standard_False;
1050 Standard_Boolean hasShowHiddenArg = Standard_False;
1051 Standard_Boolean isHLROn = Standard_False;
1052 Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
1053 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1054 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1055 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
1057 TCollection_AsciiString anArg (argv[anArgIter]);
1059 if (anUpdateTool.parseRedrawMode (anArg))
1063 else if (anArg == "-showhidden"
1064 && anArgIter + 1 < argc
1065 && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden))
1068 hasShowHiddenArg = Standard_True;
1071 else if ((anArg == "-type"
1073 || anArg == "-algotype")
1074 && anArgIter + 1 < argc
1075 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1080 else if (!hasHlrOnArg
1081 && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn))
1083 hasHlrOnArg = Standard_True;
1087 else if (!hasShowHiddenArg
1088 && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden))
1090 hasShowHiddenArg = Standard_True;
1095 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
1101 di << "HLR: " << aView->ComputedMode() << "\n";
1102 di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
1104 switch (aCtx->DefaultDrawer()->TypeOfHLR())
1106 case Prs3d_TOH_NotSet: di << "NotSet\n"; break;
1107 case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
1108 case Prs3d_TOH_Algo: di << "Algo\n"; break;
1110 anUpdateTool.Invalidate();
1114 Standard_Boolean toRecompute = Standard_False;
1115 if (aTypeOfHLR != Prs3d_TOH_NotSet
1116 && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
1118 toRecompute = Standard_True;
1119 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1121 if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
1123 toRecompute = Standard_True;
1126 aCtx->DefaultDrawer()->EnableDrawHiddenLine();
1130 aCtx->DefaultDrawer()->DisableDrawHiddenLine();
1135 if (aView->ComputedMode() && isHLROn && toRecompute)
1137 AIS_ListOfInteractive aListOfShapes;
1138 aCtx->DisplayedObjects (aListOfShapes);
1139 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
1141 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
1143 aCtx->Redisplay (aShape, Standard_False);
1148 aView->SetComputedMode (isHLROn);
1152 //==============================================================================
1153 //function : VHLRType
1154 //purpose : change type of using HLR algorithm
1155 //==============================================================================
1157 static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1159 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1160 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1163 std::cerr << "Error: No opened viewer!\n";
1167 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1168 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1169 AIS_ListOfInteractive aListOfShapes;
1170 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
1172 TCollection_AsciiString anArg (argv[anArgIter]);
1174 if (anUpdateTool.parseRedrawMode (anArg))
1178 else if ((anArg == "-type"
1180 || anArg == "-algotype")
1181 && anArgIter + 1 < argc
1182 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1188 else if (aTypeOfHLR == Prs3d_TOH_NotSet
1189 && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
1195 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
1196 TCollection_AsciiString aName (argv[anArgIter]);
1197 if (!aMap.IsBound2 (aName))
1199 std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n";
1203 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
1204 if (aShape.IsNull())
1206 std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n";
1209 aListOfShapes.Append (aShape);
1213 if (aTypeOfHLR == Prs3d_TOH_NotSet)
1215 std::cout << "Syntax error: wrong number of arguments!\n";
1219 const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
1222 aCtx->DisplayedObjects (aListOfShapes);
1223 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1226 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
1228 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1229 if (aShape.IsNull())
1234 const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
1235 && aView->ComputedMode();
1237 || aShape->TypeOfHLR() != aTypeOfHLR)
1239 aShape->SetTypeOfHLR (aTypeOfHLR);
1243 aCtx->Redisplay (aShape, Standard_False);
1249 //==============================================================================
1250 //function : FindViewIdByWindowHandle
1251 //purpose : Find theView Id in the map of views by window handle
1252 //==============================================================================
1253 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1254 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
1256 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
1257 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1259 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
1260 if (aWindowHandle == theWindowHandle)
1261 return anIter.Key1();
1263 return TCollection_AsciiString("");
1267 //! Make the view active
1268 void ActivateView (const TCollection_AsciiString& theViewName,
1269 Standard_Boolean theToUpdate = Standard_True)
1271 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1277 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1278 if (!anAISContext.IsNull())
1280 if (!ViewerTest::CurrentView().IsNull())
1282 TCollection_AsciiString aTitle("3D View - ");
1283 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1284 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1287 ViewerTest::CurrentView (aView);
1288 ViewerTest::SetAISContext (anAISContext);
1289 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ") + theViewName + "(*)";
1290 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1292 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1293 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1294 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1296 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1298 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1301 ViewerTest::CurrentView()->Redraw();
1306 //==============================================================================
1307 //function : RemoveView
1309 //==============================================================================
1310 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1311 const Standard_Boolean theToRemoveContext)
1313 if (!ViewerTest_myViews.IsBound2 (theView))
1318 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1319 RemoveView (aViewName, theToRemoveContext);
1322 //==============================================================================
1323 //function : RemoveView
1324 //purpose : Close and remove view from display, clear maps if neccessary
1325 //==============================================================================
1326 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1328 if (!ViewerTest_myViews.IsBound1(theViewName))
1330 cout << "Wrong view name\n";
1334 // Activate another view if it's active now
1335 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1337 if (ViewerTest_myViews.Extent() > 1)
1339 TCollection_AsciiString aNewViewName;
1340 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1341 anIter.More(); anIter.Next())
1343 if (anIter.Key1() != theViewName)
1345 aNewViewName = anIter.Key1();
1349 ActivateView (aNewViewName);
1353 VT_GetWindow().Nullify();
1354 ViewerTest::CurrentView (Handle(V3d_View)());
1355 if (isContextRemoved)
1357 Handle(AIS_InteractiveContext) anEmptyContext;
1358 ViewerTest::SetAISContext(anEmptyContext);
1364 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1365 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1367 // Remove view resources
1368 ViewerTest_myViews.UnBind1(theViewName);
1369 aView->Window()->Unmap();
1372 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1373 XFlush (GetDisplayConnection()->GetDisplay());
1376 // Keep context opened only if the closed view is last to avoid
1377 // unused empty contexts
1378 if (!aCurrentContext.IsNull())
1380 // Check if there are more difined views in the viewer
1381 aCurrentContext->CurrentViewer()->InitDefinedViews();
1382 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1384 // Remove driver if there is no viewers that use it
1385 Standard_Boolean isRemoveDriver = Standard_True;
1386 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1387 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1389 if (aCurrentContext != anIter.Key2() &&
1390 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1392 isRemoveDriver = Standard_False;
1397 aCurrentContext->RemoveAll (Standard_False);
1400 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1401 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1402 #if TCL_MAJOR_VERSION < 8
1403 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1405 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1410 ViewerTest_myContexts.UnBind2(aCurrentContext);
1413 cout << "3D View - " << theViewName << " was deleted.\n";
1414 if (Draw_ToExitOnCloseView)
1416 Draw_Interprete ("exit");
1420 //==============================================================================
1422 //purpose : Remove the view defined by its name
1423 //==============================================================================
1425 static int VClose (Draw_Interpretor& /*theDi*/,
1426 Standard_Integer theArgsNb,
1427 const char** theArgVec)
1429 NCollection_List<TCollection_AsciiString> aViewList;
1432 TCollection_AsciiString anArg (theArgVec[1]);
1434 if (anArg.IsEqual ("ALL")
1435 || anArg.IsEqual ("*"))
1437 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1438 anIter.More(); anIter.Next())
1440 aViewList.Append (anIter.Key1());
1442 if (aViewList.IsEmpty())
1444 std::cout << "No view to close\n";
1450 ViewerTest_Names aViewName (theArgVec[1]);
1451 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1453 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1456 aViewList.Append (aViewName.GetViewName());
1461 // close active view
1462 if (ViewerTest::CurrentView().IsNull())
1464 std::cerr << "No active view!\n";
1467 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1470 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1471 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1472 anIter.More(); anIter.Next())
1474 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1480 //==============================================================================
1481 //function : VActivate
1482 //purpose : Activate the view defined by its ID
1483 //==============================================================================
1485 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1489 theDi.Eval("vviewlist");
1493 TCollection_AsciiString aNameString;
1494 Standard_Boolean toUpdate = Standard_True;
1495 Standard_Boolean toActivate = Standard_True;
1496 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
1498 TCollection_AsciiString anArg (theArgVec[anArgIter]);
1501 && anArg == "-noupdate")
1503 toUpdate = Standard_False;
1506 && aNameString.IsEmpty()
1509 TCollection_AsciiString aTitle("3D View - ");
1510 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1511 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1512 VT_GetWindow().Nullify();
1513 ViewerTest::CurrentView (Handle(V3d_View)());
1514 ViewerTest::ResetEventManager();
1515 theDi << theArgVec[0] << ": all views are inactive\n";
1516 toActivate = Standard_False;
1519 && aNameString.IsEmpty())
1521 aNameString = theArgVec[anArgIter];
1525 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
1534 else if (aNameString.IsEmpty())
1536 std::cout << "Syntax error: wrong number of arguments\n";
1540 // Check if this view exists in the viewer with the driver
1541 ViewerTest_Names aViewNames (aNameString);
1542 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1544 theDi << "Syntax error: wrong view name '" << aNameString << "'\n";
1548 // Check if it is active already
1549 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1551 theDi << theArgVec[0] << ": the view is active already\n";
1555 ActivateView (aViewNames.GetViewName(), toUpdate);
1559 //==============================================================================
1560 //function : VViewList
1561 //purpose : Print current list of views per viewer and graphic driver ID
1562 // shared between viewers
1563 //==============================================================================
1565 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1569 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1570 << "Usage: " << theArgVec[0] << " name";
1573 if (ViewerTest_myContexts.Size() < 1)
1576 Standard_Boolean isTreeView =
1577 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1581 theDi << theArgVec[0] <<":\n";
1584 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers);
1585 aDriverIter.More(); aDriverIter.Next())
1588 theDi << aDriverIter.Key1() << ":\n";
1590 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1591 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1593 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1597 TCollection_AsciiString aContextName(aContextIter.Key1());
1598 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
1601 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews);
1602 aViewIter.More(); aViewIter.Next())
1604 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1606 TCollection_AsciiString aViewName(aViewIter.Key1());
1609 if (aViewIter.Value() == ViewerTest::CurrentView())
1610 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
1612 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1616 theDi << aViewName << " ";
1626 //==============================================================================
1627 //function : VT_ProcessKeyPress
1628 //purpose : Handle KeyPress event from a CString
1629 //==============================================================================
1630 void VT_ProcessKeyPress (const char* buf_ret)
1632 //cout << "KeyPress" << endl;
1633 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1634 // Letter in alphabetic order
1636 if (!strcasecmp (buf_ret, "A")
1637 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1640 aView->SetProj(V3d_XposYnegZpos);
1642 else if (!strcasecmp (buf_ret, "D")
1643 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1648 else if (!strcasecmp (buf_ret, "F"))
1650 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1652 ViewerTest::GetAISContext()->FitSelected (aView);
1660 else if (!strcasecmp (buf_ret, "H"))
1663 std::cout << "HLR" << std::endl;
1664 aView->SetComputedMode (!aView->ComputedMode());
1667 else if (!strcasecmp (buf_ret, "P"))
1670 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1671 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1672 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1674 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1675 if (aContext->NbSelected()==0)
1677 AIS_ListOfInteractive aListOfShapes;
1678 aContext->DisplayedObjects(aListOfShapes);
1679 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1680 anIter.More(); anIter.Next())
1682 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1683 if (aShape.IsNull())
1685 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1686 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1688 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1689 aContext->Redisplay (aShape, Standard_False);
1694 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
1696 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
1697 if (aShape.IsNull())
1699 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1700 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1702 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1703 aContext->Redisplay (aShape, Standard_False);
1707 aContext->UpdateCurrentViewer();
1710 else if (!strcasecmp (buf_ret, "S"))
1712 std::cout << "setup Shaded display mode" << std::endl;
1714 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1715 if(Ctx->NbSelected()==0)
1716 Ctx->SetDisplayMode (AIS_Shaded, Standard_True);
1718 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1719 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
1720 Ctx->UpdateCurrentViewer();
1723 else if (!strcasecmp (buf_ret, "U"))
1725 // Unset display mode
1726 std::cout << "reset display mode to defaults" << std::endl;
1728 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1729 if(Ctx->NbSelected()==0)
1730 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
1732 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1733 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
1734 Ctx->UpdateCurrentViewer();
1738 else if (!strcasecmp (buf_ret, "T")
1739 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1742 aView->SetProj(V3d_Zpos);
1744 else if (!strcasecmp (buf_ret, "B")
1745 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1748 aView->SetProj(V3d_Zneg);
1750 else if (!strcasecmp (buf_ret, "L")
1751 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1754 aView->SetProj(V3d_Xneg);
1756 else if (!strcasecmp (buf_ret, "R")
1757 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1760 aView->SetProj(V3d_Xpos);
1762 else if (!strcasecmp (buf_ret, "W"))
1764 std::cout << "setup WireFrame display mode" << std::endl;
1765 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1766 if(Ctx->NbSelected()==0)
1767 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
1769 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1770 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
1771 Ctx->UpdateCurrentViewer();
1774 else if (!strcasecmp (buf_ret, ","))
1776 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1778 else if (!strcasecmp (buf_ret, "."))
1780 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1782 else if (!strcasecmp (buf_ret, "/"))
1784 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1785 if (aCamera->IsStereo())
1787 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1791 else if (!strcasecmp (buf_ret, "*"))
1793 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1794 if (aCamera->IsStereo())
1796 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1800 else if (*buf_ret == THE_KEY_DELETE)
1802 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1804 && aCtx->NbSelected() > 0)
1806 Draw_Interprete ("verase");
1809 else if (*buf_ret == THE_KEY_ESCAPE)
1811 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1813 && Draw_ToCloseViewOnEsc)
1815 Draw_Interprete (Draw_ToExitOnCloseView ? "exit" : "vclose");
1821 const Standard_Integer aSelMode = Draw::Atoi(buf_ret);
1822 if (aSelMode >= 0 && aSelMode <= 7)
1824 bool toEnable = true;
1825 if (const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext())
1827 AIS_ListOfInteractive aPrsList;
1828 aCtx->DisplayedObjects (aPrsList);
1829 for (AIS_ListOfInteractive::Iterator aPrsIter (aPrsList); aPrsIter.More() && toEnable; aPrsIter.Next())
1831 TColStd_ListOfInteger aModes;
1832 aCtx->ActivatedModes (aPrsIter.Value(), aModes);
1833 for (TColStd_ListOfInteger::Iterator aModeIter (aModes); aModeIter.More() && toEnable; aModeIter.Next())
1835 if (aModeIter.Value() == aSelMode)
1842 TCollection_AsciiString aCmd = TCollection_AsciiString ("vselmode ") + aSelMode + (toEnable ? " 1" : " 0");
1843 Draw_Interprete (aCmd.ToCString());
1848 //==============================================================================
1849 //function : VT_ProcessExpose
1850 //purpose : Redraw the View on an Expose Event
1851 //==============================================================================
1852 void VT_ProcessExpose()
1854 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1855 if (!aView3d.IsNull())
1861 //==============================================================================
1862 //function : VT_ProcessConfigure
1863 //purpose : Resize the View on an Configure Event
1864 //==============================================================================
1865 void VT_ProcessConfigure()
1867 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1868 if (aView3d.IsNull())
1873 aView3d->MustBeResized();
1878 //==============================================================================
1879 //function : VT_ProcessButton1Press
1881 //==============================================================================
1882 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1883 const char** theArgVec,
1884 Standard_Boolean theToPick,
1885 Standard_Boolean theIsShift)
1889 TheIsAnimating = Standard_False;
1890 return Standard_False;
1895 Standard_Real X, Y, Z;
1896 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1898 Draw::Set (theArgVec[1], X);
1899 Draw::Set (theArgVec[2], Y);
1900 Draw::Set (theArgVec[3], Z);
1905 ViewerTest::CurrentEventManager()->ShiftSelect();
1909 ViewerTest::CurrentEventManager()->Select();
1912 return Standard_False;
1915 //==============================================================================
1916 //function : VT_ProcessButton1Release
1917 //purpose : End selecting
1918 //==============================================================================
1919 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1923 IsDragged = Standard_False;
1924 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1927 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1928 X_Motion, Y_Motion);
1932 EM->Select (X_ButtonPress, Y_ButtonPress,
1933 X_Motion, Y_Motion);
1938 //==============================================================================
1939 //function : VT_ProcessButton3Press
1940 //purpose : Start Rotation
1941 //==============================================================================
1942 void VT_ProcessButton3Press()
1944 if (ViewerTest_V3dView::IsCurrentViewIn2DMode())
1950 HasHlrOnBeforeRotation = ViewerTest::CurrentView()->ComputedMode();
1951 if (HasHlrOnBeforeRotation)
1953 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1955 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1958 //==============================================================================
1959 //function : VT_ProcessButton3Release
1960 //purpose : End rotation
1961 //==============================================================================
1962 void VT_ProcessButton3Release()
1967 if (HasHlrOnBeforeRotation)
1969 HasHlrOnBeforeRotation = Standard_False;
1970 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1971 ViewerTest::CurrentView()->Redraw();
1976 //==============================================================================
1977 //function : ProcessControlButton1Motion
1979 //==============================================================================
1981 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1982 static void ProcessControlButton1Motion()
1984 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1986 X_ButtonPress = X_Motion;
1987 Y_ButtonPress = Y_Motion;
1991 //==============================================================================
1992 //function : VT_ProcessControlButton2Motion
1994 //==============================================================================
1995 void VT_ProcessControlButton2Motion()
1997 Standard_Integer aDx = X_Motion - X_ButtonPress;
1998 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
2000 aDy = -aDy; // Xwindow Y axis is from top to Bottom
2002 ViewerTest::CurrentView()->Pan (aDx, aDy);
2004 X_ButtonPress = X_Motion;
2005 Y_ButtonPress = Y_Motion;
2008 //==============================================================================
2009 //function : VT_ProcessControlButton3Motion
2010 //purpose : Rotation
2011 //==============================================================================
2012 void VT_ProcessControlButton3Motion()
2016 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
2020 //==============================================================================
2021 //function : VT_ProcessMotion
2023 //==============================================================================
2024 void VT_ProcessMotion()
2026 //pre-hilights detected objects at mouse position
2028 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
2029 EM->MoveTo(X_Motion, Y_Motion);
2033 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
2035 Xpix = X_Motion;Ypix=Y_Motion;
2038 //==============================================================================
2039 //function : ViewProject: implements VAxo, VTop, VLeft, ...
2040 //purpose : Switches to an axonometric, top, left and other views
2041 //==============================================================================
2043 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
2045 if ( ViewerTest::CurrentView().IsNull() )
2047 di<<"Call vinit before this command, please\n";
2051 ViewerTest::CurrentView()->SetProj(ori);
2055 //==============================================================================
2057 //purpose : Switch to an Axonometric view
2058 //Draw arg : No args
2059 //==============================================================================
2061 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
2063 return ViewProject(di, V3d_XposYnegZpos);
2066 //==============================================================================
2068 //purpose : Switch to a Top View
2069 //Draw arg : No args
2070 //==============================================================================
2072 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
2074 return ViewProject(di, V3d_Zpos);
2077 //==============================================================================
2078 //function : VBottom
2079 //purpose : Switch to a Bottom View
2080 //Draw arg : No args
2081 //==============================================================================
2083 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
2085 return ViewProject(di, V3d_Zneg);
2088 //==============================================================================
2090 //purpose : Switch to a Left View
2091 //Draw arg : No args
2092 //==============================================================================
2094 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
2096 return ViewProject(di, V3d_Xneg);
2099 //==============================================================================
2101 //purpose : Switch to a Right View
2102 //Draw arg : No args
2103 //==============================================================================
2105 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
2107 return ViewProject(di, V3d_Xpos);
2110 //==============================================================================
2112 //purpose : Switch to a Front View
2113 //Draw arg : No args
2114 //==============================================================================
2116 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
2118 return ViewProject(di, V3d_Yneg);
2121 //==============================================================================
2123 //purpose : Switch to a Back View
2124 //Draw arg : No args
2125 //==============================================================================
2127 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
2129 return ViewProject(di, V3d_Ypos);
2132 //==============================================================================
2134 //purpose : Dsiplay help on viewer Keyboead and mouse commands
2135 //Draw arg : No args
2136 //==============================================================================
2138 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
2141 di << "Q : Quit the application\n";
2143 di << "=========================\n";
2144 di << "F : FitAll\n";
2145 di << "T : TopView\n";
2146 di << "B : BottomView\n";
2147 di << "R : RightView\n";
2148 di << "L : LeftView\n";
2149 di << "A : AxonometricView\n";
2150 di << "D : ResetView\n";
2152 di << "=========================\n";
2153 di << "S : Shading\n";
2154 di << "W : Wireframe\n";
2155 di << "H : HidelLineRemoval\n";
2156 di << "U : Unset display mode\n";
2157 di << "Delete : Remove selection from viewer\n";
2159 di << "=========================\n";
2160 di << "Selection mode \n";
2161 di << "0 : Shape\n";
2162 di << "1 : Vertex\n";
2166 di << "5 : Shell\n";
2167 di << "6 : Solid\n";
2168 di << "7 : Compound\n";
2170 di << "=========================\n";
2171 di << "Z : Switch Z clipping On/Off\n";
2172 di << ", : Hilight next detected\n";
2173 di << ". : Hilight previous detected\n";
2180 static Standard_Boolean Ppick = 0;
2181 static Standard_Integer Pargc = 0;
2182 static const char** Pargv = NULL;
2185 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
2190 if (!ViewerTest_myViews.IsEmpty()) {
2192 WPARAM fwKeys = wParam;
2197 // Delete view from map of views
2198 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
2203 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
2204 || ViewerTest::CurrentView().IsNull())
2206 // Activate inactive window
2207 if(GetWindowHandle(VT_GetWindow()) != hwnd)
2209 ActivateView (FindViewIdByWindowHandle(hwnd));
2215 if (IsDragged && !DragFirst)
2217 if (!GetActiveAISManipulator().IsNull())
2219 GetActiveAISManipulator()->StopTransform();
2220 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
2223 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2225 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2226 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2229 VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0);
2231 IsDragged = Standard_False;
2232 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2235 if (IsDragged && !DragFirst)
2237 if (!GetActiveAISManipulator().IsNull())
2239 GetActiveAISManipulator()->StopTransform (Standard_False);
2240 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
2242 IsDragged = Standard_False;
2244 return ViewerWindowProc (hwnd, Msg, wParam, lParam);
2246 case WM_LBUTTONDOWN:
2247 if (!GetActiveAISManipulator().IsNull())
2249 IsDragged = ( fwKeys == MK_LBUTTON );
2253 IsDragged = ( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) );
2258 DragFirst = Standard_True;
2259 X_ButtonPress = LOWORD(lParam);
2260 Y_ButtonPress = HIWORD(lParam);
2262 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2267 X_Motion = LOWORD (lParam);
2268 Y_Motion = HIWORD (lParam);
2269 if (!GetActiveAISManipulator().IsNull())
2273 GetActiveAISManipulator()->StartTransform (X_ButtonPress, Y_ButtonPress, ViewerTest::CurrentView());
2277 GetActiveAISManipulator()->Transform (X_Motion, Y_Motion, ViewerTest::CurrentView());
2278 ViewerTest::GetAISContext()->CurrentViewer()->Redraw();
2283 bool toRedraw = false;
2284 if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2286 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2291 if (GetClientRect (hwnd, &aRect))
2293 int aHeight = aRect.bottom - aRect.top;
2294 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2295 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed);
2300 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2304 DragFirst = Standard_False;
2307 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2311 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2315 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2319 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
2325 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2328 return DefWindowProcW (hwnd, Msg, wParam, lParam);
2335 BeginPaint(hwnd, &ps);
2336 EndPaint(hwnd, &ps);
2341 VT_ProcessConfigure();
2346 switch (aView->RenderingParams().StereoMode)
2348 case Graphic3d_StereoMode_RowInterlaced:
2349 case Graphic3d_StereoMode_ColumnInterlaced:
2350 case Graphic3d_StereoMode_ChessBoard:
2351 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2359 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2362 c[0] = (char) wParam;
2364 if (wParam == VK_DELETE)
2366 c[0] = THE_KEY_DELETE;
2368 else if (wParam == VK_ESCAPE)
2370 c[0] = THE_KEY_ESCAPE;
2373 else if (wParam == VK_OEM_COMMA)
2378 else if (wParam == VK_OEM_PERIOD)
2382 else if (wParam == VK_DIVIDE)
2387 else if (wParam == VK_MULTIPLY)
2391 VT_ProcessKeyPress (c);
2399 VT_ProcessButton3Release();
2402 case WM_LBUTTONDOWN:
2403 case WM_MBUTTONDOWN:
2404 case WM_RBUTTONDOWN:
2406 WPARAM fwKeys = wParam;
2410 X_ButtonPress = LOWORD(lParam);
2411 Y_ButtonPress = HIWORD(lParam);
2413 if (Msg == WM_LBUTTONDOWN)
2415 if ((fwKeys & MK_CONTROL) != 0)
2417 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2421 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2424 else if (Msg == WM_RBUTTONDOWN)
2427 VT_ProcessButton3Press();
2434 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2435 if (wParam & MK_CONTROL)
2437 if (aView->Camera()->IsStereo())
2439 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2443 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2450 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2457 //cout << "\t WM_MOUSEMOVE" << endl;
2458 WPARAM fwKeys = wParam;
2459 X_Motion = LOWORD(lParam);
2460 Y_Motion = HIWORD(lParam);
2463 (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 )
2466 X_ButtonPress = LOWORD(lParam);
2467 Y_ButtonPress = HIWORD(lParam);
2469 if ((fwKeys & MK_RBUTTON) != 0) {
2471 VT_ProcessButton3Press();
2475 if ((fwKeys & MK_CONTROL) != 0)
2477 if ((fwKeys & MK_LBUTTON) != 0)
2479 ProcessControlButton1Motion();
2481 else if ((fwKeys & MK_MBUTTON) != 0
2482 || ((fwKeys & MK_LBUTTON) != 0
2483 && (fwKeys & MK_RBUTTON) != 0))
2485 VT_ProcessControlButton2Motion();
2487 else if ((fwKeys & MK_RBUTTON) != 0)
2489 VT_ProcessControlButton3Motion();
2492 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2500 return DefWindowProcW (hwnd, Msg, wParam, lParam);
2505 //==============================================================================
2506 //function : ViewerMainLoop
2507 //purpose : Get a Event on the view and dispatch it
2508 //==============================================================================
2511 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2513 Ppick = (argc > 0)? 1 : 0;
2521 cout << "Start picking" << endl;
2523 while ( Ppick == 1 ) {
2524 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2525 if (GetMessageW (&msg, NULL, 0, 0))
2527 TranslateMessage (&msg);
2528 DispatchMessageW (&msg);
2532 cout << "Picking done" << endl;
2538 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2540 int min( int a, int b )
2548 int max( int a, int b )
2556 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2559 static XEvent aReport;
2560 Standard_Boolean pick = argc > 0;
2561 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2562 XNextEvent (aDisplay, &aReport);
2564 // Handle event for the chosen display connection
2565 switch (aReport.type) {
2568 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2571 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2577 // Activate inactive view
2578 Window aWindow = GetWindowHandle(VT_GetWindow());
2579 if(aWindow != aReport.xfocus.window)
2581 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2590 case ConfigureNotify:
2592 VT_ProcessConfigure();
2601 XComposeStatus status_in_out;
2603 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2604 (char *) buf_ret , 10 ,
2605 &ks_ret , &status_in_out ) ;
2608 buf_ret[ret_len] = '\0' ;
2612 VT_ProcessKeyPress (buf_ret);
2618 X_ButtonPress = aReport.xbutton.x;
2619 Y_ButtonPress = aReport.xbutton.y;
2621 if (aReport.xbutton.button == Button1)
2623 if (aReport.xbutton.state & ControlMask)
2625 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2629 IsDragged = Standard_True;
2630 DragFirst = Standard_True;
2633 else if (aReport.xbutton.button == Button3)
2636 VT_ProcessButton3Press();
2646 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2648 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2649 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2653 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2654 if( aContext.IsNull() )
2656 cout << "The context is null. Please use vinit before createmesh" << endl;
2660 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2661 if( aReport.xbutton.button==1 )
2665 aContext->ShiftSelect (Standard_True);
2669 aContext->Select (Standard_True);
2674 aContext->ShiftSelect(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2675 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2676 ViewerTest::CurrentView(), Standard_True);
2680 aContext->Select(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2681 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2682 ViewerTest::CurrentView(), Standard_True);
2685 VT_ProcessButton3Release();
2687 IsDragged = Standard_False;
2690 VT_ProcessButton3Release();
2695 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2703 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2705 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2709 X_Motion = aReport.xmotion.x;
2710 Y_Motion = aReport.xmotion.y;
2711 DragFirst = Standard_False;
2713 Window aWindow = GetWindowHandle(VT_GetWindow());
2716 unsigned int aWidth, aHeight, aBorderWidth, aDepth;
2717 XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth);
2718 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2719 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed);
2720 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2724 X_Motion = aReport.xmotion.x;
2725 Y_Motion = aReport.xmotion.y;
2727 // remove all the ButtonMotionMaskr
2728 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2730 if ( aReport.xmotion.state & ControlMask ) {
2731 if ( aReport.xmotion.state & Button1Mask ) {
2732 ProcessControlButton1Motion();
2734 else if ( aReport.xmotion.state & Button2Mask ) {
2735 VT_ProcessControlButton2Motion();
2737 else if ( aReport.xmotion.state & Button3Mask ) {
2738 VT_ProcessControlButton3Motion();
2752 //==============================================================================
2753 //function : VProcessEvents
2754 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2755 // event in the Viewer window
2756 //==============================================================================
2758 static void VProcessEvents(ClientData,int)
2760 NCollection_Vector<int> anEventNumbers;
2761 // Get number of messages from every display
2762 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2763 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2765 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2767 // Handle events for every display
2768 int anEventIter = 0;
2769 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2770 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2772 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2773 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2775 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2776 int anEventResult = ViewerMainLoop( 0, NULL);
2777 // If window is closed or context was not found finish current event processing loop
2783 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2788 //==============================================================================
2789 //function : OSWindowSetup
2790 //purpose : Setup for the X11 window to be able to cath the event
2791 //==============================================================================
2794 static void OSWindowSetup()
2796 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2799 Window window = VT_GetWindow()->XWindow();
2800 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2801 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2802 XSynchronize(aDisplay, 1);
2804 // X11 : For keyboard on SUN
2806 wmhints.flags = InputHint;
2809 XSetWMHints( aDisplay, window, &wmhints);
2811 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2812 ButtonPressMask | ButtonReleaseMask |
2813 StructureNotifyMask |
2815 Button1MotionMask | Button2MotionMask |
2816 Button3MotionMask | FocusChangeMask
2818 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2819 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2821 XSynchronize(aDisplay, 0);
2829 //==============================================================================
2832 //==============================================================================
2834 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
2836 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2839 std::cout << "Error: no active viewer!\n";
2843 Standard_Boolean toFit = Standard_True;
2844 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2845 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2847 TCollection_AsciiString anArg (theArgv[anArgIter]);
2849 if (anUpdateTool.parseRedrawMode (anArg))
2853 else if (anArg == "-selected")
2855 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
2856 toFit = Standard_False;
2860 std::cout << "Syntax error at '" << anArg << "'\n";
2866 aView->FitAll (0.01, Standard_False);
2871 //=======================================================================
2872 //function : VFitArea
2873 //purpose : Fit view to show area located between two points
2874 // : given in world 2D or 3D coordinates.
2875 //=======================================================================
2876 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2878 Handle(V3d_View) aView = ViewerTest::CurrentView();
2881 std::cerr << theArgVec[0] << "Error: No active view.\n";
2886 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2887 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2891 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2892 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2893 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2894 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2896 else if (theArgNb == 7)
2898 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2899 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2900 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2901 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2902 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2903 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2907 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2908 theDI.PrintHelp(theArgVec[0]);
2912 // Convert model coordinates to view space
2913 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2914 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2915 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2917 // Determine fit area
2918 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2919 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2921 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2923 if (aDiagonal < Precision::Confusion())
2925 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2929 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2933 //==============================================================================
2935 //purpose : ZFitall, no DRAW arguments
2936 //Draw arg : No args
2937 //==============================================================================
2938 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2940 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2942 if (aCurrentView.IsNull())
2944 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2950 aCurrentView->ZFitAll();
2951 aCurrentView->Redraw();
2955 Standard_Real aScale = 1.0;
2959 aScale = Draw::Atoi (theArgVec[1]);
2962 aCurrentView->ZFitAll (aScale);
2963 aCurrentView->Redraw();
2968 //==============================================================================
2969 //function : VRepaint
2971 //==============================================================================
2972 static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
2974 Handle(V3d_View) aView = ViewerTest::CurrentView();
2977 std::cout << "Error: no active viewer!\n";
2981 Standard_Boolean isImmediateUpdate = Standard_False;
2982 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2984 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2986 if (anArg == "-immediate")
2988 isImmediateUpdate = Standard_True;
2989 if (anArgIter + 1 < theArgNb
2990 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
2997 std::cout << "Syntax error at '" << anArg << "'\n";
3001 if (isImmediateUpdate)
3003 aView->RedrawImmediate();
3012 //==============================================================================
3014 //purpose : Remove all the object from the viewer
3015 //Draw arg : No args
3016 //==============================================================================
3018 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
3020 Handle(V3d_View) V = ViewerTest::CurrentView();
3022 ViewerTest::Clear();
3026 //==============================================================================
3029 //==============================================================================
3031 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3032 { if (ViewerTest::CurrentView().IsNull() ) return 1;
3035 di << argv[0] << "Invalid number of arguments\n";
3039 while (ViewerMainLoop( argc, argv)) {
3045 //==============================================================================
3047 //purpose : Load image as background
3048 //==============================================================================
3050 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3052 if (argc < 2 || argc > 3)
3054 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n";
3055 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n";
3059 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3060 if(AISContext.IsNull())
3062 di << "use 'vinit' command before " << argv[0] << "\n";
3066 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
3069 const char* szType = argv[2];
3070 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
3071 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
3072 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
3073 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
3076 di << "Wrong fill type : " << szType << "\n";
3077 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
3082 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3083 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
3088 //==============================================================================
3089 //function : VSetBgMode
3090 //purpose : Change background image fill type
3091 //==============================================================================
3093 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3097 di << "Usage : " << argv[0] << " filltype : Change background image mode\n";
3098 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n";
3102 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3103 if(AISContext.IsNull())
3105 di << "use 'vinit' command before " << argv[0] << "\n";
3108 Aspect_FillMethod aFillType = Aspect_FM_NONE;
3109 const char* szType = argv[1];
3110 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
3111 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
3112 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
3113 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
3116 di << "Wrong fill type : " << szType << "\n";
3117 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
3120 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3121 V3dView->SetBgImageStyle(aFillType, Standard_True);
3125 //==============================================================================
3126 //function : VSetGradientBg
3127 //purpose : Mount gradient background
3128 //==============================================================================
3129 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3133 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background\n";
3134 di << "R1,G1,B1,R2,G2,B2 = [0..255]\n";
3135 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3136 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3140 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3141 if(AISContext.IsNull())
3143 di << "use 'vinit' command before " << argv[0] << "\n";
3149 Standard_Real R1 = Draw::Atof(argv[1])/255.;
3150 Standard_Real G1 = Draw::Atof(argv[2])/255.;
3151 Standard_Real B1 = Draw::Atof(argv[3])/255.;
3152 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
3154 Standard_Real R2 = Draw::Atof(argv[4])/255.;
3155 Standard_Real G2 = Draw::Atof(argv[5])/255.;
3156 Standard_Real B2 = Draw::Atof(argv[6])/255.;
3158 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
3159 int aType = Draw::Atoi(argv[7]);
3160 if( aType < 0 || aType > 8 )
3162 di << "Wrong fill type \n";
3163 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3164 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3168 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
3170 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3171 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
3177 //==============================================================================
3178 //function : VSetGradientBgMode
3179 //purpose : Change gradient background fill style
3180 //==============================================================================
3181 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3185 di << "Usage : " << argv[0] << " Type : Change gradient background fill type\n";
3186 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3187 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3191 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3192 if(AISContext.IsNull())
3194 di << "use 'vinit' command before " << argv[0] << "\n";
3199 int aType = Draw::Atoi(argv[1]);
3200 if( aType < 0 || aType > 8 )
3202 di << "Wrong fill type \n";
3203 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3204 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3208 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
3210 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3211 V3dView->SetBgGradientStyle( aMethod, 1 );
3217 //==============================================================================
3218 //function : VSetColorBg
3219 //purpose : Set color background
3220 //==============================================================================
3221 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3225 di << "Usage : " << argv[0] << " R G B : Set color background\n";
3226 di << "R,G,B = [0..255]\n";
3230 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3231 if(AISContext.IsNull())
3233 di << "use 'vinit' command before " << argv[0] << "\n";
3239 Standard_Real R = Draw::Atof(argv[1])/255.;
3240 Standard_Real G = Draw::Atof(argv[2])/255.;
3241 Standard_Real B = Draw::Atof(argv[3])/255.;
3242 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
3244 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3245 V3dView->SetBackgroundColor( aColor );
3252 //==============================================================================
3253 //function : VSetDefaultBg
3254 //purpose : Set default viewer background fill color
3255 //==============================================================================
3256 static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3261 std::cout << "Error: wrong syntax! See usage:\n";
3262 theDI.PrintHelp (theArgVec[0]);
3266 ViewerTest_DefaultBackground.FillMethod =
3267 theArgNb == 4 ? Aspect_GFM_NONE
3268 : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]);
3272 Standard_Real R = Draw::Atof (theArgVec[1]) / 255.;
3273 Standard_Real G = Draw::Atof (theArgVec[2]) / 255.;
3274 Standard_Real B = Draw::Atof (theArgVec[3]) / 255.;
3275 ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB);
3279 Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.;
3280 Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.;
3281 Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.;
3282 ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB);
3284 Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.;
3285 Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.;
3286 Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.;
3287 ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB);
3290 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
3291 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
3293 const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer();
3294 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
3295 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
3296 ViewerTest_DefaultBackground.GradientColor2,
3297 ViewerTest_DefaultBackground.FillMethod);
3303 //==============================================================================
3305 //purpose : View Scaling
3306 //==============================================================================
3308 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3310 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3311 if ( V3dView.IsNull() ) return 1;
3314 di << argv[0] << "Invalid number of arguments\n";
3317 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
3320 //==============================================================================
3321 //function : VZBuffTrihedron
3323 //==============================================================================
3325 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
3326 Standard_Integer theArgNb,
3327 const char** theArgVec)
3329 Handle(V3d_View) aView = ViewerTest::CurrentView();
3332 std::cout << "Error: no active viewer!\n";
3336 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
3338 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
3339 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
3340 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
3341 Quantity_Color anArrowColorX = Quantity_NOC_RED;
3342 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
3343 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
3344 Standard_Real aScale = 0.1;
3345 Standard_Real aSizeRatio = 0.8;
3346 Standard_Real anArrowDiam = 0.05;
3347 Standard_Integer aNbFacets = 12;
3348 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3350 Standard_CString anArg = theArgVec[anArgIter];
3351 TCollection_AsciiString aFlag (anArg);
3353 if (anUpdateTool.parseRedrawMode (aFlag))
3357 else if (aFlag == "-on")
3361 else if (aFlag == "-off")
3363 aView->TriedronErase();
3366 else if (aFlag == "-pos"
3367 || aFlag == "-position"
3368 || aFlag == "-corner")
3370 if (++anArgIter >= theArgNb)
3372 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3376 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3377 aPosName.LowerCase();
3378 if (aPosName == "center")
3380 aPosition = Aspect_TOTP_CENTER;
3382 else if (aPosName == "left_lower"
3383 || aPosName == "lower_left"
3384 || aPosName == "leftlower"
3385 || aPosName == "lowerleft")
3387 aPosition = Aspect_TOTP_LEFT_LOWER;
3389 else if (aPosName == "left_upper"
3390 || aPosName == "upper_left"
3391 || aPosName == "leftupper"
3392 || aPosName == "upperleft")
3394 aPosition = Aspect_TOTP_LEFT_UPPER;
3396 else if (aPosName == "right_lower"
3397 || aPosName == "lower_right"
3398 || aPosName == "rightlower"
3399 || aPosName == "lowerright")
3401 aPosition = Aspect_TOTP_RIGHT_LOWER;
3403 else if (aPosName == "right_upper"
3404 || aPosName == "upper_right"
3405 || aPosName == "rightupper"
3406 || aPosName == "upperright")
3408 aPosition = Aspect_TOTP_RIGHT_UPPER;
3412 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3416 else if (aFlag == "-type")
3418 if (++anArgIter >= theArgNb)
3420 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3424 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3425 aTypeName.LowerCase();
3426 if (aTypeName == "wireframe"
3427 || aTypeName == "wire")
3429 aVisType = V3d_WIREFRAME;
3431 else if (aTypeName == "zbuffer"
3432 || aTypeName == "shaded")
3434 aVisType = V3d_ZBUFFER;
3438 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3441 else if (aFlag == "-scale")
3443 if (++anArgIter >= theArgNb)
3445 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3449 aScale = Draw::Atof (theArgVec[anArgIter]);
3451 else if (aFlag == "-size"
3452 || aFlag == "-sizeratio")
3454 if (++anArgIter >= theArgNb)
3456 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3460 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3462 else if (aFlag == "-arrowdiam"
3463 || aFlag == "-arrowdiameter")
3465 if (++anArgIter >= theArgNb)
3467 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3471 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3473 else if (aFlag == "-nbfacets")
3475 if (++anArgIter >= theArgNb)
3477 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3481 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3483 else if (aFlag == "-colorlabel"
3484 || aFlag == "-colorlabels")
3486 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3487 theArgVec + anArgIter + 1,
3491 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3494 anArgIter += aNbParsed;
3496 else if (aFlag == "-colorarrowx")
3498 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3499 theArgVec + anArgIter + 1,
3503 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3506 anArgIter += aNbParsed;
3508 else if (aFlag == "-colorarrowy")
3510 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3511 theArgVec + anArgIter + 1,
3515 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3518 anArgIter += aNbParsed;
3520 else if (aFlag == "-colorarrowz")
3522 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3523 theArgVec + anArgIter + 1,
3527 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3530 anArgIter += aNbParsed;
3534 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3539 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3540 aSizeRatio, anArrowDiam, aNbFacets);
3541 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
3546 //==============================================================================
3547 //function : VRotate
3548 //purpose : Camera Rotating
3549 //==============================================================================
3551 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3553 Handle(V3d_View) aView = ViewerTest::CurrentView();
3556 std::cout << "No active view!\n";
3560 Standard_Boolean hasFlags = Standard_False;
3561 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3563 Standard_CString anArg (theArgVec[anArgIter]);
3564 TCollection_AsciiString aFlag (anArg);
3566 if (aFlag == "-mousestart"
3567 || aFlag == "-mousefrom")
3569 hasFlags = Standard_True;
3570 if (anArgIter + 2 >= theArgNb)
3572 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3576 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3577 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3578 aView->StartRotation (anX, anY);
3580 else if (aFlag == "-mousemove")
3582 hasFlags = Standard_True;
3583 if (anArgIter + 2 >= theArgNb)
3585 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3589 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3590 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3591 aView->Rotation (anX, anY);
3593 else if (theArgNb != 4
3596 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3605 else if (theArgNb == 4)
3607 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3608 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3609 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3610 aView->Rotate (anAX, anAY, anAZ);
3613 else if (theArgNb == 7)
3615 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3616 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3617 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3619 Standard_Real anX = Draw::Atof (theArgVec[4]);
3620 Standard_Real anY = Draw::Atof (theArgVec[5]);
3621 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3623 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3627 std::cout << "Error: Invalid number of arguments\n";
3631 //==============================================================================
3633 //purpose : View zoom in / out (relative to current zoom)
3634 //==============================================================================
3636 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3637 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3638 if ( V3dView.IsNull() ) {
3643 Standard_Real coef = Draw::Atof(argv[1]);
3644 if ( coef <= 0.0 ) {
3645 di << argv[1] << "Invalid value\n";
3648 V3dView->SetZoom( Draw::Atof(argv[1]) );
3651 di << argv[0] << " Invalid number of arguments\n";
3656 //==============================================================================
3658 //purpose : View panning (in pixels)
3659 //==============================================================================
3661 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3662 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3663 if ( V3dView.IsNull() ) return 1;
3666 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
3669 di << argv[0] << " Invalid number of arguments\n";
3674 //==============================================================================
3676 //purpose : Place the point (in pixels) at the center of the window
3677 //==============================================================================
3678 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3680 Handle(V3d_View) aView = ViewerTest::CurrentView();
3683 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3689 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3693 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3698 static int VColorScale (Draw_Interpretor& theDI,
3699 Standard_Integer theArgNb,
3700 const char** theArgVec)
3702 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3703 Handle(V3d_View) aView = ViewerTest::CurrentView();
3704 if (aContext.IsNull())
3706 std::cout << "Error: no active view!\n";
3711 std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n";
3715 Handle(AIS_ColorScale) aColorScale;
3716 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
3718 // find existing object
3719 aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
3720 if (aColorScale.IsNull())
3722 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
3729 if (aColorScale.IsNull())
3731 std::cout << "Syntax error: colorscale with a given name does not exist.\n";
3735 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
3736 << "Min range: " << aColorScale->GetMin() << "\n"
3737 << "Max range: " << aColorScale->GetMax() << "\n"
3738 << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n"
3739 << "Text height: " << aColorScale->GetTextHeight() << "\n"
3740 << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n"
3741 << "Color scale title: " << aColorScale->GetTitle() << "\n"
3742 << "Label position: ";
3743 switch (aColorScale->GetLabelPosition())
3745 case Aspect_TOCSP_NONE:
3748 case Aspect_TOCSP_LEFT:
3751 case Aspect_TOCSP_RIGHT:
3754 case Aspect_TOCSP_CENTER:
3755 theDI << "Center\n";
3761 if (aColorScale.IsNull())
3763 aColorScale = new AIS_ColorScale();
3764 aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
3765 aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
3768 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
3769 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
3771 Standard_CString anArg = theArgVec[anArgIter];
3772 TCollection_AsciiString aFlag (anArg);
3774 if (anUpdateTool.parseRedrawMode (aFlag))
3778 else if (aFlag == "-range")
3780 if (anArgIter + 3 >= theArgNb)
3782 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3786 const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]);
3787 const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]);
3788 const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]);
3789 if (!aRangeMin.IsRealValue()
3790 || !aRangeMax.IsRealValue())
3792 std::cout << "Error: the range values should be real!\n";
3795 else if (!aNbIntervals.IsIntegerValue())
3797 std::cout << "Error: the number of intervals should be integer!\n";
3801 aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue());
3802 aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue());
3804 else if (aFlag == "-font")
3806 if (anArgIter + 1 >= theArgNb)
3808 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3811 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
3812 if (!aFontArg.IsIntegerValue())
3814 std::cout << "Error: HeightFont value should be integer!\n";
3818 aColorScale->SetTextHeight (aFontArg.IntegerValue());
3821 else if (aFlag == "-textpos")
3823 if (anArgIter + 1 >= theArgNb)
3825 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3829 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
3830 aTextPosArg.LowerCase();
3831 Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE;
3832 if (aTextPosArg == "none")
3834 aLabPosition = Aspect_TOCSP_NONE;
3836 else if (aTextPosArg == "left")
3838 aLabPosition = Aspect_TOCSP_LEFT;
3840 else if (aTextPosArg == "right")
3842 aLabPosition = Aspect_TOCSP_RIGHT;
3844 else if (aTextPosArg == "center")
3846 aLabPosition = Aspect_TOCSP_CENTER;
3850 std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
3853 aColorScale->SetLabelPosition (aLabPosition);
3855 else if (aFlag == "-logarithmic"
3858 if (anArgIter + 1 >= theArgNb)
3860 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3864 Standard_Boolean IsLog;
3865 if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
3867 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3870 aColorScale->SetLogarithmic (IsLog);
3872 else if (aFlag == "-huerange"
3875 if (anArgIter + 2 >= theArgNb)
3877 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3881 const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]);
3882 const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]);
3883 aColorScale->SetHueRange (aHueMin, aHueMax);
3885 else if (aFlag == "-colorrange")
3887 Quantity_Color aColorMin, aColorMax;
3888 Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3889 theArgVec + (anArgIter + 1),
3891 anArgIter += aNbParsed1;
3892 Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3893 theArgVec + (anArgIter + 1),
3895 anArgIter += aNbParsed2;
3899 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3903 aColorScale->SetColorRange (aColorMin, aColorMax);
3905 else if (aFlag == "-reversed"
3906 || aFlag == "-inverted"
3907 || aFlag == "-topdown"
3908 || aFlag == "-bottomup")
3910 Standard_Boolean toEnable = Standard_True;
3911 if (anArgIter + 1 < theArgNb
3912 && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable))
3916 aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable);
3918 else if (aFlag == "-smooth"
3919 || aFlag == "-smoothtransition")
3921 Standard_Boolean toEnable = Standard_True;
3922 if (anArgIter + 1 < theArgNb
3923 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
3927 aColorScale->SetSmoothTransition (toEnable);
3929 else if (aFlag == "-xy")
3931 if (anArgIter + 2 >= theArgNb)
3933 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3937 const TCollection_AsciiString anX (theArgVec[++anArgIter]);
3938 const TCollection_AsciiString anY (theArgVec[++anArgIter]);
3939 if (!anX.IsIntegerValue()
3940 || !anY.IsIntegerValue())
3942 std::cout << "Error: coordinates should be integer values!\n";
3946 aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue());
3948 else if (aFlag == "-width"
3950 || aFlag == "-breadth")
3952 if (anArgIter + 1 >= theArgNb)
3954 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3958 const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]);
3959 if (!aBreadth.IsIntegerValue())
3961 std::cout << "Error: a width should be an integer value!\n";
3964 aColorScale->SetBreadth (aBreadth.IntegerValue());
3966 else if (aFlag == "-height"
3969 if (anArgIter + 1 >= theArgNb)
3971 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3975 const TCollection_AsciiString aHeight (theArgVec[++anArgIter]);
3976 if (!aHeight.IsIntegerValue())
3978 std::cout << "Error: a width should be an integer value!\n";
3981 aColorScale->SetHeight (aHeight.IntegerValue());
3983 else if (aFlag == "-color")
3985 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
3987 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3990 else if (anArgIter + 2 >= theArgNb)
3992 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3996 const TCollection_AsciiString anInd (theArgVec[++anArgIter]);
3997 if (!anInd.IsIntegerValue())
3999 std::cout << "Error: Index value should be integer!\n";
4002 const Standard_Integer anIndex = anInd.IntegerValue();
4003 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals())
4005 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() <<"!\n";
4009 Quantity_Color aColor;
4010 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4011 theArgVec + (anArgIter + 1),
4015 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4018 aColorScale->SetIntervalColor (aColor, anIndex);
4019 aColorScale->SetColorType (Aspect_TOCSD_USER);
4020 anArgIter += aNbParsed;
4022 else if (aFlag == "-label")
4024 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
4026 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
4029 else if (anArgIter + 2 >= theArgNb)
4031 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4035 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
4036 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1)
4038 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() + 1 <<"!\n";
4042 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
4043 aColorScale->SetLabel (aText, anIndex);
4044 aColorScale->SetLabelType (Aspect_TOCSD_USER);
4047 else if (aFlag == "-labelat"
4048 || aFlag == "-labat"
4049 || aFlag == "-labelatborder"
4050 || aFlag == "-labatborder"
4051 || aFlag == "-labelatcenter"
4052 || aFlag == "-labatcenter")
4054 Standard_Boolean toEnable = Standard_True;
4055 if (aFlag == "-labelat"
4056 || aFlag == "-labat")
4058 Standard_Integer aLabAtBorder = -1;
4059 if (++anArgIter >= theArgNb)
4061 TCollection_AsciiString anAtBorder (theArgVec[anArgIter]);
4062 anAtBorder.LowerCase();
4063 if (anAtBorder == "border")
4067 else if (anAtBorder == "center")
4072 if (aLabAtBorder == -1)
4074 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4077 toEnable = (aLabAtBorder == 1);
4079 else if (anArgIter + 1 < theArgNb
4080 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
4084 aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter"
4085 || aFlag == "-labatcenter"
4089 else if (aFlag == "-colors")
4091 Aspect_SequenceOfColor aSeq;
4094 Quantity_Color aColor;
4095 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4096 theArgVec + (anArgIter + 1),
4102 anArgIter += aNbParsed;
4103 aSeq.Append (aColor);
4105 if (aSeq.Length() != aColorScale->GetNumberOfIntervals())
4107 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
4108 << aColorScale->GetNumberOfIntervals() << " intervals\n";
4112 aColorScale->SetColors (aSeq);
4113 aColorScale->SetColorType (Aspect_TOCSD_USER);
4115 else if (aFlag == "-labels"
4116 || aFlag == "-freelabels")
4118 if (anArgIter + 1 >= theArgNb)
4120 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4124 Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder()
4125 ? aColorScale->GetNumberOfIntervals() + 1
4126 : aColorScale->GetNumberOfIntervals();
4127 if (aFlag == "-freelabels")
4130 aNbLabels = Draw::Atoi (theArgVec[anArgIter]);
4132 if (anArgIter + aNbLabels >= theArgNb)
4134 std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n";
4138 TColStd_SequenceOfExtendedString aSeq;
4139 for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter)
4141 aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter]));
4143 aColorScale->SetLabels (aSeq);
4144 aColorScale->SetLabelType (Aspect_TOCSD_USER);
4146 else if (aFlag == "-title")
4148 if (anArgIter + 1 >= theArgNb)
4150 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4154 Standard_Boolean isTwoArgs = Standard_False;
4155 if (anArgIter + 2 < theArgNb)
4157 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
4158 aSecondArg.LowerCase();
4159 Standard_DISABLE_DEPRECATION_WARNINGS
4160 if (aSecondArg == "none")
4162 aColorScale->SetTitlePosition (Aspect_TOCSP_NONE);
4163 isTwoArgs = Standard_True;
4165 else if (aSecondArg == "left")
4167 aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT);
4168 isTwoArgs = Standard_True;
4170 else if (aSecondArg == "right")
4172 aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT);
4173 isTwoArgs = Standard_True;
4175 else if (aSecondArg == "center")
4177 aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER);
4178 isTwoArgs = Standard_True;
4180 Standard_ENABLE_DEPRECATION_WARNINGS
4183 aColorScale->SetTitle (theArgVec[anArgIter + 1]);
4190 else if (aFlag == "-demoversion"
4191 || aFlag == "-demo")
4193 aColorScale->SetPosition (0, 0);
4194 aColorScale->SetTextHeight (16);
4195 aColorScale->SetRange (0.0, 100.0);
4196 aColorScale->SetNumberOfIntervals (10);
4197 aColorScale->SetBreadth (0);
4198 aColorScale->SetHeight (0);
4199 aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT);
4200 aColorScale->SetColorType (Aspect_TOCSD_AUTO);
4201 aColorScale->SetLabelType (Aspect_TOCSD_AUTO);
4203 else if (aFlag == "-findcolor")
4205 if (anArgIter + 1 >= theArgNb)
4207 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4211 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
4213 if (!anArg1.IsRealValue())
4215 std::cout << "Error: the value should be real!\n";
4219 Quantity_Color aColor;
4220 aColorScale->FindColor (anArg1.RealValue(), aColor);
4221 theDI << Quantity_Color::StringName (aColor.Name());
4226 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
4231 Standard_Integer aWinWidth = 0, aWinHeight = 0;
4232 aView->Window()->Size (aWinWidth, aWinHeight);
4233 if (aColorScale->GetBreadth() == 0)
4235 aColorScale->SetBreadth (aWinWidth);
4237 if (aColorScale->GetHeight() == 0)
4239 aColorScale->SetHeight (aWinHeight);
4241 aColorScale->SetToUpdate();
4242 ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True);
4246 //==============================================================================
4247 //function : VGraduatedTrihedron
4248 //purpose : Displays or hides a graduated trihedron
4249 //==============================================================================
4250 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
4251 Quantity_Color& theColor)
4253 Quantity_NameOfColor aColorName;
4254 TCollection_AsciiString aVal = theValue;
4256 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
4258 return Standard_False;
4260 theColor = Quantity_Color (aColorName);
4261 return Standard_True;
4264 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
4268 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
4269 << theArgs[0] <<"' for more information.\n";
4270 return 1; //TCL_ERROR
4273 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
4274 TCollection_AsciiString aParseKey;
4275 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
4277 TCollection_AsciiString anArg (theArgs [anArgIt]);
4279 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
4282 aParseKey.Remove (1);
4283 aParseKey.LowerCase();
4284 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
4288 if (aParseKey.IsEmpty())
4293 aMapOfArgs(aParseKey)->Append (anArg);
4297 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
4298 aMapIt.More(); aMapIt.Next())
4300 const TCollection_AsciiString& aKey = aMapIt.Key();
4301 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
4303 // Bool key, without arguments
4304 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
4305 && anArgs->IsEmpty())
4311 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
4312 && anArgs->Length() == 1)
4318 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
4319 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
4320 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
4321 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
4322 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
4327 // One string argument
4328 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
4329 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
4330 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4335 // One integer argument
4336 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
4337 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
4338 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
4339 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
4340 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
4345 // One real argument
4346 if ( aKey.IsEqual ("arrowlength")
4347 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
4352 // Two string arguments
4353 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
4354 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4359 TCollection_AsciiString aLowerKey;
4362 aLowerKey.LowerCase();
4363 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
4364 std::cout << "Type help for more information.\n";
4368 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4369 if (anAISContext.IsNull())
4371 std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n";
4375 Standard_Boolean toDisplay = Standard_True;
4376 Quantity_Color aColor;
4377 Graphic3d_GraduatedTrihedron aTrihedronData;
4378 // Process parameters
4379 Handle(TColStd_HSequenceOfAsciiString) aValues;
4380 if (aMapOfArgs.Find ("off", aValues))
4382 toDisplay = Standard_False;
4386 if (aMapOfArgs.Find ("xname", aValues))
4388 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
4390 if (aMapOfArgs.Find ("yname", aValues))
4392 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
4394 if (aMapOfArgs.Find ("zname", aValues))
4396 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
4398 if (aMapOfArgs.Find ("xdrawname", aValues))
4400 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4402 if (aMapOfArgs.Find ("ydrawname", aValues))
4404 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4406 if (aMapOfArgs.Find ("zdrawname", aValues))
4408 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4410 if (aMapOfArgs.Find ("xnameoffset", aValues))
4412 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4414 if (aMapOfArgs.Find ("ynameoffset", aValues))
4416 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4418 if (aMapOfArgs.Find ("znameoffset", aValues))
4420 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4424 if (aMapOfArgs.Find ("xnamecolor", aValues))
4426 if (!GetColor (aValues->Value(1), aColor))
4428 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
4431 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
4433 if (aMapOfArgs.Find ("ynamecolor", aValues))
4435 if (!GetColor (aValues->Value(1), aColor))
4437 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
4440 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
4442 if (aMapOfArgs.Find ("znamecolor", aValues))
4444 if (!GetColor (aValues->Value(1), aColor))
4446 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
4449 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
4451 if (aMapOfArgs.Find ("xcolor", aValues))
4453 if (!GetColor (aValues->Value(1), aColor))
4455 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
4458 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
4460 if (aMapOfArgs.Find ("ycolor", aValues))
4462 if (!GetColor (aValues->Value(1), aColor))
4464 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
4467 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
4469 if (aMapOfArgs.Find ("zcolor", aValues))
4471 if (!GetColor (aValues->Value(1), aColor))
4473 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
4476 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
4480 if (aMapOfArgs.Find ("xticks", aValues))
4482 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4484 if (aMapOfArgs.Find ("yticks", aValues))
4486 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4488 if (aMapOfArgs.Find ("zticks", aValues))
4490 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4492 if (aMapOfArgs.Find ("xticklength", aValues))
4494 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4496 if (aMapOfArgs.Find ("yticklength", aValues))
4498 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4500 if (aMapOfArgs.Find ("zticklength", aValues))
4502 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4504 if (aMapOfArgs.Find ("xdrawticks", aValues))
4506 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4508 if (aMapOfArgs.Find ("ydrawticks", aValues))
4510 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4512 if (aMapOfArgs.Find ("zdrawticks", aValues))
4514 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4518 if (aMapOfArgs.Find ("xdrawvalues", aValues))
4520 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4522 if (aMapOfArgs.Find ("ydrawvalues", aValues))
4524 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4526 if (aMapOfArgs.Find ("zdrawvalues", aValues))
4528 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4530 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
4532 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4534 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
4536 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4538 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
4540 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4544 if (aMapOfArgs.Find ("arrowlength", aValues))
4546 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
4550 if (aMapOfArgs.Find ("namefont", aValues))
4552 aTrihedronData.SetNamesFont (aValues->Value(1));
4554 if (aMapOfArgs.Find ("valuesfont", aValues))
4556 aTrihedronData.SetValuesFont (aValues->Value(1));
4559 if (aMapOfArgs.Find ("drawgrid", aValues))
4561 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
4563 if (aMapOfArgs.Find ("drawaxes", aValues))
4565 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
4568 // The final step: display of erase trihedron
4571 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
4575 ViewerTest::CurrentView()->GraduatedTrihedronErase();
4578 ViewerTest::GetAISContext()->UpdateCurrentViewer();
4579 ViewerTest::CurrentView()->Redraw();
4584 //==============================================================================
4587 //==============================================================================
4588 static int VTile (Draw_Interpretor& theDI,
4589 Standard_Integer theArgNb,
4590 const char** theArgVec)
4592 Handle(V3d_View) aView = ViewerTest::CurrentView();
4595 std::cerr << "Error: no active viewer.\n";
4599 Graphic3d_CameraTile aTile = aView->Camera()->Tile();
4602 theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
4603 << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n"
4604 << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n";
4608 aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
4609 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4611 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4613 if (anArg == "-lowerleft"
4614 || anArg == "-upperleft")
4616 if (anArgIter + 3 < theArgNb)
4618 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4621 aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
4622 aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4623 aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4625 else if (anArg == "-total"
4626 || anArg == "-totalsize"
4627 || anArg == "-viewsize")
4629 if (anArgIter + 3 < theArgNb)
4631 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4634 aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4635 aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4636 if (aTile.TotalSize.x() < 1
4637 || aTile.TotalSize.y() < 1)
4639 std::cerr << "Error: total size is incorrect.\n";
4643 else if (anArg == "-tilesize")
4645 if (anArgIter + 3 < theArgNb)
4647 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4651 aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4652 aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4653 if (aTile.TileSize.x() < 1
4654 || aTile.TileSize.y() < 1)
4656 std::cerr << "Error: tile size is incorrect.\n";
4660 else if (anArg == "-unset")
4662 aView->Camera()->SetTile (Graphic3d_CameraTile());
4668 if (aTile.TileSize.x() < 1
4669 || aTile.TileSize.y() < 1)
4671 std::cerr << "Error: tile size is undefined.\n";
4674 else if (aTile.TotalSize.x() < 1
4675 || aTile.TotalSize.y() < 1)
4677 std::cerr << "Error: total size is undefined.\n";
4681 aView->Camera()->SetTile (aTile);
4686 //! Format ZLayer ID.
4687 inline const char* formZLayerId (const Standard_Integer theLayerId)
4691 case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]";
4692 case Graphic3d_ZLayerId_Default: return "[DEFAULT]";
4693 case Graphic3d_ZLayerId_Top: return "[TOP]";
4694 case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]";
4695 case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]";
4696 case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]";
4701 //! Print the ZLayer information.
4702 inline void printZLayerInfo (Draw_Interpretor& theDI,
4703 const Graphic3d_ZLayerSettings& theLayer)
4705 if (!theLayer.Name().IsEmpty())
4707 theDI << " Name: " << theLayer.Name() << "\n";
4709 if (theLayer.IsImmediate())
4711 theDI << " Immediate: TRUE\n";
4713 theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n";
4714 theDI << " Culling distance: " << theLayer.CullingDistance() << "\n";
4715 theDI << " Culling size: " << theLayer.CullingSize() << "\n";
4716 theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n";
4717 theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n";
4718 theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n";
4719 if (theLayer.PolygonOffset().Mode != Aspect_POM_None)
4721 theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n";
4725 //==============================================================================
4726 //function : VZLayer
4727 //purpose : Test z layer operations for v3d viewer
4728 //==============================================================================
4729 static int VZLayer (Draw_Interpretor& theDI,
4730 Standard_Integer theArgNb,
4731 const char** theArgVec)
4733 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4734 if (aContextAIS.IsNull())
4736 std::cout << "No active viewer!\n";
4740 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
4743 TColStd_SequenceOfInteger aLayers;
4744 aViewer->GetAllZLayers (aLayers);
4745 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4747 theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n";
4748 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4749 printZLayerInfo (theDI, aSettings);
4754 Standard_Integer anArgIter = 1;
4755 Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4756 ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView());
4757 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
4762 TCollection_AsciiString aFirstArg (theArgVec[anArgIter]);
4763 if (aFirstArg.IsIntegerValue())
4766 aLayerId = aFirstArg.IntegerValue();
4770 aFirstArg.LowerCase();
4771 if (aFirstArg == "default"
4772 || aFirstArg == "def")
4774 aLayerId = Graphic3d_ZLayerId_Default;
4777 else if (aFirstArg == "top")
4779 aLayerId = Graphic3d_ZLayerId_Top;
4782 else if (aFirstArg == "topmost")
4784 aLayerId = Graphic3d_ZLayerId_Topmost;
4787 else if (aFirstArg == "overlay"
4788 || aFirstArg == "toposd")
4790 aLayerId = Graphic3d_ZLayerId_TopOSD;
4793 else if (aFirstArg == "underlay"
4794 || aFirstArg == "botosd")
4796 aLayerId = Graphic3d_ZLayerId_BotOSD;
4801 TColStd_SequenceOfInteger aLayers;
4802 aViewer->GetAllZLayers (aLayers);
4803 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4805 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4806 if (TCollection_AsciiString::IsSameString (aSettings.Name(), aFirstArg, Standard_False))
4808 aLayerId = aLayeriter.Value();
4816 for (; anArgIter < theArgNb; ++anArgIter)
4818 // perform operation
4819 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4821 if (anUpdateTool.parseRedrawMode (anArg))
4825 else if (anArg == "-add"
4828 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4829 if (!aViewer->AddZLayer (aLayerId))
4831 std::cout << "Error: can not add a new z layer!\n";
4837 else if (anArg == "-del"
4838 || anArg == "-delete"
4841 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4843 if (++anArgIter >= theArgNb)
4845 std::cout << "Syntax error: id of z layer to remove is missing\n";
4849 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4852 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN
4853 || aLayerId == Graphic3d_ZLayerId_Default
4854 || aLayerId == Graphic3d_ZLayerId_Top
4855 || aLayerId == Graphic3d_ZLayerId_Topmost
4856 || aLayerId == Graphic3d_ZLayerId_TopOSD
4857 || aLayerId == Graphic3d_ZLayerId_BotOSD)
4859 std::cout << "Syntax error: standard Z layer can not be removed\n";
4863 // move all object displayed in removing layer to default layer
4864 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4865 anObjIter.More(); anObjIter.Next())
4867 const Handle(AIS_InteractiveObject)& aPrs = anObjIter.Key1();
4869 || aPrs->ZLayer() != aLayerId)
4873 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4876 if (!aViewer->RemoveZLayer (aLayerId))
4878 std::cout << "Z layer can not be removed!\n";
4882 theDI << aLayerId << " ";
4885 else if (anArg == "-get"
4888 TColStd_SequenceOfInteger aLayers;
4889 aViewer->GetAllZLayers (aLayers);
4890 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4892 theDI << aLayeriter.Value() << " ";
4897 else if (anArg == "-name")
4899 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4901 std::cout << "Syntax error: id of Z layer is missing\n";
4905 if (++anArgIter >= theArgNb)
4907 std::cout << "Syntax error: name is missing\n";
4911 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4912 aSettings.SetName (theArgVec[anArgIter]);
4913 aViewer->SetZLayerSettings (aLayerId, aSettings);
4915 else if (anArg == "-origin")
4917 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4919 std::cout << "Syntax error: id of Z layer is missing\n";
4923 if (anArgIter + 2 >= theArgNb)
4925 std::cout << "Syntax error: origin coordinates are missing\n";
4929 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4931 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1]));
4932 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2]));
4933 anOrigin.SetZ (0.0);
4934 if (anArgIter + 3 < theArgNb)
4936 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3]));
4943 aSettings.SetOrigin (anOrigin);
4944 aViewer->SetZLayerSettings (aLayerId, aSettings);
4946 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
4947 && anArgIter + 1 < theArgNb
4948 && (anArg == "-cullingdistance"
4949 || anArg == "-cullingdist"
4950 || anArg == "-culldistance"
4951 || anArg == "-culldist"
4952 || anArg == "-distcull"
4953 || anArg == "-distculling"
4954 || anArg == "-distanceculling"))
4956 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4957 const Standard_Real aDist = Draw::Atof (theArgVec[++anArgIter]);
4958 aSettings.SetCullingDistance (aDist);
4959 aViewer->SetZLayerSettings (aLayerId, aSettings);
4961 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
4962 && anArgIter + 1 < theArgNb
4963 && (anArg == "-cullingsize"
4964 || anArg == "-cullsize"
4965 || anArg == "-sizecull"
4966 || anArg == "-sizeculling"))
4968 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4969 const Standard_Real aSize = Draw::Atof (theArgVec[++anArgIter]);
4970 aSettings.SetCullingSize (aSize);
4971 aViewer->SetZLayerSettings (aLayerId, aSettings);
4973 else if (anArg == "-settings"
4974 || anArg == "settings")
4976 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4978 if (++anArgIter >= theArgNb)
4980 std::cout << "Syntax error: id of Z layer is missing\n";
4984 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4987 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4988 printZLayerInfo (theDI, aSettings);
4990 else if (anArg == "-enable"
4991 || anArg == "enable"
4992 || anArg == "-disable"
4993 || anArg == "disable")
4995 const Standard_Boolean toEnable = anArg == "-enable"
4996 || anArg == "enable";
4997 if (++anArgIter >= theArgNb)
4999 std::cout << "Syntax error: option name is missing\n";
5003 TCollection_AsciiString aSubOp (theArgVec[anArgIter]);
5005 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5007 if (++anArgIter >= theArgNb)
5009 std::cout << "Syntax error: id of Z layer is missing\n";
5013 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5016 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5017 if (aSubOp == "depthtest"
5018 || aSubOp == "test")
5020 aSettings.SetEnableDepthTest (toEnable);
5022 else if (aSubOp == "depthwrite"
5023 || aSubOp == "write")
5025 aSettings.SetEnableDepthWrite (toEnable);
5027 else if (aSubOp == "depthclear"
5028 || aSubOp == "clear")
5030 aSettings.SetClearDepth (toEnable);
5032 else if (aSubOp == "depthoffset"
5033 || aSubOp == "offset")
5035 Graphic3d_PolygonOffset aParams;
5036 aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None;
5039 if (anArgIter + 2 >= theArgNb)
5041 std::cout << "Syntax error: factor and units values for depth offset are missing\n";
5045 aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5046 aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5048 aSettings.SetPolygonOffset (aParams);
5050 else if (aSubOp == "positiveoffset"
5051 || aSubOp == "poffset")
5055 aSettings.SetDepthOffsetPositive();
5059 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
5062 else if (aSubOp == "negativeoffset"
5063 || aSubOp == "noffset")
5067 aSettings.SetDepthOffsetNegative();
5071 aSettings.SetPolygonOffset(Graphic3d_PolygonOffset());
5074 else if (aSubOp == "textureenv")
5076 aSettings.SetEnvironmentTexture (toEnable);
5079 aViewer->SetZLayerSettings (aLayerId, aSettings);
5083 std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n";
5091 // The interactive presentation of 2d layer item
5092 // for "vlayerline" command it provides a presentation of
5093 // line with user-defined linewidth, linetype and transparency.
5094 class V3d_LineItem : public AIS_InteractiveObject
5098 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
5101 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5102 Standard_Real X2, Standard_Real Y2,
5103 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
5104 Standard_Real theWidth = 0.5,
5105 Standard_Real theTransp = 1.0);
5109 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
5110 const Handle(Prs3d_Presentation)& thePresentation,
5111 const Standard_Integer theMode) Standard_OVERRIDE;
5113 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
5114 const Standard_Integer /*aMode*/) Standard_OVERRIDE
5119 Standard_Real myX1, myY1, myX2, myY2;
5120 Aspect_TypeOfLine myType;
5121 Standard_Real myWidth;
5124 // default constructor for line item
5125 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5126 Standard_Real X2, Standard_Real Y2,
5127 Aspect_TypeOfLine theType,
5128 Standard_Real theWidth,
5129 Standard_Real theTransp) :
5130 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
5131 myType(theType), myWidth(theWidth)
5133 SetTransparency (1-theTransp);
5137 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
5138 const Handle(Prs3d_Presentation)& thePresentation,
5139 const Standard_Integer /*theMode*/)
5141 thePresentation->Clear();
5142 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
5143 Standard_Integer aWidth, aHeight;
5144 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
5145 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
5146 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
5147 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
5148 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
5149 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
5150 aGroup->SetPrimitivesAspect (anAspect->Aspect());
5151 aGroup->AddPrimitiveArray (aPrim);
5154 //=============================================================================
5155 //function : VLayerLine
5156 //purpose : Draws line in the v3d view layer with given attributes: linetype,
5157 // : linewidth, transparency coefficient
5158 //============================================================================
5159 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5161 // get the active view
5162 Handle(V3d_View) aView = ViewerTest::CurrentView();
5165 di << "Call vinit before!\n";
5170 di << "Use: " << argv[0];
5171 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
5172 di << " linetype : { 0 | 1 | 2 | 3 } \n";
5173 di << " 0 - solid \n";
5174 di << " 1 - dashed \n";
5175 di << " 2 - dot \n";
5176 di << " 3 - dashdot\n";
5177 di << " transparency : { 0.0 - 1.0 } \n";
5178 di << " 0.0 - transparent\n";
5179 di << " 1.0 - visible \n";
5183 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5184 // get the input params
5185 Standard_Real X1 = Draw::Atof(argv[1]);
5186 Standard_Real Y1 = Draw::Atof(argv[2]);
5187 Standard_Real X2 = Draw::Atof(argv[3]);
5188 Standard_Real Y2 = Draw::Atof(argv[4]);
5190 Standard_Real aWidth = 0.5;
5191 Standard_Real aTransparency = 1.0;
5195 aWidth = Draw::Atof(argv[5]);
5197 // select appropriate line type
5198 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
5200 && !ViewerTest::ParseLineType (argv[6], aLineType))
5202 std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n";
5209 aTransparency = Draw::Atof(argv[7]);
5210 if (aTransparency < 0 || aTransparency > 1.0)
5211 aTransparency = 1.0;
5214 static Handle (V3d_LineItem) aLine;
5215 if (!aLine.IsNull())
5217 aContext->Erase (aLine, Standard_False);
5219 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
5223 aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
5224 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
5225 aLine->SetToUpdate();
5226 aContext->Display (aLine, Standard_True);
5232 //==============================================================================
5235 //==============================================================================
5237 static int VGrid (Draw_Interpretor& /*theDI*/,
5238 Standard_Integer theArgNb,
5239 const char** theArgVec)
5241 Handle(V3d_View) aView = ViewerTest::CurrentView();
5242 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5243 if (aView.IsNull() || aViewer.IsNull())
5245 std::cerr << "Error: no active view\n";
5249 Aspect_GridType aType = aViewer->GridType();
5250 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
5251 Graphic3d_Vec2d aNewOriginXY, aNewStepXY, aNewSizeXY;
5252 Standard_Real aNewRotAngle = 0.0, aNewZOffset = 0.0;
5253 bool hasOrigin = false, hasStep = false, hasRotAngle = false, hasSize = false, hasZOffset = false;
5254 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
5255 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5257 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5259 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5263 else if (anArgIter + 1 < theArgNb
5264 && anArg == "-type")
5266 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
5267 anArgNext.LowerCase();
5268 if (anArgNext == "r"
5269 || anArgNext == "rect"
5270 || anArgNext == "rectangular")
5272 aType = Aspect_GT_Rectangular;
5274 else if (anArgNext == "c"
5275 || anArgNext == "circ"
5276 || anArgNext == "circular")
5278 aType = Aspect_GT_Circular;
5282 std::cout << "Syntax error at '" << anArgNext << "'\n";
5286 else if (anArgIter + 1 < theArgNb
5287 && anArg == "-mode")
5289 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
5290 anArgNext.LowerCase();
5291 if (anArgNext == "l"
5292 || anArgNext == "line"
5293 || anArgNext == "lines")
5295 aMode = Aspect_GDM_Lines;
5297 else if (anArgNext == "p"
5298 || anArgNext == "point"
5299 || anArgNext == "points")
5301 aMode = Aspect_GDM_Points;
5305 std::cout << "Syntax error at '" << anArgNext << "'\n";
5309 else if (anArgIter + 2 < theArgNb
5310 && (anArg == "-origin"
5311 || anArg == "-orig"))
5314 aNewOriginXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
5315 Draw::Atof (theArgVec[anArgIter + 2]));
5318 else if (anArgIter + 2 < theArgNb
5319 && anArg == "-step")
5322 aNewStepXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
5323 Draw::Atof (theArgVec[anArgIter + 2]));
5324 if (aNewStepXY.x() <= 0.0
5325 || aNewStepXY.y() <= 0.0)
5327 std::cout << "Syntax error: wrong step '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'\n";
5332 else if (anArgIter + 1 < theArgNb
5333 && (anArg == "-angle"
5334 || anArg == "-rotangle"
5335 || anArg == "-rotationangle"))
5338 aNewRotAngle = Draw::Atof (theArgVec[++anArgIter]);
5340 else if (anArgIter + 1 < theArgNb
5341 && (anArg == "-zoffset"
5345 aNewZOffset = Draw::Atof (theArgVec[++anArgIter]);
5347 else if (anArgIter + 1 < theArgNb
5348 && anArg == "-radius")
5352 aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter]), 0.0);
5353 if (aNewStepXY.x() <= 0.0)
5355 std::cout << "Syntax error: wrong size '" << theArgVec[anArgIter] << "'\n";
5359 else if (anArgIter + 2 < theArgNb
5360 && anArg == "-size")
5363 aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
5364 Draw::Atof (theArgVec[anArgIter + 2]));
5365 if (aNewStepXY.x() <= 0.0
5366 || aNewStepXY.y() <= 0.0)
5368 std::cout << "Syntax error: wrong size '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'\n";
5373 else if (anArg == "r"
5375 || anArg == "rectangular")
5377 aType = Aspect_GT_Rectangular;
5379 else if (anArg == "c"
5381 || anArg == "circular")
5383 aType = Aspect_GT_Circular;
5385 else if (anArg == "l"
5387 || anArg == "lines")
5389 aMode = Aspect_GDM_Lines;
5391 else if (anArg == "p"
5393 || anArg == "points")
5395 aMode = Aspect_GDM_Points;
5397 else if (anArgIter + 1 >= theArgNb
5400 aViewer->DeactivateGrid();
5405 std::cout << "Syntax error at '" << anArg << "'\n";
5410 if (aType == Aspect_GT_Rectangular)
5412 Graphic3d_Vec2d anOrigXY, aStepXY;
5413 Standard_Real aRotAngle = 0.0;
5414 aViewer->RectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle);
5417 anOrigXY = aNewOriginXY;
5421 aStepXY = aNewStepXY;
5425 aRotAngle = aNewRotAngle;
5427 aViewer->SetRectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle);
5428 if (hasSize || hasZOffset)
5430 Graphic3d_Vec3d aSize;
5431 aViewer->RectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z());
5434 aSize.x() = aNewSizeXY.x();
5435 aSize.y() = aNewSizeXY.y();
5439 aSize.z() = aNewZOffset;
5441 aViewer->SetRectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z());
5444 else if (aType == Aspect_GT_Circular)
5446 Graphic3d_Vec2d anOrigXY;
5447 Standard_Real aRadiusStep;
5448 Standard_Integer aDivisionNumber;
5449 Standard_Real aRotAngle = 0.0;
5450 aViewer->CircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle);
5453 anOrigXY = aNewOriginXY;
5457 aRadiusStep = aNewStepXY[0];
5458 aDivisionNumber = (int )aNewStepXY[1];
5459 if (aDivisionNumber < 1)
5461 std::cout << "Syntax error: invalid division number '" << aNewStepXY[1] << "'\n";
5467 aRotAngle = aNewRotAngle;
5470 aViewer->SetCircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle);
5471 if (hasSize || hasZOffset)
5473 Standard_Real aRadius = 0.0, aZOffset = 0.0;
5474 aViewer->CircularGridGraphicValues (aRadius, aZOffset);
5477 aRadius = aNewSizeXY.x();
5478 if (aNewSizeXY.y() != 0.0)
5480 std::cout << "Syntax error: circular size should be specified as radius\n";
5486 aZOffset = aNewZOffset;
5488 aViewer->SetCircularGridGraphicValues (aRadius, aZOffset);
5491 aViewer->ActivateGrid (aType, aMode);
5495 //==============================================================================
5496 //function : VPriviledgedPlane
5498 //==============================================================================
5500 static int VPriviledgedPlane (Draw_Interpretor& theDI,
5501 Standard_Integer theArgNb,
5502 const char** theArgVec)
5504 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
5506 std::cerr << "Error: wrong number of arguments! See usage:\n";
5507 theDI.PrintHelp (theArgVec[0]);
5511 // get the active viewer
5512 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5513 if (aViewer.IsNull())
5515 std::cerr << "Error: no active viewer. Please call vinit.\n";
5521 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
5522 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
5523 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
5524 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
5525 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
5526 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
5527 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
5531 Standard_Integer anArgIdx = 1;
5532 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
5533 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
5534 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
5535 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
5536 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
5537 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
5539 gp_Ax3 aPriviledgedPlane;
5540 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
5541 gp_Dir aNorm (aNormX, aNormY, aNormZ);
5544 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
5545 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
5546 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
5547 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
5548 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
5552 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
5555 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
5560 //==============================================================================
5561 //function : VConvert
5563 //==============================================================================
5565 static int VConvert (Draw_Interpretor& theDI,
5566 Standard_Integer theArgNb,
5567 const char** theArgVec)
5569 // get the active view
5570 Handle(V3d_View) aView = ViewerTest::CurrentView();
5573 std::cerr << "Error: no active view. Please call vinit.\n";
5577 enum { Model, Ray, View, Window, Grid } aMode = Model;
5579 // access coordinate arguments
5580 TColStd_SequenceOfReal aCoord;
5581 Standard_Integer anArgIdx = 1;
5582 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
5584 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5585 if (!anArg.IsRealValue())
5589 aCoord.Append (anArg.RealValue());
5592 // non-numeric argument too early
5593 if (aCoord.IsEmpty())
5595 std::cerr << "Error: wrong number of arguments! See usage:\n";
5596 theDI.PrintHelp (theArgVec[0]);
5600 // collect all other arguments and options
5601 for (; anArgIdx < theArgNb; ++anArgIdx)
5603 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5605 if (anArg == "window") aMode = Window;
5606 else if (anArg == "view") aMode = View;
5607 else if (anArg == "grid") aMode = Grid;
5608 else if (anArg == "ray") aMode = Ray;
5611 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
5612 theDI.PrintHelp (theArgVec[0]);
5617 // complete input checks
5618 if ((aCoord.Length() == 1 && theArgNb > 3) ||
5619 (aCoord.Length() == 2 && theArgNb > 4) ||
5620 (aCoord.Length() == 3 && theArgNb > 5))
5622 std::cerr << "Error: wrong number of arguments! See usage:\n";
5623 theDI.PrintHelp (theArgVec[0]);
5627 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
5628 Standard_Integer aXYp[2] = {0, 0};
5630 // convert one-dimensional coordinate
5631 if (aCoord.Length() == 1)
5635 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0;
5636 case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0;
5638 std::cerr << "Error: wrong arguments! See usage:\n";
5639 theDI.PrintHelp (theArgVec[0]);
5644 // convert 2D coordinates from projection or view reference space
5645 if (aCoord.Length() == 2)
5650 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5651 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5655 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5656 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5660 aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]);
5661 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5665 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5666 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5667 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5671 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5672 (Standard_Integer) aCoord (2),
5673 aXYZ[0], aXYZ[1], aXYZ[2],
5674 aXYZ[3], aXYZ[4], aXYZ[5]);
5675 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5679 std::cerr << "Error: wrong arguments! See usage:\n";
5680 theDI.PrintHelp (theArgVec[0]);
5685 // convert 3D coordinates from view reference space
5686 else if (aCoord.Length() == 3)
5691 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5692 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5696 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5697 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5701 std::cerr << "Error: wrong arguments! See usage:\n";
5702 theDI.PrintHelp (theArgVec[0]);
5710 //==============================================================================
5713 //==============================================================================
5715 static int VFps (Draw_Interpretor& theDI,
5716 Standard_Integer theArgNb,
5717 const char** theArgVec)
5719 // get the active view
5720 Handle(V3d_View) aView = ViewerTest::CurrentView();
5723 std::cerr << "No active view. Please call vinit.\n";
5727 Standard_Integer aFramesNb = -1;
5728 Standard_Real aDuration = -1.0;
5729 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5731 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5734 && anArgIter + 1 < theArgNb
5735 && (anArg == "-duration"
5737 || anArg == "-time"))
5739 aDuration = Draw::Atof (theArgVec[++anArgIter]);
5741 else if (aFramesNb < 0
5742 && anArg.IsIntegerValue())
5744 aFramesNb = anArg.IntegerValue();
5747 std::cerr << "Syntax error at '" << anArg << "'\n";
5753 std::cerr << "Syntax error at '" << anArg << "'\n";
5757 if (aFramesNb < 0 && aDuration < 0.0)
5762 // the time is meaningless for first call
5763 // due to async OpenGl rendering
5766 // redraw view in loop to estimate average values
5769 Standard_Integer aFrameIter = 1;
5770 for (;; ++aFrameIter)
5774 && aFrameIter >= aFramesNb)
5776 && aTimer.ElapsedTime() >= aDuration))
5783 const Standard_Real aTime = aTimer.ElapsedTime();
5784 aTimer.OSD_Chronometer::Show (aCpu);
5786 const Standard_Real aFpsAver = Standard_Real(aFrameIter) / aTime;
5787 const Standard_Real aCpuAver = aCpu / Standard_Real(aFrameIter);
5789 // return statistics
5790 theDI << "FPS: " << aFpsAver << "\n"
5791 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5793 // compute additional statistics in ray-tracing mode
5794 const Graphic3d_RenderingParams& aParams = aView->RenderingParams();
5795 if (aParams.Method == Graphic3d_RM_RAYTRACING)
5797 Graphic3d_Vec2i aWinSize (0, 0);
5798 aView->Window()->Size (aWinSize.x(), aWinSize.y());
5800 // 1 shadow ray and 1 secondary ray pew each bounce
5801 const Standard_Real aMRays = aWinSize.x() * aWinSize.y() * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
5802 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
5808 //! Auxiliary function for parsing glsl dump level argument.
5809 static Standard_Boolean parseGlslSourceFlag (Standard_CString theArg,
5810 OpenGl_ShaderProgramDumpLevel& theGlslDumpLevel)
5812 TCollection_AsciiString aTypeStr (theArg);
5813 aTypeStr.LowerCase();
5814 if (aTypeStr == "off"
5817 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
5819 else if (aTypeStr == "short")
5821 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Short;
5823 else if (aTypeStr == "full"
5826 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
5830 return Standard_False;
5832 return Standard_True;
5835 //==============================================================================
5836 //function : VGlDebug
5838 //==============================================================================
5840 static int VGlDebug (Draw_Interpretor& theDI,
5841 Standard_Integer theArgNb,
5842 const char** theArgVec)
5844 Handle(OpenGl_GraphicDriver) aDriver;
5845 Handle(V3d_View) aView = ViewerTest::CurrentView();
5846 if (!aView.IsNull())
5848 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5850 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
5851 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
5855 TCollection_AsciiString aDebActive, aSyncActive;
5862 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
5863 "GL_ARB_debug_output");
5864 aDebActive = isActive ? " (active)" : " (inactive)";
5867 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
5868 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
5872 TCollection_AsciiString aGlslCodeDebugStatus = TCollection_AsciiString()
5873 + "glslSourceCode: "
5874 + (aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Off
5876 : aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Short
5880 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
5881 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
5882 << "glslWarn: " << (aCaps->glslWarnings ? "1" : "0") << "\n"
5883 << aGlslCodeDebugStatus
5884 << "extraMsg: " << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
5888 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5890 Standard_CString anArg = theArgVec[anArgIter];
5891 TCollection_AsciiString anArgCase (anArg);
5892 anArgCase.LowerCase();
5893 Standard_Boolean toEnableDebug = Standard_True;
5894 if (anArgCase == "-glsl"
5895 || anArgCase == "-glslwarn"
5896 || anArgCase == "-glslwarns"
5897 || anArgCase == "-glslwarnings")
5899 Standard_Boolean toShowWarns = Standard_True;
5900 if (++anArgIter < theArgNb
5901 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
5905 aDefCaps->glslWarnings = toShowWarns;
5908 aCaps->glslWarnings = toShowWarns;
5911 else if (anArgCase == "-extra"
5912 || anArgCase == "-extramsg"
5913 || anArgCase == "-extramessages")
5915 Standard_Boolean toShow = Standard_True;
5916 if (++anArgIter < theArgNb
5917 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
5921 aDefCaps->suppressExtraMsg = !toShow;
5924 aCaps->suppressExtraMsg = !toShow;
5927 else if (anArgCase == "-noextra"
5928 || anArgCase == "-noextramsg"
5929 || anArgCase == "-noextramessages")
5931 Standard_Boolean toSuppress = Standard_True;
5932 if (++anArgIter < theArgNb
5933 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
5937 aDefCaps->suppressExtraMsg = toSuppress;
5940 aCaps->suppressExtraMsg = toSuppress;
5943 else if (anArgCase == "-sync")
5945 Standard_Boolean toSync = Standard_True;
5946 if (++anArgIter < theArgNb
5947 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
5951 aDefCaps->contextSyncDebug = toSync;
5954 aDefCaps->contextDebug = Standard_True;
5957 else if (anArgCase == "-glslsourcecode"
5958 || anArgCase == "-glslcode")
5960 OpenGl_ShaderProgramDumpLevel aGslsDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
5961 if (++anArgIter < theArgNb
5962 && !parseGlslSourceFlag (theArgVec[anArgIter], aGslsDumpLevel))
5966 aDefCaps->glslDumpLevel = aGslsDumpLevel;
5969 aCaps->glslDumpLevel = aGslsDumpLevel;
5972 else if (anArgCase == "-debug")
5974 if (++anArgIter < theArgNb
5975 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
5979 aDefCaps->contextDebug = toEnableDebug;
5981 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
5982 && (anArgIter + 1 == theArgNb))
5984 // simple alias to turn on almost everything
5985 aDefCaps->contextDebug = toEnableDebug;
5986 aDefCaps->contextSyncDebug = toEnableDebug;
5987 aDefCaps->glslWarnings = toEnableDebug;
5990 aDefCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
5992 aDefCaps->suppressExtraMsg = !toEnableDebug;
5995 aCaps->contextDebug = toEnableDebug;
5996 aCaps->contextSyncDebug = toEnableDebug;
5997 aCaps->glslWarnings = toEnableDebug;
6000 aCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
6002 aCaps->suppressExtraMsg = !toEnableDebug;
6007 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
6015 //==============================================================================
6018 //==============================================================================
6020 static int VVbo (Draw_Interpretor& theDI,
6021 Standard_Integer theArgNb,
6022 const char** theArgVec)
6024 const Standard_Boolean toSet = (theArgNb > 1);
6025 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
6028 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
6032 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
6033 if (aContextAIS.IsNull())
6037 std::cerr << "No active view!\n";
6041 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
6042 if (!aDriver.IsNull())
6046 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
6050 aDriver->ChangeOptions().vboDisable = toUseVbo;
6057 //==============================================================================
6060 //==============================================================================
6062 static int VCaps (Draw_Interpretor& theDI,
6063 Standard_Integer theArgNb,
6064 const char** theArgVec)
6066 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
6067 Handle(OpenGl_GraphicDriver) aDriver;
6068 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6069 if (!aContext.IsNull())
6071 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
6072 aCaps = &aDriver->ChangeOptions();
6077 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
6078 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
6079 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
6080 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
6081 theDI << "PolygonMode: " << (aCaps->usePolygonMode ? "1" : "0") << "\n";
6082 theDI << "VSync: " << aCaps->swapInterval << "\n";
6083 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
6084 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
6085 theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n";
6089 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
6090 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6092 Standard_CString anArg = theArgVec[anArgIter];
6093 TCollection_AsciiString anArgCase (anArg);
6094 anArgCase.LowerCase();
6095 if (anUpdateTool.parseRedrawMode (anArg))
6099 else if (anArgCase == "-vsync"
6100 || anArgCase == "-swapinterval")
6102 Standard_Boolean toEnable = Standard_True;
6103 if (++anArgIter < theArgNb
6104 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6108 aCaps->swapInterval = toEnable;
6110 else if (anArgCase == "-ffp")
6112 Standard_Boolean toEnable = Standard_True;
6113 if (++anArgIter < theArgNb
6114 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6118 aCaps->ffpEnable = toEnable;
6120 else if (anArgCase == "-polygonmode")
6122 Standard_Boolean toEnable = Standard_True;
6123 if (++anArgIter < theArgNb
6124 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6128 aCaps->usePolygonMode = toEnable;
6130 else if (anArgCase == "-vbo")
6132 Standard_Boolean toEnable = Standard_True;
6133 if (++anArgIter < theArgNb
6134 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6138 aCaps->vboDisable = !toEnable;
6140 else if (anArgCase == "-sprite"
6141 || anArgCase == "-sprites")
6143 Standard_Boolean toEnable = Standard_True;
6144 if (++anArgIter < theArgNb
6145 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6149 aCaps->pntSpritesDisable = !toEnable;
6151 else if (anArgCase == "-softmode")
6153 Standard_Boolean toEnable = Standard_True;
6154 if (++anArgIter < theArgNb
6155 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6159 aCaps->contextNoAccel = toEnable;
6161 else if (anArgCase == "-winbuffer"
6162 || anArgCase == "-windowbuffer"
6163 || anArgCase == "-usewinbuffer"
6164 || anArgCase == "-usewindowbuffer"
6165 || anArgCase == "-usesystembuffer")
6167 Standard_Boolean toEnable = Standard_True;
6168 if (++anArgIter < theArgNb
6169 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6173 aCaps->useSystemBuffer = toEnable;
6175 else if (anArgCase == "-accel"
6176 || anArgCase == "-acceleration")
6178 Standard_Boolean toEnable = Standard_True;
6179 if (++anArgIter < theArgNb
6180 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6184 aCaps->contextNoAccel = !toEnable;
6186 else if (anArgCase == "-compat"
6187 || anArgCase == "-compatprofile"
6188 || anArgCase == "-compatible"
6189 || anArgCase == "-compatibleprofile")
6191 Standard_Boolean toEnable = Standard_True;
6192 if (++anArgIter < theArgNb
6193 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6197 aCaps->contextCompatible = toEnable;
6198 if (!aCaps->contextCompatible)
6200 aCaps->ffpEnable = Standard_False;
6203 else if (anArgCase == "-core"
6204 || anArgCase == "-coreprofile")
6206 Standard_Boolean toEnable = Standard_True;
6207 if (++anArgIter < theArgNb
6208 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6212 aCaps->contextCompatible = !toEnable;
6213 if (!aCaps->contextCompatible)
6215 aCaps->ffpEnable = Standard_False;
6218 else if (anArgCase == "-stereo"
6219 || anArgCase == "-quadbuffer")
6221 Standard_Boolean toEnable = Standard_True;
6222 if (++anArgIter < theArgNb
6223 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6227 aCaps->contextStereo = toEnable;
6231 std::cout << "Error: unknown argument '" << anArg << "'\n";
6235 if (aCaps != &ViewerTest_myDefaultCaps)
6237 ViewerTest_myDefaultCaps = *aCaps;
6242 //==============================================================================
6243 //function : VMemGpu
6245 //==============================================================================
6247 static int VMemGpu (Draw_Interpretor& theDI,
6248 Standard_Integer theArgNb,
6249 const char** theArgVec)
6252 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
6253 if (aContextAIS.IsNull())
6255 std::cerr << "No active view. Please call vinit.\n";
6259 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
6260 if (aDriver.IsNull())
6262 std::cerr << "Graphic driver not available.\n";
6266 Standard_Size aFreeBytes = 0;
6267 TCollection_AsciiString anInfo;
6268 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
6270 std::cerr << "Information not available.\n";
6274 if (theArgNb > 1 && *theArgVec[1] == 'f')
6276 theDI << Standard_Real (aFreeBytes);
6286 // ==============================================================================
6287 // function : VReadPixel
6289 // ==============================================================================
6290 static int VReadPixel (Draw_Interpretor& theDI,
6291 Standard_Integer theArgNb,
6292 const char** theArgVec)
6294 // get the active view
6295 Handle(V3d_View) aView = ViewerTest::CurrentView();
6298 std::cerr << "No active view. Please call vinit.\n";
6301 else if (theArgNb < 3)
6303 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
6307 Image_Format aFormat = Image_Format_RGBA;
6308 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
6310 Standard_Integer aWidth, aHeight;
6311 aView->Window()->Size (aWidth, aHeight);
6312 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
6313 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
6314 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
6316 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
6320 Standard_Boolean toShowName = Standard_False;
6321 Standard_Boolean toShowHls = Standard_False;
6322 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
6324 TCollection_AsciiString aParam (theArgVec[anIter]);
6326 if (aParam == "rgb")
6328 aFormat = Image_Format_RGB;
6329 aBufferType = Graphic3d_BT_RGB;
6331 else if (aParam == "hls")
6333 aFormat = Image_Format_RGB;
6334 aBufferType = Graphic3d_BT_RGB;
6335 toShowHls = Standard_True;
6337 else if (aParam == "rgbf")
6339 aFormat = Image_Format_RGBF;
6340 aBufferType = Graphic3d_BT_RGB;
6342 else if (aParam == "rgba")
6344 aFormat = Image_Format_RGBA;
6345 aBufferType = Graphic3d_BT_RGBA;
6347 else if (aParam == "rgbaf")
6349 aFormat = Image_Format_RGBAF;
6350 aBufferType = Graphic3d_BT_RGBA;
6352 else if (aParam == "depth")
6354 aFormat = Image_Format_GrayF;
6355 aBufferType = Graphic3d_BT_Depth;
6357 else if (aParam == "name")
6359 toShowName = Standard_True;
6363 Image_PixMap anImage;
6364 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
6366 std::cerr << "Image allocation failed\n";
6369 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
6371 std::cerr << "Image dump failed\n";
6375 // redirect possible warning messages that could have been added by ToPixMap
6376 // into the Tcl interpretor (via DefaultMessenger) to cout, so that they do not
6377 // contaminate result of the command
6378 Standard_CString aWarnLog = theDI.Result();
6379 if (aWarnLog != NULL && aWarnLog[0] != '\0')
6381 std::cout << aWarnLog << std::endl;
6385 Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY);
6388 if (aBufferType == Graphic3d_BT_RGBA)
6390 theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha();
6394 theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
6399 switch (aBufferType)
6402 case Graphic3d_BT_RGB:
6406 theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation();
6410 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue();
6414 case Graphic3d_BT_RGBA:
6416 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue() << " " << aColor.Alpha();
6419 case Graphic3d_BT_Depth:
6421 theDI << aColor.GetRGB().Red();
6430 //! Auxiliary presentation for an image plane.
6431 class ViewerTest_ImagePrs : public AIS_InteractiveObject
6434 //! Main constructor.
6435 ViewerTest_ImagePrs (const Handle(Image_PixMap)& theImage,
6436 const Standard_Real theWidth,
6437 const Standard_Real theHeight,
6438 const TCollection_AsciiString& theLabel)
6439 : myLabel (theLabel), myWidth (theWidth), myHeight(theHeight)
6443 myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost);
6445 myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
6446 const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect();
6447 Graphic3d_MaterialAspect aMat;
6448 aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC);
6449 aMat.SetAmbient (1.0);
6450 aMat.SetDiffuse (1.0);
6451 aMat.SetSpecular (1.0);
6452 aMat.SetEmissive (1.0);
6453 aMat.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
6454 aMat.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
6455 aMat.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
6456 aMat.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
6457 aMat.SetAmbientColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6458 aMat.SetDiffuseColor (Quantity_Color (1.0, 1.0, 1.0, Quantity_TOC_RGB));
6459 aMat.SetSpecularColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6460 aMat.SetEmissiveColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6461 aFillAspect->SetFrontMaterial (aMat);
6462 aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage));
6463 aFillAspect->SetTextureMapOn();
6466 Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect();
6467 aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER);
6468 aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER);
6469 myDrawer->SetTextAspect (aTextAspect);
6472 const gp_Dir aNorm (0.0, 0.0, 1.0);
6473 myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true);
6474 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0));
6475 myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0));
6476 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0));
6477 myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0));
6478 myTris->AddEdge (1);
6479 myTris->AddEdge (2);
6480 myTris->AddEdge (3);
6481 myTris->AddEdge (3);
6482 myTris->AddEdge (2);
6483 myTris->AddEdge (4);
6485 myRect = new Graphic3d_ArrayOfPolylines (4);
6486 myRect->AddVertex (myTris->Vertice (1));
6487 myRect->AddVertex (myTris->Vertice (3));
6488 myRect->AddVertex (myTris->Vertice (4));
6489 myRect->AddVertex (myTris->Vertice (2));
6493 //! Returns TRUE for accepted display modes.
6494 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; }
6496 //! Compute presentation.
6497 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& , const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) Standard_OVERRIDE
6503 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
6504 aGroup->AddPrimitiveArray (myTris);
6505 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
6506 aGroup->AddPrimitiveArray (myRect);
6507 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
6512 Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0));
6513 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
6514 aGroup->AddPrimitiveArray (myRect);
6515 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
6521 //! Compute selection.
6522 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE
6526 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5);
6527 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner);
6528 aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location());
6529 theSel->Add (aSensitive);
6534 Handle(Graphic3d_ArrayOfTriangles) myTris;
6535 Handle(Graphic3d_ArrayOfPolylines) myRect;
6536 TCollection_AsciiString myLabel;
6537 Standard_Real myWidth;
6538 Standard_Real myHeight;
6541 //==============================================================================
6542 //function : VDiffImage
6543 //purpose : The draw-command compares two images.
6544 //==============================================================================
6546 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
6550 std::cout << "Syntax error: not enough arguments.\n";
6554 Standard_Integer anArgIter = 1;
6555 TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]);
6556 TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]);
6557 TCollection_AsciiString aDiffImagePath;
6558 Standard_Real aTolColor = -1.0;
6559 Standard_Integer toBlackWhite = -1;
6560 Standard_Integer isBorderFilterOn = -1;
6561 Standard_Boolean isOldSyntax = Standard_False;
6562 TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff;
6563 for (; anArgIter < theArgNb; ++anArgIter)
6565 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6567 if (anArgIter + 1 < theArgNb
6568 && (anArg == "-toleranceofcolor"
6569 || anArg == "-tolerancecolor"
6570 || anArg == "-tolerance"
6571 || anArg == "-toler"))
6573 aTolColor = Atof (theArgVec[++anArgIter]);
6574 if (aTolColor < 0.0 || aTolColor > 1.0)
6576 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
6580 else if (anArg == "-blackwhite")
6582 Standard_Boolean toEnable = Standard_True;
6583 if (anArgIter + 1 < theArgNb
6584 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6588 toBlackWhite = toEnable ? 1 : 0;
6590 else if (anArg == "-borderfilter")
6592 Standard_Boolean toEnable = Standard_True;
6593 if (anArgIter + 1 < theArgNb
6594 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6598 isBorderFilterOn = toEnable ? 1 : 0;
6600 else if (anArg == "-exitonclose")
6602 Draw_ToExitOnCloseView = true;
6603 if (anArgIter + 1 < theArgNb
6604 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToExitOnCloseView))
6609 else if (anArg == "-closeonescape"
6610 || anArg == "-closeonesc")
6612 Draw_ToCloseViewOnEsc = true;
6613 if (anArgIter + 1 < theArgNb
6614 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToCloseViewOnEsc))
6619 else if (anArgIter + 3 < theArgNb
6620 && anArg == "-display")
6622 aViewName = theArgVec[++anArgIter];
6623 aPrsNameRef = theArgVec[++anArgIter];
6624 aPrsNameNew = theArgVec[++anArgIter];
6625 if (anArgIter + 1 < theArgNb
6626 && *theArgVec[anArgIter + 1] != '-')
6628 aPrsNameDiff = theArgVec[++anArgIter];
6631 else if (aTolColor < 0.0
6632 && anArg.IsRealValue())
6634 isOldSyntax = Standard_True;
6635 aTolColor = anArg.RealValue();
6636 if (aTolColor < 0.0 || aTolColor > 1.0)
6638 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
6642 else if (isOldSyntax
6643 && toBlackWhite == -1
6644 && (anArg == "0" || anArg == "1"))
6646 toBlackWhite = anArg == "1" ? 1 : 0;
6648 else if (isOldSyntax
6649 && isBorderFilterOn == -1
6650 && (anArg == "0" || anArg == "1"))
6652 isBorderFilterOn = anArg == "1" ? 1 : 0;
6654 else if (aDiffImagePath.IsEmpty())
6656 aDiffImagePath = theArgVec[anArgIter];
6660 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
6665 Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap();
6666 Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap();
6667 if (!anImgRef->Load (anImgPathRef))
6669 std::cout << "Error: image file '" << anImgPathRef << "' cannot be read\n";
6672 if (!anImgNew->Load (anImgPathNew))
6674 std::cout << "Error: image file '" << anImgPathNew << "' cannot be read\n";
6678 // compare the images
6679 Image_Diff aComparer;
6680 Standard_Integer aDiffColorsNb = -1;
6681 if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1))
6683 aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0);
6684 aComparer.SetBorderFilterOn (isBorderFilterOn == 1);
6685 aDiffColorsNb = aComparer.Compare();
6686 theDI << aDiffColorsNb << "\n";
6689 // save image of difference
6690 Handle(Image_AlienPixMap) aDiff;
6691 if (aDiffColorsNb > 0
6692 && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty()))
6694 aDiff = new Image_AlienPixMap();
6695 if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY()))
6697 std::cout << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY() << "\n";
6700 aComparer.SaveDiffImage (*aDiff);
6701 if (!aDiffImagePath.IsEmpty()
6702 && !aDiff->Save (aDiffImagePath))
6704 std::cout << "Error: diff image file '" << aDiffImagePath << "' cannot be written\n";
6709 if (aViewName.IsEmpty())
6714 ViewerTest_Names aViewNames (aViewName);
6715 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
6717 TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName();
6718 theDI.Eval (aCommand.ToCString());
6721 Standard_Integer aPxLeft = 0;
6722 Standard_Integer aPxTop = 0;
6723 Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2);
6724 Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty()
6725 ? int(anImgRef->SizeY() * 2)
6726 : int(anImgRef->SizeY());
6727 TCollection_AsciiString aDisplayName;
6728 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aWinSizeX, aWinSizeY,
6729 aViewName, aDisplayName);
6731 Standard_Real aRatio = anImgRef->Ratio();
6732 Standard_Real aSizeX = 1.0;
6733 Standard_Real aSizeY = aSizeX / aRatio;
6735 OSD_Path aPath (anImgPathRef);
6736 TCollection_AsciiString aLabelRef;
6737 if (!aPath.Name().IsEmpty())
6739 aLabelRef = aPath.Name() + aPath.Extension();
6741 aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY());
6743 Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef);
6745 aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0));
6746 anImgRefPrs->SetLocalTransformation (aTrsfRef);
6747 ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true);
6750 OSD_Path aPath (anImgPathNew);
6751 TCollection_AsciiString aLabelNew;
6752 if (!aPath.Name().IsEmpty())
6754 aLabelNew = aPath.Name() + aPath.Extension();
6756 aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY());
6758 Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew);
6760 aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0));
6761 anImgNewPrs->SetLocalTransformation (aTrsfRef);
6762 ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true);
6764 Handle(ViewerTest_ImagePrs) anImgDiffPrs;
6765 if (!aDiff.IsNull())
6767 anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels");
6769 aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0));
6770 anImgDiffPrs->SetLocalTransformation (aTrsfDiff);
6772 if (!aPrsNameDiff.IsEmpty())
6774 ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true);
6776 ViewerTest::CurrentView()->SetProj (V3d_Zpos);
6777 ViewerTest::CurrentView()->FitAll();
6781 //=======================================================================
6782 //function : VSelect
6783 //purpose : Emulates different types of selection by mouse:
6784 // 1) single click selection
6785 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
6786 // 3) selection with polygon having corners at
6787 // pixel positions (x1,y1),...,(xn,yn)
6788 // 4) any of these selections with shift button pressed
6789 //=======================================================================
6790 static Standard_Integer VSelect (Draw_Interpretor& di,
6791 Standard_Integer argc,
6796 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]\n";
6800 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
6801 if(myAIScontext.IsNull())
6803 di << "use 'vinit' command before " << argv[0] << "\n";
6807 const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1));
6808 Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1;
6809 TCollection_AsciiString anArg;
6810 anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2];
6812 if (anArg == "-allowoverlap")
6814 Standard_Boolean isValidated = isShiftSelection ? argc == 8
6818 di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection";
6822 Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
6823 myAIScontext->MainSelector()->AllowOverlapDetection (isToAllow != 0);
6827 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
6828 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
6831 if(isShiftSelection)
6832 aCurrentEventManager->ShiftSelect();
6834 aCurrentEventManager->Select();
6836 else if(aCoordsNb == 4)
6838 if(isShiftSelection)
6839 aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
6841 aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
6845 TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2);
6847 for(Standard_Integer i=1;i<=aCoordsNb / 2;++i)
6848 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
6850 if(isShiftSelection)
6851 aCurrentEventManager->ShiftSelect(aPolyline);
6853 aCurrentEventManager->Select(aPolyline);
6858 //=======================================================================
6859 //function : VMoveTo
6860 //purpose : Emulates cursor movement to defined pixel position
6861 //=======================================================================
6862 static Standard_Integer VMoveTo (Draw_Interpretor& theDI,
6863 Standard_Integer theNbArgs,
6864 const char** theArgVec)
6866 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
6867 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
6868 if (aContext.IsNull())
6870 std::cout << "Error: no active View\n";
6874 Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast());
6875 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
6877 TCollection_AsciiString anArgStr (theArgVec[anArgIter]);
6878 anArgStr.LowerCase();
6879 if (anArgStr == "-reset"
6880 || anArgStr == "-clear")
6882 if (anArgIter + 1 < theNbArgs)
6884 std::cout << "Syntax error at '" << theArgVec[anArgIter + 1] << "'\n";
6888 const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive()
6889 && aContext->CurrentViewer()->GridEcho();
6892 aContext->CurrentViewer()->HideGridEcho (aView);
6894 if (aContext->ClearDetected() || toEchoGrid)
6896 aContext->CurrentViewer()->RedrawImmediate();
6900 else if (aMousePos.x() == IntegerLast()
6901 && anArgStr.IsIntegerValue())
6903 aMousePos.x() = anArgStr.IntegerValue();
6905 else if (aMousePos.y() == IntegerLast()
6906 && anArgStr.IsIntegerValue())
6908 aMousePos.y() = anArgStr.IntegerValue();
6912 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
6917 if (aMousePos.x() == IntegerLast()
6918 || aMousePos.y() == IntegerLast())
6920 std::cout << "Syntax error: wrong number of arguments\n";
6924 ViewerTest::CurrentEventManager()->MoveTo (aMousePos.x(), aMousePos.y());
6925 gp_Pnt aTopPnt (RealLast(), RealLast(), RealLast());
6926 const Handle(SelectMgr_EntityOwner)& aDetOwner = aContext->DetectedOwner();
6927 for (Standard_Integer aDetIter = 1; aDetIter <= aContext->MainSelector()->NbPicked(); ++aDetIter)
6929 if (aContext->MainSelector()->Picked (aDetIter) == aDetOwner)
6931 aTopPnt = aContext->MainSelector()->PickedPoint (aDetIter);
6935 theDI << aTopPnt.X() << " " << aTopPnt.Y() << " " << aTopPnt.Z();
6941 //! Global map storing all animations registered in ViewerTest.
6942 static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap;
6944 //! The animation calling the Draw Harness command.
6945 class ViewerTest_AnimationProc : public AIS_Animation
6949 //! Main constructor.
6950 ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName,
6951 Draw_Interpretor* theDI,
6952 const TCollection_AsciiString& theCommand)
6953 : AIS_Animation (theAnimationName),
6955 myCommand (theCommand)
6962 //! Evaluate the command.
6963 virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE
6965 TCollection_AsciiString aCmd = myCommand;
6966 replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts));
6967 replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts));
6968 replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts));
6969 replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized));
6970 replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized));
6971 myDrawInter->Eval (aCmd.ToCString());
6974 //! Find the keyword in the command and replace it with value.
6975 //! @return the position of the keyword to pass value
6976 void replace (TCollection_AsciiString& theCmd,
6977 const TCollection_AsciiString& theKey,
6978 const TCollection_AsciiString& theVal)
6980 TCollection_AsciiString aCmd (theCmd);
6982 const Standard_Integer aPos = aCmd.Search (theKey);
6988 TCollection_AsciiString aPart1, aPart2;
6989 Standard_Integer aPart1To = aPos - 1;
6991 && aPart1To <= theCmd.Length())
6993 aPart1 = theCmd.SubString (1, aPart1To);
6996 Standard_Integer aPart2From = aPos + theKey.Length();
6998 && aPart2From <= theCmd.Length())
7000 aPart2 = theCmd.SubString (aPart2From, theCmd.Length());
7003 theCmd = aPart1 + theVal + aPart2;
7008 Draw_Interpretor* myDrawInter;
7009 TCollection_AsciiString myCommand;
7013 //! Replace the animation with the new one.
7014 static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation,
7015 Handle(AIS_Animation)& theAnimation,
7016 const Handle(AIS_Animation)& theAnimationNew)
7018 theAnimationNew->CopyFrom (theAnimation);
7019 if (!theParentAnimation.IsNull())
7021 theParentAnimation->Replace (theAnimation, theAnimationNew);
7025 ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name());
7026 ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew);
7028 theAnimation = theAnimationNew;
7031 //! Parse the point.
7032 static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
7034 const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
7035 if (!anXYZ[0].IsRealValue()
7036 || !anXYZ[1].IsRealValue()
7037 || !anXYZ[2].IsRealValue())
7039 return Standard_False;
7042 thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue());
7043 return Standard_True;
7046 //! Parse the quaternion.
7047 static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
7049 const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
7050 if (!anXYZW[0].IsRealValue()
7051 || !anXYZW[1].IsRealValue()
7052 || !anXYZW[2].IsRealValue()
7053 || !anXYZW[3].IsRealValue())
7055 return Standard_False;
7058 theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue());
7059 return Standard_True;
7062 //! Auxiliary class for flipping image upside-down.
7067 //! Empty constructor.
7068 ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {}
7070 //! Perform flipping.
7071 Standard_Boolean FlipY (Image_PixMap& theImage)
7073 if (theImage.IsEmpty()
7074 || theImage.SizeX() == 0
7075 || theImage.SizeY() == 0)
7077 return Standard_False;
7080 const Standard_Size aRowSize = theImage.SizeRowBytes();
7081 if (myTmp.Size() < aRowSize
7082 && !myTmp.Allocate (aRowSize))
7084 return Standard_False;
7087 // for odd height middle row should be left as is
7088 Standard_Size aNbRowsHalf = theImage.SizeY() / 2;
7089 for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB)
7091 Standard_Byte* aTop = theImage.ChangeRow (aRowT);
7092 Standard_Byte* aBot = theImage.ChangeRow (aRowB);
7093 memcpy (myTmp.ChangeData(), aTop, aRowSize);
7094 memcpy (aTop, aBot, aRowSize);
7095 memcpy (aBot, myTmp.Data(), aRowSize);
7097 return Standard_True;
7101 NCollection_Buffer myTmp;
7106 //=================================================================================================
7107 //function : VViewParams
7108 //purpose : Gets or sets AIS View characteristics
7109 //=================================================================================================
7110 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7112 Handle(V3d_View) aView = ViewerTest::CurrentView();
7115 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
7119 Standard_Boolean toSetProj = Standard_False;
7120 Standard_Boolean toSetUp = Standard_False;
7121 Standard_Boolean toSetAt = Standard_False;
7122 Standard_Boolean toSetEye = Standard_False;
7123 Standard_Boolean toSetScale = Standard_False;
7124 Standard_Boolean toSetSize = Standard_False;
7125 Standard_Boolean toSetCenter2d = Standard_False;
7126 Standard_Real aViewScale = aView->Scale();
7127 Standard_Real aViewSize = 1.0;
7128 Graphic3d_Vec2i aCenter2d;
7129 gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
7130 aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3));
7131 aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
7132 aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
7133 aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
7136 // print all of the available view parameters
7140 "Proj: %12g %12g %12g\n"
7141 "Up: %12g %12g %12g\n"
7142 "At: %12g %12g %12g\n"
7143 "Eye: %12g %12g %12g\n",
7145 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
7146 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
7147 aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
7148 aViewEye.X(), aViewEye.Y(), aViewEye.Z());
7153 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7154 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7156 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7158 if (anUpdateTool.parseRedrawMode (anArg))
7162 else if (anArg == "-cmd"
7163 || anArg == "-command"
7164 || anArg == "-args")
7173 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
7174 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
7175 aViewAt.X(), aViewAt.Y(), aViewAt.Z());
7178 else if (anArg == "-scale"
7179 || anArg == "-size")
7181 if (anArgIter + 1 < theArgsNb
7182 && *theArgVec[anArgIter + 1] != '-')
7184 const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
7185 if (aValueArg.IsRealValue())
7188 if (anArg == "-scale")
7190 toSetScale = Standard_True;
7191 aViewScale = aValueArg.RealValue();
7193 else if (anArg == "-size")
7195 toSetSize = Standard_True;
7196 aViewSize = aValueArg.RealValue();
7201 if (anArg == "-scale")
7203 theDi << "Scale: " << aView->Scale() << "\n";
7205 else if (anArg == "-size")
7207 Graphic3d_Vec2d aSizeXY;
7208 aView->Size (aSizeXY.x(), aSizeXY.y());
7209 theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n";
7212 else if (anArg == "-eye"
7215 || anArg == "-proj")
7217 if (anArgIter + 3 < theArgsNb)
7220 if (parseXYZ (theArgVec + anArgIter + 1, anXYZ))
7223 if (anArg == "-eye")
7225 toSetEye = Standard_True;
7228 else if (anArg == "-at")
7230 toSetAt = Standard_True;
7233 else if (anArg == "-up")
7235 toSetUp = Standard_True;
7238 else if (anArg == "-proj")
7240 toSetProj = Standard_True;
7247 if (anArg == "-eye")
7249 theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n";
7251 else if (anArg == "-at")
7253 theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n";
7255 else if (anArg == "-up")
7257 theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n";
7259 else if (anArg == "-proj")
7261 theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n";
7264 else if (anArg == "-center")
7266 if (anArgIter + 2 < theArgsNb)
7268 const TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
7269 const TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
7270 if (anX.IsIntegerValue()
7271 && anY.IsIntegerValue())
7273 toSetCenter2d = Standard_True;
7274 aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue());
7280 std::cout << "Syntax error at '" << anArg << "'\n";
7285 // change view parameters in proper order
7288 aView->SetScale (aViewScale);
7292 aView->SetSize (aViewSize);
7296 aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z());
7300 aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z());
7304 aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z());
7308 aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z());
7312 aView->SetCenter (aCenter2d.x(), aCenter2d.y());
7318 //==============================================================================
7319 //function : V2DMode
7321 //==============================================================================
7322 static Standard_Integer V2DMode (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec)
7324 bool is2dMode = true;
7325 Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView());
7326 if (aV3dView.IsNull())
7328 std::cout << "Error: no active view.\n";
7331 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
7333 const TCollection_AsciiString anArg = theArgVec[anArgIt];
7334 TCollection_AsciiString anArgCase = anArg;
7335 anArgCase.LowerCase();
7336 if (anArgIt + 1 < theArgsNb
7337 && anArgCase == "-name")
7339 ViewerTest_Names aViewNames (theArgVec[++anArgIt]);
7340 TCollection_AsciiString aViewName = aViewNames.GetViewName();
7341 if (!ViewerTest_myViews.IsBound1 (aViewName))
7343 std::cout << "Syntax error: unknown view '" << theArgVec[anArgIt - 1] << "'.\n";
7346 aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest_myViews.Find1 (aViewName));
7348 else if (anArgCase == "-mode")
7350 if (anArgIt + 1 < theArgsNb
7351 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], is2dMode))
7356 else if (ViewerTest::ParseOnOff (theArgVec[anArgIt], is2dMode))
7362 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
7367 aV3dView->SetView2DMode (is2dMode);
7371 //==============================================================================
7372 //function : VAnimation
7374 //==============================================================================
7375 static Standard_Integer VAnimation (Draw_Interpretor& theDI,
7376 Standard_Integer theArgNb,
7377 const char** theArgVec)
7379 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
7382 for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator
7383 anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next())
7385 theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n";
7391 std::cout << "Error: no active view\n";
7395 Standard_Integer anArgIter = 1;
7396 TCollection_AsciiString aNameArg (theArgVec[anArgIter++]);
7397 if (aNameArg.IsEmpty())
7399 std::cout << "Syntax error: animation name is not defined.\n";
7403 TCollection_AsciiString aNameArgLower = aNameArg;
7404 aNameArgLower.LowerCase();
7405 if (aNameArgLower == "-reset"
7406 || aNameArgLower == "-clear")
7408 ViewerTest_AnimationTimelineMap.Clear();
7411 else if (aNameArg.Value (1) == '-')
7413 std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n";
7417 const char* aNameSplitter = "/";
7418 Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter);
7419 if (aSplitPos == -1)
7421 aNameSplitter = ".";
7422 aSplitPos = aNameArg.Search (aNameSplitter);
7425 // find existing or create a new animation by specified name within syntax "parent.child".
7426 Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation;
7427 for (; !aNameArg.IsEmpty();)
7429 TCollection_AsciiString aNameParent;
7430 if (aSplitPos != -1)
7432 if (aSplitPos == aNameArg.Length())
7434 std::cout << "Syntax error: animation name is not defined.\n";
7438 aNameParent = aNameArg.SubString ( 1, aSplitPos - 1);
7439 aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length());
7441 aSplitPos = aNameArg.Search (aNameSplitter);
7445 aNameParent = aNameArg;
7449 if (anAnimation.IsNull())
7451 if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation))
7453 anAnimation = new AIS_Animation (aNameParent);
7454 ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation);
7456 aRootAnimation = anAnimation;
7460 aParentAnimation = anAnimation;
7461 anAnimation = aParentAnimation->Find (aNameParent);
7462 if (anAnimation.IsNull())
7464 anAnimation = new AIS_Animation (aNameParent);
7465 aParentAnimation->Add (anAnimation);
7470 if (anArgIter >= theArgNb)
7472 // just print the list of children
7473 for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next())
7475 theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n";
7480 // animation parameters
7481 Standard_Boolean toPlay = Standard_False;
7482 Standard_Real aPlaySpeed = 1.0;
7483 Standard_Real aPlayStartTime = anAnimation->StartPts();
7484 Standard_Real aPlayDuration = anAnimation->Duration();
7485 Standard_Boolean isFreeCamera = Standard_False;
7486 Standard_Boolean isLockLoop = Standard_False;
7488 // video recording parameters
7489 TCollection_AsciiString aRecFile;
7490 Image_VideoParams aRecParams;
7492 Handle(V3d_View) aView = ViewerTest::CurrentView();
7493 for (; anArgIter < theArgNb; ++anArgIter)
7495 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7498 if (anArg == "-reset"
7499 || anArg == "-clear")
7501 anAnimation->Clear();
7503 else if (anArg == "-remove"
7505 || anArg == "-delete")
7507 if (!aParentAnimation.IsNull())
7509 ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name());
7513 aParentAnimation->Remove (anAnimation);
7517 else if (anArg == "-play")
7519 toPlay = Standard_True;
7520 if (++anArgIter < theArgNb)
7522 if (*theArgVec[anArgIter] == '-')
7527 aPlayStartTime = Draw::Atof (theArgVec[anArgIter]);
7529 if (++anArgIter < theArgNb)
7531 if (*theArgVec[anArgIter] == '-')
7536 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
7540 else if (anArg == "-resume")
7542 toPlay = Standard_True;
7543 aPlayStartTime = anAnimation->ElapsedTime();
7544 if (++anArgIter < theArgNb)
7546 if (*theArgVec[anArgIter] == '-')
7552 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
7555 else if (anArg == "-playspeed"
7556 || anArg == "-speed")
7558 if (++anArgIter >= theArgNb)
7560 std::cout << "Syntax error at " << anArg << ".\n";
7563 aPlaySpeed = Draw::Atof (theArgVec[anArgIter]);
7565 else if (anArg == "-lock"
7566 || anArg == "-lockloop"
7567 || anArg == "-playlockloop")
7569 isLockLoop = Standard_True;
7571 else if (anArg == "-freecamera"
7572 || anArg == "-playfreecamera"
7573 || anArg == "-freelook")
7575 isFreeCamera = Standard_True;
7577 // video recodring options
7578 else if (anArg == "-rec"
7579 || anArg == "-record")
7581 if (++anArgIter >= theArgNb)
7583 std::cout << "Syntax error at " << anArg << ".\n";
7587 aRecFile = theArgVec[anArgIter];
7588 if (aRecParams.FpsNum <= 0)
7590 aRecParams.FpsNum = 24;
7593 if (anArgIter + 2 < theArgNb
7594 && *theArgVec[anArgIter + 1] != '-'
7595 && *theArgVec[anArgIter + 2] != '-')
7597 TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]);
7598 TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]);
7599 if (aWidthArg .IsIntegerValue()
7600 && aHeightArg.IsIntegerValue())
7602 aRecParams.Width = aWidthArg .IntegerValue();
7603 aRecParams.Height = aHeightArg.IntegerValue();
7608 else if (anArg == "-fps")
7610 if (++anArgIter >= theArgNb)
7612 std::cout << "Syntax error at " << anArg << ".\n";
7616 TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
7617 Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
7618 if (aSplitIndex == 0)
7620 aRecParams.FpsNum = aFpsArg.IntegerValue();
7624 const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
7625 aFpsArg.Split (aFpsArg.Length() - 1);
7626 const TCollection_AsciiString aNumStr = aFpsArg;
7627 aRecParams.FpsNum = aNumStr.IntegerValue();
7628 aRecParams.FpsDen = aDenStr.IntegerValue();
7629 if (aRecParams.FpsDen < 1)
7631 std::cout << "Syntax error at " << anArg << ".\n";
7636 else if (anArg == "-format")
7638 if (++anArgIter >= theArgNb)
7640 std::cout << "Syntax error at " << anArg << ".\n";
7643 aRecParams.Format = theArgVec[anArgIter];
7645 else if (anArg == "-pix_fmt"
7646 || anArg == "-pixfmt"
7647 || anArg == "-pixelformat")
7649 if (++anArgIter >= theArgNb)
7651 std::cout << "Syntax error at " << anArg << ".\n";
7654 aRecParams.PixelFormat = theArgVec[anArgIter];
7656 else if (anArg == "-codec"
7657 || anArg == "-vcodec"
7658 || anArg == "-videocodec")
7660 if (++anArgIter >= theArgNb)
7662 std::cout << "Syntax error at " << anArg << ".\n";
7665 aRecParams.VideoCodec = theArgVec[anArgIter];
7667 else if (anArg == "-crf"
7668 || anArg == "-preset"
7671 const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length());
7672 if (++anArgIter >= theArgNb)
7674 std::cout << "Syntax error at " << anArg << ".\n";
7678 aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]);
7680 // animation definition options
7681 else if (anArg == "-start"
7682 || anArg == "-starttime"
7683 || anArg == "-startpts")
7685 if (++anArgIter >= theArgNb)
7687 std::cout << "Syntax error at " << anArg << ".\n";
7691 anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter]));
7692 aRootAnimation->UpdateTotalDuration();
7694 else if (anArg == "-end"
7695 || anArg == "-endtime"
7696 || anArg == "-endpts")
7698 if (++anArgIter >= theArgNb)
7700 std::cout << "Syntax error at " << anArg << ".\n";
7704 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts());
7705 aRootAnimation->UpdateTotalDuration();
7707 else if (anArg == "-dur"
7708 || anArg == "-duration")
7710 if (++anArgIter >= theArgNb)
7712 std::cout << "Syntax error at " << anArg << ".\n";
7716 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]));
7717 aRootAnimation->UpdateTotalDuration();
7719 else if (anArg == "-command"
7721 || anArg == "-invoke"
7723 || anArg == "-proc")
7725 if (++anArgIter >= theArgNb)
7727 std::cout << "Syntax error at " << anArg << ".\n";
7731 Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]);
7732 replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation);
7734 else if (anArg == "-objecttrsf"
7735 || anArg == "-objectransformation"
7736 || anArg == "-objtransformation"
7737 || anArg == "-objtrsf"
7738 || anArg == "-object"
7741 if (++anArgIter >= theArgNb)
7743 std::cout << "Syntax error at " << anArg << ".\n";
7747 TCollection_AsciiString anObjName (theArgVec[anArgIter]);
7748 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS();
7749 Handle(AIS_InteractiveObject) anObject;
7750 if (!aMapOfAIS.Find2 (anObjName, anObject))
7752 std::cout << "Syntax error: wrong object name at " << anArg << "\n";
7756 gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() };
7757 gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() };
7758 gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
7759 Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
7760 Standard_Boolean isTrsfSet = Standard_False;
7761 Standard_Integer aTrsfArgIter = anArgIter + 1;
7762 for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
7764 TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]);
7765 aTrsfArg.LowerCase();
7766 const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1;
7767 if (aTrsfArg.StartsWith ("-rotation")
7768 || aTrsfArg.StartsWith ("-rot"))
7770 isTrsfSet = Standard_True;
7771 if (aTrsfArgIter + 4 >= theArgNb
7772 || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex]))
7774 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7779 else if (aTrsfArg.StartsWith ("-location")
7780 || aTrsfArg.StartsWith ("-loc"))
7782 isTrsfSet = Standard_True;
7783 if (aTrsfArgIter + 3 >= theArgNb
7784 || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex]))
7786 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7791 else if (aTrsfArg.StartsWith ("-scale"))
7793 isTrsfSet = Standard_True;
7794 if (++aTrsfArgIter >= theArgNb)
7796 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7800 const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
7801 if (!aScaleStr.IsRealValue())
7803 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7806 aScales[anIndex] = aScaleStr.RealValue();
7810 anArgIter = aTrsfArgIter - 1;
7816 std::cout << "Syntax error at " << anArg << ".\n";
7819 else if (aTrsfArgIter >= theArgNb)
7821 anArgIter = theArgNb;
7824 aTrsfs[0].SetRotation (aRotQuats[0]);
7825 aTrsfs[1].SetRotation (aRotQuats[1]);
7826 aTrsfs[0].SetTranslationPart (aLocPnts[0]);
7827 aTrsfs[1].SetTranslationPart (aLocPnts[1]);
7828 aTrsfs[0].SetScaleFactor (aScales[0]);
7829 aTrsfs[1].SetScaleFactor (aScales[1]);
7831 Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
7832 replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
7834 else if (anArg == "-viewtrsf"
7835 || anArg == "-view")
7837 Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation);
7838 if (aCamAnimation.IsNull())
7840 aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView);
7841 replaceAnimation (aParentAnimation, anAnimation, aCamAnimation);
7844 Handle(Graphic3d_Camera) aCams[2] =
7846 new Graphic3d_Camera (aCamAnimation->View()->Camera()),
7847 new Graphic3d_Camera (aCamAnimation->View()->Camera())
7850 Standard_Boolean isTrsfSet = Standard_False;
7851 Standard_Integer aViewArgIter = anArgIter + 1;
7852 for (; aViewArgIter < theArgNb; ++aViewArgIter)
7854 TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]);
7855 aViewArg.LowerCase();
7856 const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1;
7857 if (aViewArg.StartsWith ("-scale"))
7859 isTrsfSet = Standard_True;
7860 if (++aViewArgIter >= theArgNb)
7862 std::cout << "Syntax error at " << anArg << ".\n";
7866 const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
7867 if (!aScaleStr.IsRealValue())
7869 std::cout << "Syntax error at " << aViewArg << ".\n";
7872 Standard_Real aScale = aScaleStr.RealValue();
7873 aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale;
7874 aCams[anIndex]->SetScale (aScale);
7876 else if (aViewArg.StartsWith ("-eye")
7877 || aViewArg.StartsWith ("-center")
7878 || aViewArg.StartsWith ("-at")
7879 || aViewArg.StartsWith ("-up"))
7881 isTrsfSet = Standard_True;
7883 if (aViewArgIter + 3 >= theArgNb
7884 || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ))
7886 std::cout << "Syntax error at " << aViewArg << ".\n";
7891 if (aViewArg.StartsWith ("-eye"))
7893 aCams[anIndex]->SetEye (anXYZ);
7895 else if (aViewArg.StartsWith ("-center")
7896 || aViewArg.StartsWith ("-at"))
7898 aCams[anIndex]->SetCenter (anXYZ);
7900 else if (aViewArg.StartsWith ("-up"))
7902 aCams[anIndex]->SetUp (anXYZ);
7907 anArgIter = aViewArgIter - 1;
7913 std::cout << "Syntax error at " << anArg << ".\n";
7916 else if (aViewArgIter >= theArgNb)
7918 anArgIter = theArgNb;
7921 aCamAnimation->SetCameraStart(aCams[0]);
7922 aCamAnimation->SetCameraEnd (aCams[1]);
7926 std::cout << "Syntax error at " << anArg << ".\n";
7931 if (!toPlay && aRecFile.IsEmpty())
7936 // Start animation timeline and process frame updating.
7937 TheIsAnimating = Standard_True;
7938 const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
7939 Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera());
7940 anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
7943 aView->Camera()->Copy (aCameraBack);
7946 const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
7947 if (aRecParams.FpsNum <= 0)
7949 while (!anAnimation->IsStopped())
7951 aCameraBack->Copy (aView->Camera());
7952 const Standard_Real aPts = anAnimation->UpdateTimer();
7955 aView->Camera()->Copy (aCameraBack);
7958 if (aPts >= anUpperPts)
7960 anAnimation->Pause();
7964 if (aView->IsInvalidated())
7970 aView->RedrawImmediate();
7975 // handle user events
7976 theDI.Eval ("after 1 set waiter 1");
7977 theDI.Eval ("vwait waiter");
7979 if (!TheIsAnimating)
7981 anAnimation->Pause();
7987 if (aView->IsInvalidated())
7993 aView->RedrawImmediate();
7998 OSD_Timer aPerfTimer;
8001 Handle(Image_VideoRecorder) aRecorder;
8002 ImageFlipper aFlipper;
8003 Handle(Draw_ProgressIndicator) aProgress;
8004 if (!aRecFile.IsEmpty())
8006 if (aRecParams.Width <= 0
8007 || aRecParams.Height <= 0)
8009 aView->Window()->Size (aRecParams.Width, aRecParams.Height);
8012 aRecorder = new Image_VideoRecorder();
8013 if (!aRecorder->Open (aRecFile.ToCString(), aRecParams))
8015 std::cout << "Error: failed to open video file for recording\n";
8019 aProgress = new Draw_ProgressIndicator (theDI, 1);
8022 // Manage frame-rated animation here
8023 Standard_Real aPts = aPlayStartTime;
8024 int64_t aNbFrames = 0;
8025 Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1);
8026 Standard_Integer aSecondsProgress = 0;
8027 for (; aPts <= anUpperPts && aPSentry.More();)
8029 const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames));
8030 aPts = aPlayStartTime + aRecPts;
8032 if (!anAnimation->Update (aPts))
8037 if (!aRecorder.IsNull())
8039 V3d_ImageDumpOptions aDumpParams;
8040 aDumpParams.Width = aRecParams.Width;
8041 aDumpParams.Height = aRecParams.Height;
8042 aDumpParams.BufferType = Graphic3d_BT_RGBA;
8043 aDumpParams.StereoOptions = V3d_SDO_MONO;
8044 aDumpParams.ToAdjustAspect = Standard_True;
8045 if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams))
8047 std::cout << "Error: view dump is failed!\n";
8050 aFlipper.FlipY (aRecorder->ChangeFrame());
8051 if (!aRecorder->PushFrame())
8061 while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed))
8069 anAnimation->Stop();
8070 const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
8071 theDI << "Average FPS: " << aRecFps << "\n"
8072 << "Nb. Frames: " << Standard_Real(aNbFrames);
8077 aView->SetImmediateUpdate (wasImmediateUpdate);
8078 TheIsAnimating = Standard_False;
8083 //=======================================================================
8084 //function : VChangeSelected
8085 //purpose : Adds the shape to selection or remove one from it
8086 //=======================================================================
8087 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
8088 Standard_Integer argc,
8093 di<<"Usage : " << argv[0] << " shape \n";
8097 TCollection_AsciiString aName(argv[1]);
8098 Handle(AIS_InteractiveObject) anAISObject;
8099 if (!GetMapOfAIS().Find2 (aName, anAISObject)
8100 || anAISObject.IsNull())
8102 di<<"Use 'vdisplay' before";
8106 ViewerTest::GetAISContext()->AddOrRemoveSelected(anAISObject, Standard_True);
8110 //=======================================================================
8111 //function : VNbSelected
8112 //purpose : Returns number of selected objects
8113 //=======================================================================
8114 static Standard_Integer VNbSelected (Draw_Interpretor& di,
8115 Standard_Integer argc,
8120 di << "Usage : " << argv[0] << "\n";
8123 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8124 if(aContext.IsNull())
8126 di << "use 'vinit' command before " << argv[0] << "\n";
8129 di << aContext->NbSelected() << "\n";
8133 //=======================================================================
8134 //function : VPurgeDisplay
8135 //purpose : Switches altialiasing on or off
8136 //=======================================================================
8137 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
8138 Standard_Integer argc,
8143 di << "Usage : " << argv[0] << "\n";
8146 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8147 if (aContext.IsNull())
8149 di << "use 'vinit' command before " << argv[0] << "\n";
8153 di << aContext->PurgeDisplay() << "\n";
8157 //=======================================================================
8158 //function : VSetViewSize
8160 //=======================================================================
8161 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
8162 Standard_Integer argc,
8165 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8166 if(aContext.IsNull())
8168 di << "use 'vinit' command before " << argv[0] << "\n";
8173 di<<"Usage : " << argv[0] << " Size\n";
8176 Standard_Real aSize = Draw::Atof (argv[1]);
8179 di<<"Bad Size value : " << aSize << "\n";
8183 Handle(V3d_View) aView = ViewerTest::CurrentView();
8184 aView->SetSize(aSize);
8188 //=======================================================================
8189 //function : VMoveView
8191 //=======================================================================
8192 static Standard_Integer VMoveView (Draw_Interpretor& di,
8193 Standard_Integer argc,
8196 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8197 if(aContext.IsNull())
8199 di << "use 'vinit' command before " << argv[0] << "\n";
8202 if(argc < 4 || argc > 5)
8204 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
8207 Standard_Real Dx = Draw::Atof (argv[1]);
8208 Standard_Real Dy = Draw::Atof (argv[2]);
8209 Standard_Real Dz = Draw::Atof (argv[3]);
8210 Standard_Boolean aStart = Standard_True;
8213 aStart = (Draw::Atoi (argv[4]) > 0);
8216 Handle(V3d_View) aView = ViewerTest::CurrentView();
8217 aView->Move(Dx,Dy,Dz,aStart);
8221 //=======================================================================
8222 //function : VTranslateView
8224 //=======================================================================
8225 static Standard_Integer VTranslateView (Draw_Interpretor& di,
8226 Standard_Integer argc,
8229 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8230 if(aContext.IsNull())
8232 di << "use 'vinit' command before " << argv[0] << "\n";
8235 if(argc < 4 || argc > 5)
8237 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
8240 Standard_Real Dx = Draw::Atof (argv[1]);
8241 Standard_Real Dy = Draw::Atof (argv[2]);
8242 Standard_Real Dz = Draw::Atof (argv[3]);
8243 Standard_Boolean aStart = Standard_True;
8246 aStart = (Draw::Atoi (argv[4]) > 0);
8249 Handle(V3d_View) aView = ViewerTest::CurrentView();
8250 aView->Translate(Dx,Dy,Dz,aStart);
8254 //=======================================================================
8255 //function : VTurnView
8257 //=======================================================================
8258 static Standard_Integer VTurnView (Draw_Interpretor& di,
8259 Standard_Integer argc,
8262 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8263 if(aContext.IsNull()) {
8264 di << "use 'vinit' command before " << argv[0] << "\n";
8267 if(argc < 4 || argc > 5){
8268 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
8271 Standard_Real Ax = Draw::Atof (argv[1]);
8272 Standard_Real Ay = Draw::Atof (argv[2]);
8273 Standard_Real Az = Draw::Atof (argv[3]);
8274 Standard_Boolean aStart = Standard_True;
8277 aStart = (Draw::Atoi (argv[4]) > 0);
8280 Handle(V3d_View) aView = ViewerTest::CurrentView();
8281 aView->Turn(Ax,Ay,Az,aStart);
8285 //==============================================================================
8286 //function : VTextureEnv
8287 //purpose : ENables or disables environment mapping
8288 //==============================================================================
8289 class OCC_TextureEnv : public Graphic3d_TextureEnv
8292 OCC_TextureEnv(const Standard_CString FileName);
8293 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
8294 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
8295 const Standard_Boolean theModulateFlag,
8296 const Graphic3d_TypeOfTextureFilter theFilter,
8297 const Standard_ShortReal theXScale,
8298 const Standard_ShortReal theYScale,
8299 const Standard_ShortReal theXShift,
8300 const Standard_ShortReal theYShift,
8301 const Standard_ShortReal theAngle);
8302 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
8304 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
8306 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
8307 : Graphic3d_TextureEnv(theFileName)
8311 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
8312 : Graphic3d_TextureEnv(theTexId)
8316 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
8317 const Standard_Boolean theModulateFlag,
8318 const Graphic3d_TypeOfTextureFilter theFilter,
8319 const Standard_ShortReal theXScale,
8320 const Standard_ShortReal theYScale,
8321 const Standard_ShortReal theXShift,
8322 const Standard_ShortReal theYShift,
8323 const Standard_ShortReal theAngle)
8325 myParams->SetRepeat (theRepeatFlag);
8326 myParams->SetModulate (theModulateFlag);
8327 myParams->SetFilter (theFilter);
8328 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
8329 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
8330 myParams->SetRotation (theAngle);
8333 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
8335 // get the active view
8336 Handle(V3d_View) aView = ViewerTest::CurrentView();
8339 std::cerr << "No active view. Please call vinit.\n";
8343 // Checking the input arguments
8344 Standard_Boolean anEnableFlag = Standard_False;
8345 Standard_Boolean isOk = theArgNb >= 2;
8348 TCollection_AsciiString anEnableOpt(theArgVec[1]);
8349 anEnableFlag = anEnableOpt.IsEqual("on");
8350 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
8354 isOk = (theArgNb == 3 || theArgNb == 11);
8357 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8358 isOk = (!aTextureOpt.IsIntegerValue() ||
8359 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
8361 if (isOk && theArgNb == 11)
8363 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
8364 aModulateOpt(theArgVec[4]),
8365 aFilterOpt (theArgVec[5]),
8366 aSScaleOpt (theArgVec[6]),
8367 aTScaleOpt (theArgVec[7]),
8368 aSTransOpt (theArgVec[8]),
8369 aTTransOpt (theArgVec[9]),
8370 anAngleOpt (theArgVec[10]);
8371 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
8372 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
8373 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
8374 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
8375 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
8376 anAngleOpt.IsRealValue());
8383 std::cerr << "Usage :" << std::endl;
8384 std::cerr << theArgVec[0] << " off" << std::endl;
8385 std::cerr << theArgVec[0] << " on {index_of_std_texture(0..7)|texture_file_name} [{clamp|repeat} {decal|modulate} {nearest|bilinear|trilinear} scale_s scale_t translation_s translation_t rotation_degrees]" << std::endl;
8391 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8392 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
8393 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
8394 new OCC_TextureEnv(theArgVec[2]);
8398 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
8399 aTexEnv->SetTextureParameters(
8400 aRepeatOpt. IsEqual("repeat"),
8401 aModulateOpt.IsEqual("modulate"),
8402 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
8403 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
8404 Graphic3d_TOTF_TRILINEAR,
8405 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
8406 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
8407 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
8408 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
8409 (Standard_ShortReal)Draw::Atof(theArgVec[10])
8412 aView->SetTextureEnv(aTexEnv);
8414 else // Disabling environment mapping
8416 Handle(Graphic3d_TextureEnv) aTexture;
8417 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
8426 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
8428 //! Remove registered clipping plane from all views and objects.
8429 static void removePlane (MapOfPlanes& theRegPlanes,
8430 const TCollection_AsciiString& theName)
8432 Handle(Graphic3d_ClipPlane) aClipPlane;
8433 if (!theRegPlanes.Find (theName, aClipPlane))
8435 std::cout << "Warning: no such plane.\n";
8439 theRegPlanes.UnBind (theName);
8440 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
8441 anIObjIt.More(); anIObjIt.Next())
8443 const Handle(AIS_InteractiveObject)& aPrs = anIObjIt.Key1();
8444 aPrs->RemoveClipPlane (aClipPlane);
8447 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
8448 aViewIt.More(); aViewIt.Next())
8450 const Handle(V3d_View)& aView = aViewIt.Key2();
8451 aView->RemoveClipPlane(aClipPlane);
8454 ViewerTest::RedrawAllViews();
8458 //===============================================================================================
8459 //function : VClipPlane
8461 //===============================================================================================
8462 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8464 // use short-cut for created clip planes map of created (or "registered by name") clip planes
8465 static MapOfPlanes aRegPlanes;
8469 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
8471 theDi << aPlaneIter.Key() << " ";
8476 TCollection_AsciiString aCommand (theArgVec[1]);
8477 aCommand.LowerCase();
8478 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
8479 if (anActiveView.IsNull())
8481 std::cout << "Error: no active view.\n";
8485 // print maximum number of planes for current viewer
8486 if (aCommand == "-maxplanes"
8487 || aCommand == "maxplanes")
8489 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
8490 << " plane slots provided by driver.\n";
8494 // create / delete plane instance
8495 if (aCommand == "-create"
8496 || aCommand == "create"
8497 || aCommand == "-delete"
8498 || aCommand == "delete"
8499 || aCommand == "-clone"
8500 || aCommand == "clone")
8504 std::cout << "Syntax error: plane name is required.\n";
8508 Standard_Boolean toCreate = aCommand == "-create"
8509 || aCommand == "create";
8510 Standard_Boolean toClone = aCommand == "-clone"
8511 || aCommand == "clone";
8512 Standard_Boolean toDelete = aCommand == "-delete"
8513 || aCommand == "delete";
8514 TCollection_AsciiString aPlane (theArgVec[2]);
8518 if (aRegPlanes.IsBound (aPlane))
8520 std::cout << "Warning: existing plane has been overridden.\n";
8525 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8529 else if (toClone) // toClone
8531 if (!aRegPlanes.IsBound (aPlane))
8533 std::cout << "Error: no such plane.\n";
8536 else if (theArgsNb < 4)
8538 std::cout << "Syntax error: enter name for new plane.\n";
8542 TCollection_AsciiString aClone (theArgVec[3]);
8543 if (aRegPlanes.IsBound (aClone))
8545 std::cout << "Error: plane name is in use.\n";
8549 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
8551 aRegPlanes.Bind (aClone, aClipPlane->Clone());
8561 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
8563 aPlane = aPlaneIter.Key();
8564 removePlane (aRegPlanes, aPlane);
8565 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
8570 removePlane (aRegPlanes, aPlane);
8576 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8581 // set / unset plane command
8582 if (aCommand == "set"
8583 || aCommand == "unset")
8587 std::cout << "Syntax error: need more arguments.\n";
8591 // redirect to new syntax
8592 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
8593 anArgVec.SetValue (1, theArgVec[0]);
8594 anArgVec.SetValue (2, theArgVec[2]);
8595 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
8596 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
8598 anArgVec.SetValue (anIt, theArgVec[anIt]);
8601 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
8604 // change plane command
8605 TCollection_AsciiString aPlaneName;
8606 Handle(Graphic3d_ClipPlane) aClipPlane;
8607 Standard_Integer anArgIter = 0;
8608 if (aCommand == "-change"
8609 || aCommand == "change")
8611 // old syntax support
8614 std::cout << "Syntax error: need more arguments.\n";
8619 aPlaneName = theArgVec[2];
8620 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
8622 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
8626 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
8629 aPlaneName = theArgVec[1];
8634 aPlaneName = theArgVec[1];
8635 aClipPlane = new Graphic3d_ClipPlane();
8636 aRegPlanes.Bind (aPlaneName, aClipPlane);
8637 theDi << "Created new plane " << aPlaneName << ".\n";
8640 if (theArgsNb - anArgIter < 1)
8642 std::cout << "Syntax error: need more arguments.\n";
8646 for (; anArgIter < theArgsNb; ++anArgIter)
8648 const char** aChangeArgs = theArgVec + anArgIter;
8649 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
8650 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
8651 aChangeArg.LowerCase();
8653 Standard_Boolean toEnable = Standard_True;
8654 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
8656 aClipPlane->SetOn (toEnable);
8658 else if (aChangeArg.StartsWith ("-equation")
8659 || aChangeArg.StartsWith ("equation"))
8661 if (aNbChangeArgs < 5)
8663 std::cout << "Syntax error: need more arguments.\n";
8667 Standard_Integer aSubIndex = 1;
8668 Standard_Integer aPrefixLen = 8 + (aChangeArg.Value (1) == '-' ? 1 : 0);
8669 if (aPrefixLen < aChangeArg.Length())
8671 TCollection_AsciiString aSubStr = aChangeArg.SubString (aPrefixLen + 1, aChangeArg.Length());
8672 if (!aSubStr.IsIntegerValue()
8673 || aSubStr.IntegerValue() <= 0)
8675 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
8678 aSubIndex = aSubStr.IntegerValue();
8681 Standard_Real aCoeffA = Draw::Atof (aChangeArgs[1]);
8682 Standard_Real aCoeffB = Draw::Atof (aChangeArgs[2]);
8683 Standard_Real aCoeffC = Draw::Atof (aChangeArgs[3]);
8684 Standard_Real aCoeffD = Draw::Atof (aChangeArgs[4]);
8685 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
8686 for (Standard_Integer aSubPlaneIter = 1; aSubPlaneIter < aSubIndex; ++aSubPlaneIter)
8688 if (aSubPln->ChainNextPlane().IsNull())
8690 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
8692 aSubPln = aSubPln->ChainNextPlane();
8694 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
8695 aSubPln->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
8698 else if ((aChangeArg == "-boxinterior"
8699 || aChangeArg == "-boxint"
8700 || aChangeArg == "-box")
8701 && aNbChangeArgs >= 7)
8703 Graphic3d_BndBox3d aBndBox;
8704 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[1]), Draw::Atof (aChangeArgs[2]), Draw::Atof (aChangeArgs[3])));
8705 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[4]), Draw::Atof (aChangeArgs[5]), Draw::Atof (aChangeArgs[6])));
8708 Standard_Integer aNbSubPlanes = 6;
8709 const Graphic3d_Vec3d aDirArray[6] =
8711 Graphic3d_Vec3d (-1, 0, 0),
8712 Graphic3d_Vec3d ( 1, 0, 0),
8713 Graphic3d_Vec3d ( 0,-1, 0),
8714 Graphic3d_Vec3d ( 0, 1, 0),
8715 Graphic3d_Vec3d ( 0, 0,-1),
8716 Graphic3d_Vec3d ( 0, 0, 1),
8718 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
8719 for (Standard_Integer aSubPlaneIter = 0; aSubPlaneIter < aNbSubPlanes; ++aSubPlaneIter)
8721 const Graphic3d_Vec3d& aDir = aDirArray[aSubPlaneIter];
8722 const Standard_Real aW = -aDir.Dot ((aSubPlaneIter % 2 == 1) ? aBndBox.CornerMax() : aBndBox.CornerMin());
8723 aSubPln->SetEquation (gp_Pln (aDir.x(), aDir.y(), aDir.z(), aW));
8724 if (aSubPlaneIter + 1 == aNbSubPlanes)
8726 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
8730 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
8732 aSubPln = aSubPln->ChainNextPlane();
8735 else if (aChangeArg == "-capping"
8736 || aChangeArg == "capping")
8738 if (aNbChangeArgs < 2)
8740 std::cout << "Syntax error: need more arguments.\n";
8744 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8746 aClipPlane->SetCapping (toEnable);
8751 // just skip otherwise (old syntax)
8754 else if (aChangeArg == "-useobjectmaterial"
8755 || aChangeArg == "-useobjectmat"
8756 || aChangeArg == "-useobjmat"
8757 || aChangeArg == "-useobjmaterial")
8759 if (aNbChangeArgs < 2)
8761 std::cout << "Syntax error: need more arguments.\n";
8765 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8767 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
8771 else if (aChangeArg == "-useobjecttexture"
8772 || aChangeArg == "-useobjecttex"
8773 || aChangeArg == "-useobjtexture"
8774 || aChangeArg == "-useobjtex")
8776 if (aNbChangeArgs < 2)
8778 std::cout << "Syntax error: need more arguments.\n";
8782 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8784 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
8788 else if (aChangeArg == "-useobjectshader"
8789 || aChangeArg == "-useobjshader")
8791 if (aNbChangeArgs < 2)
8793 std::cout << "Syntax error: need more arguments.\n";
8797 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8799 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
8803 else if (aChangeArg == "-color"
8804 || aChangeArg == "color")
8806 Quantity_Color aColor;
8807 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
8812 std::cout << "Syntax error: need more arguments.\n";
8816 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
8817 aMat.SetAmbientColor (aColor);
8818 aMat.SetDiffuseColor (aColor);
8819 aClipPlane->SetCappingMaterial (aMat);
8820 anArgIter += aNbParsed;
8822 else if ((aChangeArg == "-transparency"
8823 || aChangeArg == "-transp")
8824 && aNbChangeArgs >= 2)
8826 TCollection_AsciiString aValStr (aChangeArgs[1]);
8827 Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect();
8828 if (aValStr.IsRealValue())
8830 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
8831 aMat.SetTransparency ((float )aValStr.RealValue());
8832 anAspect->SetAlphaMode (Graphic3d_AlphaMode_BlendAuto);
8833 aClipPlane->SetCappingMaterial (aMat);
8837 aValStr.LowerCase();
8838 Graphic3d_AlphaMode aMode = Graphic3d_AlphaMode_BlendAuto;
8839 if (aValStr == "opaque")
8841 aMode = Graphic3d_AlphaMode_Opaque;
8843 else if (aValStr == "mask")
8845 aMode = Graphic3d_AlphaMode_Mask;
8847 else if (aValStr == "blend")
8849 aMode = Graphic3d_AlphaMode_Blend;
8851 else if (aValStr == "blendauto")
8853 aMode = Graphic3d_AlphaMode_BlendAuto;
8857 std::cout << "Syntax error at '" << aValStr << "'\n";
8860 anAspect->SetAlphaMode (aMode);
8861 aClipPlane->SetCappingAspect (anAspect);
8865 else if (aChangeArg == "-texname"
8866 || aChangeArg == "texname")
8868 if (aNbChangeArgs < 2)
8870 std::cout << "Syntax error: need more arguments.\n";
8874 TCollection_AsciiString aTextureName (aChangeArgs[1]);
8875 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
8876 if (!aTexture->IsDone())
8878 aClipPlane->SetCappingTexture (NULL);
8882 aTexture->EnableModulate();
8883 aTexture->EnableRepeat();
8884 aClipPlane->SetCappingTexture (aTexture);
8888 else if (aChangeArg == "-texscale"
8889 || aChangeArg == "texscale")
8891 if (aClipPlane->CappingTexture().IsNull())
8893 std::cout << "Error: no texture is set.\n";
8897 if (aNbChangeArgs < 3)
8899 std::cout << "Syntax error: need more arguments.\n";
8903 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8904 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8905 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
8908 else if (aChangeArg == "-texorigin"
8909 || aChangeArg == "texorigin") // texture origin
8911 if (aClipPlane->CappingTexture().IsNull())
8913 std::cout << "Error: no texture is set.\n";
8917 if (aNbChangeArgs < 3)
8919 std::cout << "Syntax error: need more arguments.\n";
8923 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8924 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8926 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
8929 else if (aChangeArg == "-texrotate"
8930 || aChangeArg == "texrotate") // texture rotation
8932 if (aClipPlane->CappingTexture().IsNull())
8934 std::cout << "Error: no texture is set.\n";
8938 if (aNbChangeArgs < 2)
8940 std::cout << "Syntax error: need more arguments.\n";
8944 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8945 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
8948 else if (aChangeArg == "-hatch"
8949 || aChangeArg == "hatch")
8951 if (aNbChangeArgs < 2)
8953 std::cout << "Syntax error: need more arguments.\n";
8957 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
8958 aHatchStr.LowerCase();
8959 if (aHatchStr == "on")
8961 aClipPlane->SetCappingHatchOn();
8963 else if (aHatchStr == "off")
8965 aClipPlane->SetCappingHatchOff();
8969 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
8973 else if (aChangeArg == "-delete"
8974 || aChangeArg == "delete")
8976 removePlane (aRegPlanes, aPlaneName);
8979 else if (aChangeArg == "-set"
8980 || aChangeArg == "-unset"
8981 || aChangeArg == "-setoverrideglobal")
8983 // set / unset plane command
8984 const Standard_Boolean toSet = aChangeArg.StartsWith ("-set");
8985 const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal";
8986 Standard_Integer anIt = 1;
8987 for (; anIt < aNbChangeArgs; ++anIt)
8989 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
8990 if (anEntityName.IsEmpty()
8991 || anEntityName.Value (1) == '-')
8995 else if (!toOverrideGlobal
8996 && ViewerTest_myViews.IsBound1 (anEntityName))
8998 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
9001 aView->AddClipPlane (aClipPlane);
9005 aView->RemoveClipPlane (aClipPlane);
9009 else if (GetMapOfAIS().IsBound2 (anEntityName))
9011 Handle(AIS_InteractiveObject) aIObj = GetMapOfAIS().Find2 (anEntityName);
9014 aIObj->AddClipPlane (aClipPlane);
9018 aIObj->RemoveClipPlane (aClipPlane);
9020 if (!aIObj->ClipPlanes().IsNull())
9022 aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal);
9027 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
9034 // apply to active view
9037 anActiveView->AddClipPlane (aClipPlane);
9041 anActiveView->RemoveClipPlane (aClipPlane);
9046 anArgIter = anArgIter + anIt - 1;
9051 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
9056 ViewerTest::RedrawAllViews();
9060 //===============================================================================================
9061 //function : VZRange
9063 //===============================================================================================
9064 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9066 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
9068 if (aCurrentView.IsNull())
9070 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
9074 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
9078 theDi << "ZNear: " << aCamera->ZNear() << "\n";
9079 theDi << "ZFar: " << aCamera->ZFar() << "\n";
9085 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
9086 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
9088 if (aNewZNear >= aNewZFar)
9090 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
9094 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
9096 std::cout << theArgVec[0] << ": invalid arguments: ";
9097 std::cout << "znear, zfar should be positive for perspective camera.\n";
9101 aCamera->SetZRange (aNewZNear, aNewZFar);
9105 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
9109 aCurrentView->Redraw();
9114 //===============================================================================================
9115 //function : VAutoZFit
9117 //===============================================================================================
9118 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9120 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
9122 if (aCurrentView.IsNull())
9124 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
9128 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
9132 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
9138 theDi << "Auto z-fit mode: \n"
9139 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
9140 << "Scale: " << aScale << "\n";
9144 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
9148 aScale = Draw::Atoi (theArgVec[2]);
9151 aCurrentView->SetAutoZFitMode (isOn, aScale);
9152 aCurrentView->AutoZFit();
9153 aCurrentView->Redraw();
9158 //! Auxiliary function to print projection type
9159 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
9161 switch (theProjType)
9163 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
9164 case Graphic3d_Camera::Projection_Perspective: return "perspective";
9165 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
9166 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
9167 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
9172 //===============================================================================================
9173 //function : VCamera
9175 //===============================================================================================
9176 static int VCamera (Draw_Interpretor& theDI,
9177 Standard_Integer theArgsNb,
9178 const char** theArgVec)
9180 Handle(V3d_View) aView = ViewerTest::CurrentView();
9183 std::cout << "Error: no active view.\n";
9187 Handle(Graphic3d_Camera) aCamera = aView->Camera();
9190 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
9191 theDI << "FOVy: " << aCamera->FOVy() << "\n";
9192 theDI << "Distance: " << aCamera->Distance() << "\n";
9193 theDI << "IOD: " << aCamera->IOD() << "\n";
9194 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
9195 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
9196 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
9200 TCollection_AsciiString aPrsName;
9201 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
9203 Standard_CString anArg = theArgVec[anArgIter];
9204 TCollection_AsciiString anArgCase (anArg);
9205 anArgCase.LowerCase();
9206 if (anArgCase == "-proj"
9207 || anArgCase == "-projection"
9208 || anArgCase == "-projtype"
9209 || anArgCase == "-projectiontype")
9211 theDI << projTypeName (aCamera->ProjectionType()) << " ";
9213 else if (anArgCase == "-ortho"
9214 || anArgCase == "-orthographic")
9216 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
9218 else if (anArgCase == "-persp"
9219 || anArgCase == "-perspective"
9220 || anArgCase == "-perspmono"
9221 || anArgCase == "-perspectivemono"
9222 || anArgCase == "-mono")
9224 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
9226 else if (anArgCase == "-stereo"
9227 || anArgCase == "-stereoscopic"
9228 || anArgCase == "-perspstereo"
9229 || anArgCase == "-perspectivestereo")
9231 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9233 else if (anArgCase == "-left"
9234 || anArgCase == "-lefteye"
9235 || anArgCase == "-monoleft"
9236 || anArgCase == "-monolefteye"
9237 || anArgCase == "-perpsleft"
9238 || anArgCase == "-perpslefteye")
9240 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
9242 else if (anArgCase == "-right"
9243 || anArgCase == "-righteye"
9244 || anArgCase == "-monoright"
9245 || anArgCase == "-monorighteye"
9246 || anArgCase == "-perpsright")
9248 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
9250 else if (anArgCase == "-dist"
9251 || anArgCase == "-distance")
9253 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9254 if (anArgValue != NULL
9255 && *anArgValue != '-')
9258 aCamera->SetDistance (Draw::Atof (anArgValue));
9261 theDI << aCamera->Distance() << " ";
9263 else if (anArgCase == "-iod")
9265 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9266 if (anArgValue != NULL
9267 && *anArgValue != '-')
9270 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
9273 theDI << aCamera->IOD() << " ";
9275 else if (anArgCase == "-iodtype")
9277 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
9278 TCollection_AsciiString anValueCase (anArgValue);
9279 anValueCase.LowerCase();
9280 if (anValueCase == "abs"
9281 || anValueCase == "absolute")
9284 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
9287 else if (anValueCase == "rel"
9288 || anValueCase == "relative")
9291 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
9294 else if (*anArgValue != '-')
9296 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
9299 switch (aCamera->GetIODType())
9301 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
9302 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
9305 else if (anArgCase == "-zfocus")
9307 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9308 if (anArgValue != NULL
9309 && *anArgValue != '-')
9312 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
9315 theDI << aCamera->ZFocus() << " ";
9317 else if (anArgCase == "-zfocustype")
9319 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
9320 TCollection_AsciiString anValueCase (anArgValue);
9321 anValueCase.LowerCase();
9322 if (anValueCase == "abs"
9323 || anValueCase == "absolute")
9326 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
9329 else if (anValueCase == "rel"
9330 || anValueCase == "relative")
9333 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
9336 else if (*anArgValue != '-')
9338 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
9341 switch (aCamera->ZFocusType())
9343 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
9344 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
9347 else if (anArgCase == "-fov"
9348 || anArgCase == "-fovy")
9350 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9351 if (anArgValue != NULL
9352 && *anArgValue != '-')
9355 aCamera->SetFOVy (Draw::Atof (anArgValue));
9358 theDI << aCamera->FOVy() << " ";
9360 else if (aPrsName.IsEmpty()
9361 && !anArgCase.StartsWith ("-"))
9367 std::cout << "Error: unknown argument '" << anArg << "'\n";
9372 if (aPrsName.IsEmpty()
9379 if (!aPrsName.IsEmpty())
9381 Handle(AIS_CameraFrustum) aCameraFrustum;
9382 if (GetMapOfAIS().IsBound2 (aPrsName))
9384 // find existing object
9385 aCameraFrustum = Handle(AIS_CameraFrustum)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
9386 if (aCameraFrustum.IsNull())
9388 std::cout << "Error: object '" << aPrsName << "'is already defined and is not a camera frustum!\n";
9393 if (aCameraFrustum.IsNull())
9395 aCameraFrustum = new AIS_CameraFrustum();
9399 // not include displayed object of old camera frustum in the new one.
9400 ViewerTest::GetAISContext()->Erase (aCameraFrustum, false);
9403 aCameraFrustum->SetCameraFrustum (aView->Camera());
9405 ViewerTest::Display (aPrsName, aCameraFrustum);
9411 //! Parse stereo output mode
9412 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
9413 Graphic3d_StereoMode& theMode)
9415 TCollection_AsciiString aFlag (theArg);
9417 if (aFlag == "quadbuffer")
9419 theMode = Graphic3d_StereoMode_QuadBuffer;
9421 else if (aFlag == "anaglyph")
9423 theMode = Graphic3d_StereoMode_Anaglyph;
9425 else if (aFlag == "row"
9426 || aFlag == "rowinterlaced")
9428 theMode = Graphic3d_StereoMode_RowInterlaced;
9430 else if (aFlag == "col"
9431 || aFlag == "colinterlaced"
9432 || aFlag == "columninterlaced")
9434 theMode = Graphic3d_StereoMode_ColumnInterlaced;
9436 else if (aFlag == "chess"
9437 || aFlag == "chessboard")
9439 theMode = Graphic3d_StereoMode_ChessBoard;
9441 else if (aFlag == "sbs"
9442 || aFlag == "sidebyside")
9444 theMode = Graphic3d_StereoMode_SideBySide;
9446 else if (aFlag == "ou"
9447 || aFlag == "overunder")
9449 theMode = Graphic3d_StereoMode_OverUnder;
9451 else if (aFlag == "pageflip"
9452 || aFlag == "softpageflip")
9454 theMode = Graphic3d_StereoMode_SoftPageFlip;
9458 return Standard_False;
9460 return Standard_True;
9463 //! Parse anaglyph filter
9464 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
9465 Graphic3d_RenderingParams::Anaglyph& theFilter)
9467 TCollection_AsciiString aFlag (theArg);
9469 if (aFlag == "redcyansimple")
9471 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9473 else if (aFlag == "redcyan"
9474 || aFlag == "redcyanoptimized")
9476 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
9478 else if (aFlag == "yellowbluesimple")
9480 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
9482 else if (aFlag == "yellowblue"
9483 || aFlag == "yellowblueoptimized")
9485 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
9487 else if (aFlag == "greenmagenta"
9488 || aFlag == "greenmagentasimple")
9490 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
9494 return Standard_False;
9496 return Standard_True;
9499 //==============================================================================
9500 //function : VStereo
9502 //==============================================================================
9504 static int VStereo (Draw_Interpretor& theDI,
9505 Standard_Integer theArgNb,
9506 const char** theArgVec)
9508 Handle(V3d_View) aView = ViewerTest::CurrentView();
9513 std::cout << "Error: no active viewer!\n";
9517 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
9518 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
9521 TCollection_AsciiString aMode;
9522 switch (aView->RenderingParams().StereoMode)
9524 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
9525 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
9526 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
9527 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
9528 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
9529 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
9530 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
9531 case Graphic3d_StereoMode_Anaglyph :
9533 switch (aView->RenderingParams().AnaglyphFilter)
9535 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
9536 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
9537 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
9538 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
9539 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
9544 theDI << "Mode " << aMode << "\n";
9549 Handle(Graphic3d_Camera) aCamera;
9550 Graphic3d_RenderingParams* aParams = NULL;
9551 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
9552 if (!aView.IsNull())
9554 aParams = &aView->ChangeRenderingParams();
9555 aMode = aParams->StereoMode;
9556 aCamera = aView->Camera();
9559 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
9560 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
9562 Standard_CString anArg = theArgVec[anArgIter];
9563 TCollection_AsciiString aFlag (anArg);
9565 if (anUpdateTool.parseRedrawMode (aFlag))
9569 else if (aFlag == "0"
9572 if (++anArgIter < theArgNb)
9574 std::cout << "Error: wrong number of arguments!\n";
9578 if (!aCamera.IsNull()
9579 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
9581 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
9583 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
9586 else if (aFlag == "1"
9589 if (++anArgIter < theArgNb)
9591 std::cout << "Error: wrong number of arguments!\n";
9595 if (!aCamera.IsNull())
9597 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9599 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9602 else if (aFlag == "-reverse"
9603 || aFlag == "-reversed"
9604 || aFlag == "-swap")
9606 Standard_Boolean toEnable = Standard_True;
9607 if (++anArgIter < theArgNb
9608 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9612 aParams->ToReverseStereo = toEnable;
9614 else if (aFlag == "-noreverse"
9615 || aFlag == "-noswap")
9617 Standard_Boolean toDisable = Standard_True;
9618 if (++anArgIter < theArgNb
9619 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
9623 aParams->ToReverseStereo = !toDisable;
9625 else if (aFlag == "-mode"
9626 || aFlag == "-stereomode")
9628 if (++anArgIter >= theArgNb
9629 || !parseStereoMode (theArgVec[anArgIter], aMode))
9631 std::cout << "Error: syntax error at '" << anArg << "'\n";
9635 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9637 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9640 else if (aFlag == "-anaglyph"
9641 || aFlag == "-anaglyphfilter")
9643 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9644 if (++anArgIter >= theArgNb
9645 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
9647 std::cout << "Error: syntax error at '" << anArg << "'\n";
9651 aMode = Graphic3d_StereoMode_Anaglyph;
9652 aParams->AnaglyphFilter = aFilter;
9654 else if (parseStereoMode (anArg, aMode)) // short syntax
9656 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9658 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9663 std::cout << "Error: syntax error at '" << anArg << "'\n";
9668 if (!aView.IsNull())
9670 aParams->StereoMode = aMode;
9671 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9676 //===============================================================================================
9677 //function : VDefaults
9679 //===============================================================================================
9680 static int VDefaults (Draw_Interpretor& theDi,
9681 Standard_Integer theArgsNb,
9682 const char** theArgVec)
9684 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
9687 std::cerr << "No active viewer!\n";
9691 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
9694 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
9696 theDi << "DeflType: relative\n"
9697 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
9701 theDi << "DeflType: absolute\n"
9702 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
9704 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
9705 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
9709 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
9711 TCollection_AsciiString anArg (theArgVec[anArgIter]);
9713 if (anArg == "-ABSDEFL"
9714 || anArg == "-ABSOLUTEDEFLECTION"
9716 || anArg == "-DEFLECTION")
9718 if (++anArgIter >= theArgsNb)
9720 std::cout << "Error: wrong syntax at " << anArg << "\n";
9723 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
9724 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
9726 else if (anArg == "-RELDEFL"
9727 || anArg == "-RELATIVEDEFLECTION"
9728 || anArg == "-DEVCOEFF"
9729 || anArg == "-DEVIATIONCOEFF"
9730 || anArg == "-DEVIATIONCOEFFICIENT")
9732 if (++anArgIter >= theArgsNb)
9734 std::cout << "Error: wrong syntax at " << anArg << "\n";
9737 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
9738 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
9740 else if (anArg == "-ANGDEFL"
9741 || anArg == "-ANGULARDEFL"
9742 || anArg == "-ANGULARDEFLECTION")
9744 if (++anArgIter >= theArgsNb)
9746 std::cout << "Error: wrong syntax at " << anArg << "\n";
9749 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
9750 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
9752 else if (anArg == "-AUTOTR"
9753 || anArg == "-AUTOTRIANG"
9754 || anArg == "-AUTOTRIANGULATION")
9756 if (++anArgIter >= theArgsNb)
9758 std::cout << "Error: wrong syntax at " << anArg << "\n";
9761 TCollection_AsciiString aValue (theArgVec[anArgIter]);
9766 aDefParams->SetAutoTriangulation (Standard_True);
9768 else if (aValue == "off"
9771 aDefParams->SetAutoTriangulation (Standard_False);
9776 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
9783 //! Auxiliary method
9784 inline void addLight (const Handle(V3d_Light)& theLightNew,
9785 const Graphic3d_ZLayerId theLayer,
9786 const Standard_Boolean theIsGlobal)
9788 if (theLightNew.IsNull())
9793 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9794 if (theLayer == Graphic3d_ZLayerId_UNKNOWN)
9796 aViewer->AddLight (theLightNew);
9799 aViewer->SetLightOn (theLightNew);
9803 ViewerTest::CurrentView()->SetLightOn (theLightNew);
9808 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer);
9809 if (aSettings.Lights().IsNull())
9811 aSettings.SetLights (new Graphic3d_LightSet());
9813 aSettings.Lights()->Add (theLightNew);
9814 aViewer->SetZLayerSettings (theLayer, aSettings);
9818 //! Auxiliary method
9819 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
9821 TCollection_AsciiString anArgNextCase (theArgNext);
9822 anArgNextCase.UpperCase();
9823 if (anArgNextCase.Length() > 5
9824 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
9826 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
9830 return theArgNext.IntegerValue();
9834 //===============================================================================================
9837 //===============================================================================================
9838 static int VLight (Draw_Interpretor& theDi,
9839 Standard_Integer theArgsNb,
9840 const char** theArgVec)
9842 Handle(V3d_View) aView = ViewerTest::CurrentView();
9843 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9845 || aViewer.IsNull())
9847 std::cerr << "No active viewer!\n";
9851 Standard_Real anXYZ[3] = {};
9852 Standard_Real anAtten[2] = {};
9855 // print lights info
9856 Standard_Integer aLightId = 0;
9857 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
9859 Handle(V3d_Light) aLight = aLightIter.Value();
9860 const Quantity_Color aColor = aLight->Color();
9861 theDi << "Light #" << aLightId
9862 << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "")
9863 << " [" << aLight->GetId() << "]" << "\n";
9864 switch (aLight->Type())
9868 theDi << " Type: Ambient\n";
9869 theDi << " Intensity: " << aLight->Intensity() << "\n";
9872 case V3d_DIRECTIONAL:
9874 theDi << " Type: Directional\n";
9875 theDi << " Intensity: " << aLight->Intensity() << "\n";
9876 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9877 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
9878 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
9879 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9882 case V3d_POSITIONAL:
9884 theDi << " Type: Positional\n";
9885 theDi << " Intensity: " << aLight->Intensity() << "\n";
9886 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9887 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
9888 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9889 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9890 aLight->Attenuation (anAtten[0], anAtten[1]);
9891 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
9896 theDi << " Type: Spot\n";
9897 theDi << " Intensity: " << aLight->Intensity() << "\n";
9898 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9899 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9900 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9901 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
9902 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9903 aLight->Attenuation (anAtten[0], anAtten[1]);
9904 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
9905 theDi << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n";
9906 theDi << " Exponent: " << aLight->Concentration() << "\n";
9911 theDi << " Type: UNKNOWN\n";
9915 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n";
9919 Handle(V3d_Light) aLightNew;
9920 Handle(V3d_Light) aLightOld;
9921 Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN;
9922 Standard_Boolean isGlobal = Standard_True;
9923 Standard_Boolean toCreate = Standard_False;
9924 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
9925 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
9927 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
9929 TCollection_AsciiString aName, aValue;
9930 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
9931 TCollection_AsciiString anArgCase (anArg);
9932 anArgCase.UpperCase();
9933 if (anUpdateTool.parseRedrawMode (anArg))
9938 if (anArgCase.IsEqual ("NEW")
9939 || anArgCase.IsEqual ("ADD")
9940 || anArgCase.IsEqual ("CREATE")
9941 || anArgCase.IsEqual ("-NEW")
9942 || anArgCase.IsEqual ("-ADD")
9943 || anArgCase.IsEqual ("-CREATE"))
9945 toCreate = Standard_True;
9947 else if (anArgCase.IsEqual ("-LAYER")
9948 || anArgCase.IsEqual ("-ZLAYER"))
9950 if (++anArgIt >= theArgsNb)
9952 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9956 TCollection_AsciiString aValStr (theArgVec[anArgIt]);
9957 aValStr.LowerCase();
9958 if (aValStr == "default"
9959 || aValStr == "def")
9961 aLayer = Graphic3d_ZLayerId_Default;
9963 else if (aValStr == "top")
9965 aLayer = Graphic3d_ZLayerId_Top;
9967 else if (aValStr == "topmost")
9969 aLayer = Graphic3d_ZLayerId_Topmost;
9971 else if (aValStr == "toposd"
9972 || aValStr == "osd")
9974 aLayer = Graphic3d_ZLayerId_TopOSD;
9976 else if (aValStr == "botosd"
9977 || aValStr == "bottom")
9979 aLayer = Graphic3d_ZLayerId_BotOSD;
9981 else if (aValStr.IsIntegerValue())
9983 aLayer = Draw::Atoi (theArgVec[anArgIt]);
9987 std::cout << "Wrong syntax at argument '" << anArg << "'!\n";
9991 else if (anArgCase.IsEqual ("GLOB")
9992 || anArgCase.IsEqual ("GLOBAL")
9993 || anArgCase.IsEqual ("-GLOB")
9994 || anArgCase.IsEqual ("-GLOBAL"))
9996 isGlobal = Standard_True;
9998 else if (anArgCase.IsEqual ("LOC")
9999 || anArgCase.IsEqual ("LOCAL")
10000 || anArgCase.IsEqual ("-LOC")
10001 || anArgCase.IsEqual ("-LOCAL"))
10003 isGlobal = Standard_False;
10005 else if (anArgCase.IsEqual ("DEF")
10006 || anArgCase.IsEqual ("DEFAULTS")
10007 || anArgCase.IsEqual ("-DEF")
10008 || anArgCase.IsEqual ("-DEFAULTS"))
10010 toCreate = Standard_False;
10011 aViewer->SetDefaultLights();
10013 else if (anArgCase.IsEqual ("CLR")
10014 || anArgCase.IsEqual ("CLEAR")
10015 || anArgCase.IsEqual ("-CLR")
10016 || anArgCase.IsEqual ("-CLEAR"))
10018 toCreate = Standard_False;
10020 TColStd_SequenceOfInteger aLayers;
10021 aViewer->GetAllZLayers (aLayers);
10022 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
10024 if (aLayeriter.Value() == aLayer
10025 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
10027 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
10028 aSettings.SetLights (Handle(Graphic3d_LightSet)());
10029 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
10030 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
10037 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
10039 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
10041 Handle(V3d_Light) aLight = aLightIter.Value();
10042 aViewer->DelLight (aLight);
10043 aLightIter = aView->ActiveLightIterator();
10047 else if (anArgCase.IsEqual ("AMB")
10048 || anArgCase.IsEqual ("AMBIENT")
10049 || anArgCase.IsEqual ("AMBLIGHT"))
10053 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10057 addLight (aLightNew, aLayer, isGlobal);
10058 toCreate = Standard_False;
10059 aLightNew = new V3d_AmbientLight();
10061 else if (anArgCase.IsEqual ("DIRECTIONAL")
10062 || anArgCase.IsEqual ("DIRLIGHT"))
10066 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10070 addLight (aLightNew, aLayer, isGlobal);
10071 toCreate = Standard_False;
10072 aLightNew = new V3d_DirectionalLight();
10074 else if (anArgCase.IsEqual ("SPOT")
10075 || anArgCase.IsEqual ("SPOTLIGHT"))
10079 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10083 addLight (aLightNew, aLayer, isGlobal);
10084 toCreate = Standard_False;
10085 aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0));
10087 else if (anArgCase.IsEqual ("POSLIGHT")
10088 || anArgCase.IsEqual ("POSITIONAL"))
10092 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10096 addLight (aLightNew, aLayer, isGlobal);
10097 toCreate = Standard_False;
10098 aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0));
10100 else if (anArgCase.IsEqual ("CHANGE")
10101 || anArgCase.IsEqual ("-CHANGE"))
10103 if (++anArgIt >= theArgsNb)
10105 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10109 addLight (aLightNew, aLayer, isGlobal);
10110 aLightNew.Nullify();
10111 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
10112 Standard_Integer aLightIt = 0;
10113 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
10115 if (aLightIt == aLightId)
10117 aLightOld = aLightIter.Value();
10122 if (aLightOld.IsNull())
10124 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
10128 else if (anArgCase.IsEqual ("DEL")
10129 || anArgCase.IsEqual ("DELETE")
10130 || anArgCase.IsEqual ("-DEL")
10131 || anArgCase.IsEqual ("-DELETE"))
10133 Handle(V3d_Light) aLightDel;
10134 if (++anArgIt >= theArgsNb)
10136 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10140 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
10141 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
10142 Standard_Integer aLightIt = 0;
10143 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
10145 aLightDel = aLightIter.Value();
10146 if (aLightIt == aLightDelId)
10151 if (aLightDel.IsNull())
10156 TColStd_SequenceOfInteger aLayers;
10157 aViewer->GetAllZLayers (aLayers);
10158 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
10160 if (aLayeriter.Value() == aLayer
10161 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
10163 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
10164 if (!aSettings.Lights().IsNull())
10166 aSettings.Lights()->Remove (aLightDel);
10167 if (aSettings.Lights()->IsEmpty())
10169 aSettings.SetLights (Handle(Graphic3d_LightSet)());
10172 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
10173 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
10180 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
10182 aViewer->DelLight (aLightDel);
10185 else if (anArgCase.IsEqual ("COLOR")
10186 || anArgCase.IsEqual ("COLOUR")
10187 || anArgCase.IsEqual ("-COLOR")
10188 || anArgCase.IsEqual ("-COLOUR"))
10190 if (++anArgIt >= theArgsNb
10191 || aLightCurr.IsNull())
10193 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10197 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
10198 anArgNext.UpperCase();
10199 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
10200 aLightCurr->SetColor (aColor);
10202 else if (anArgCase.IsEqual ("POS")
10203 || anArgCase.IsEqual ("POSITION")
10204 || anArgCase.IsEqual ("-POS")
10205 || anArgCase.IsEqual ("-POSITION"))
10207 if ((anArgIt + 3) >= theArgsNb
10208 || aLightCurr.IsNull()
10209 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10210 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
10212 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10216 anXYZ[0] = Atof (theArgVec[++anArgIt]);
10217 anXYZ[1] = Atof (theArgVec[++anArgIt]);
10218 anXYZ[2] = Atof (theArgVec[++anArgIt]);
10219 aLightCurr->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
10221 else if (anArgCase.IsEqual ("DIR")
10222 || anArgCase.IsEqual ("DIRECTION")
10223 || anArgCase.IsEqual ("-DIR")
10224 || anArgCase.IsEqual ("-DIRECTION"))
10226 if ((anArgIt + 3) >= theArgsNb
10227 || aLightCurr.IsNull()
10228 || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL
10229 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
10231 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10235 anXYZ[0] = Atof (theArgVec[++anArgIt]);
10236 anXYZ[1] = Atof (theArgVec[++anArgIt]);
10237 anXYZ[2] = Atof (theArgVec[++anArgIt]);
10238 aLightCurr->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
10240 else if (anArgCase.IsEqual ("SM")
10241 || anArgCase.IsEqual ("SMOOTHNESS")
10242 || anArgCase.IsEqual ("-SM")
10243 || anArgCase.IsEqual ("-SMOOTHNESS"))
10245 if (++anArgIt >= theArgsNb
10246 || aLightCurr.IsNull())
10248 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10252 Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
10253 if (Abs (aSmoothness) <= ShortRealEpsilon())
10255 aLightCurr->SetIntensity (1.f);
10257 else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon())
10259 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
10263 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
10264 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
10267 if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL)
10269 aLightCurr->SetSmoothRadius (aSmoothness);
10271 else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
10273 aLightCurr->SetSmoothAngle (aSmoothness);
10276 else if (anArgCase.IsEqual ("INT")
10277 || anArgCase.IsEqual ("INTENSITY")
10278 || anArgCase.IsEqual ("-INT")
10279 || anArgCase.IsEqual ("-INTENSITY"))
10281 if (++anArgIt >= theArgsNb
10282 || aLightCurr.IsNull())
10284 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10288 Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
10289 aLightCurr->SetIntensity (aIntensity);
10291 else if (anArgCase.IsEqual ("ANG")
10292 || anArgCase.IsEqual ("ANGLE")
10293 || anArgCase.IsEqual ("-ANG")
10294 || anArgCase.IsEqual ("-ANGLE"))
10296 if (++anArgIt >= theArgsNb
10297 || aLightCurr.IsNull()
10298 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
10300 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10304 Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
10305 aLightCurr->SetAngle (Standard_ShortReal (anAngle / 180.0 * M_PI));
10307 else if (anArgCase.IsEqual ("CONSTATTEN")
10308 || anArgCase.IsEqual ("CONSTATTENUATION")
10309 || anArgCase.IsEqual ("-CONSTATTEN")
10310 || anArgCase.IsEqual ("-CONSTATTENUATION"))
10312 if (++anArgIt >= theArgsNb
10313 || aLightCurr.IsNull()
10314 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10315 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
10317 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10321 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
10322 anAtten[0] = Atof (theArgVec[anArgIt]);
10323 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
10325 else if (anArgCase.IsEqual ("LINATTEN")
10326 || anArgCase.IsEqual ("LINEARATTEN")
10327 || anArgCase.IsEqual ("LINEARATTENUATION")
10328 || anArgCase.IsEqual ("-LINATTEN")
10329 || anArgCase.IsEqual ("-LINEARATTEN")
10330 || anArgCase.IsEqual ("-LINEARATTENUATION"))
10332 if (++anArgIt >= theArgsNb
10333 || aLightCurr.IsNull()
10334 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10335 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
10337 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10341 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
10342 anAtten[1] = Atof (theArgVec[anArgIt]);
10343 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
10345 else if (anArgCase.IsEqual ("EXP")
10346 || anArgCase.IsEqual ("EXPONENT")
10347 || anArgCase.IsEqual ("SPOTEXP")
10348 || anArgCase.IsEqual ("SPOTEXPONENT")
10349 || anArgCase.IsEqual ("-EXP")
10350 || anArgCase.IsEqual ("-EXPONENT")
10351 || anArgCase.IsEqual ("-SPOTEXP")
10352 || anArgCase.IsEqual ("-SPOTEXPONENT"))
10354 if (++anArgIt >= theArgsNb
10355 || aLightCurr.IsNull()
10356 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
10358 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10362 aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt]));
10364 else if (anArgCase.IsEqual ("HEAD")
10365 || anArgCase.IsEqual ("HEADLIGHT")
10366 || anArgCase.IsEqual ("-HEAD")
10367 || anArgCase.IsEqual ("-HEADLIGHT"))
10369 if (aLightCurr.IsNull()
10370 || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
10372 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10376 Standard_Boolean isHeadLight = Standard_True;
10377 if (anArgIt + 1 < theArgsNb
10378 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight))
10382 aLightCurr->SetHeadlight (isHeadLight);
10386 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
10390 addLight (aLightNew, aLayer, isGlobal);
10394 //! Read Graphic3d_RenderingParams::PerfCounters flag.
10395 static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue,
10396 Standard_Boolean& theToReset,
10397 Graphic3d_RenderingParams::PerfCounters& theFlagsRem,
10398 Graphic3d_RenderingParams::PerfCounters& theFlagsAdd)
10400 Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE;
10401 TCollection_AsciiString aVal = theValue;
10402 Standard_Boolean toReverse = Standard_False;
10403 if (aVal == "none")
10405 theToReset = Standard_True;
10406 return Standard_True;
10408 else if (aVal.StartsWith ("-"))
10410 toReverse = Standard_True;
10411 aVal = aVal.SubString (2, aVal.Length());
10413 else if (aVal.StartsWith ("no"))
10415 toReverse = Standard_True;
10416 aVal = aVal.SubString (3, aVal.Length());
10418 else if (aVal.StartsWith ("+"))
10420 aVal = aVal.SubString (2, aVal.Length());
10424 theToReset = Standard_True;
10428 || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate;
10429 else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU;
10430 else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers;
10431 else if (aVal == "structs"
10432 || aVal == "structures"
10433 || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures;
10434 else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups;
10435 else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
10436 else if (aVal == "tris"
10437 || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles;
10438 else if (aVal == "pnts"
10439 || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points;
10440 else if (aVal == "mem"
10441 || aVal == "gpumem"
10442 || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem;
10443 else if (aVal == "skipimmediate"
10444 || aVal == "noimmediate") aFlag = Graphic3d_RenderingParams::PerfCounters_SkipImmediate;
10445 else if (aVal == "frametime"
10446 || aVal == "frametimers"
10447 || aVal == "time") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameTime;
10448 else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic;
10449 else if (aVal == "extended"
10450 || aVal == "verbose"
10451 || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended;
10452 else if (aVal == "full"
10453 || aVal == "all") aFlag = Graphic3d_RenderingParams::PerfCounters_All;
10456 return Standard_False;
10461 theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag);
10465 theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag);
10467 return Standard_True;
10470 //! Read Graphic3d_RenderingParams::PerfCounters flags.
10471 static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue,
10472 Graphic3d_RenderingParams::PerfCounters& theFlags)
10474 TCollection_AsciiString aValue = theValue;
10475 Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE;
10476 Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE;
10477 Standard_Boolean toReset = Standard_False;
10480 Standard_Integer aSplitPos = aValue.Search ("|");
10481 if (aSplitPos <= 0)
10483 if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd))
10485 return Standard_False;
10489 theFlags = Graphic3d_RenderingParams::PerfCounters_NONE;
10491 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd);
10492 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem);
10493 return Standard_True;
10498 TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1);
10499 if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd))
10501 return Standard_False;
10504 aValue = aValue.SubString (aSplitPos + 1, aValue.Length());
10508 //=======================================================================
10509 //function : VRenderParams
10510 //purpose : Enables/disables rendering features
10511 //=======================================================================
10513 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
10514 Standard_Integer theArgNb,
10515 const char** theArgVec)
10517 Handle(V3d_View) aView = ViewerTest::CurrentView();
10518 if (aView.IsNull())
10520 std::cerr << "Error: no active viewer!\n";
10524 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
10525 TCollection_AsciiString aCmdName (theArgVec[0]);
10526 aCmdName.LowerCase();
10527 if (aCmdName == "vraytrace")
10531 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
10534 else if (theArgNb == 2)
10536 TCollection_AsciiString aValue (theArgVec[1]);
10537 aValue.LowerCase();
10541 aParams.Method = Graphic3d_RM_RAYTRACING;
10545 else if (aValue == "off"
10548 aParams.Method = Graphic3d_RM_RASTERIZATION;
10554 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
10560 std::cout << "Error: wrong number of arguments\n";
10567 theDI << "renderMode: ";
10568 switch (aParams.Method)
10570 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
10571 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
10574 theDI << "transparency: ";
10575 switch (aParams.TransparencyMethod)
10577 case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break;
10578 case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: "
10579 << TCollection_AsciiString (aParams.OitDepthFactor); break;
10582 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
10583 theDI << "rendScale: " << aParams.RenderResolutionScale << "\n";
10584 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
10585 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
10586 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
10587 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
10588 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
10589 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
10590 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
10591 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
10592 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
10593 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
10594 theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
10595 theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n";
10596 theDI << "tile size (iss):" << aParams.RayTracingTileSize << "x" << aParams.RayTracingTileSize << "\n";
10597 theDI << "shadingModel: ";
10598 switch (aView->ShadingModel())
10600 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
10601 case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break;
10602 case Graphic3d_TOSM_FACET: theDI << "flat"; break;
10603 case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break;
10604 case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break;
10607 theDI << "perfCounters:";
10608 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0)
10612 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
10616 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
10618 theDI << " structs";
10620 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0)
10622 theDI << " groups";
10624 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0)
10626 theDI << " arrays";
10628 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0)
10632 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
10636 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0)
10638 theDI << " gpumem";
10640 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameTime) != 0)
10642 theDI << " frameTime";
10644 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_SkipImmediate) != 0)
10646 theDI << " skipimmediate";
10648 if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE)
10654 theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n";
10655 theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n";
10656 theDI << "frustum culling: " << (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On ? "on" :
10657 aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off ? "off" :
10658 "noUpdate") << "\n";
10663 Standard_Boolean toPrint = Standard_False;
10664 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10665 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
10667 Standard_CString anArg (theArgVec[anArgIter]);
10668 TCollection_AsciiString aFlag (anArg);
10670 if (anUpdateTool.parseRedrawMode (aFlag))
10674 else if (aFlag == "-echo"
10675 || aFlag == "-print")
10677 toPrint = Standard_True;
10678 anUpdateTool.Invalidate();
10680 else if (aFlag == "-mode"
10681 || aFlag == "-rendermode"
10682 || aFlag == "-render_mode")
10686 switch (aParams.Method)
10688 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
10689 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
10695 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10699 else if (aFlag == "-ray"
10700 || aFlag == "-raytrace")
10704 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
10708 aParams.Method = Graphic3d_RM_RAYTRACING;
10710 else if (aFlag == "-rast"
10711 || aFlag == "-raster"
10712 || aFlag == "-rasterization")
10716 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
10720 aParams.Method = Graphic3d_RM_RASTERIZATION;
10722 else if (aFlag == "-msaa")
10726 theDI << aParams.NbMsaaSamples << " ";
10729 else if (++anArgIter >= theArgNb)
10731 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10735 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
10736 if (aNbSamples < 0)
10738 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
10743 aParams.NbMsaaSamples = aNbSamples;
10746 else if (aFlag == "-linefeather"
10747 || aFlag == "-edgefeather"
10748 || aFlag == "-feather")
10752 theDI << " " << aParams.LineFeather << " ";
10755 else if (++anArgIter >= theArgNb)
10757 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10761 TCollection_AsciiString aParam = theArgVec[anArgIter];
10762 const Standard_ShortReal aFeather = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
10763 if (aFeather <= 0.0f)
10765 std::cerr << "Error: invalid value of line width feather " << aFeather << ". Should be > 0\n";
10768 aParams.LineFeather = aFeather;
10770 else if (aFlag == "-oit")
10774 if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
10776 theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " ";
10780 theDI << "off" << " ";
10784 else if (++anArgIter >= theArgNb)
10786 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10790 TCollection_AsciiString aParam = theArgVec[anArgIter];
10791 aParam.LowerCase();
10792 if (aParam.IsRealValue())
10794 const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
10795 if (aWeight < 0.f || aWeight > 1.f)
10797 std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n";
10801 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
10802 aParams.OitDepthFactor = aWeight;
10804 else if (aParam == "off")
10806 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED;
10810 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10814 else if (aFlag == "-depthprepass")
10818 theDI << (aParams.ToEnableDepthPrepass ? "on " : "off ");
10821 aParams.ToEnableDepthPrepass = Standard_True;
10822 if (anArgIter + 1 < theArgNb
10823 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass))
10828 else if (aFlag == "-samplealphatocoverage"
10829 || aFlag == "-alphatocoverage")
10833 theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off ");
10836 aParams.ToEnableAlphaToCoverage = Standard_True;
10837 if (anArgIter + 1 < theArgNb
10838 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage))
10843 else if (aFlag == "-rendscale"
10844 || aFlag == "-renderscale"
10845 || aFlag == "-renderresolutionscale")
10849 theDI << aParams.RenderResolutionScale << " ";
10852 else if (++anArgIter >= theArgNb)
10854 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10858 const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
10861 std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n";
10866 aParams.RenderResolutionScale = Standard_ShortReal(aScale);
10869 else if (aFlag == "-raydepth"
10870 || aFlag == "-ray_depth")
10874 theDI << aParams.RaytracingDepth << " ";
10877 else if (++anArgIter >= theArgNb)
10879 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10883 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
10885 // We allow RaytracingDepth be more than 10 in case of GI enabled
10886 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
10888 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
10893 aParams.RaytracingDepth = aDepth;
10896 else if (aFlag == "-shad"
10897 || aFlag == "-shadows")
10901 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
10905 Standard_Boolean toEnable = Standard_True;
10906 if (++anArgIter < theArgNb
10907 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10911 aParams.IsShadowEnabled = toEnable;
10913 else if (aFlag == "-refl"
10914 || aFlag == "-reflections")
10918 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
10922 Standard_Boolean toEnable = Standard_True;
10923 if (++anArgIter < theArgNb
10924 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10928 aParams.IsReflectionEnabled = toEnable;
10930 else if (aFlag == "-fsaa")
10934 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
10938 Standard_Boolean toEnable = Standard_True;
10939 if (++anArgIter < theArgNb
10940 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10944 aParams.IsAntialiasingEnabled = toEnable;
10946 else if (aFlag == "-gleam")
10950 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
10954 Standard_Boolean toEnable = Standard_True;
10955 if (++anArgIter < theArgNb
10956 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10960 aParams.IsTransparentShadowEnabled = toEnable;
10962 else if (aFlag == "-gi")
10966 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
10970 Standard_Boolean toEnable = Standard_True;
10971 if (++anArgIter < theArgNb
10972 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10976 aParams.IsGlobalIlluminationEnabled = toEnable;
10979 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
10982 else if (aFlag == "-blockedrng"
10983 || aFlag == "-brng")
10987 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
10991 Standard_Boolean toEnable = Standard_True;
10992 if (++anArgIter < theArgNb
10993 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10997 aParams.CoherentPathTracingMode = toEnable;
10999 else if (aFlag == "-maxrad")
11003 theDI << aParams.RadianceClampingValue << " ";
11006 else if (++anArgIter >= theArgNb)
11008 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11012 const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
11013 if (!aMaxRadStr.IsRealValue())
11015 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11019 const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
11020 if (aMaxRadiance <= 0.0)
11022 std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n";
11027 aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
11030 else if (aFlag == "-iss")
11034 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
11038 Standard_Boolean toEnable = Standard_True;
11039 if (++anArgIter < theArgNb
11040 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11044 aParams.AdaptiveScreenSampling = toEnable;
11046 else if (aFlag == "-issatomic")
11050 theDI << (aParams.AdaptiveScreenSamplingAtomic ? "on" : "off") << " ";
11054 Standard_Boolean toEnable = Standard_True;
11055 if (++anArgIter < theArgNb
11056 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11060 aParams.AdaptiveScreenSamplingAtomic = toEnable;
11062 else if (aFlag == "-issd")
11066 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
11070 Standard_Boolean toEnable = Standard_True;
11071 if (++anArgIter < theArgNb
11072 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11076 aParams.ShowSamplingTiles = toEnable;
11078 else if (aFlag == "-tilesize")
11082 theDI << aParams.RayTracingTileSize << " ";
11085 else if (++anArgIter >= theArgNb)
11087 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11091 const Standard_Integer aTileSize = Draw::Atoi (theArgVec[anArgIter]);
11094 std::cerr << "Error: invalid size of ISS tile " << aTileSize << ".\n";
11097 aParams.RayTracingTileSize = aTileSize;
11099 else if (aFlag == "-nbtiles")
11103 theDI << aParams.NbRayTracingTiles << " ";
11106 else if (++anArgIter >= theArgNb)
11108 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11112 const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]);
11115 std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n";
11118 else if (aNbTiles > 0
11120 || aNbTiles > 1024))
11122 std::cerr << "Warning: suboptimal number of ISS tiles " << aNbTiles << ". Recommended range: [64, 1024].\n";
11124 aParams.NbRayTracingTiles = aNbTiles;
11126 else if (aFlag == "-env")
11130 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
11134 Standard_Boolean toEnable = Standard_True;
11135 if (++anArgIter < theArgNb
11136 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11140 aParams.UseEnvironmentMapBackground = toEnable;
11142 else if (aFlag == "-twoside")
11146 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
11150 Standard_Boolean toEnable = Standard_True;
11151 if (++anArgIter < theArgNb
11152 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11156 aParams.TwoSidedBsdfModels = toEnable;
11158 else if (aFlag == "-shademodel"
11159 || aFlag == "-shadingmodel"
11160 || aFlag == "-shading")
11164 switch (aView->ShadingModel())
11166 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
11167 case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break;
11168 case Graphic3d_TOSM_FACET: theDI << "flat "; break;
11169 case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break;
11170 case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break;
11175 if (++anArgIter >= theArgNb)
11177 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11180 Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT;
11181 if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel)
11182 && aModel != Graphic3d_TOSM_DEFAULT)
11184 aView->SetShadingModel (aModel);
11188 std::cout << "Error: unknown shading model '" << theArgVec[anArgIter] << "'\n";
11192 else if (aFlag == "-resolution")
11194 if (++anArgIter >= theArgNb)
11196 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11200 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
11201 if (aResolution.IsIntegerValue())
11203 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
11207 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11211 else if (aFlag == "-rebuildglsl"
11212 || aFlag == "-rebuild")
11216 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
11220 Standard_Boolean toEnable = Standard_True;
11221 if (++anArgIter < theArgNb
11222 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11226 aParams.RebuildRayTracingShaders = toEnable;
11228 else if (aFlag == "-focal")
11230 if (++anArgIter >= theArgNb)
11232 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11236 TCollection_AsciiString aParam (theArgVec[anArgIter]);
11237 if (aParam.IsRealValue())
11239 float aFocalDist = static_cast<float> (aParam.RealValue());
11240 if (aFocalDist < 0)
11242 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
11245 aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist;
11249 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11253 else if (aFlag == "-aperture")
11255 if (++anArgIter >= theArgNb)
11257 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11261 TCollection_AsciiString aParam(theArgVec[anArgIter]);
11262 if (aParam.IsRealValue())
11264 float aApertureSize = static_cast<float> (aParam.RealValue());
11265 if (aApertureSize < 0)
11267 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
11270 aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize;
11274 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11278 else if (aFlag == "-exposure")
11280 if (++anArgIter >= theArgNb)
11282 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11286 TCollection_AsciiString anExposure (theArgVec[anArgIter]);
11287 if (anExposure.IsRealValue())
11289 aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
11293 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11297 else if (aFlag == "-whitepoint")
11299 if (++anArgIter >= theArgNb)
11301 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11305 TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
11306 if (aWhitePoint.IsRealValue())
11308 aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
11312 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11316 else if (aFlag == "-tonemapping")
11318 if (++anArgIter >= theArgNb)
11320 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11324 TCollection_AsciiString aMode (theArgVec[anArgIter]);
11327 if (aMode == "disabled")
11329 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled;
11331 else if (aMode == "filmic")
11333 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;
11337 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11341 else if (aFlag == "-performancestats"
11342 || aFlag == "-performancecounters"
11343 || aFlag == "-perfstats"
11344 || aFlag == "-perfcounters"
11345 || aFlag == "-stats")
11347 if (++anArgIter >= theArgNb)
11349 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11353 TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]);
11354 aFlagsStr.LowerCase();
11355 Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats;
11356 if (!convertToPerfStatsFlags (aFlagsStr, aFlags))
11358 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11361 aView->ChangeRenderingParams().CollectedStats = aFlags;
11362 aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE;
11364 else if (aFlag == "-perfupdateinterval"
11365 || aFlag == "-statsupdateinterval")
11367 if (++anArgIter >= theArgNb)
11369 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11372 aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
11374 else if (aFlag == "-perfchart"
11375 || aFlag == "-statschart")
11377 if (++anArgIter >= theArgNb)
11379 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11382 aView->ChangeRenderingParams().StatsNbFrames = Draw::Atoi (theArgVec[anArgIter]);
11384 else if (aFlag == "-perfchartmax"
11385 || aFlag == "-statschartmax")
11387 if (++anArgIter >= theArgNb)
11389 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11392 aView->ChangeRenderingParams().StatsMaxChartTime = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
11394 else if (aFlag == "-frustumculling"
11395 || aFlag == "-culling")
11399 theDI << ((aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On) ? "on" :
11400 (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off) ? "off" :
11401 "noUpdate") << " ";
11405 Graphic3d_RenderingParams::FrustumCulling aState = Graphic3d_RenderingParams::FrustumCulling_On;
11406 if (++anArgIter < theArgNb)
11408 TCollection_AsciiString aStateStr(theArgVec[anArgIter]);
11409 aStateStr.LowerCase();
11410 bool toEnable = true;
11411 if (ViewerTest::ParseOnOff (aStateStr.ToCString(), toEnable))
11413 aState = toEnable ? Graphic3d_RenderingParams::FrustumCulling_On : Graphic3d_RenderingParams::FrustumCulling_Off;
11415 else if (aStateStr == "noupdate"
11416 || aStateStr == "freeze")
11418 aState = Graphic3d_RenderingParams::FrustumCulling_NoUpdate;
11425 aParams.FrustumCullingState = aState;
11429 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
11437 //=======================================================================
11438 //function : searchInfo
11440 //=======================================================================
11441 inline TCollection_AsciiString searchInfo (const TColStd_IndexedDataMapOfStringString& theDict,
11442 const TCollection_AsciiString& theKey)
11444 for (TColStd_IndexedDataMapOfStringString::Iterator anIter (theDict); anIter.More(); anIter.Next())
11446 if (TCollection_AsciiString::IsSameString (anIter.Key(), theKey, Standard_False))
11448 return anIter.Value();
11451 return TCollection_AsciiString();
11454 //=======================================================================
11455 //function : VStatProfiler
11457 //=======================================================================
11458 static Standard_Integer VStatProfiler (Draw_Interpretor& theDI,
11459 Standard_Integer theArgNb,
11460 const char** theArgVec)
11462 Handle(V3d_View) aView = ViewerTest::CurrentView();
11463 if (aView.IsNull())
11465 std::cerr << "Error: no active viewer!\n";
11469 Standard_Boolean toRedraw = Standard_True;
11470 Graphic3d_RenderingParams::PerfCounters aPrevCounters = aView->ChangeRenderingParams().CollectedStats;
11471 Standard_ShortReal aPrevUpdInterval = aView->ChangeRenderingParams().StatsUpdateInterval;
11472 Graphic3d_RenderingParams::PerfCounters aRenderParams = Graphic3d_RenderingParams::PerfCounters_NONE;
11473 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
11475 Standard_CString anArg (theArgVec[anArgIter]);
11476 TCollection_AsciiString aFlag (anArg);
11478 if (aFlag == "-noredraw")
11480 toRedraw = Standard_False;
11484 Graphic3d_RenderingParams::PerfCounters aParam = Graphic3d_RenderingParams::PerfCounters_NONE;
11485 if (aFlag == "fps") aParam = Graphic3d_RenderingParams::PerfCounters_FrameRate;
11486 else if (aFlag == "cpu") aParam = Graphic3d_RenderingParams::PerfCounters_CPU;
11487 else if (aFlag == "alllayers"
11488 || aFlag == "layers") aParam = Graphic3d_RenderingParams::PerfCounters_Layers;
11489 else if (aFlag == "allstructs"
11490 || aFlag == "structs") aParam = Graphic3d_RenderingParams::PerfCounters_Structures;
11491 else if (aFlag == "groups") aParam = Graphic3d_RenderingParams::PerfCounters_Groups;
11492 else if (aFlag == "allarrays"
11493 || aFlag == "fillarrays"
11494 || aFlag == "linearrays"
11495 || aFlag == "pointarrays"
11496 || aFlag == "textarrays") aParam = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
11497 else if (aFlag == "triangles") aParam = Graphic3d_RenderingParams::PerfCounters_Triangles;
11498 else if (aFlag == "points") aParam = Graphic3d_RenderingParams::PerfCounters_Points;
11499 else if (aFlag == "geommem"
11500 || aFlag == "texturemem"
11501 || aFlag == "framemem") aParam = Graphic3d_RenderingParams::PerfCounters_EstimMem;
11502 else if (aFlag == "elapsedframe"
11503 || aFlag == "cpuframeaverage"
11504 || aFlag == "cpupickingaverage"
11505 || aFlag == "cpucullingaverage"
11506 || aFlag == "cpudynaverage"
11507 || aFlag == "cpuframemax"
11508 || aFlag == "cpupickingmax"
11509 || aFlag == "cpucullingmax"
11510 || aFlag == "cpudynmax") aParam = Graphic3d_RenderingParams::PerfCounters_FrameTime;
11513 std::cerr << "Unknown argument '" << theArgVec[anArgIter] << "'!\n";
11517 aRenderParams = Graphic3d_RenderingParams::PerfCounters (aRenderParams | aParam);
11521 if (aRenderParams != Graphic3d_RenderingParams::PerfCounters_NONE)
11523 aView->ChangeRenderingParams().CollectedStats =
11524 Graphic3d_RenderingParams::PerfCounters (aView->RenderingParams().CollectedStats | aRenderParams);
11528 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
11530 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
11533 TColStd_IndexedDataMapOfStringString aDict;
11534 aView->StatisticInformation (aDict);
11536 aView->ChangeRenderingParams().CollectedStats = aPrevCounters;
11538 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
11540 Standard_CString anArg(theArgVec[anArgIter]);
11541 TCollection_AsciiString aFlag(anArg);
11543 if (aFlag == "fps")
11545 theDI << searchInfo (aDict, "FPS") << " ";
11547 else if (aFlag == "cpu")
11549 theDI << searchInfo (aDict, "CPU FPS") << " ";
11551 else if (aFlag == "alllayers")
11553 theDI << searchInfo (aDict, "Layers") << " ";
11555 else if (aFlag == "layers")
11557 theDI << searchInfo (aDict, "Rendered layers") << " ";
11559 else if (aFlag == "allstructs")
11561 theDI << searchInfo (aDict, "Structs") << " ";
11563 else if (aFlag == "structs")
11565 theDI << searchInfo (aDict, "Rendered structs") << " ";
11567 else if (aFlag == "groups")
11569 theDI << searchInfo (aDict, "Rendered groups") << " ";
11571 else if (aFlag == "allarrays")
11573 theDI << searchInfo (aDict, "Rendered arrays") << " ";
11575 else if (aFlag == "fillarrays")
11577 theDI << searchInfo (aDict, "Rendered [fill] arrays") << " ";
11579 else if (aFlag == "linearrays")
11581 theDI << searchInfo (aDict, "Rendered [line] arrays") << " ";
11583 else if (aFlag == "pointarrays")
11585 theDI << searchInfo (aDict, "Rendered [point] arrays") << " ";
11587 else if (aFlag == "textarrays")
11589 theDI << searchInfo (aDict, "Rendered [text] arrays") << " ";
11591 else if (aFlag == "triangles")
11593 theDI << searchInfo (aDict, "Rendered triangles") << " ";
11595 else if (aFlag == "points")
11597 theDI << searchInfo (aDict, "Rendered points") << " ";
11599 else if (aFlag == "geommem")
11601 theDI << searchInfo (aDict, "GPU Memory [geometry]") << " ";
11603 else if (aFlag == "texturemem")
11605 theDI << searchInfo (aDict, "GPU Memory [textures]") << " ";
11607 else if (aFlag == "framemem")
11609 theDI << searchInfo (aDict, "GPU Memory [frames]") << " ";
11611 else if (aFlag == "elapsedframe")
11613 theDI << searchInfo (aDict, "Elapsed Frame (average)") << " ";
11615 else if (aFlag == "cpuframe_average")
11617 theDI << searchInfo (aDict, "CPU Frame (average)") << " ";
11619 else if (aFlag == "cpupicking_average")
11621 theDI << searchInfo (aDict, "CPU Picking (average)") << " ";
11623 else if (aFlag == "cpuculling_average")
11625 theDI << searchInfo (aDict, "CPU Culling (average)") << " ";
11627 else if (aFlag == "cpudyn_average")
11629 theDI << searchInfo (aDict, "CPU Dynamics (average)") << " ";
11631 else if (aFlag == "cpuframe_max")
11633 theDI << searchInfo (aDict, "CPU Frame (max)") << " ";
11635 else if (aFlag == "cpupicking_max")
11637 theDI << searchInfo (aDict, "CPU Picking (max)") << " ";
11639 else if (aFlag == "cpuculling_max")
11641 theDI << searchInfo (aDict, "CPU Culling (max)") << " ";
11643 else if (aFlag == "cpudyn_max")
11645 theDI << searchInfo (aDict, "CPU Dynamics (max)") << " ";
11653 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
11655 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
11657 theDI << "Statistic info:\n" << aView->StatisticInformation();
11662 //=======================================================================
11663 //function : VProgressiveMode
11665 //=======================================================================
11666 #if defined(_WIN32)
11667 static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
11668 Standard_Integer /*theNbArgs*/,
11669 const char** /*theArgs*/)
11671 Handle(V3d_View) aView = ViewerTest::CurrentView();
11672 if (aView.IsNull())
11674 std::cerr << "Error: no active viewer!\n";
11678 std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
11684 Standard_Boolean toExit = Standard_False;
11687 while (PeekMessageW (&aMsg, NULL, 0, 0, PM_REMOVE))
11689 if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
11691 toExit = Standard_True;
11694 TranslateMessage (&aMsg);
11695 DispatchMessageW (&aMsg);
11708 //=======================================================================
11709 //function : VXRotate
11711 //=======================================================================
11712 static Standard_Integer VXRotate (Draw_Interpretor& di,
11713 Standard_Integer argc,
11714 const char ** argv)
11716 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
11717 if (aContext.IsNull())
11719 di << argv[0] << "ERROR : use 'vinit' command before \n";
11725 di << "ERROR : Usage : " << argv[0] << " name angle\n";
11729 TCollection_AsciiString aName (argv[1]);
11730 Standard_Real anAngle = Draw::Atof (argv[2]);
11733 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
11734 Handle(AIS_InteractiveObject) anIObj;
11735 if (!aMap.Find2 (aName, anIObj))
11737 di << "Use 'vdisplay' before\n";
11741 gp_Trsf aTransform;
11742 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
11743 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
11745 aContext->SetLocation (anIObj, aTransform);
11746 aContext->UpdateCurrentViewer();
11750 //===============================================================================================
11751 //class : ViewerTest_AISManipulator
11752 //purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances
11753 //===============================================================================================
11754 DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
11756 class ViewerTest_AISManipulator : public AIS_Manipulator
11760 ViewerTest_AISManipulator() : AIS_Manipulator()
11762 GetMapOfAISManipulators().Add (this);
11765 virtual ~ViewerTest_AISManipulator()
11767 GetMapOfAISManipulators().Remove (this);
11770 DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
11773 IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
11774 IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
11776 //===============================================================================================
11777 //function : VManipulator
11779 //===============================================================================================
11780 static int VManipulator (Draw_Interpretor& theDi,
11781 Standard_Integer theArgsNb,
11782 const char** theArgVec)
11784 Handle(V3d_View) aView = ViewerTest::CurrentView();
11785 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
11786 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
11788 || aViewer.IsNull())
11790 std::cerr << "No active viewer!\n";
11794 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
11795 Standard_Integer anArgIter = 1;
11796 for (; anArgIter < theArgsNb; ++anArgIter)
11798 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
11801 ViewerTest_CmdParser aCmd;
11802 aCmd.AddDescription ("Manages manipulator for interactive objects:");
11803 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
11804 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
11805 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
11806 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
11807 aCmd.AddOption ("detach", "... - detach manipulator");
11809 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
11810 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
11811 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
11813 aCmd.AddOption ("move", "... x y z - move object");
11814 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
11815 aCmd.AddOption ("scale", "... factor - scale object");
11817 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
11818 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
11819 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
11820 aCmd.AddOption ("followDragging", "... {0|1} - set following dragging transform");
11821 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
11822 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
11823 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
11824 aCmd.AddOption ("size", "... size - set size of manipulator");
11825 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
11827 aCmd.Parse (theArgsNb, theArgVec);
11829 if (aCmd.HasOption ("help"))
11831 theDi.PrintHelp (theArgVec[0]);
11835 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
11837 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
11839 if (aName.IsEmpty())
11841 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
11845 // ----------------------------------
11846 // detach existing manipulator object
11847 // ----------------------------------
11849 if (aCmd.HasOption ("detach"))
11851 if (!aMapAIS.IsBound2 (aName))
11853 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
11857 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
11858 if (aManipulator.IsNull())
11860 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
11864 aManipulator->Detach();
11865 aMapAIS.UnBind2 (aName);
11866 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True);
11871 // -----------------------------------------------
11872 // find or create manipulator if it does not exist
11873 // -----------------------------------------------
11875 Handle(AIS_Manipulator) aManipulator;
11876 if (!aMapAIS.IsBound2 (aName))
11878 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
11880 aManipulator = new ViewerTest_AISManipulator();
11881 aMapAIS.Bind (aManipulator, aName);
11885 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
11886 if (aManipulator.IsNull())
11888 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
11893 // -----------------------------------------
11894 // change properties of manipulator instance
11895 // -----------------------------------------
11897 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
11899 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
11901 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
11903 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
11905 if (aCmd.HasOption ("followRotation", 1, Standard_True))
11907 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
11909 if (aCmd.HasOption("followDragging", 1, Standard_True))
11911 aManipulator->ChangeTransformBehavior().SetFollowDragging(aCmd.ArgBool("followDragging"));
11913 if (aCmd.HasOption ("gap", 1, Standard_True))
11915 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
11917 if (aCmd.HasOption ("part", 3, Standard_True))
11919 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
11920 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
11921 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
11922 if (aMode < 1 || aMode > 4)
11924 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 4].\n";
11928 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
11930 if (aCmd.HasOption ("pos", 3, Standard_True))
11932 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
11933 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
11934 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
11936 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
11938 if (aCmd.HasOption ("size", 1, Standard_True))
11940 aManipulator->SetSize (aCmd.ArgFloat ("size"));
11942 if (aCmd.HasOption ("zoomable", 1, Standard_True))
11944 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
11946 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
11948 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
11949 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
11953 // ---------------------------------------------------
11954 // attach, detach or access manipulator from an object
11955 // ---------------------------------------------------
11957 if (aCmd.HasOption ("attach"))
11959 // Find an object and attach manipulator to it
11960 if (!aCmd.HasOption ("attach", 1, Standard_True))
11965 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
11966 Handle(AIS_InteractiveObject) anObject;
11967 if (!aMapAIS.Find2 (anObjName, anObject))
11969 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
11973 for (ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators()); anIt.More(); anIt.Next())
11975 if (anIt.Value()->IsAttached()
11976 && anIt.Value()->Object() == anObject)
11978 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
11983 AIS_Manipulator::OptionsForAttach anOptions;
11984 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
11986 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
11988 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
11990 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
11992 if (aCmd.HasOption ("enableModes", 1, Standard_True))
11994 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
11997 aManipulator->Attach (anObject, anOptions);
12000 // --------------------------------------
12001 // apply transformation using manipulator
12002 // --------------------------------------
12004 if (aCmd.HasOption ("startTransform", 2, Standard_True))
12006 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
12008 if (aCmd.HasOption ("transform", 2, Standard_True))
12010 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
12012 if (aCmd.HasOption ("stopTransform"))
12014 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
12016 aManipulator->StopTransform (toApply);
12020 if (aCmd.HasOption ("move", 3, Standard_True))
12022 aT.SetTranslationPart (aCmd.ArgVec ("move"));
12024 if (aCmd.HasOption ("rotate", 7, Standard_True))
12026 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
12028 if (aCmd.HasOption ("scale", 1))
12030 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
12033 if (aT.Form() != gp_Identity)
12035 aManipulator->Transform (aT);
12038 ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True);
12043 //===============================================================================================
12044 //function : VSelectionProperties
12046 //===============================================================================================
12047 static int VSelectionProperties (Draw_Interpretor& theDi,
12048 Standard_Integer theArgsNb,
12049 const char** theArgVec)
12051 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
12054 std::cerr << "No active viewer!\n";
12058 if (TCollection_AsciiString (theArgVec[0]) == "vhighlightselected")
12060 // handle obsolete alias
12061 bool toEnable = true;
12064 theDi << (aCtx->ToHilightSelected() ? "on" : "off");
12067 else if (theArgsNb != 2
12068 || !ViewerTest::ParseOnOff (theArgVec[1], toEnable))
12070 std::cout << "Syntax error: wrong number of parameters.";
12073 if (toEnable != aCtx->ToHilightSelected())
12075 aCtx->ClearDetected();
12076 aCtx->SetToHilightSelected (toEnable);
12081 Standard_Boolean toPrint = theArgsNb == 1;
12082 Standard_Boolean toRedraw = Standard_False;
12083 Standard_Integer anArgIter = 1;
12084 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
12085 if (anArgIter < theArgsNb)
12087 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
12088 anArgFirst.LowerCase();
12090 if (anArgFirst == "dynhighlight"
12091 || anArgFirst == "dynhilight"
12092 || anArgFirst == "dynamichighlight"
12093 || anArgFirst == "dynamichilight")
12095 aType = Prs3d_TypeOfHighlight_Dynamic;
12097 else if (anArgFirst == "localdynhighlight"
12098 || anArgFirst == "localdynhilight"
12099 || anArgFirst == "localdynamichighlight"
12100 || anArgFirst == "localdynamichilight")
12102 aType = Prs3d_TypeOfHighlight_LocalDynamic;
12104 else if (anArgFirst == "selhighlight"
12105 || anArgFirst == "selhilight"
12106 || anArgFirst == "selectedhighlight"
12107 || anArgFirst == "selectedhilight")
12109 aType = Prs3d_TypeOfHighlight_Selected;
12111 else if (anArgFirst == "localselhighlight"
12112 || anArgFirst == "localselhilight"
12113 || anArgFirst == "localselectedhighlight"
12114 || anArgFirst == "localselectedhilight")
12116 aType = Prs3d_TypeOfHighlight_LocalSelected;
12123 for (; anArgIter < theArgsNb; ++anArgIter)
12125 TCollection_AsciiString anArg (theArgVec[anArgIter]);
12127 if (anArg == "-help")
12129 theDi.PrintHelp (theArgVec[0]);
12132 else if (anArg == "-print")
12134 toPrint = Standard_True;
12136 else if (anArg == "-autoactivate")
12138 Standard_Boolean toEnable = Standard_True;
12139 if (anArgIter + 1 < theArgsNb
12140 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12144 aCtx->SetAutoActivateSelection (toEnable);
12146 else if (anArg == "-automatichighlight"
12147 || anArg == "-automatichilight"
12148 || anArg == "-autohighlight"
12149 || anArg == "-autohilight")
12151 Standard_Boolean toEnable = Standard_True;
12152 if (anArgIter + 1 < theArgsNb
12153 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12157 aCtx->ClearSelected (false);
12158 aCtx->ClearDetected();
12159 aCtx->SetAutomaticHilight (toEnable);
12162 else if (anArg == "-highlightselected"
12163 || anArg == "-hilightselected")
12165 Standard_Boolean toEnable = Standard_True;
12166 if (anArgIter + 1 < theArgsNb
12167 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12171 aCtx->ClearDetected();
12172 aCtx->SetToHilightSelected (toEnable);
12175 else if (anArg == "-pickstrategy"
12176 || anArg == "-pickingstrategy")
12178 if (++anArgIter >= theArgsNb)
12180 std::cout << "Syntax error: type of highlighting is undefined\n";
12184 SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
12185 TCollection_AsciiString aVal (theArgVec[anArgIter]);
12187 if (aVal == "first"
12188 || aVal == "firstaccepted"
12189 || aVal == "firstacceptable")
12191 aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
12193 else if (aVal == "topmost"
12194 || aVal == "onlyTopmost")
12196 aStrategy = SelectMgr_PickingStrategy_OnlyTopmost;
12200 std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n";
12204 aCtx->SetPickingStrategy (aStrategy);
12206 else if (anArg == "-pixtol"
12207 && anArgIter + 1 < theArgsNb)
12209 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
12211 else if ((anArg == "-mode"
12212 || anArg == "-dispmode")
12213 && anArgIter + 1 < theArgsNb)
12215 if (aType == Prs3d_TypeOfHighlight_None)
12217 std::cout << "Syntax error: type of highlighting is undefined\n";
12221 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
12222 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12223 aStyle->SetDisplayMode (aDispMode);
12224 toRedraw = Standard_True;
12226 else if (anArg == "-layer"
12227 && anArgIter + 1 < theArgsNb)
12229 if (aType == Prs3d_TypeOfHighlight_None)
12231 std::cout << "Syntax error: type of highlighting is undefined\n";
12235 const Standard_Integer aNewLayer = Draw::Atoi (theArgVec[++anArgIter]);
12236 if (aNewLayer != Graphic3d_ZLayerId_UNKNOWN)
12238 TColStd_SequenceOfInteger aLayers;
12239 aCtx->CurrentViewer()->GetAllZLayers (aLayers);
12240 if (std::find (aLayers.begin(), aLayers.end(), aNewLayer) == aLayers.end())
12242 std::cout << "Syntax error: Layer " << aNewLayer << " is undefined\n";
12247 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12248 aStyle->SetZLayer (aNewLayer);
12249 toRedraw = Standard_True;
12251 else if (anArg == "-hicolor"
12252 || anArg == "-selcolor"
12253 || anArg == "-color")
12255 if (anArg.StartsWith ("-hi"))
12257 aType = Prs3d_TypeOfHighlight_Dynamic;
12259 else if (anArg.StartsWith ("-sel"))
12261 aType = Prs3d_TypeOfHighlight_Selected;
12263 else if (aType == Prs3d_TypeOfHighlight_None)
12265 std::cout << "Syntax error: type of highlighting is undefined\n";
12269 Quantity_Color aColor;
12270 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1,
12271 theArgVec + anArgIter + 1,
12273 if (aNbParsed == 0)
12275 std::cout << "Syntax error: need more arguments.\n";
12278 anArgIter += aNbParsed;
12280 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12281 aStyle->SetColor (aColor);
12282 toRedraw = Standard_True;
12284 else if ((anArg == "-transp"
12285 || anArg == "-transparency"
12286 || anArg == "-hitransp"
12287 || anArg == "-seltransp"
12288 || anArg == "-hitransplocal"
12289 || anArg == "-seltransplocal")
12290 && anArgIter + 1 < theArgsNb)
12292 if (anArg.StartsWith ("-hi"))
12294 aType = Prs3d_TypeOfHighlight_Dynamic;
12296 else if (anArg.StartsWith ("-sel"))
12298 aType = Prs3d_TypeOfHighlight_Selected;
12300 else if (aType == Prs3d_TypeOfHighlight_None)
12302 std::cout << "Syntax error: type of highlighting is undefined\n";
12306 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
12307 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12308 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
12309 toRedraw = Standard_True;
12311 else if ((anArg == "-mat"
12312 || anArg == "-material")
12313 && anArgIter + 1 < theArgsNb)
12315 if (aType == Prs3d_TypeOfHighlight_None)
12317 std::cout << "Syntax error: type of highlighting is undefined\n";
12321 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12322 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
12323 if (aMatName != Graphic3d_NOM_DEFAULT)
12326 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
12327 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
12328 Graphic3d_MaterialAspect aMat (aMatName);
12329 aMat.SetColor (aStyle->Color());
12330 aMat.SetTransparency (aStyle->Transparency());
12331 anAspect->SetFrontMaterial (aMat);
12332 anAspect->SetInteriorColor (aStyle->Color());
12333 aStyle->SetBasicFillAreaAspect (anAspect);
12337 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
12339 toRedraw = Standard_True;
12343 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
12349 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
12350 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
12351 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
12352 theDi << "Auto-highlight : " << (aCtx->AutomaticHilight() ? "On" : "Off") << "\n";
12353 theDi << "Highlight selected : " << (aCtx->ToHilightSelected() ? "On" : "Off") << "\n";
12354 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
12355 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
12356 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
12357 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
12358 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
12359 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
12360 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
12361 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
12362 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
12365 if (aCtx->NbSelected() != 0 && toRedraw)
12367 aCtx->HilightSelected (Standard_True);
12373 //===============================================================================================
12374 //function : VDumpSelectionImage
12376 //===============================================================================================
12377 static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
12378 Standard_Integer theArgsNb,
12379 const char** theArgVec)
12383 std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
12387 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
12388 if (aContext.IsNull())
12390 std::cout << "Error: no active view.\n";
12394 TCollection_AsciiString aFile;
12395 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
12396 Image_Format anImgFormat = Image_Format_BGR;
12397 Standard_Integer aPickedIndex = 1;
12398 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
12400 TCollection_AsciiString aParam (theArgVec[anArgIter]);
12401 aParam.LowerCase();
12402 if (aParam == "-type")
12404 if (++anArgIter >= theArgsNb)
12406 std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n";
12410 TCollection_AsciiString aValue (theArgVec[anArgIter]);
12411 aValue.LowerCase();
12412 if (aValue == "depth"
12413 || aValue == "normdepth"
12414 || aValue == "normalizeddepth")
12416 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
12417 anImgFormat = Image_Format_GrayF;
12419 if (aValue == "depthinverted"
12420 || aValue == "normdepthinverted"
12421 || aValue == "normalizeddepthinverted"
12422 || aValue == "inverted")
12424 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
12425 anImgFormat = Image_Format_GrayF;
12427 else if (aValue == "unnormdepth"
12428 || aValue == "unnormalizeddepth")
12430 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
12431 anImgFormat = Image_Format_GrayF;
12433 else if (aValue == "objectcolor"
12434 || aValue == "object"
12435 || aValue == "color")
12437 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
12439 else if (aValue == "entitycolor"
12440 || aValue == "entity")
12442 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
12444 else if (aValue == "ownercolor"
12445 || aValue == "owner")
12447 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
12449 else if (aValue == "selectionmodecolor"
12450 || aValue == "selectionmode"
12451 || aValue == "selmodecolor"
12452 || aValue == "selmode")
12454 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
12457 else if (aParam == "-picked"
12458 || aParam == "-pickeddepth"
12459 || aParam == "-pickedindex")
12461 if (++anArgIter >= theArgsNb)
12463 std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n";
12467 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
12469 else if (aFile.IsEmpty())
12471 aFile = theArgVec[anArgIter];
12475 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n";
12479 if (aFile.IsEmpty())
12481 std::cout << "Syntax error: image file name is missing.\n";
12485 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
12486 Standard_Integer aWidth = 0, aHeight = 0;
12487 aView->Window()->Size (aWidth, aHeight);
12489 Image_AlienPixMap aPixMap;
12490 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
12492 std::cout << "Error: can't allocate image.\n";
12495 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
12497 std::cout << "Error: can't generate selection image.\n";
12500 if (!aPixMap.Save (aFile))
12502 std::cout << "Error: can't save selection image.\n";
12508 //=======================================================================
12509 //function : ViewerCommands
12511 //=======================================================================
12513 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
12516 const char *group = "ZeViewer";
12517 theCommands.Add("vinit",
12518 "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]"
12519 "\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]"
12520 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
12521 "\n\t\t: [-display displayName]"
12523 "\n\t\t: Creates new View window with specified name viewName."
12524 "\n\t\t: By default the new view is created in the viewer and in"
12525 "\n\t\t: graphic driver shared with active view."
12526 "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}"
12527 "\n\t\t: If driverName isn't specified the driver will be shared with active view."
12528 "\n\t\t: If viewerName isn't specified the viewer will be shared with active view."
12529 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
12530 "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]"
12531 "\n\t\t: Display name will be used within creation of graphic driver, when specified."
12533 "\n\t\t: -left, -top pixel position of left top corner of the window."
12534 "\n\t\t: -width, -height width and heigth of window respectively."
12535 "\n\t\t: -cloneActive floag to copy camera and dimensions of active view."
12536 "\n\t\t: -exitOnClose when specified, closing the view will exit application."
12537 "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape."
12538 "\n\t\t: -2d_mode when on, view will not react on rotate scene events"
12539 "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.",
12540 __FILE__,VInit,group);
12541 theCommands.Add("vclose" ,
12542 "[view_id [keep_context=0|1]]\n"
12543 "or vclose ALL - to remove all created views\n"
12544 " - removes view(viewer window) defined by its view_id.\n"
12545 " - keep_context: by default 0; if 1 and the last view is deleted"
12546 " the current context is not removed.",
12547 __FILE__,VClose,group);
12548 theCommands.Add("vactivate" ,
12549 "vactivate view_id [-noUpdate]"
12550 " - activates view(viewer window) defined by its view_id",
12551 __FILE__,VActivate,group);
12552 theCommands.Add("vviewlist",
12553 "vviewlist [format={tree, long}]"
12554 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
12555 " - format: format of result output, if tree the output is a tree view;"
12556 "otherwise it's a list of full view names. By default format = tree",
12557 __FILE__,VViewList,group);
12558 theCommands.Add("vhelp" ,
12559 "vhelp : display help on the viewer commands",
12560 __FILE__,VHelp,group);
12561 theCommands.Add("vtop" ,
12562 "vtop or <T> : Top view. Orientation +X+Y" ,
12563 __FILE__,VTop,group);
12564 theCommands.Add("vbottom" ,
12565 "vbottom : Bottom view. Orientation +X-Y" ,
12566 __FILE__,VBottom,group);
12567 theCommands.Add("vleft" ,
12568 "vleft : Left view. Orientation -Y+Z" ,
12569 __FILE__,VLeft,group);
12570 theCommands.Add("vright" ,
12571 "vright : Right view. Orientation +Y+Z" ,
12572 __FILE__,VRight,group);
12573 theCommands.Add("vaxo" ,
12574 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
12575 __FILE__,VAxo,group);
12576 theCommands.Add("vfront" ,
12577 "vfront : Front view. Orientation +X+Z" ,
12578 __FILE__,VFront,group);
12579 theCommands.Add("vback" ,
12580 "vback : Back view. Orientation -X+Z" ,
12581 __FILE__,VBack,group);
12582 theCommands.Add("vpick" ,
12583 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
12585 theCommands.Add("vfit",
12586 "vfit or <F> [-selected] [-noupdate]"
12587 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
12588 __FILE__,VFit,group);
12589 theCommands.Add ("vfitarea",
12590 "vfitarea x1 y1 x2 y2"
12591 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
12592 "\n\t\t: Fit view to show area located between two points"
12593 "\n\t\t: given in world 2D or 3D corrdinates.",
12594 __FILE__, VFitArea, group);
12595 theCommands.Add ("vzfit", "vzfit [scale]\n"
12596 " Matches Z near, Z far view volume planes to the displayed objects.\n"
12597 " \"scale\" - specifies factor to scale computed z range.\n",
12598 __FILE__, VZFit, group);
12599 theCommands.Add("vrepaint",
12600 "vrepaint [-immediate]"
12601 "\n\t\t: force redraw",
12602 __FILE__,VRepaint,group);
12603 theCommands.Add("vclear",
12605 "\n\t\t: remove all the object from the viewer",
12606 __FILE__,VClear,group);
12607 theCommands.Add("vsetbg",
12608 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
12609 __FILE__,VSetBg,group);
12610 theCommands.Add("vsetbgmode",
12611 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
12612 __FILE__,VSetBgMode,group);
12613 theCommands.Add("vsetgradientbg",
12614 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
12615 __FILE__,VSetGradientBg,group);
12616 theCommands.Add("vsetgrbgmode",
12617 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
12618 __FILE__,VSetGradientBgMode,group);
12619 theCommands.Add("vsetcolorbg",
12620 "vsetcolorbg : vsetcolorbg r g b : Set background color",
12621 __FILE__,VSetColorBg,group);
12622 theCommands.Add("vsetdefaultbg",
12623 "vsetdefaultbg r g b\n"
12624 "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode"
12625 "\n\t\t: Set default viewer background fill color (flat/gradient).",
12626 __FILE__,VSetDefaultBg,group);
12627 theCommands.Add("vscale",
12628 "vscale : vscale X Y Z",
12629 __FILE__,VScale,group);
12630 theCommands.Add("vzbufftrihedron",
12631 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
12632 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
12633 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
12634 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
12635 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
12636 "\n\t\t: Displays a trihedron",
12637 __FILE__,VZBuffTrihedron,group);
12638 theCommands.Add("vrotate",
12639 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
12640 "\n : Option -mouseStart starts rotation according to the mouse position"
12641 "\n : Option -mouseMove continues rotation with angle computed"
12642 "\n : from last and new mouse position."
12643 "\n : vrotate AX AY AZ [X Y Z]",
12644 __FILE__,VRotate,group);
12645 theCommands.Add("vzoom",
12646 "vzoom : vzoom coef",
12647 __FILE__,VZoom,group);
12648 theCommands.Add("vpan",
12649 "vpan : vpan dx dy",
12650 __FILE__,VPan,group);
12651 theCommands.Add("vcolorscale",
12652 "vcolorscale name [-noupdate|-update] [-demo]"
12653 "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
12654 "\n\t\t: [-font HeightFont=20]"
12655 "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
12656 "\n\t\t: [-smoothTransition {on|off}=off]"
12657 "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
12658 "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
12659 "\n\t\t: [-textpos {left|right|center|none}=right]"
12660 "\n\t\t: [-labelAtBorder {on|off}=on]"
12661 "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
12662 "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
12663 "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
12664 "\n\t\t: [-xy Left=0 Bottom=0]"
12665 "\n\t\t: -demo - displays a color scale with demonstratio values"
12666 "\n\t\t: -colors - set colors for all intervals"
12667 "\n\t\t: -color - set color for specific interval"
12668 "\n\t\t: -textpos - horizontal label position relative to color scale bar"
12669 "\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
12670 "\n\t\t: at border means the value inbetween neighbor intervals,"
12671 "\n\t\t: at center means the center value within current interval"
12672 "\n\t\t: -labels - set labels for all intervals"
12673 "\n\t\t: -freeLabels - same as -labels but does not require"
12674 "\n\t\t: matching the number of intervals"
12675 "\n\t\t: -label - set label for specific interval"
12676 "\n\t\t: -title - set title"
12677 "\n\t\t: -reversed - setup smooth color transition between intervals"
12678 "\n\t\t: -smoothTransition - swap colorscale direction"
12679 "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values"
12680 __FILE__, VColorScale, group);
12681 theCommands.Add("vgraduatedtrihedron",
12682 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
12683 "\t[-namefont Name] [-valuesfont Name]\n"
12684 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
12685 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
12686 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
12687 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
12688 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
12689 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
12690 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
12691 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
12692 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
12693 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
12694 " - Displays or erases graduated trihedron"
12695 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
12696 " - namefont - font of axes names. Default: Arial\n"
12697 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
12698 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
12699 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
12700 " - valuesfont - font of axes values. Default: Arial\n"
12701 " - xcolor, ycolor, zcolor - color of axis and values\n"
12702 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
12703 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
12704 __FILE__,VGraduatedTrihedron,group);
12705 theCommands.Add("vtile" ,
12706 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
12707 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
12708 "\n\t\t: -totalSize the size of virtual bigger viewport"
12709 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
12710 "\n\t\t: -lowerLeft tile offset as lower left corner"
12711 "\n\t\t: -upperLeft tile offset as upper left corner",
12712 __FILE__, VTile, group);
12713 theCommands.Add("vzlayer",
12714 "vzlayer [layerId]"
12715 "\n\t\t: [-add|-delete|-get|-settings]"
12716 "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]"
12717 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
12718 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv}]"
12719 "\n\t\t: ZLayer list management:"
12720 "\n\t\t: -add add new z layer to viewer and print its id"
12721 "\n\t\t: -delete delete z layer"
12722 "\n\t\t: -get print sequence of z layers"
12723 "\n\t\t: -settings print status of z layer settings"
12724 "\n\t\t: -disable disables given setting"
12725 "\n\t\t: -enable enables given setting",
12726 __FILE__,VZLayer,group);
12727 theCommands.Add("vlayerline",
12728 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
12729 __FILE__,VLayerLine,group);
12730 theCommands.Add("vgrid",
12731 "vgrid [off] [-type {rect|circ}] [-mode {line|point}] [-origin X Y] [-rotAngle Angle] [-zoffset DZ]"
12732 "\n\t\t: [-step X Y] [-size DX DY]"
12733 "\n\t\t: [-step StepRadius NbDivisions] [-radius Radius]",
12734 __FILE__, VGrid, group);
12735 theCommands.Add ("vpriviledgedplane",
12736 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
12737 "\n\t\t: Ox, Oy, Oz - plane origin"
12738 "\n\t\t: Nx, Ny, Nz - plane normal direction"
12739 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
12740 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
12741 __FILE__, VPriviledgedPlane, group);
12742 theCommands.Add ("vconvert",
12743 "vconvert v [Mode={window|view}]"
12744 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
12745 "\n\t\t: vconvert x y z [Mode={window|grid}]"
12746 "\n\t\t: window - convert to window coordinates, pixels"
12747 "\n\t\t: view - convert to view projection plane"
12748 "\n\t\t: grid - convert to model coordinates, given on grid"
12749 "\n\t\t: ray - convert projection ray to model coordiantes"
12750 "\n\t\t: - vconvert v window : convert view to window;"
12751 "\n\t\t: - vconvert v view : convert window to view;"
12752 "\n\t\t: - vconvert x y window : convert view to window;"
12753 "\n\t\t: - vconvert x y view : convert window to view;"
12754 "\n\t\t: - vconvert x y : convert window to model;"
12755 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
12756 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
12757 "\n\t\t: - vconvert x y z window : convert model to window;"
12758 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
12759 "\n\t\t: Converts the given coordinates to window/view/model space.",
12760 __FILE__, VConvert, group);
12761 theCommands.Add ("vfps",
12762 "vfps [framesNb=100] [-duration seconds] : estimate average frame rate for active view",
12763 __FILE__, VFps, group);
12764 theCommands.Add ("vgldebug",
12765 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
12766 "\n\t\t: [-glslCode {off|short|full}] [-extraMsg {0|1}] [{0|1}]"
12767 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
12768 "\n\t\t: Debug context can be requested only on Windows"
12769 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
12770 "\n\t\t: -sync - request synchronized debug GL context"
12771 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
12772 "\n\t\t: which are suppressed by default,"
12773 "\n\t\t: -glslCode - log GLSL program source code,"
12774 "\n\t\t: which are suppressed by default,"
12775 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
12776 "\n\t\t: which are suppressed by default",
12777 __FILE__, VGlDebug, group);
12778 theCommands.Add ("vvbo",
12779 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
12780 __FILE__, VVbo, group);
12781 theCommands.Add ("vstereo",
12782 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
12783 "\n\t\t: [-anaglyph Filter]"
12784 "\n\t\t: Control stereo output mode. Available modes for -mode:"
12785 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
12786 "\n\t\t: requires driver support."
12787 "\n\t\t: Should be called BEFORE vinit!"
12788 "\n\t\t: anaglyph - Anaglyph glasses"
12789 "\n\t\t: rowInterlaced - row-interlaced display"
12790 "\n\t\t: columnInterlaced - column-interlaced display"
12791 "\n\t\t: chessBoard - chess-board output"
12792 "\n\t\t: sideBySide - horizontal pair"
12793 "\n\t\t: overUnder - vertical pair"
12794 "\n\t\t: Available Anaglyph filters for -anaglyph:"
12795 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
12796 "\n\t\t: greenMagentaSimple",
12797 __FILE__, VStereo, group);
12798 theCommands.Add ("vcaps",
12799 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}] [-polygonMode {0|1}]"
12800 "\n\t\t: [-compatibleProfile {0|1}]"
12801 "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]"
12802 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
12803 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
12804 "\n\t\t: Modify particular graphic driver options:"
12805 "\n\t\t: FFP - use fixed-function pipeline instead of"
12806 "\n\t\t: built-in GLSL programs"
12807 "\n\t\t: (requires compatible profile)"
12808 "\n\t\t: polygonMode - use Polygon Mode instead of built-in GLSL programs"
12809 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
12810 "\n\t\t: arrays to GPU memory)"
12811 "\n\t\t: sprite - use textured sprites instead of bitmaps"
12812 "\n\t\t: vsync - switch VSync on or off"
12813 "\n\t\t: winBuffer - allow using window buffer for rendering"
12814 "\n\t\t: Context creation options:"
12815 "\n\t\t: softMode - software OpenGL implementation"
12816 "\n\t\t: compatibleProfile - backward-compatible profile"
12817 "\n\t\t: quadbuffer - QuadBuffer"
12818 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
12819 "\n\t\t: rendering paths producing the same visual result when"
12820 "\n\t\t: possible."
12821 "\n\t\t: Command is intended for testing old hardware compatibility.",
12822 __FILE__, VCaps, group);
12823 theCommands.Add ("vmemgpu",
12824 "vmemgpu [f]: print system-dependent GPU memory information if available;"
12825 " with f option returns free memory in bytes",
12826 __FILE__, VMemGpu, group);
12827 theCommands.Add ("vreadpixel",
12828 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
12829 " : Read pixel value for active view",
12830 __FILE__, VReadPixel, group);
12831 theCommands.Add("diffimage",
12832 "diffimage imageFile1 imageFile2 [diffImageFile]"
12833 "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]"
12834 "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]"
12835 "\n\t\t: Compare two images by content and generate difference image."
12836 "\n\t\t: When -exitOnClose is specified, closing the view will exit application."
12837 "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.",
12838 __FILE__, VDiffImage, group);
12839 theCommands.Add ("vselect",
12840 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
12841 "- emulates different types of selection:\n"
12842 "- 1) single click selection\n"
12843 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
12844 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
12845 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
12846 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
12847 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
12848 " (partial inclusion - overlap - is not allowed by default)\n"
12849 "- 5) any of these selections with shift button pressed",
12850 __FILE__, VSelect, group);
12851 theCommands.Add ("vmoveto",
12852 "vmoveto [x y] [-reset]"
12853 "\n\t\t: Emulates cursor movement to pixel position (x,y)."
12854 "\n\t\t: -reset resets current highlighting",
12855 __FILE__, VMoveTo, group);
12856 theCommands.Add ("vviewparams",
12857 "vviewparams [-args] [-scale [s]]"
12858 "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]"
12859 "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]"
12860 "\n\t\t: Manage current view parameters or prints all"
12861 "\n\t\t: current values when called without argument."
12862 "\n\t\t: -scale [s] prints or sets viewport relative scale"
12863 "\n\t\t: -eye [x y z] prints or sets eye location"
12864 "\n\t\t: -at [x y z] prints or sets center of look"
12865 "\n\t\t: -up [x y z] prints or sets direction of up vector"
12866 "\n\t\t: -proj [x y z] prints or sets direction of look"
12867 "\n\t\t: -center x y sets location of center of the screen in pixels"
12868 "\n\t\t: -size [sx] prints viewport projection width and height sizes"
12869 "\n\t\t: or changes the size of its maximum dimension"
12870 "\n\t\t: -args prints vviewparams arguments for restoring current view",
12871 __FILE__, VViewParams, group);
12873 theCommands.Add("v2dmode",
12874 "v2dmode [-name viewName] [-mode {-on|-off}=-on]"
12875 "\n\t\t: name - name of existing view, if not defined, the active view is changed"
12876 "\n\t\t: mode - switches On/Off rotation mode"
12877 "\n\t\t: Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:"
12878 "\n\t\t: - rotation of the view by 3rd mouse button with Ctrl active"
12879 "\n\t\t: - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right"
12880 "\n\t\t: View camera position might be changed only by commands.",
12881 __FILE__, V2DMode, group);
12883 theCommands.Add("vanimation", "Alias for vanim",
12884 __FILE__, VAnimation, group);
12886 theCommands.Add("vanim",
12887 "List existing animations:"
12889 "\n\t\t: Animation playback:"
12890 "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]"
12891 "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]"
12892 "\n\t\t: -speed playback speed (1.0 is normal speed)"
12893 "\n\t\t: -freeLook skip camera animations"
12894 "\n\t\t: -lockLoop disable any interactions"
12896 "\n\t\t: Animation definition:"
12897 "\n\t\t: vanim Name/sub/name [-clear] [-delete]"
12898 "\n\t\t: [start TimeSec] [duration TimeSec]"
12900 "\n\t\t: Animation name defined in path-style (anim/name or anim.name)"
12901 "\n\t\t: specifies nested animations."
12902 "\n\t\t: There is no syntax to explicitly add new animation,"
12903 "\n\t\t: and all non-existing animations within the name will be"
12904 "\n\t\t: implicitly created on first use (including parents)."
12906 "\n\t\t: Each animation might define the SINGLE action (see below),"
12907 "\n\t\t: like camera transition, object transformation or custom callback."
12908 "\n\t\t: Child animations can be used for defining concurrent actions."
12910 "\n\t\t: Camera animation:"
12911 "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]"
12912 "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]"
12913 "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]"
12914 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
12915 "\n\t\t: -eyeX camera Eye positions pair (start and end)"
12916 "\n\t\t: -atX camera Center positions pair"
12917 "\n\t\t: -upX camera Up directions pair"
12918 "\n\t\t: -scaleX camera Scale factors pair"
12919 "\n\t\t: Object animation:"
12920 "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]"
12921 "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]"
12922 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
12923 "\n\t\t: -locX object Location points pair (translation)"
12924 "\n\t\t: -rotX object Orientations pair (quaternions)"
12925 "\n\t\t: -scaleX object Scale factors pair (quaternions)"
12926 "\n\t\t: Custom callback:"
12927 "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\""
12928 "\n\t\t: %Pts overall animation presentation timestamp"
12929 "\n\t\t: %LocalPts local animation timestamp"
12930 "\n\t\t: %Normalized local animation normalized value in range 0..1"
12932 "\n\t\t: Video recording:"
12933 "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]"
12934 "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]"
12935 "\n\t\t: [-crf Value] [-preset Preset]"
12936 "\n\t\t: -fps video framerate"
12937 "\n\t\t: -format file format, container (matroska, etc.)"
12938 "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)"
12939 "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)"
12940 "\n\t\t: -crf constant rate factor (specific to codec)"
12941 "\n\t\t: -preset codec parameters preset (specific to codec)"
12942 __FILE__, VAnimation, group);
12944 theCommands.Add("vchangeselected",
12945 "vchangeselected shape"
12946 "- adds to shape to selection or remove one from it",
12947 __FILE__, VChangeSelected, group);
12948 theCommands.Add ("vnbselected",
12950 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
12951 theCommands.Add ("vcamera",
12952 "vcamera [PrsName] [-ortho] [-projtype]"
12954 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
12955 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
12956 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
12957 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
12958 "\n\t\t: Manages camera parameters."
12959 "\n\t\t: Displays frustum when presntation name PrsName is specified."
12960 "\n\t\t: Prints current value when option called without argument."
12961 "\n\t\t: Orthographic camera:"
12962 "\n\t\t: -ortho activate orthographic projection"
12963 "\n\t\t: Perspective camera:"
12964 "\n\t\t: -persp activate perspective projection (mono)"
12965 "\n\t\t: -fovy field of view in y axis, in degrees"
12966 "\n\t\t: -distance distance of eye from camera center"
12967 "\n\t\t: Stereoscopic camera:"
12968 "\n\t\t: -stereo perspective projection (stereo)"
12969 "\n\t\t: -leftEye perspective projection (left eye)"
12970 "\n\t\t: -rightEye perspective projection (right eye)"
12971 "\n\t\t: -iod intraocular distance value"
12972 "\n\t\t: -iodType distance type, absolute or relative"
12973 "\n\t\t: -zfocus stereographic focus value"
12974 "\n\t\t: -zfocusType focus type, absolute or relative",
12975 __FILE__, VCamera, group);
12976 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
12977 "- vautozfit [on={1|0}] [scale]\n"
12978 " Prints or changes parameters of automatic z-fit mode:\n"
12979 " \"on\" - turns automatic z-fit on or off\n"
12980 " \"scale\" - specifies factor to scale computed z range.\n",
12981 __FILE__, VAutoZFit, group);
12982 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
12983 " vzrange - without parameters shows current values\n"
12984 " vzrange [znear] [zfar] - applies provided values to view",
12985 __FILE__,VZRange, group);
12986 theCommands.Add ("vpurgedisplay",
12988 "- removes structures which don't belong to objects displayed in neutral point",
12989 __FILE__, VPurgeDisplay, group);
12990 theCommands.Add("vsetviewsize",
12991 "vsetviewsize size",
12992 __FILE__,VSetViewSize,group);
12993 theCommands.Add("vmoveview",
12994 "vmoveview Dx Dy Dz [Start = 1|0]",
12995 __FILE__,VMoveView,group);
12996 theCommands.Add("vtranslateview",
12997 "vtranslateview Dx Dy Dz [Start = 1|0)]",
12998 __FILE__,VTranslateView,group);
12999 theCommands.Add("vturnview",
13000 "vturnview Ax Ay Az [Start = 1|0]",
13001 __FILE__,VTurnView,group);
13002 theCommands.Add("vtextureenv",
13003 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
13004 "or user-defined file and optionally applying texture mapping parameters\n"
13006 " vtextureenv off - disables environment mapping\n"
13007 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
13008 " std_texture = (0..7)\n"
13009 " rep = {clamp|repeat}\n"
13010 " mod = {decal|modulate}\n"
13011 " flt = {nearest|bilinear|trilinear}\n"
13012 " ss, st - scale factors for s and t texture coordinates\n"
13013 " ts, tt - translation for s and t texture coordinates\n"
13014 " rot - texture rotation angle in degrees",
13015 __FILE__, VTextureEnv, group);
13016 theCommands.Add("vhlr",
13017 "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
13018 "\n\t\t: Hidden Line Removal algorithm."
13019 "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones"
13020 "\n\t\t: -algoType type of HLR algorithm.\n",
13021 __FILE__,VHLR,group);
13022 theCommands.Add("vhlrtype",
13023 "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
13024 "\n\t\t: Changes the type of HLR algorithm using for shapes:"
13025 "\n\t\t: 'algo' - exact HLR algorithm is applied"
13026 "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied"
13027 "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
13028 __FILE__,VHLRType,group);
13029 theCommands.Add("vclipplane",
13030 "vclipplane planeName [{0|1}]"
13031 "\n\t\t: [-equation1 A B C D]"
13032 "\n\t\t: [-equation2 A B C D]"
13033 "\n\t\t: [-boxInterior MinX MinY MinZ MaxX MaxY MaxZ]"
13034 "\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]"
13035 "\n\t\t: [-maxPlanes]"
13036 "\n\t\t: [-capping {0|1}]"
13037 "\n\t\t: [-color R G B] [-transparency Value] [-hatch {on|off|ID}]"
13038 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
13039 "\n\t\t: [-texRotate Angle]"
13040 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
13041 "\n\t\t: [-useObjShader {0|1}]"
13042 "\n\t\t: Clipping planes management:"
13043 "\n\t\t: -maxPlanes print plane limit for view"
13044 "\n\t\t: -delete delete plane with given name"
13045 "\n\t\t: {off|on|0|1} turn clipping on/off"
13046 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
13047 "\n\t\t: applied to active View when list is omitted"
13048 "\n\t\t: -equation A B C D change plane equation"
13049 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
13050 "\n\t\t: Capping options:"
13051 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
13052 "\n\t\t: -color R G B set capping color"
13053 "\n\t\t: -transparency Value set capping transparency 0..1"
13054 "\n\t\t: -texName Texture set capping texture"
13055 "\n\t\t: -texScale SX SY set capping tex scale"
13056 "\n\t\t: -texOrigin TX TY set capping tex origin"
13057 "\n\t\t: -texRotate Angle set capping tex rotation"
13058 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
13059 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
13060 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
13061 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
13062 __FILE__, VClipPlane, group);
13063 theCommands.Add("vdefaults",
13064 "vdefaults [-absDefl value]"
13065 "\n\t\t: [-devCoeff value]"
13066 "\n\t\t: [-angDefl value]"
13067 "\n\t\t: [-autoTriang {off/on | 0/1}]"
13068 , __FILE__, VDefaults, group);
13069 theCommands.Add("vlight",
13070 "tool to manage light sources, without arguments shows list of lights."
13071 "\n Main commands: "
13072 "\n '-clear' to clear lights"
13073 "\n '-{def}aults' to load deafault lights"
13074 "\n '-add' <type> to add any light source"
13075 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
13076 "\n 'change' <lightId> to edit light source with specified lightId"
13077 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
13079 "\n -{pos}ition X Y Z"
13080 "\n -{dir}ection X Y Z (for directional light or for spotlight)"
13081 "\n -color colorName"
13082 "\n -{head}light 0|1"
13083 "\n -{sm}oothness value"
13084 "\n -{int}ensity value"
13085 "\n -{constAtten}uation value"
13086 "\n -{linearAtten}uation value"
13087 "\n -angle angleDeg"
13088 "\n -{spotexp}onent value"
13089 "\n -local|-global"
13090 "\n\n example: vlight -add positional -head 1 -pos 0 1 1 -color red"
13091 "\n example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2",
13092 __FILE__, VLight, group);
13093 theCommands.Add("vraytrace",
13095 "\n\t\t: Turns on/off ray-tracing renderer."
13096 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
13097 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
13098 __FILE__, VRenderParams, group);
13099 theCommands.Add("vrenderparams",
13100 "\n Manages rendering parameters: "
13101 "\n '-raster' Disables GPU ray-tracing"
13102 "\n '-msaa 0..4' Specifies number of samples for MSAA"
13103 "\n '-lineFeather > 0' Sets line feather factor"
13104 "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor"
13105 "\n '-depthPrePass on|off' Enables/disables depth pre-pass"
13106 "\n '-alphatocoverage on|off' Enables/disables alpha to coverage (needs MSAA)"
13107 "\n '-rendScale value Rendering resolution scale factor"
13108 "\n '-rayTrace' Enables GPU ray-tracing"
13109 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
13110 "\n '-shadows on|off' Enables/disables shadows rendering"
13111 "\n '-reflections on|off' Enables/disables specular reflections"
13112 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
13113 "\n '-gleam on|off' Enables/disables transparency shadow effects"
13114 "\n '-gi on|off' Enables/disables global illumination effects"
13115 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
13116 "\n '-env on|off' Enables/disables environment map background"
13117 "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
13118 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
13119 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
13120 "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)"
13121 "\n '-tileSize 1..4096' Specifies size of screen tiles in ISS mode (32 by default)"
13122 "\n '-nbtiles 64..1024' Specifies number of screen tiles per Redraw in ISS mode (256 by default)"
13123 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
13124 "\n '-shadingModel model' Controls shading model from enumeration"
13125 "\n color, flat, gouraud, phong"
13126 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
13127 "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)"
13128 "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect"
13129 "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)"
13130 "\n '-whitepoint value' White point value for filmic tone mapping"
13131 "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)"
13132 "\n '-perfCounters none|fps|cpu|layers|structures|groups|arrays|triagles|points"
13133 "\n ' |gpuMem|frameTime|basic|extended|full|nofps|skipImmediate'"
13134 "\n Show/hide performance counters (flags can be combined)"
13135 "\n '-perfUpdateInterval nbSeconds' Performance counters update interval"
13136 "\n '-perfChart nbFrames' Show frame timers chart limited by specified number of frames"
13137 "\n '-perfChartMax seconds' Maximum time in seconds with the chart"
13138 "\n '-frustumCulling on|off|noupdate' Enable/disable objects frustum clipping or"
13139 "\n set state to check structures culled previously."
13140 "\n Unlike vcaps, these parameters dramatically change visual properties."
13141 "\n Command is intended to control presentation quality depending on"
13142 "\n hardware capabilities and performance.",
13143 __FILE__, VRenderParams, group);
13144 theCommands.Add("vstatprofiler",
13145 "\n vstatprofiler [fps|cpu|allLayers|layers|allstructures|structures|groups"
13146 "\n |allArrays|fillArrays|lineArrays|pointArrays|textArrays"
13147 "\n |triagles|points|geomMem|textureMem|frameMem"
13148 "\n |elapsedFrame|cpuFrameAverage|cpuPickingAverage|cpuCullingAverage|cpuDynAverage"
13149 "\n |cpuFrameMax|cpuPickingMax|cpuCullingMax|cpuDynMax]"
13151 "\n\t\t: Prints rendering statistics."
13152 "\n\t\t: If there are some parameters - print corresponding statistic counters values,"
13153 "\n\t\t: else - print all performance counters set previously."
13154 "\n\t\t: '-noredraw' Flag to avoid additional redraw call and use already collected values.\n",
13155 __FILE__, VStatProfiler, group);
13156 theCommands.Add ("vplace",
13158 "\n\t\t: Places the point (in pixels) at the center of the window",
13159 __FILE__, VPlace, group);
13160 theCommands.Add("vxrotate",
13162 __FILE__,VXRotate,group);
13164 theCommands.Add("vmanipulator",
13165 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
13166 "\n tool to create and manage AIS manipulators."
13168 "\n '-attach AISObject' attach manipulator to AISObject"
13169 "\n '-adjustPosition {0|1}' adjust position when attaching"
13170 "\n '-adjustSize {0|1}' adjust size when attaching"
13171 "\n '-enableModes {0|1}' enable modes when attaching"
13172 "\n '-detach' detach manipulator"
13173 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
13174 "\n '-transform mouse_x mouse_y' - invoke transformation"
13175 "\n '-stopTransform [abort]' - invoke stop of transformation"
13176 "\n '-move x y z' - move attached object"
13177 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
13178 "\n '-scale factor' - scale attached object"
13179 "\n '-autoActivate {0|1}' - set activation on detection"
13180 "\n '-followTranslation {0|1}' - set following translation transform"
13181 "\n '-followRotation {0|1}' - set following rotation transform"
13182 "\n '-followDragging {0|1}' - set following dragging transform"
13183 "\n '-gap value' - set gap between sub-parts"
13184 "\n '-part axis mode {0|1}' - set visual part"
13185 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
13186 "\n '-size value' - set size of manipulator"
13187 "\n '-zoomable {0|1}' - set zoom persistence",
13188 __FILE__, VManipulator, group);
13190 theCommands.Add("vselprops",
13191 "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]"
13192 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
13193 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
13194 "\n -autoHighlight {0|1} : disables|enables automatic highlighting in 3D Viewer"
13195 "\n -highlightSelected {0|1}: disables|enables highlighting of detected object in selected state"
13196 "\n -pickStrategy {first|topmost} : defines picking strategy"
13197 "\n 'first' to pick first acceptable (default)"
13198 "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)"
13199 "\n -pixTol value : sets up pixel tolerance"
13200 "\n -dispMode dispMode : sets display mode for highlighting"
13201 "\n -layer ZLayer : sets ZLayer for highlighting"
13202 "\n -color {name|r g b} : sets highlight color"
13203 "\n -transp value : sets transparency coefficient for highlight"
13204 "\n -material material : sets highlight material"
13205 "\n -print : prints current state of all mentioned parameters",
13206 __FILE__, VSelectionProperties, group);
13207 theCommands.Add ("vhighlightselected",
13208 "vhighlightselected [0|1]: alias for vselprops -highlightSelected.\n",
13209 __FILE__, VSelectionProperties, group);
13211 theCommands.Add ("vseldump",
13212 "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1"
13213 "\n\t\t: Generate an image based on detection results:"
13214 "\n\t\t: depth normalized depth values"
13215 "\n\t\t: unnormDepth unnormalized depth values"
13216 "\n\t\t: object color of detected object"
13217 "\n\t\t: owner color of detected owner"
13218 "\n\t\t: selMode color of selection mode"
13219 "\n\t\t: entity color of etected entity",
13220 __FILE__, VDumpSelectionImage, group);
13222 #if defined(_WIN32)
13223 theCommands.Add("vprogressive",
13225 __FILE__, VProgressiveMode, group);