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]))
4763 TCollection_AsciiString aFirstArg (theArgVec[anArgIter]);
4764 if (aFirstArg.IsIntegerValue())
4767 aLayerId = aFirstArg.IntegerValue();
4771 if (ViewerTest::ParseZLayerName (aFirstArg.ToCString(), aLayerId))
4778 for (; anArgIter < theArgNb; ++anArgIter)
4780 // perform operation
4781 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4783 if (anUpdateTool.parseRedrawMode (anArg))
4787 else if (anArg == "-add"
4790 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4791 if (!aViewer->AddZLayer (aLayerId))
4793 std::cout << "Error: can not add a new z layer!\n";
4799 else if (anArg == "-del"
4800 || anArg == "-delete"
4803 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4805 if (++anArgIter >= theArgNb)
4807 std::cout << "Syntax error: id of z layer to remove is missing\n";
4811 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4814 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN
4815 || aLayerId == Graphic3d_ZLayerId_Default
4816 || aLayerId == Graphic3d_ZLayerId_Top
4817 || aLayerId == Graphic3d_ZLayerId_Topmost
4818 || aLayerId == Graphic3d_ZLayerId_TopOSD
4819 || aLayerId == Graphic3d_ZLayerId_BotOSD)
4821 std::cout << "Syntax error: standard Z layer can not be removed\n";
4825 // move all object displayed in removing layer to default layer
4826 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4827 anObjIter.More(); anObjIter.Next())
4829 const Handle(AIS_InteractiveObject)& aPrs = anObjIter.Key1();
4831 || aPrs->ZLayer() != aLayerId)
4835 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4838 if (!aViewer->RemoveZLayer (aLayerId))
4840 std::cout << "Z layer can not be removed!\n";
4844 theDI << aLayerId << " ";
4847 else if (anArg == "-get"
4850 TColStd_SequenceOfInteger aLayers;
4851 aViewer->GetAllZLayers (aLayers);
4852 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4854 theDI << aLayeriter.Value() << " ";
4859 else if (anArg == "-name")
4861 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4863 std::cout << "Syntax error: id of Z layer is missing\n";
4867 if (++anArgIter >= theArgNb)
4869 std::cout << "Syntax error: name is missing\n";
4873 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4874 aSettings.SetName (theArgVec[anArgIter]);
4875 aViewer->SetZLayerSettings (aLayerId, aSettings);
4877 else if (anArg == "-origin")
4879 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4881 std::cout << "Syntax error: id of Z layer is missing\n";
4885 if (anArgIter + 2 >= theArgNb)
4887 std::cout << "Syntax error: origin coordinates are missing\n";
4891 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4893 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1]));
4894 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2]));
4895 anOrigin.SetZ (0.0);
4896 if (anArgIter + 3 < theArgNb)
4898 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3]));
4905 aSettings.SetOrigin (anOrigin);
4906 aViewer->SetZLayerSettings (aLayerId, aSettings);
4908 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
4909 && anArgIter + 1 < theArgNb
4910 && (anArg == "-cullingdistance"
4911 || anArg == "-cullingdist"
4912 || anArg == "-culldistance"
4913 || anArg == "-culldist"
4914 || anArg == "-distcull"
4915 || anArg == "-distculling"
4916 || anArg == "-distanceculling"))
4918 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4919 const Standard_Real aDist = Draw::Atof (theArgVec[++anArgIter]);
4920 aSettings.SetCullingDistance (aDist);
4921 aViewer->SetZLayerSettings (aLayerId, aSettings);
4923 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
4924 && anArgIter + 1 < theArgNb
4925 && (anArg == "-cullingsize"
4926 || anArg == "-cullsize"
4927 || anArg == "-sizecull"
4928 || anArg == "-sizeculling"))
4930 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4931 const Standard_Real aSize = Draw::Atof (theArgVec[++anArgIter]);
4932 aSettings.SetCullingSize (aSize);
4933 aViewer->SetZLayerSettings (aLayerId, aSettings);
4935 else if (anArg == "-settings"
4936 || anArg == "settings")
4938 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4940 if (++anArgIter >= theArgNb)
4942 std::cout << "Syntax error: id of Z layer is missing\n";
4946 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4949 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4950 printZLayerInfo (theDI, aSettings);
4952 else if (anArg == "-enable"
4953 || anArg == "enable"
4954 || anArg == "-disable"
4955 || anArg == "disable")
4957 const Standard_Boolean toEnable = anArg == "-enable"
4958 || anArg == "enable";
4959 if (++anArgIter >= theArgNb)
4961 std::cout << "Syntax error: option name is missing\n";
4965 TCollection_AsciiString aSubOp (theArgVec[anArgIter]);
4967 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4969 if (++anArgIter >= theArgNb)
4971 std::cout << "Syntax error: id of Z layer is missing\n";
4975 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4978 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4979 if (aSubOp == "depthtest"
4980 || aSubOp == "test")
4982 aSettings.SetEnableDepthTest (toEnable);
4984 else if (aSubOp == "depthwrite"
4985 || aSubOp == "write")
4987 aSettings.SetEnableDepthWrite (toEnable);
4989 else if (aSubOp == "depthclear"
4990 || aSubOp == "clear")
4992 aSettings.SetClearDepth (toEnable);
4994 else if (aSubOp == "depthoffset"
4995 || aSubOp == "offset")
4997 Graphic3d_PolygonOffset aParams;
4998 aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None;
5001 if (anArgIter + 2 >= theArgNb)
5003 std::cout << "Syntax error: factor and units values for depth offset are missing\n";
5007 aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5008 aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5010 aSettings.SetPolygonOffset (aParams);
5012 else if (aSubOp == "positiveoffset"
5013 || aSubOp == "poffset")
5017 aSettings.SetDepthOffsetPositive();
5021 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
5024 else if (aSubOp == "negativeoffset"
5025 || aSubOp == "noffset")
5029 aSettings.SetDepthOffsetNegative();
5033 aSettings.SetPolygonOffset(Graphic3d_PolygonOffset());
5036 else if (aSubOp == "textureenv")
5038 aSettings.SetEnvironmentTexture (toEnable);
5041 aViewer->SetZLayerSettings (aLayerId, aSettings);
5045 std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n";
5053 // The interactive presentation of 2d layer item
5054 // for "vlayerline" command it provides a presentation of
5055 // line with user-defined linewidth, linetype and transparency.
5056 class V3d_LineItem : public AIS_InteractiveObject
5060 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
5063 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5064 Standard_Real X2, Standard_Real Y2,
5065 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
5066 Standard_Real theWidth = 0.5,
5067 Standard_Real theTransp = 1.0);
5071 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
5072 const Handle(Prs3d_Presentation)& thePresentation,
5073 const Standard_Integer theMode) Standard_OVERRIDE;
5075 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
5076 const Standard_Integer /*aMode*/) Standard_OVERRIDE
5081 Standard_Real myX1, myY1, myX2, myY2;
5082 Aspect_TypeOfLine myType;
5083 Standard_Real myWidth;
5086 // default constructor for line item
5087 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5088 Standard_Real X2, Standard_Real Y2,
5089 Aspect_TypeOfLine theType,
5090 Standard_Real theWidth,
5091 Standard_Real theTransp) :
5092 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
5093 myType(theType), myWidth(theWidth)
5095 SetTransparency (1-theTransp);
5099 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
5100 const Handle(Prs3d_Presentation)& thePresentation,
5101 const Standard_Integer /*theMode*/)
5103 thePresentation->Clear();
5104 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
5105 Standard_Integer aWidth, aHeight;
5106 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
5107 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
5108 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
5109 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
5110 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
5111 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
5112 aGroup->SetPrimitivesAspect (anAspect->Aspect());
5113 aGroup->AddPrimitiveArray (aPrim);
5116 //=============================================================================
5117 //function : VLayerLine
5118 //purpose : Draws line in the v3d view layer with given attributes: linetype,
5119 // : linewidth, transparency coefficient
5120 //============================================================================
5121 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5123 // get the active view
5124 Handle(V3d_View) aView = ViewerTest::CurrentView();
5127 di << "Call vinit before!\n";
5132 di << "Use: " << argv[0];
5133 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
5134 di << " linetype : { 0 | 1 | 2 | 3 } \n";
5135 di << " 0 - solid \n";
5136 di << " 1 - dashed \n";
5137 di << " 2 - dot \n";
5138 di << " 3 - dashdot\n";
5139 di << " transparency : { 0.0 - 1.0 } \n";
5140 di << " 0.0 - transparent\n";
5141 di << " 1.0 - visible \n";
5145 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5146 // get the input params
5147 Standard_Real X1 = Draw::Atof(argv[1]);
5148 Standard_Real Y1 = Draw::Atof(argv[2]);
5149 Standard_Real X2 = Draw::Atof(argv[3]);
5150 Standard_Real Y2 = Draw::Atof(argv[4]);
5152 Standard_Real aWidth = 0.5;
5153 Standard_Real aTransparency = 1.0;
5157 aWidth = Draw::Atof(argv[5]);
5159 // select appropriate line type
5160 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
5162 && !ViewerTest::ParseLineType (argv[6], aLineType))
5164 std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n";
5171 aTransparency = Draw::Atof(argv[7]);
5172 if (aTransparency < 0 || aTransparency > 1.0)
5173 aTransparency = 1.0;
5176 static Handle (V3d_LineItem) aLine;
5177 if (!aLine.IsNull())
5179 aContext->Erase (aLine, Standard_False);
5181 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
5185 aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
5186 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
5187 aLine->SetToUpdate();
5188 aContext->Display (aLine, Standard_True);
5194 //==============================================================================
5197 //==============================================================================
5199 static int VGrid (Draw_Interpretor& /*theDI*/,
5200 Standard_Integer theArgNb,
5201 const char** theArgVec)
5203 Handle(V3d_View) aView = ViewerTest::CurrentView();
5204 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5205 if (aView.IsNull() || aViewer.IsNull())
5207 std::cerr << "Error: no active view\n";
5211 Aspect_GridType aType = aViewer->GridType();
5212 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
5213 Graphic3d_Vec2d aNewOriginXY, aNewStepXY, aNewSizeXY;
5214 Standard_Real aNewRotAngle = 0.0, aNewZOffset = 0.0;
5215 bool hasOrigin = false, hasStep = false, hasRotAngle = false, hasSize = false, hasZOffset = false;
5216 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
5217 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5219 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5221 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
5225 else if (anArgIter + 1 < theArgNb
5226 && anArg == "-type")
5228 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
5229 anArgNext.LowerCase();
5230 if (anArgNext == "r"
5231 || anArgNext == "rect"
5232 || anArgNext == "rectangular")
5234 aType = Aspect_GT_Rectangular;
5236 else if (anArgNext == "c"
5237 || anArgNext == "circ"
5238 || anArgNext == "circular")
5240 aType = Aspect_GT_Circular;
5244 std::cout << "Syntax error at '" << anArgNext << "'\n";
5248 else if (anArgIter + 1 < theArgNb
5249 && anArg == "-mode")
5251 TCollection_AsciiString anArgNext (theArgVec[++anArgIter]);
5252 anArgNext.LowerCase();
5253 if (anArgNext == "l"
5254 || anArgNext == "line"
5255 || anArgNext == "lines")
5257 aMode = Aspect_GDM_Lines;
5259 else if (anArgNext == "p"
5260 || anArgNext == "point"
5261 || anArgNext == "points")
5263 aMode = Aspect_GDM_Points;
5267 std::cout << "Syntax error at '" << anArgNext << "'\n";
5271 else if (anArgIter + 2 < theArgNb
5272 && (anArg == "-origin"
5273 || anArg == "-orig"))
5276 aNewOriginXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
5277 Draw::Atof (theArgVec[anArgIter + 2]));
5280 else if (anArgIter + 2 < theArgNb
5281 && anArg == "-step")
5284 aNewStepXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
5285 Draw::Atof (theArgVec[anArgIter + 2]));
5286 if (aNewStepXY.x() <= 0.0
5287 || aNewStepXY.y() <= 0.0)
5289 std::cout << "Syntax error: wrong step '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'\n";
5294 else if (anArgIter + 1 < theArgNb
5295 && (anArg == "-angle"
5296 || anArg == "-rotangle"
5297 || anArg == "-rotationangle"))
5300 aNewRotAngle = Draw::Atof (theArgVec[++anArgIter]);
5302 else if (anArgIter + 1 < theArgNb
5303 && (anArg == "-zoffset"
5307 aNewZOffset = Draw::Atof (theArgVec[++anArgIter]);
5309 else if (anArgIter + 1 < theArgNb
5310 && anArg == "-radius")
5314 aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter]), 0.0);
5315 if (aNewStepXY.x() <= 0.0)
5317 std::cout << "Syntax error: wrong size '" << theArgVec[anArgIter] << "'\n";
5321 else if (anArgIter + 2 < theArgNb
5322 && anArg == "-size")
5325 aNewSizeXY.SetValues (Draw::Atof (theArgVec[anArgIter + 1]),
5326 Draw::Atof (theArgVec[anArgIter + 2]));
5327 if (aNewStepXY.x() <= 0.0
5328 || aNewStepXY.y() <= 0.0)
5330 std::cout << "Syntax error: wrong size '" << theArgVec[anArgIter + 1] << " " << theArgVec[anArgIter + 2] << "'\n";
5335 else if (anArg == "r"
5337 || anArg == "rectangular")
5339 aType = Aspect_GT_Rectangular;
5341 else if (anArg == "c"
5343 || anArg == "circular")
5345 aType = Aspect_GT_Circular;
5347 else if (anArg == "l"
5349 || anArg == "lines")
5351 aMode = Aspect_GDM_Lines;
5353 else if (anArg == "p"
5355 || anArg == "points")
5357 aMode = Aspect_GDM_Points;
5359 else if (anArgIter + 1 >= theArgNb
5362 aViewer->DeactivateGrid();
5367 std::cout << "Syntax error at '" << anArg << "'\n";
5372 if (aType == Aspect_GT_Rectangular)
5374 Graphic3d_Vec2d anOrigXY, aStepXY;
5375 Standard_Real aRotAngle = 0.0;
5376 aViewer->RectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle);
5379 anOrigXY = aNewOriginXY;
5383 aStepXY = aNewStepXY;
5387 aRotAngle = aNewRotAngle;
5389 aViewer->SetRectangularGridValues (anOrigXY.x(), anOrigXY.y(), aStepXY.x(), aStepXY.y(), aRotAngle);
5390 if (hasSize || hasZOffset)
5392 Graphic3d_Vec3d aSize;
5393 aViewer->RectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z());
5396 aSize.x() = aNewSizeXY.x();
5397 aSize.y() = aNewSizeXY.y();
5401 aSize.z() = aNewZOffset;
5403 aViewer->SetRectangularGridGraphicValues (aSize.x(), aSize.y(), aSize.z());
5406 else if (aType == Aspect_GT_Circular)
5408 Graphic3d_Vec2d anOrigXY;
5409 Standard_Real aRadiusStep;
5410 Standard_Integer aDivisionNumber;
5411 Standard_Real aRotAngle = 0.0;
5412 aViewer->CircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle);
5415 anOrigXY = aNewOriginXY;
5419 aRadiusStep = aNewStepXY[0];
5420 aDivisionNumber = (int )aNewStepXY[1];
5421 if (aDivisionNumber < 1)
5423 std::cout << "Syntax error: invalid division number '" << aNewStepXY[1] << "'\n";
5429 aRotAngle = aNewRotAngle;
5432 aViewer->SetCircularGridValues (anOrigXY.x(), anOrigXY.y(), aRadiusStep, aDivisionNumber, aRotAngle);
5433 if (hasSize || hasZOffset)
5435 Standard_Real aRadius = 0.0, aZOffset = 0.0;
5436 aViewer->CircularGridGraphicValues (aRadius, aZOffset);
5439 aRadius = aNewSizeXY.x();
5440 if (aNewSizeXY.y() != 0.0)
5442 std::cout << "Syntax error: circular size should be specified as radius\n";
5448 aZOffset = aNewZOffset;
5450 aViewer->SetCircularGridGraphicValues (aRadius, aZOffset);
5453 aViewer->ActivateGrid (aType, aMode);
5457 //==============================================================================
5458 //function : VPriviledgedPlane
5460 //==============================================================================
5462 static int VPriviledgedPlane (Draw_Interpretor& theDI,
5463 Standard_Integer theArgNb,
5464 const char** theArgVec)
5466 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
5468 std::cerr << "Error: wrong number of arguments! See usage:\n";
5469 theDI.PrintHelp (theArgVec[0]);
5473 // get the active viewer
5474 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5475 if (aViewer.IsNull())
5477 std::cerr << "Error: no active viewer. Please call vinit.\n";
5483 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
5484 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
5485 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
5486 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
5487 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
5488 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
5489 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
5493 Standard_Integer anArgIdx = 1;
5494 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
5495 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
5496 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
5497 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
5498 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
5499 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
5501 gp_Ax3 aPriviledgedPlane;
5502 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
5503 gp_Dir aNorm (aNormX, aNormY, aNormZ);
5506 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
5507 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
5508 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
5509 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
5510 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
5514 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
5517 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
5522 //==============================================================================
5523 //function : VConvert
5525 //==============================================================================
5527 static int VConvert (Draw_Interpretor& theDI,
5528 Standard_Integer theArgNb,
5529 const char** theArgVec)
5531 // get the active view
5532 Handle(V3d_View) aView = ViewerTest::CurrentView();
5535 std::cerr << "Error: no active view. Please call vinit.\n";
5539 enum { Model, Ray, View, Window, Grid } aMode = Model;
5541 // access coordinate arguments
5542 TColStd_SequenceOfReal aCoord;
5543 Standard_Integer anArgIdx = 1;
5544 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
5546 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5547 if (!anArg.IsRealValue())
5551 aCoord.Append (anArg.RealValue());
5554 // non-numeric argument too early
5555 if (aCoord.IsEmpty())
5557 std::cerr << "Error: wrong number of arguments! See usage:\n";
5558 theDI.PrintHelp (theArgVec[0]);
5562 // collect all other arguments and options
5563 for (; anArgIdx < theArgNb; ++anArgIdx)
5565 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5567 if (anArg == "window") aMode = Window;
5568 else if (anArg == "view") aMode = View;
5569 else if (anArg == "grid") aMode = Grid;
5570 else if (anArg == "ray") aMode = Ray;
5573 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
5574 theDI.PrintHelp (theArgVec[0]);
5579 // complete input checks
5580 if ((aCoord.Length() == 1 && theArgNb > 3) ||
5581 (aCoord.Length() == 2 && theArgNb > 4) ||
5582 (aCoord.Length() == 3 && theArgNb > 5))
5584 std::cerr << "Error: wrong number of arguments! See usage:\n";
5585 theDI.PrintHelp (theArgVec[0]);
5589 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
5590 Standard_Integer aXYp[2] = {0, 0};
5592 // convert one-dimensional coordinate
5593 if (aCoord.Length() == 1)
5597 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0;
5598 case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0;
5600 std::cerr << "Error: wrong arguments! See usage:\n";
5601 theDI.PrintHelp (theArgVec[0]);
5606 // convert 2D coordinates from projection or view reference space
5607 if (aCoord.Length() == 2)
5612 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5613 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5617 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5618 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5622 aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]);
5623 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5627 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5628 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5629 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5633 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5634 (Standard_Integer) aCoord (2),
5635 aXYZ[0], aXYZ[1], aXYZ[2],
5636 aXYZ[3], aXYZ[4], aXYZ[5]);
5637 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5641 std::cerr << "Error: wrong arguments! See usage:\n";
5642 theDI.PrintHelp (theArgVec[0]);
5647 // convert 3D coordinates from view reference space
5648 else if (aCoord.Length() == 3)
5653 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5654 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5658 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5659 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5663 std::cerr << "Error: wrong arguments! See usage:\n";
5664 theDI.PrintHelp (theArgVec[0]);
5672 //==============================================================================
5675 //==============================================================================
5677 static int VFps (Draw_Interpretor& theDI,
5678 Standard_Integer theArgNb,
5679 const char** theArgVec)
5681 // get the active view
5682 Handle(V3d_View) aView = ViewerTest::CurrentView();
5685 std::cerr << "No active view. Please call vinit.\n";
5689 Standard_Integer aFramesNb = -1;
5690 Standard_Real aDuration = -1.0;
5691 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5693 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5696 && anArgIter + 1 < theArgNb
5697 && (anArg == "-duration"
5699 || anArg == "-time"))
5701 aDuration = Draw::Atof (theArgVec[++anArgIter]);
5703 else if (aFramesNb < 0
5704 && anArg.IsIntegerValue())
5706 aFramesNb = anArg.IntegerValue();
5709 std::cerr << "Syntax error at '" << anArg << "'\n";
5715 std::cerr << "Syntax error at '" << anArg << "'\n";
5719 if (aFramesNb < 0 && aDuration < 0.0)
5724 // the time is meaningless for first call
5725 // due to async OpenGl rendering
5728 // redraw view in loop to estimate average values
5731 Standard_Integer aFrameIter = 1;
5732 for (;; ++aFrameIter)
5736 && aFrameIter >= aFramesNb)
5738 && aTimer.ElapsedTime() >= aDuration))
5745 const Standard_Real aTime = aTimer.ElapsedTime();
5746 aTimer.OSD_Chronometer::Show (aCpu);
5748 const Standard_Real aFpsAver = Standard_Real(aFrameIter) / aTime;
5749 const Standard_Real aCpuAver = aCpu / Standard_Real(aFrameIter);
5751 // return statistics
5752 theDI << "FPS: " << aFpsAver << "\n"
5753 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5755 // compute additional statistics in ray-tracing mode
5756 const Graphic3d_RenderingParams& aParams = aView->RenderingParams();
5757 if (aParams.Method == Graphic3d_RM_RAYTRACING)
5759 Graphic3d_Vec2i aWinSize (0, 0);
5760 aView->Window()->Size (aWinSize.x(), aWinSize.y());
5762 // 1 shadow ray and 1 secondary ray pew each bounce
5763 const Standard_Real aMRays = aWinSize.x() * aWinSize.y() * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
5764 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
5770 //! Auxiliary function for parsing glsl dump level argument.
5771 static Standard_Boolean parseGlslSourceFlag (Standard_CString theArg,
5772 OpenGl_ShaderProgramDumpLevel& theGlslDumpLevel)
5774 TCollection_AsciiString aTypeStr (theArg);
5775 aTypeStr.LowerCase();
5776 if (aTypeStr == "off"
5779 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
5781 else if (aTypeStr == "short")
5783 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Short;
5785 else if (aTypeStr == "full"
5788 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
5792 return Standard_False;
5794 return Standard_True;
5797 //==============================================================================
5798 //function : VGlDebug
5800 //==============================================================================
5802 static int VGlDebug (Draw_Interpretor& theDI,
5803 Standard_Integer theArgNb,
5804 const char** theArgVec)
5806 Handle(OpenGl_GraphicDriver) aDriver;
5807 Handle(V3d_View) aView = ViewerTest::CurrentView();
5808 if (!aView.IsNull())
5810 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5812 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
5813 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
5817 TCollection_AsciiString aDebActive, aSyncActive;
5824 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
5825 "GL_ARB_debug_output");
5826 aDebActive = isActive ? " (active)" : " (inactive)";
5829 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
5830 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
5834 TCollection_AsciiString aGlslCodeDebugStatus = TCollection_AsciiString()
5835 + "glslSourceCode: "
5836 + (aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Off
5838 : aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Short
5842 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
5843 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
5844 << "glslWarn: " << (aCaps->glslWarnings ? "1" : "0") << "\n"
5845 << aGlslCodeDebugStatus
5846 << "extraMsg: " << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
5850 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5852 Standard_CString anArg = theArgVec[anArgIter];
5853 TCollection_AsciiString anArgCase (anArg);
5854 anArgCase.LowerCase();
5855 Standard_Boolean toEnableDebug = Standard_True;
5856 if (anArgCase == "-glsl"
5857 || anArgCase == "-glslwarn"
5858 || anArgCase == "-glslwarns"
5859 || anArgCase == "-glslwarnings")
5861 Standard_Boolean toShowWarns = Standard_True;
5862 if (++anArgIter < theArgNb
5863 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
5867 aDefCaps->glslWarnings = toShowWarns;
5870 aCaps->glslWarnings = toShowWarns;
5873 else if (anArgCase == "-extra"
5874 || anArgCase == "-extramsg"
5875 || anArgCase == "-extramessages")
5877 Standard_Boolean toShow = Standard_True;
5878 if (++anArgIter < theArgNb
5879 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
5883 aDefCaps->suppressExtraMsg = !toShow;
5886 aCaps->suppressExtraMsg = !toShow;
5889 else if (anArgCase == "-noextra"
5890 || anArgCase == "-noextramsg"
5891 || anArgCase == "-noextramessages")
5893 Standard_Boolean toSuppress = Standard_True;
5894 if (++anArgIter < theArgNb
5895 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
5899 aDefCaps->suppressExtraMsg = toSuppress;
5902 aCaps->suppressExtraMsg = toSuppress;
5905 else if (anArgCase == "-sync")
5907 Standard_Boolean toSync = Standard_True;
5908 if (++anArgIter < theArgNb
5909 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
5913 aDefCaps->contextSyncDebug = toSync;
5916 aDefCaps->contextDebug = Standard_True;
5919 else if (anArgCase == "-glslsourcecode"
5920 || anArgCase == "-glslcode")
5922 OpenGl_ShaderProgramDumpLevel aGslsDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
5923 if (++anArgIter < theArgNb
5924 && !parseGlslSourceFlag (theArgVec[anArgIter], aGslsDumpLevel))
5928 aDefCaps->glslDumpLevel = aGslsDumpLevel;
5931 aCaps->glslDumpLevel = aGslsDumpLevel;
5934 else if (anArgCase == "-debug")
5936 if (++anArgIter < theArgNb
5937 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
5941 aDefCaps->contextDebug = toEnableDebug;
5943 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
5944 && (anArgIter + 1 == theArgNb))
5946 // simple alias to turn on almost everything
5947 aDefCaps->contextDebug = toEnableDebug;
5948 aDefCaps->contextSyncDebug = toEnableDebug;
5949 aDefCaps->glslWarnings = toEnableDebug;
5952 aDefCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
5954 aDefCaps->suppressExtraMsg = !toEnableDebug;
5957 aCaps->contextDebug = toEnableDebug;
5958 aCaps->contextSyncDebug = toEnableDebug;
5959 aCaps->glslWarnings = toEnableDebug;
5962 aCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
5964 aCaps->suppressExtraMsg = !toEnableDebug;
5969 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
5977 //==============================================================================
5980 //==============================================================================
5982 static int VVbo (Draw_Interpretor& theDI,
5983 Standard_Integer theArgNb,
5984 const char** theArgVec)
5986 const Standard_Boolean toSet = (theArgNb > 1);
5987 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
5990 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
5994 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5995 if (aContextAIS.IsNull())
5999 std::cerr << "No active view!\n";
6003 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
6004 if (!aDriver.IsNull())
6008 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
6012 aDriver->ChangeOptions().vboDisable = toUseVbo;
6019 //==============================================================================
6022 //==============================================================================
6024 static int VCaps (Draw_Interpretor& theDI,
6025 Standard_Integer theArgNb,
6026 const char** theArgVec)
6028 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
6029 Handle(OpenGl_GraphicDriver) aDriver;
6030 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6031 if (!aContext.IsNull())
6033 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
6034 aCaps = &aDriver->ChangeOptions();
6039 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
6040 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
6041 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
6042 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
6043 theDI << "PolygonMode: " << (aCaps->usePolygonMode ? "1" : "0") << "\n";
6044 theDI << "VSync: " << aCaps->swapInterval << "\n";
6045 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
6046 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
6047 theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n";
6051 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
6052 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
6054 Standard_CString anArg = theArgVec[anArgIter];
6055 TCollection_AsciiString anArgCase (anArg);
6056 anArgCase.LowerCase();
6057 if (anUpdateTool.parseRedrawMode (anArg))
6061 else if (anArgCase == "-vsync"
6062 || anArgCase == "-swapinterval")
6064 Standard_Boolean toEnable = Standard_True;
6065 if (++anArgIter < theArgNb
6066 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6070 aCaps->swapInterval = toEnable;
6072 else if (anArgCase == "-ffp")
6074 Standard_Boolean toEnable = Standard_True;
6075 if (++anArgIter < theArgNb
6076 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6080 aCaps->ffpEnable = toEnable;
6082 else if (anArgCase == "-polygonmode")
6084 Standard_Boolean toEnable = Standard_True;
6085 if (++anArgIter < theArgNb
6086 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6090 aCaps->usePolygonMode = toEnable;
6092 else if (anArgCase == "-vbo")
6094 Standard_Boolean toEnable = Standard_True;
6095 if (++anArgIter < theArgNb
6096 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6100 aCaps->vboDisable = !toEnable;
6102 else if (anArgCase == "-sprite"
6103 || anArgCase == "-sprites")
6105 Standard_Boolean toEnable = Standard_True;
6106 if (++anArgIter < theArgNb
6107 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6111 aCaps->pntSpritesDisable = !toEnable;
6113 else if (anArgCase == "-softmode")
6115 Standard_Boolean toEnable = Standard_True;
6116 if (++anArgIter < theArgNb
6117 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6121 aCaps->contextNoAccel = toEnable;
6123 else if (anArgCase == "-winbuffer"
6124 || anArgCase == "-windowbuffer"
6125 || anArgCase == "-usewinbuffer"
6126 || anArgCase == "-usewindowbuffer"
6127 || anArgCase == "-usesystembuffer")
6129 Standard_Boolean toEnable = Standard_True;
6130 if (++anArgIter < theArgNb
6131 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6135 aCaps->useSystemBuffer = toEnable;
6137 else if (anArgCase == "-accel"
6138 || anArgCase == "-acceleration")
6140 Standard_Boolean toEnable = Standard_True;
6141 if (++anArgIter < theArgNb
6142 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6146 aCaps->contextNoAccel = !toEnable;
6148 else if (anArgCase == "-compat"
6149 || anArgCase == "-compatprofile"
6150 || anArgCase == "-compatible"
6151 || anArgCase == "-compatibleprofile")
6153 Standard_Boolean toEnable = Standard_True;
6154 if (++anArgIter < theArgNb
6155 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6159 aCaps->contextCompatible = toEnable;
6160 if (!aCaps->contextCompatible)
6162 aCaps->ffpEnable = Standard_False;
6165 else if (anArgCase == "-core"
6166 || anArgCase == "-coreprofile")
6168 Standard_Boolean toEnable = Standard_True;
6169 if (++anArgIter < theArgNb
6170 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6174 aCaps->contextCompatible = !toEnable;
6175 if (!aCaps->contextCompatible)
6177 aCaps->ffpEnable = Standard_False;
6180 else if (anArgCase == "-stereo"
6181 || anArgCase == "-quadbuffer")
6183 Standard_Boolean toEnable = Standard_True;
6184 if (++anArgIter < theArgNb
6185 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6189 aCaps->contextStereo = toEnable;
6193 std::cout << "Error: unknown argument '" << anArg << "'\n";
6197 if (aCaps != &ViewerTest_myDefaultCaps)
6199 ViewerTest_myDefaultCaps = *aCaps;
6204 //==============================================================================
6205 //function : VMemGpu
6207 //==============================================================================
6209 static int VMemGpu (Draw_Interpretor& theDI,
6210 Standard_Integer theArgNb,
6211 const char** theArgVec)
6214 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
6215 if (aContextAIS.IsNull())
6217 std::cerr << "No active view. Please call vinit.\n";
6221 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
6222 if (aDriver.IsNull())
6224 std::cerr << "Graphic driver not available.\n";
6228 Standard_Size aFreeBytes = 0;
6229 TCollection_AsciiString anInfo;
6230 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
6232 std::cerr << "Information not available.\n";
6236 if (theArgNb > 1 && *theArgVec[1] == 'f')
6238 theDI << Standard_Real (aFreeBytes);
6248 // ==============================================================================
6249 // function : VReadPixel
6251 // ==============================================================================
6252 static int VReadPixel (Draw_Interpretor& theDI,
6253 Standard_Integer theArgNb,
6254 const char** theArgVec)
6256 // get the active view
6257 Handle(V3d_View) aView = ViewerTest::CurrentView();
6260 std::cerr << "No active view. Please call vinit.\n";
6263 else if (theArgNb < 3)
6265 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
6269 Image_Format aFormat = Image_Format_RGBA;
6270 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
6272 Standard_Integer aWidth, aHeight;
6273 aView->Window()->Size (aWidth, aHeight);
6274 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
6275 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
6276 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
6278 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
6282 Standard_Boolean toShowName = Standard_False;
6283 Standard_Boolean toShowHls = Standard_False;
6284 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
6286 TCollection_AsciiString aParam (theArgVec[anIter]);
6288 if (aParam == "-rgb"
6291 aFormat = Image_Format_RGB;
6292 aBufferType = Graphic3d_BT_RGB;
6294 else if (aParam == "-hls"
6297 aFormat = Image_Format_RGB;
6298 aBufferType = Graphic3d_BT_RGB;
6299 toShowHls = Standard_True;
6301 else if (aParam == "-rgbf"
6302 || aParam == "rgbf")
6304 aFormat = Image_Format_RGBF;
6305 aBufferType = Graphic3d_BT_RGB;
6307 else if (aParam == "-rgba"
6308 || aParam == "rgba")
6310 aFormat = Image_Format_RGBA;
6311 aBufferType = Graphic3d_BT_RGBA;
6313 else if (aParam == "-rgbaf"
6314 || aParam == "rgbaf")
6316 aFormat = Image_Format_RGBAF;
6317 aBufferType = Graphic3d_BT_RGBA;
6319 else if (aParam == "-depth"
6320 || aParam == "depth")
6322 aFormat = Image_Format_GrayF;
6323 aBufferType = Graphic3d_BT_Depth;
6325 else if (aParam == "-name"
6326 || aParam == "name")
6328 toShowName = Standard_True;
6332 std::cout << "Syntax error at '" << aParam << "'\n";
6336 Image_PixMap anImage;
6337 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
6339 std::cerr << "Image allocation failed\n";
6342 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
6344 std::cerr << "Image dump failed\n";
6348 // redirect possible warning messages that could have been added by ToPixMap
6349 // into the Tcl interpretor (via DefaultMessenger) to cout, so that they do not
6350 // contaminate result of the command
6351 Standard_CString aWarnLog = theDI.Result();
6352 if (aWarnLog != NULL && aWarnLog[0] != '\0')
6354 std::cout << aWarnLog << std::endl;
6358 Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY);
6361 if (aBufferType == Graphic3d_BT_RGBA)
6363 theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha();
6367 theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
6372 switch (aBufferType)
6375 case Graphic3d_BT_RGB:
6379 theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation();
6383 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue();
6387 case Graphic3d_BT_RGBA:
6389 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue() << " " << aColor.Alpha();
6392 case Graphic3d_BT_Depth:
6394 theDI << aColor.GetRGB().Red();
6403 //! Auxiliary presentation for an image plane.
6404 class ViewerTest_ImagePrs : public AIS_InteractiveObject
6407 //! Main constructor.
6408 ViewerTest_ImagePrs (const Handle(Image_PixMap)& theImage,
6409 const Standard_Real theWidth,
6410 const Standard_Real theHeight,
6411 const TCollection_AsciiString& theLabel)
6412 : myLabel (theLabel), myWidth (theWidth), myHeight(theHeight)
6416 myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost);
6418 myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
6419 const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect();
6420 Graphic3d_MaterialAspect aMat;
6421 aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC);
6422 aMat.SetAmbient (1.0);
6423 aMat.SetDiffuse (1.0);
6424 aMat.SetSpecular (1.0);
6425 aMat.SetEmissive (1.0);
6426 aMat.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
6427 aMat.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
6428 aMat.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
6429 aMat.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
6430 aMat.SetAmbientColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6431 aMat.SetDiffuseColor (Quantity_Color (1.0, 1.0, 1.0, Quantity_TOC_RGB));
6432 aMat.SetSpecularColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6433 aMat.SetEmissiveColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6434 aFillAspect->SetFrontMaterial (aMat);
6435 aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage));
6436 aFillAspect->SetTextureMapOn();
6439 Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect();
6440 aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER);
6441 aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER);
6442 myDrawer->SetTextAspect (aTextAspect);
6445 const gp_Dir aNorm (0.0, 0.0, 1.0);
6446 myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true);
6447 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0));
6448 myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0));
6449 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0));
6450 myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0));
6451 myTris->AddEdge (1);
6452 myTris->AddEdge (2);
6453 myTris->AddEdge (3);
6454 myTris->AddEdge (3);
6455 myTris->AddEdge (2);
6456 myTris->AddEdge (4);
6458 myRect = new Graphic3d_ArrayOfPolylines (4);
6459 myRect->AddVertex (myTris->Vertice (1));
6460 myRect->AddVertex (myTris->Vertice (3));
6461 myRect->AddVertex (myTris->Vertice (4));
6462 myRect->AddVertex (myTris->Vertice (2));
6466 //! Returns TRUE for accepted display modes.
6467 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; }
6469 //! Compute presentation.
6470 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& , const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) Standard_OVERRIDE
6476 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
6477 aGroup->AddPrimitiveArray (myTris);
6478 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
6479 aGroup->AddPrimitiveArray (myRect);
6480 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
6485 Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0));
6486 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
6487 aGroup->AddPrimitiveArray (myRect);
6488 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
6494 //! Compute selection.
6495 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE
6499 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5);
6500 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner);
6501 aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location());
6502 theSel->Add (aSensitive);
6507 Handle(Graphic3d_ArrayOfTriangles) myTris;
6508 Handle(Graphic3d_ArrayOfPolylines) myRect;
6509 TCollection_AsciiString myLabel;
6510 Standard_Real myWidth;
6511 Standard_Real myHeight;
6514 //==============================================================================
6515 //function : VDiffImage
6516 //purpose : The draw-command compares two images.
6517 //==============================================================================
6519 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
6523 std::cout << "Syntax error: not enough arguments.\n";
6527 Standard_Integer anArgIter = 1;
6528 TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]);
6529 TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]);
6530 TCollection_AsciiString aDiffImagePath;
6531 Standard_Real aTolColor = -1.0;
6532 Standard_Integer toBlackWhite = -1;
6533 Standard_Integer isBorderFilterOn = -1;
6534 Standard_Boolean isOldSyntax = Standard_False;
6535 TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff;
6536 for (; anArgIter < theArgNb; ++anArgIter)
6538 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6540 if (anArgIter + 1 < theArgNb
6541 && (anArg == "-toleranceofcolor"
6542 || anArg == "-tolerancecolor"
6543 || anArg == "-tolerance"
6544 || anArg == "-toler"))
6546 aTolColor = Atof (theArgVec[++anArgIter]);
6547 if (aTolColor < 0.0 || aTolColor > 1.0)
6549 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
6553 else if (anArg == "-blackwhite")
6555 Standard_Boolean toEnable = Standard_True;
6556 if (anArgIter + 1 < theArgNb
6557 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6561 toBlackWhite = toEnable ? 1 : 0;
6563 else if (anArg == "-borderfilter")
6565 Standard_Boolean toEnable = Standard_True;
6566 if (anArgIter + 1 < theArgNb
6567 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6571 isBorderFilterOn = toEnable ? 1 : 0;
6573 else if (anArg == "-exitonclose")
6575 Draw_ToExitOnCloseView = true;
6576 if (anArgIter + 1 < theArgNb
6577 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToExitOnCloseView))
6582 else if (anArg == "-closeonescape"
6583 || anArg == "-closeonesc")
6585 Draw_ToCloseViewOnEsc = true;
6586 if (anArgIter + 1 < theArgNb
6587 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToCloseViewOnEsc))
6592 else if (anArgIter + 3 < theArgNb
6593 && anArg == "-display")
6595 aViewName = theArgVec[++anArgIter];
6596 aPrsNameRef = theArgVec[++anArgIter];
6597 aPrsNameNew = theArgVec[++anArgIter];
6598 if (anArgIter + 1 < theArgNb
6599 && *theArgVec[anArgIter + 1] != '-')
6601 aPrsNameDiff = theArgVec[++anArgIter];
6604 else if (aTolColor < 0.0
6605 && anArg.IsRealValue())
6607 isOldSyntax = Standard_True;
6608 aTolColor = anArg.RealValue();
6609 if (aTolColor < 0.0 || aTolColor > 1.0)
6611 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
6615 else if (isOldSyntax
6616 && toBlackWhite == -1
6617 && (anArg == "0" || anArg == "1"))
6619 toBlackWhite = anArg == "1" ? 1 : 0;
6621 else if (isOldSyntax
6622 && isBorderFilterOn == -1
6623 && (anArg == "0" || anArg == "1"))
6625 isBorderFilterOn = anArg == "1" ? 1 : 0;
6627 else if (aDiffImagePath.IsEmpty())
6629 aDiffImagePath = theArgVec[anArgIter];
6633 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
6638 Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap();
6639 Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap();
6640 if (!anImgRef->Load (anImgPathRef))
6642 std::cout << "Error: image file '" << anImgPathRef << "' cannot be read\n";
6645 if (!anImgNew->Load (anImgPathNew))
6647 std::cout << "Error: image file '" << anImgPathNew << "' cannot be read\n";
6651 // compare the images
6652 Image_Diff aComparer;
6653 Standard_Integer aDiffColorsNb = -1;
6654 if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1))
6656 aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0);
6657 aComparer.SetBorderFilterOn (isBorderFilterOn == 1);
6658 aDiffColorsNb = aComparer.Compare();
6659 theDI << aDiffColorsNb << "\n";
6662 // save image of difference
6663 Handle(Image_AlienPixMap) aDiff;
6664 if (aDiffColorsNb > 0
6665 && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty()))
6667 aDiff = new Image_AlienPixMap();
6668 if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY()))
6670 std::cout << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY() << "\n";
6673 aComparer.SaveDiffImage (*aDiff);
6674 if (!aDiffImagePath.IsEmpty()
6675 && !aDiff->Save (aDiffImagePath))
6677 std::cout << "Error: diff image file '" << aDiffImagePath << "' cannot be written\n";
6682 if (aViewName.IsEmpty())
6687 ViewerTest_Names aViewNames (aViewName);
6688 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
6690 TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName();
6691 theDI.Eval (aCommand.ToCString());
6694 Standard_Integer aPxLeft = 0;
6695 Standard_Integer aPxTop = 0;
6696 Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2);
6697 Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty()
6698 ? int(anImgRef->SizeY() * 2)
6699 : int(anImgRef->SizeY());
6700 TCollection_AsciiString aDisplayName;
6701 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aWinSizeX, aWinSizeY,
6702 aViewName, aDisplayName);
6704 Standard_Real aRatio = anImgRef->Ratio();
6705 Standard_Real aSizeX = 1.0;
6706 Standard_Real aSizeY = aSizeX / aRatio;
6708 OSD_Path aPath (anImgPathRef);
6709 TCollection_AsciiString aLabelRef;
6710 if (!aPath.Name().IsEmpty())
6712 aLabelRef = aPath.Name() + aPath.Extension();
6714 aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY());
6716 Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef);
6718 aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0));
6719 anImgRefPrs->SetLocalTransformation (aTrsfRef);
6720 ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true);
6723 OSD_Path aPath (anImgPathNew);
6724 TCollection_AsciiString aLabelNew;
6725 if (!aPath.Name().IsEmpty())
6727 aLabelNew = aPath.Name() + aPath.Extension();
6729 aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY());
6731 Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew);
6733 aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0));
6734 anImgNewPrs->SetLocalTransformation (aTrsfRef);
6735 ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true);
6737 Handle(ViewerTest_ImagePrs) anImgDiffPrs;
6738 if (!aDiff.IsNull())
6740 anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels");
6742 aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0));
6743 anImgDiffPrs->SetLocalTransformation (aTrsfDiff);
6745 if (!aPrsNameDiff.IsEmpty())
6747 ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true);
6749 ViewerTest::CurrentView()->SetProj (V3d_Zpos);
6750 ViewerTest::CurrentView()->FitAll();
6754 //=======================================================================
6755 //function : VSelect
6756 //purpose : Emulates different types of selection by mouse:
6757 // 1) single click selection
6758 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
6759 // 3) selection with polygon having corners at
6760 // pixel positions (x1,y1),...,(xn,yn)
6761 // 4) any of these selections with shift button pressed
6762 //=======================================================================
6763 static Standard_Integer VSelect (Draw_Interpretor& di,
6764 Standard_Integer argc,
6769 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]\n";
6773 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
6774 if(myAIScontext.IsNull())
6776 di << "use 'vinit' command before " << argv[0] << "\n";
6780 const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1));
6781 Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1;
6782 TCollection_AsciiString anArg;
6783 anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2];
6785 if (anArg == "-allowoverlap")
6787 Standard_Boolean isValidated = isShiftSelection ? argc == 8
6791 di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection";
6795 Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
6796 myAIScontext->MainSelector()->AllowOverlapDetection (isToAllow != 0);
6800 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
6801 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
6804 if(isShiftSelection)
6805 aCurrentEventManager->ShiftSelect();
6807 aCurrentEventManager->Select();
6809 else if(aCoordsNb == 4)
6811 if(isShiftSelection)
6812 aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
6814 aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
6818 TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2);
6820 for(Standard_Integer i=1;i<=aCoordsNb / 2;++i)
6821 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
6823 if(isShiftSelection)
6824 aCurrentEventManager->ShiftSelect(aPolyline);
6826 aCurrentEventManager->Select(aPolyline);
6831 //=======================================================================
6832 //function : VMoveTo
6833 //purpose : Emulates cursor movement to defined pixel position
6834 //=======================================================================
6835 static Standard_Integer VMoveTo (Draw_Interpretor& theDI,
6836 Standard_Integer theNbArgs,
6837 const char** theArgVec)
6839 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
6840 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
6841 if (aContext.IsNull())
6843 std::cout << "Error: no active View\n";
6847 Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast());
6848 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
6850 TCollection_AsciiString anArgStr (theArgVec[anArgIter]);
6851 anArgStr.LowerCase();
6852 if (anArgStr == "-reset"
6853 || anArgStr == "-clear")
6855 if (anArgIter + 1 < theNbArgs)
6857 std::cout << "Syntax error at '" << theArgVec[anArgIter + 1] << "'\n";
6861 const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive()
6862 && aContext->CurrentViewer()->GridEcho();
6865 aContext->CurrentViewer()->HideGridEcho (aView);
6867 if (aContext->ClearDetected() || toEchoGrid)
6869 aContext->CurrentViewer()->RedrawImmediate();
6873 else if (aMousePos.x() == IntegerLast()
6874 && anArgStr.IsIntegerValue())
6876 aMousePos.x() = anArgStr.IntegerValue();
6878 else if (aMousePos.y() == IntegerLast()
6879 && anArgStr.IsIntegerValue())
6881 aMousePos.y() = anArgStr.IntegerValue();
6885 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
6890 if (aMousePos.x() == IntegerLast()
6891 || aMousePos.y() == IntegerLast())
6893 std::cout << "Syntax error: wrong number of arguments\n";
6897 ViewerTest::CurrentEventManager()->MoveTo (aMousePos.x(), aMousePos.y());
6898 gp_Pnt aTopPnt (RealLast(), RealLast(), RealLast());
6899 const Handle(SelectMgr_EntityOwner)& aDetOwner = aContext->DetectedOwner();
6900 for (Standard_Integer aDetIter = 1; aDetIter <= aContext->MainSelector()->NbPicked(); ++aDetIter)
6902 if (aContext->MainSelector()->Picked (aDetIter) == aDetOwner)
6904 aTopPnt = aContext->MainSelector()->PickedPoint (aDetIter);
6908 theDI << aTopPnt.X() << " " << aTopPnt.Y() << " " << aTopPnt.Z();
6914 //! Global map storing all animations registered in ViewerTest.
6915 static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap;
6917 //! The animation calling the Draw Harness command.
6918 class ViewerTest_AnimationProc : public AIS_Animation
6922 //! Main constructor.
6923 ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName,
6924 Draw_Interpretor* theDI,
6925 const TCollection_AsciiString& theCommand)
6926 : AIS_Animation (theAnimationName),
6928 myCommand (theCommand)
6935 //! Evaluate the command.
6936 virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE
6938 TCollection_AsciiString aCmd = myCommand;
6939 replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts));
6940 replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts));
6941 replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts));
6942 replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized));
6943 replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized));
6944 myDrawInter->Eval (aCmd.ToCString());
6947 //! Find the keyword in the command and replace it with value.
6948 //! @return the position of the keyword to pass value
6949 void replace (TCollection_AsciiString& theCmd,
6950 const TCollection_AsciiString& theKey,
6951 const TCollection_AsciiString& theVal)
6953 TCollection_AsciiString aCmd (theCmd);
6955 const Standard_Integer aPos = aCmd.Search (theKey);
6961 TCollection_AsciiString aPart1, aPart2;
6962 Standard_Integer aPart1To = aPos - 1;
6964 && aPart1To <= theCmd.Length())
6966 aPart1 = theCmd.SubString (1, aPart1To);
6969 Standard_Integer aPart2From = aPos + theKey.Length();
6971 && aPart2From <= theCmd.Length())
6973 aPart2 = theCmd.SubString (aPart2From, theCmd.Length());
6976 theCmd = aPart1 + theVal + aPart2;
6981 Draw_Interpretor* myDrawInter;
6982 TCollection_AsciiString myCommand;
6986 //! Replace the animation with the new one.
6987 static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation,
6988 Handle(AIS_Animation)& theAnimation,
6989 const Handle(AIS_Animation)& theAnimationNew)
6991 theAnimationNew->CopyFrom (theAnimation);
6992 if (!theParentAnimation.IsNull())
6994 theParentAnimation->Replace (theAnimation, theAnimationNew);
6998 ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name());
6999 ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew);
7001 theAnimation = theAnimationNew;
7004 //! Parse the point.
7005 static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
7007 const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
7008 if (!anXYZ[0].IsRealValue()
7009 || !anXYZ[1].IsRealValue()
7010 || !anXYZ[2].IsRealValue())
7012 return Standard_False;
7015 thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue());
7016 return Standard_True;
7019 //! Parse the quaternion.
7020 static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
7022 const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
7023 if (!anXYZW[0].IsRealValue()
7024 || !anXYZW[1].IsRealValue()
7025 || !anXYZW[2].IsRealValue()
7026 || !anXYZW[3].IsRealValue())
7028 return Standard_False;
7031 theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue());
7032 return Standard_True;
7035 //! Auxiliary class for flipping image upside-down.
7040 //! Empty constructor.
7041 ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {}
7043 //! Perform flipping.
7044 Standard_Boolean FlipY (Image_PixMap& theImage)
7046 if (theImage.IsEmpty()
7047 || theImage.SizeX() == 0
7048 || theImage.SizeY() == 0)
7050 return Standard_False;
7053 const Standard_Size aRowSize = theImage.SizeRowBytes();
7054 if (myTmp.Size() < aRowSize
7055 && !myTmp.Allocate (aRowSize))
7057 return Standard_False;
7060 // for odd height middle row should be left as is
7061 Standard_Size aNbRowsHalf = theImage.SizeY() / 2;
7062 for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB)
7064 Standard_Byte* aTop = theImage.ChangeRow (aRowT);
7065 Standard_Byte* aBot = theImage.ChangeRow (aRowB);
7066 memcpy (myTmp.ChangeData(), aTop, aRowSize);
7067 memcpy (aTop, aBot, aRowSize);
7068 memcpy (aBot, myTmp.Data(), aRowSize);
7070 return Standard_True;
7074 NCollection_Buffer myTmp;
7079 //=================================================================================================
7080 //function : VViewParams
7081 //purpose : Gets or sets AIS View characteristics
7082 //=================================================================================================
7083 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7085 Handle(V3d_View) aView = ViewerTest::CurrentView();
7088 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
7092 Standard_Boolean toSetProj = Standard_False;
7093 Standard_Boolean toSetUp = Standard_False;
7094 Standard_Boolean toSetAt = Standard_False;
7095 Standard_Boolean toSetEye = Standard_False;
7096 Standard_Boolean toSetScale = Standard_False;
7097 Standard_Boolean toSetSize = Standard_False;
7098 Standard_Boolean toSetCenter2d = Standard_False;
7099 Standard_Real aViewScale = aView->Scale();
7100 Standard_Real aViewSize = 1.0;
7101 Graphic3d_Vec2i aCenter2d;
7102 gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
7103 aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3));
7104 aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
7105 aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
7106 aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
7109 // print all of the available view parameters
7113 "Proj: %12g %12g %12g\n"
7114 "Up: %12g %12g %12g\n"
7115 "At: %12g %12g %12g\n"
7116 "Eye: %12g %12g %12g\n",
7118 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
7119 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
7120 aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
7121 aViewEye.X(), aViewEye.Y(), aViewEye.Z());
7126 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7127 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7129 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7131 if (anUpdateTool.parseRedrawMode (anArg))
7135 else if (anArg == "-cmd"
7136 || anArg == "-command"
7137 || anArg == "-args")
7146 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
7147 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
7148 aViewAt.X(), aViewAt.Y(), aViewAt.Z());
7151 else if (anArg == "-scale"
7152 || anArg == "-size")
7154 if (anArgIter + 1 < theArgsNb
7155 && *theArgVec[anArgIter + 1] != '-')
7157 const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
7158 if (aValueArg.IsRealValue())
7161 if (anArg == "-scale")
7163 toSetScale = Standard_True;
7164 aViewScale = aValueArg.RealValue();
7166 else if (anArg == "-size")
7168 toSetSize = Standard_True;
7169 aViewSize = aValueArg.RealValue();
7174 if (anArg == "-scale")
7176 theDi << "Scale: " << aView->Scale() << "\n";
7178 else if (anArg == "-size")
7180 Graphic3d_Vec2d aSizeXY;
7181 aView->Size (aSizeXY.x(), aSizeXY.y());
7182 theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n";
7185 else if (anArg == "-eye"
7188 || anArg == "-proj")
7190 if (anArgIter + 3 < theArgsNb)
7193 if (parseXYZ (theArgVec + anArgIter + 1, anXYZ))
7196 if (anArg == "-eye")
7198 toSetEye = Standard_True;
7201 else if (anArg == "-at")
7203 toSetAt = Standard_True;
7206 else if (anArg == "-up")
7208 toSetUp = Standard_True;
7211 else if (anArg == "-proj")
7213 toSetProj = Standard_True;
7220 if (anArg == "-eye")
7222 theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n";
7224 else if (anArg == "-at")
7226 theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n";
7228 else if (anArg == "-up")
7230 theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n";
7232 else if (anArg == "-proj")
7234 theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n";
7237 else if (anArg == "-center")
7239 if (anArgIter + 2 < theArgsNb)
7241 const TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
7242 const TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
7243 if (anX.IsIntegerValue()
7244 && anY.IsIntegerValue())
7246 toSetCenter2d = Standard_True;
7247 aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue());
7253 std::cout << "Syntax error at '" << anArg << "'\n";
7258 // change view parameters in proper order
7261 aView->SetScale (aViewScale);
7265 aView->SetSize (aViewSize);
7269 aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z());
7273 aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z());
7277 aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z());
7281 aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z());
7285 aView->SetCenter (aCenter2d.x(), aCenter2d.y());
7291 //==============================================================================
7292 //function : V2DMode
7294 //==============================================================================
7295 static Standard_Integer V2DMode (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec)
7297 bool is2dMode = true;
7298 Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView());
7299 if (aV3dView.IsNull())
7301 std::cout << "Error: no active view.\n";
7304 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
7306 const TCollection_AsciiString anArg = theArgVec[anArgIt];
7307 TCollection_AsciiString anArgCase = anArg;
7308 anArgCase.LowerCase();
7309 if (anArgIt + 1 < theArgsNb
7310 && anArgCase == "-name")
7312 ViewerTest_Names aViewNames (theArgVec[++anArgIt]);
7313 TCollection_AsciiString aViewName = aViewNames.GetViewName();
7314 if (!ViewerTest_myViews.IsBound1 (aViewName))
7316 std::cout << "Syntax error: unknown view '" << theArgVec[anArgIt - 1] << "'.\n";
7319 aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest_myViews.Find1 (aViewName));
7321 else if (anArgCase == "-mode")
7323 if (anArgIt + 1 < theArgsNb
7324 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], is2dMode))
7329 else if (ViewerTest::ParseOnOff (theArgVec[anArgIt], is2dMode))
7335 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
7340 aV3dView->SetView2DMode (is2dMode);
7344 //==============================================================================
7345 //function : VAnimation
7347 //==============================================================================
7348 static Standard_Integer VAnimation (Draw_Interpretor& theDI,
7349 Standard_Integer theArgNb,
7350 const char** theArgVec)
7352 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
7355 for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator
7356 anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next())
7358 theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n";
7364 std::cout << "Error: no active view\n";
7368 Standard_Integer anArgIter = 1;
7369 TCollection_AsciiString aNameArg (theArgVec[anArgIter++]);
7370 if (aNameArg.IsEmpty())
7372 std::cout << "Syntax error: animation name is not defined.\n";
7376 TCollection_AsciiString aNameArgLower = aNameArg;
7377 aNameArgLower.LowerCase();
7378 if (aNameArgLower == "-reset"
7379 || aNameArgLower == "-clear")
7381 ViewerTest_AnimationTimelineMap.Clear();
7384 else if (aNameArg.Value (1) == '-')
7386 std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n";
7390 const char* aNameSplitter = "/";
7391 Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter);
7392 if (aSplitPos == -1)
7394 aNameSplitter = ".";
7395 aSplitPos = aNameArg.Search (aNameSplitter);
7398 // find existing or create a new animation by specified name within syntax "parent.child".
7399 Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation;
7400 for (; !aNameArg.IsEmpty();)
7402 TCollection_AsciiString aNameParent;
7403 if (aSplitPos != -1)
7405 if (aSplitPos == aNameArg.Length())
7407 std::cout << "Syntax error: animation name is not defined.\n";
7411 aNameParent = aNameArg.SubString ( 1, aSplitPos - 1);
7412 aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length());
7414 aSplitPos = aNameArg.Search (aNameSplitter);
7418 aNameParent = aNameArg;
7422 if (anAnimation.IsNull())
7424 if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation))
7426 anAnimation = new AIS_Animation (aNameParent);
7427 ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation);
7429 aRootAnimation = anAnimation;
7433 aParentAnimation = anAnimation;
7434 anAnimation = aParentAnimation->Find (aNameParent);
7435 if (anAnimation.IsNull())
7437 anAnimation = new AIS_Animation (aNameParent);
7438 aParentAnimation->Add (anAnimation);
7443 if (anArgIter >= theArgNb)
7445 // just print the list of children
7446 for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next())
7448 theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n";
7453 // animation parameters
7454 Standard_Boolean toPlay = Standard_False;
7455 Standard_Real aPlaySpeed = 1.0;
7456 Standard_Real aPlayStartTime = anAnimation->StartPts();
7457 Standard_Real aPlayDuration = anAnimation->Duration();
7458 Standard_Boolean isFreeCamera = Standard_False;
7459 Standard_Boolean isLockLoop = Standard_False;
7461 // video recording parameters
7462 TCollection_AsciiString aRecFile;
7463 Image_VideoParams aRecParams;
7465 Handle(V3d_View) aView = ViewerTest::CurrentView();
7466 for (; anArgIter < theArgNb; ++anArgIter)
7468 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7471 if (anArg == "-reset"
7472 || anArg == "-clear")
7474 anAnimation->Clear();
7476 else if (anArg == "-remove"
7478 || anArg == "-delete")
7480 if (!aParentAnimation.IsNull())
7482 ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name());
7486 aParentAnimation->Remove (anAnimation);
7490 else if (anArg == "-play")
7492 toPlay = Standard_True;
7493 if (++anArgIter < theArgNb)
7495 if (*theArgVec[anArgIter] == '-')
7500 aPlayStartTime = Draw::Atof (theArgVec[anArgIter]);
7502 if (++anArgIter < theArgNb)
7504 if (*theArgVec[anArgIter] == '-')
7509 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
7513 else if (anArg == "-resume")
7515 toPlay = Standard_True;
7516 aPlayStartTime = anAnimation->ElapsedTime();
7517 if (++anArgIter < theArgNb)
7519 if (*theArgVec[anArgIter] == '-')
7525 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
7528 else if (anArg == "-playspeed"
7529 || anArg == "-speed")
7531 if (++anArgIter >= theArgNb)
7533 std::cout << "Syntax error at " << anArg << ".\n";
7536 aPlaySpeed = Draw::Atof (theArgVec[anArgIter]);
7538 else if (anArg == "-lock"
7539 || anArg == "-lockloop"
7540 || anArg == "-playlockloop")
7542 isLockLoop = Standard_True;
7544 else if (anArg == "-freecamera"
7545 || anArg == "-playfreecamera"
7546 || anArg == "-freelook")
7548 isFreeCamera = Standard_True;
7550 // video recodring options
7551 else if (anArg == "-rec"
7552 || anArg == "-record")
7554 if (++anArgIter >= theArgNb)
7556 std::cout << "Syntax error at " << anArg << ".\n";
7560 aRecFile = theArgVec[anArgIter];
7561 if (aRecParams.FpsNum <= 0)
7563 aRecParams.FpsNum = 24;
7566 if (anArgIter + 2 < theArgNb
7567 && *theArgVec[anArgIter + 1] != '-'
7568 && *theArgVec[anArgIter + 2] != '-')
7570 TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]);
7571 TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]);
7572 if (aWidthArg .IsIntegerValue()
7573 && aHeightArg.IsIntegerValue())
7575 aRecParams.Width = aWidthArg .IntegerValue();
7576 aRecParams.Height = aHeightArg.IntegerValue();
7581 else if (anArg == "-fps")
7583 if (++anArgIter >= theArgNb)
7585 std::cout << "Syntax error at " << anArg << ".\n";
7589 TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
7590 Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
7591 if (aSplitIndex == 0)
7593 aRecParams.FpsNum = aFpsArg.IntegerValue();
7597 const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
7598 aFpsArg.Split (aFpsArg.Length() - 1);
7599 const TCollection_AsciiString aNumStr = aFpsArg;
7600 aRecParams.FpsNum = aNumStr.IntegerValue();
7601 aRecParams.FpsDen = aDenStr.IntegerValue();
7602 if (aRecParams.FpsDen < 1)
7604 std::cout << "Syntax error at " << anArg << ".\n";
7609 else if (anArg == "-format")
7611 if (++anArgIter >= theArgNb)
7613 std::cout << "Syntax error at " << anArg << ".\n";
7616 aRecParams.Format = theArgVec[anArgIter];
7618 else if (anArg == "-pix_fmt"
7619 || anArg == "-pixfmt"
7620 || anArg == "-pixelformat")
7622 if (++anArgIter >= theArgNb)
7624 std::cout << "Syntax error at " << anArg << ".\n";
7627 aRecParams.PixelFormat = theArgVec[anArgIter];
7629 else if (anArg == "-codec"
7630 || anArg == "-vcodec"
7631 || anArg == "-videocodec")
7633 if (++anArgIter >= theArgNb)
7635 std::cout << "Syntax error at " << anArg << ".\n";
7638 aRecParams.VideoCodec = theArgVec[anArgIter];
7640 else if (anArg == "-crf"
7641 || anArg == "-preset"
7644 const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length());
7645 if (++anArgIter >= theArgNb)
7647 std::cout << "Syntax error at " << anArg << ".\n";
7651 aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]);
7653 // animation definition options
7654 else if (anArg == "-start"
7655 || anArg == "-starttime"
7656 || anArg == "-startpts")
7658 if (++anArgIter >= theArgNb)
7660 std::cout << "Syntax error at " << anArg << ".\n";
7664 anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter]));
7665 aRootAnimation->UpdateTotalDuration();
7667 else if (anArg == "-end"
7668 || anArg == "-endtime"
7669 || anArg == "-endpts")
7671 if (++anArgIter >= theArgNb)
7673 std::cout << "Syntax error at " << anArg << ".\n";
7677 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts());
7678 aRootAnimation->UpdateTotalDuration();
7680 else if (anArg == "-dur"
7681 || anArg == "-duration")
7683 if (++anArgIter >= theArgNb)
7685 std::cout << "Syntax error at " << anArg << ".\n";
7689 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]));
7690 aRootAnimation->UpdateTotalDuration();
7692 else if (anArg == "-command"
7694 || anArg == "-invoke"
7696 || anArg == "-proc")
7698 if (++anArgIter >= theArgNb)
7700 std::cout << "Syntax error at " << anArg << ".\n";
7704 Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]);
7705 replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation);
7707 else if (anArg == "-objecttrsf"
7708 || anArg == "-objectransformation"
7709 || anArg == "-objtransformation"
7710 || anArg == "-objtrsf"
7711 || anArg == "-object"
7714 if (++anArgIter >= theArgNb)
7716 std::cout << "Syntax error at " << anArg << ".\n";
7720 TCollection_AsciiString anObjName (theArgVec[anArgIter]);
7721 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS();
7722 Handle(AIS_InteractiveObject) anObject;
7723 if (!aMapOfAIS.Find2 (anObjName, anObject))
7725 std::cout << "Syntax error: wrong object name at " << anArg << "\n";
7729 gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() };
7730 gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() };
7731 gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
7732 Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
7733 Standard_Boolean isTrsfSet = Standard_False;
7734 Standard_Integer aTrsfArgIter = anArgIter + 1;
7735 for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
7737 TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]);
7738 aTrsfArg.LowerCase();
7739 const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1;
7740 if (aTrsfArg.StartsWith ("-rotation")
7741 || aTrsfArg.StartsWith ("-rot"))
7743 isTrsfSet = Standard_True;
7744 if (aTrsfArgIter + 4 >= theArgNb
7745 || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex]))
7747 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7752 else if (aTrsfArg.StartsWith ("-location")
7753 || aTrsfArg.StartsWith ("-loc"))
7755 isTrsfSet = Standard_True;
7756 if (aTrsfArgIter + 3 >= theArgNb
7757 || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex]))
7759 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7764 else if (aTrsfArg.StartsWith ("-scale"))
7766 isTrsfSet = Standard_True;
7767 if (++aTrsfArgIter >= theArgNb)
7769 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7773 const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
7774 if (!aScaleStr.IsRealValue())
7776 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7779 aScales[anIndex] = aScaleStr.RealValue();
7783 anArgIter = aTrsfArgIter - 1;
7789 std::cout << "Syntax error at " << anArg << ".\n";
7792 else if (aTrsfArgIter >= theArgNb)
7794 anArgIter = theArgNb;
7797 aTrsfs[0].SetRotation (aRotQuats[0]);
7798 aTrsfs[1].SetRotation (aRotQuats[1]);
7799 aTrsfs[0].SetTranslationPart (aLocPnts[0]);
7800 aTrsfs[1].SetTranslationPart (aLocPnts[1]);
7801 aTrsfs[0].SetScaleFactor (aScales[0]);
7802 aTrsfs[1].SetScaleFactor (aScales[1]);
7804 Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
7805 replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
7807 else if (anArg == "-viewtrsf"
7808 || anArg == "-view")
7810 Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation);
7811 if (aCamAnimation.IsNull())
7813 aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView);
7814 replaceAnimation (aParentAnimation, anAnimation, aCamAnimation);
7817 Handle(Graphic3d_Camera) aCams[2] =
7819 new Graphic3d_Camera (aCamAnimation->View()->Camera()),
7820 new Graphic3d_Camera (aCamAnimation->View()->Camera())
7823 Standard_Boolean isTrsfSet = Standard_False;
7824 Standard_Integer aViewArgIter = anArgIter + 1;
7825 for (; aViewArgIter < theArgNb; ++aViewArgIter)
7827 TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]);
7828 aViewArg.LowerCase();
7829 const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1;
7830 if (aViewArg.StartsWith ("-scale"))
7832 isTrsfSet = Standard_True;
7833 if (++aViewArgIter >= theArgNb)
7835 std::cout << "Syntax error at " << anArg << ".\n";
7839 const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
7840 if (!aScaleStr.IsRealValue())
7842 std::cout << "Syntax error at " << aViewArg << ".\n";
7845 Standard_Real aScale = aScaleStr.RealValue();
7846 aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale;
7847 aCams[anIndex]->SetScale (aScale);
7849 else if (aViewArg.StartsWith ("-eye")
7850 || aViewArg.StartsWith ("-center")
7851 || aViewArg.StartsWith ("-at")
7852 || aViewArg.StartsWith ("-up"))
7854 isTrsfSet = Standard_True;
7856 if (aViewArgIter + 3 >= theArgNb
7857 || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ))
7859 std::cout << "Syntax error at " << aViewArg << ".\n";
7864 if (aViewArg.StartsWith ("-eye"))
7866 aCams[anIndex]->SetEye (anXYZ);
7868 else if (aViewArg.StartsWith ("-center")
7869 || aViewArg.StartsWith ("-at"))
7871 aCams[anIndex]->SetCenter (anXYZ);
7873 else if (aViewArg.StartsWith ("-up"))
7875 aCams[anIndex]->SetUp (anXYZ);
7880 anArgIter = aViewArgIter - 1;
7886 std::cout << "Syntax error at " << anArg << ".\n";
7889 else if (aViewArgIter >= theArgNb)
7891 anArgIter = theArgNb;
7894 aCamAnimation->SetCameraStart(aCams[0]);
7895 aCamAnimation->SetCameraEnd (aCams[1]);
7899 std::cout << "Syntax error at " << anArg << ".\n";
7904 if (!toPlay && aRecFile.IsEmpty())
7909 // Start animation timeline and process frame updating.
7910 TheIsAnimating = Standard_True;
7911 const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
7912 Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera());
7913 anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
7916 aView->Camera()->Copy (aCameraBack);
7919 const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
7920 if (aRecParams.FpsNum <= 0)
7922 while (!anAnimation->IsStopped())
7924 aCameraBack->Copy (aView->Camera());
7925 const Standard_Real aPts = anAnimation->UpdateTimer();
7928 aView->Camera()->Copy (aCameraBack);
7931 if (aPts >= anUpperPts)
7933 anAnimation->Pause();
7937 if (aView->IsInvalidated())
7943 aView->RedrawImmediate();
7948 // handle user events
7949 theDI.Eval ("after 1 set waiter 1");
7950 theDI.Eval ("vwait waiter");
7952 if (!TheIsAnimating)
7954 anAnimation->Pause();
7960 if (aView->IsInvalidated())
7966 aView->RedrawImmediate();
7971 OSD_Timer aPerfTimer;
7974 Handle(Image_VideoRecorder) aRecorder;
7975 ImageFlipper aFlipper;
7976 Handle(Draw_ProgressIndicator) aProgress;
7977 if (!aRecFile.IsEmpty())
7979 if (aRecParams.Width <= 0
7980 || aRecParams.Height <= 0)
7982 aView->Window()->Size (aRecParams.Width, aRecParams.Height);
7985 aRecorder = new Image_VideoRecorder();
7986 if (!aRecorder->Open (aRecFile.ToCString(), aRecParams))
7988 std::cout << "Error: failed to open video file for recording\n";
7992 aProgress = new Draw_ProgressIndicator (theDI, 1);
7995 // Manage frame-rated animation here
7996 Standard_Real aPts = aPlayStartTime;
7997 int64_t aNbFrames = 0;
7998 Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1);
7999 Standard_Integer aSecondsProgress = 0;
8000 for (; aPts <= anUpperPts && aPSentry.More();)
8002 const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames));
8003 aPts = aPlayStartTime + aRecPts;
8005 if (!anAnimation->Update (aPts))
8010 if (!aRecorder.IsNull())
8012 V3d_ImageDumpOptions aDumpParams;
8013 aDumpParams.Width = aRecParams.Width;
8014 aDumpParams.Height = aRecParams.Height;
8015 aDumpParams.BufferType = Graphic3d_BT_RGBA;
8016 aDumpParams.StereoOptions = V3d_SDO_MONO;
8017 aDumpParams.ToAdjustAspect = Standard_True;
8018 if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams))
8020 std::cout << "Error: view dump is failed!\n";
8023 aFlipper.FlipY (aRecorder->ChangeFrame());
8024 if (!aRecorder->PushFrame())
8034 while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed))
8042 anAnimation->Stop();
8043 const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
8044 theDI << "Average FPS: " << aRecFps << "\n"
8045 << "Nb. Frames: " << Standard_Real(aNbFrames);
8050 aView->SetImmediateUpdate (wasImmediateUpdate);
8051 TheIsAnimating = Standard_False;
8056 //=======================================================================
8057 //function : VChangeSelected
8058 //purpose : Adds the shape to selection or remove one from it
8059 //=======================================================================
8060 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
8061 Standard_Integer argc,
8066 di<<"Usage : " << argv[0] << " shape \n";
8070 TCollection_AsciiString aName(argv[1]);
8071 Handle(AIS_InteractiveObject) anAISObject;
8072 if (!GetMapOfAIS().Find2 (aName, anAISObject)
8073 || anAISObject.IsNull())
8075 di<<"Use 'vdisplay' before";
8079 ViewerTest::GetAISContext()->AddOrRemoveSelected(anAISObject, Standard_True);
8083 //=======================================================================
8084 //function : VNbSelected
8085 //purpose : Returns number of selected objects
8086 //=======================================================================
8087 static Standard_Integer VNbSelected (Draw_Interpretor& di,
8088 Standard_Integer argc,
8093 di << "Usage : " << argv[0] << "\n";
8096 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8097 if(aContext.IsNull())
8099 di << "use 'vinit' command before " << argv[0] << "\n";
8102 di << aContext->NbSelected() << "\n";
8106 //=======================================================================
8107 //function : VPurgeDisplay
8108 //purpose : Switches altialiasing on or off
8109 //=======================================================================
8110 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
8111 Standard_Integer argc,
8116 di << "Usage : " << argv[0] << "\n";
8119 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8120 if (aContext.IsNull())
8122 di << "use 'vinit' command before " << argv[0] << "\n";
8126 di << aContext->PurgeDisplay() << "\n";
8130 //=======================================================================
8131 //function : VSetViewSize
8133 //=======================================================================
8134 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
8135 Standard_Integer argc,
8138 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8139 if(aContext.IsNull())
8141 di << "use 'vinit' command before " << argv[0] << "\n";
8146 di<<"Usage : " << argv[0] << " Size\n";
8149 Standard_Real aSize = Draw::Atof (argv[1]);
8152 di<<"Bad Size value : " << aSize << "\n";
8156 Handle(V3d_View) aView = ViewerTest::CurrentView();
8157 aView->SetSize(aSize);
8161 //=======================================================================
8162 //function : VMoveView
8164 //=======================================================================
8165 static Standard_Integer VMoveView (Draw_Interpretor& di,
8166 Standard_Integer argc,
8169 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8170 if(aContext.IsNull())
8172 di << "use 'vinit' command before " << argv[0] << "\n";
8175 if(argc < 4 || argc > 5)
8177 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
8180 Standard_Real Dx = Draw::Atof (argv[1]);
8181 Standard_Real Dy = Draw::Atof (argv[2]);
8182 Standard_Real Dz = Draw::Atof (argv[3]);
8183 Standard_Boolean aStart = Standard_True;
8186 aStart = (Draw::Atoi (argv[4]) > 0);
8189 Handle(V3d_View) aView = ViewerTest::CurrentView();
8190 aView->Move(Dx,Dy,Dz,aStart);
8194 //=======================================================================
8195 //function : VTranslateView
8197 //=======================================================================
8198 static Standard_Integer VTranslateView (Draw_Interpretor& di,
8199 Standard_Integer argc,
8202 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8203 if(aContext.IsNull())
8205 di << "use 'vinit' command before " << argv[0] << "\n";
8208 if(argc < 4 || argc > 5)
8210 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
8213 Standard_Real Dx = Draw::Atof (argv[1]);
8214 Standard_Real Dy = Draw::Atof (argv[2]);
8215 Standard_Real Dz = Draw::Atof (argv[3]);
8216 Standard_Boolean aStart = Standard_True;
8219 aStart = (Draw::Atoi (argv[4]) > 0);
8222 Handle(V3d_View) aView = ViewerTest::CurrentView();
8223 aView->Translate(Dx,Dy,Dz,aStart);
8227 //=======================================================================
8228 //function : VTurnView
8230 //=======================================================================
8231 static Standard_Integer VTurnView (Draw_Interpretor& di,
8232 Standard_Integer argc,
8235 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8236 if(aContext.IsNull()) {
8237 di << "use 'vinit' command before " << argv[0] << "\n";
8240 if(argc < 4 || argc > 5){
8241 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
8244 Standard_Real Ax = Draw::Atof (argv[1]);
8245 Standard_Real Ay = Draw::Atof (argv[2]);
8246 Standard_Real Az = Draw::Atof (argv[3]);
8247 Standard_Boolean aStart = Standard_True;
8250 aStart = (Draw::Atoi (argv[4]) > 0);
8253 Handle(V3d_View) aView = ViewerTest::CurrentView();
8254 aView->Turn(Ax,Ay,Az,aStart);
8258 //==============================================================================
8259 //function : VTextureEnv
8260 //purpose : ENables or disables environment mapping
8261 //==============================================================================
8262 class OCC_TextureEnv : public Graphic3d_TextureEnv
8265 OCC_TextureEnv(const Standard_CString FileName);
8266 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
8267 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
8268 const Standard_Boolean theModulateFlag,
8269 const Graphic3d_TypeOfTextureFilter theFilter,
8270 const Standard_ShortReal theXScale,
8271 const Standard_ShortReal theYScale,
8272 const Standard_ShortReal theXShift,
8273 const Standard_ShortReal theYShift,
8274 const Standard_ShortReal theAngle);
8275 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
8277 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
8279 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
8280 : Graphic3d_TextureEnv(theFileName)
8284 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
8285 : Graphic3d_TextureEnv(theTexId)
8289 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
8290 const Standard_Boolean theModulateFlag,
8291 const Graphic3d_TypeOfTextureFilter theFilter,
8292 const Standard_ShortReal theXScale,
8293 const Standard_ShortReal theYScale,
8294 const Standard_ShortReal theXShift,
8295 const Standard_ShortReal theYShift,
8296 const Standard_ShortReal theAngle)
8298 myParams->SetRepeat (theRepeatFlag);
8299 myParams->SetModulate (theModulateFlag);
8300 myParams->SetFilter (theFilter);
8301 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
8302 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
8303 myParams->SetRotation (theAngle);
8306 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
8308 // get the active view
8309 Handle(V3d_View) aView = ViewerTest::CurrentView();
8312 std::cerr << "No active view. Please call vinit.\n";
8316 // Checking the input arguments
8317 Standard_Boolean anEnableFlag = Standard_False;
8318 Standard_Boolean isOk = theArgNb >= 2;
8321 TCollection_AsciiString anEnableOpt(theArgVec[1]);
8322 anEnableFlag = anEnableOpt.IsEqual("on");
8323 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
8327 isOk = (theArgNb == 3 || theArgNb == 11);
8330 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8331 isOk = (!aTextureOpt.IsIntegerValue() ||
8332 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
8334 if (isOk && theArgNb == 11)
8336 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
8337 aModulateOpt(theArgVec[4]),
8338 aFilterOpt (theArgVec[5]),
8339 aSScaleOpt (theArgVec[6]),
8340 aTScaleOpt (theArgVec[7]),
8341 aSTransOpt (theArgVec[8]),
8342 aTTransOpt (theArgVec[9]),
8343 anAngleOpt (theArgVec[10]);
8344 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
8345 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
8346 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
8347 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
8348 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
8349 anAngleOpt.IsRealValue());
8356 std::cerr << "Usage :" << std::endl;
8357 std::cerr << theArgVec[0] << " off" << std::endl;
8358 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;
8364 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8365 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
8366 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
8367 new OCC_TextureEnv(theArgVec[2]);
8371 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
8372 aTexEnv->SetTextureParameters(
8373 aRepeatOpt. IsEqual("repeat"),
8374 aModulateOpt.IsEqual("modulate"),
8375 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
8376 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
8377 Graphic3d_TOTF_TRILINEAR,
8378 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
8379 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
8380 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
8381 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
8382 (Standard_ShortReal)Draw::Atof(theArgVec[10])
8385 aView->SetTextureEnv(aTexEnv);
8387 else // Disabling environment mapping
8389 Handle(Graphic3d_TextureEnv) aTexture;
8390 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
8399 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
8401 //! Remove registered clipping plane from all views and objects.
8402 static void removePlane (MapOfPlanes& theRegPlanes,
8403 const TCollection_AsciiString& theName)
8405 Handle(Graphic3d_ClipPlane) aClipPlane;
8406 if (!theRegPlanes.Find (theName, aClipPlane))
8408 std::cout << "Warning: no such plane.\n";
8412 theRegPlanes.UnBind (theName);
8413 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
8414 anIObjIt.More(); anIObjIt.Next())
8416 const Handle(AIS_InteractiveObject)& aPrs = anIObjIt.Key1();
8417 aPrs->RemoveClipPlane (aClipPlane);
8420 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
8421 aViewIt.More(); aViewIt.Next())
8423 const Handle(V3d_View)& aView = aViewIt.Key2();
8424 aView->RemoveClipPlane(aClipPlane);
8427 ViewerTest::RedrawAllViews();
8431 //===============================================================================================
8432 //function : VClipPlane
8434 //===============================================================================================
8435 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8437 // use short-cut for created clip planes map of created (or "registered by name") clip planes
8438 static MapOfPlanes aRegPlanes;
8442 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
8444 theDi << aPlaneIter.Key() << " ";
8449 TCollection_AsciiString aCommand (theArgVec[1]);
8450 aCommand.LowerCase();
8451 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
8452 if (anActiveView.IsNull())
8454 std::cout << "Error: no active view.\n";
8458 // print maximum number of planes for current viewer
8459 if (aCommand == "-maxplanes"
8460 || aCommand == "maxplanes")
8462 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
8463 << " plane slots provided by driver.\n";
8467 // create / delete plane instance
8468 if (aCommand == "-create"
8469 || aCommand == "create"
8470 || aCommand == "-delete"
8471 || aCommand == "delete"
8472 || aCommand == "-clone"
8473 || aCommand == "clone")
8477 std::cout << "Syntax error: plane name is required.\n";
8481 Standard_Boolean toCreate = aCommand == "-create"
8482 || aCommand == "create";
8483 Standard_Boolean toClone = aCommand == "-clone"
8484 || aCommand == "clone";
8485 Standard_Boolean toDelete = aCommand == "-delete"
8486 || aCommand == "delete";
8487 TCollection_AsciiString aPlane (theArgVec[2]);
8491 if (aRegPlanes.IsBound (aPlane))
8493 std::cout << "Warning: existing plane has been overridden.\n";
8498 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8502 else if (toClone) // toClone
8504 if (!aRegPlanes.IsBound (aPlane))
8506 std::cout << "Error: no such plane.\n";
8509 else if (theArgsNb < 4)
8511 std::cout << "Syntax error: enter name for new plane.\n";
8515 TCollection_AsciiString aClone (theArgVec[3]);
8516 if (aRegPlanes.IsBound (aClone))
8518 std::cout << "Error: plane name is in use.\n";
8522 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
8524 aRegPlanes.Bind (aClone, aClipPlane->Clone());
8534 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
8536 aPlane = aPlaneIter.Key();
8537 removePlane (aRegPlanes, aPlane);
8538 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
8543 removePlane (aRegPlanes, aPlane);
8549 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8554 // set / unset plane command
8555 if (aCommand == "set"
8556 || aCommand == "unset")
8560 std::cout << "Syntax error: need more arguments.\n";
8564 // redirect to new syntax
8565 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
8566 anArgVec.SetValue (1, theArgVec[0]);
8567 anArgVec.SetValue (2, theArgVec[2]);
8568 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
8569 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
8571 anArgVec.SetValue (anIt, theArgVec[anIt]);
8574 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
8577 // change plane command
8578 TCollection_AsciiString aPlaneName;
8579 Handle(Graphic3d_ClipPlane) aClipPlane;
8580 Standard_Integer anArgIter = 0;
8581 if (aCommand == "-change"
8582 || aCommand == "change")
8584 // old syntax support
8587 std::cout << "Syntax error: need more arguments.\n";
8592 aPlaneName = theArgVec[2];
8593 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
8595 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
8599 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
8602 aPlaneName = theArgVec[1];
8607 aPlaneName = theArgVec[1];
8608 aClipPlane = new Graphic3d_ClipPlane();
8609 aRegPlanes.Bind (aPlaneName, aClipPlane);
8610 theDi << "Created new plane " << aPlaneName << ".\n";
8613 if (theArgsNb - anArgIter < 1)
8615 std::cout << "Syntax error: need more arguments.\n";
8619 for (; anArgIter < theArgsNb; ++anArgIter)
8621 const char** aChangeArgs = theArgVec + anArgIter;
8622 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
8623 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
8624 aChangeArg.LowerCase();
8626 Standard_Boolean toEnable = Standard_True;
8627 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
8629 aClipPlane->SetOn (toEnable);
8631 else if (aChangeArg.StartsWith ("-equation")
8632 || aChangeArg.StartsWith ("equation"))
8634 if (aNbChangeArgs < 5)
8636 std::cout << "Syntax error: need more arguments.\n";
8640 Standard_Integer aSubIndex = 1;
8641 Standard_Integer aPrefixLen = 8 + (aChangeArg.Value (1) == '-' ? 1 : 0);
8642 if (aPrefixLen < aChangeArg.Length())
8644 TCollection_AsciiString aSubStr = aChangeArg.SubString (aPrefixLen + 1, aChangeArg.Length());
8645 if (!aSubStr.IsIntegerValue()
8646 || aSubStr.IntegerValue() <= 0)
8648 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
8651 aSubIndex = aSubStr.IntegerValue();
8654 Standard_Real aCoeffA = Draw::Atof (aChangeArgs[1]);
8655 Standard_Real aCoeffB = Draw::Atof (aChangeArgs[2]);
8656 Standard_Real aCoeffC = Draw::Atof (aChangeArgs[3]);
8657 Standard_Real aCoeffD = Draw::Atof (aChangeArgs[4]);
8658 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
8659 for (Standard_Integer aSubPlaneIter = 1; aSubPlaneIter < aSubIndex; ++aSubPlaneIter)
8661 if (aSubPln->ChainNextPlane().IsNull())
8663 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
8665 aSubPln = aSubPln->ChainNextPlane();
8667 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
8668 aSubPln->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
8671 else if ((aChangeArg == "-boxinterior"
8672 || aChangeArg == "-boxint"
8673 || aChangeArg == "-box")
8674 && aNbChangeArgs >= 7)
8676 Graphic3d_BndBox3d aBndBox;
8677 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[1]), Draw::Atof (aChangeArgs[2]), Draw::Atof (aChangeArgs[3])));
8678 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[4]), Draw::Atof (aChangeArgs[5]), Draw::Atof (aChangeArgs[6])));
8681 Standard_Integer aNbSubPlanes = 6;
8682 const Graphic3d_Vec3d aDirArray[6] =
8684 Graphic3d_Vec3d (-1, 0, 0),
8685 Graphic3d_Vec3d ( 1, 0, 0),
8686 Graphic3d_Vec3d ( 0,-1, 0),
8687 Graphic3d_Vec3d ( 0, 1, 0),
8688 Graphic3d_Vec3d ( 0, 0,-1),
8689 Graphic3d_Vec3d ( 0, 0, 1),
8691 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
8692 for (Standard_Integer aSubPlaneIter = 0; aSubPlaneIter < aNbSubPlanes; ++aSubPlaneIter)
8694 const Graphic3d_Vec3d& aDir = aDirArray[aSubPlaneIter];
8695 const Standard_Real aW = -aDir.Dot ((aSubPlaneIter % 2 == 1) ? aBndBox.CornerMax() : aBndBox.CornerMin());
8696 aSubPln->SetEquation (gp_Pln (aDir.x(), aDir.y(), aDir.z(), aW));
8697 if (aSubPlaneIter + 1 == aNbSubPlanes)
8699 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
8703 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
8705 aSubPln = aSubPln->ChainNextPlane();
8708 else if (aChangeArg == "-capping"
8709 || aChangeArg == "capping")
8711 if (aNbChangeArgs < 2)
8713 std::cout << "Syntax error: need more arguments.\n";
8717 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8719 aClipPlane->SetCapping (toEnable);
8724 // just skip otherwise (old syntax)
8727 else if (aChangeArg == "-useobjectmaterial"
8728 || aChangeArg == "-useobjectmat"
8729 || aChangeArg == "-useobjmat"
8730 || aChangeArg == "-useobjmaterial")
8732 if (aNbChangeArgs < 2)
8734 std::cout << "Syntax error: need more arguments.\n";
8738 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8740 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
8744 else if (aChangeArg == "-useobjecttexture"
8745 || aChangeArg == "-useobjecttex"
8746 || aChangeArg == "-useobjtexture"
8747 || aChangeArg == "-useobjtex")
8749 if (aNbChangeArgs < 2)
8751 std::cout << "Syntax error: need more arguments.\n";
8755 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8757 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
8761 else if (aChangeArg == "-useobjectshader"
8762 || aChangeArg == "-useobjshader")
8764 if (aNbChangeArgs < 2)
8766 std::cout << "Syntax error: need more arguments.\n";
8770 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8772 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
8776 else if (aChangeArg == "-color"
8777 || aChangeArg == "color")
8779 Quantity_Color aColor;
8780 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
8785 std::cout << "Syntax error: need more arguments.\n";
8789 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
8790 aMat.SetAmbientColor (aColor);
8791 aMat.SetDiffuseColor (aColor);
8792 aClipPlane->SetCappingMaterial (aMat);
8793 anArgIter += aNbParsed;
8795 else if ((aChangeArg == "-transparency"
8796 || aChangeArg == "-transp")
8797 && aNbChangeArgs >= 2)
8799 TCollection_AsciiString aValStr (aChangeArgs[1]);
8800 Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect();
8801 if (aValStr.IsRealValue())
8803 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
8804 aMat.SetTransparency ((float )aValStr.RealValue());
8805 anAspect->SetAlphaMode (Graphic3d_AlphaMode_BlendAuto);
8806 aClipPlane->SetCappingMaterial (aMat);
8810 aValStr.LowerCase();
8811 Graphic3d_AlphaMode aMode = Graphic3d_AlphaMode_BlendAuto;
8812 if (aValStr == "opaque")
8814 aMode = Graphic3d_AlphaMode_Opaque;
8816 else if (aValStr == "mask")
8818 aMode = Graphic3d_AlphaMode_Mask;
8820 else if (aValStr == "blend")
8822 aMode = Graphic3d_AlphaMode_Blend;
8824 else if (aValStr == "blendauto")
8826 aMode = Graphic3d_AlphaMode_BlendAuto;
8830 std::cout << "Syntax error at '" << aValStr << "'\n";
8833 anAspect->SetAlphaMode (aMode);
8834 aClipPlane->SetCappingAspect (anAspect);
8838 else if (aChangeArg == "-texname"
8839 || aChangeArg == "texname")
8841 if (aNbChangeArgs < 2)
8843 std::cout << "Syntax error: need more arguments.\n";
8847 TCollection_AsciiString aTextureName (aChangeArgs[1]);
8848 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
8849 if (!aTexture->IsDone())
8851 aClipPlane->SetCappingTexture (NULL);
8855 aTexture->EnableModulate();
8856 aTexture->EnableRepeat();
8857 aClipPlane->SetCappingTexture (aTexture);
8861 else if (aChangeArg == "-texscale"
8862 || aChangeArg == "texscale")
8864 if (aClipPlane->CappingTexture().IsNull())
8866 std::cout << "Error: no texture is set.\n";
8870 if (aNbChangeArgs < 3)
8872 std::cout << "Syntax error: need more arguments.\n";
8876 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8877 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8878 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
8881 else if (aChangeArg == "-texorigin"
8882 || aChangeArg == "texorigin") // texture origin
8884 if (aClipPlane->CappingTexture().IsNull())
8886 std::cout << "Error: no texture is set.\n";
8890 if (aNbChangeArgs < 3)
8892 std::cout << "Syntax error: need more arguments.\n";
8896 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8897 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8899 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
8902 else if (aChangeArg == "-texrotate"
8903 || aChangeArg == "texrotate") // texture rotation
8905 if (aClipPlane->CappingTexture().IsNull())
8907 std::cout << "Error: no texture is set.\n";
8911 if (aNbChangeArgs < 2)
8913 std::cout << "Syntax error: need more arguments.\n";
8917 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8918 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
8921 else if (aChangeArg == "-hatch"
8922 || aChangeArg == "hatch")
8924 if (aNbChangeArgs < 2)
8926 std::cout << "Syntax error: need more arguments.\n";
8930 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
8931 aHatchStr.LowerCase();
8932 if (aHatchStr == "on")
8934 aClipPlane->SetCappingHatchOn();
8936 else if (aHatchStr == "off")
8938 aClipPlane->SetCappingHatchOff();
8942 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
8946 else if (aChangeArg == "-delete"
8947 || aChangeArg == "delete")
8949 removePlane (aRegPlanes, aPlaneName);
8952 else if (aChangeArg == "-set"
8953 || aChangeArg == "-unset"
8954 || aChangeArg == "-setoverrideglobal")
8956 // set / unset plane command
8957 const Standard_Boolean toSet = aChangeArg.StartsWith ("-set");
8958 const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal";
8959 Standard_Integer anIt = 1;
8960 for (; anIt < aNbChangeArgs; ++anIt)
8962 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
8963 if (anEntityName.IsEmpty()
8964 || anEntityName.Value (1) == '-')
8968 else if (!toOverrideGlobal
8969 && ViewerTest_myViews.IsBound1 (anEntityName))
8971 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
8974 aView->AddClipPlane (aClipPlane);
8978 aView->RemoveClipPlane (aClipPlane);
8982 else if (GetMapOfAIS().IsBound2 (anEntityName))
8984 Handle(AIS_InteractiveObject) aIObj = GetMapOfAIS().Find2 (anEntityName);
8987 aIObj->AddClipPlane (aClipPlane);
8991 aIObj->RemoveClipPlane (aClipPlane);
8993 if (!aIObj->ClipPlanes().IsNull())
8995 aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal);
9000 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
9007 // apply to active view
9010 anActiveView->AddClipPlane (aClipPlane);
9014 anActiveView->RemoveClipPlane (aClipPlane);
9019 anArgIter = anArgIter + anIt - 1;
9024 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
9029 ViewerTest::RedrawAllViews();
9033 //===============================================================================================
9034 //function : VZRange
9036 //===============================================================================================
9037 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9039 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
9041 if (aCurrentView.IsNull())
9043 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
9047 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
9051 theDi << "ZNear: " << aCamera->ZNear() << "\n";
9052 theDi << "ZFar: " << aCamera->ZFar() << "\n";
9058 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
9059 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
9061 if (aNewZNear >= aNewZFar)
9063 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
9067 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
9069 std::cout << theArgVec[0] << ": invalid arguments: ";
9070 std::cout << "znear, zfar should be positive for perspective camera.\n";
9074 aCamera->SetZRange (aNewZNear, aNewZFar);
9078 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
9082 aCurrentView->Redraw();
9087 //===============================================================================================
9088 //function : VAutoZFit
9090 //===============================================================================================
9091 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
9093 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
9095 if (aCurrentView.IsNull())
9097 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
9101 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
9105 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
9111 theDi << "Auto z-fit mode: \n"
9112 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
9113 << "Scale: " << aScale << "\n";
9117 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
9121 aScale = Draw::Atoi (theArgVec[2]);
9124 aCurrentView->SetAutoZFitMode (isOn, aScale);
9125 aCurrentView->AutoZFit();
9126 aCurrentView->Redraw();
9131 //! Auxiliary function to print projection type
9132 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
9134 switch (theProjType)
9136 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
9137 case Graphic3d_Camera::Projection_Perspective: return "perspective";
9138 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
9139 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
9140 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
9145 //===============================================================================================
9146 //function : VCamera
9148 //===============================================================================================
9149 static int VCamera (Draw_Interpretor& theDI,
9150 Standard_Integer theArgsNb,
9151 const char** theArgVec)
9153 Handle(V3d_View) aView = ViewerTest::CurrentView();
9156 std::cout << "Error: no active view.\n";
9160 Handle(Graphic3d_Camera) aCamera = aView->Camera();
9163 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
9164 theDI << "FOVy: " << aCamera->FOVy() << "\n";
9165 theDI << "Distance: " << aCamera->Distance() << "\n";
9166 theDI << "IOD: " << aCamera->IOD() << "\n";
9167 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
9168 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
9169 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
9173 TCollection_AsciiString aPrsName;
9174 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
9176 Standard_CString anArg = theArgVec[anArgIter];
9177 TCollection_AsciiString anArgCase (anArg);
9178 anArgCase.LowerCase();
9179 if (anArgCase == "-proj"
9180 || anArgCase == "-projection"
9181 || anArgCase == "-projtype"
9182 || anArgCase == "-projectiontype")
9184 theDI << projTypeName (aCamera->ProjectionType()) << " ";
9186 else if (anArgCase == "-ortho"
9187 || anArgCase == "-orthographic")
9189 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
9191 else if (anArgCase == "-persp"
9192 || anArgCase == "-perspective"
9193 || anArgCase == "-perspmono"
9194 || anArgCase == "-perspectivemono"
9195 || anArgCase == "-mono")
9197 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
9199 else if (anArgCase == "-stereo"
9200 || anArgCase == "-stereoscopic"
9201 || anArgCase == "-perspstereo"
9202 || anArgCase == "-perspectivestereo")
9204 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9206 else if (anArgCase == "-left"
9207 || anArgCase == "-lefteye"
9208 || anArgCase == "-monoleft"
9209 || anArgCase == "-monolefteye"
9210 || anArgCase == "-perpsleft"
9211 || anArgCase == "-perpslefteye")
9213 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
9215 else if (anArgCase == "-right"
9216 || anArgCase == "-righteye"
9217 || anArgCase == "-monoright"
9218 || anArgCase == "-monorighteye"
9219 || anArgCase == "-perpsright")
9221 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
9223 else if (anArgCase == "-dist"
9224 || anArgCase == "-distance")
9226 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9227 if (anArgValue != NULL
9228 && *anArgValue != '-')
9231 aCamera->SetDistance (Draw::Atof (anArgValue));
9234 theDI << aCamera->Distance() << " ";
9236 else if (anArgCase == "-iod")
9238 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9239 if (anArgValue != NULL
9240 && *anArgValue != '-')
9243 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
9246 theDI << aCamera->IOD() << " ";
9248 else if (anArgCase == "-iodtype")
9250 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
9251 TCollection_AsciiString anValueCase (anArgValue);
9252 anValueCase.LowerCase();
9253 if (anValueCase == "abs"
9254 || anValueCase == "absolute")
9257 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
9260 else if (anValueCase == "rel"
9261 || anValueCase == "relative")
9264 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
9267 else if (*anArgValue != '-')
9269 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
9272 switch (aCamera->GetIODType())
9274 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
9275 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
9278 else if (anArgCase == "-zfocus")
9280 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9281 if (anArgValue != NULL
9282 && *anArgValue != '-')
9285 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
9288 theDI << aCamera->ZFocus() << " ";
9290 else if (anArgCase == "-zfocustype")
9292 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
9293 TCollection_AsciiString anValueCase (anArgValue);
9294 anValueCase.LowerCase();
9295 if (anValueCase == "abs"
9296 || anValueCase == "absolute")
9299 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
9302 else if (anValueCase == "rel"
9303 || anValueCase == "relative")
9306 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
9309 else if (*anArgValue != '-')
9311 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
9314 switch (aCamera->ZFocusType())
9316 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
9317 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
9320 else if (anArgCase == "-fov"
9321 || anArgCase == "-fovy")
9323 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9324 if (anArgValue != NULL
9325 && *anArgValue != '-')
9328 aCamera->SetFOVy (Draw::Atof (anArgValue));
9331 theDI << aCamera->FOVy() << " ";
9333 else if (aPrsName.IsEmpty()
9334 && !anArgCase.StartsWith ("-"))
9340 std::cout << "Error: unknown argument '" << anArg << "'\n";
9345 if (aPrsName.IsEmpty()
9352 if (!aPrsName.IsEmpty())
9354 Handle(AIS_CameraFrustum) aCameraFrustum;
9355 if (GetMapOfAIS().IsBound2 (aPrsName))
9357 // find existing object
9358 aCameraFrustum = Handle(AIS_CameraFrustum)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
9359 if (aCameraFrustum.IsNull())
9361 std::cout << "Error: object '" << aPrsName << "'is already defined and is not a camera frustum!\n";
9366 if (aCameraFrustum.IsNull())
9368 aCameraFrustum = new AIS_CameraFrustum();
9372 // not include displayed object of old camera frustum in the new one.
9373 ViewerTest::GetAISContext()->Erase (aCameraFrustum, false);
9376 aCameraFrustum->SetCameraFrustum (aView->Camera());
9378 ViewerTest::Display (aPrsName, aCameraFrustum);
9384 //! Parse stereo output mode
9385 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
9386 Graphic3d_StereoMode& theMode)
9388 TCollection_AsciiString aFlag (theArg);
9390 if (aFlag == "quadbuffer")
9392 theMode = Graphic3d_StereoMode_QuadBuffer;
9394 else if (aFlag == "anaglyph")
9396 theMode = Graphic3d_StereoMode_Anaglyph;
9398 else if (aFlag == "row"
9399 || aFlag == "rowinterlaced")
9401 theMode = Graphic3d_StereoMode_RowInterlaced;
9403 else if (aFlag == "col"
9404 || aFlag == "colinterlaced"
9405 || aFlag == "columninterlaced")
9407 theMode = Graphic3d_StereoMode_ColumnInterlaced;
9409 else if (aFlag == "chess"
9410 || aFlag == "chessboard")
9412 theMode = Graphic3d_StereoMode_ChessBoard;
9414 else if (aFlag == "sbs"
9415 || aFlag == "sidebyside")
9417 theMode = Graphic3d_StereoMode_SideBySide;
9419 else if (aFlag == "ou"
9420 || aFlag == "overunder")
9422 theMode = Graphic3d_StereoMode_OverUnder;
9424 else if (aFlag == "pageflip"
9425 || aFlag == "softpageflip")
9427 theMode = Graphic3d_StereoMode_SoftPageFlip;
9431 return Standard_False;
9433 return Standard_True;
9436 //! Parse anaglyph filter
9437 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
9438 Graphic3d_RenderingParams::Anaglyph& theFilter)
9440 TCollection_AsciiString aFlag (theArg);
9442 if (aFlag == "redcyansimple")
9444 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9446 else if (aFlag == "redcyan"
9447 || aFlag == "redcyanoptimized")
9449 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
9451 else if (aFlag == "yellowbluesimple")
9453 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
9455 else if (aFlag == "yellowblue"
9456 || aFlag == "yellowblueoptimized")
9458 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
9460 else if (aFlag == "greenmagenta"
9461 || aFlag == "greenmagentasimple")
9463 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
9467 return Standard_False;
9469 return Standard_True;
9472 //==============================================================================
9473 //function : VStereo
9475 //==============================================================================
9477 static int VStereo (Draw_Interpretor& theDI,
9478 Standard_Integer theArgNb,
9479 const char** theArgVec)
9481 Handle(V3d_View) aView = ViewerTest::CurrentView();
9486 std::cout << "Error: no active viewer!\n";
9490 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
9491 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
9494 TCollection_AsciiString aMode;
9495 switch (aView->RenderingParams().StereoMode)
9497 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
9498 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
9499 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
9500 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
9501 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
9502 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
9503 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
9504 case Graphic3d_StereoMode_Anaglyph :
9506 switch (aView->RenderingParams().AnaglyphFilter)
9508 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
9509 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
9510 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
9511 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
9512 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
9517 theDI << "Mode " << aMode << "\n";
9522 Handle(Graphic3d_Camera) aCamera;
9523 Graphic3d_RenderingParams* aParams = NULL;
9524 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
9525 if (!aView.IsNull())
9527 aParams = &aView->ChangeRenderingParams();
9528 aMode = aParams->StereoMode;
9529 aCamera = aView->Camera();
9532 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
9533 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
9535 Standard_CString anArg = theArgVec[anArgIter];
9536 TCollection_AsciiString aFlag (anArg);
9538 if (anUpdateTool.parseRedrawMode (aFlag))
9542 else if (aFlag == "0"
9545 if (++anArgIter < theArgNb)
9547 std::cout << "Error: wrong number of arguments!\n";
9551 if (!aCamera.IsNull()
9552 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
9554 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
9556 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
9559 else if (aFlag == "1"
9562 if (++anArgIter < theArgNb)
9564 std::cout << "Error: wrong number of arguments!\n";
9568 if (!aCamera.IsNull())
9570 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9572 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9575 else if (aFlag == "-reverse"
9576 || aFlag == "-reversed"
9577 || aFlag == "-swap")
9579 Standard_Boolean toEnable = Standard_True;
9580 if (++anArgIter < theArgNb
9581 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9585 aParams->ToReverseStereo = toEnable;
9587 else if (aFlag == "-noreverse"
9588 || aFlag == "-noswap")
9590 Standard_Boolean toDisable = Standard_True;
9591 if (++anArgIter < theArgNb
9592 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
9596 aParams->ToReverseStereo = !toDisable;
9598 else if (aFlag == "-mode"
9599 || aFlag == "-stereomode")
9601 if (++anArgIter >= theArgNb
9602 || !parseStereoMode (theArgVec[anArgIter], aMode))
9604 std::cout << "Error: syntax error at '" << anArg << "'\n";
9608 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9610 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9613 else if (aFlag == "-anaglyph"
9614 || aFlag == "-anaglyphfilter")
9616 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9617 if (++anArgIter >= theArgNb
9618 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
9620 std::cout << "Error: syntax error at '" << anArg << "'\n";
9624 aMode = Graphic3d_StereoMode_Anaglyph;
9625 aParams->AnaglyphFilter = aFilter;
9627 else if (parseStereoMode (anArg, aMode)) // short syntax
9629 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9631 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9636 std::cout << "Error: syntax error at '" << anArg << "'\n";
9641 if (!aView.IsNull())
9643 aParams->StereoMode = aMode;
9644 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9649 //===============================================================================================
9650 //function : VDefaults
9652 //===============================================================================================
9653 static int VDefaults (Draw_Interpretor& theDi,
9654 Standard_Integer theArgsNb,
9655 const char** theArgVec)
9657 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
9660 std::cerr << "No active viewer!\n";
9664 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
9667 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
9669 theDi << "DeflType: relative\n"
9670 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
9674 theDi << "DeflType: absolute\n"
9675 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
9677 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
9678 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
9682 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
9684 TCollection_AsciiString anArg (theArgVec[anArgIter]);
9686 if (anArg == "-ABSDEFL"
9687 || anArg == "-ABSOLUTEDEFLECTION"
9689 || anArg == "-DEFLECTION")
9691 if (++anArgIter >= theArgsNb)
9693 std::cout << "Error: wrong syntax at " << anArg << "\n";
9696 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
9697 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
9699 else if (anArg == "-RELDEFL"
9700 || anArg == "-RELATIVEDEFLECTION"
9701 || anArg == "-DEVCOEFF"
9702 || anArg == "-DEVIATIONCOEFF"
9703 || anArg == "-DEVIATIONCOEFFICIENT")
9705 if (++anArgIter >= theArgsNb)
9707 std::cout << "Error: wrong syntax at " << anArg << "\n";
9710 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
9711 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
9713 else if (anArg == "-ANGDEFL"
9714 || anArg == "-ANGULARDEFL"
9715 || anArg == "-ANGULARDEFLECTION")
9717 if (++anArgIter >= theArgsNb)
9719 std::cout << "Error: wrong syntax at " << anArg << "\n";
9722 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
9723 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
9725 else if (anArg == "-AUTOTR"
9726 || anArg == "-AUTOTRIANG"
9727 || anArg == "-AUTOTRIANGULATION")
9729 if (++anArgIter >= theArgsNb)
9731 std::cout << "Error: wrong syntax at " << anArg << "\n";
9734 TCollection_AsciiString aValue (theArgVec[anArgIter]);
9739 aDefParams->SetAutoTriangulation (Standard_True);
9741 else if (aValue == "off"
9744 aDefParams->SetAutoTriangulation (Standard_False);
9749 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
9756 //! Auxiliary method
9757 inline void addLight (const Handle(V3d_Light)& theLightNew,
9758 const Graphic3d_ZLayerId theLayer,
9759 const Standard_Boolean theIsGlobal)
9761 if (theLightNew.IsNull())
9766 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9767 if (theLayer == Graphic3d_ZLayerId_UNKNOWN)
9769 aViewer->AddLight (theLightNew);
9772 aViewer->SetLightOn (theLightNew);
9776 ViewerTest::CurrentView()->SetLightOn (theLightNew);
9781 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer);
9782 if (aSettings.Lights().IsNull())
9784 aSettings.SetLights (new Graphic3d_LightSet());
9786 aSettings.Lights()->Add (theLightNew);
9787 aViewer->SetZLayerSettings (theLayer, aSettings);
9791 //! Auxiliary method
9792 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
9794 TCollection_AsciiString anArgNextCase (theArgNext);
9795 anArgNextCase.UpperCase();
9796 if (anArgNextCase.Length() > 5
9797 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
9799 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
9803 return theArgNext.IntegerValue();
9807 //===============================================================================================
9810 //===============================================================================================
9811 static int VLight (Draw_Interpretor& theDi,
9812 Standard_Integer theArgsNb,
9813 const char** theArgVec)
9815 Handle(V3d_View) aView = ViewerTest::CurrentView();
9816 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9818 || aViewer.IsNull())
9820 std::cerr << "No active viewer!\n";
9824 Standard_Real anXYZ[3] = {};
9825 Standard_Real anAtten[2] = {};
9828 // print lights info
9829 Standard_Integer aLightId = 0;
9830 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
9832 Handle(V3d_Light) aLight = aLightIter.Value();
9833 const Quantity_Color aColor = aLight->Color();
9834 theDi << "Light #" << aLightId
9835 << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "")
9836 << " [" << aLight->GetId() << "]" << "\n";
9837 switch (aLight->Type())
9841 theDi << " Type: Ambient\n";
9842 theDi << " Intensity: " << aLight->Intensity() << "\n";
9845 case V3d_DIRECTIONAL:
9847 theDi << " Type: Directional\n";
9848 theDi << " Intensity: " << aLight->Intensity() << "\n";
9849 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9850 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
9851 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
9852 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9855 case V3d_POSITIONAL:
9857 theDi << " Type: Positional\n";
9858 theDi << " Intensity: " << aLight->Intensity() << "\n";
9859 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9860 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
9861 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9862 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9863 aLight->Attenuation (anAtten[0], anAtten[1]);
9864 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
9869 theDi << " Type: Spot\n";
9870 theDi << " Intensity: " << aLight->Intensity() << "\n";
9871 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9872 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9873 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9874 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
9875 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9876 aLight->Attenuation (anAtten[0], anAtten[1]);
9877 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
9878 theDi << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n";
9879 theDi << " Exponent: " << aLight->Concentration() << "\n";
9884 theDi << " Type: UNKNOWN\n";
9888 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n";
9892 Handle(V3d_Light) aLightNew;
9893 Handle(V3d_Light) aLightOld;
9894 Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN;
9895 Standard_Boolean isGlobal = Standard_True;
9896 Standard_Boolean toCreate = Standard_False;
9897 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
9898 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
9900 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
9902 TCollection_AsciiString aName, aValue;
9903 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
9904 TCollection_AsciiString anArgCase (anArg);
9905 anArgCase.UpperCase();
9906 if (anUpdateTool.parseRedrawMode (anArg))
9911 if (anArgCase.IsEqual ("NEW")
9912 || anArgCase.IsEqual ("ADD")
9913 || anArgCase.IsEqual ("CREATE")
9914 || anArgCase.IsEqual ("-NEW")
9915 || anArgCase.IsEqual ("-ADD")
9916 || anArgCase.IsEqual ("-CREATE"))
9918 toCreate = Standard_True;
9920 else if (anArgCase.IsEqual ("-LAYER")
9921 || anArgCase.IsEqual ("-ZLAYER"))
9923 if (++anArgIt >= theArgsNb)
9925 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9929 TCollection_AsciiString aValStr (theArgVec[anArgIt]);
9930 aValStr.LowerCase();
9931 if (aValStr == "default"
9932 || aValStr == "def")
9934 aLayer = Graphic3d_ZLayerId_Default;
9936 else if (aValStr == "top")
9938 aLayer = Graphic3d_ZLayerId_Top;
9940 else if (aValStr == "topmost")
9942 aLayer = Graphic3d_ZLayerId_Topmost;
9944 else if (aValStr == "toposd"
9945 || aValStr == "osd")
9947 aLayer = Graphic3d_ZLayerId_TopOSD;
9949 else if (aValStr == "botosd"
9950 || aValStr == "bottom")
9952 aLayer = Graphic3d_ZLayerId_BotOSD;
9954 else if (aValStr.IsIntegerValue())
9956 aLayer = Draw::Atoi (theArgVec[anArgIt]);
9960 std::cout << "Wrong syntax at argument '" << anArg << "'!\n";
9964 else if (anArgCase.IsEqual ("GLOB")
9965 || anArgCase.IsEqual ("GLOBAL")
9966 || anArgCase.IsEqual ("-GLOB")
9967 || anArgCase.IsEqual ("-GLOBAL"))
9969 isGlobal = Standard_True;
9971 else if (anArgCase.IsEqual ("LOC")
9972 || anArgCase.IsEqual ("LOCAL")
9973 || anArgCase.IsEqual ("-LOC")
9974 || anArgCase.IsEqual ("-LOCAL"))
9976 isGlobal = Standard_False;
9978 else if (anArgCase.IsEqual ("DEF")
9979 || anArgCase.IsEqual ("DEFAULTS")
9980 || anArgCase.IsEqual ("-DEF")
9981 || anArgCase.IsEqual ("-DEFAULTS"))
9983 toCreate = Standard_False;
9984 aViewer->SetDefaultLights();
9986 else if (anArgCase.IsEqual ("CLR")
9987 || anArgCase.IsEqual ("CLEAR")
9988 || anArgCase.IsEqual ("-CLR")
9989 || anArgCase.IsEqual ("-CLEAR"))
9991 toCreate = Standard_False;
9993 TColStd_SequenceOfInteger aLayers;
9994 aViewer->GetAllZLayers (aLayers);
9995 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
9997 if (aLayeriter.Value() == aLayer
9998 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
10000 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
10001 aSettings.SetLights (Handle(Graphic3d_LightSet)());
10002 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
10003 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
10010 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
10012 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
10014 Handle(V3d_Light) aLight = aLightIter.Value();
10015 aViewer->DelLight (aLight);
10016 aLightIter = aView->ActiveLightIterator();
10020 else if (anArgCase.IsEqual ("AMB")
10021 || anArgCase.IsEqual ("AMBIENT")
10022 || anArgCase.IsEqual ("AMBLIGHT"))
10026 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10030 addLight (aLightNew, aLayer, isGlobal);
10031 toCreate = Standard_False;
10032 aLightNew = new V3d_AmbientLight();
10034 else if (anArgCase.IsEqual ("DIRECTIONAL")
10035 || anArgCase.IsEqual ("DIRLIGHT"))
10039 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10043 addLight (aLightNew, aLayer, isGlobal);
10044 toCreate = Standard_False;
10045 aLightNew = new V3d_DirectionalLight();
10047 else if (anArgCase.IsEqual ("SPOT")
10048 || anArgCase.IsEqual ("SPOTLIGHT"))
10052 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10056 addLight (aLightNew, aLayer, isGlobal);
10057 toCreate = Standard_False;
10058 aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0));
10060 else if (anArgCase.IsEqual ("POSLIGHT")
10061 || anArgCase.IsEqual ("POSITIONAL"))
10065 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10069 addLight (aLightNew, aLayer, isGlobal);
10070 toCreate = Standard_False;
10071 aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0));
10073 else if (anArgCase.IsEqual ("CHANGE")
10074 || anArgCase.IsEqual ("-CHANGE"))
10076 if (++anArgIt >= theArgsNb)
10078 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10082 addLight (aLightNew, aLayer, isGlobal);
10083 aLightNew.Nullify();
10084 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
10085 Standard_Integer aLightIt = 0;
10086 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
10088 if (aLightIt == aLightId)
10090 aLightOld = aLightIter.Value();
10095 if (aLightOld.IsNull())
10097 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
10101 else if (anArgCase.IsEqual ("DEL")
10102 || anArgCase.IsEqual ("DELETE")
10103 || anArgCase.IsEqual ("-DEL")
10104 || anArgCase.IsEqual ("-DELETE"))
10106 Handle(V3d_Light) aLightDel;
10107 if (++anArgIt >= theArgsNb)
10109 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10113 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
10114 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
10115 Standard_Integer aLightIt = 0;
10116 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
10118 aLightDel = aLightIter.Value();
10119 if (aLightIt == aLightDelId)
10124 if (aLightDel.IsNull())
10129 TColStd_SequenceOfInteger aLayers;
10130 aViewer->GetAllZLayers (aLayers);
10131 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
10133 if (aLayeriter.Value() == aLayer
10134 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
10136 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
10137 if (!aSettings.Lights().IsNull())
10139 aSettings.Lights()->Remove (aLightDel);
10140 if (aSettings.Lights()->IsEmpty())
10142 aSettings.SetLights (Handle(Graphic3d_LightSet)());
10145 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
10146 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
10153 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
10155 aViewer->DelLight (aLightDel);
10158 else if (anArgCase.IsEqual ("COLOR")
10159 || anArgCase.IsEqual ("COLOUR")
10160 || anArgCase.IsEqual ("-COLOR")
10161 || anArgCase.IsEqual ("-COLOUR"))
10163 if (++anArgIt >= theArgsNb
10164 || aLightCurr.IsNull())
10166 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10170 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
10171 anArgNext.UpperCase();
10172 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
10173 aLightCurr->SetColor (aColor);
10175 else if (anArgCase.IsEqual ("POS")
10176 || anArgCase.IsEqual ("POSITION")
10177 || anArgCase.IsEqual ("-POS")
10178 || anArgCase.IsEqual ("-POSITION"))
10180 if ((anArgIt + 3) >= theArgsNb
10181 || aLightCurr.IsNull()
10182 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10183 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
10185 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10189 anXYZ[0] = Atof (theArgVec[++anArgIt]);
10190 anXYZ[1] = Atof (theArgVec[++anArgIt]);
10191 anXYZ[2] = Atof (theArgVec[++anArgIt]);
10192 aLightCurr->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
10194 else if (anArgCase.IsEqual ("DIR")
10195 || anArgCase.IsEqual ("DIRECTION")
10196 || anArgCase.IsEqual ("-DIR")
10197 || anArgCase.IsEqual ("-DIRECTION"))
10199 if ((anArgIt + 3) >= theArgsNb
10200 || aLightCurr.IsNull()
10201 || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL
10202 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
10204 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10208 anXYZ[0] = Atof (theArgVec[++anArgIt]);
10209 anXYZ[1] = Atof (theArgVec[++anArgIt]);
10210 anXYZ[2] = Atof (theArgVec[++anArgIt]);
10211 aLightCurr->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
10213 else if (anArgCase.IsEqual ("SM")
10214 || anArgCase.IsEqual ("SMOOTHNESS")
10215 || anArgCase.IsEqual ("-SM")
10216 || anArgCase.IsEqual ("-SMOOTHNESS"))
10218 if (++anArgIt >= theArgsNb
10219 || aLightCurr.IsNull())
10221 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10225 Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
10226 if (Abs (aSmoothness) <= ShortRealEpsilon())
10228 aLightCurr->SetIntensity (1.f);
10230 else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon())
10232 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
10236 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
10237 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
10240 if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL)
10242 aLightCurr->SetSmoothRadius (aSmoothness);
10244 else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
10246 aLightCurr->SetSmoothAngle (aSmoothness);
10249 else if (anArgCase.IsEqual ("INT")
10250 || anArgCase.IsEqual ("INTENSITY")
10251 || anArgCase.IsEqual ("-INT")
10252 || anArgCase.IsEqual ("-INTENSITY"))
10254 if (++anArgIt >= theArgsNb
10255 || aLightCurr.IsNull())
10257 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10261 Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
10262 aLightCurr->SetIntensity (aIntensity);
10264 else if (anArgCase.IsEqual ("ANG")
10265 || anArgCase.IsEqual ("ANGLE")
10266 || anArgCase.IsEqual ("-ANG")
10267 || anArgCase.IsEqual ("-ANGLE"))
10269 if (++anArgIt >= theArgsNb
10270 || aLightCurr.IsNull()
10271 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
10273 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10277 Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
10278 aLightCurr->SetAngle (Standard_ShortReal (anAngle / 180.0 * M_PI));
10280 else if (anArgCase.IsEqual ("CONSTATTEN")
10281 || anArgCase.IsEqual ("CONSTATTENUATION")
10282 || anArgCase.IsEqual ("-CONSTATTEN")
10283 || anArgCase.IsEqual ("-CONSTATTENUATION"))
10285 if (++anArgIt >= theArgsNb
10286 || aLightCurr.IsNull()
10287 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10288 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
10290 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10294 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
10295 anAtten[0] = Atof (theArgVec[anArgIt]);
10296 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
10298 else if (anArgCase.IsEqual ("LINATTEN")
10299 || anArgCase.IsEqual ("LINEARATTEN")
10300 || anArgCase.IsEqual ("LINEARATTENUATION")
10301 || anArgCase.IsEqual ("-LINATTEN")
10302 || anArgCase.IsEqual ("-LINEARATTEN")
10303 || anArgCase.IsEqual ("-LINEARATTENUATION"))
10305 if (++anArgIt >= theArgsNb
10306 || aLightCurr.IsNull()
10307 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10308 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
10310 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10314 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
10315 anAtten[1] = Atof (theArgVec[anArgIt]);
10316 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
10318 else if (anArgCase.IsEqual ("EXP")
10319 || anArgCase.IsEqual ("EXPONENT")
10320 || anArgCase.IsEqual ("SPOTEXP")
10321 || anArgCase.IsEqual ("SPOTEXPONENT")
10322 || anArgCase.IsEqual ("-EXP")
10323 || anArgCase.IsEqual ("-EXPONENT")
10324 || anArgCase.IsEqual ("-SPOTEXP")
10325 || anArgCase.IsEqual ("-SPOTEXPONENT"))
10327 if (++anArgIt >= theArgsNb
10328 || aLightCurr.IsNull()
10329 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
10331 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10335 aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt]));
10337 else if (anArgCase.IsEqual ("HEAD")
10338 || anArgCase.IsEqual ("HEADLIGHT")
10339 || anArgCase.IsEqual ("-HEAD")
10340 || anArgCase.IsEqual ("-HEADLIGHT"))
10342 if (aLightCurr.IsNull()
10343 || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
10345 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10349 Standard_Boolean isHeadLight = Standard_True;
10350 if (anArgIt + 1 < theArgsNb
10351 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight))
10355 aLightCurr->SetHeadlight (isHeadLight);
10359 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
10363 addLight (aLightNew, aLayer, isGlobal);
10367 //! Read Graphic3d_RenderingParams::PerfCounters flag.
10368 static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue,
10369 Standard_Boolean& theToReset,
10370 Graphic3d_RenderingParams::PerfCounters& theFlagsRem,
10371 Graphic3d_RenderingParams::PerfCounters& theFlagsAdd)
10373 Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE;
10374 TCollection_AsciiString aVal = theValue;
10375 Standard_Boolean toReverse = Standard_False;
10376 if (aVal == "none")
10378 theToReset = Standard_True;
10379 return Standard_True;
10381 else if (aVal.StartsWith ("-"))
10383 toReverse = Standard_True;
10384 aVal = aVal.SubString (2, aVal.Length());
10386 else if (aVal.StartsWith ("no"))
10388 toReverse = Standard_True;
10389 aVal = aVal.SubString (3, aVal.Length());
10391 else if (aVal.StartsWith ("+"))
10393 aVal = aVal.SubString (2, aVal.Length());
10397 theToReset = Standard_True;
10401 || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate;
10402 else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU;
10403 else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers;
10404 else if (aVal == "structs"
10405 || aVal == "structures"
10406 || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures;
10407 else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups;
10408 else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
10409 else if (aVal == "tris"
10410 || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles;
10411 else if (aVal == "pnts"
10412 || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points;
10413 else if (aVal == "mem"
10414 || aVal == "gpumem"
10415 || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem;
10416 else if (aVal == "skipimmediate"
10417 || aVal == "noimmediate") aFlag = Graphic3d_RenderingParams::PerfCounters_SkipImmediate;
10418 else if (aVal == "frametime"
10419 || aVal == "frametimers"
10420 || aVal == "time") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameTime;
10421 else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic;
10422 else if (aVal == "extended"
10423 || aVal == "verbose"
10424 || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended;
10425 else if (aVal == "full"
10426 || aVal == "all") aFlag = Graphic3d_RenderingParams::PerfCounters_All;
10429 return Standard_False;
10434 theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag);
10438 theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag);
10440 return Standard_True;
10443 //! Read Graphic3d_RenderingParams::PerfCounters flags.
10444 static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue,
10445 Graphic3d_RenderingParams::PerfCounters& theFlags)
10447 TCollection_AsciiString aValue = theValue;
10448 Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE;
10449 Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE;
10450 Standard_Boolean toReset = Standard_False;
10453 Standard_Integer aSplitPos = aValue.Search ("|");
10454 if (aSplitPos <= 0)
10456 if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd))
10458 return Standard_False;
10462 theFlags = Graphic3d_RenderingParams::PerfCounters_NONE;
10464 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd);
10465 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem);
10466 return Standard_True;
10471 TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1);
10472 if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd))
10474 return Standard_False;
10477 aValue = aValue.SubString (aSplitPos + 1, aValue.Length());
10481 //=======================================================================
10482 //function : VRenderParams
10483 //purpose : Enables/disables rendering features
10484 //=======================================================================
10486 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
10487 Standard_Integer theArgNb,
10488 const char** theArgVec)
10490 Handle(V3d_View) aView = ViewerTest::CurrentView();
10491 if (aView.IsNull())
10493 std::cerr << "Error: no active viewer!\n";
10497 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
10498 TCollection_AsciiString aCmdName (theArgVec[0]);
10499 aCmdName.LowerCase();
10500 if (aCmdName == "vraytrace")
10504 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
10507 else if (theArgNb == 2)
10509 TCollection_AsciiString aValue (theArgVec[1]);
10510 aValue.LowerCase();
10514 aParams.Method = Graphic3d_RM_RAYTRACING;
10518 else if (aValue == "off"
10521 aParams.Method = Graphic3d_RM_RASTERIZATION;
10527 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
10533 std::cout << "Error: wrong number of arguments\n";
10540 theDI << "renderMode: ";
10541 switch (aParams.Method)
10543 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
10544 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
10547 theDI << "transparency: ";
10548 switch (aParams.TransparencyMethod)
10550 case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break;
10551 case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: "
10552 << TCollection_AsciiString (aParams.OitDepthFactor); break;
10555 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
10556 theDI << "rendScale: " << aParams.RenderResolutionScale << "\n";
10557 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
10558 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
10559 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
10560 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
10561 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
10562 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
10563 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
10564 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
10565 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
10566 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
10567 theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
10568 theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n";
10569 theDI << "tile size (iss):" << aParams.RayTracingTileSize << "x" << aParams.RayTracingTileSize << "\n";
10570 theDI << "shadingModel: ";
10571 switch (aView->ShadingModel())
10573 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
10574 case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break;
10575 case Graphic3d_TOSM_FACET: theDI << "flat"; break;
10576 case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break;
10577 case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break;
10580 theDI << "perfCounters:";
10581 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0)
10585 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
10589 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
10591 theDI << " structs";
10593 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0)
10595 theDI << " groups";
10597 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0)
10599 theDI << " arrays";
10601 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0)
10605 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
10609 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0)
10611 theDI << " gpumem";
10613 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameTime) != 0)
10615 theDI << " frameTime";
10617 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_SkipImmediate) != 0)
10619 theDI << " skipimmediate";
10621 if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE)
10627 theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n";
10628 theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n";
10629 theDI << "frustum culling: " << (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On ? "on" :
10630 aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off ? "off" :
10631 "noUpdate") << "\n";
10636 Standard_Boolean toPrint = Standard_False;
10637 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10638 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
10640 Standard_CString anArg (theArgVec[anArgIter]);
10641 TCollection_AsciiString aFlag (anArg);
10643 if (anUpdateTool.parseRedrawMode (aFlag))
10647 else if (aFlag == "-echo"
10648 || aFlag == "-print")
10650 toPrint = Standard_True;
10651 anUpdateTool.Invalidate();
10653 else if (aFlag == "-mode"
10654 || aFlag == "-rendermode"
10655 || aFlag == "-render_mode")
10659 switch (aParams.Method)
10661 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
10662 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
10668 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10672 else if (aFlag == "-ray"
10673 || aFlag == "-raytrace")
10677 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
10681 aParams.Method = Graphic3d_RM_RAYTRACING;
10683 else if (aFlag == "-rast"
10684 || aFlag == "-raster"
10685 || aFlag == "-rasterization")
10689 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
10693 aParams.Method = Graphic3d_RM_RASTERIZATION;
10695 else if (aFlag == "-msaa")
10699 theDI << aParams.NbMsaaSamples << " ";
10702 else if (++anArgIter >= theArgNb)
10704 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10708 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
10709 if (aNbSamples < 0)
10711 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
10716 aParams.NbMsaaSamples = aNbSamples;
10719 else if (aFlag == "-linefeather"
10720 || aFlag == "-edgefeather"
10721 || aFlag == "-feather")
10725 theDI << " " << aParams.LineFeather << " ";
10728 else if (++anArgIter >= theArgNb)
10730 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10734 TCollection_AsciiString aParam = theArgVec[anArgIter];
10735 const Standard_ShortReal aFeather = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
10736 if (aFeather <= 0.0f)
10738 std::cerr << "Error: invalid value of line width feather " << aFeather << ". Should be > 0\n";
10741 aParams.LineFeather = aFeather;
10743 else if (aFlag == "-oit")
10747 if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
10749 theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " ";
10753 theDI << "off" << " ";
10757 else if (++anArgIter >= theArgNb)
10759 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10763 TCollection_AsciiString aParam = theArgVec[anArgIter];
10764 aParam.LowerCase();
10765 if (aParam.IsRealValue())
10767 const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
10768 if (aWeight < 0.f || aWeight > 1.f)
10770 std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n";
10774 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
10775 aParams.OitDepthFactor = aWeight;
10777 else if (aParam == "off")
10779 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED;
10783 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10787 else if (aFlag == "-depthprepass")
10791 theDI << (aParams.ToEnableDepthPrepass ? "on " : "off ");
10794 aParams.ToEnableDepthPrepass = Standard_True;
10795 if (anArgIter + 1 < theArgNb
10796 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass))
10801 else if (aFlag == "-samplealphatocoverage"
10802 || aFlag == "-alphatocoverage")
10806 theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off ");
10809 aParams.ToEnableAlphaToCoverage = Standard_True;
10810 if (anArgIter + 1 < theArgNb
10811 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage))
10816 else if (aFlag == "-rendscale"
10817 || aFlag == "-renderscale"
10818 || aFlag == "-renderresolutionscale")
10822 theDI << aParams.RenderResolutionScale << " ";
10825 else if (++anArgIter >= theArgNb)
10827 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10831 const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
10834 std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n";
10839 aParams.RenderResolutionScale = Standard_ShortReal(aScale);
10842 else if (aFlag == "-raydepth"
10843 || aFlag == "-ray_depth")
10847 theDI << aParams.RaytracingDepth << " ";
10850 else if (++anArgIter >= theArgNb)
10852 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10856 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
10858 // We allow RaytracingDepth be more than 10 in case of GI enabled
10859 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
10861 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
10866 aParams.RaytracingDepth = aDepth;
10869 else if (aFlag == "-shad"
10870 || aFlag == "-shadows")
10874 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
10878 Standard_Boolean toEnable = Standard_True;
10879 if (++anArgIter < theArgNb
10880 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10884 aParams.IsShadowEnabled = toEnable;
10886 else if (aFlag == "-refl"
10887 || aFlag == "-reflections")
10891 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
10895 Standard_Boolean toEnable = Standard_True;
10896 if (++anArgIter < theArgNb
10897 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10901 aParams.IsReflectionEnabled = toEnable;
10903 else if (aFlag == "-fsaa")
10907 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
10911 Standard_Boolean toEnable = Standard_True;
10912 if (++anArgIter < theArgNb
10913 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10917 aParams.IsAntialiasingEnabled = toEnable;
10919 else if (aFlag == "-gleam")
10923 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
10927 Standard_Boolean toEnable = Standard_True;
10928 if (++anArgIter < theArgNb
10929 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10933 aParams.IsTransparentShadowEnabled = toEnable;
10935 else if (aFlag == "-gi")
10939 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
10943 Standard_Boolean toEnable = Standard_True;
10944 if (++anArgIter < theArgNb
10945 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10949 aParams.IsGlobalIlluminationEnabled = toEnable;
10952 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
10955 else if (aFlag == "-blockedrng"
10956 || aFlag == "-brng")
10960 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
10964 Standard_Boolean toEnable = Standard_True;
10965 if (++anArgIter < theArgNb
10966 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10970 aParams.CoherentPathTracingMode = toEnable;
10972 else if (aFlag == "-maxrad")
10976 theDI << aParams.RadianceClampingValue << " ";
10979 else if (++anArgIter >= theArgNb)
10981 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10985 const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
10986 if (!aMaxRadStr.IsRealValue())
10988 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10992 const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
10993 if (aMaxRadiance <= 0.0)
10995 std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n";
11000 aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
11003 else if (aFlag == "-iss")
11007 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
11011 Standard_Boolean toEnable = Standard_True;
11012 if (++anArgIter < theArgNb
11013 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11017 aParams.AdaptiveScreenSampling = toEnable;
11019 else if (aFlag == "-issatomic")
11023 theDI << (aParams.AdaptiveScreenSamplingAtomic ? "on" : "off") << " ";
11027 Standard_Boolean toEnable = Standard_True;
11028 if (++anArgIter < theArgNb
11029 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11033 aParams.AdaptiveScreenSamplingAtomic = toEnable;
11035 else if (aFlag == "-issd")
11039 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
11043 Standard_Boolean toEnable = Standard_True;
11044 if (++anArgIter < theArgNb
11045 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11049 aParams.ShowSamplingTiles = toEnable;
11051 else if (aFlag == "-tilesize")
11055 theDI << aParams.RayTracingTileSize << " ";
11058 else if (++anArgIter >= theArgNb)
11060 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11064 const Standard_Integer aTileSize = Draw::Atoi (theArgVec[anArgIter]);
11067 std::cerr << "Error: invalid size of ISS tile " << aTileSize << ".\n";
11070 aParams.RayTracingTileSize = aTileSize;
11072 else if (aFlag == "-nbtiles")
11076 theDI << aParams.NbRayTracingTiles << " ";
11079 else if (++anArgIter >= theArgNb)
11081 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11085 const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]);
11088 std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n";
11091 else if (aNbTiles > 0
11093 || aNbTiles > 1024))
11095 std::cerr << "Warning: suboptimal number of ISS tiles " << aNbTiles << ". Recommended range: [64, 1024].\n";
11097 aParams.NbRayTracingTiles = aNbTiles;
11099 else if (aFlag == "-env")
11103 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
11107 Standard_Boolean toEnable = Standard_True;
11108 if (++anArgIter < theArgNb
11109 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11113 aParams.UseEnvironmentMapBackground = toEnable;
11115 else if (aFlag == "-twoside")
11119 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
11123 Standard_Boolean toEnable = Standard_True;
11124 if (++anArgIter < theArgNb
11125 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11129 aParams.TwoSidedBsdfModels = toEnable;
11131 else if (aFlag == "-shademodel"
11132 || aFlag == "-shadingmodel"
11133 || aFlag == "-shading")
11137 switch (aView->ShadingModel())
11139 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
11140 case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break;
11141 case Graphic3d_TOSM_FACET: theDI << "flat "; break;
11142 case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break;
11143 case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break;
11148 if (++anArgIter >= theArgNb)
11150 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11153 Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT;
11154 if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel)
11155 && aModel != Graphic3d_TOSM_DEFAULT)
11157 aView->SetShadingModel (aModel);
11161 std::cout << "Error: unknown shading model '" << theArgVec[anArgIter] << "'\n";
11165 else if (aFlag == "-resolution")
11167 if (++anArgIter >= theArgNb)
11169 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11173 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
11174 if (aResolution.IsIntegerValue())
11176 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
11180 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11184 else if (aFlag == "-rebuildglsl"
11185 || aFlag == "-rebuild")
11189 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
11193 Standard_Boolean toEnable = Standard_True;
11194 if (++anArgIter < theArgNb
11195 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11199 aParams.RebuildRayTracingShaders = toEnable;
11201 else if (aFlag == "-focal")
11203 if (++anArgIter >= theArgNb)
11205 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11209 TCollection_AsciiString aParam (theArgVec[anArgIter]);
11210 if (aParam.IsRealValue())
11212 float aFocalDist = static_cast<float> (aParam.RealValue());
11213 if (aFocalDist < 0)
11215 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
11218 aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist;
11222 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11226 else if (aFlag == "-aperture")
11228 if (++anArgIter >= theArgNb)
11230 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11234 TCollection_AsciiString aParam(theArgVec[anArgIter]);
11235 if (aParam.IsRealValue())
11237 float aApertureSize = static_cast<float> (aParam.RealValue());
11238 if (aApertureSize < 0)
11240 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
11243 aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize;
11247 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11251 else if (aFlag == "-exposure")
11253 if (++anArgIter >= theArgNb)
11255 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11259 TCollection_AsciiString anExposure (theArgVec[anArgIter]);
11260 if (anExposure.IsRealValue())
11262 aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
11266 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11270 else if (aFlag == "-whitepoint")
11272 if (++anArgIter >= theArgNb)
11274 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11278 TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
11279 if (aWhitePoint.IsRealValue())
11281 aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
11285 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11289 else if (aFlag == "-tonemapping")
11291 if (++anArgIter >= theArgNb)
11293 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11297 TCollection_AsciiString aMode (theArgVec[anArgIter]);
11300 if (aMode == "disabled")
11302 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled;
11304 else if (aMode == "filmic")
11306 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;
11310 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11314 else if (aFlag == "-performancestats"
11315 || aFlag == "-performancecounters"
11316 || aFlag == "-perfstats"
11317 || aFlag == "-perfcounters"
11318 || aFlag == "-stats")
11320 if (++anArgIter >= theArgNb)
11322 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11326 TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]);
11327 aFlagsStr.LowerCase();
11328 Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats;
11329 if (!convertToPerfStatsFlags (aFlagsStr, aFlags))
11331 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11334 aView->ChangeRenderingParams().CollectedStats = aFlags;
11335 aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE;
11337 else if (aFlag == "-perfupdateinterval"
11338 || aFlag == "-statsupdateinterval")
11340 if (++anArgIter >= theArgNb)
11342 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11345 aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
11347 else if (aFlag == "-perfchart"
11348 || aFlag == "-statschart")
11350 if (++anArgIter >= theArgNb)
11352 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11355 aView->ChangeRenderingParams().StatsNbFrames = Draw::Atoi (theArgVec[anArgIter]);
11357 else if (aFlag == "-perfchartmax"
11358 || aFlag == "-statschartmax")
11360 if (++anArgIter >= theArgNb)
11362 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11365 aView->ChangeRenderingParams().StatsMaxChartTime = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
11367 else if (aFlag == "-frustumculling"
11368 || aFlag == "-culling")
11372 theDI << ((aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On) ? "on" :
11373 (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off) ? "off" :
11374 "noUpdate") << " ";
11378 Graphic3d_RenderingParams::FrustumCulling aState = Graphic3d_RenderingParams::FrustumCulling_On;
11379 if (++anArgIter < theArgNb)
11381 TCollection_AsciiString aStateStr(theArgVec[anArgIter]);
11382 aStateStr.LowerCase();
11383 bool toEnable = true;
11384 if (ViewerTest::ParseOnOff (aStateStr.ToCString(), toEnable))
11386 aState = toEnable ? Graphic3d_RenderingParams::FrustumCulling_On : Graphic3d_RenderingParams::FrustumCulling_Off;
11388 else if (aStateStr == "noupdate"
11389 || aStateStr == "freeze")
11391 aState = Graphic3d_RenderingParams::FrustumCulling_NoUpdate;
11398 aParams.FrustumCullingState = aState;
11402 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
11410 //=======================================================================
11411 //function : searchInfo
11413 //=======================================================================
11414 inline TCollection_AsciiString searchInfo (const TColStd_IndexedDataMapOfStringString& theDict,
11415 const TCollection_AsciiString& theKey)
11417 for (TColStd_IndexedDataMapOfStringString::Iterator anIter (theDict); anIter.More(); anIter.Next())
11419 if (TCollection_AsciiString::IsSameString (anIter.Key(), theKey, Standard_False))
11421 return anIter.Value();
11424 return TCollection_AsciiString();
11427 //=======================================================================
11428 //function : VStatProfiler
11430 //=======================================================================
11431 static Standard_Integer VStatProfiler (Draw_Interpretor& theDI,
11432 Standard_Integer theArgNb,
11433 const char** theArgVec)
11435 Handle(V3d_View) aView = ViewerTest::CurrentView();
11436 if (aView.IsNull())
11438 std::cerr << "Error: no active viewer!\n";
11442 Standard_Boolean toRedraw = Standard_True;
11443 Graphic3d_RenderingParams::PerfCounters aPrevCounters = aView->ChangeRenderingParams().CollectedStats;
11444 Standard_ShortReal aPrevUpdInterval = aView->ChangeRenderingParams().StatsUpdateInterval;
11445 Graphic3d_RenderingParams::PerfCounters aRenderParams = Graphic3d_RenderingParams::PerfCounters_NONE;
11446 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
11448 Standard_CString anArg (theArgVec[anArgIter]);
11449 TCollection_AsciiString aFlag (anArg);
11451 if (aFlag == "-noredraw")
11453 toRedraw = Standard_False;
11457 Graphic3d_RenderingParams::PerfCounters aParam = Graphic3d_RenderingParams::PerfCounters_NONE;
11458 if (aFlag == "fps") aParam = Graphic3d_RenderingParams::PerfCounters_FrameRate;
11459 else if (aFlag == "cpu") aParam = Graphic3d_RenderingParams::PerfCounters_CPU;
11460 else if (aFlag == "alllayers"
11461 || aFlag == "layers") aParam = Graphic3d_RenderingParams::PerfCounters_Layers;
11462 else if (aFlag == "allstructs"
11463 || aFlag == "structs") aParam = Graphic3d_RenderingParams::PerfCounters_Structures;
11464 else if (aFlag == "groups") aParam = Graphic3d_RenderingParams::PerfCounters_Groups;
11465 else if (aFlag == "allarrays"
11466 || aFlag == "fillarrays"
11467 || aFlag == "linearrays"
11468 || aFlag == "pointarrays"
11469 || aFlag == "textarrays") aParam = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
11470 else if (aFlag == "triangles") aParam = Graphic3d_RenderingParams::PerfCounters_Triangles;
11471 else if (aFlag == "points") aParam = Graphic3d_RenderingParams::PerfCounters_Points;
11472 else if (aFlag == "geommem"
11473 || aFlag == "texturemem"
11474 || aFlag == "framemem") aParam = Graphic3d_RenderingParams::PerfCounters_EstimMem;
11475 else if (aFlag == "elapsedframe"
11476 || aFlag == "cpuframeaverage"
11477 || aFlag == "cpupickingaverage"
11478 || aFlag == "cpucullingaverage"
11479 || aFlag == "cpudynaverage"
11480 || aFlag == "cpuframemax"
11481 || aFlag == "cpupickingmax"
11482 || aFlag == "cpucullingmax"
11483 || aFlag == "cpudynmax") aParam = Graphic3d_RenderingParams::PerfCounters_FrameTime;
11486 std::cerr << "Unknown argument '" << theArgVec[anArgIter] << "'!\n";
11490 aRenderParams = Graphic3d_RenderingParams::PerfCounters (aRenderParams | aParam);
11494 if (aRenderParams != Graphic3d_RenderingParams::PerfCounters_NONE)
11496 aView->ChangeRenderingParams().CollectedStats =
11497 Graphic3d_RenderingParams::PerfCounters (aView->RenderingParams().CollectedStats | aRenderParams);
11501 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
11503 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
11506 TColStd_IndexedDataMapOfStringString aDict;
11507 aView->StatisticInformation (aDict);
11509 aView->ChangeRenderingParams().CollectedStats = aPrevCounters;
11511 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
11513 Standard_CString anArg(theArgVec[anArgIter]);
11514 TCollection_AsciiString aFlag(anArg);
11516 if (aFlag == "fps")
11518 theDI << searchInfo (aDict, "FPS") << " ";
11520 else if (aFlag == "cpu")
11522 theDI << searchInfo (aDict, "CPU FPS") << " ";
11524 else if (aFlag == "alllayers")
11526 theDI << searchInfo (aDict, "Layers") << " ";
11528 else if (aFlag == "layers")
11530 theDI << searchInfo (aDict, "Rendered layers") << " ";
11532 else if (aFlag == "allstructs")
11534 theDI << searchInfo (aDict, "Structs") << " ";
11536 else if (aFlag == "structs")
11538 theDI << searchInfo (aDict, "Rendered structs") << " ";
11540 else if (aFlag == "groups")
11542 theDI << searchInfo (aDict, "Rendered groups") << " ";
11544 else if (aFlag == "allarrays")
11546 theDI << searchInfo (aDict, "Rendered arrays") << " ";
11548 else if (aFlag == "fillarrays")
11550 theDI << searchInfo (aDict, "Rendered [fill] arrays") << " ";
11552 else if (aFlag == "linearrays")
11554 theDI << searchInfo (aDict, "Rendered [line] arrays") << " ";
11556 else if (aFlag == "pointarrays")
11558 theDI << searchInfo (aDict, "Rendered [point] arrays") << " ";
11560 else if (aFlag == "textarrays")
11562 theDI << searchInfo (aDict, "Rendered [text] arrays") << " ";
11564 else if (aFlag == "triangles")
11566 theDI << searchInfo (aDict, "Rendered triangles") << " ";
11568 else if (aFlag == "points")
11570 theDI << searchInfo (aDict, "Rendered points") << " ";
11572 else if (aFlag == "geommem")
11574 theDI << searchInfo (aDict, "GPU Memory [geometry]") << " ";
11576 else if (aFlag == "texturemem")
11578 theDI << searchInfo (aDict, "GPU Memory [textures]") << " ";
11580 else if (aFlag == "framemem")
11582 theDI << searchInfo (aDict, "GPU Memory [frames]") << " ";
11584 else if (aFlag == "elapsedframe")
11586 theDI << searchInfo (aDict, "Elapsed Frame (average)") << " ";
11588 else if (aFlag == "cpuframe_average")
11590 theDI << searchInfo (aDict, "CPU Frame (average)") << " ";
11592 else if (aFlag == "cpupicking_average")
11594 theDI << searchInfo (aDict, "CPU Picking (average)") << " ";
11596 else if (aFlag == "cpuculling_average")
11598 theDI << searchInfo (aDict, "CPU Culling (average)") << " ";
11600 else if (aFlag == "cpudyn_average")
11602 theDI << searchInfo (aDict, "CPU Dynamics (average)") << " ";
11604 else if (aFlag == "cpuframe_max")
11606 theDI << searchInfo (aDict, "CPU Frame (max)") << " ";
11608 else if (aFlag == "cpupicking_max")
11610 theDI << searchInfo (aDict, "CPU Picking (max)") << " ";
11612 else if (aFlag == "cpuculling_max")
11614 theDI << searchInfo (aDict, "CPU Culling (max)") << " ";
11616 else if (aFlag == "cpudyn_max")
11618 theDI << searchInfo (aDict, "CPU Dynamics (max)") << " ";
11626 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
11628 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
11630 theDI << "Statistic info:\n" << aView->StatisticInformation();
11635 //=======================================================================
11636 //function : VProgressiveMode
11638 //=======================================================================
11639 #if defined(_WIN32)
11640 static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
11641 Standard_Integer /*theNbArgs*/,
11642 const char** /*theArgs*/)
11644 Handle(V3d_View) aView = ViewerTest::CurrentView();
11645 if (aView.IsNull())
11647 std::cerr << "Error: no active viewer!\n";
11651 std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
11657 Standard_Boolean toExit = Standard_False;
11660 while (PeekMessageW (&aMsg, NULL, 0, 0, PM_REMOVE))
11662 if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
11664 toExit = Standard_True;
11667 TranslateMessage (&aMsg);
11668 DispatchMessageW (&aMsg);
11681 //=======================================================================
11682 //function : VXRotate
11684 //=======================================================================
11685 static Standard_Integer VXRotate (Draw_Interpretor& di,
11686 Standard_Integer argc,
11687 const char ** argv)
11689 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
11690 if (aContext.IsNull())
11692 di << argv[0] << "ERROR : use 'vinit' command before \n";
11698 di << "ERROR : Usage : " << argv[0] << " name angle\n";
11702 TCollection_AsciiString aName (argv[1]);
11703 Standard_Real anAngle = Draw::Atof (argv[2]);
11706 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
11707 Handle(AIS_InteractiveObject) anIObj;
11708 if (!aMap.Find2 (aName, anIObj))
11710 di << "Use 'vdisplay' before\n";
11714 gp_Trsf aTransform;
11715 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
11716 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
11718 aContext->SetLocation (anIObj, aTransform);
11719 aContext->UpdateCurrentViewer();
11723 //===============================================================================================
11724 //class : ViewerTest_AISManipulator
11725 //purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances
11726 //===============================================================================================
11727 DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
11729 class ViewerTest_AISManipulator : public AIS_Manipulator
11733 ViewerTest_AISManipulator() : AIS_Manipulator()
11735 GetMapOfAISManipulators().Add (this);
11738 virtual ~ViewerTest_AISManipulator()
11740 GetMapOfAISManipulators().Remove (this);
11743 DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
11746 IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
11747 IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
11749 //===============================================================================================
11750 //function : VManipulator
11752 //===============================================================================================
11753 static int VManipulator (Draw_Interpretor& theDi,
11754 Standard_Integer theArgsNb,
11755 const char** theArgVec)
11757 Handle(V3d_View) aView = ViewerTest::CurrentView();
11758 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
11759 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
11761 || aViewer.IsNull())
11763 std::cerr << "No active viewer!\n";
11767 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
11768 Standard_Integer anArgIter = 1;
11769 for (; anArgIter < theArgsNb; ++anArgIter)
11771 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
11774 ViewerTest_CmdParser aCmd;
11775 aCmd.AddDescription ("Manages manipulator for interactive objects:");
11776 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
11777 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
11778 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
11779 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
11780 aCmd.AddOption ("detach", "... - detach manipulator");
11782 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
11783 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
11784 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
11786 aCmd.AddOption ("move", "... x y z - move object");
11787 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
11788 aCmd.AddOption ("scale", "... factor - scale object");
11790 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
11791 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
11792 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
11793 aCmd.AddOption ("followDragging", "... {0|1} - set following dragging transform");
11794 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
11795 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
11796 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
11797 aCmd.AddOption ("size", "... size - set size of manipulator");
11798 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
11800 aCmd.Parse (theArgsNb, theArgVec);
11802 if (aCmd.HasOption ("help"))
11804 theDi.PrintHelp (theArgVec[0]);
11808 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
11810 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
11812 if (aName.IsEmpty())
11814 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
11818 // ----------------------------------
11819 // detach existing manipulator object
11820 // ----------------------------------
11822 if (aCmd.HasOption ("detach"))
11824 if (!aMapAIS.IsBound2 (aName))
11826 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
11830 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
11831 if (aManipulator.IsNull())
11833 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
11837 aManipulator->Detach();
11838 aMapAIS.UnBind2 (aName);
11839 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True);
11844 // -----------------------------------------------
11845 // find or create manipulator if it does not exist
11846 // -----------------------------------------------
11848 Handle(AIS_Manipulator) aManipulator;
11849 if (!aMapAIS.IsBound2 (aName))
11851 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
11853 aManipulator = new ViewerTest_AISManipulator();
11854 aMapAIS.Bind (aManipulator, aName);
11858 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
11859 if (aManipulator.IsNull())
11861 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
11866 // -----------------------------------------
11867 // change properties of manipulator instance
11868 // -----------------------------------------
11870 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
11872 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
11874 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
11876 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
11878 if (aCmd.HasOption ("followRotation", 1, Standard_True))
11880 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
11882 if (aCmd.HasOption("followDragging", 1, Standard_True))
11884 aManipulator->ChangeTransformBehavior().SetFollowDragging(aCmd.ArgBool("followDragging"));
11886 if (aCmd.HasOption ("gap", 1, Standard_True))
11888 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
11890 if (aCmd.HasOption ("part", 3, Standard_True))
11892 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
11893 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
11894 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
11895 if (aMode < 1 || aMode > 4)
11897 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 4].\n";
11901 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
11903 if (aCmd.HasOption ("pos", 3, Standard_True))
11905 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
11906 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
11907 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
11909 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
11911 if (aCmd.HasOption ("size", 1, Standard_True))
11913 aManipulator->SetSize (aCmd.ArgFloat ("size"));
11915 if (aCmd.HasOption ("zoomable", 1, Standard_True))
11917 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
11919 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
11921 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
11922 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
11926 // ---------------------------------------------------
11927 // attach, detach or access manipulator from an object
11928 // ---------------------------------------------------
11930 if (aCmd.HasOption ("attach"))
11932 // Find an object and attach manipulator to it
11933 if (!aCmd.HasOption ("attach", 1, Standard_True))
11938 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
11939 Handle(AIS_InteractiveObject) anObject;
11940 if (!aMapAIS.Find2 (anObjName, anObject))
11942 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
11946 for (ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators()); anIt.More(); anIt.Next())
11948 if (anIt.Value()->IsAttached()
11949 && anIt.Value()->Object() == anObject)
11951 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
11956 AIS_Manipulator::OptionsForAttach anOptions;
11957 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
11959 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
11961 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
11963 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
11965 if (aCmd.HasOption ("enableModes", 1, Standard_True))
11967 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
11970 aManipulator->Attach (anObject, anOptions);
11973 // --------------------------------------
11974 // apply transformation using manipulator
11975 // --------------------------------------
11977 if (aCmd.HasOption ("startTransform", 2, Standard_True))
11979 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
11981 if (aCmd.HasOption ("transform", 2, Standard_True))
11983 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
11985 if (aCmd.HasOption ("stopTransform"))
11987 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
11989 aManipulator->StopTransform (toApply);
11993 if (aCmd.HasOption ("move", 3, Standard_True))
11995 aT.SetTranslationPart (aCmd.ArgVec ("move"));
11997 if (aCmd.HasOption ("rotate", 7, Standard_True))
11999 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
12001 if (aCmd.HasOption ("scale", 1))
12003 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
12006 if (aT.Form() != gp_Identity)
12008 aManipulator->Transform (aT);
12011 ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True);
12016 //===============================================================================================
12017 //function : VSelectionProperties
12019 //===============================================================================================
12020 static int VSelectionProperties (Draw_Interpretor& theDi,
12021 Standard_Integer theArgsNb,
12022 const char** theArgVec)
12024 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
12027 std::cerr << "No active viewer!\n";
12031 if (TCollection_AsciiString (theArgVec[0]) == "vhighlightselected")
12033 // handle obsolete alias
12034 bool toEnable = true;
12037 theDi << (aCtx->ToHilightSelected() ? "on" : "off");
12040 else if (theArgsNb != 2
12041 || !ViewerTest::ParseOnOff (theArgVec[1], toEnable))
12043 std::cout << "Syntax error: wrong number of parameters.";
12046 if (toEnable != aCtx->ToHilightSelected())
12048 aCtx->ClearDetected();
12049 aCtx->SetToHilightSelected (toEnable);
12054 Standard_Boolean toPrint = theArgsNb == 1;
12055 Standard_Boolean toRedraw = Standard_False;
12056 Standard_Integer anArgIter = 1;
12057 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
12058 if (anArgIter < theArgsNb)
12060 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
12061 anArgFirst.LowerCase();
12063 if (anArgFirst == "dynhighlight"
12064 || anArgFirst == "dynhilight"
12065 || anArgFirst == "dynamichighlight"
12066 || anArgFirst == "dynamichilight")
12068 aType = Prs3d_TypeOfHighlight_Dynamic;
12070 else if (anArgFirst == "localdynhighlight"
12071 || anArgFirst == "localdynhilight"
12072 || anArgFirst == "localdynamichighlight"
12073 || anArgFirst == "localdynamichilight")
12075 aType = Prs3d_TypeOfHighlight_LocalDynamic;
12077 else if (anArgFirst == "selhighlight"
12078 || anArgFirst == "selhilight"
12079 || anArgFirst == "selectedhighlight"
12080 || anArgFirst == "selectedhilight")
12082 aType = Prs3d_TypeOfHighlight_Selected;
12084 else if (anArgFirst == "localselhighlight"
12085 || anArgFirst == "localselhilight"
12086 || anArgFirst == "localselectedhighlight"
12087 || anArgFirst == "localselectedhilight")
12089 aType = Prs3d_TypeOfHighlight_LocalSelected;
12096 for (; anArgIter < theArgsNb; ++anArgIter)
12098 TCollection_AsciiString anArg (theArgVec[anArgIter]);
12100 if (anArg == "-help")
12102 theDi.PrintHelp (theArgVec[0]);
12105 else if (anArg == "-print")
12107 toPrint = Standard_True;
12109 else if (anArg == "-autoactivate")
12111 Standard_Boolean toEnable = Standard_True;
12112 if (anArgIter + 1 < theArgsNb
12113 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12117 aCtx->SetAutoActivateSelection (toEnable);
12119 else if (anArg == "-automatichighlight"
12120 || anArg == "-automatichilight"
12121 || anArg == "-autohighlight"
12122 || anArg == "-autohilight")
12124 Standard_Boolean toEnable = Standard_True;
12125 if (anArgIter + 1 < theArgsNb
12126 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12130 aCtx->ClearSelected (false);
12131 aCtx->ClearDetected();
12132 aCtx->SetAutomaticHilight (toEnable);
12135 else if (anArg == "-highlightselected"
12136 || anArg == "-hilightselected")
12138 Standard_Boolean toEnable = Standard_True;
12139 if (anArgIter + 1 < theArgsNb
12140 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12144 aCtx->ClearDetected();
12145 aCtx->SetToHilightSelected (toEnable);
12148 else if (anArg == "-pickstrategy"
12149 || anArg == "-pickingstrategy")
12151 if (++anArgIter >= theArgsNb)
12153 std::cout << "Syntax error: type of highlighting is undefined\n";
12157 SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
12158 TCollection_AsciiString aVal (theArgVec[anArgIter]);
12160 if (aVal == "first"
12161 || aVal == "firstaccepted"
12162 || aVal == "firstacceptable")
12164 aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
12166 else if (aVal == "topmost"
12167 || aVal == "onlyTopmost")
12169 aStrategy = SelectMgr_PickingStrategy_OnlyTopmost;
12173 std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n";
12177 aCtx->SetPickingStrategy (aStrategy);
12179 else if (anArg == "-pixtol"
12180 && anArgIter + 1 < theArgsNb)
12182 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
12184 else if ((anArg == "-mode"
12185 || anArg == "-dispmode")
12186 && anArgIter + 1 < theArgsNb)
12188 if (aType == Prs3d_TypeOfHighlight_None)
12190 std::cout << "Syntax error: type of highlighting is undefined\n";
12194 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
12195 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12196 aStyle->SetDisplayMode (aDispMode);
12197 toRedraw = Standard_True;
12199 else if (anArg == "-layer"
12200 && anArgIter + 1 < theArgsNb)
12202 if (aType == Prs3d_TypeOfHighlight_None)
12204 std::cout << "Syntax error: type of highlighting is undefined\n";
12209 Graphic3d_ZLayerId aNewLayer = Graphic3d_ZLayerId_UNKNOWN;
12210 if (!ViewerTest::ParseZLayer (theArgVec[anArgIter], aNewLayer))
12212 std::cerr << "Error: wrong syntax at " << theArgVec[anArgIter] << ".\n";
12216 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12217 aStyle->SetZLayer (aNewLayer);
12218 toRedraw = Standard_True;
12220 else if (anArg == "-hicolor"
12221 || anArg == "-selcolor"
12222 || anArg == "-color")
12224 if (anArg.StartsWith ("-hi"))
12226 aType = Prs3d_TypeOfHighlight_Dynamic;
12228 else if (anArg.StartsWith ("-sel"))
12230 aType = Prs3d_TypeOfHighlight_Selected;
12232 else if (aType == Prs3d_TypeOfHighlight_None)
12234 std::cout << "Syntax error: type of highlighting is undefined\n";
12238 Quantity_Color aColor;
12239 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1,
12240 theArgVec + anArgIter + 1,
12242 if (aNbParsed == 0)
12244 std::cout << "Syntax error: need more arguments.\n";
12247 anArgIter += aNbParsed;
12249 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12250 aStyle->SetColor (aColor);
12251 toRedraw = Standard_True;
12253 else if ((anArg == "-transp"
12254 || anArg == "-transparency"
12255 || anArg == "-hitransp"
12256 || anArg == "-seltransp"
12257 || anArg == "-hitransplocal"
12258 || anArg == "-seltransplocal")
12259 && anArgIter + 1 < theArgsNb)
12261 if (anArg.StartsWith ("-hi"))
12263 aType = Prs3d_TypeOfHighlight_Dynamic;
12265 else if (anArg.StartsWith ("-sel"))
12267 aType = Prs3d_TypeOfHighlight_Selected;
12269 else if (aType == Prs3d_TypeOfHighlight_None)
12271 std::cout << "Syntax error: type of highlighting is undefined\n";
12275 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
12276 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12277 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
12278 toRedraw = Standard_True;
12280 else if ((anArg == "-mat"
12281 || anArg == "-material")
12282 && anArgIter + 1 < theArgsNb)
12284 if (aType == Prs3d_TypeOfHighlight_None)
12286 std::cout << "Syntax error: type of highlighting is undefined\n";
12290 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12291 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
12292 if (aMatName != Graphic3d_NOM_DEFAULT)
12295 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
12296 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
12297 Graphic3d_MaterialAspect aMat (aMatName);
12298 aMat.SetColor (aStyle->Color());
12299 aMat.SetTransparency (aStyle->Transparency());
12300 anAspect->SetFrontMaterial (aMat);
12301 anAspect->SetInteriorColor (aStyle->Color());
12302 aStyle->SetBasicFillAreaAspect (anAspect);
12306 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
12308 toRedraw = Standard_True;
12312 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
12318 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
12319 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
12320 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
12321 theDi << "Auto-highlight : " << (aCtx->AutomaticHilight() ? "On" : "Off") << "\n";
12322 theDi << "Highlight selected : " << (aCtx->ToHilightSelected() ? "On" : "Off") << "\n";
12323 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
12324 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
12325 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
12326 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
12327 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
12328 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
12329 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
12330 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
12331 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
12334 if (aCtx->NbSelected() != 0 && toRedraw)
12336 aCtx->HilightSelected (Standard_True);
12342 //===============================================================================================
12343 //function : VDumpSelectionImage
12345 //===============================================================================================
12346 static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
12347 Standard_Integer theArgsNb,
12348 const char** theArgVec)
12352 std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
12356 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
12357 if (aContext.IsNull())
12359 std::cout << "Error: no active view.\n";
12363 TCollection_AsciiString aFile;
12364 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
12365 Image_Format anImgFormat = Image_Format_BGR;
12366 Standard_Integer aPickedIndex = 1;
12367 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
12369 TCollection_AsciiString aParam (theArgVec[anArgIter]);
12370 aParam.LowerCase();
12371 if (aParam == "-type")
12373 if (++anArgIter >= theArgsNb)
12375 std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n";
12379 TCollection_AsciiString aValue (theArgVec[anArgIter]);
12380 aValue.LowerCase();
12381 if (aValue == "depth"
12382 || aValue == "normdepth"
12383 || aValue == "normalizeddepth")
12385 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
12386 anImgFormat = Image_Format_GrayF;
12388 if (aValue == "depthinverted"
12389 || aValue == "normdepthinverted"
12390 || aValue == "normalizeddepthinverted"
12391 || aValue == "inverted")
12393 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
12394 anImgFormat = Image_Format_GrayF;
12396 else if (aValue == "unnormdepth"
12397 || aValue == "unnormalizeddepth")
12399 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
12400 anImgFormat = Image_Format_GrayF;
12402 else if (aValue == "objectcolor"
12403 || aValue == "object"
12404 || aValue == "color")
12406 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
12408 else if (aValue == "entitycolor"
12409 || aValue == "entity")
12411 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
12413 else if (aValue == "ownercolor"
12414 || aValue == "owner")
12416 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
12418 else if (aValue == "selectionmodecolor"
12419 || aValue == "selectionmode"
12420 || aValue == "selmodecolor"
12421 || aValue == "selmode")
12423 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
12426 else if (aParam == "-picked"
12427 || aParam == "-pickeddepth"
12428 || aParam == "-pickedindex")
12430 if (++anArgIter >= theArgsNb)
12432 std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n";
12436 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
12438 else if (aFile.IsEmpty())
12440 aFile = theArgVec[anArgIter];
12444 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n";
12448 if (aFile.IsEmpty())
12450 std::cout << "Syntax error: image file name is missing.\n";
12454 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
12455 Standard_Integer aWidth = 0, aHeight = 0;
12456 aView->Window()->Size (aWidth, aHeight);
12458 Image_AlienPixMap aPixMap;
12459 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
12461 std::cout << "Error: can't allocate image.\n";
12464 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
12466 std::cout << "Error: can't generate selection image.\n";
12469 if (!aPixMap.Save (aFile))
12471 std::cout << "Error: can't save selection image.\n";
12477 //=======================================================================
12478 //function : ViewerCommands
12480 //=======================================================================
12482 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
12485 const char *group = "ZeViewer";
12486 theCommands.Add("vinit",
12487 "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]"
12488 "\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]"
12489 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
12490 "\n\t\t: [-display displayName]"
12492 "\n\t\t: Creates new View window with specified name viewName."
12493 "\n\t\t: By default the new view is created in the viewer and in"
12494 "\n\t\t: graphic driver shared with active view."
12495 "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}"
12496 "\n\t\t: If driverName isn't specified the driver will be shared with active view."
12497 "\n\t\t: If viewerName isn't specified the viewer will be shared with active view."
12498 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
12499 "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]"
12500 "\n\t\t: Display name will be used within creation of graphic driver, when specified."
12502 "\n\t\t: -left, -top pixel position of left top corner of the window."
12503 "\n\t\t: -width, -height width and heigth of window respectively."
12504 "\n\t\t: -cloneActive floag to copy camera and dimensions of active view."
12505 "\n\t\t: -exitOnClose when specified, closing the view will exit application."
12506 "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape."
12507 "\n\t\t: -2d_mode when on, view will not react on rotate scene events"
12508 "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.",
12509 __FILE__,VInit,group);
12510 theCommands.Add("vclose" ,
12511 "[view_id [keep_context=0|1]]\n"
12512 "or vclose ALL - to remove all created views\n"
12513 " - removes view(viewer window) defined by its view_id.\n"
12514 " - keep_context: by default 0; if 1 and the last view is deleted"
12515 " the current context is not removed.",
12516 __FILE__,VClose,group);
12517 theCommands.Add("vactivate" ,
12518 "vactivate view_id [-noUpdate]"
12519 " - activates view(viewer window) defined by its view_id",
12520 __FILE__,VActivate,group);
12521 theCommands.Add("vviewlist",
12522 "vviewlist [format={tree, long}]"
12523 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
12524 " - format: format of result output, if tree the output is a tree view;"
12525 "otherwise it's a list of full view names. By default format = tree",
12526 __FILE__,VViewList,group);
12527 theCommands.Add("vhelp" ,
12528 "vhelp : display help on the viewer commands",
12529 __FILE__,VHelp,group);
12530 theCommands.Add("vtop" ,
12531 "vtop or <T> : Top view. Orientation +X+Y" ,
12532 __FILE__,VTop,group);
12533 theCommands.Add("vbottom" ,
12534 "vbottom : Bottom view. Orientation +X-Y" ,
12535 __FILE__,VBottom,group);
12536 theCommands.Add("vleft" ,
12537 "vleft : Left view. Orientation -Y+Z" ,
12538 __FILE__,VLeft,group);
12539 theCommands.Add("vright" ,
12540 "vright : Right view. Orientation +Y+Z" ,
12541 __FILE__,VRight,group);
12542 theCommands.Add("vaxo" ,
12543 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
12544 __FILE__,VAxo,group);
12545 theCommands.Add("vfront" ,
12546 "vfront : Front view. Orientation +X+Z" ,
12547 __FILE__,VFront,group);
12548 theCommands.Add("vback" ,
12549 "vback : Back view. Orientation -X+Z" ,
12550 __FILE__,VBack,group);
12551 theCommands.Add("vpick" ,
12552 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
12554 theCommands.Add("vfit",
12555 "vfit or <F> [-selected] [-noupdate]"
12556 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
12557 __FILE__,VFit,group);
12558 theCommands.Add ("vfitarea",
12559 "vfitarea x1 y1 x2 y2"
12560 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
12561 "\n\t\t: Fit view to show area located between two points"
12562 "\n\t\t: given in world 2D or 3D corrdinates.",
12563 __FILE__, VFitArea, group);
12564 theCommands.Add ("vzfit", "vzfit [scale]\n"
12565 " Matches Z near, Z far view volume planes to the displayed objects.\n"
12566 " \"scale\" - specifies factor to scale computed z range.\n",
12567 __FILE__, VZFit, group);
12568 theCommands.Add("vrepaint",
12569 "vrepaint [-immediate]"
12570 "\n\t\t: force redraw",
12571 __FILE__,VRepaint,group);
12572 theCommands.Add("vclear",
12574 "\n\t\t: remove all the object from the viewer",
12575 __FILE__,VClear,group);
12576 theCommands.Add("vsetbg",
12577 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
12578 __FILE__,VSetBg,group);
12579 theCommands.Add("vsetbgmode",
12580 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
12581 __FILE__,VSetBgMode,group);
12582 theCommands.Add("vsetgradientbg",
12583 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
12584 __FILE__,VSetGradientBg,group);
12585 theCommands.Add("vsetgrbgmode",
12586 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
12587 __FILE__,VSetGradientBgMode,group);
12588 theCommands.Add("vsetcolorbg",
12589 "vsetcolorbg : vsetcolorbg r g b : Set background color",
12590 __FILE__,VSetColorBg,group);
12591 theCommands.Add("vsetdefaultbg",
12592 "vsetdefaultbg r g b\n"
12593 "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode"
12594 "\n\t\t: Set default viewer background fill color (flat/gradient).",
12595 __FILE__,VSetDefaultBg,group);
12596 theCommands.Add("vscale",
12597 "vscale : vscale X Y Z",
12598 __FILE__,VScale,group);
12599 theCommands.Add("vzbufftrihedron",
12600 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
12601 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
12602 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
12603 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
12604 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
12605 "\n\t\t: Displays a trihedron",
12606 __FILE__,VZBuffTrihedron,group);
12607 theCommands.Add("vrotate",
12608 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
12609 "\n : Option -mouseStart starts rotation according to the mouse position"
12610 "\n : Option -mouseMove continues rotation with angle computed"
12611 "\n : from last and new mouse position."
12612 "\n : vrotate AX AY AZ [X Y Z]",
12613 __FILE__,VRotate,group);
12614 theCommands.Add("vzoom",
12615 "vzoom : vzoom coef",
12616 __FILE__,VZoom,group);
12617 theCommands.Add("vpan",
12618 "vpan : vpan dx dy",
12619 __FILE__,VPan,group);
12620 theCommands.Add("vcolorscale",
12621 "vcolorscale name [-noupdate|-update] [-demo]"
12622 "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
12623 "\n\t\t: [-font HeightFont=20]"
12624 "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
12625 "\n\t\t: [-smoothTransition {on|off}=off]"
12626 "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
12627 "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
12628 "\n\t\t: [-textpos {left|right|center|none}=right]"
12629 "\n\t\t: [-labelAtBorder {on|off}=on]"
12630 "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
12631 "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
12632 "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
12633 "\n\t\t: [-xy Left=0 Bottom=0]"
12634 "\n\t\t: -demo - displays a color scale with demonstratio values"
12635 "\n\t\t: -colors - set colors for all intervals"
12636 "\n\t\t: -color - set color for specific interval"
12637 "\n\t\t: -textpos - horizontal label position relative to color scale bar"
12638 "\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
12639 "\n\t\t: at border means the value inbetween neighbor intervals,"
12640 "\n\t\t: at center means the center value within current interval"
12641 "\n\t\t: -labels - set labels for all intervals"
12642 "\n\t\t: -freeLabels - same as -labels but does not require"
12643 "\n\t\t: matching the number of intervals"
12644 "\n\t\t: -label - set label for specific interval"
12645 "\n\t\t: -title - set title"
12646 "\n\t\t: -reversed - setup smooth color transition between intervals"
12647 "\n\t\t: -smoothTransition - swap colorscale direction"
12648 "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values"
12649 __FILE__, VColorScale, group);
12650 theCommands.Add("vgraduatedtrihedron",
12651 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
12652 "\t[-namefont Name] [-valuesfont Name]\n"
12653 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
12654 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
12655 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
12656 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
12657 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
12658 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
12659 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
12660 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
12661 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
12662 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
12663 " - Displays or erases graduated trihedron"
12664 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
12665 " - namefont - font of axes names. Default: Arial\n"
12666 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
12667 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
12668 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
12669 " - valuesfont - font of axes values. Default: Arial\n"
12670 " - xcolor, ycolor, zcolor - color of axis and values\n"
12671 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
12672 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
12673 __FILE__,VGraduatedTrihedron,group);
12674 theCommands.Add("vtile" ,
12675 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
12676 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
12677 "\n\t\t: -totalSize the size of virtual bigger viewport"
12678 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
12679 "\n\t\t: -lowerLeft tile offset as lower left corner"
12680 "\n\t\t: -upperLeft tile offset as upper left corner",
12681 __FILE__, VTile, group);
12682 theCommands.Add("vzlayer",
12683 "vzlayer [layerId]"
12684 "\n\t\t: [-add|-delete|-get|-settings]"
12685 "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]"
12686 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
12687 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv}]"
12688 "\n\t\t: ZLayer list management:"
12689 "\n\t\t: -add add new z layer to viewer and print its id"
12690 "\n\t\t: -delete delete z layer"
12691 "\n\t\t: -get print sequence of z layers"
12692 "\n\t\t: -settings print status of z layer settings"
12693 "\n\t\t: -disable disables given setting"
12694 "\n\t\t: -enable enables given setting",
12695 __FILE__,VZLayer,group);
12696 theCommands.Add("vlayerline",
12697 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
12698 __FILE__,VLayerLine,group);
12699 theCommands.Add("vgrid",
12700 "vgrid [off] [-type {rect|circ}] [-mode {line|point}] [-origin X Y] [-rotAngle Angle] [-zoffset DZ]"
12701 "\n\t\t: [-step X Y] [-size DX DY]"
12702 "\n\t\t: [-step StepRadius NbDivisions] [-radius Radius]",
12703 __FILE__, VGrid, group);
12704 theCommands.Add ("vpriviledgedplane",
12705 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
12706 "\n\t\t: Ox, Oy, Oz - plane origin"
12707 "\n\t\t: Nx, Ny, Nz - plane normal direction"
12708 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
12709 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
12710 __FILE__, VPriviledgedPlane, group);
12711 theCommands.Add ("vconvert",
12712 "vconvert v [Mode={window|view}]"
12713 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
12714 "\n\t\t: vconvert x y z [Mode={window|grid}]"
12715 "\n\t\t: window - convert to window coordinates, pixels"
12716 "\n\t\t: view - convert to view projection plane"
12717 "\n\t\t: grid - convert to model coordinates, given on grid"
12718 "\n\t\t: ray - convert projection ray to model coordiantes"
12719 "\n\t\t: - vconvert v window : convert view to window;"
12720 "\n\t\t: - vconvert v view : convert window to view;"
12721 "\n\t\t: - vconvert x y window : convert view to window;"
12722 "\n\t\t: - vconvert x y view : convert window to view;"
12723 "\n\t\t: - vconvert x y : convert window to model;"
12724 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
12725 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
12726 "\n\t\t: - vconvert x y z window : convert model to window;"
12727 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
12728 "\n\t\t: Converts the given coordinates to window/view/model space.",
12729 __FILE__, VConvert, group);
12730 theCommands.Add ("vfps",
12731 "vfps [framesNb=100] [-duration seconds] : estimate average frame rate for active view",
12732 __FILE__, VFps, group);
12733 theCommands.Add ("vgldebug",
12734 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
12735 "\n\t\t: [-glslCode {off|short|full}] [-extraMsg {0|1}] [{0|1}]"
12736 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
12737 "\n\t\t: Debug context can be requested only on Windows"
12738 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
12739 "\n\t\t: -sync - request synchronized debug GL context"
12740 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
12741 "\n\t\t: which are suppressed by default,"
12742 "\n\t\t: -glslCode - log GLSL program source code,"
12743 "\n\t\t: which are suppressed by default,"
12744 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
12745 "\n\t\t: which are suppressed by default",
12746 __FILE__, VGlDebug, group);
12747 theCommands.Add ("vvbo",
12748 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
12749 __FILE__, VVbo, group);
12750 theCommands.Add ("vstereo",
12751 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
12752 "\n\t\t: [-anaglyph Filter]"
12753 "\n\t\t: Control stereo output mode. Available modes for -mode:"
12754 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
12755 "\n\t\t: requires driver support."
12756 "\n\t\t: Should be called BEFORE vinit!"
12757 "\n\t\t: anaglyph - Anaglyph glasses"
12758 "\n\t\t: rowInterlaced - row-interlaced display"
12759 "\n\t\t: columnInterlaced - column-interlaced display"
12760 "\n\t\t: chessBoard - chess-board output"
12761 "\n\t\t: sideBySide - horizontal pair"
12762 "\n\t\t: overUnder - vertical pair"
12763 "\n\t\t: Available Anaglyph filters for -anaglyph:"
12764 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
12765 "\n\t\t: greenMagentaSimple",
12766 __FILE__, VStereo, group);
12767 theCommands.Add ("vcaps",
12768 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}] [-polygonMode {0|1}]"
12769 "\n\t\t: [-compatibleProfile {0|1}]"
12770 "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]"
12771 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
12772 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
12773 "\n\t\t: Modify particular graphic driver options:"
12774 "\n\t\t: FFP - use fixed-function pipeline instead of"
12775 "\n\t\t: built-in GLSL programs"
12776 "\n\t\t: (requires compatible profile)"
12777 "\n\t\t: polygonMode - use Polygon Mode instead of built-in GLSL programs"
12778 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
12779 "\n\t\t: arrays to GPU memory)"
12780 "\n\t\t: sprite - use textured sprites instead of bitmaps"
12781 "\n\t\t: vsync - switch VSync on or off"
12782 "\n\t\t: winBuffer - allow using window buffer for rendering"
12783 "\n\t\t: Context creation options:"
12784 "\n\t\t: softMode - software OpenGL implementation"
12785 "\n\t\t: compatibleProfile - backward-compatible profile"
12786 "\n\t\t: quadbuffer - QuadBuffer"
12787 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
12788 "\n\t\t: rendering paths producing the same visual result when"
12789 "\n\t\t: possible."
12790 "\n\t\t: Command is intended for testing old hardware compatibility.",
12791 __FILE__, VCaps, group);
12792 theCommands.Add ("vmemgpu",
12793 "vmemgpu [f]: print system-dependent GPU memory information if available;"
12794 " with f option returns free memory in bytes",
12795 __FILE__, VMemGpu, group);
12796 theCommands.Add ("vreadpixel",
12797 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [-name]"
12798 " : Read pixel value for active view",
12799 __FILE__, VReadPixel, group);
12800 theCommands.Add("diffimage",
12801 "diffimage imageFile1 imageFile2 [diffImageFile]"
12802 "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]"
12803 "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]"
12804 "\n\t\t: Compare two images by content and generate difference image."
12805 "\n\t\t: When -exitOnClose is specified, closing the view will exit application."
12806 "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.",
12807 __FILE__, VDiffImage, group);
12808 theCommands.Add ("vselect",
12809 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
12810 "- emulates different types of selection:\n"
12811 "- 1) single click selection\n"
12812 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
12813 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
12814 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
12815 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
12816 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
12817 " (partial inclusion - overlap - is not allowed by default)\n"
12818 "- 5) any of these selections with shift button pressed",
12819 __FILE__, VSelect, group);
12820 theCommands.Add ("vmoveto",
12821 "vmoveto [x y] [-reset]"
12822 "\n\t\t: Emulates cursor movement to pixel position (x,y)."
12823 "\n\t\t: -reset resets current highlighting",
12824 __FILE__, VMoveTo, group);
12825 theCommands.Add ("vviewparams",
12826 "vviewparams [-args] [-scale [s]]"
12827 "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]"
12828 "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]"
12829 "\n\t\t: Manage current view parameters or prints all"
12830 "\n\t\t: current values when called without argument."
12831 "\n\t\t: -scale [s] prints or sets viewport relative scale"
12832 "\n\t\t: -eye [x y z] prints or sets eye location"
12833 "\n\t\t: -at [x y z] prints or sets center of look"
12834 "\n\t\t: -up [x y z] prints or sets direction of up vector"
12835 "\n\t\t: -proj [x y z] prints or sets direction of look"
12836 "\n\t\t: -center x y sets location of center of the screen in pixels"
12837 "\n\t\t: -size [sx] prints viewport projection width and height sizes"
12838 "\n\t\t: or changes the size of its maximum dimension"
12839 "\n\t\t: -args prints vviewparams arguments for restoring current view",
12840 __FILE__, VViewParams, group);
12842 theCommands.Add("v2dmode",
12843 "v2dmode [-name viewName] [-mode {-on|-off}=-on]"
12844 "\n\t\t: name - name of existing view, if not defined, the active view is changed"
12845 "\n\t\t: mode - switches On/Off rotation mode"
12846 "\n\t\t: Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:"
12847 "\n\t\t: - rotation of the view by 3rd mouse button with Ctrl active"
12848 "\n\t\t: - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right"
12849 "\n\t\t: View camera position might be changed only by commands.",
12850 __FILE__, V2DMode, group);
12852 theCommands.Add("vanimation", "Alias for vanim",
12853 __FILE__, VAnimation, group);
12855 theCommands.Add("vanim",
12856 "List existing animations:"
12858 "\n\t\t: Animation playback:"
12859 "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]"
12860 "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]"
12861 "\n\t\t: -speed playback speed (1.0 is normal speed)"
12862 "\n\t\t: -freeLook skip camera animations"
12863 "\n\t\t: -lockLoop disable any interactions"
12865 "\n\t\t: Animation definition:"
12866 "\n\t\t: vanim Name/sub/name [-clear] [-delete]"
12867 "\n\t\t: [start TimeSec] [duration TimeSec]"
12869 "\n\t\t: Animation name defined in path-style (anim/name or anim.name)"
12870 "\n\t\t: specifies nested animations."
12871 "\n\t\t: There is no syntax to explicitly add new animation,"
12872 "\n\t\t: and all non-existing animations within the name will be"
12873 "\n\t\t: implicitly created on first use (including parents)."
12875 "\n\t\t: Each animation might define the SINGLE action (see below),"
12876 "\n\t\t: like camera transition, object transformation or custom callback."
12877 "\n\t\t: Child animations can be used for defining concurrent actions."
12879 "\n\t\t: Camera animation:"
12880 "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]"
12881 "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]"
12882 "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]"
12883 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
12884 "\n\t\t: -eyeX camera Eye positions pair (start and end)"
12885 "\n\t\t: -atX camera Center positions pair"
12886 "\n\t\t: -upX camera Up directions pair"
12887 "\n\t\t: -scaleX camera Scale factors pair"
12888 "\n\t\t: Object animation:"
12889 "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]"
12890 "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]"
12891 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
12892 "\n\t\t: -locX object Location points pair (translation)"
12893 "\n\t\t: -rotX object Orientations pair (quaternions)"
12894 "\n\t\t: -scaleX object Scale factors pair (quaternions)"
12895 "\n\t\t: Custom callback:"
12896 "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\""
12897 "\n\t\t: %Pts overall animation presentation timestamp"
12898 "\n\t\t: %LocalPts local animation timestamp"
12899 "\n\t\t: %Normalized local animation normalized value in range 0..1"
12901 "\n\t\t: Video recording:"
12902 "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]"
12903 "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]"
12904 "\n\t\t: [-crf Value] [-preset Preset]"
12905 "\n\t\t: -fps video framerate"
12906 "\n\t\t: -format file format, container (matroska, etc.)"
12907 "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)"
12908 "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)"
12909 "\n\t\t: -crf constant rate factor (specific to codec)"
12910 "\n\t\t: -preset codec parameters preset (specific to codec)"
12911 __FILE__, VAnimation, group);
12913 theCommands.Add("vchangeselected",
12914 "vchangeselected shape"
12915 "- adds to shape to selection or remove one from it",
12916 __FILE__, VChangeSelected, group);
12917 theCommands.Add ("vnbselected",
12919 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
12920 theCommands.Add ("vcamera",
12921 "vcamera [PrsName] [-ortho] [-projtype]"
12923 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
12924 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
12925 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
12926 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
12927 "\n\t\t: Manages camera parameters."
12928 "\n\t\t: Displays frustum when presntation name PrsName is specified."
12929 "\n\t\t: Prints current value when option called without argument."
12930 "\n\t\t: Orthographic camera:"
12931 "\n\t\t: -ortho activate orthographic projection"
12932 "\n\t\t: Perspective camera:"
12933 "\n\t\t: -persp activate perspective projection (mono)"
12934 "\n\t\t: -fovy field of view in y axis, in degrees"
12935 "\n\t\t: -distance distance of eye from camera center"
12936 "\n\t\t: Stereoscopic camera:"
12937 "\n\t\t: -stereo perspective projection (stereo)"
12938 "\n\t\t: -leftEye perspective projection (left eye)"
12939 "\n\t\t: -rightEye perspective projection (right eye)"
12940 "\n\t\t: -iod intraocular distance value"
12941 "\n\t\t: -iodType distance type, absolute or relative"
12942 "\n\t\t: -zfocus stereographic focus value"
12943 "\n\t\t: -zfocusType focus type, absolute or relative",
12944 __FILE__, VCamera, group);
12945 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
12946 "- vautozfit [on={1|0}] [scale]\n"
12947 " Prints or changes parameters of automatic z-fit mode:\n"
12948 " \"on\" - turns automatic z-fit on or off\n"
12949 " \"scale\" - specifies factor to scale computed z range.\n",
12950 __FILE__, VAutoZFit, group);
12951 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
12952 " vzrange - without parameters shows current values\n"
12953 " vzrange [znear] [zfar] - applies provided values to view",
12954 __FILE__,VZRange, group);
12955 theCommands.Add ("vpurgedisplay",
12957 "- removes structures which don't belong to objects displayed in neutral point",
12958 __FILE__, VPurgeDisplay, group);
12959 theCommands.Add("vsetviewsize",
12960 "vsetviewsize size",
12961 __FILE__,VSetViewSize,group);
12962 theCommands.Add("vmoveview",
12963 "vmoveview Dx Dy Dz [Start = 1|0]",
12964 __FILE__,VMoveView,group);
12965 theCommands.Add("vtranslateview",
12966 "vtranslateview Dx Dy Dz [Start = 1|0)]",
12967 __FILE__,VTranslateView,group);
12968 theCommands.Add("vturnview",
12969 "vturnview Ax Ay Az [Start = 1|0]",
12970 __FILE__,VTurnView,group);
12971 theCommands.Add("vtextureenv",
12972 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
12973 "or user-defined file and optionally applying texture mapping parameters\n"
12975 " vtextureenv off - disables environment mapping\n"
12976 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
12977 " std_texture = (0..7)\n"
12978 " rep = {clamp|repeat}\n"
12979 " mod = {decal|modulate}\n"
12980 " flt = {nearest|bilinear|trilinear}\n"
12981 " ss, st - scale factors for s and t texture coordinates\n"
12982 " ts, tt - translation for s and t texture coordinates\n"
12983 " rot - texture rotation angle in degrees",
12984 __FILE__, VTextureEnv, group);
12985 theCommands.Add("vhlr",
12986 "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
12987 "\n\t\t: Hidden Line Removal algorithm."
12988 "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones"
12989 "\n\t\t: -algoType type of HLR algorithm.\n",
12990 __FILE__,VHLR,group);
12991 theCommands.Add("vhlrtype",
12992 "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
12993 "\n\t\t: Changes the type of HLR algorithm using for shapes:"
12994 "\n\t\t: 'algo' - exact HLR algorithm is applied"
12995 "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied"
12996 "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
12997 __FILE__,VHLRType,group);
12998 theCommands.Add("vclipplane",
12999 "vclipplane planeName [{0|1}]"
13000 "\n\t\t: [-equation1 A B C D]"
13001 "\n\t\t: [-equation2 A B C D]"
13002 "\n\t\t: [-boxInterior MinX MinY MinZ MaxX MaxY MaxZ]"
13003 "\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]"
13004 "\n\t\t: [-maxPlanes]"
13005 "\n\t\t: [-capping {0|1}]"
13006 "\n\t\t: [-color R G B] [-transparency Value] [-hatch {on|off|ID}]"
13007 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
13008 "\n\t\t: [-texRotate Angle]"
13009 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
13010 "\n\t\t: [-useObjShader {0|1}]"
13011 "\n\t\t: Clipping planes management:"
13012 "\n\t\t: -maxPlanes print plane limit for view"
13013 "\n\t\t: -delete delete plane with given name"
13014 "\n\t\t: {off|on|0|1} turn clipping on/off"
13015 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
13016 "\n\t\t: applied to active View when list is omitted"
13017 "\n\t\t: -equation A B C D change plane equation"
13018 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
13019 "\n\t\t: Capping options:"
13020 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
13021 "\n\t\t: -color R G B set capping color"
13022 "\n\t\t: -transparency Value set capping transparency 0..1"
13023 "\n\t\t: -texName Texture set capping texture"
13024 "\n\t\t: -texScale SX SY set capping tex scale"
13025 "\n\t\t: -texOrigin TX TY set capping tex origin"
13026 "\n\t\t: -texRotate Angle set capping tex rotation"
13027 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
13028 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
13029 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
13030 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
13031 __FILE__, VClipPlane, group);
13032 theCommands.Add("vdefaults",
13033 "vdefaults [-absDefl value]"
13034 "\n\t\t: [-devCoeff value]"
13035 "\n\t\t: [-angDefl value]"
13036 "\n\t\t: [-autoTriang {off/on | 0/1}]"
13037 , __FILE__, VDefaults, group);
13038 theCommands.Add("vlight",
13039 "tool to manage light sources, without arguments shows list of lights."
13040 "\n Main commands: "
13041 "\n '-clear' to clear lights"
13042 "\n '-{def}aults' to load deafault lights"
13043 "\n '-add' <type> to add any light source"
13044 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
13045 "\n 'change' <lightId> to edit light source with specified lightId"
13046 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
13048 "\n -{pos}ition X Y Z"
13049 "\n -{dir}ection X Y Z (for directional light or for spotlight)"
13050 "\n -color colorName"
13051 "\n -{head}light 0|1"
13052 "\n -{sm}oothness value"
13053 "\n -{int}ensity value"
13054 "\n -{constAtten}uation value"
13055 "\n -{linearAtten}uation value"
13056 "\n -angle angleDeg"
13057 "\n -{spotexp}onent value"
13058 "\n -local|-global"
13059 "\n\n example: vlight -add positional -head 1 -pos 0 1 1 -color red"
13060 "\n example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2",
13061 __FILE__, VLight, group);
13062 theCommands.Add("vraytrace",
13064 "\n\t\t: Turns on/off ray-tracing renderer."
13065 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
13066 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
13067 __FILE__, VRenderParams, group);
13068 theCommands.Add("vrenderparams",
13069 "\n Manages rendering parameters: "
13070 "\n '-raster' Disables GPU ray-tracing"
13071 "\n '-msaa 0..4' Specifies number of samples for MSAA"
13072 "\n '-lineFeather > 0' Sets line feather factor"
13073 "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor"
13074 "\n '-depthPrePass on|off' Enables/disables depth pre-pass"
13075 "\n '-alphatocoverage on|off' Enables/disables alpha to coverage (needs MSAA)"
13076 "\n '-rendScale value Rendering resolution scale factor"
13077 "\n '-rayTrace' Enables GPU ray-tracing"
13078 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
13079 "\n '-shadows on|off' Enables/disables shadows rendering"
13080 "\n '-reflections on|off' Enables/disables specular reflections"
13081 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
13082 "\n '-gleam on|off' Enables/disables transparency shadow effects"
13083 "\n '-gi on|off' Enables/disables global illumination effects"
13084 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
13085 "\n '-env on|off' Enables/disables environment map background"
13086 "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
13087 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
13088 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
13089 "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)"
13090 "\n '-tileSize 1..4096' Specifies size of screen tiles in ISS mode (32 by default)"
13091 "\n '-nbtiles 64..1024' Specifies number of screen tiles per Redraw in ISS mode (256 by default)"
13092 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
13093 "\n '-shadingModel model' Controls shading model from enumeration"
13094 "\n color, flat, gouraud, phong"
13095 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
13096 "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)"
13097 "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect"
13098 "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)"
13099 "\n '-whitepoint value' White point value for filmic tone mapping"
13100 "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)"
13101 "\n '-perfCounters none|fps|cpu|layers|structures|groups|arrays|triagles|points"
13102 "\n ' |gpuMem|frameTime|basic|extended|full|nofps|skipImmediate'"
13103 "\n Show/hide performance counters (flags can be combined)"
13104 "\n '-perfUpdateInterval nbSeconds' Performance counters update interval"
13105 "\n '-perfChart nbFrames' Show frame timers chart limited by specified number of frames"
13106 "\n '-perfChartMax seconds' Maximum time in seconds with the chart"
13107 "\n '-frustumCulling on|off|noupdate' Enable/disable objects frustum clipping or"
13108 "\n set state to check structures culled previously."
13109 "\n Unlike vcaps, these parameters dramatically change visual properties."
13110 "\n Command is intended to control presentation quality depending on"
13111 "\n hardware capabilities and performance.",
13112 __FILE__, VRenderParams, group);
13113 theCommands.Add("vstatprofiler",
13114 "\n vstatprofiler [fps|cpu|allLayers|layers|allstructures|structures|groups"
13115 "\n |allArrays|fillArrays|lineArrays|pointArrays|textArrays"
13116 "\n |triagles|points|geomMem|textureMem|frameMem"
13117 "\n |elapsedFrame|cpuFrameAverage|cpuPickingAverage|cpuCullingAverage|cpuDynAverage"
13118 "\n |cpuFrameMax|cpuPickingMax|cpuCullingMax|cpuDynMax]"
13120 "\n\t\t: Prints rendering statistics."
13121 "\n\t\t: If there are some parameters - print corresponding statistic counters values,"
13122 "\n\t\t: else - print all performance counters set previously."
13123 "\n\t\t: '-noredraw' Flag to avoid additional redraw call and use already collected values.\n",
13124 __FILE__, VStatProfiler, group);
13125 theCommands.Add ("vplace",
13127 "\n\t\t: Places the point (in pixels) at the center of the window",
13128 __FILE__, VPlace, group);
13129 theCommands.Add("vxrotate",
13131 __FILE__,VXRotate,group);
13133 theCommands.Add("vmanipulator",
13134 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
13135 "\n tool to create and manage AIS manipulators."
13137 "\n '-attach AISObject' attach manipulator to AISObject"
13138 "\n '-adjustPosition {0|1}' adjust position when attaching"
13139 "\n '-adjustSize {0|1}' adjust size when attaching"
13140 "\n '-enableModes {0|1}' enable modes when attaching"
13141 "\n '-detach' detach manipulator"
13142 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
13143 "\n '-transform mouse_x mouse_y' - invoke transformation"
13144 "\n '-stopTransform [abort]' - invoke stop of transformation"
13145 "\n '-move x y z' - move attached object"
13146 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
13147 "\n '-scale factor' - scale attached object"
13148 "\n '-autoActivate {0|1}' - set activation on detection"
13149 "\n '-followTranslation {0|1}' - set following translation transform"
13150 "\n '-followRotation {0|1}' - set following rotation transform"
13151 "\n '-followDragging {0|1}' - set following dragging transform"
13152 "\n '-gap value' - set gap between sub-parts"
13153 "\n '-part axis mode {0|1}' - set visual part"
13154 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
13155 "\n '-size value' - set size of manipulator"
13156 "\n '-zoomable {0|1}' - set zoom persistence",
13157 __FILE__, VManipulator, group);
13159 theCommands.Add("vselprops",
13160 "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]"
13161 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
13162 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
13163 "\n -autoHighlight {0|1} : disables|enables automatic highlighting in 3D Viewer"
13164 "\n -highlightSelected {0|1}: disables|enables highlighting of detected object in selected state"
13165 "\n -pickStrategy {first|topmost} : defines picking strategy"
13166 "\n 'first' to pick first acceptable (default)"
13167 "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)"
13168 "\n -pixTol value : sets up pixel tolerance"
13169 "\n -dispMode dispMode : sets display mode for highlighting"
13170 "\n -layer ZLayer : sets ZLayer for highlighting"
13171 "\n -color {name|r g b} : sets highlight color"
13172 "\n -transp value : sets transparency coefficient for highlight"
13173 "\n -material material : sets highlight material"
13174 "\n -print : prints current state of all mentioned parameters",
13175 __FILE__, VSelectionProperties, group);
13176 theCommands.Add ("vhighlightselected",
13177 "vhighlightselected [0|1]: alias for vselprops -highlightSelected.\n",
13178 __FILE__, VSelectionProperties, group);
13180 theCommands.Add ("vseldump",
13181 "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1"
13182 "\n\t\t: Generate an image based on detection results:"
13183 "\n\t\t: depth normalized depth values"
13184 "\n\t\t: unnormDepth unnormalized depth values"
13185 "\n\t\t: object color of detected object"
13186 "\n\t\t: owner color of detected owner"
13187 "\n\t\t: selMode color of selection mode"
13188 "\n\t\t: entity color of etected entity",
13189 __FILE__, VDumpSelectionImage, group);
13191 #if defined(_WIN32)
13192 theCommands.Add("vprogressive",
13194 __FILE__, VProgressiveMode, group);