1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <OpenGl_GlCore20.hxx>
19 #include <AIS_Animation.hxx>
20 #include <AIS_AnimationCamera.hxx>
21 #include <AIS_AnimationObject.hxx>
22 #include <AIS_CameraFrustum.hxx>
23 #include <AIS_ColorScale.hxx>
24 #include <AIS_Manipulator.hxx>
25 #include <AIS_RubberBand.hxx>
26 #include <AIS_Shape.hxx>
27 #include <AIS_InteractiveObject.hxx>
28 #include <AIS_ListOfInteractive.hxx>
29 #include <AIS_ListIteratorOfListOfInteractive.hxx>
30 #include <Aspect_Grid.hxx>
32 #include <Draw_ProgressIndicator.hxx>
33 #include <Graphic3d_ArrayOfPolylines.hxx>
34 #include <Graphic3d_AspectMarker3d.hxx>
35 #include <Graphic3d_NameOfTextureEnv.hxx>
36 #include <Graphic3d_GraduatedTrihedron.hxx>
37 #include <Graphic3d_TextureEnv.hxx>
38 #include <Graphic3d_TextureParams.hxx>
39 #include <Graphic3d_TypeOfTextureFilter.hxx>
40 #include <Graphic3d_AspectFillArea3d.hxx>
41 #include <ViewerTest.hxx>
42 #include <ViewerTest_AutoUpdater.hxx>
43 #include <ViewerTest_EventManager.hxx>
44 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
45 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
46 #include <ViewerTest_CmdParser.hxx>
47 #include <V3d_AmbientLight.hxx>
48 #include <V3d_DirectionalLight.hxx>
49 #include <V3d_PositionalLight.hxx>
50 #include <V3d_SpotLight.hxx>
51 #include <Message_ProgressSentry.hxx>
52 #include <NCollection_DoubleMap.hxx>
53 #include <NCollection_List.hxx>
54 #include <NCollection_Vector.hxx>
55 #include <AIS_InteractiveContext.hxx>
56 #include <Draw_Interpretor.hxx>
58 #include <Draw_Appli.hxx>
59 #include <Image_AlienPixMap.hxx>
60 #include <Image_VideoRecorder.hxx>
61 #include <OpenGl_GraphicDriver.hxx>
62 #include <OSD_Timer.hxx>
63 #include <TColStd_HSequenceOfAsciiString.hxx>
64 #include <TColStd_SequenceOfInteger.hxx>
65 #include <TColStd_HSequenceOfReal.hxx>
66 #include <TColgp_Array1OfPnt2d.hxx>
67 #include <TColStd_MapOfAsciiString.hxx>
68 #include <Aspect_TypeOfLine.hxx>
69 #include <Image_Diff.hxx>
70 #include <Aspect_DisplayConnection.hxx>
74 #include <PrsMgr_PresentableObject.hxx>
75 #include <Graphic3d_ClipPlane.hxx>
76 #include <NCollection_DataMap.hxx>
77 #include <Graphic3d_Texture2Dmanual.hxx>
78 #include <Prs3d_ShadingAspect.hxx>
79 #include <Prs3d_Drawer.hxx>
80 #include <Prs3d_LineAspect.hxx>
81 #include <Prs3d_Root.hxx>
82 #include <Prs3d_Text.hxx>
83 #include <Select3D_SensitivePrimitiveArray.hxx>
92 #include <WNT_WClass.hxx>
93 #include <WNT_Window.hxx>
94 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
95 #include <Cocoa_Window.hxx>
97 #include <Xw_Window.hxx>
98 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
99 #include <X11/Xutil.h>
103 // Auxiliary definitions
104 static const char THE_KEY_DELETE = 127;
105 static const char THE_KEY_ESCAPE = 27;
107 //==============================================================================
108 // VIEWER GLOBAL VARIABLES
109 //==============================================================================
111 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
112 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
114 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
115 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
117 extern int VErase (Draw_Interpretor& theDI,
118 Standard_Integer theArgNb,
119 const char** theArgVec);
122 static Handle(WNT_Window)& VT_GetWindow() {
123 static Handle(WNT_Window) WNTWin;
126 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
127 static Handle(Cocoa_Window)& VT_GetWindow()
129 static Handle(Cocoa_Window) aWindow;
132 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
133 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
134 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
137 static Handle(Xw_Window)& VT_GetWindow(){
138 static Handle(Xw_Window) XWWin;
142 static void VProcessEvents(ClientData,int);
145 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
147 static Handle(Aspect_DisplayConnection) aDisplayConnection;
148 return aDisplayConnection;
151 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
153 GetDisplayConnection() = theDisplayConnection;
156 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
157 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
159 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
161 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
162 if (!aWindow.IsNull())
163 return aWindow->HWindow();
164 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
165 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
166 if (!aWindow.IsNull())
167 return aWindow->XWindow();
169 return aWindowHandle;
173 //! Setting additional flag to store 2D mode of the View to avoid scene rotation by mouse/key events
174 class ViewerTest_V3dView : public V3d_View
176 DEFINE_STANDARD_RTTI_INLINE(ViewerTest_V3dView, V3d_View)
178 //! Initializes the view.
179 ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const V3d_TypeOfView theType = V3d_ORTHOGRAPHIC,
180 bool theIs2dMode = false)
181 : V3d_View (theViewer, theType), myIs2dMode (theIs2dMode) {}
183 //! Initializes the view by copying.
184 ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const Handle(V3d_View)& theView)
185 : V3d_View (theViewer, theView), myIs2dMode (false)
187 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (theView))
189 myIs2dMode = aV3dView->IsViewIn2DMode();
193 //! Returns true if 2D mode is set for the view
194 bool IsViewIn2DMode() const { return myIs2dMode; }
196 //! Sets 2D mode for the view
197 void SetView2DMode (bool the2dMode) { myIs2dMode = the2dMode; }
201 //! Returns true if active view in 2D mode.
202 static bool IsCurrentViewIn2DMode()
204 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
206 return aV3dView->IsViewIn2DMode();
211 //! Set if active view in 2D mode.
212 static void SetCurrentView2DMode (bool theIs2d)
214 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
216 aV3dView->SetView2DMode (theIs2d);
222 Standard_Boolean myIs2dMode; //!< 2D mode flag
226 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
227 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
228 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
229 static OpenGl_Caps ViewerTest_myDefaultCaps;
231 static void OSWindowSetup();
235 Quantity_Color FlatColor;
236 Quantity_Color GradientColor1;
237 Quantity_Color GradientColor2;
238 Aspect_GradientFillMethod FillMethod;
239 } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
241 //==============================================================================
242 // EVENT GLOBAL VARIABLES
243 //==============================================================================
245 static int Start_Rot = 0;
246 Standard_Boolean HasHlrOnBeforeRotation = Standard_False;
247 int X_Motion = 0; // Current cursor position
249 int X_ButtonPress = 0; // Last ButtonPress position
250 int Y_ButtonPress = 0;
251 Standard_Boolean IsDragged = Standard_False;
252 Standard_Boolean DragFirst = Standard_False;
253 Standard_Boolean TheIsAnimating = Standard_False;
254 Standard_Boolean Draw_ToExitOnCloseView = Standard_False;
255 Standard_Boolean Draw_ToCloseViewOnEsc = Standard_False;
258 Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand()
260 static Handle(AIS_RubberBand) aBand;
263 aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0);
264 aBand->SetDisplayMode (0);
269 typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators;
271 Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators()
273 static ViewerTest_MapOfAISManipulators aMap;
277 Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator()
279 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
280 for (; anIt.More(); anIt.Next())
282 if (anIt.Value()->HasActiveMode())
290 //==============================================================================
293 static LRESULT WINAPI ViewerWindowProc(
298 static LRESULT WINAPI AdvViewerWindowProc(
306 //==============================================================================
309 //==============================================================================
311 const Handle(Standard_Transient)& ViewerTest::WClass()
313 static Handle(Standard_Transient) theWClass;
315 if (theWClass.IsNull())
317 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
318 CS_VREDRAW | CS_HREDRAW, 0, 0,
319 ::LoadCursor (NULL, IDC_ARROW));
325 //==============================================================================
326 //function : CreateName
327 //purpose : Create numerical name for new object in theMap
328 //==============================================================================
329 template <typename ObjectType>
330 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
331 const TCollection_AsciiString& theDefaultString)
333 if (theObjectMap.IsEmpty())
334 return theDefaultString + TCollection_AsciiString(1);
336 Standard_Integer aNextKey = 1;
337 Standard_Boolean isFound = Standard_False;
340 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
341 // Look for objects with default names
342 if (theObjectMap.IsBound1(aStringKey))
347 isFound = Standard_True;
350 return theDefaultString + TCollection_AsciiString(aNextKey);
353 //==============================================================================
354 //structure : ViewerTest_Names
355 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
356 //==============================================================================
357 struct ViewerTest_Names
360 TCollection_AsciiString myDriverName;
361 TCollection_AsciiString myViewerName;
362 TCollection_AsciiString myViewName;
366 const TCollection_AsciiString& GetDriverName () const
370 void SetDriverName (const TCollection_AsciiString& theDriverName)
372 myDriverName = theDriverName;
374 const TCollection_AsciiString& GetViewerName () const
378 void SetViewerName (const TCollection_AsciiString& theViewerName)
380 myViewerName = theViewerName;
382 const TCollection_AsciiString& GetViewName () const
386 void SetViewName (const TCollection_AsciiString& theViewName)
388 myViewName = theViewName;
391 //===========================================================================
392 //function : Constructor for ViewerTest_Names
393 //purpose : Get view, viewer, driver names from custom string
394 //===========================================================================
396 ViewerTest_Names (const TCollection_AsciiString& theInputString)
398 TCollection_AsciiString aName(theInputString);
399 if (theInputString.IsEmpty())
401 // Get current configuration
402 if (ViewerTest_myDrivers.IsEmpty())
403 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
404 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
406 myDriverName = ViewerTest_myDrivers.Find2
407 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
409 if(ViewerTest_myContexts.IsEmpty())
411 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
412 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
416 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
419 myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
423 // There is at least view name
424 Standard_Integer aParserNumber = 0;
425 for (Standard_Integer i = 0; i < 3; ++i)
427 Standard_Integer aParserPos = aName.SearchFromEnd("/");
431 aName.Split(aParserPos-1);
436 if (aParserNumber == 0)
439 if (!ViewerTest::GetAISContext().IsNull())
441 myDriverName = ViewerTest_myDrivers.Find2
442 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
443 myViewerName = ViewerTest_myContexts.Find2
444 (ViewerTest::GetAISContext());
448 // There is no opened contexts here, need to create names for viewer and driver
449 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
450 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
452 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
453 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
455 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
457 else if (aParserNumber == 1)
459 // Here is viewerName/viewName
460 if (!ViewerTest::GetAISContext().IsNull())
461 myDriverName = ViewerTest_myDrivers.Find2
462 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
465 // There is no opened contexts here, need to create name for driver
466 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
467 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
469 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
471 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
475 //Here is driverName/viewerName/viewName
476 myDriverName = TCollection_AsciiString(aName);
478 TCollection_AsciiString aViewerName(theInputString);
479 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
480 myViewerName = TCollection_AsciiString(aViewerName);
482 myViewName = TCollection_AsciiString(theInputString);
488 //==============================================================================
489 //function : FindContextByView
490 //purpose : Find AIS_InteractiveContext by View
491 //==============================================================================
493 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
495 Handle(AIS_InteractiveContext) anAISContext;
497 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
498 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
500 if (anIter.Value()->CurrentViewer() == theView->Viewer())
501 return anIter.Key2();
507 //==============================================================================
508 //function : SetWindowTitle
509 //purpose : Set window title
510 //==============================================================================
512 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
513 Standard_CString theTitle)
516 const TCollection_ExtendedString theTitleW (theTitle);
517 SetWindowTextW ((HWND )Handle(WNT_Window)::DownCast(theWindow)->HWindow(), theTitleW.ToWideString());
518 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
519 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
521 if(GetDisplayConnection()->GetDisplay())
524 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
525 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
530 //==============================================================================
531 //function : IsWindowOverlapped
532 //purpose : Check if theWindow overlapp another view
533 //==============================================================================
535 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
536 const Standard_Integer thePxTop,
537 const Standard_Integer thePxRight,
538 const Standard_Integer thePxBottom,
539 TCollection_AsciiString& theViewId)
541 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
542 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
544 Standard_Integer aTop = 0,
548 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
549 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
550 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
551 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
552 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
554 theViewId = anIter.Key1();
555 return Standard_True;
558 return Standard_False;
561 // Workaround: to create and delete non-orthographic views outside ViewerTest
562 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
564 ViewerTest_myViews.UnBind1 (theName);
567 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
568 const Handle(V3d_View)& theView)
570 ViewerTest_myViews.Bind (theName, theView);
573 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
575 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
577 //==============================================================================
578 //function : ViewerInit
579 //purpose : Create the window viewer and initialize all the global variable
580 //==============================================================================
582 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
583 const Standard_Integer thePxTop,
584 const Standard_Integer thePxWidth,
585 const Standard_Integer thePxHeight,
586 const TCollection_AsciiString& theViewName,
587 const TCollection_AsciiString& theDisplayName,
588 const Handle(V3d_View)& theViewToClone)
590 // Default position and dimension of the viewer window.
591 // Note that left top corner is set to be sufficiently small to have
592 // window fit in the small screens (actual for remote desktops, see #23003).
593 // The position corresponds to the window's client area, thus some
594 // gap is added for window frame to be visible.
595 Standard_Integer aPxLeft = 20;
596 Standard_Integer aPxTop = 40;
597 Standard_Integer aPxWidth = 409;
598 Standard_Integer aPxHeight = 409;
599 Standard_Boolean toCreateViewer = Standard_False;
600 if (!theViewToClone.IsNull())
602 theViewToClone->Window()->Size (aPxWidth, aPxHeight);
605 Handle(OpenGl_GraphicDriver) aGraphicDriver;
606 ViewerTest_Names aViewNames(theViewName);
607 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
608 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
615 aPxWidth = thePxWidth;
616 if (thePxHeight != 0)
617 aPxHeight = thePxHeight;
619 // Get graphic driver (create it or get from another view)
620 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
622 // Get connection string
623 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
624 TCollection_AsciiString aDisplayName(theDisplayName);
625 if (!aDisplayName.IsEmpty())
626 SetDisplayConnection (new Aspect_DisplayConnection ());
628 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
630 (void)theDisplayName; // avoid warning on unused argument
631 SetDisplayConnection (new Aspect_DisplayConnection ());
634 if (Draw_VirtualWindows)
636 // don't waste the time waiting for VSync when window is not displayed on the screen
637 ViewerTest_myDefaultCaps.swapInterval = 0;
638 // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
639 //ViewerTest_myDefaultCaps.buffersNoSwap = true;
641 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
642 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
644 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
645 toCreateViewer = Standard_True;
649 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
652 //Dispose the window if input parameters are default
653 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
655 Standard_Integer aTop = 0,
662 // Get screen resolution
663 #if defined(_WIN32) || defined(__WIN32__)
665 GetClientRect(GetDesktopWindow(), &aWindowSize);
666 aScreenHeight = aWindowSize.bottom;
667 aScreenWidth = aWindowSize.right;
668 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
669 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
671 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
672 aScreenWidth = WidthOfScreen(aScreen);
673 aScreenHeight = HeightOfScreen(aScreen);
676 TCollection_AsciiString anOverlappedViewId("");
678 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
680 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
682 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
683 && aRight + 2*aPxWidth + 40 > aScreenWidth)
685 if (aBottom + aPxHeight + 40 > aScreenHeight)
692 aPxTop = aBottom + 40;
695 aPxLeft = aRight + 20;
700 TCollection_AsciiString aTitle("3D View - ");
701 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
703 // Change name of current active window
704 if (!ViewerTest::CurrentView().IsNull())
706 TCollection_AsciiString anActiveWindowTitle("3D View - ");
707 anActiveWindowTitle = anActiveWindowTitle
708 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
709 SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString());
713 Handle(V3d_Viewer) a3DViewer;
714 // If it's the single view, we first look for empty context
715 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
717 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
718 anIter(ViewerTest_myContexts);
720 ViewerTest::SetAISContext (anIter.Value());
721 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
723 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
725 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
726 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
728 else if (a3DViewer.IsNull())
730 toCreateViewer = Standard_True;
731 a3DViewer = new V3d_Viewer(aGraphicDriver);
732 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
733 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
734 ViewerTest_DefaultBackground.GradientColor2,
735 ViewerTest_DefaultBackground.FillMethod);
739 if (ViewerTest::GetAISContext().IsNull() ||
740 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
742 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
743 ViewerTest::SetAISContext (aContext);
744 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
748 ViewerTest::ResetEventManager();
753 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
754 Handle(WNT_WClass)::DownCast (WClass()),
755 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
759 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
760 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
762 aPxWidth, aPxHeight);
763 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
765 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
768 aPxWidth, aPxHeight);
770 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
773 Handle(V3d_View) aView;
774 if (!theViewToClone.IsNull())
776 aView = new ViewerTest_V3dView (a3DViewer, theViewToClone);
780 aView = new ViewerTest_V3dView (a3DViewer, a3DViewer->DefaultTypeOfView());
783 aView->SetWindow (VT_GetWindow());
784 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
786 ViewerTest::CurrentView(aView);
787 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
789 // Setup for X11 or NT
792 // Set parameters for V3d_View and V3d_Viewer
793 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
794 aV3dView->SetComputedMode(Standard_False);
796 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
799 a3DViewer->SetDefaultLights();
800 a3DViewer->SetLightOn();
803 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
804 #if TCL_MAJOR_VERSION < 8
805 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
806 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
808 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
809 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
813 VT_GetWindow()->Map();
815 // Set the handle of created view in the event manager
816 ViewerTest::ResetEventManager();
818 ViewerTest::CurrentView()->Redraw();
823 return aViewNames.GetViewName();
826 //==============================================================================
827 //function : RedrawAllViews
828 //purpose : Redraw all created views
829 //==============================================================================
830 void ViewerTest::RedrawAllViews()
832 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
833 for (; aViewIt.More(); aViewIt.Next())
835 const Handle(V3d_View)& aView = aViewIt.Key2();
840 //==============================================================================
842 //purpose : Create the window viewer and initialize all the global variable
843 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
844 //==============================================================================
846 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
848 TCollection_AsciiString aViewName, aDisplayName;
849 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
850 Handle(V3d_View) aCopyFrom;
851 TCollection_AsciiString aName, aValue;
853 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
855 const TCollection_AsciiString anArg = theArgVec[anArgIt];
856 TCollection_AsciiString anArgCase = anArg;
857 anArgCase.LowerCase();
858 if (anArgIt + 1 < theArgsNb
859 && anArgCase == "-name")
861 aViewName = theArgVec[++anArgIt];
863 else if (anArgIt + 1 < theArgsNb
864 && (anArgCase == "-left"
865 || anArgCase == "-l"))
867 aPxLeft = Draw::Atoi (theArgVec[++anArgIt]);
869 else if (anArgIt + 1 < theArgsNb
870 && (anArgCase == "-top"
871 || anArgCase == "-t"))
873 aPxTop = Draw::Atoi (theArgVec[++anArgIt]);
875 else if (anArgIt + 1 < theArgsNb
876 && (anArgCase == "-width"
877 || anArgCase == "-w"))
879 aPxWidth = Draw::Atoi (theArgVec[++anArgIt]);
881 else if (anArgIt + 1 < theArgsNb
882 && (anArgCase == "-height"
883 || anArgCase == "-h"))
885 aPxHeight = Draw::Atoi (theArgVec[++anArgIt]);
887 else if (anArgCase == "-exitonclose")
889 Draw_ToExitOnCloseView = true;
890 if (anArgIt + 1 < theArgsNb
891 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToExitOnCloseView))
896 else if (anArgCase == "-closeonescape"
897 || anArgCase == "-closeonesc")
899 Draw_ToCloseViewOnEsc = true;
900 if (anArgIt + 1 < theArgsNb
901 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToCloseViewOnEsc))
906 else if (anArgCase == "-2d_mode"
907 || anArgCase == "-2dmode"
908 || anArgCase == "-2d")
910 bool toEnable = true;
911 if (anArgIt + 1 < theArgsNb
912 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], toEnable))
916 is2dMode = toEnable ? 1 : 0;
918 else if (anArgIt + 1 < theArgsNb
919 && (anArgCase == "-disp"
920 || anArgCase == "-display"))
922 aDisplayName = theArgVec[++anArgIt];
924 else if (!ViewerTest::CurrentView().IsNull()
925 && aCopyFrom.IsNull()
926 && (anArgCase == "-copy"
927 || anArgCase == "-clone"
928 || anArgCase == "-cloneactive"
929 || anArgCase == "-cloneactiveview"))
931 aCopyFrom = ViewerTest::CurrentView();
934 else if (ViewerTest::SplitParameter (anArg, aName, aValue))
941 else if (aName == "l"
944 aPxLeft = aValue.IntegerValue();
946 else if (aName == "t"
949 aPxTop = aValue.IntegerValue();
951 else if (aName == "disp"
952 || aName == "display")
954 aDisplayName = aValue;
956 else if (aName == "w"
959 aPxWidth = aValue.IntegerValue();
961 else if (aName == "h"
962 || aName == "height")
964 aPxHeight = aValue.IntegerValue();
968 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
972 else if (aViewName.IsEmpty())
978 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
983 #if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
984 if (!aDisplayName.IsEmpty())
986 aDisplayName.Clear();
987 std::cout << "Warning: display parameter will be ignored.\n";
991 ViewerTest_Names aViewNames (aViewName);
992 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
994 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
995 theDi.Eval (aCommand.ToCString());
998 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
1003 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
1004 aViewName, aDisplayName, aCopyFrom);
1007 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
1013 //! Parse HLR algo type.
1014 static Standard_Boolean parseHlrAlgoType (const char* theName,
1015 Prs3d_TypeOfHLR& theType)
1017 TCollection_AsciiString aName (theName);
1019 if (aName == "polyalgo")
1021 theType = Prs3d_TOH_PolyAlgo;
1023 else if (aName == "algo")
1025 theType = Prs3d_TOH_Algo;
1029 return Standard_False;
1031 return Standard_True;
1034 //==============================================================================
1036 //purpose : hidden lines removal algorithm
1037 //==============================================================================
1039 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1041 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1042 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1045 std::cerr << "Error: No opened viewer!\n";
1049 Standard_Boolean hasHlrOnArg = Standard_False;
1050 Standard_Boolean hasShowHiddenArg = Standard_False;
1051 Standard_Boolean isHLROn = Standard_False;
1052 Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
1053 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1054 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1055 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
1057 TCollection_AsciiString anArg (argv[anArgIter]);
1059 if (anUpdateTool.parseRedrawMode (anArg))
1063 else if (anArg == "-showhidden"
1064 && anArgIter + 1 < argc
1065 && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden))
1068 hasShowHiddenArg = Standard_True;
1071 else if ((anArg == "-type"
1073 || anArg == "-algotype")
1074 && anArgIter + 1 < argc
1075 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1080 else if (!hasHlrOnArg
1081 && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn))
1083 hasHlrOnArg = Standard_True;
1087 else if (!hasShowHiddenArg
1088 && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden))
1090 hasShowHiddenArg = Standard_True;
1095 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
1101 di << "HLR: " << aView->ComputedMode() << "\n";
1102 di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
1104 switch (aCtx->DefaultDrawer()->TypeOfHLR())
1106 case Prs3d_TOH_NotSet: di << "NotSet\n"; break;
1107 case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
1108 case Prs3d_TOH_Algo: di << "Algo\n"; break;
1110 anUpdateTool.Invalidate();
1114 Standard_Boolean toRecompute = Standard_False;
1115 if (aTypeOfHLR != Prs3d_TOH_NotSet
1116 && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
1118 toRecompute = Standard_True;
1119 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1121 if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
1123 toRecompute = Standard_True;
1126 aCtx->DefaultDrawer()->EnableDrawHiddenLine();
1130 aCtx->DefaultDrawer()->DisableDrawHiddenLine();
1135 if (aView->ComputedMode() && isHLROn && toRecompute)
1137 AIS_ListOfInteractive aListOfShapes;
1138 aCtx->DisplayedObjects (aListOfShapes);
1139 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
1141 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
1143 aCtx->Redisplay (aShape, Standard_False);
1148 aView->SetComputedMode (isHLROn);
1152 //==============================================================================
1153 //function : VHLRType
1154 //purpose : change type of using HLR algorithm
1155 //==============================================================================
1157 static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1159 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1160 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1163 std::cerr << "Error: No opened viewer!\n";
1167 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1168 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1169 AIS_ListOfInteractive aListOfShapes;
1170 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
1172 TCollection_AsciiString anArg (argv[anArgIter]);
1174 if (anUpdateTool.parseRedrawMode (anArg))
1178 else if ((anArg == "-type"
1180 || anArg == "-algotype")
1181 && anArgIter + 1 < argc
1182 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1188 else if (aTypeOfHLR == Prs3d_TOH_NotSet
1189 && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
1195 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
1196 TCollection_AsciiString aName (argv[anArgIter]);
1197 if (!aMap.IsBound2 (aName))
1199 std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n";
1203 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
1204 if (aShape.IsNull())
1206 std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n";
1209 aListOfShapes.Append (aShape);
1213 if (aTypeOfHLR == Prs3d_TOH_NotSet)
1215 std::cout << "Syntax error: wrong number of arguments!\n";
1219 const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
1222 aCtx->DisplayedObjects (aListOfShapes);
1223 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1226 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
1228 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1229 if (aShape.IsNull())
1234 const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
1235 && aView->ComputedMode();
1237 || aShape->TypeOfHLR() != aTypeOfHLR)
1239 aShape->SetTypeOfHLR (aTypeOfHLR);
1243 aCtx->Redisplay (aShape, Standard_False);
1249 //==============================================================================
1250 //function : FindViewIdByWindowHandle
1251 //purpose : Find theView Id in the map of views by window handle
1252 //==============================================================================
1253 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1254 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
1256 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
1257 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1259 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
1260 if (aWindowHandle == theWindowHandle)
1261 return anIter.Key1();
1263 return TCollection_AsciiString("");
1267 //! Make the view active
1268 void ActivateView (const TCollection_AsciiString& theViewName,
1269 Standard_Boolean theToUpdate = Standard_True)
1271 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1277 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1278 if (!anAISContext.IsNull())
1280 if (!ViewerTest::CurrentView().IsNull())
1282 TCollection_AsciiString aTitle("3D View - ");
1283 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1284 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1287 ViewerTest::CurrentView (aView);
1288 ViewerTest::SetAISContext (anAISContext);
1289 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ") + theViewName + "(*)";
1290 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1292 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1293 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1294 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1296 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1298 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1301 ViewerTest::CurrentView()->Redraw();
1306 //==============================================================================
1307 //function : RemoveView
1309 //==============================================================================
1310 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1311 const Standard_Boolean theToRemoveContext)
1313 if (!ViewerTest_myViews.IsBound2 (theView))
1318 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1319 RemoveView (aViewName, theToRemoveContext);
1322 //==============================================================================
1323 //function : RemoveView
1324 //purpose : Close and remove view from display, clear maps if neccessary
1325 //==============================================================================
1326 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1328 if (!ViewerTest_myViews.IsBound1(theViewName))
1330 cout << "Wrong view name\n";
1334 // Activate another view if it's active now
1335 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1337 if (ViewerTest_myViews.Extent() > 1)
1339 TCollection_AsciiString aNewViewName;
1340 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1341 anIter.More(); anIter.Next())
1343 if (anIter.Key1() != theViewName)
1345 aNewViewName = anIter.Key1();
1349 ActivateView (aNewViewName);
1353 VT_GetWindow().Nullify();
1354 ViewerTest::CurrentView (Handle(V3d_View)());
1355 if (isContextRemoved)
1357 Handle(AIS_InteractiveContext) anEmptyContext;
1358 ViewerTest::SetAISContext(anEmptyContext);
1364 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1365 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1367 // Remove view resources
1368 ViewerTest_myViews.UnBind1(theViewName);
1369 aView->Window()->Unmap();
1372 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1373 XFlush (GetDisplayConnection()->GetDisplay());
1376 // Keep context opened only if the closed view is last to avoid
1377 // unused empty contexts
1378 if (!aCurrentContext.IsNull())
1380 // Check if there are more difined views in the viewer
1381 aCurrentContext->CurrentViewer()->InitDefinedViews();
1382 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1384 // Remove driver if there is no viewers that use it
1385 Standard_Boolean isRemoveDriver = Standard_True;
1386 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1387 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1389 if (aCurrentContext != anIter.Key2() &&
1390 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1392 isRemoveDriver = Standard_False;
1397 aCurrentContext->RemoveAll (Standard_False);
1400 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1401 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1402 #if TCL_MAJOR_VERSION < 8
1403 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1405 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1410 ViewerTest_myContexts.UnBind2(aCurrentContext);
1413 cout << "3D View - " << theViewName << " was deleted.\n";
1414 if (Draw_ToExitOnCloseView)
1416 Draw_Interprete ("exit");
1420 //==============================================================================
1422 //purpose : Remove the view defined by its name
1423 //==============================================================================
1425 static int VClose (Draw_Interpretor& /*theDi*/,
1426 Standard_Integer theArgsNb,
1427 const char** theArgVec)
1429 NCollection_List<TCollection_AsciiString> aViewList;
1432 TCollection_AsciiString anArg (theArgVec[1]);
1434 if (anArg.IsEqual ("ALL")
1435 || anArg.IsEqual ("*"))
1437 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1438 anIter.More(); anIter.Next())
1440 aViewList.Append (anIter.Key1());
1442 if (aViewList.IsEmpty())
1444 std::cout << "No view to close\n";
1450 ViewerTest_Names aViewName (theArgVec[1]);
1451 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1453 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1456 aViewList.Append (aViewName.GetViewName());
1461 // close active view
1462 if (ViewerTest::CurrentView().IsNull())
1464 std::cerr << "No active view!\n";
1467 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1470 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1471 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1472 anIter.More(); anIter.Next())
1474 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1480 //==============================================================================
1481 //function : VActivate
1482 //purpose : Activate the view defined by its ID
1483 //==============================================================================
1485 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1489 theDi.Eval("vviewlist");
1493 TCollection_AsciiString aNameString;
1494 Standard_Boolean toUpdate = Standard_True;
1495 Standard_Boolean toActivate = Standard_True;
1496 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
1498 TCollection_AsciiString anArg (theArgVec[anArgIter]);
1501 && anArg == "-noupdate")
1503 toUpdate = Standard_False;
1506 && aNameString.IsEmpty()
1509 TCollection_AsciiString aTitle("3D View - ");
1510 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1511 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1512 VT_GetWindow().Nullify();
1513 ViewerTest::CurrentView (Handle(V3d_View)());
1514 ViewerTest::ResetEventManager();
1515 theDi << theArgVec[0] << ": all views are inactive\n";
1516 toActivate = Standard_False;
1519 && aNameString.IsEmpty())
1521 aNameString = theArgVec[anArgIter];
1525 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
1534 else if (aNameString.IsEmpty())
1536 std::cout << "Syntax error: wrong number of arguments\n";
1540 // Check if this view exists in the viewer with the driver
1541 ViewerTest_Names aViewNames (aNameString);
1542 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1544 theDi << "Syntax error: wrong view name '" << aNameString << "'\n";
1548 // Check if it is active already
1549 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1551 theDi << theArgVec[0] << ": the view is active already\n";
1555 ActivateView (aViewNames.GetViewName(), toUpdate);
1559 //==============================================================================
1560 //function : VViewList
1561 //purpose : Print current list of views per viewer and graphic driver ID
1562 // shared between viewers
1563 //==============================================================================
1565 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1569 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1570 << "Usage: " << theArgVec[0] << " name";
1573 if (ViewerTest_myContexts.Size() < 1)
1576 Standard_Boolean isTreeView =
1577 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1581 theDi << theArgVec[0] <<":\n";
1584 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers);
1585 aDriverIter.More(); aDriverIter.Next())
1588 theDi << aDriverIter.Key1() << ":\n";
1590 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1591 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1593 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1597 TCollection_AsciiString aContextName(aContextIter.Key1());
1598 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
1601 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews);
1602 aViewIter.More(); aViewIter.Next())
1604 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1606 TCollection_AsciiString aViewName(aViewIter.Key1());
1609 if (aViewIter.Value() == ViewerTest::CurrentView())
1610 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
1612 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1616 theDi << aViewName << " ";
1626 //==============================================================================
1627 //function : VT_ProcessKeyPress
1628 //purpose : Handle KeyPress event from a CString
1629 //==============================================================================
1630 void VT_ProcessKeyPress (const char* buf_ret)
1632 //cout << "KeyPress" << endl;
1633 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1634 // Letter in alphabetic order
1636 if (!strcasecmp (buf_ret, "A")
1637 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1640 aView->SetProj(V3d_XposYnegZpos);
1642 else if (!strcasecmp (buf_ret, "D")
1643 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1648 else if (!strcasecmp (buf_ret, "F"))
1650 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1652 ViewerTest::GetAISContext()->FitSelected (aView);
1660 else if (!strcasecmp (buf_ret, "H"))
1663 std::cout << "HLR" << std::endl;
1664 aView->SetComputedMode (!aView->ComputedMode());
1667 else if (!strcasecmp (buf_ret, "P"))
1670 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1671 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1672 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1674 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1675 if (aContext->NbSelected()==0)
1677 AIS_ListOfInteractive aListOfShapes;
1678 aContext->DisplayedObjects(aListOfShapes);
1679 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1680 anIter.More(); anIter.Next())
1682 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1683 if (aShape.IsNull())
1685 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1686 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1688 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1689 aContext->Redisplay (aShape, Standard_False);
1694 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
1696 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
1697 if (aShape.IsNull())
1699 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1700 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1702 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1703 aContext->Redisplay (aShape, Standard_False);
1707 aContext->UpdateCurrentViewer();
1710 else if (!strcasecmp (buf_ret, "S"))
1712 std::cout << "setup Shaded display mode" << std::endl;
1714 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1715 if(Ctx->NbSelected()==0)
1716 Ctx->SetDisplayMode (AIS_Shaded, Standard_True);
1718 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1719 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
1720 Ctx->UpdateCurrentViewer();
1723 else if (!strcasecmp (buf_ret, "U"))
1725 // Unset display mode
1726 std::cout << "reset display mode to defaults" << std::endl;
1728 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1729 if(Ctx->NbSelected()==0)
1730 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
1732 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1733 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
1734 Ctx->UpdateCurrentViewer();
1738 else if (!strcasecmp (buf_ret, "T")
1739 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1742 aView->SetProj(V3d_Zpos);
1744 else if (!strcasecmp (buf_ret, "B")
1745 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1748 aView->SetProj(V3d_Zneg);
1750 else if (!strcasecmp (buf_ret, "L")
1751 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1754 aView->SetProj(V3d_Xneg);
1756 else if (!strcasecmp (buf_ret, "R")
1757 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1760 aView->SetProj(V3d_Xpos);
1762 else if (!strcasecmp (buf_ret, "W"))
1764 std::cout << "setup WireFrame display mode" << std::endl;
1765 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1766 if(Ctx->NbSelected()==0)
1767 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
1769 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1770 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
1771 Ctx->UpdateCurrentViewer();
1774 else if (!strcasecmp (buf_ret, ","))
1776 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1778 else if (!strcasecmp (buf_ret, "."))
1780 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1782 else if (!strcasecmp (buf_ret, "/"))
1784 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1785 if (aCamera->IsStereo())
1787 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1791 else if (!strcasecmp (buf_ret, "*"))
1793 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1794 if (aCamera->IsStereo())
1796 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1800 else if (*buf_ret == THE_KEY_DELETE)
1802 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1804 && aCtx->NbSelected() > 0)
1806 Draw_Interprete ("verase");
1809 else if (*buf_ret == THE_KEY_ESCAPE)
1811 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1813 && Draw_ToCloseViewOnEsc)
1815 Draw_Interprete (Draw_ToExitOnCloseView ? "exit" : "vclose");
1821 const Standard_Integer aSelMode = Draw::Atoi(buf_ret);
1822 if (aSelMode >= 0 && aSelMode <= 7)
1824 bool toEnable = true;
1825 if (const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext())
1827 AIS_ListOfInteractive aPrsList;
1828 aCtx->DisplayedObjects (aPrsList);
1829 for (AIS_ListOfInteractive::Iterator aPrsIter (aPrsList); aPrsIter.More() && toEnable; aPrsIter.Next())
1831 TColStd_ListOfInteger aModes;
1832 aCtx->ActivatedModes (aPrsIter.Value(), aModes);
1833 for (TColStd_ListOfInteger::Iterator aModeIter (aModes); aModeIter.More() && toEnable; aModeIter.Next())
1835 if (aModeIter.Value() == aSelMode)
1842 TCollection_AsciiString aCmd = TCollection_AsciiString ("vselmode ") + aSelMode + (toEnable ? " 1" : " 0");
1843 Draw_Interprete (aCmd.ToCString());
1848 //==============================================================================
1849 //function : VT_ProcessExpose
1850 //purpose : Redraw the View on an Expose Event
1851 //==============================================================================
1852 void VT_ProcessExpose()
1854 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1855 if (!aView3d.IsNull())
1861 //==============================================================================
1862 //function : VT_ProcessConfigure
1863 //purpose : Resize the View on an Configure Event
1864 //==============================================================================
1865 void VT_ProcessConfigure()
1867 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1868 if (aView3d.IsNull())
1873 aView3d->MustBeResized();
1878 //==============================================================================
1879 //function : VT_ProcessButton1Press
1881 //==============================================================================
1882 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1883 const char** theArgVec,
1884 Standard_Boolean theToPick,
1885 Standard_Boolean theIsShift)
1889 TheIsAnimating = Standard_False;
1890 return Standard_False;
1895 Standard_Real X, Y, Z;
1896 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1898 Draw::Set (theArgVec[1], X);
1899 Draw::Set (theArgVec[2], Y);
1900 Draw::Set (theArgVec[3], Z);
1905 ViewerTest::CurrentEventManager()->ShiftSelect();
1909 ViewerTest::CurrentEventManager()->Select();
1912 return Standard_False;
1915 //==============================================================================
1916 //function : VT_ProcessButton1Release
1917 //purpose : End selecting
1918 //==============================================================================
1919 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1923 IsDragged = Standard_False;
1924 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1927 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1928 X_Motion, Y_Motion);
1932 EM->Select (X_ButtonPress, Y_ButtonPress,
1933 X_Motion, Y_Motion);
1938 //==============================================================================
1939 //function : VT_ProcessButton3Press
1940 //purpose : Start Rotation
1941 //==============================================================================
1942 void VT_ProcessButton3Press()
1944 if (ViewerTest_V3dView::IsCurrentViewIn2DMode())
1950 HasHlrOnBeforeRotation = ViewerTest::CurrentView()->ComputedMode();
1951 if (HasHlrOnBeforeRotation)
1953 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1955 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1958 //==============================================================================
1959 //function : VT_ProcessButton3Release
1960 //purpose : End rotation
1961 //==============================================================================
1962 void VT_ProcessButton3Release()
1967 if (HasHlrOnBeforeRotation)
1969 HasHlrOnBeforeRotation = Standard_False;
1970 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1971 ViewerTest::CurrentView()->Redraw();
1976 //==============================================================================
1977 //function : ProcessControlButton1Motion
1979 //==============================================================================
1981 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1982 static void ProcessControlButton1Motion()
1984 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1986 X_ButtonPress = X_Motion;
1987 Y_ButtonPress = Y_Motion;
1991 //==============================================================================
1992 //function : VT_ProcessControlButton2Motion
1994 //==============================================================================
1995 void VT_ProcessControlButton2Motion()
1997 Standard_Integer aDx = X_Motion - X_ButtonPress;
1998 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
2000 aDy = -aDy; // Xwindow Y axis is from top to Bottom
2002 ViewerTest::CurrentView()->Pan (aDx, aDy);
2004 X_ButtonPress = X_Motion;
2005 Y_ButtonPress = Y_Motion;
2008 //==============================================================================
2009 //function : VT_ProcessControlButton3Motion
2010 //purpose : Rotation
2011 //==============================================================================
2012 void VT_ProcessControlButton3Motion()
2016 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
2020 //==============================================================================
2021 //function : VT_ProcessMotion
2023 //==============================================================================
2024 void VT_ProcessMotion()
2026 //pre-hilights detected objects at mouse position
2028 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
2029 EM->MoveTo(X_Motion, Y_Motion);
2033 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
2035 Xpix = X_Motion;Ypix=Y_Motion;
2038 //==============================================================================
2039 //function : ViewProject: implements VAxo, VTop, VLeft, ...
2040 //purpose : Switches to an axonometric, top, left and other views
2041 //==============================================================================
2043 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
2045 if ( ViewerTest::CurrentView().IsNull() )
2047 di<<"Call vinit before this command, please\n";
2051 ViewerTest::CurrentView()->SetProj(ori);
2055 //==============================================================================
2057 //purpose : Switch to an Axonometric view
2058 //Draw arg : No args
2059 //==============================================================================
2061 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
2063 return ViewProject(di, V3d_XposYnegZpos);
2066 //==============================================================================
2068 //purpose : Switch to a Top View
2069 //Draw arg : No args
2070 //==============================================================================
2072 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
2074 return ViewProject(di, V3d_Zpos);
2077 //==============================================================================
2078 //function : VBottom
2079 //purpose : Switch to a Bottom View
2080 //Draw arg : No args
2081 //==============================================================================
2083 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
2085 return ViewProject(di, V3d_Zneg);
2088 //==============================================================================
2090 //purpose : Switch to a Left View
2091 //Draw arg : No args
2092 //==============================================================================
2094 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
2096 return ViewProject(di, V3d_Xneg);
2099 //==============================================================================
2101 //purpose : Switch to a Right View
2102 //Draw arg : No args
2103 //==============================================================================
2105 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
2107 return ViewProject(di, V3d_Xpos);
2110 //==============================================================================
2112 //purpose : Switch to a Front View
2113 //Draw arg : No args
2114 //==============================================================================
2116 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
2118 return ViewProject(di, V3d_Yneg);
2121 //==============================================================================
2123 //purpose : Switch to a Back View
2124 //Draw arg : No args
2125 //==============================================================================
2127 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
2129 return ViewProject(di, V3d_Ypos);
2132 //==============================================================================
2134 //purpose : Dsiplay help on viewer Keyboead and mouse commands
2135 //Draw arg : No args
2136 //==============================================================================
2138 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
2141 di << "Q : Quit the application\n";
2143 di << "=========================\n";
2144 di << "F : FitAll\n";
2145 di << "T : TopView\n";
2146 di << "B : BottomView\n";
2147 di << "R : RightView\n";
2148 di << "L : LeftView\n";
2149 di << "A : AxonometricView\n";
2150 di << "D : ResetView\n";
2152 di << "=========================\n";
2153 di << "S : Shading\n";
2154 di << "W : Wireframe\n";
2155 di << "H : HidelLineRemoval\n";
2156 di << "U : Unset display mode\n";
2157 di << "Delete : Remove selection from viewer\n";
2159 di << "=========================\n";
2160 di << "Selection mode \n";
2161 di << "0 : Shape\n";
2162 di << "1 : Vertex\n";
2166 di << "5 : Shell\n";
2167 di << "6 : Solid\n";
2168 di << "7 : Compound\n";
2170 di << "=========================\n";
2171 di << "Z : Switch Z clipping On/Off\n";
2172 di << ", : Hilight next detected\n";
2173 di << ". : Hilight previous detected\n";
2180 static Standard_Boolean Ppick = 0;
2181 static Standard_Integer Pargc = 0;
2182 static const char** Pargv = NULL;
2185 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
2190 if (!ViewerTest_myViews.IsEmpty()) {
2192 WPARAM fwKeys = wParam;
2197 // Delete view from map of views
2198 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
2203 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
2204 || ViewerTest::CurrentView().IsNull())
2206 // Activate inactive window
2207 if(GetWindowHandle(VT_GetWindow()) != hwnd)
2209 ActivateView (FindViewIdByWindowHandle(hwnd));
2215 if (IsDragged && !DragFirst)
2217 if (!GetActiveAISManipulator().IsNull())
2219 GetActiveAISManipulator()->StopTransform();
2220 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
2223 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2225 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2226 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2229 VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0);
2231 IsDragged = Standard_False;
2232 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2235 if (IsDragged && !DragFirst)
2237 if (!GetActiveAISManipulator().IsNull())
2239 GetActiveAISManipulator()->StopTransform (Standard_False);
2240 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
2242 IsDragged = Standard_False;
2244 return ViewerWindowProc (hwnd, Msg, wParam, lParam);
2246 case WM_LBUTTONDOWN:
2247 if (!GetActiveAISManipulator().IsNull())
2249 IsDragged = ( fwKeys == MK_LBUTTON );
2253 IsDragged = ( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) );
2258 DragFirst = Standard_True;
2259 X_ButtonPress = LOWORD(lParam);
2260 Y_ButtonPress = HIWORD(lParam);
2262 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2267 X_Motion = LOWORD (lParam);
2268 Y_Motion = HIWORD (lParam);
2269 if (!GetActiveAISManipulator().IsNull())
2273 GetActiveAISManipulator()->StartTransform (X_ButtonPress, Y_ButtonPress, ViewerTest::CurrentView());
2277 GetActiveAISManipulator()->Transform (X_Motion, Y_Motion, ViewerTest::CurrentView());
2278 ViewerTest::GetAISContext()->CurrentViewer()->Redraw();
2283 bool toRedraw = false;
2284 if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2286 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2291 if (GetClientRect (hwnd, &aRect))
2293 int aHeight = aRect.bottom - aRect.top;
2294 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2295 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed);
2300 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2304 DragFirst = Standard_False;
2307 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2311 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2315 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2319 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
2325 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2328 return DefWindowProcW (hwnd, Msg, wParam, lParam);
2335 BeginPaint(hwnd, &ps);
2336 EndPaint(hwnd, &ps);
2341 VT_ProcessConfigure();
2346 switch (aView->RenderingParams().StereoMode)
2348 case Graphic3d_StereoMode_RowInterlaced:
2349 case Graphic3d_StereoMode_ColumnInterlaced:
2350 case Graphic3d_StereoMode_ChessBoard:
2351 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2359 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2362 c[0] = (char) wParam;
2364 if (wParam == VK_DELETE)
2366 c[0] = THE_KEY_DELETE;
2368 else if (wParam == VK_ESCAPE)
2370 c[0] = THE_KEY_ESCAPE;
2373 else if (wParam == VK_OEM_COMMA)
2378 else if (wParam == VK_OEM_PERIOD)
2382 else if (wParam == VK_DIVIDE)
2387 else if (wParam == VK_MULTIPLY)
2391 VT_ProcessKeyPress (c);
2399 VT_ProcessButton3Release();
2402 case WM_LBUTTONDOWN:
2403 case WM_MBUTTONDOWN:
2404 case WM_RBUTTONDOWN:
2406 WPARAM fwKeys = wParam;
2410 X_ButtonPress = LOWORD(lParam);
2411 Y_ButtonPress = HIWORD(lParam);
2413 if (Msg == WM_LBUTTONDOWN)
2415 if ((fwKeys & MK_CONTROL) != 0)
2417 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2421 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2424 else if (Msg == WM_RBUTTONDOWN)
2427 VT_ProcessButton3Press();
2434 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2435 if (wParam & MK_CONTROL)
2437 if (aView->Camera()->IsStereo())
2439 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2443 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2450 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2457 //cout << "\t WM_MOUSEMOVE" << endl;
2458 WPARAM fwKeys = wParam;
2459 X_Motion = LOWORD(lParam);
2460 Y_Motion = HIWORD(lParam);
2463 (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 )
2466 X_ButtonPress = LOWORD(lParam);
2467 Y_ButtonPress = HIWORD(lParam);
2469 if ((fwKeys & MK_RBUTTON) != 0) {
2471 VT_ProcessButton3Press();
2475 if ((fwKeys & MK_CONTROL) != 0)
2477 if ((fwKeys & MK_LBUTTON) != 0)
2479 ProcessControlButton1Motion();
2481 else if ((fwKeys & MK_MBUTTON) != 0
2482 || ((fwKeys & MK_LBUTTON) != 0
2483 && (fwKeys & MK_RBUTTON) != 0))
2485 VT_ProcessControlButton2Motion();
2487 else if ((fwKeys & MK_RBUTTON) != 0)
2489 VT_ProcessControlButton3Motion();
2492 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2500 return DefWindowProcW (hwnd, Msg, wParam, lParam);
2505 //==============================================================================
2506 //function : ViewerMainLoop
2507 //purpose : Get a Event on the view and dispatch it
2508 //==============================================================================
2511 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2513 Ppick = (argc > 0)? 1 : 0;
2521 cout << "Start picking" << endl;
2523 while ( Ppick == 1 ) {
2524 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2525 if (GetMessageW (&msg, NULL, 0, 0))
2527 TranslateMessage (&msg);
2528 DispatchMessageW (&msg);
2532 cout << "Picking done" << endl;
2538 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2540 int min( int a, int b )
2548 int max( int a, int b )
2556 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2559 static XEvent aReport;
2560 Standard_Boolean pick = argc > 0;
2561 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2562 XNextEvent (aDisplay, &aReport);
2564 // Handle event for the chosen display connection
2565 switch (aReport.type) {
2568 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2571 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2577 // Activate inactive view
2578 Window aWindow = GetWindowHandle(VT_GetWindow());
2579 if(aWindow != aReport.xfocus.window)
2581 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2590 case ConfigureNotify:
2592 VT_ProcessConfigure();
2601 XComposeStatus status_in_out;
2603 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2604 (char *) buf_ret , 10 ,
2605 &ks_ret , &status_in_out ) ;
2608 buf_ret[ret_len] = '\0' ;
2612 VT_ProcessKeyPress (buf_ret);
2618 X_ButtonPress = aReport.xbutton.x;
2619 Y_ButtonPress = aReport.xbutton.y;
2621 if (aReport.xbutton.button == Button1)
2623 if (aReport.xbutton.state & ControlMask)
2625 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2629 IsDragged = Standard_True;
2630 DragFirst = Standard_True;
2633 else if (aReport.xbutton.button == Button3)
2636 VT_ProcessButton3Press();
2646 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2648 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2649 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2653 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2654 if( aContext.IsNull() )
2656 cout << "The context is null. Please use vinit before createmesh" << endl;
2660 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2661 if( aReport.xbutton.button==1 )
2665 aContext->ShiftSelect (Standard_True);
2669 aContext->Select (Standard_True);
2674 aContext->ShiftSelect(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2675 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2676 ViewerTest::CurrentView(), Standard_True);
2680 aContext->Select(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2681 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2682 ViewerTest::CurrentView(), Standard_True);
2685 VT_ProcessButton3Release();
2687 IsDragged = Standard_False;
2690 VT_ProcessButton3Release();
2695 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2703 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2705 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2709 X_Motion = aReport.xmotion.x;
2710 Y_Motion = aReport.xmotion.y;
2711 DragFirst = Standard_False;
2713 Window aWindow = GetWindowHandle(VT_GetWindow());
2716 unsigned int aWidth, aHeight, aBorderWidth, aDepth;
2717 XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth);
2718 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2719 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed);
2720 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2724 X_Motion = aReport.xmotion.x;
2725 Y_Motion = aReport.xmotion.y;
2727 // remove all the ButtonMotionMaskr
2728 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2730 if ( aReport.xmotion.state & ControlMask ) {
2731 if ( aReport.xmotion.state & Button1Mask ) {
2732 ProcessControlButton1Motion();
2734 else if ( aReport.xmotion.state & Button2Mask ) {
2735 VT_ProcessControlButton2Motion();
2737 else if ( aReport.xmotion.state & Button3Mask ) {
2738 VT_ProcessControlButton3Motion();
2752 //==============================================================================
2753 //function : VProcessEvents
2754 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2755 // event in the Viewer window
2756 //==============================================================================
2758 static void VProcessEvents(ClientData,int)
2760 NCollection_Vector<int> anEventNumbers;
2761 // Get number of messages from every display
2762 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2763 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2765 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2767 // Handle events for every display
2768 int anEventIter = 0;
2769 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2770 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2772 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2773 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2775 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2776 int anEventResult = ViewerMainLoop( 0, NULL);
2777 // If window is closed or context was not found finish current event processing loop
2783 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2788 //==============================================================================
2789 //function : OSWindowSetup
2790 //purpose : Setup for the X11 window to be able to cath the event
2791 //==============================================================================
2794 static void OSWindowSetup()
2796 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2799 Window window = VT_GetWindow()->XWindow();
2800 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2801 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2802 XSynchronize(aDisplay, 1);
2804 // X11 : For keyboard on SUN
2806 wmhints.flags = InputHint;
2809 XSetWMHints( aDisplay, window, &wmhints);
2811 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2812 ButtonPressMask | ButtonReleaseMask |
2813 StructureNotifyMask |
2815 Button1MotionMask | Button2MotionMask |
2816 Button3MotionMask | FocusChangeMask
2818 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2819 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2821 XSynchronize(aDisplay, 0);
2829 //==============================================================================
2832 //==============================================================================
2834 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
2836 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2839 std::cout << "Error: no active viewer!\n";
2843 Standard_Boolean toFit = Standard_True;
2844 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2845 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2847 TCollection_AsciiString anArg (theArgv[anArgIter]);
2849 if (anUpdateTool.parseRedrawMode (anArg))
2853 else if (anArg == "-selected")
2855 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
2856 toFit = Standard_False;
2860 std::cout << "Syntax error at '" << anArg << "'\n";
2866 aView->FitAll (0.01, Standard_False);
2871 //=======================================================================
2872 //function : VFitArea
2873 //purpose : Fit view to show area located between two points
2874 // : given in world 2D or 3D coordinates.
2875 //=======================================================================
2876 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2878 Handle(V3d_View) aView = ViewerTest::CurrentView();
2881 std::cerr << theArgVec[0] << "Error: No active view.\n";
2886 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2887 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2891 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2892 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2893 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2894 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2896 else if (theArgNb == 7)
2898 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2899 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2900 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2901 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2902 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2903 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2907 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2908 theDI.PrintHelp(theArgVec[0]);
2912 // Convert model coordinates to view space
2913 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2914 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2915 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2917 // Determine fit area
2918 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2919 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2921 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2923 if (aDiagonal < Precision::Confusion())
2925 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2929 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2933 //==============================================================================
2935 //purpose : ZFitall, no DRAW arguments
2936 //Draw arg : No args
2937 //==============================================================================
2938 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2940 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2942 if (aCurrentView.IsNull())
2944 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2950 aCurrentView->ZFitAll();
2951 aCurrentView->Redraw();
2955 Standard_Real aScale = 1.0;
2959 aScale = Draw::Atoi (theArgVec[1]);
2962 aCurrentView->ZFitAll (aScale);
2963 aCurrentView->Redraw();
2968 //==============================================================================
2969 //function : VRepaint
2971 //==============================================================================
2972 static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
2974 Handle(V3d_View) aView = ViewerTest::CurrentView();
2977 std::cout << "Error: no active viewer!\n";
2981 Standard_Boolean isImmediateUpdate = Standard_False;
2982 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2984 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2986 if (anArg == "-immediate")
2988 isImmediateUpdate = Standard_True;
2989 if (anArgIter + 1 < theArgNb
2990 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
2997 std::cout << "Syntax error at '" << anArg << "'\n";
3001 if (isImmediateUpdate)
3003 aView->RedrawImmediate();
3012 //==============================================================================
3014 //purpose : Remove all the object from the viewer
3015 //Draw arg : No args
3016 //==============================================================================
3018 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
3020 Handle(V3d_View) V = ViewerTest::CurrentView();
3022 ViewerTest::Clear();
3026 //==============================================================================
3029 //==============================================================================
3031 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3032 { if (ViewerTest::CurrentView().IsNull() ) return 1;
3035 di << argv[0] << "Invalid number of arguments\n";
3039 while (ViewerMainLoop( argc, argv)) {
3045 //==============================================================================
3047 //purpose : Load image as background
3048 //==============================================================================
3050 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3052 if (argc < 2 || argc > 3)
3054 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n";
3055 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n";
3059 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3060 if(AISContext.IsNull())
3062 di << "use 'vinit' command before " << argv[0] << "\n";
3066 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
3069 const char* szType = argv[2];
3070 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
3071 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
3072 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
3073 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
3076 di << "Wrong fill type : " << szType << "\n";
3077 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
3082 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3083 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
3088 //==============================================================================
3089 //function : VSetBgMode
3090 //purpose : Change background image fill type
3091 //==============================================================================
3093 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3097 di << "Usage : " << argv[0] << " filltype : Change background image mode\n";
3098 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n";
3102 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3103 if(AISContext.IsNull())
3105 di << "use 'vinit' command before " << argv[0] << "\n";
3108 Aspect_FillMethod aFillType = Aspect_FM_NONE;
3109 const char* szType = argv[1];
3110 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
3111 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
3112 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
3113 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
3116 di << "Wrong fill type : " << szType << "\n";
3117 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
3120 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3121 V3dView->SetBgImageStyle(aFillType, Standard_True);
3125 //==============================================================================
3126 //function : VSetGradientBg
3127 //purpose : Mount gradient background
3128 //==============================================================================
3129 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3133 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background\n";
3134 di << "R1,G1,B1,R2,G2,B2 = [0..255]\n";
3135 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3136 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3140 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3141 if(AISContext.IsNull())
3143 di << "use 'vinit' command before " << argv[0] << "\n";
3149 Standard_Real R1 = Draw::Atof(argv[1])/255.;
3150 Standard_Real G1 = Draw::Atof(argv[2])/255.;
3151 Standard_Real B1 = Draw::Atof(argv[3])/255.;
3152 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
3154 Standard_Real R2 = Draw::Atof(argv[4])/255.;
3155 Standard_Real G2 = Draw::Atof(argv[5])/255.;
3156 Standard_Real B2 = Draw::Atof(argv[6])/255.;
3158 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
3159 int aType = Draw::Atoi(argv[7]);
3160 if( aType < 0 || aType > 8 )
3162 di << "Wrong fill type \n";
3163 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3164 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3168 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
3170 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3171 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
3177 //==============================================================================
3178 //function : VSetGradientBgMode
3179 //purpose : Change gradient background fill style
3180 //==============================================================================
3181 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3185 di << "Usage : " << argv[0] << " Type : Change gradient background fill type\n";
3186 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3187 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3191 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3192 if(AISContext.IsNull())
3194 di << "use 'vinit' command before " << argv[0] << "\n";
3199 int aType = Draw::Atoi(argv[1]);
3200 if( aType < 0 || aType > 8 )
3202 di << "Wrong fill type \n";
3203 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3204 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3208 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
3210 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3211 V3dView->SetBgGradientStyle( aMethod, 1 );
3217 //==============================================================================
3218 //function : VSetColorBg
3219 //purpose : Set color background
3220 //==============================================================================
3221 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3225 di << "Usage : " << argv[0] << " R G B : Set color background\n";
3226 di << "R,G,B = [0..255]\n";
3230 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3231 if(AISContext.IsNull())
3233 di << "use 'vinit' command before " << argv[0] << "\n";
3239 Standard_Real R = Draw::Atof(argv[1])/255.;
3240 Standard_Real G = Draw::Atof(argv[2])/255.;
3241 Standard_Real B = Draw::Atof(argv[3])/255.;
3242 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
3244 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3245 V3dView->SetBackgroundColor( aColor );
3252 //==============================================================================
3253 //function : VSetDefaultBg
3254 //purpose : Set default viewer background fill color
3255 //==============================================================================
3256 static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3261 std::cout << "Error: wrong syntax! See usage:\n";
3262 theDI.PrintHelp (theArgVec[0]);
3266 ViewerTest_DefaultBackground.FillMethod =
3267 theArgNb == 4 ? Aspect_GFM_NONE
3268 : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]);
3272 Standard_Real R = Draw::Atof (theArgVec[1]) / 255.;
3273 Standard_Real G = Draw::Atof (theArgVec[2]) / 255.;
3274 Standard_Real B = Draw::Atof (theArgVec[3]) / 255.;
3275 ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB);
3279 Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.;
3280 Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.;
3281 Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.;
3282 ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB);
3284 Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.;
3285 Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.;
3286 Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.;
3287 ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB);
3290 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
3291 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
3293 const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer();
3294 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
3295 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
3296 ViewerTest_DefaultBackground.GradientColor2,
3297 ViewerTest_DefaultBackground.FillMethod);
3303 //==============================================================================
3305 //purpose : View Scaling
3306 //==============================================================================
3308 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3310 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3311 if ( V3dView.IsNull() ) return 1;
3314 di << argv[0] << "Invalid number of arguments\n";
3317 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
3320 //==============================================================================
3321 //function : VZBuffTrihedron
3323 //==============================================================================
3325 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
3326 Standard_Integer theArgNb,
3327 const char** theArgVec)
3329 Handle(V3d_View) aView = ViewerTest::CurrentView();
3332 std::cout << "Error: no active viewer!\n";
3336 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
3338 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
3339 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
3340 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
3341 Quantity_Color anArrowColorX = Quantity_NOC_RED;
3342 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
3343 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
3344 Standard_Real aScale = 0.1;
3345 Standard_Real aSizeRatio = 0.8;
3346 Standard_Real anArrowDiam = 0.05;
3347 Standard_Integer aNbFacets = 12;
3348 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3350 Standard_CString anArg = theArgVec[anArgIter];
3351 TCollection_AsciiString aFlag (anArg);
3353 if (anUpdateTool.parseRedrawMode (aFlag))
3357 else if (aFlag == "-on")
3361 else if (aFlag == "-off")
3363 aView->TriedronErase();
3366 else if (aFlag == "-pos"
3367 || aFlag == "-position"
3368 || aFlag == "-corner")
3370 if (++anArgIter >= theArgNb)
3372 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3376 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3377 aPosName.LowerCase();
3378 if (aPosName == "center")
3380 aPosition = Aspect_TOTP_CENTER;
3382 else if (aPosName == "left_lower"
3383 || aPosName == "lower_left"
3384 || aPosName == "leftlower"
3385 || aPosName == "lowerleft")
3387 aPosition = Aspect_TOTP_LEFT_LOWER;
3389 else if (aPosName == "left_upper"
3390 || aPosName == "upper_left"
3391 || aPosName == "leftupper"
3392 || aPosName == "upperleft")
3394 aPosition = Aspect_TOTP_LEFT_UPPER;
3396 else if (aPosName == "right_lower"
3397 || aPosName == "lower_right"
3398 || aPosName == "rightlower"
3399 || aPosName == "lowerright")
3401 aPosition = Aspect_TOTP_RIGHT_LOWER;
3403 else if (aPosName == "right_upper"
3404 || aPosName == "upper_right"
3405 || aPosName == "rightupper"
3406 || aPosName == "upperright")
3408 aPosition = Aspect_TOTP_RIGHT_UPPER;
3412 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3416 else if (aFlag == "-type")
3418 if (++anArgIter >= theArgNb)
3420 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3424 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3425 aTypeName.LowerCase();
3426 if (aTypeName == "wireframe"
3427 || aTypeName == "wire")
3429 aVisType = V3d_WIREFRAME;
3431 else if (aTypeName == "zbuffer"
3432 || aTypeName == "shaded")
3434 aVisType = V3d_ZBUFFER;
3438 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3441 else if (aFlag == "-scale")
3443 if (++anArgIter >= theArgNb)
3445 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3449 aScale = Draw::Atof (theArgVec[anArgIter]);
3451 else if (aFlag == "-size"
3452 || aFlag == "-sizeratio")
3454 if (++anArgIter >= theArgNb)
3456 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3460 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3462 else if (aFlag == "-arrowdiam"
3463 || aFlag == "-arrowdiameter")
3465 if (++anArgIter >= theArgNb)
3467 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3471 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3473 else if (aFlag == "-nbfacets")
3475 if (++anArgIter >= theArgNb)
3477 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3481 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3483 else if (aFlag == "-colorlabel"
3484 || aFlag == "-colorlabels")
3486 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3487 theArgVec + anArgIter + 1,
3491 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3494 anArgIter += aNbParsed;
3496 else if (aFlag == "-colorarrowx")
3498 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3499 theArgVec + anArgIter + 1,
3503 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3506 anArgIter += aNbParsed;
3508 else if (aFlag == "-colorarrowy")
3510 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3511 theArgVec + anArgIter + 1,
3515 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3518 anArgIter += aNbParsed;
3520 else if (aFlag == "-colorarrowz")
3522 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3523 theArgVec + anArgIter + 1,
3527 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3530 anArgIter += aNbParsed;
3534 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3539 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3540 aSizeRatio, anArrowDiam, aNbFacets);
3541 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
3546 //==============================================================================
3547 //function : VRotate
3548 //purpose : Camera Rotating
3549 //==============================================================================
3551 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3553 Handle(V3d_View) aView = ViewerTest::CurrentView();
3556 std::cout << "No active view!\n";
3560 Standard_Boolean hasFlags = Standard_False;
3561 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3563 Standard_CString anArg (theArgVec[anArgIter]);
3564 TCollection_AsciiString aFlag (anArg);
3566 if (aFlag == "-mousestart"
3567 || aFlag == "-mousefrom")
3569 hasFlags = Standard_True;
3570 if (anArgIter + 2 >= theArgNb)
3572 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3576 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3577 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3578 aView->StartRotation (anX, anY);
3580 else if (aFlag == "-mousemove")
3582 hasFlags = Standard_True;
3583 if (anArgIter + 2 >= theArgNb)
3585 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3589 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3590 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3591 aView->Rotation (anX, anY);
3593 else if (theArgNb != 4
3596 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3605 else if (theArgNb == 4)
3607 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3608 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3609 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3610 aView->Rotate (anAX, anAY, anAZ);
3613 else if (theArgNb == 7)
3615 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3616 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3617 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3619 Standard_Real anX = Draw::Atof (theArgVec[4]);
3620 Standard_Real anY = Draw::Atof (theArgVec[5]);
3621 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3623 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3627 std::cout << "Error: Invalid number of arguments\n";
3631 //==============================================================================
3633 //purpose : View zoom in / out (relative to current zoom)
3634 //==============================================================================
3636 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3637 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3638 if ( V3dView.IsNull() ) {
3643 Standard_Real coef = Draw::Atof(argv[1]);
3644 if ( coef <= 0.0 ) {
3645 di << argv[1] << "Invalid value\n";
3648 V3dView->SetZoom( Draw::Atof(argv[1]) );
3651 di << argv[0] << " Invalid number of arguments\n";
3656 //==============================================================================
3658 //purpose : View panning (in pixels)
3659 //==============================================================================
3661 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3662 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3663 if ( V3dView.IsNull() ) return 1;
3666 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
3669 di << argv[0] << " Invalid number of arguments\n";
3674 //==============================================================================
3676 //purpose : Place the point (in pixels) at the center of the window
3677 //==============================================================================
3678 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3680 Handle(V3d_View) aView = ViewerTest::CurrentView();
3683 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3689 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3693 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3698 static int VColorScale (Draw_Interpretor& theDI,
3699 Standard_Integer theArgNb,
3700 const char** theArgVec)
3702 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3703 Handle(V3d_View) aView = ViewerTest::CurrentView();
3704 if (aContext.IsNull())
3706 std::cout << "Error: no active view!\n";
3711 std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n";
3715 Handle(AIS_ColorScale) aColorScale;
3716 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
3718 // find existing object
3719 aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
3720 if (aColorScale.IsNull())
3722 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
3729 if (aColorScale.IsNull())
3731 std::cout << "Syntax error: colorscale with a given name does not exist.\n";
3735 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
3736 << "Min range: " << aColorScale->GetMin() << "\n"
3737 << "Max range: " << aColorScale->GetMax() << "\n"
3738 << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n"
3739 << "Text height: " << aColorScale->GetTextHeight() << "\n"
3740 << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n"
3741 << "Color scale title: " << aColorScale->GetTitle() << "\n"
3742 << "Label position: ";
3743 switch (aColorScale->GetLabelPosition())
3745 case Aspect_TOCSP_NONE:
3748 case Aspect_TOCSP_LEFT:
3751 case Aspect_TOCSP_RIGHT:
3754 case Aspect_TOCSP_CENTER:
3755 theDI << "Center\n";
3761 if (aColorScale.IsNull())
3763 aColorScale = new AIS_ColorScale();
3764 aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
3765 aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
3768 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
3769 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
3771 Standard_CString anArg = theArgVec[anArgIter];
3772 TCollection_AsciiString aFlag (anArg);
3774 if (anUpdateTool.parseRedrawMode (aFlag))
3778 else if (aFlag == "-range")
3780 if (anArgIter + 3 >= theArgNb)
3782 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3786 const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]);
3787 const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]);
3788 const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]);
3789 if (!aRangeMin.IsRealValue()
3790 || !aRangeMax.IsRealValue())
3792 std::cout << "Error: the range values should be real!\n";
3795 else if (!aNbIntervals.IsIntegerValue())
3797 std::cout << "Error: the number of intervals should be integer!\n";
3801 aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue());
3802 aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue());
3804 else if (aFlag == "-font")
3806 if (anArgIter + 1 >= theArgNb)
3808 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3811 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
3812 if (!aFontArg.IsIntegerValue())
3814 std::cout << "Error: HeightFont value should be integer!\n";
3818 aColorScale->SetTextHeight (aFontArg.IntegerValue());
3821 else if (aFlag == "-textpos")
3823 if (anArgIter + 1 >= theArgNb)
3825 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3829 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
3830 aTextPosArg.LowerCase();
3831 Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE;
3832 if (aTextPosArg == "none")
3834 aLabPosition = Aspect_TOCSP_NONE;
3836 else if (aTextPosArg == "left")
3838 aLabPosition = Aspect_TOCSP_LEFT;
3840 else if (aTextPosArg == "right")
3842 aLabPosition = Aspect_TOCSP_RIGHT;
3844 else if (aTextPosArg == "center")
3846 aLabPosition = Aspect_TOCSP_CENTER;
3850 std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
3853 aColorScale->SetLabelPosition (aLabPosition);
3855 else if (aFlag == "-logarithmic"
3858 if (anArgIter + 1 >= theArgNb)
3860 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3864 Standard_Boolean IsLog;
3865 if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
3867 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3870 aColorScale->SetLogarithmic (IsLog);
3872 else if (aFlag == "-huerange"
3875 if (anArgIter + 2 >= theArgNb)
3877 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3881 const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]);
3882 const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]);
3883 aColorScale->SetHueRange (aHueMin, aHueMax);
3885 else if (aFlag == "-colorrange")
3887 Quantity_Color aColorMin, aColorMax;
3888 Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3889 theArgVec + (anArgIter + 1),
3891 anArgIter += aNbParsed1;
3892 Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3893 theArgVec + (anArgIter + 1),
3895 anArgIter += aNbParsed2;
3899 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3903 aColorScale->SetColorRange (aColorMin, aColorMax);
3905 else if (aFlag == "-reversed"
3906 || aFlag == "-inverted"
3907 || aFlag == "-topdown"
3908 || aFlag == "-bottomup")
3910 Standard_Boolean toEnable = Standard_True;
3911 if (anArgIter + 1 < theArgNb
3912 && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable))
3916 aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable);
3918 else if (aFlag == "-smooth"
3919 || aFlag == "-smoothtransition")
3921 Standard_Boolean toEnable = Standard_True;
3922 if (anArgIter + 1 < theArgNb
3923 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
3927 aColorScale->SetSmoothTransition (toEnable);
3929 else if (aFlag == "-xy")
3931 if (anArgIter + 2 >= theArgNb)
3933 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3937 const TCollection_AsciiString anX (theArgVec[++anArgIter]);
3938 const TCollection_AsciiString anY (theArgVec[++anArgIter]);
3939 if (!anX.IsIntegerValue()
3940 || !anY.IsIntegerValue())
3942 std::cout << "Error: coordinates should be integer values!\n";
3946 aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue());
3948 else if (aFlag == "-width"
3950 || aFlag == "-breadth")
3952 if (anArgIter + 1 >= theArgNb)
3954 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3958 const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]);
3959 if (!aBreadth.IsIntegerValue())
3961 std::cout << "Error: a width should be an integer value!\n";
3964 aColorScale->SetBreadth (aBreadth.IntegerValue());
3966 else if (aFlag == "-height"
3969 if (anArgIter + 1 >= theArgNb)
3971 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3975 const TCollection_AsciiString aHeight (theArgVec[++anArgIter]);
3976 if (!aHeight.IsIntegerValue())
3978 std::cout << "Error: a width should be an integer value!\n";
3981 aColorScale->SetHeight (aHeight.IntegerValue());
3983 else if (aFlag == "-color")
3985 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
3987 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3990 else if (anArgIter + 2 >= theArgNb)
3992 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3996 const TCollection_AsciiString anInd (theArgVec[++anArgIter]);
3997 if (!anInd.IsIntegerValue())
3999 std::cout << "Error: Index value should be integer!\n";
4002 const Standard_Integer anIndex = anInd.IntegerValue();
4003 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals())
4005 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() <<"!\n";
4009 Quantity_Color aColor;
4010 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4011 theArgVec + (anArgIter + 1),
4015 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4018 aColorScale->SetIntervalColor (aColor, anIndex);
4019 aColorScale->SetColorType (Aspect_TOCSD_USER);
4020 anArgIter += aNbParsed;
4022 else if (aFlag == "-label")
4024 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
4026 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
4029 else if (anArgIter + 2 >= theArgNb)
4031 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4035 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
4036 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1)
4038 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() + 1 <<"!\n";
4042 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
4043 aColorScale->SetLabel (aText, anIndex);
4044 aColorScale->SetLabelType (Aspect_TOCSD_USER);
4047 else if (aFlag == "-labelat"
4048 || aFlag == "-labat"
4049 || aFlag == "-labelatborder"
4050 || aFlag == "-labatborder"
4051 || aFlag == "-labelatcenter"
4052 || aFlag == "-labatcenter")
4054 Standard_Boolean toEnable = Standard_True;
4055 if (aFlag == "-labelat"
4056 || aFlag == "-labat")
4058 Standard_Integer aLabAtBorder = -1;
4059 if (++anArgIter >= theArgNb)
4061 TCollection_AsciiString anAtBorder (theArgVec[anArgIter]);
4062 anAtBorder.LowerCase();
4063 if (anAtBorder == "border")
4067 else if (anAtBorder == "center")
4072 if (aLabAtBorder == -1)
4074 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4077 toEnable = (aLabAtBorder == 1);
4079 else if (anArgIter + 1 < theArgNb
4080 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
4084 aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter"
4085 || aFlag == "-labatcenter"
4089 else if (aFlag == "-colors")
4091 Aspect_SequenceOfColor aSeq;
4094 Quantity_Color aColor;
4095 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4096 theArgVec + (anArgIter + 1),
4102 anArgIter += aNbParsed;
4103 aSeq.Append (aColor);
4105 if (aSeq.Length() != aColorScale->GetNumberOfIntervals())
4107 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
4108 << aColorScale->GetNumberOfIntervals() << " intervals\n";
4112 aColorScale->SetColors (aSeq);
4113 aColorScale->SetColorType (Aspect_TOCSD_USER);
4115 else if (aFlag == "-labels"
4116 || aFlag == "-freelabels")
4118 if (anArgIter + 1 >= theArgNb)
4120 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4124 Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder()
4125 ? aColorScale->GetNumberOfIntervals() + 1
4126 : aColorScale->GetNumberOfIntervals();
4127 if (aFlag == "-freelabels")
4130 aNbLabels = Draw::Atoi (theArgVec[anArgIter]);
4132 if (anArgIter + aNbLabels >= theArgNb)
4134 std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n";
4138 TColStd_SequenceOfExtendedString aSeq;
4139 for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter)
4141 aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter]));
4143 aColorScale->SetLabels (aSeq);
4144 aColorScale->SetLabelType (Aspect_TOCSD_USER);
4146 else if (aFlag == "-title")
4148 if (anArgIter + 1 >= theArgNb)
4150 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4154 Standard_Boolean isTwoArgs = Standard_False;
4155 if (anArgIter + 2 < theArgNb)
4157 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
4158 aSecondArg.LowerCase();
4159 Standard_DISABLE_DEPRECATION_WARNINGS
4160 if (aSecondArg == "none")
4162 aColorScale->SetTitlePosition (Aspect_TOCSP_NONE);
4163 isTwoArgs = Standard_True;
4165 else if (aSecondArg == "left")
4167 aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT);
4168 isTwoArgs = Standard_True;
4170 else if (aSecondArg == "right")
4172 aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT);
4173 isTwoArgs = Standard_True;
4175 else if (aSecondArg == "center")
4177 aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER);
4178 isTwoArgs = Standard_True;
4180 Standard_ENABLE_DEPRECATION_WARNINGS
4183 aColorScale->SetTitle (theArgVec[anArgIter + 1]);
4190 else if (aFlag == "-demoversion"
4191 || aFlag == "-demo")
4193 aColorScale->SetPosition (0, 0);
4194 aColorScale->SetTextHeight (16);
4195 aColorScale->SetRange (0.0, 100.0);
4196 aColorScale->SetNumberOfIntervals (10);
4197 aColorScale->SetBreadth (0);
4198 aColorScale->SetHeight (0);
4199 aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT);
4200 aColorScale->SetColorType (Aspect_TOCSD_AUTO);
4201 aColorScale->SetLabelType (Aspect_TOCSD_AUTO);
4203 else if (aFlag == "-findcolor")
4205 if (anArgIter + 1 >= theArgNb)
4207 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4211 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
4213 if (!anArg1.IsRealValue())
4215 std::cout << "Error: the value should be real!\n";
4219 Quantity_Color aColor;
4220 aColorScale->FindColor (anArg1.RealValue(), aColor);
4221 theDI << Quantity_Color::StringName (aColor.Name());
4226 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
4231 Standard_Integer aWinWidth = 0, aWinHeight = 0;
4232 aView->Window()->Size (aWinWidth, aWinHeight);
4233 if (aColorScale->GetBreadth() == 0)
4235 aColorScale->SetBreadth (aWinWidth);
4237 if (aColorScale->GetHeight() == 0)
4239 aColorScale->SetHeight (aWinHeight);
4241 aColorScale->SetToUpdate();
4242 ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True);
4246 //==============================================================================
4247 //function : VGraduatedTrihedron
4248 //purpose : Displays or hides a graduated trihedron
4249 //==============================================================================
4250 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
4251 Quantity_Color& theColor)
4253 Quantity_NameOfColor aColorName;
4254 TCollection_AsciiString aVal = theValue;
4256 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
4258 return Standard_False;
4260 theColor = Quantity_Color (aColorName);
4261 return Standard_True;
4264 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
4268 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
4269 << theArgs[0] <<"' for more information.\n";
4270 return 1; //TCL_ERROR
4273 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
4274 TCollection_AsciiString aParseKey;
4275 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
4277 TCollection_AsciiString anArg (theArgs [anArgIt]);
4279 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
4282 aParseKey.Remove (1);
4283 aParseKey.LowerCase();
4284 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
4288 if (aParseKey.IsEmpty())
4293 aMapOfArgs(aParseKey)->Append (anArg);
4297 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
4298 aMapIt.More(); aMapIt.Next())
4300 const TCollection_AsciiString& aKey = aMapIt.Key();
4301 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
4303 // Bool key, without arguments
4304 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
4305 && anArgs->IsEmpty())
4311 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
4312 && anArgs->Length() == 1)
4318 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
4319 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
4320 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
4321 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
4322 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
4327 // One string argument
4328 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
4329 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
4330 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4335 // One integer argument
4336 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
4337 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
4338 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
4339 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
4340 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
4345 // One real argument
4346 if ( aKey.IsEqual ("arrowlength")
4347 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
4352 // Two string arguments
4353 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
4354 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4359 TCollection_AsciiString aLowerKey;
4362 aLowerKey.LowerCase();
4363 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
4364 std::cout << "Type help for more information.\n";
4368 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4369 if (anAISContext.IsNull())
4371 std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n";
4375 Standard_Boolean toDisplay = Standard_True;
4376 Quantity_Color aColor;
4377 Graphic3d_GraduatedTrihedron aTrihedronData;
4378 // Process parameters
4379 Handle(TColStd_HSequenceOfAsciiString) aValues;
4380 if (aMapOfArgs.Find ("off", aValues))
4382 toDisplay = Standard_False;
4386 if (aMapOfArgs.Find ("xname", aValues))
4388 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
4390 if (aMapOfArgs.Find ("yname", aValues))
4392 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
4394 if (aMapOfArgs.Find ("zname", aValues))
4396 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
4398 if (aMapOfArgs.Find ("xdrawname", aValues))
4400 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4402 if (aMapOfArgs.Find ("ydrawname", aValues))
4404 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4406 if (aMapOfArgs.Find ("zdrawname", aValues))
4408 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4410 if (aMapOfArgs.Find ("xnameoffset", aValues))
4412 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4414 if (aMapOfArgs.Find ("ynameoffset", aValues))
4416 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4418 if (aMapOfArgs.Find ("znameoffset", aValues))
4420 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4424 if (aMapOfArgs.Find ("xnamecolor", aValues))
4426 if (!GetColor (aValues->Value(1), aColor))
4428 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
4431 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
4433 if (aMapOfArgs.Find ("ynamecolor", aValues))
4435 if (!GetColor (aValues->Value(1), aColor))
4437 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
4440 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
4442 if (aMapOfArgs.Find ("znamecolor", aValues))
4444 if (!GetColor (aValues->Value(1), aColor))
4446 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
4449 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
4451 if (aMapOfArgs.Find ("xcolor", aValues))
4453 if (!GetColor (aValues->Value(1), aColor))
4455 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
4458 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
4460 if (aMapOfArgs.Find ("ycolor", aValues))
4462 if (!GetColor (aValues->Value(1), aColor))
4464 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
4467 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
4469 if (aMapOfArgs.Find ("zcolor", aValues))
4471 if (!GetColor (aValues->Value(1), aColor))
4473 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
4476 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
4480 if (aMapOfArgs.Find ("xticks", aValues))
4482 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4484 if (aMapOfArgs.Find ("yticks", aValues))
4486 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4488 if (aMapOfArgs.Find ("zticks", aValues))
4490 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4492 if (aMapOfArgs.Find ("xticklength", aValues))
4494 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4496 if (aMapOfArgs.Find ("yticklength", aValues))
4498 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4500 if (aMapOfArgs.Find ("zticklength", aValues))
4502 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4504 if (aMapOfArgs.Find ("xdrawticks", aValues))
4506 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4508 if (aMapOfArgs.Find ("ydrawticks", aValues))
4510 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4512 if (aMapOfArgs.Find ("zdrawticks", aValues))
4514 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4518 if (aMapOfArgs.Find ("xdrawvalues", aValues))
4520 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4522 if (aMapOfArgs.Find ("ydrawvalues", aValues))
4524 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4526 if (aMapOfArgs.Find ("zdrawvalues", aValues))
4528 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4530 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
4532 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4534 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
4536 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4538 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
4540 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4544 if (aMapOfArgs.Find ("arrowlength", aValues))
4546 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
4550 if (aMapOfArgs.Find ("namefont", aValues))
4552 aTrihedronData.SetNamesFont (aValues->Value(1));
4554 if (aMapOfArgs.Find ("valuesfont", aValues))
4556 aTrihedronData.SetValuesFont (aValues->Value(1));
4559 if (aMapOfArgs.Find ("drawgrid", aValues))
4561 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
4563 if (aMapOfArgs.Find ("drawaxes", aValues))
4565 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
4568 // The final step: display of erase trihedron
4571 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
4575 ViewerTest::CurrentView()->GraduatedTrihedronErase();
4578 ViewerTest::GetAISContext()->UpdateCurrentViewer();
4579 ViewerTest::CurrentView()->Redraw();
4584 //==============================================================================
4587 //==============================================================================
4588 static int VTile (Draw_Interpretor& theDI,
4589 Standard_Integer theArgNb,
4590 const char** theArgVec)
4592 Handle(V3d_View) aView = ViewerTest::CurrentView();
4595 std::cerr << "Error: no active viewer.\n";
4599 Graphic3d_CameraTile aTile = aView->Camera()->Tile();
4602 theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
4603 << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n"
4604 << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n";
4608 aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
4609 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4611 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4613 if (anArg == "-lowerleft"
4614 || anArg == "-upperleft")
4616 if (anArgIter + 3 < theArgNb)
4618 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4621 aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
4622 aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4623 aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4625 else if (anArg == "-total"
4626 || anArg == "-totalsize"
4627 || anArg == "-viewsize")
4629 if (anArgIter + 3 < theArgNb)
4631 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4634 aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4635 aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4636 if (aTile.TotalSize.x() < 1
4637 || aTile.TotalSize.y() < 1)
4639 std::cerr << "Error: total size is incorrect.\n";
4643 else if (anArg == "-tilesize")
4645 if (anArgIter + 3 < theArgNb)
4647 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4651 aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4652 aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4653 if (aTile.TileSize.x() < 1
4654 || aTile.TileSize.y() < 1)
4656 std::cerr << "Error: tile size is incorrect.\n";
4660 else if (anArg == "-unset")
4662 aView->Camera()->SetTile (Graphic3d_CameraTile());
4668 if (aTile.TileSize.x() < 1
4669 || aTile.TileSize.y() < 1)
4671 std::cerr << "Error: tile size is undefined.\n";
4674 else if (aTile.TotalSize.x() < 1
4675 || aTile.TotalSize.y() < 1)
4677 std::cerr << "Error: total size is undefined.\n";
4681 aView->Camera()->SetTile (aTile);
4686 //! Format ZLayer ID.
4687 inline const char* formZLayerId (const Standard_Integer theLayerId)
4691 case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]";
4692 case Graphic3d_ZLayerId_Default: return "[DEFAULT]";
4693 case Graphic3d_ZLayerId_Top: return "[TOP]";
4694 case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]";
4695 case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]";
4696 case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]";
4701 //! Print the ZLayer information.
4702 inline void printZLayerInfo (Draw_Interpretor& theDI,
4703 const Graphic3d_ZLayerSettings& theLayer)
4705 if (!theLayer.Name().IsEmpty())
4707 theDI << " Name: " << theLayer.Name() << "\n";
4709 if (theLayer.IsImmediate())
4711 theDI << " Immediate: TRUE\n";
4713 theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n";
4714 theDI << " Culling distance: " << theLayer.CullingDistance() << "\n";
4715 theDI << " Culling size: " << theLayer.CullingSize() << "\n";
4716 theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n";
4717 theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n";
4718 theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n";
4719 if (theLayer.PolygonOffset().Mode != Aspect_POM_None)
4721 theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n";
4725 //==============================================================================
4726 //function : VZLayer
4727 //purpose : Test z layer operations for v3d viewer
4728 //==============================================================================
4729 static int VZLayer (Draw_Interpretor& theDI,
4730 Standard_Integer theArgNb,
4731 const char** theArgVec)
4733 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4734 if (aContextAIS.IsNull())
4736 std::cout << "No active viewer!\n";
4740 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
4743 TColStd_SequenceOfInteger aLayers;
4744 aViewer->GetAllZLayers (aLayers);
4745 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4747 theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n";
4748 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4749 printZLayerInfo (theDI, aSettings);
4754 Standard_Integer anArgIter = 1;
4755 Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4756 ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView());
4757 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
4762 TCollection_AsciiString aFirstArg (theArgVec[anArgIter]);
4763 if (aFirstArg.IsIntegerValue())
4766 aLayerId = aFirstArg.IntegerValue();
4770 aFirstArg.LowerCase();
4771 if (aFirstArg == "default"
4772 || aFirstArg == "def")
4774 aLayerId = Graphic3d_ZLayerId_Default;
4777 else if (aFirstArg == "top")
4779 aLayerId = Graphic3d_ZLayerId_Top;
4782 else if (aFirstArg == "topmost")
4784 aLayerId = Graphic3d_ZLayerId_Topmost;
4787 else if (aFirstArg == "overlay"
4788 || aFirstArg == "toposd")
4790 aLayerId = Graphic3d_ZLayerId_TopOSD;
4793 else if (aFirstArg == "underlay"
4794 || aFirstArg == "botosd")
4796 aLayerId = Graphic3d_ZLayerId_BotOSD;
4801 TColStd_SequenceOfInteger aLayers;
4802 aViewer->GetAllZLayers (aLayers);
4803 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4805 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4806 if (TCollection_AsciiString::IsSameString (aSettings.Name(), aFirstArg, Standard_False))
4808 aLayerId = aLayeriter.Value();
4816 for (; anArgIter < theArgNb; ++anArgIter)
4818 // perform operation
4819 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4821 if (anUpdateTool.parseRedrawMode (anArg))
4825 else if (anArg == "-add"
4828 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4829 if (!aViewer->AddZLayer (aLayerId))
4831 std::cout << "Error: can not add a new z layer!\n";
4837 else if (anArg == "-del"
4838 || anArg == "-delete"
4841 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4843 if (++anArgIter >= theArgNb)
4845 std::cout << "Syntax error: id of z layer to remove is missing\n";
4849 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4852 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN
4853 || aLayerId == Graphic3d_ZLayerId_Default
4854 || aLayerId == Graphic3d_ZLayerId_Top
4855 || aLayerId == Graphic3d_ZLayerId_Topmost
4856 || aLayerId == Graphic3d_ZLayerId_TopOSD
4857 || aLayerId == Graphic3d_ZLayerId_BotOSD)
4859 std::cout << "Syntax error: standard Z layer can not be removed\n";
4863 // move all object displayed in removing layer to default layer
4864 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4865 anObjIter.More(); anObjIter.Next())
4867 const Handle(AIS_InteractiveObject)& aPrs = anObjIter.Key1();
4869 || aPrs->ZLayer() != aLayerId)
4873 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4876 if (!aViewer->RemoveZLayer (aLayerId))
4878 std::cout << "Z layer can not be removed!\n";
4882 theDI << aLayerId << " ";
4885 else if (anArg == "-get"
4888 TColStd_SequenceOfInteger aLayers;
4889 aViewer->GetAllZLayers (aLayers);
4890 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4892 theDI << aLayeriter.Value() << " ";
4897 else if (anArg == "-name")
4899 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4901 std::cout << "Syntax error: id of Z layer is missing\n";
4905 if (++anArgIter >= theArgNb)
4907 std::cout << "Syntax error: name is missing\n";
4911 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4912 aSettings.SetName (theArgVec[anArgIter]);
4913 aViewer->SetZLayerSettings (aLayerId, aSettings);
4915 else if (anArg == "-origin")
4917 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4919 std::cout << "Syntax error: id of Z layer is missing\n";
4923 if (anArgIter + 2 >= theArgNb)
4925 std::cout << "Syntax error: origin coordinates are missing\n";
4929 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4931 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1]));
4932 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2]));
4933 anOrigin.SetZ (0.0);
4934 if (anArgIter + 3 < theArgNb)
4936 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3]));
4943 aSettings.SetOrigin (anOrigin);
4944 aViewer->SetZLayerSettings (aLayerId, aSettings);
4946 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
4947 && anArgIter + 1 < theArgNb
4948 && (anArg == "-cullingdistance"
4949 || anArg == "-cullingdist"
4950 || anArg == "-culldistance"
4951 || anArg == "-culldist"
4952 || anArg == "-distcull"
4953 || anArg == "-distculling"
4954 || anArg == "-distanceculling"))
4956 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4957 const Standard_Real aDist = Draw::Atof (theArgVec[++anArgIter]);
4958 aSettings.SetCullingDistance (aDist);
4959 aViewer->SetZLayerSettings (aLayerId, aSettings);
4961 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
4962 && anArgIter + 1 < theArgNb
4963 && (anArg == "-cullingsize"
4964 || anArg == "-cullsize"
4965 || anArg == "-sizecull"
4966 || anArg == "-sizeculling"))
4968 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4969 const Standard_Real aSize = Draw::Atof (theArgVec[++anArgIter]);
4970 aSettings.SetCullingSize (aSize);
4971 aViewer->SetZLayerSettings (aLayerId, aSettings);
4973 else if (anArg == "-settings"
4974 || anArg == "settings")
4976 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4978 if (++anArgIter >= theArgNb)
4980 std::cout << "Syntax error: id of Z layer is missing\n";
4984 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4987 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4988 printZLayerInfo (theDI, aSettings);
4990 else if (anArg == "-enable"
4991 || anArg == "enable"
4992 || anArg == "-disable"
4993 || anArg == "disable")
4995 const Standard_Boolean toEnable = anArg == "-enable"
4996 || anArg == "enable";
4997 if (++anArgIter >= theArgNb)
4999 std::cout << "Syntax error: option name is missing\n";
5003 TCollection_AsciiString aSubOp (theArgVec[anArgIter]);
5005 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
5007 if (++anArgIter >= theArgNb)
5009 std::cout << "Syntax error: id of Z layer is missing\n";
5013 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5016 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5017 if (aSubOp == "depthtest"
5018 || aSubOp == "test")
5020 aSettings.SetEnableDepthTest (toEnable);
5022 else if (aSubOp == "depthwrite"
5023 || aSubOp == "write")
5025 aSettings.SetEnableDepthWrite (toEnable);
5027 else if (aSubOp == "depthclear"
5028 || aSubOp == "clear")
5030 aSettings.SetClearDepth (toEnable);
5032 else if (aSubOp == "depthoffset"
5033 || aSubOp == "offset")
5035 Graphic3d_PolygonOffset aParams;
5036 aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None;
5039 if (anArgIter + 2 >= theArgNb)
5041 std::cout << "Syntax error: factor and units values for depth offset are missing\n";
5045 aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5046 aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5048 aSettings.SetPolygonOffset (aParams);
5050 else if (aSubOp == "positiveoffset"
5051 || aSubOp == "poffset")
5055 aSettings.SetDepthOffsetPositive();
5059 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
5062 else if (aSubOp == "negativeoffset"
5063 || aSubOp == "noffset")
5067 aSettings.SetDepthOffsetNegative();
5071 aSettings.SetPolygonOffset(Graphic3d_PolygonOffset());
5074 else if (aSubOp == "textureenv")
5076 aSettings.SetEnvironmentTexture (toEnable);
5079 aViewer->SetZLayerSettings (aLayerId, aSettings);
5083 std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n";
5091 // The interactive presentation of 2d layer item
5092 // for "vlayerline" command it provides a presentation of
5093 // line with user-defined linewidth, linetype and transparency.
5094 class V3d_LineItem : public AIS_InteractiveObject
5098 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
5101 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5102 Standard_Real X2, Standard_Real Y2,
5103 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
5104 Standard_Real theWidth = 0.5,
5105 Standard_Real theTransp = 1.0);
5109 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
5110 const Handle(Prs3d_Presentation)& thePresentation,
5111 const Standard_Integer theMode) Standard_OVERRIDE;
5113 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
5114 const Standard_Integer /*aMode*/) Standard_OVERRIDE
5119 Standard_Real myX1, myY1, myX2, myY2;
5120 Aspect_TypeOfLine myType;
5121 Standard_Real myWidth;
5124 // default constructor for line item
5125 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5126 Standard_Real X2, Standard_Real Y2,
5127 Aspect_TypeOfLine theType,
5128 Standard_Real theWidth,
5129 Standard_Real theTransp) :
5130 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
5131 myType(theType), myWidth(theWidth)
5133 SetTransparency (1-theTransp);
5137 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
5138 const Handle(Prs3d_Presentation)& thePresentation,
5139 const Standard_Integer /*theMode*/)
5141 thePresentation->Clear();
5142 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
5143 Standard_Integer aWidth, aHeight;
5144 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
5145 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
5146 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
5147 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
5148 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
5149 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
5150 aGroup->SetPrimitivesAspect (anAspect->Aspect());
5151 aGroup->AddPrimitiveArray (aPrim);
5154 //=============================================================================
5155 //function : VLayerLine
5156 //purpose : Draws line in the v3d view layer with given attributes: linetype,
5157 // : linewidth, transparency coefficient
5158 //============================================================================
5159 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5161 // get the active view
5162 Handle(V3d_View) aView = ViewerTest::CurrentView();
5165 di << "Call vinit before!\n";
5170 di << "Use: " << argv[0];
5171 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
5172 di << " linetype : { 0 | 1 | 2 | 3 } \n";
5173 di << " 0 - solid \n";
5174 di << " 1 - dashed \n";
5175 di << " 2 - dot \n";
5176 di << " 3 - dashdot\n";
5177 di << " transparency : { 0.0 - 1.0 } \n";
5178 di << " 0.0 - transparent\n";
5179 di << " 1.0 - visible \n";
5183 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5184 // get the input params
5185 Standard_Real X1 = Draw::Atof(argv[1]);
5186 Standard_Real Y1 = Draw::Atof(argv[2]);
5187 Standard_Real X2 = Draw::Atof(argv[3]);
5188 Standard_Real Y2 = Draw::Atof(argv[4]);
5190 Standard_Real aWidth = 0.5;
5191 Standard_Real aTransparency = 1.0;
5195 aWidth = Draw::Atof(argv[5]);
5197 // select appropriate line type
5198 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
5200 && !ViewerTest::ParseLineType (argv[6], aLineType))
5202 std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n";
5209 aTransparency = Draw::Atof(argv[7]);
5210 if (aTransparency < 0 || aTransparency > 1.0)
5211 aTransparency = 1.0;
5214 static Handle (V3d_LineItem) aLine;
5215 if (!aLine.IsNull())
5217 aContext->Erase (aLine, Standard_False);
5219 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
5223 aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
5224 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
5225 aLine->SetToUpdate();
5226 aContext->Display (aLine, Standard_True);
5232 //==============================================================================
5235 //==============================================================================
5237 static int VGrid (Draw_Interpretor& /*theDI*/,
5238 Standard_Integer theArgNb,
5239 const char** theArgVec)
5241 // get the active view
5242 Handle(V3d_View) aView = ViewerTest::CurrentView();
5243 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5244 if (aView.IsNull() || aViewer.IsNull())
5246 std::cerr << "No active view. Please call vinit.\n";
5250 Aspect_GridType aType = aViewer->GridType();
5251 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
5252 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
5253 Standard_Integer anIter = 1;
5254 for (; anIter < theArgNb; ++anIter)
5256 const char* aValue = theArgVec[anIter];
5257 if (anUpdateTool.parseRedrawMode (aValue))
5261 else if (*aValue == 'r')
5263 aType = Aspect_GT_Rectangular;
5265 else if (*aValue == 'c')
5267 aType = Aspect_GT_Circular;
5269 else if (*aValue == 'l')
5271 aMode = Aspect_GDM_Lines;
5273 else if (*aValue == 'p')
5275 aMode = Aspect_GDM_Points;
5277 else if (strcmp (aValue, "off" ) == 0)
5279 aViewer->DeactivateGrid();
5288 Standard_Integer aTail = (theArgNb - anIter);
5291 aViewer->ActivateGrid (aType, aMode);
5294 else if (aTail != 2 && aTail != 5)
5296 std::cerr << "Incorrect arguments number! Usage:\n"
5297 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
5301 Standard_Real anOriginX, anOriginY, aRotAngle;
5302 if (aType == Aspect_GT_Rectangular)
5304 Standard_Real aRStepX, aRStepY;
5305 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
5307 anOriginX = Draw::Atof (theArgVec[anIter++]);
5308 anOriginY = Draw::Atof (theArgVec[anIter++]);
5311 aRStepX = Draw::Atof (theArgVec[anIter++]);
5312 aRStepY = Draw::Atof (theArgVec[anIter++]);
5313 aRotAngle = Draw::Atof (theArgVec[anIter++]);
5315 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
5316 aViewer->ActivateGrid (aType, aMode);
5318 else if (aType == Aspect_GT_Circular)
5320 Standard_Real aRadiusStep;
5321 Standard_Integer aDivisionNumber;
5322 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
5324 anOriginX = Draw::Atof (theArgVec[anIter++]);
5325 anOriginY = Draw::Atof (theArgVec[anIter++]);
5328 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
5329 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
5330 aRotAngle = Draw::Atof (theArgVec[anIter++]);
5333 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
5334 aViewer->ActivateGrid (aType, aMode);
5340 //==============================================================================
5341 //function : VPriviledgedPlane
5343 //==============================================================================
5345 static int VPriviledgedPlane (Draw_Interpretor& theDI,
5346 Standard_Integer theArgNb,
5347 const char** theArgVec)
5349 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
5351 std::cerr << "Error: wrong number of arguments! See usage:\n";
5352 theDI.PrintHelp (theArgVec[0]);
5356 // get the active viewer
5357 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5358 if (aViewer.IsNull())
5360 std::cerr << "Error: no active viewer. Please call vinit.\n";
5366 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
5367 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
5368 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
5369 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
5370 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
5371 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
5372 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
5376 Standard_Integer anArgIdx = 1;
5377 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
5378 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
5379 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
5380 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
5381 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
5382 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
5384 gp_Ax3 aPriviledgedPlane;
5385 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
5386 gp_Dir aNorm (aNormX, aNormY, aNormZ);
5389 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
5390 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
5391 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
5392 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
5393 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
5397 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
5400 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
5405 //==============================================================================
5406 //function : VConvert
5408 //==============================================================================
5410 static int VConvert (Draw_Interpretor& theDI,
5411 Standard_Integer theArgNb,
5412 const char** theArgVec)
5414 // get the active view
5415 Handle(V3d_View) aView = ViewerTest::CurrentView();
5418 std::cerr << "Error: no active view. Please call vinit.\n";
5422 enum { Model, Ray, View, Window, Grid } aMode = Model;
5424 // access coordinate arguments
5425 TColStd_SequenceOfReal aCoord;
5426 Standard_Integer anArgIdx = 1;
5427 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
5429 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5430 if (!anArg.IsRealValue())
5434 aCoord.Append (anArg.RealValue());
5437 // non-numeric argument too early
5438 if (aCoord.IsEmpty())
5440 std::cerr << "Error: wrong number of arguments! See usage:\n";
5441 theDI.PrintHelp (theArgVec[0]);
5445 // collect all other arguments and options
5446 for (; anArgIdx < theArgNb; ++anArgIdx)
5448 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5450 if (anArg == "window") aMode = Window;
5451 else if (anArg == "view") aMode = View;
5452 else if (anArg == "grid") aMode = Grid;
5453 else if (anArg == "ray") aMode = Ray;
5456 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
5457 theDI.PrintHelp (theArgVec[0]);
5462 // complete input checks
5463 if ((aCoord.Length() == 1 && theArgNb > 3) ||
5464 (aCoord.Length() == 2 && theArgNb > 4) ||
5465 (aCoord.Length() == 3 && theArgNb > 5))
5467 std::cerr << "Error: wrong number of arguments! See usage:\n";
5468 theDI.PrintHelp (theArgVec[0]);
5472 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
5473 Standard_Integer aXYp[2] = {0, 0};
5475 // convert one-dimensional coordinate
5476 if (aCoord.Length() == 1)
5480 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0;
5481 case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0;
5483 std::cerr << "Error: wrong arguments! See usage:\n";
5484 theDI.PrintHelp (theArgVec[0]);
5489 // convert 2D coordinates from projection or view reference space
5490 if (aCoord.Length() == 2)
5495 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5496 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5500 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5501 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5505 aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]);
5506 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5510 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5511 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5512 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5516 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5517 (Standard_Integer) aCoord (2),
5518 aXYZ[0], aXYZ[1], aXYZ[2],
5519 aXYZ[3], aXYZ[4], aXYZ[5]);
5520 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5524 std::cerr << "Error: wrong arguments! See usage:\n";
5525 theDI.PrintHelp (theArgVec[0]);
5530 // convert 3D coordinates from view reference space
5531 else if (aCoord.Length() == 3)
5536 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5537 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5541 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5542 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5546 std::cerr << "Error: wrong arguments! See usage:\n";
5547 theDI.PrintHelp (theArgVec[0]);
5555 //==============================================================================
5558 //==============================================================================
5560 static int VFps (Draw_Interpretor& theDI,
5561 Standard_Integer theArgNb,
5562 const char** theArgVec)
5564 // get the active view
5565 Handle(V3d_View) aView = ViewerTest::CurrentView();
5568 std::cerr << "No active view. Please call vinit.\n";
5572 Standard_Integer aFramesNb = -1;
5573 Standard_Real aDuration = -1.0;
5574 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5576 TCollection_AsciiString anArg (theArgVec[anArgIter]);
5579 && anArgIter + 1 < theArgNb
5580 && (anArg == "-duration"
5582 || anArg == "-time"))
5584 aDuration = Draw::Atof (theArgVec[++anArgIter]);
5586 else if (aFramesNb < 0
5587 && anArg.IsIntegerValue())
5589 aFramesNb = anArg.IntegerValue();
5592 std::cerr << "Syntax error at '" << anArg << "'\n";
5598 std::cerr << "Syntax error at '" << anArg << "'\n";
5602 if (aFramesNb < 0 && aDuration < 0.0)
5607 // the time is meaningless for first call
5608 // due to async OpenGl rendering
5611 // redraw view in loop to estimate average values
5614 Standard_Integer aFrameIter = 1;
5615 for (;; ++aFrameIter)
5619 && aFrameIter >= aFramesNb)
5621 && aTimer.ElapsedTime() >= aDuration))
5628 const Standard_Real aTime = aTimer.ElapsedTime();
5629 aTimer.OSD_Chronometer::Show (aCpu);
5631 const Standard_Real aFpsAver = Standard_Real(aFrameIter) / aTime;
5632 const Standard_Real aCpuAver = aCpu / Standard_Real(aFrameIter);
5634 // return statistics
5635 theDI << "FPS: " << aFpsAver << "\n"
5636 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5638 // compute additional statistics in ray-tracing mode
5639 const Graphic3d_RenderingParams& aParams = aView->RenderingParams();
5640 if (aParams.Method == Graphic3d_RM_RAYTRACING)
5642 Graphic3d_Vec2i aWinSize (0, 0);
5643 aView->Window()->Size (aWinSize.x(), aWinSize.y());
5645 // 1 shadow ray and 1 secondary ray pew each bounce
5646 const Standard_Real aMRays = aWinSize.x() * aWinSize.y() * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
5647 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
5653 //! Auxiliary function for parsing glsl dump level argument.
5654 static Standard_Boolean parseGlslSourceFlag (Standard_CString theArg,
5655 OpenGl_ShaderProgramDumpLevel& theGlslDumpLevel)
5657 TCollection_AsciiString aTypeStr (theArg);
5658 aTypeStr.LowerCase();
5659 if (aTypeStr == "off"
5662 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
5664 else if (aTypeStr == "short")
5666 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Short;
5668 else if (aTypeStr == "full"
5671 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
5675 return Standard_False;
5677 return Standard_True;
5680 //==============================================================================
5681 //function : VGlDebug
5683 //==============================================================================
5685 static int VGlDebug (Draw_Interpretor& theDI,
5686 Standard_Integer theArgNb,
5687 const char** theArgVec)
5689 Handle(OpenGl_GraphicDriver) aDriver;
5690 Handle(V3d_View) aView = ViewerTest::CurrentView();
5691 if (!aView.IsNull())
5693 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5695 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
5696 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
5700 TCollection_AsciiString aDebActive, aSyncActive;
5707 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
5708 "GL_ARB_debug_output");
5709 aDebActive = isActive ? " (active)" : " (inactive)";
5712 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
5713 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
5717 TCollection_AsciiString aGlslCodeDebugStatus = TCollection_AsciiString()
5718 + "glslSourceCode: "
5719 + (aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Off
5721 : aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Short
5725 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
5726 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
5727 << "glslWarn: " << (aCaps->glslWarnings ? "1" : "0") << "\n"
5728 << aGlslCodeDebugStatus
5729 << "extraMsg: " << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
5733 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5735 Standard_CString anArg = theArgVec[anArgIter];
5736 TCollection_AsciiString anArgCase (anArg);
5737 anArgCase.LowerCase();
5738 Standard_Boolean toEnableDebug = Standard_True;
5739 if (anArgCase == "-glsl"
5740 || anArgCase == "-glslwarn"
5741 || anArgCase == "-glslwarns"
5742 || anArgCase == "-glslwarnings")
5744 Standard_Boolean toShowWarns = Standard_True;
5745 if (++anArgIter < theArgNb
5746 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
5750 aDefCaps->glslWarnings = toShowWarns;
5753 aCaps->glslWarnings = toShowWarns;
5756 else if (anArgCase == "-extra"
5757 || anArgCase == "-extramsg"
5758 || anArgCase == "-extramessages")
5760 Standard_Boolean toShow = Standard_True;
5761 if (++anArgIter < theArgNb
5762 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
5766 aDefCaps->suppressExtraMsg = !toShow;
5769 aCaps->suppressExtraMsg = !toShow;
5772 else if (anArgCase == "-noextra"
5773 || anArgCase == "-noextramsg"
5774 || anArgCase == "-noextramessages")
5776 Standard_Boolean toSuppress = Standard_True;
5777 if (++anArgIter < theArgNb
5778 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
5782 aDefCaps->suppressExtraMsg = toSuppress;
5785 aCaps->suppressExtraMsg = toSuppress;
5788 else if (anArgCase == "-sync")
5790 Standard_Boolean toSync = Standard_True;
5791 if (++anArgIter < theArgNb
5792 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
5796 aDefCaps->contextSyncDebug = toSync;
5799 aDefCaps->contextDebug = Standard_True;
5802 else if (anArgCase == "-glslsourcecode"
5803 || anArgCase == "-glslcode")
5805 OpenGl_ShaderProgramDumpLevel aGslsDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
5806 if (++anArgIter < theArgNb
5807 && !parseGlslSourceFlag (theArgVec[anArgIter], aGslsDumpLevel))
5811 aDefCaps->glslDumpLevel = aGslsDumpLevel;
5814 aCaps->glslDumpLevel = aGslsDumpLevel;
5817 else if (anArgCase == "-debug")
5819 if (++anArgIter < theArgNb
5820 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
5824 aDefCaps->contextDebug = toEnableDebug;
5826 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
5827 && (anArgIter + 1 == theArgNb))
5829 // simple alias to turn on almost everything
5830 aDefCaps->contextDebug = toEnableDebug;
5831 aDefCaps->contextSyncDebug = toEnableDebug;
5832 aDefCaps->glslWarnings = toEnableDebug;
5835 aDefCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
5837 aDefCaps->suppressExtraMsg = !toEnableDebug;
5840 aCaps->contextDebug = toEnableDebug;
5841 aCaps->contextSyncDebug = toEnableDebug;
5842 aCaps->glslWarnings = toEnableDebug;
5845 aCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
5847 aCaps->suppressExtraMsg = !toEnableDebug;
5852 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
5860 //==============================================================================
5863 //==============================================================================
5865 static int VVbo (Draw_Interpretor& theDI,
5866 Standard_Integer theArgNb,
5867 const char** theArgVec)
5869 const Standard_Boolean toSet = (theArgNb > 1);
5870 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
5873 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
5877 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5878 if (aContextAIS.IsNull())
5882 std::cerr << "No active view!\n";
5886 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5887 if (!aDriver.IsNull())
5891 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
5895 aDriver->ChangeOptions().vboDisable = toUseVbo;
5902 //==============================================================================
5905 //==============================================================================
5907 static int VCaps (Draw_Interpretor& theDI,
5908 Standard_Integer theArgNb,
5909 const char** theArgVec)
5911 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
5912 Handle(OpenGl_GraphicDriver) aDriver;
5913 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5914 if (!aContext.IsNull())
5916 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
5917 aCaps = &aDriver->ChangeOptions();
5922 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
5923 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
5924 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
5925 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
5926 theDI << "PolygonMode: " << (aCaps->usePolygonMode ? "1" : "0") << "\n";
5927 theDI << "VSync: " << aCaps->swapInterval << "\n";
5928 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
5929 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
5930 theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n";
5934 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5935 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5937 Standard_CString anArg = theArgVec[anArgIter];
5938 TCollection_AsciiString anArgCase (anArg);
5939 anArgCase.LowerCase();
5940 if (anUpdateTool.parseRedrawMode (anArg))
5944 else if (anArgCase == "-vsync"
5945 || anArgCase == "-swapinterval")
5947 Standard_Boolean toEnable = Standard_True;
5948 if (++anArgIter < theArgNb
5949 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5953 aCaps->swapInterval = toEnable;
5955 else if (anArgCase == "-ffp")
5957 Standard_Boolean toEnable = Standard_True;
5958 if (++anArgIter < theArgNb
5959 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5963 aCaps->ffpEnable = toEnable;
5965 else if (anArgCase == "-polygonmode")
5967 Standard_Boolean toEnable = Standard_True;
5968 if (++anArgIter < theArgNb
5969 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5973 aCaps->usePolygonMode = toEnable;
5975 else if (anArgCase == "-vbo")
5977 Standard_Boolean toEnable = Standard_True;
5978 if (++anArgIter < theArgNb
5979 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5983 aCaps->vboDisable = !toEnable;
5985 else if (anArgCase == "-sprite"
5986 || anArgCase == "-sprites")
5988 Standard_Boolean toEnable = Standard_True;
5989 if (++anArgIter < theArgNb
5990 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5994 aCaps->pntSpritesDisable = !toEnable;
5996 else if (anArgCase == "-softmode")
5998 Standard_Boolean toEnable = Standard_True;
5999 if (++anArgIter < theArgNb
6000 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6004 aCaps->contextNoAccel = toEnable;
6006 else if (anArgCase == "-winbuffer"
6007 || anArgCase == "-windowbuffer"
6008 || anArgCase == "-usewinbuffer"
6009 || anArgCase == "-usewindowbuffer"
6010 || anArgCase == "-usesystembuffer")
6012 Standard_Boolean toEnable = Standard_True;
6013 if (++anArgIter < theArgNb
6014 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6018 aCaps->useSystemBuffer = toEnable;
6020 else if (anArgCase == "-accel"
6021 || anArgCase == "-acceleration")
6023 Standard_Boolean toEnable = Standard_True;
6024 if (++anArgIter < theArgNb
6025 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6029 aCaps->contextNoAccel = !toEnable;
6031 else if (anArgCase == "-compat"
6032 || anArgCase == "-compatprofile"
6033 || anArgCase == "-compatible"
6034 || anArgCase == "-compatibleprofile")
6036 Standard_Boolean toEnable = Standard_True;
6037 if (++anArgIter < theArgNb
6038 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6042 aCaps->contextCompatible = toEnable;
6043 if (!aCaps->contextCompatible)
6045 aCaps->ffpEnable = Standard_False;
6048 else if (anArgCase == "-core"
6049 || anArgCase == "-coreprofile")
6051 Standard_Boolean toEnable = Standard_True;
6052 if (++anArgIter < theArgNb
6053 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6057 aCaps->contextCompatible = !toEnable;
6058 if (!aCaps->contextCompatible)
6060 aCaps->ffpEnable = Standard_False;
6063 else if (anArgCase == "-stereo"
6064 || anArgCase == "-quadbuffer")
6066 Standard_Boolean toEnable = Standard_True;
6067 if (++anArgIter < theArgNb
6068 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6072 aCaps->contextStereo = toEnable;
6076 std::cout << "Error: unknown argument '" << anArg << "'\n";
6080 if (aCaps != &ViewerTest_myDefaultCaps)
6082 ViewerTest_myDefaultCaps = *aCaps;
6087 //==============================================================================
6088 //function : VMemGpu
6090 //==============================================================================
6092 static int VMemGpu (Draw_Interpretor& theDI,
6093 Standard_Integer theArgNb,
6094 const char** theArgVec)
6097 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
6098 if (aContextAIS.IsNull())
6100 std::cerr << "No active view. Please call vinit.\n";
6104 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
6105 if (aDriver.IsNull())
6107 std::cerr << "Graphic driver not available.\n";
6111 Standard_Size aFreeBytes = 0;
6112 TCollection_AsciiString anInfo;
6113 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
6115 std::cerr << "Information not available.\n";
6119 if (theArgNb > 1 && *theArgVec[1] == 'f')
6121 theDI << Standard_Real (aFreeBytes);
6131 // ==============================================================================
6132 // function : VReadPixel
6134 // ==============================================================================
6135 static int VReadPixel (Draw_Interpretor& theDI,
6136 Standard_Integer theArgNb,
6137 const char** theArgVec)
6139 // get the active view
6140 Handle(V3d_View) aView = ViewerTest::CurrentView();
6143 std::cerr << "No active view. Please call vinit.\n";
6146 else if (theArgNb < 3)
6148 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
6152 Image_Format aFormat = Image_Format_RGBA;
6153 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
6155 Standard_Integer aWidth, aHeight;
6156 aView->Window()->Size (aWidth, aHeight);
6157 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
6158 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
6159 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
6161 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
6165 Standard_Boolean toShowName = Standard_False;
6166 Standard_Boolean toShowHls = Standard_False;
6167 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
6169 TCollection_AsciiString aParam (theArgVec[anIter]);
6171 if (aParam == "rgb")
6173 aFormat = Image_Format_RGB;
6174 aBufferType = Graphic3d_BT_RGB;
6176 else if (aParam == "hls")
6178 aFormat = Image_Format_RGB;
6179 aBufferType = Graphic3d_BT_RGB;
6180 toShowHls = Standard_True;
6182 else if (aParam == "rgbf")
6184 aFormat = Image_Format_RGBF;
6185 aBufferType = Graphic3d_BT_RGB;
6187 else if (aParam == "rgba")
6189 aFormat = Image_Format_RGBA;
6190 aBufferType = Graphic3d_BT_RGBA;
6192 else if (aParam == "rgbaf")
6194 aFormat = Image_Format_RGBAF;
6195 aBufferType = Graphic3d_BT_RGBA;
6197 else if (aParam == "depth")
6199 aFormat = Image_Format_GrayF;
6200 aBufferType = Graphic3d_BT_Depth;
6202 else if (aParam == "name")
6204 toShowName = Standard_True;
6208 Image_PixMap anImage;
6209 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
6211 std::cerr << "Image allocation failed\n";
6214 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
6216 std::cerr << "Image dump failed\n";
6220 // redirect possible warning messages that could have been added by ToPixMap
6221 // into the Tcl interpretor (via DefaultMessenger) to cout, so that they do not
6222 // contaminate result of the command
6223 Standard_CString aWarnLog = theDI.Result();
6224 if (aWarnLog != NULL && aWarnLog[0] != '\0')
6226 std::cout << aWarnLog << std::endl;
6230 Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY);
6233 if (aBufferType == Graphic3d_BT_RGBA)
6235 theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha();
6239 theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
6244 switch (aBufferType)
6247 case Graphic3d_BT_RGB:
6251 theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation();
6255 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue();
6259 case Graphic3d_BT_RGBA:
6261 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue() << " " << aColor.Alpha();
6264 case Graphic3d_BT_Depth:
6266 theDI << aColor.GetRGB().Red();
6275 //! Auxiliary presentation for an image plane.
6276 class ViewerTest_ImagePrs : public AIS_InteractiveObject
6279 //! Main constructor.
6280 ViewerTest_ImagePrs (const Handle(Image_PixMap)& theImage,
6281 const Standard_Real theWidth,
6282 const Standard_Real theHeight,
6283 const TCollection_AsciiString& theLabel)
6284 : myLabel (theLabel), myWidth (theWidth), myHeight(theHeight)
6288 myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost);
6290 myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
6291 const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect();
6292 Graphic3d_MaterialAspect aMat;
6293 aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC);
6294 aMat.SetAmbient (1.0);
6295 aMat.SetDiffuse (1.0);
6296 aMat.SetSpecular (1.0);
6297 aMat.SetEmissive (1.0);
6298 aMat.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
6299 aMat.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
6300 aMat.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
6301 aMat.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
6302 aMat.SetAmbientColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6303 aMat.SetDiffuseColor (Quantity_Color (1.0, 1.0, 1.0, Quantity_TOC_RGB));
6304 aMat.SetSpecularColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6305 aMat.SetEmissiveColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6306 aFillAspect->SetFrontMaterial (aMat);
6307 aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage));
6308 aFillAspect->SetTextureMapOn();
6311 Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect();
6312 aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER);
6313 aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER);
6314 myDrawer->SetTextAspect (aTextAspect);
6317 const gp_Dir aNorm (0.0, 0.0, 1.0);
6318 myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true);
6319 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0));
6320 myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0));
6321 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0));
6322 myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0));
6323 myTris->AddEdge (1);
6324 myTris->AddEdge (2);
6325 myTris->AddEdge (3);
6326 myTris->AddEdge (3);
6327 myTris->AddEdge (2);
6328 myTris->AddEdge (4);
6330 myRect = new Graphic3d_ArrayOfPolylines (4);
6331 myRect->AddVertex (myTris->Vertice (1));
6332 myRect->AddVertex (myTris->Vertice (3));
6333 myRect->AddVertex (myTris->Vertice (4));
6334 myRect->AddVertex (myTris->Vertice (2));
6338 //! Returns TRUE for accepted display modes.
6339 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; }
6341 //! Compute presentation.
6342 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& , const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) Standard_OVERRIDE
6348 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
6349 aGroup->AddPrimitiveArray (myTris);
6350 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
6351 aGroup->AddPrimitiveArray (myRect);
6352 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
6357 Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0));
6358 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
6359 aGroup->AddPrimitiveArray (myRect);
6360 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
6366 //! Compute selection.
6367 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE
6371 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5);
6372 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner);
6373 aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location());
6374 theSel->Add (aSensitive);
6379 Handle(Graphic3d_ArrayOfTriangles) myTris;
6380 Handle(Graphic3d_ArrayOfPolylines) myRect;
6381 TCollection_AsciiString myLabel;
6382 Standard_Real myWidth;
6383 Standard_Real myHeight;
6386 //==============================================================================
6387 //function : VDiffImage
6388 //purpose : The draw-command compares two images.
6389 //==============================================================================
6391 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
6395 std::cout << "Syntax error: not enough arguments.\n";
6399 Standard_Integer anArgIter = 1;
6400 TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]);
6401 TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]);
6402 TCollection_AsciiString aDiffImagePath;
6403 Standard_Real aTolColor = -1.0;
6404 Standard_Integer toBlackWhite = -1;
6405 Standard_Integer isBorderFilterOn = -1;
6406 Standard_Boolean isOldSyntax = Standard_False;
6407 TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff;
6408 for (; anArgIter < theArgNb; ++anArgIter)
6410 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6412 if (anArgIter + 1 < theArgNb
6413 && (anArg == "-toleranceofcolor"
6414 || anArg == "-tolerancecolor"
6415 || anArg == "-tolerance"
6416 || anArg == "-toler"))
6418 aTolColor = Atof (theArgVec[++anArgIter]);
6419 if (aTolColor < 0.0 || aTolColor > 1.0)
6421 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
6425 else if (anArg == "-blackwhite")
6427 Standard_Boolean toEnable = Standard_True;
6428 if (anArgIter + 1 < theArgNb
6429 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6433 toBlackWhite = toEnable ? 1 : 0;
6435 else if (anArg == "-borderfilter")
6437 Standard_Boolean toEnable = Standard_True;
6438 if (anArgIter + 1 < theArgNb
6439 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6443 isBorderFilterOn = toEnable ? 1 : 0;
6445 else if (anArg == "-exitonclose")
6447 Draw_ToExitOnCloseView = true;
6448 if (anArgIter + 1 < theArgNb
6449 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToExitOnCloseView))
6454 else if (anArg == "-closeonescape"
6455 || anArg == "-closeonesc")
6457 Draw_ToCloseViewOnEsc = true;
6458 if (anArgIter + 1 < theArgNb
6459 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToCloseViewOnEsc))
6464 else if (anArgIter + 3 < theArgNb
6465 && anArg == "-display")
6467 aViewName = theArgVec[++anArgIter];
6468 aPrsNameRef = theArgVec[++anArgIter];
6469 aPrsNameNew = theArgVec[++anArgIter];
6470 if (anArgIter + 1 < theArgNb
6471 && *theArgVec[anArgIter + 1] != '-')
6473 aPrsNameDiff = theArgVec[++anArgIter];
6476 else if (aTolColor < 0.0
6477 && anArg.IsRealValue())
6479 isOldSyntax = Standard_True;
6480 aTolColor = anArg.RealValue();
6481 if (aTolColor < 0.0 || aTolColor > 1.0)
6483 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
6487 else if (isOldSyntax
6488 && toBlackWhite == -1
6489 && (anArg == "0" || anArg == "1"))
6491 toBlackWhite = anArg == "1" ? 1 : 0;
6493 else if (isOldSyntax
6494 && isBorderFilterOn == -1
6495 && (anArg == "0" || anArg == "1"))
6497 isBorderFilterOn = anArg == "1" ? 1 : 0;
6499 else if (aDiffImagePath.IsEmpty())
6501 aDiffImagePath = theArgVec[anArgIter];
6505 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
6510 Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap();
6511 Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap();
6512 if (!anImgRef->Load (anImgPathRef))
6514 std::cout << "Error: image file '" << anImgPathRef << "' cannot be read\n";
6517 if (!anImgNew->Load (anImgPathNew))
6519 std::cout << "Error: image file '" << anImgPathNew << "' cannot be read\n";
6523 // compare the images
6524 Image_Diff aComparer;
6525 Standard_Integer aDiffColorsNb = -1;
6526 if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1))
6528 aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0);
6529 aComparer.SetBorderFilterOn (isBorderFilterOn == 1);
6530 aDiffColorsNb = aComparer.Compare();
6531 theDI << aDiffColorsNb << "\n";
6534 // save image of difference
6535 Handle(Image_AlienPixMap) aDiff;
6536 if (aDiffColorsNb > 0
6537 && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty()))
6539 aDiff = new Image_AlienPixMap();
6540 if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY()))
6542 std::cout << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY() << "\n";
6545 aComparer.SaveDiffImage (*aDiff);
6546 if (!aDiffImagePath.IsEmpty()
6547 && !aDiff->Save (aDiffImagePath))
6549 std::cout << "Error: diff image file '" << aDiffImagePath << "' cannot be written\n";
6554 if (aViewName.IsEmpty())
6559 ViewerTest_Names aViewNames (aViewName);
6560 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
6562 TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName();
6563 theDI.Eval (aCommand.ToCString());
6566 Standard_Integer aPxLeft = 0;
6567 Standard_Integer aPxTop = 0;
6568 Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2);
6569 Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty()
6570 ? int(anImgRef->SizeY() * 2)
6571 : int(anImgRef->SizeY());
6572 TCollection_AsciiString aDisplayName;
6573 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aWinSizeX, aWinSizeY,
6574 aViewName, aDisplayName);
6576 Standard_Real aRatio = anImgRef->Ratio();
6577 Standard_Real aSizeX = 1.0;
6578 Standard_Real aSizeY = aSizeX / aRatio;
6580 OSD_Path aPath (anImgPathRef);
6581 TCollection_AsciiString aLabelRef;
6582 if (!aPath.Name().IsEmpty())
6584 aLabelRef = aPath.Name() + aPath.Extension();
6586 aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY());
6588 Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef);
6590 aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0));
6591 anImgRefPrs->SetLocalTransformation (aTrsfRef);
6592 ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true);
6595 OSD_Path aPath (anImgPathNew);
6596 TCollection_AsciiString aLabelNew;
6597 if (!aPath.Name().IsEmpty())
6599 aLabelNew = aPath.Name() + aPath.Extension();
6601 aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY());
6603 Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew);
6605 aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0));
6606 anImgNewPrs->SetLocalTransformation (aTrsfRef);
6607 ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true);
6609 Handle(ViewerTest_ImagePrs) anImgDiffPrs;
6610 if (!aDiff.IsNull())
6612 anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels");
6614 aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0));
6615 anImgDiffPrs->SetLocalTransformation (aTrsfDiff);
6617 if (!aPrsNameDiff.IsEmpty())
6619 ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true);
6621 ViewerTest::CurrentView()->SetProj (V3d_Zpos);
6622 ViewerTest::CurrentView()->FitAll();
6626 //=======================================================================
6627 //function : VSelect
6628 //purpose : Emulates different types of selection by mouse:
6629 // 1) single click selection
6630 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
6631 // 3) selection with polygon having corners at
6632 // pixel positions (x1,y1),...,(xn,yn)
6633 // 4) any of these selections with shift button pressed
6634 //=======================================================================
6635 static Standard_Integer VSelect (Draw_Interpretor& di,
6636 Standard_Integer argc,
6641 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]\n";
6645 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
6646 if(myAIScontext.IsNull())
6648 di << "use 'vinit' command before " << argv[0] << "\n";
6652 const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1));
6653 Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1;
6654 TCollection_AsciiString anArg;
6655 anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2];
6657 if (anArg == "-allowoverlap")
6659 Standard_Boolean isValidated = isShiftSelection ? argc == 8
6663 di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection";
6667 Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
6668 myAIScontext->MainSelector()->AllowOverlapDetection (isToAllow != 0);
6672 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
6673 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
6676 if(isShiftSelection)
6677 aCurrentEventManager->ShiftSelect();
6679 aCurrentEventManager->Select();
6681 else if(aCoordsNb == 4)
6683 if(isShiftSelection)
6684 aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
6686 aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
6690 TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2);
6692 for(Standard_Integer i=1;i<=aCoordsNb / 2;++i)
6693 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
6695 if(isShiftSelection)
6696 aCurrentEventManager->ShiftSelect(aPolyline);
6698 aCurrentEventManager->Select(aPolyline);
6703 //=======================================================================
6704 //function : VMoveTo
6705 //purpose : Emulates cursor movement to defined pixel position
6706 //=======================================================================
6707 static Standard_Integer VMoveTo (Draw_Interpretor& theDI,
6708 Standard_Integer theNbArgs,
6709 const char** theArgVec)
6711 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
6712 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
6713 if (aContext.IsNull())
6715 std::cout << "Error: no active View\n";
6719 Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast());
6720 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
6722 TCollection_AsciiString anArgStr (theArgVec[anArgIter]);
6723 anArgStr.LowerCase();
6724 if (anArgStr == "-reset"
6725 || anArgStr == "-clear")
6727 if (anArgIter + 1 < theNbArgs)
6729 std::cout << "Syntax error at '" << theArgVec[anArgIter + 1] << "'\n";
6733 const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive()
6734 && aContext->CurrentViewer()->GridEcho();
6737 aContext->CurrentViewer()->HideGridEcho (aView);
6739 if (aContext->ClearDetected() || toEchoGrid)
6741 aContext->CurrentViewer()->RedrawImmediate();
6745 else if (aMousePos.x() == IntegerLast()
6746 && anArgStr.IsIntegerValue())
6748 aMousePos.x() = anArgStr.IntegerValue();
6750 else if (aMousePos.y() == IntegerLast()
6751 && anArgStr.IsIntegerValue())
6753 aMousePos.y() = anArgStr.IntegerValue();
6757 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
6762 if (aMousePos.x() == IntegerLast()
6763 || aMousePos.y() == IntegerLast())
6765 std::cout << "Syntax error: wrong number of arguments\n";
6769 ViewerTest::CurrentEventManager()->MoveTo (aMousePos.x(), aMousePos.y());
6770 gp_Pnt aTopPnt (RealLast(), RealLast(), RealLast());
6771 const Handle(SelectMgr_EntityOwner)& aDetOwner = aContext->DetectedOwner();
6772 for (Standard_Integer aDetIter = 1; aDetIter <= aContext->MainSelector()->NbPicked(); ++aDetIter)
6774 if (aContext->MainSelector()->Picked (aDetIter) == aDetOwner)
6776 aTopPnt = aContext->MainSelector()->PickedPoint (aDetIter);
6780 theDI << aTopPnt.X() << " " << aTopPnt.Y() << " " << aTopPnt.Z();
6786 //! Global map storing all animations registered in ViewerTest.
6787 static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap;
6789 //! The animation calling the Draw Harness command.
6790 class ViewerTest_AnimationProc : public AIS_Animation
6794 //! Main constructor.
6795 ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName,
6796 Draw_Interpretor* theDI,
6797 const TCollection_AsciiString& theCommand)
6798 : AIS_Animation (theAnimationName),
6800 myCommand (theCommand)
6807 //! Evaluate the command.
6808 virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE
6810 TCollection_AsciiString aCmd = myCommand;
6811 replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts));
6812 replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts));
6813 replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts));
6814 replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized));
6815 replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized));
6816 myDrawInter->Eval (aCmd.ToCString());
6819 //! Find the keyword in the command and replace it with value.
6820 //! @return the position of the keyword to pass value
6821 void replace (TCollection_AsciiString& theCmd,
6822 const TCollection_AsciiString& theKey,
6823 const TCollection_AsciiString& theVal)
6825 TCollection_AsciiString aCmd (theCmd);
6827 const Standard_Integer aPos = aCmd.Search (theKey);
6833 TCollection_AsciiString aPart1, aPart2;
6834 Standard_Integer aPart1To = aPos - 1;
6836 && aPart1To <= theCmd.Length())
6838 aPart1 = theCmd.SubString (1, aPart1To);
6841 Standard_Integer aPart2From = aPos + theKey.Length();
6843 && aPart2From <= theCmd.Length())
6845 aPart2 = theCmd.SubString (aPart2From, theCmd.Length());
6848 theCmd = aPart1 + theVal + aPart2;
6853 Draw_Interpretor* myDrawInter;
6854 TCollection_AsciiString myCommand;
6858 //! Replace the animation with the new one.
6859 static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation,
6860 Handle(AIS_Animation)& theAnimation,
6861 const Handle(AIS_Animation)& theAnimationNew)
6863 theAnimationNew->CopyFrom (theAnimation);
6864 if (!theParentAnimation.IsNull())
6866 theParentAnimation->Replace (theAnimation, theAnimationNew);
6870 ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name());
6871 ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew);
6873 theAnimation = theAnimationNew;
6876 //! Parse the point.
6877 static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
6879 const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
6880 if (!anXYZ[0].IsRealValue()
6881 || !anXYZ[1].IsRealValue()
6882 || !anXYZ[2].IsRealValue())
6884 return Standard_False;
6887 thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue());
6888 return Standard_True;
6891 //! Parse the quaternion.
6892 static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
6894 const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
6895 if (!anXYZW[0].IsRealValue()
6896 || !anXYZW[1].IsRealValue()
6897 || !anXYZW[2].IsRealValue()
6898 || !anXYZW[3].IsRealValue())
6900 return Standard_False;
6903 theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue());
6904 return Standard_True;
6907 //! Auxiliary class for flipping image upside-down.
6912 //! Empty constructor.
6913 ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {}
6915 //! Perform flipping.
6916 Standard_Boolean FlipY (Image_PixMap& theImage)
6918 if (theImage.IsEmpty()
6919 || theImage.SizeX() == 0
6920 || theImage.SizeY() == 0)
6922 return Standard_False;
6925 const Standard_Size aRowSize = theImage.SizeRowBytes();
6926 if (myTmp.Size() < aRowSize
6927 && !myTmp.Allocate (aRowSize))
6929 return Standard_False;
6932 // for odd height middle row should be left as is
6933 Standard_Size aNbRowsHalf = theImage.SizeY() / 2;
6934 for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB)
6936 Standard_Byte* aTop = theImage.ChangeRow (aRowT);
6937 Standard_Byte* aBot = theImage.ChangeRow (aRowB);
6938 memcpy (myTmp.ChangeData(), aTop, aRowSize);
6939 memcpy (aTop, aBot, aRowSize);
6940 memcpy (aBot, myTmp.Data(), aRowSize);
6942 return Standard_True;
6946 NCollection_Buffer myTmp;
6951 //=================================================================================================
6952 //function : VViewParams
6953 //purpose : Gets or sets AIS View characteristics
6954 //=================================================================================================
6955 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6957 Handle(V3d_View) aView = ViewerTest::CurrentView();
6960 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
6964 Standard_Boolean toSetProj = Standard_False;
6965 Standard_Boolean toSetUp = Standard_False;
6966 Standard_Boolean toSetAt = Standard_False;
6967 Standard_Boolean toSetEye = Standard_False;
6968 Standard_Boolean toSetScale = Standard_False;
6969 Standard_Boolean toSetSize = Standard_False;
6970 Standard_Boolean toSetCenter2d = Standard_False;
6971 Standard_Real aViewScale = aView->Scale();
6972 Standard_Real aViewSize = 1.0;
6973 Graphic3d_Vec2i aCenter2d;
6974 gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
6975 aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3));
6976 aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
6977 aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
6978 aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
6981 // print all of the available view parameters
6985 "Proj: %12g %12g %12g\n"
6986 "Up: %12g %12g %12g\n"
6987 "At: %12g %12g %12g\n"
6988 "Eye: %12g %12g %12g\n",
6990 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
6991 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
6992 aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
6993 aViewEye.X(), aViewEye.Y(), aViewEye.Z());
6998 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
6999 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7001 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7003 if (anUpdateTool.parseRedrawMode (anArg))
7007 else if (anArg == "-cmd"
7008 || anArg == "-command"
7009 || anArg == "-args")
7018 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
7019 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
7020 aViewAt.X(), aViewAt.Y(), aViewAt.Z());
7023 else if (anArg == "-scale"
7024 || anArg == "-size")
7026 if (anArgIter + 1 < theArgsNb
7027 && *theArgVec[anArgIter + 1] != '-')
7029 const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
7030 if (aValueArg.IsRealValue())
7033 if (anArg == "-scale")
7035 toSetScale = Standard_True;
7036 aViewScale = aValueArg.RealValue();
7038 else if (anArg == "-size")
7040 toSetSize = Standard_True;
7041 aViewSize = aValueArg.RealValue();
7046 if (anArg == "-scale")
7048 theDi << "Scale: " << aView->Scale() << "\n";
7050 else if (anArg == "-size")
7052 Graphic3d_Vec2d aSizeXY;
7053 aView->Size (aSizeXY.x(), aSizeXY.y());
7054 theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n";
7057 else if (anArg == "-eye"
7060 || anArg == "-proj")
7062 if (anArgIter + 3 < theArgsNb)
7065 if (parseXYZ (theArgVec + anArgIter + 1, anXYZ))
7068 if (anArg == "-eye")
7070 toSetEye = Standard_True;
7073 else if (anArg == "-at")
7075 toSetAt = Standard_True;
7078 else if (anArg == "-up")
7080 toSetUp = Standard_True;
7083 else if (anArg == "-proj")
7085 toSetProj = Standard_True;
7092 if (anArg == "-eye")
7094 theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n";
7096 else if (anArg == "-at")
7098 theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n";
7100 else if (anArg == "-up")
7102 theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n";
7104 else if (anArg == "-proj")
7106 theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n";
7109 else if (anArg == "-center")
7111 if (anArgIter + 2 < theArgsNb)
7113 const TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
7114 const TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
7115 if (anX.IsIntegerValue()
7116 && anY.IsIntegerValue())
7118 toSetCenter2d = Standard_True;
7119 aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue());
7125 std::cout << "Syntax error at '" << anArg << "'\n";
7130 // change view parameters in proper order
7133 aView->SetScale (aViewScale);
7137 aView->SetSize (aViewSize);
7141 aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z());
7145 aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z());
7149 aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z());
7153 aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z());
7157 aView->SetCenter (aCenter2d.x(), aCenter2d.y());
7163 //==============================================================================
7164 //function : V2DMode
7166 //==============================================================================
7167 static Standard_Integer V2DMode (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec)
7169 bool is2dMode = true;
7170 Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView());
7171 if (aV3dView.IsNull())
7173 std::cout << "Error: no active view.\n";
7176 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
7178 const TCollection_AsciiString anArg = theArgVec[anArgIt];
7179 TCollection_AsciiString anArgCase = anArg;
7180 anArgCase.LowerCase();
7181 if (anArgIt + 1 < theArgsNb
7182 && anArgCase == "-name")
7184 ViewerTest_Names aViewNames (theArgVec[++anArgIt]);
7185 TCollection_AsciiString aViewName = aViewNames.GetViewName();
7186 if (!ViewerTest_myViews.IsBound1 (aViewName))
7188 std::cout << "Syntax error: unknown view '" << theArgVec[anArgIt - 1] << "'.\n";
7191 aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest_myViews.Find1 (aViewName));
7193 else if (anArgCase == "-mode")
7195 if (anArgIt + 1 < theArgsNb
7196 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], is2dMode))
7201 else if (ViewerTest::ParseOnOff (theArgVec[anArgIt], is2dMode))
7207 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
7212 aV3dView->SetView2DMode (is2dMode);
7216 //==============================================================================
7217 //function : VAnimation
7219 //==============================================================================
7220 static Standard_Integer VAnimation (Draw_Interpretor& theDI,
7221 Standard_Integer theArgNb,
7222 const char** theArgVec)
7224 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
7227 for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator
7228 anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next())
7230 theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n";
7236 std::cout << "Error: no active view\n";
7240 Standard_Integer anArgIter = 1;
7241 TCollection_AsciiString aNameArg (theArgVec[anArgIter++]);
7242 if (aNameArg.IsEmpty())
7244 std::cout << "Syntax error: animation name is not defined.\n";
7248 TCollection_AsciiString aNameArgLower = aNameArg;
7249 aNameArgLower.LowerCase();
7250 if (aNameArgLower == "-reset"
7251 || aNameArgLower == "-clear")
7253 ViewerTest_AnimationTimelineMap.Clear();
7256 else if (aNameArg.Value (1) == '-')
7258 std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n";
7262 const char* aNameSplitter = "/";
7263 Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter);
7264 if (aSplitPos == -1)
7266 aNameSplitter = ".";
7267 aSplitPos = aNameArg.Search (aNameSplitter);
7270 // find existing or create a new animation by specified name within syntax "parent.child".
7271 Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation;
7272 for (; !aNameArg.IsEmpty();)
7274 TCollection_AsciiString aNameParent;
7275 if (aSplitPos != -1)
7277 if (aSplitPos == aNameArg.Length())
7279 std::cout << "Syntax error: animation name is not defined.\n";
7283 aNameParent = aNameArg.SubString ( 1, aSplitPos - 1);
7284 aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length());
7286 aSplitPos = aNameArg.Search (aNameSplitter);
7290 aNameParent = aNameArg;
7294 if (anAnimation.IsNull())
7296 if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation))
7298 anAnimation = new AIS_Animation (aNameParent);
7299 ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation);
7301 aRootAnimation = anAnimation;
7305 aParentAnimation = anAnimation;
7306 anAnimation = aParentAnimation->Find (aNameParent);
7307 if (anAnimation.IsNull())
7309 anAnimation = new AIS_Animation (aNameParent);
7310 aParentAnimation->Add (anAnimation);
7315 if (anArgIter >= theArgNb)
7317 // just print the list of children
7318 for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next())
7320 theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n";
7325 // animation parameters
7326 Standard_Boolean toPlay = Standard_False;
7327 Standard_Real aPlaySpeed = 1.0;
7328 Standard_Real aPlayStartTime = anAnimation->StartPts();
7329 Standard_Real aPlayDuration = anAnimation->Duration();
7330 Standard_Boolean isFreeCamera = Standard_False;
7331 Standard_Boolean isLockLoop = Standard_False;
7333 // video recording parameters
7334 TCollection_AsciiString aRecFile;
7335 Image_VideoParams aRecParams;
7337 Handle(V3d_View) aView = ViewerTest::CurrentView();
7338 for (; anArgIter < theArgNb; ++anArgIter)
7340 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7343 if (anArg == "-reset"
7344 || anArg == "-clear")
7346 anAnimation->Clear();
7348 else if (anArg == "-remove"
7350 || anArg == "-delete")
7352 if (!aParentAnimation.IsNull())
7354 ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name());
7358 aParentAnimation->Remove (anAnimation);
7362 else if (anArg == "-play")
7364 toPlay = Standard_True;
7365 if (++anArgIter < theArgNb)
7367 if (*theArgVec[anArgIter] == '-')
7372 aPlayStartTime = Draw::Atof (theArgVec[anArgIter]);
7374 if (++anArgIter < theArgNb)
7376 if (*theArgVec[anArgIter] == '-')
7381 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
7385 else if (anArg == "-resume")
7387 toPlay = Standard_True;
7388 aPlayStartTime = anAnimation->ElapsedTime();
7389 if (++anArgIter < theArgNb)
7391 if (*theArgVec[anArgIter] == '-')
7397 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
7400 else if (anArg == "-playspeed"
7401 || anArg == "-speed")
7403 if (++anArgIter >= theArgNb)
7405 std::cout << "Syntax error at " << anArg << ".\n";
7408 aPlaySpeed = Draw::Atof (theArgVec[anArgIter]);
7410 else if (anArg == "-lock"
7411 || anArg == "-lockloop"
7412 || anArg == "-playlockloop")
7414 isLockLoop = Standard_True;
7416 else if (anArg == "-freecamera"
7417 || anArg == "-playfreecamera"
7418 || anArg == "-freelook")
7420 isFreeCamera = Standard_True;
7422 // video recodring options
7423 else if (anArg == "-rec"
7424 || anArg == "-record")
7426 if (++anArgIter >= theArgNb)
7428 std::cout << "Syntax error at " << anArg << ".\n";
7432 aRecFile = theArgVec[anArgIter];
7433 if (aRecParams.FpsNum <= 0)
7435 aRecParams.FpsNum = 24;
7438 if (anArgIter + 2 < theArgNb
7439 && *theArgVec[anArgIter + 1] != '-'
7440 && *theArgVec[anArgIter + 2] != '-')
7442 TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]);
7443 TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]);
7444 if (aWidthArg .IsIntegerValue()
7445 && aHeightArg.IsIntegerValue())
7447 aRecParams.Width = aWidthArg .IntegerValue();
7448 aRecParams.Height = aHeightArg.IntegerValue();
7453 else if (anArg == "-fps")
7455 if (++anArgIter >= theArgNb)
7457 std::cout << "Syntax error at " << anArg << ".\n";
7461 TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
7462 Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
7463 if (aSplitIndex == 0)
7465 aRecParams.FpsNum = aFpsArg.IntegerValue();
7469 const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
7470 aFpsArg.Split (aFpsArg.Length() - 1);
7471 const TCollection_AsciiString aNumStr = aFpsArg;
7472 aRecParams.FpsNum = aNumStr.IntegerValue();
7473 aRecParams.FpsDen = aDenStr.IntegerValue();
7474 if (aRecParams.FpsDen < 1)
7476 std::cout << "Syntax error at " << anArg << ".\n";
7481 else if (anArg == "-format")
7483 if (++anArgIter >= theArgNb)
7485 std::cout << "Syntax error at " << anArg << ".\n";
7488 aRecParams.Format = theArgVec[anArgIter];
7490 else if (anArg == "-pix_fmt"
7491 || anArg == "-pixfmt"
7492 || anArg == "-pixelformat")
7494 if (++anArgIter >= theArgNb)
7496 std::cout << "Syntax error at " << anArg << ".\n";
7499 aRecParams.PixelFormat = theArgVec[anArgIter];
7501 else if (anArg == "-codec"
7502 || anArg == "-vcodec"
7503 || anArg == "-videocodec")
7505 if (++anArgIter >= theArgNb)
7507 std::cout << "Syntax error at " << anArg << ".\n";
7510 aRecParams.VideoCodec = theArgVec[anArgIter];
7512 else if (anArg == "-crf"
7513 || anArg == "-preset"
7516 const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length());
7517 if (++anArgIter >= theArgNb)
7519 std::cout << "Syntax error at " << anArg << ".\n";
7523 aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]);
7525 // animation definition options
7526 else if (anArg == "-start"
7527 || anArg == "-starttime"
7528 || anArg == "-startpts")
7530 if (++anArgIter >= theArgNb)
7532 std::cout << "Syntax error at " << anArg << ".\n";
7536 anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter]));
7537 aRootAnimation->UpdateTotalDuration();
7539 else if (anArg == "-end"
7540 || anArg == "-endtime"
7541 || anArg == "-endpts")
7543 if (++anArgIter >= theArgNb)
7545 std::cout << "Syntax error at " << anArg << ".\n";
7549 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts());
7550 aRootAnimation->UpdateTotalDuration();
7552 else if (anArg == "-dur"
7553 || anArg == "-duration")
7555 if (++anArgIter >= theArgNb)
7557 std::cout << "Syntax error at " << anArg << ".\n";
7561 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]));
7562 aRootAnimation->UpdateTotalDuration();
7564 else if (anArg == "-command"
7566 || anArg == "-invoke"
7568 || anArg == "-proc")
7570 if (++anArgIter >= theArgNb)
7572 std::cout << "Syntax error at " << anArg << ".\n";
7576 Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]);
7577 replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation);
7579 else if (anArg == "-objecttrsf"
7580 || anArg == "-objectransformation"
7581 || anArg == "-objtransformation"
7582 || anArg == "-objtrsf"
7583 || anArg == "-object"
7586 if (++anArgIter >= theArgNb)
7588 std::cout << "Syntax error at " << anArg << ".\n";
7592 TCollection_AsciiString anObjName (theArgVec[anArgIter]);
7593 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS();
7594 Handle(AIS_InteractiveObject) anObject;
7595 if (!aMapOfAIS.Find2 (anObjName, anObject))
7597 std::cout << "Syntax error: wrong object name at " << anArg << "\n";
7601 gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() };
7602 gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() };
7603 gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
7604 Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
7605 Standard_Boolean isTrsfSet = Standard_False;
7606 Standard_Integer aTrsfArgIter = anArgIter + 1;
7607 for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
7609 TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]);
7610 aTrsfArg.LowerCase();
7611 const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1;
7612 if (aTrsfArg.StartsWith ("-rotation")
7613 || aTrsfArg.StartsWith ("-rot"))
7615 isTrsfSet = Standard_True;
7616 if (aTrsfArgIter + 4 >= theArgNb
7617 || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex]))
7619 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7624 else if (aTrsfArg.StartsWith ("-location")
7625 || aTrsfArg.StartsWith ("-loc"))
7627 isTrsfSet = Standard_True;
7628 if (aTrsfArgIter + 3 >= theArgNb
7629 || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex]))
7631 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7636 else if (aTrsfArg.StartsWith ("-scale"))
7638 isTrsfSet = Standard_True;
7639 if (++aTrsfArgIter >= theArgNb)
7641 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7645 const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
7646 if (!aScaleStr.IsRealValue())
7648 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7651 aScales[anIndex] = aScaleStr.RealValue();
7655 anArgIter = aTrsfArgIter - 1;
7661 std::cout << "Syntax error at " << anArg << ".\n";
7664 else if (aTrsfArgIter >= theArgNb)
7666 anArgIter = theArgNb;
7669 aTrsfs[0].SetRotation (aRotQuats[0]);
7670 aTrsfs[1].SetRotation (aRotQuats[1]);
7671 aTrsfs[0].SetTranslationPart (aLocPnts[0]);
7672 aTrsfs[1].SetTranslationPart (aLocPnts[1]);
7673 aTrsfs[0].SetScaleFactor (aScales[0]);
7674 aTrsfs[1].SetScaleFactor (aScales[1]);
7676 Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
7677 replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
7679 else if (anArg == "-viewtrsf"
7680 || anArg == "-view")
7682 Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation);
7683 if (aCamAnimation.IsNull())
7685 aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView);
7686 replaceAnimation (aParentAnimation, anAnimation, aCamAnimation);
7689 Handle(Graphic3d_Camera) aCams[2] =
7691 new Graphic3d_Camera (aCamAnimation->View()->Camera()),
7692 new Graphic3d_Camera (aCamAnimation->View()->Camera())
7695 Standard_Boolean isTrsfSet = Standard_False;
7696 Standard_Integer aViewArgIter = anArgIter + 1;
7697 for (; aViewArgIter < theArgNb; ++aViewArgIter)
7699 TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]);
7700 aViewArg.LowerCase();
7701 const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1;
7702 if (aViewArg.StartsWith ("-scale"))
7704 isTrsfSet = Standard_True;
7705 if (++aViewArgIter >= theArgNb)
7707 std::cout << "Syntax error at " << anArg << ".\n";
7711 const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
7712 if (!aScaleStr.IsRealValue())
7714 std::cout << "Syntax error at " << aViewArg << ".\n";
7717 Standard_Real aScale = aScaleStr.RealValue();
7718 aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale;
7719 aCams[anIndex]->SetScale (aScale);
7721 else if (aViewArg.StartsWith ("-eye")
7722 || aViewArg.StartsWith ("-center")
7723 || aViewArg.StartsWith ("-at")
7724 || aViewArg.StartsWith ("-up"))
7726 isTrsfSet = Standard_True;
7728 if (aViewArgIter + 3 >= theArgNb
7729 || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ))
7731 std::cout << "Syntax error at " << aViewArg << ".\n";
7736 if (aViewArg.StartsWith ("-eye"))
7738 aCams[anIndex]->SetEye (anXYZ);
7740 else if (aViewArg.StartsWith ("-center")
7741 || aViewArg.StartsWith ("-at"))
7743 aCams[anIndex]->SetCenter (anXYZ);
7745 else if (aViewArg.StartsWith ("-up"))
7747 aCams[anIndex]->SetUp (anXYZ);
7752 anArgIter = aViewArgIter - 1;
7758 std::cout << "Syntax error at " << anArg << ".\n";
7761 else if (aViewArgIter >= theArgNb)
7763 anArgIter = theArgNb;
7766 aCamAnimation->SetCameraStart(aCams[0]);
7767 aCamAnimation->SetCameraEnd (aCams[1]);
7771 std::cout << "Syntax error at " << anArg << ".\n";
7776 if (!toPlay && aRecFile.IsEmpty())
7781 // Start animation timeline and process frame updating.
7782 TheIsAnimating = Standard_True;
7783 const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
7784 Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera());
7785 anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
7788 aView->Camera()->Copy (aCameraBack);
7791 const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
7792 if (aRecParams.FpsNum <= 0)
7794 while (!anAnimation->IsStopped())
7796 aCameraBack->Copy (aView->Camera());
7797 const Standard_Real aPts = anAnimation->UpdateTimer();
7800 aView->Camera()->Copy (aCameraBack);
7803 if (aPts >= anUpperPts)
7805 anAnimation->Pause();
7809 if (aView->IsInvalidated())
7815 aView->RedrawImmediate();
7820 // handle user events
7821 theDI.Eval ("after 1 set waiter 1");
7822 theDI.Eval ("vwait waiter");
7824 if (!TheIsAnimating)
7826 anAnimation->Pause();
7832 if (aView->IsInvalidated())
7838 aView->RedrawImmediate();
7843 OSD_Timer aPerfTimer;
7846 Handle(Image_VideoRecorder) aRecorder;
7847 ImageFlipper aFlipper;
7848 Handle(Draw_ProgressIndicator) aProgress;
7849 if (!aRecFile.IsEmpty())
7851 if (aRecParams.Width <= 0
7852 || aRecParams.Height <= 0)
7854 aView->Window()->Size (aRecParams.Width, aRecParams.Height);
7857 aRecorder = new Image_VideoRecorder();
7858 if (!aRecorder->Open (aRecFile.ToCString(), aRecParams))
7860 std::cout << "Error: failed to open video file for recording\n";
7864 aProgress = new Draw_ProgressIndicator (theDI, 1);
7867 // Manage frame-rated animation here
7868 Standard_Real aPts = aPlayStartTime;
7869 int64_t aNbFrames = 0;
7870 Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1);
7871 Standard_Integer aSecondsProgress = 0;
7872 for (; aPts <= anUpperPts && aPSentry.More();)
7874 const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames));
7875 aPts = aPlayStartTime + aRecPts;
7877 if (!anAnimation->Update (aPts))
7882 if (!aRecorder.IsNull())
7884 V3d_ImageDumpOptions aDumpParams;
7885 aDumpParams.Width = aRecParams.Width;
7886 aDumpParams.Height = aRecParams.Height;
7887 aDumpParams.BufferType = Graphic3d_BT_RGBA;
7888 aDumpParams.StereoOptions = V3d_SDO_MONO;
7889 aDumpParams.ToAdjustAspect = Standard_True;
7890 if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams))
7892 std::cout << "Error: view dump is failed!\n";
7895 aFlipper.FlipY (aRecorder->ChangeFrame());
7896 if (!aRecorder->PushFrame())
7906 while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed))
7914 anAnimation->Stop();
7915 const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
7916 theDI << "Average FPS: " << aRecFps << "\n"
7917 << "Nb. Frames: " << Standard_Real(aNbFrames);
7922 aView->SetImmediateUpdate (wasImmediateUpdate);
7923 TheIsAnimating = Standard_False;
7928 //=======================================================================
7929 //function : VChangeSelected
7930 //purpose : Adds the shape to selection or remove one from it
7931 //=======================================================================
7932 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
7933 Standard_Integer argc,
7938 di<<"Usage : " << argv[0] << " shape \n";
7942 TCollection_AsciiString aName(argv[1]);
7943 Handle(AIS_InteractiveObject) anAISObject;
7944 if (!GetMapOfAIS().Find2 (aName, anAISObject)
7945 || anAISObject.IsNull())
7947 di<<"Use 'vdisplay' before";
7951 ViewerTest::GetAISContext()->AddOrRemoveSelected(anAISObject, Standard_True);
7955 //=======================================================================
7956 //function : VNbSelected
7957 //purpose : Returns number of selected objects
7958 //=======================================================================
7959 static Standard_Integer VNbSelected (Draw_Interpretor& di,
7960 Standard_Integer argc,
7965 di << "Usage : " << argv[0] << "\n";
7968 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7969 if(aContext.IsNull())
7971 di << "use 'vinit' command before " << argv[0] << "\n";
7974 di << aContext->NbSelected() << "\n";
7978 //=======================================================================
7979 //function : VPurgeDisplay
7980 //purpose : Switches altialiasing on or off
7981 //=======================================================================
7982 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
7983 Standard_Integer argc,
7988 di << "Usage : " << argv[0] << "\n";
7991 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7992 if (aContext.IsNull())
7994 di << "use 'vinit' command before " << argv[0] << "\n";
7998 di << aContext->PurgeDisplay() << "\n";
8002 //=======================================================================
8003 //function : VSetViewSize
8005 //=======================================================================
8006 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
8007 Standard_Integer argc,
8010 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8011 if(aContext.IsNull())
8013 di << "use 'vinit' command before " << argv[0] << "\n";
8018 di<<"Usage : " << argv[0] << " Size\n";
8021 Standard_Real aSize = Draw::Atof (argv[1]);
8024 di<<"Bad Size value : " << aSize << "\n";
8028 Handle(V3d_View) aView = ViewerTest::CurrentView();
8029 aView->SetSize(aSize);
8033 //=======================================================================
8034 //function : VMoveView
8036 //=======================================================================
8037 static Standard_Integer VMoveView (Draw_Interpretor& di,
8038 Standard_Integer argc,
8041 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8042 if(aContext.IsNull())
8044 di << "use 'vinit' command before " << argv[0] << "\n";
8047 if(argc < 4 || argc > 5)
8049 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
8052 Standard_Real Dx = Draw::Atof (argv[1]);
8053 Standard_Real Dy = Draw::Atof (argv[2]);
8054 Standard_Real Dz = Draw::Atof (argv[3]);
8055 Standard_Boolean aStart = Standard_True;
8058 aStart = (Draw::Atoi (argv[4]) > 0);
8061 Handle(V3d_View) aView = ViewerTest::CurrentView();
8062 aView->Move(Dx,Dy,Dz,aStart);
8066 //=======================================================================
8067 //function : VTranslateView
8069 //=======================================================================
8070 static Standard_Integer VTranslateView (Draw_Interpretor& di,
8071 Standard_Integer argc,
8074 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8075 if(aContext.IsNull())
8077 di << "use 'vinit' command before " << argv[0] << "\n";
8080 if(argc < 4 || argc > 5)
8082 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
8085 Standard_Real Dx = Draw::Atof (argv[1]);
8086 Standard_Real Dy = Draw::Atof (argv[2]);
8087 Standard_Real Dz = Draw::Atof (argv[3]);
8088 Standard_Boolean aStart = Standard_True;
8091 aStart = (Draw::Atoi (argv[4]) > 0);
8094 Handle(V3d_View) aView = ViewerTest::CurrentView();
8095 aView->Translate(Dx,Dy,Dz,aStart);
8099 //=======================================================================
8100 //function : VTurnView
8102 //=======================================================================
8103 static Standard_Integer VTurnView (Draw_Interpretor& di,
8104 Standard_Integer argc,
8107 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8108 if(aContext.IsNull()) {
8109 di << "use 'vinit' command before " << argv[0] << "\n";
8112 if(argc < 4 || argc > 5){
8113 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
8116 Standard_Real Ax = Draw::Atof (argv[1]);
8117 Standard_Real Ay = Draw::Atof (argv[2]);
8118 Standard_Real Az = Draw::Atof (argv[3]);
8119 Standard_Boolean aStart = Standard_True;
8122 aStart = (Draw::Atoi (argv[4]) > 0);
8125 Handle(V3d_View) aView = ViewerTest::CurrentView();
8126 aView->Turn(Ax,Ay,Az,aStart);
8130 //==============================================================================
8131 //function : VTextureEnv
8132 //purpose : ENables or disables environment mapping
8133 //==============================================================================
8134 class OCC_TextureEnv : public Graphic3d_TextureEnv
8137 OCC_TextureEnv(const Standard_CString FileName);
8138 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
8139 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
8140 const Standard_Boolean theModulateFlag,
8141 const Graphic3d_TypeOfTextureFilter theFilter,
8142 const Standard_ShortReal theXScale,
8143 const Standard_ShortReal theYScale,
8144 const Standard_ShortReal theXShift,
8145 const Standard_ShortReal theYShift,
8146 const Standard_ShortReal theAngle);
8147 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
8149 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
8151 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
8152 : Graphic3d_TextureEnv(theFileName)
8156 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
8157 : Graphic3d_TextureEnv(theTexId)
8161 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
8162 const Standard_Boolean theModulateFlag,
8163 const Graphic3d_TypeOfTextureFilter theFilter,
8164 const Standard_ShortReal theXScale,
8165 const Standard_ShortReal theYScale,
8166 const Standard_ShortReal theXShift,
8167 const Standard_ShortReal theYShift,
8168 const Standard_ShortReal theAngle)
8170 myParams->SetRepeat (theRepeatFlag);
8171 myParams->SetModulate (theModulateFlag);
8172 myParams->SetFilter (theFilter);
8173 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
8174 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
8175 myParams->SetRotation (theAngle);
8178 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
8180 // get the active view
8181 Handle(V3d_View) aView = ViewerTest::CurrentView();
8184 std::cerr << "No active view. Please call vinit.\n";
8188 // Checking the input arguments
8189 Standard_Boolean anEnableFlag = Standard_False;
8190 Standard_Boolean isOk = theArgNb >= 2;
8193 TCollection_AsciiString anEnableOpt(theArgVec[1]);
8194 anEnableFlag = anEnableOpt.IsEqual("on");
8195 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
8199 isOk = (theArgNb == 3 || theArgNb == 11);
8202 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8203 isOk = (!aTextureOpt.IsIntegerValue() ||
8204 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
8206 if (isOk && theArgNb == 11)
8208 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
8209 aModulateOpt(theArgVec[4]),
8210 aFilterOpt (theArgVec[5]),
8211 aSScaleOpt (theArgVec[6]),
8212 aTScaleOpt (theArgVec[7]),
8213 aSTransOpt (theArgVec[8]),
8214 aTTransOpt (theArgVec[9]),
8215 anAngleOpt (theArgVec[10]);
8216 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
8217 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
8218 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
8219 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
8220 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
8221 anAngleOpt.IsRealValue());
8228 std::cerr << "Usage :" << std::endl;
8229 std::cerr << theArgVec[0] << " off" << std::endl;
8230 std::cerr << theArgVec[0] << " on {index_of_std_texture(0..7)|texture_file_name} [{clamp|repeat} {decal|modulate} {nearest|bilinear|trilinear} scale_s scale_t translation_s translation_t rotation_degrees]" << std::endl;
8236 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8237 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
8238 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
8239 new OCC_TextureEnv(theArgVec[2]);
8243 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
8244 aTexEnv->SetTextureParameters(
8245 aRepeatOpt. IsEqual("repeat"),
8246 aModulateOpt.IsEqual("modulate"),
8247 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
8248 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
8249 Graphic3d_TOTF_TRILINEAR,
8250 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
8251 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
8252 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
8253 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
8254 (Standard_ShortReal)Draw::Atof(theArgVec[10])
8257 aView->SetTextureEnv(aTexEnv);
8259 else // Disabling environment mapping
8261 Handle(Graphic3d_TextureEnv) aTexture;
8262 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
8271 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
8273 //! Remove registered clipping plane from all views and objects.
8274 static void removePlane (MapOfPlanes& theRegPlanes,
8275 const TCollection_AsciiString& theName)
8277 Handle(Graphic3d_ClipPlane) aClipPlane;
8278 if (!theRegPlanes.Find (theName, aClipPlane))
8280 std::cout << "Warning: no such plane.\n";
8284 theRegPlanes.UnBind (theName);
8285 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
8286 anIObjIt.More(); anIObjIt.Next())
8288 const Handle(AIS_InteractiveObject)& aPrs = anIObjIt.Key1();
8289 aPrs->RemoveClipPlane (aClipPlane);
8292 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
8293 aViewIt.More(); aViewIt.Next())
8295 const Handle(V3d_View)& aView = aViewIt.Key2();
8296 aView->RemoveClipPlane(aClipPlane);
8299 ViewerTest::RedrawAllViews();
8303 //===============================================================================================
8304 //function : VClipPlane
8306 //===============================================================================================
8307 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8309 // use short-cut for created clip planes map of created (or "registered by name") clip planes
8310 static MapOfPlanes aRegPlanes;
8314 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
8316 theDi << aPlaneIter.Key() << " ";
8321 TCollection_AsciiString aCommand (theArgVec[1]);
8322 aCommand.LowerCase();
8323 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
8324 if (anActiveView.IsNull())
8326 std::cout << "Error: no active view.\n";
8330 // print maximum number of planes for current viewer
8331 if (aCommand == "-maxplanes"
8332 || aCommand == "maxplanes")
8334 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
8335 << " plane slots provided by driver.\n";
8339 // create / delete plane instance
8340 if (aCommand == "-create"
8341 || aCommand == "create"
8342 || aCommand == "-delete"
8343 || aCommand == "delete"
8344 || aCommand == "-clone"
8345 || aCommand == "clone")
8349 std::cout << "Syntax error: plane name is required.\n";
8353 Standard_Boolean toCreate = aCommand == "-create"
8354 || aCommand == "create";
8355 Standard_Boolean toClone = aCommand == "-clone"
8356 || aCommand == "clone";
8357 Standard_Boolean toDelete = aCommand == "-delete"
8358 || aCommand == "delete";
8359 TCollection_AsciiString aPlane (theArgVec[2]);
8363 if (aRegPlanes.IsBound (aPlane))
8365 std::cout << "Warning: existing plane has been overridden.\n";
8370 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8374 else if (toClone) // toClone
8376 if (!aRegPlanes.IsBound (aPlane))
8378 std::cout << "Error: no such plane.\n";
8381 else if (theArgsNb < 4)
8383 std::cout << "Syntax error: enter name for new plane.\n";
8387 TCollection_AsciiString aClone (theArgVec[3]);
8388 if (aRegPlanes.IsBound (aClone))
8390 std::cout << "Error: plane name is in use.\n";
8394 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
8396 aRegPlanes.Bind (aClone, aClipPlane->Clone());
8406 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
8408 aPlane = aPlaneIter.Key();
8409 removePlane (aRegPlanes, aPlane);
8410 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
8415 removePlane (aRegPlanes, aPlane);
8421 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8426 // set / unset plane command
8427 if (aCommand == "set"
8428 || aCommand == "unset")
8432 std::cout << "Syntax error: need more arguments.\n";
8436 // redirect to new syntax
8437 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
8438 anArgVec.SetValue (1, theArgVec[0]);
8439 anArgVec.SetValue (2, theArgVec[2]);
8440 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
8441 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
8443 anArgVec.SetValue (anIt, theArgVec[anIt]);
8446 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
8449 // change plane command
8450 TCollection_AsciiString aPlaneName;
8451 Handle(Graphic3d_ClipPlane) aClipPlane;
8452 Standard_Integer anArgIter = 0;
8453 if (aCommand == "-change"
8454 || aCommand == "change")
8456 // old syntax support
8459 std::cout << "Syntax error: need more arguments.\n";
8464 aPlaneName = theArgVec[2];
8465 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
8467 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
8471 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
8474 aPlaneName = theArgVec[1];
8479 aPlaneName = theArgVec[1];
8480 aClipPlane = new Graphic3d_ClipPlane();
8481 aRegPlanes.Bind (aPlaneName, aClipPlane);
8482 theDi << "Created new plane " << aPlaneName << ".\n";
8485 if (theArgsNb - anArgIter < 1)
8487 std::cout << "Syntax error: need more arguments.\n";
8491 for (; anArgIter < theArgsNb; ++anArgIter)
8493 const char** aChangeArgs = theArgVec + anArgIter;
8494 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
8495 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
8496 aChangeArg.LowerCase();
8498 Standard_Boolean toEnable = Standard_True;
8499 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
8501 aClipPlane->SetOn (toEnable);
8503 else if (aChangeArg.StartsWith ("-equation")
8504 || aChangeArg.StartsWith ("equation"))
8506 if (aNbChangeArgs < 5)
8508 std::cout << "Syntax error: need more arguments.\n";
8512 Standard_Integer aSubIndex = 1;
8513 Standard_Integer aPrefixLen = 8 + (aChangeArg.Value (1) == '-' ? 1 : 0);
8514 if (aPrefixLen < aChangeArg.Length())
8516 TCollection_AsciiString aSubStr = aChangeArg.SubString (aPrefixLen + 1, aChangeArg.Length());
8517 if (!aSubStr.IsIntegerValue()
8518 || aSubStr.IntegerValue() <= 0)
8520 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
8523 aSubIndex = aSubStr.IntegerValue();
8526 Standard_Real aCoeffA = Draw::Atof (aChangeArgs[1]);
8527 Standard_Real aCoeffB = Draw::Atof (aChangeArgs[2]);
8528 Standard_Real aCoeffC = Draw::Atof (aChangeArgs[3]);
8529 Standard_Real aCoeffD = Draw::Atof (aChangeArgs[4]);
8530 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
8531 for (Standard_Integer aSubPlaneIter = 1; aSubPlaneIter < aSubIndex; ++aSubPlaneIter)
8533 if (aSubPln->ChainNextPlane().IsNull())
8535 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
8537 aSubPln = aSubPln->ChainNextPlane();
8539 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
8540 aSubPln->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
8543 else if ((aChangeArg == "-boxinterior"
8544 || aChangeArg == "-boxint"
8545 || aChangeArg == "-box")
8546 && aNbChangeArgs >= 7)
8548 Graphic3d_BndBox3d aBndBox;
8549 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[1]), Draw::Atof (aChangeArgs[2]), Draw::Atof (aChangeArgs[3])));
8550 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[4]), Draw::Atof (aChangeArgs[5]), Draw::Atof (aChangeArgs[6])));
8553 Standard_Integer aNbSubPlanes = 6;
8554 const Graphic3d_Vec3d aDirArray[6] =
8556 Graphic3d_Vec3d (-1, 0, 0),
8557 Graphic3d_Vec3d ( 1, 0, 0),
8558 Graphic3d_Vec3d ( 0,-1, 0),
8559 Graphic3d_Vec3d ( 0, 1, 0),
8560 Graphic3d_Vec3d ( 0, 0,-1),
8561 Graphic3d_Vec3d ( 0, 0, 1),
8563 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
8564 for (Standard_Integer aSubPlaneIter = 0; aSubPlaneIter < aNbSubPlanes; ++aSubPlaneIter)
8566 const Graphic3d_Vec3d& aDir = aDirArray[aSubPlaneIter];
8567 const Standard_Real aW = -aDir.Dot ((aSubPlaneIter % 2 == 1) ? aBndBox.CornerMax() : aBndBox.CornerMin());
8568 aSubPln->SetEquation (gp_Pln (aDir.x(), aDir.y(), aDir.z(), aW));
8569 if (aSubPlaneIter + 1 == aNbSubPlanes)
8571 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
8575 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
8577 aSubPln = aSubPln->ChainNextPlane();
8580 else if (aChangeArg == "-capping"
8581 || aChangeArg == "capping")
8583 if (aNbChangeArgs < 2)
8585 std::cout << "Syntax error: need more arguments.\n";
8589 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8591 aClipPlane->SetCapping (toEnable);
8596 // just skip otherwise (old syntax)
8599 else if (aChangeArg == "-useobjectmaterial"
8600 || aChangeArg == "-useobjectmat"
8601 || aChangeArg == "-useobjmat"
8602 || aChangeArg == "-useobjmaterial")
8604 if (aNbChangeArgs < 2)
8606 std::cout << "Syntax error: need more arguments.\n";
8610 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8612 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
8616 else if (aChangeArg == "-useobjecttexture"
8617 || aChangeArg == "-useobjecttex"
8618 || aChangeArg == "-useobjtexture"
8619 || aChangeArg == "-useobjtex")
8621 if (aNbChangeArgs < 2)
8623 std::cout << "Syntax error: need more arguments.\n";
8627 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8629 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
8633 else if (aChangeArg == "-useobjectshader"
8634 || aChangeArg == "-useobjshader")
8636 if (aNbChangeArgs < 2)
8638 std::cout << "Syntax error: need more arguments.\n";
8642 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8644 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
8648 else if (aChangeArg == "-color"
8649 || aChangeArg == "color")
8651 Quantity_Color aColor;
8652 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
8657 std::cout << "Syntax error: need more arguments.\n";
8661 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
8662 aMat.SetAmbientColor (aColor);
8663 aMat.SetDiffuseColor (aColor);
8664 aClipPlane->SetCappingMaterial (aMat);
8665 anArgIter += aNbParsed;
8667 else if ((aChangeArg == "-transparency"
8668 || aChangeArg == "-transp")
8669 && aNbChangeArgs >= 2)
8671 TCollection_AsciiString aValStr (aChangeArgs[1]);
8672 Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect();
8673 if (aValStr.IsRealValue())
8675 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
8676 aMat.SetTransparency ((float )aValStr.RealValue());
8677 anAspect->SetAlphaMode (Graphic3d_AlphaMode_BlendAuto);
8678 aClipPlane->SetCappingMaterial (aMat);
8682 aValStr.LowerCase();
8683 Graphic3d_AlphaMode aMode = Graphic3d_AlphaMode_BlendAuto;
8684 if (aValStr == "opaque")
8686 aMode = Graphic3d_AlphaMode_Opaque;
8688 else if (aValStr == "mask")
8690 aMode = Graphic3d_AlphaMode_Mask;
8692 else if (aValStr == "blend")
8694 aMode = Graphic3d_AlphaMode_Blend;
8696 else if (aValStr == "blendauto")
8698 aMode = Graphic3d_AlphaMode_BlendAuto;
8702 std::cout << "Syntax error at '" << aValStr << "'\n";
8705 anAspect->SetAlphaMode (aMode);
8706 aClipPlane->SetCappingAspect (anAspect);
8710 else if (aChangeArg == "-texname"
8711 || aChangeArg == "texname")
8713 if (aNbChangeArgs < 2)
8715 std::cout << "Syntax error: need more arguments.\n";
8719 TCollection_AsciiString aTextureName (aChangeArgs[1]);
8720 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
8721 if (!aTexture->IsDone())
8723 aClipPlane->SetCappingTexture (NULL);
8727 aTexture->EnableModulate();
8728 aTexture->EnableRepeat();
8729 aClipPlane->SetCappingTexture (aTexture);
8733 else if (aChangeArg == "-texscale"
8734 || aChangeArg == "texscale")
8736 if (aClipPlane->CappingTexture().IsNull())
8738 std::cout << "Error: no texture is set.\n";
8742 if (aNbChangeArgs < 3)
8744 std::cout << "Syntax error: need more arguments.\n";
8748 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8749 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8750 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
8753 else if (aChangeArg == "-texorigin"
8754 || aChangeArg == "texorigin") // texture origin
8756 if (aClipPlane->CappingTexture().IsNull())
8758 std::cout << "Error: no texture is set.\n";
8762 if (aNbChangeArgs < 3)
8764 std::cout << "Syntax error: need more arguments.\n";
8768 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8769 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8771 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
8774 else if (aChangeArg == "-texrotate"
8775 || aChangeArg == "texrotate") // texture rotation
8777 if (aClipPlane->CappingTexture().IsNull())
8779 std::cout << "Error: no texture is set.\n";
8783 if (aNbChangeArgs < 2)
8785 std::cout << "Syntax error: need more arguments.\n";
8789 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8790 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
8793 else if (aChangeArg == "-hatch"
8794 || aChangeArg == "hatch")
8796 if (aNbChangeArgs < 2)
8798 std::cout << "Syntax error: need more arguments.\n";
8802 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
8803 aHatchStr.LowerCase();
8804 if (aHatchStr == "on")
8806 aClipPlane->SetCappingHatchOn();
8808 else if (aHatchStr == "off")
8810 aClipPlane->SetCappingHatchOff();
8814 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
8818 else if (aChangeArg == "-delete"
8819 || aChangeArg == "delete")
8821 removePlane (aRegPlanes, aPlaneName);
8824 else if (aChangeArg == "-set"
8825 || aChangeArg == "-unset"
8826 || aChangeArg == "-setoverrideglobal")
8828 // set / unset plane command
8829 const Standard_Boolean toSet = aChangeArg.StartsWith ("-set");
8830 const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal";
8831 Standard_Integer anIt = 1;
8832 for (; anIt < aNbChangeArgs; ++anIt)
8834 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
8835 if (anEntityName.IsEmpty()
8836 || anEntityName.Value (1) == '-')
8840 else if (!toOverrideGlobal
8841 && ViewerTest_myViews.IsBound1 (anEntityName))
8843 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
8846 aView->AddClipPlane (aClipPlane);
8850 aView->RemoveClipPlane (aClipPlane);
8854 else if (GetMapOfAIS().IsBound2 (anEntityName))
8856 Handle(AIS_InteractiveObject) aIObj = GetMapOfAIS().Find2 (anEntityName);
8859 aIObj->AddClipPlane (aClipPlane);
8863 aIObj->RemoveClipPlane (aClipPlane);
8865 if (!aIObj->ClipPlanes().IsNull())
8867 aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal);
8872 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
8879 // apply to active view
8882 anActiveView->AddClipPlane (aClipPlane);
8886 anActiveView->RemoveClipPlane (aClipPlane);
8891 anArgIter = anArgIter + anIt - 1;
8896 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
8901 ViewerTest::RedrawAllViews();
8905 //===============================================================================================
8906 //function : VZRange
8908 //===============================================================================================
8909 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8911 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
8913 if (aCurrentView.IsNull())
8915 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
8919 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
8923 theDi << "ZNear: " << aCamera->ZNear() << "\n";
8924 theDi << "ZFar: " << aCamera->ZFar() << "\n";
8930 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
8931 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
8933 if (aNewZNear >= aNewZFar)
8935 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
8939 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
8941 std::cout << theArgVec[0] << ": invalid arguments: ";
8942 std::cout << "znear, zfar should be positive for perspective camera.\n";
8946 aCamera->SetZRange (aNewZNear, aNewZFar);
8950 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
8954 aCurrentView->Redraw();
8959 //===============================================================================================
8960 //function : VAutoZFit
8962 //===============================================================================================
8963 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8965 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
8967 if (aCurrentView.IsNull())
8969 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
8973 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
8977 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
8983 theDi << "Auto z-fit mode: \n"
8984 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
8985 << "Scale: " << aScale << "\n";
8989 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
8993 aScale = Draw::Atoi (theArgVec[2]);
8996 aCurrentView->SetAutoZFitMode (isOn, aScale);
8997 aCurrentView->AutoZFit();
8998 aCurrentView->Redraw();
9003 //! Auxiliary function to print projection type
9004 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
9006 switch (theProjType)
9008 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
9009 case Graphic3d_Camera::Projection_Perspective: return "perspective";
9010 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
9011 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
9012 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
9017 //===============================================================================================
9018 //function : VCamera
9020 //===============================================================================================
9021 static int VCamera (Draw_Interpretor& theDI,
9022 Standard_Integer theArgsNb,
9023 const char** theArgVec)
9025 Handle(V3d_View) aView = ViewerTest::CurrentView();
9028 std::cout << "Error: no active view.\n";
9032 Handle(Graphic3d_Camera) aCamera = aView->Camera();
9035 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
9036 theDI << "FOVy: " << aCamera->FOVy() << "\n";
9037 theDI << "Distance: " << aCamera->Distance() << "\n";
9038 theDI << "IOD: " << aCamera->IOD() << "\n";
9039 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
9040 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
9041 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
9045 TCollection_AsciiString aPrsName;
9046 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
9048 Standard_CString anArg = theArgVec[anArgIter];
9049 TCollection_AsciiString anArgCase (anArg);
9050 anArgCase.LowerCase();
9051 if (anArgCase == "-proj"
9052 || anArgCase == "-projection"
9053 || anArgCase == "-projtype"
9054 || anArgCase == "-projectiontype")
9056 theDI << projTypeName (aCamera->ProjectionType()) << " ";
9058 else if (anArgCase == "-ortho"
9059 || anArgCase == "-orthographic")
9061 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
9063 else if (anArgCase == "-persp"
9064 || anArgCase == "-perspective"
9065 || anArgCase == "-perspmono"
9066 || anArgCase == "-perspectivemono"
9067 || anArgCase == "-mono")
9069 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
9071 else if (anArgCase == "-stereo"
9072 || anArgCase == "-stereoscopic"
9073 || anArgCase == "-perspstereo"
9074 || anArgCase == "-perspectivestereo")
9076 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9078 else if (anArgCase == "-left"
9079 || anArgCase == "-lefteye"
9080 || anArgCase == "-monoleft"
9081 || anArgCase == "-monolefteye"
9082 || anArgCase == "-perpsleft"
9083 || anArgCase == "-perpslefteye")
9085 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
9087 else if (anArgCase == "-right"
9088 || anArgCase == "-righteye"
9089 || anArgCase == "-monoright"
9090 || anArgCase == "-monorighteye"
9091 || anArgCase == "-perpsright")
9093 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
9095 else if (anArgCase == "-dist"
9096 || anArgCase == "-distance")
9098 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9099 if (anArgValue != NULL
9100 && *anArgValue != '-')
9103 aCamera->SetDistance (Draw::Atof (anArgValue));
9106 theDI << aCamera->Distance() << " ";
9108 else if (anArgCase == "-iod")
9110 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9111 if (anArgValue != NULL
9112 && *anArgValue != '-')
9115 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
9118 theDI << aCamera->IOD() << " ";
9120 else if (anArgCase == "-iodtype")
9122 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
9123 TCollection_AsciiString anValueCase (anArgValue);
9124 anValueCase.LowerCase();
9125 if (anValueCase == "abs"
9126 || anValueCase == "absolute")
9129 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
9132 else if (anValueCase == "rel"
9133 || anValueCase == "relative")
9136 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
9139 else if (*anArgValue != '-')
9141 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
9144 switch (aCamera->GetIODType())
9146 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
9147 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
9150 else if (anArgCase == "-zfocus")
9152 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9153 if (anArgValue != NULL
9154 && *anArgValue != '-')
9157 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
9160 theDI << aCamera->ZFocus() << " ";
9162 else if (anArgCase == "-zfocustype")
9164 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
9165 TCollection_AsciiString anValueCase (anArgValue);
9166 anValueCase.LowerCase();
9167 if (anValueCase == "abs"
9168 || anValueCase == "absolute")
9171 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
9174 else if (anValueCase == "rel"
9175 || anValueCase == "relative")
9178 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
9181 else if (*anArgValue != '-')
9183 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
9186 switch (aCamera->ZFocusType())
9188 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
9189 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
9192 else if (anArgCase == "-fov"
9193 || anArgCase == "-fovy")
9195 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9196 if (anArgValue != NULL
9197 && *anArgValue != '-')
9200 aCamera->SetFOVy (Draw::Atof (anArgValue));
9203 theDI << aCamera->FOVy() << " ";
9205 else if (aPrsName.IsEmpty()
9206 && !anArgCase.StartsWith ("-"))
9212 std::cout << "Error: unknown argument '" << anArg << "'\n";
9217 if (aPrsName.IsEmpty()
9224 if (!aPrsName.IsEmpty())
9226 Handle(AIS_CameraFrustum) aCameraFrustum;
9227 if (GetMapOfAIS().IsBound2 (aPrsName))
9229 // find existing object
9230 aCameraFrustum = Handle(AIS_CameraFrustum)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
9231 if (aCameraFrustum.IsNull())
9233 std::cout << "Error: object '" << aPrsName << "'is already defined and is not a camera frustum!\n";
9238 if (aCameraFrustum.IsNull())
9240 aCameraFrustum = new AIS_CameraFrustum();
9244 // not include displayed object of old camera frustum in the new one.
9245 ViewerTest::GetAISContext()->Erase (aCameraFrustum, false);
9248 aCameraFrustum->SetCameraFrustum (aView->Camera());
9250 ViewerTest::Display (aPrsName, aCameraFrustum);
9256 //! Parse stereo output mode
9257 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
9258 Graphic3d_StereoMode& theMode)
9260 TCollection_AsciiString aFlag (theArg);
9262 if (aFlag == "quadbuffer")
9264 theMode = Graphic3d_StereoMode_QuadBuffer;
9266 else if (aFlag == "anaglyph")
9268 theMode = Graphic3d_StereoMode_Anaglyph;
9270 else if (aFlag == "row"
9271 || aFlag == "rowinterlaced")
9273 theMode = Graphic3d_StereoMode_RowInterlaced;
9275 else if (aFlag == "col"
9276 || aFlag == "colinterlaced"
9277 || aFlag == "columninterlaced")
9279 theMode = Graphic3d_StereoMode_ColumnInterlaced;
9281 else if (aFlag == "chess"
9282 || aFlag == "chessboard")
9284 theMode = Graphic3d_StereoMode_ChessBoard;
9286 else if (aFlag == "sbs"
9287 || aFlag == "sidebyside")
9289 theMode = Graphic3d_StereoMode_SideBySide;
9291 else if (aFlag == "ou"
9292 || aFlag == "overunder")
9294 theMode = Graphic3d_StereoMode_OverUnder;
9296 else if (aFlag == "pageflip"
9297 || aFlag == "softpageflip")
9299 theMode = Graphic3d_StereoMode_SoftPageFlip;
9303 return Standard_False;
9305 return Standard_True;
9308 //! Parse anaglyph filter
9309 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
9310 Graphic3d_RenderingParams::Anaglyph& theFilter)
9312 TCollection_AsciiString aFlag (theArg);
9314 if (aFlag == "redcyansimple")
9316 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9318 else if (aFlag == "redcyan"
9319 || aFlag == "redcyanoptimized")
9321 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
9323 else if (aFlag == "yellowbluesimple")
9325 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
9327 else if (aFlag == "yellowblue"
9328 || aFlag == "yellowblueoptimized")
9330 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
9332 else if (aFlag == "greenmagenta"
9333 || aFlag == "greenmagentasimple")
9335 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
9339 return Standard_False;
9341 return Standard_True;
9344 //==============================================================================
9345 //function : VStereo
9347 //==============================================================================
9349 static int VStereo (Draw_Interpretor& theDI,
9350 Standard_Integer theArgNb,
9351 const char** theArgVec)
9353 Handle(V3d_View) aView = ViewerTest::CurrentView();
9358 std::cout << "Error: no active viewer!\n";
9362 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
9363 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
9366 TCollection_AsciiString aMode;
9367 switch (aView->RenderingParams().StereoMode)
9369 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
9370 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
9371 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
9372 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
9373 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
9374 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
9375 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
9376 case Graphic3d_StereoMode_Anaglyph :
9378 switch (aView->RenderingParams().AnaglyphFilter)
9380 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
9381 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
9382 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
9383 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
9384 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
9389 theDI << "Mode " << aMode << "\n";
9394 Handle(Graphic3d_Camera) aCamera;
9395 Graphic3d_RenderingParams* aParams = NULL;
9396 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
9397 if (!aView.IsNull())
9399 aParams = &aView->ChangeRenderingParams();
9400 aMode = aParams->StereoMode;
9401 aCamera = aView->Camera();
9404 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
9405 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
9407 Standard_CString anArg = theArgVec[anArgIter];
9408 TCollection_AsciiString aFlag (anArg);
9410 if (anUpdateTool.parseRedrawMode (aFlag))
9414 else if (aFlag == "0"
9417 if (++anArgIter < theArgNb)
9419 std::cout << "Error: wrong number of arguments!\n";
9423 if (!aCamera.IsNull()
9424 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
9426 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
9428 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
9431 else if (aFlag == "1"
9434 if (++anArgIter < theArgNb)
9436 std::cout << "Error: wrong number of arguments!\n";
9440 if (!aCamera.IsNull())
9442 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9444 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9447 else if (aFlag == "-reverse"
9448 || aFlag == "-reversed"
9449 || aFlag == "-swap")
9451 Standard_Boolean toEnable = Standard_True;
9452 if (++anArgIter < theArgNb
9453 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9457 aParams->ToReverseStereo = toEnable;
9459 else if (aFlag == "-noreverse"
9460 || aFlag == "-noswap")
9462 Standard_Boolean toDisable = Standard_True;
9463 if (++anArgIter < theArgNb
9464 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
9468 aParams->ToReverseStereo = !toDisable;
9470 else if (aFlag == "-mode"
9471 || aFlag == "-stereomode")
9473 if (++anArgIter >= theArgNb
9474 || !parseStereoMode (theArgVec[anArgIter], aMode))
9476 std::cout << "Error: syntax error at '" << anArg << "'\n";
9480 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9482 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9485 else if (aFlag == "-anaglyph"
9486 || aFlag == "-anaglyphfilter")
9488 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9489 if (++anArgIter >= theArgNb
9490 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
9492 std::cout << "Error: syntax error at '" << anArg << "'\n";
9496 aMode = Graphic3d_StereoMode_Anaglyph;
9497 aParams->AnaglyphFilter = aFilter;
9499 else if (parseStereoMode (anArg, aMode)) // short syntax
9501 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9503 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9508 std::cout << "Error: syntax error at '" << anArg << "'\n";
9513 if (!aView.IsNull())
9515 aParams->StereoMode = aMode;
9516 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9521 //===============================================================================================
9522 //function : VDefaults
9524 //===============================================================================================
9525 static int VDefaults (Draw_Interpretor& theDi,
9526 Standard_Integer theArgsNb,
9527 const char** theArgVec)
9529 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
9532 std::cerr << "No active viewer!\n";
9536 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
9539 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
9541 theDi << "DeflType: relative\n"
9542 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
9546 theDi << "DeflType: absolute\n"
9547 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
9549 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
9550 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
9554 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
9556 TCollection_AsciiString anArg (theArgVec[anArgIter]);
9558 if (anArg == "-ABSDEFL"
9559 || anArg == "-ABSOLUTEDEFLECTION"
9561 || anArg == "-DEFLECTION")
9563 if (++anArgIter >= theArgsNb)
9565 std::cout << "Error: wrong syntax at " << anArg << "\n";
9568 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
9569 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
9571 else if (anArg == "-RELDEFL"
9572 || anArg == "-RELATIVEDEFLECTION"
9573 || anArg == "-DEVCOEFF"
9574 || anArg == "-DEVIATIONCOEFF"
9575 || anArg == "-DEVIATIONCOEFFICIENT")
9577 if (++anArgIter >= theArgsNb)
9579 std::cout << "Error: wrong syntax at " << anArg << "\n";
9582 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
9583 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
9585 else if (anArg == "-ANGDEFL"
9586 || anArg == "-ANGULARDEFL"
9587 || anArg == "-ANGULARDEFLECTION")
9589 if (++anArgIter >= theArgsNb)
9591 std::cout << "Error: wrong syntax at " << anArg << "\n";
9594 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
9595 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
9597 else if (anArg == "-AUTOTR"
9598 || anArg == "-AUTOTRIANG"
9599 || anArg == "-AUTOTRIANGULATION")
9601 if (++anArgIter >= theArgsNb)
9603 std::cout << "Error: wrong syntax at " << anArg << "\n";
9606 TCollection_AsciiString aValue (theArgVec[anArgIter]);
9611 aDefParams->SetAutoTriangulation (Standard_True);
9613 else if (aValue == "off"
9616 aDefParams->SetAutoTriangulation (Standard_False);
9621 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
9628 //! Auxiliary method
9629 inline void addLight (const Handle(V3d_Light)& theLightNew,
9630 const Graphic3d_ZLayerId theLayer,
9631 const Standard_Boolean theIsGlobal)
9633 if (theLightNew.IsNull())
9638 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9639 if (theLayer == Graphic3d_ZLayerId_UNKNOWN)
9641 aViewer->AddLight (theLightNew);
9644 aViewer->SetLightOn (theLightNew);
9648 ViewerTest::CurrentView()->SetLightOn (theLightNew);
9653 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer);
9654 if (aSettings.Lights().IsNull())
9656 aSettings.SetLights (new Graphic3d_LightSet());
9658 aSettings.Lights()->Add (theLightNew);
9659 aViewer->SetZLayerSettings (theLayer, aSettings);
9663 //! Auxiliary method
9664 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
9666 TCollection_AsciiString anArgNextCase (theArgNext);
9667 anArgNextCase.UpperCase();
9668 if (anArgNextCase.Length() > 5
9669 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
9671 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
9675 return theArgNext.IntegerValue();
9679 //===============================================================================================
9682 //===============================================================================================
9683 static int VLight (Draw_Interpretor& theDi,
9684 Standard_Integer theArgsNb,
9685 const char** theArgVec)
9687 Handle(V3d_View) aView = ViewerTest::CurrentView();
9688 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9690 || aViewer.IsNull())
9692 std::cerr << "No active viewer!\n";
9696 Standard_Real anXYZ[3] = {};
9697 Standard_Real anAtten[2] = {};
9700 // print lights info
9701 Standard_Integer aLightId = 0;
9702 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
9704 Handle(V3d_Light) aLight = aLightIter.Value();
9705 const Quantity_Color aColor = aLight->Color();
9706 theDi << "Light #" << aLightId
9707 << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "")
9708 << " [" << aLight->GetId() << "]" << "\n";
9709 switch (aLight->Type())
9713 theDi << " Type: Ambient\n";
9714 theDi << " Intensity: " << aLight->Intensity() << "\n";
9717 case V3d_DIRECTIONAL:
9719 theDi << " Type: Directional\n";
9720 theDi << " Intensity: " << aLight->Intensity() << "\n";
9721 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9722 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
9723 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
9724 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9727 case V3d_POSITIONAL:
9729 theDi << " Type: Positional\n";
9730 theDi << " Intensity: " << aLight->Intensity() << "\n";
9731 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9732 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
9733 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9734 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9735 aLight->Attenuation (anAtten[0], anAtten[1]);
9736 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
9741 theDi << " Type: Spot\n";
9742 theDi << " Intensity: " << aLight->Intensity() << "\n";
9743 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9744 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9745 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9746 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
9747 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9748 aLight->Attenuation (anAtten[0], anAtten[1]);
9749 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
9750 theDi << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n";
9751 theDi << " Exponent: " << aLight->Concentration() << "\n";
9756 theDi << " Type: UNKNOWN\n";
9760 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n";
9764 Handle(V3d_Light) aLightNew;
9765 Handle(V3d_Light) aLightOld;
9766 Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN;
9767 Standard_Boolean isGlobal = Standard_True;
9768 Standard_Boolean toCreate = Standard_False;
9769 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
9770 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
9772 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
9774 TCollection_AsciiString aName, aValue;
9775 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
9776 TCollection_AsciiString anArgCase (anArg);
9777 anArgCase.UpperCase();
9778 if (anUpdateTool.parseRedrawMode (anArg))
9783 if (anArgCase.IsEqual ("NEW")
9784 || anArgCase.IsEqual ("ADD")
9785 || anArgCase.IsEqual ("CREATE")
9786 || anArgCase.IsEqual ("-NEW")
9787 || anArgCase.IsEqual ("-ADD")
9788 || anArgCase.IsEqual ("-CREATE"))
9790 toCreate = Standard_True;
9792 else if (anArgCase.IsEqual ("-LAYER")
9793 || anArgCase.IsEqual ("-ZLAYER"))
9795 if (++anArgIt >= theArgsNb)
9797 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9801 TCollection_AsciiString aValStr (theArgVec[anArgIt]);
9802 aValStr.LowerCase();
9803 if (aValStr == "default"
9804 || aValStr == "def")
9806 aLayer = Graphic3d_ZLayerId_Default;
9808 else if (aValStr == "top")
9810 aLayer = Graphic3d_ZLayerId_Top;
9812 else if (aValStr == "topmost")
9814 aLayer = Graphic3d_ZLayerId_Topmost;
9816 else if (aValStr == "toposd"
9817 || aValStr == "osd")
9819 aLayer = Graphic3d_ZLayerId_TopOSD;
9821 else if (aValStr == "botosd"
9822 || aValStr == "bottom")
9824 aLayer = Graphic3d_ZLayerId_BotOSD;
9826 else if (aValStr.IsIntegerValue())
9828 aLayer = Draw::Atoi (theArgVec[anArgIt]);
9832 std::cout << "Wrong syntax at argument '" << anArg << "'!\n";
9836 else if (anArgCase.IsEqual ("GLOB")
9837 || anArgCase.IsEqual ("GLOBAL")
9838 || anArgCase.IsEqual ("-GLOB")
9839 || anArgCase.IsEqual ("-GLOBAL"))
9841 isGlobal = Standard_True;
9843 else if (anArgCase.IsEqual ("LOC")
9844 || anArgCase.IsEqual ("LOCAL")
9845 || anArgCase.IsEqual ("-LOC")
9846 || anArgCase.IsEqual ("-LOCAL"))
9848 isGlobal = Standard_False;
9850 else if (anArgCase.IsEqual ("DEF")
9851 || anArgCase.IsEqual ("DEFAULTS")
9852 || anArgCase.IsEqual ("-DEF")
9853 || anArgCase.IsEqual ("-DEFAULTS"))
9855 toCreate = Standard_False;
9856 aViewer->SetDefaultLights();
9858 else if (anArgCase.IsEqual ("CLR")
9859 || anArgCase.IsEqual ("CLEAR")
9860 || anArgCase.IsEqual ("-CLR")
9861 || anArgCase.IsEqual ("-CLEAR"))
9863 toCreate = Standard_False;
9865 TColStd_SequenceOfInteger aLayers;
9866 aViewer->GetAllZLayers (aLayers);
9867 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
9869 if (aLayeriter.Value() == aLayer
9870 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
9872 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
9873 aSettings.SetLights (Handle(Graphic3d_LightSet)());
9874 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
9875 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
9882 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
9884 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
9886 Handle(V3d_Light) aLight = aLightIter.Value();
9887 aViewer->DelLight (aLight);
9888 aLightIter = aView->ActiveLightIterator();
9892 else if (anArgCase.IsEqual ("AMB")
9893 || anArgCase.IsEqual ("AMBIENT")
9894 || anArgCase.IsEqual ("AMBLIGHT"))
9898 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9902 addLight (aLightNew, aLayer, isGlobal);
9903 toCreate = Standard_False;
9904 aLightNew = new V3d_AmbientLight();
9906 else if (anArgCase.IsEqual ("DIRECTIONAL")
9907 || anArgCase.IsEqual ("DIRLIGHT"))
9911 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9915 addLight (aLightNew, aLayer, isGlobal);
9916 toCreate = Standard_False;
9917 aLightNew = new V3d_DirectionalLight();
9919 else if (anArgCase.IsEqual ("SPOT")
9920 || anArgCase.IsEqual ("SPOTLIGHT"))
9924 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9928 addLight (aLightNew, aLayer, isGlobal);
9929 toCreate = Standard_False;
9930 aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0));
9932 else if (anArgCase.IsEqual ("POSLIGHT")
9933 || anArgCase.IsEqual ("POSITIONAL"))
9937 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9941 addLight (aLightNew, aLayer, isGlobal);
9942 toCreate = Standard_False;
9943 aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0));
9945 else if (anArgCase.IsEqual ("CHANGE")
9946 || anArgCase.IsEqual ("-CHANGE"))
9948 if (++anArgIt >= theArgsNb)
9950 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9954 addLight (aLightNew, aLayer, isGlobal);
9955 aLightNew.Nullify();
9956 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
9957 Standard_Integer aLightIt = 0;
9958 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
9960 if (aLightIt == aLightId)
9962 aLightOld = aLightIter.Value();
9967 if (aLightOld.IsNull())
9969 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
9973 else if (anArgCase.IsEqual ("DEL")
9974 || anArgCase.IsEqual ("DELETE")
9975 || anArgCase.IsEqual ("-DEL")
9976 || anArgCase.IsEqual ("-DELETE"))
9978 Handle(V3d_Light) aLightDel;
9979 if (++anArgIt >= theArgsNb)
9981 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9985 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
9986 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
9987 Standard_Integer aLightIt = 0;
9988 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
9990 aLightDel = aLightIter.Value();
9991 if (aLightIt == aLightDelId)
9996 if (aLightDel.IsNull())
10001 TColStd_SequenceOfInteger aLayers;
10002 aViewer->GetAllZLayers (aLayers);
10003 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
10005 if (aLayeriter.Value() == aLayer
10006 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
10008 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
10009 if (!aSettings.Lights().IsNull())
10011 aSettings.Lights()->Remove (aLightDel);
10012 if (aSettings.Lights()->IsEmpty())
10014 aSettings.SetLights (Handle(Graphic3d_LightSet)());
10017 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
10018 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
10025 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
10027 aViewer->DelLight (aLightDel);
10030 else if (anArgCase.IsEqual ("COLOR")
10031 || anArgCase.IsEqual ("COLOUR")
10032 || anArgCase.IsEqual ("-COLOR")
10033 || anArgCase.IsEqual ("-COLOUR"))
10035 if (++anArgIt >= theArgsNb
10036 || aLightCurr.IsNull())
10038 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10042 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
10043 anArgNext.UpperCase();
10044 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
10045 aLightCurr->SetColor (aColor);
10047 else if (anArgCase.IsEqual ("POS")
10048 || anArgCase.IsEqual ("POSITION")
10049 || anArgCase.IsEqual ("-POS")
10050 || anArgCase.IsEqual ("-POSITION"))
10052 if ((anArgIt + 3) >= theArgsNb
10053 || aLightCurr.IsNull()
10054 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10055 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
10057 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10061 anXYZ[0] = Atof (theArgVec[++anArgIt]);
10062 anXYZ[1] = Atof (theArgVec[++anArgIt]);
10063 anXYZ[2] = Atof (theArgVec[++anArgIt]);
10064 aLightCurr->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
10066 else if (anArgCase.IsEqual ("DIR")
10067 || anArgCase.IsEqual ("DIRECTION")
10068 || anArgCase.IsEqual ("-DIR")
10069 || anArgCase.IsEqual ("-DIRECTION"))
10071 if ((anArgIt + 3) >= theArgsNb
10072 || aLightCurr.IsNull()
10073 || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL
10074 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
10076 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10080 anXYZ[0] = Atof (theArgVec[++anArgIt]);
10081 anXYZ[1] = Atof (theArgVec[++anArgIt]);
10082 anXYZ[2] = Atof (theArgVec[++anArgIt]);
10083 aLightCurr->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
10085 else if (anArgCase.IsEqual ("SM")
10086 || anArgCase.IsEqual ("SMOOTHNESS")
10087 || anArgCase.IsEqual ("-SM")
10088 || anArgCase.IsEqual ("-SMOOTHNESS"))
10090 if (++anArgIt >= theArgsNb
10091 || aLightCurr.IsNull())
10093 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10097 Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
10098 if (Abs (aSmoothness) <= ShortRealEpsilon())
10100 aLightCurr->SetIntensity (1.f);
10102 else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon())
10104 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
10108 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
10109 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
10112 if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL)
10114 aLightCurr->SetSmoothRadius (aSmoothness);
10116 else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
10118 aLightCurr->SetSmoothAngle (aSmoothness);
10121 else if (anArgCase.IsEqual ("INT")
10122 || anArgCase.IsEqual ("INTENSITY")
10123 || anArgCase.IsEqual ("-INT")
10124 || anArgCase.IsEqual ("-INTENSITY"))
10126 if (++anArgIt >= theArgsNb
10127 || aLightCurr.IsNull())
10129 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10133 Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
10134 aLightCurr->SetIntensity (aIntensity);
10136 else if (anArgCase.IsEqual ("ANG")
10137 || anArgCase.IsEqual ("ANGLE")
10138 || anArgCase.IsEqual ("-ANG")
10139 || anArgCase.IsEqual ("-ANGLE"))
10141 if (++anArgIt >= theArgsNb
10142 || aLightCurr.IsNull()
10143 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
10145 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10149 Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
10150 aLightCurr->SetAngle (Standard_ShortReal (anAngle / 180.0 * M_PI));
10152 else if (anArgCase.IsEqual ("CONSTATTEN")
10153 || anArgCase.IsEqual ("CONSTATTENUATION")
10154 || anArgCase.IsEqual ("-CONSTATTEN")
10155 || anArgCase.IsEqual ("-CONSTATTENUATION"))
10157 if (++anArgIt >= theArgsNb
10158 || aLightCurr.IsNull()
10159 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10160 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
10162 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10166 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
10167 anAtten[0] = Atof (theArgVec[anArgIt]);
10168 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
10170 else if (anArgCase.IsEqual ("LINATTEN")
10171 || anArgCase.IsEqual ("LINEARATTEN")
10172 || anArgCase.IsEqual ("LINEARATTENUATION")
10173 || anArgCase.IsEqual ("-LINATTEN")
10174 || anArgCase.IsEqual ("-LINEARATTEN")
10175 || anArgCase.IsEqual ("-LINEARATTENUATION"))
10177 if (++anArgIt >= theArgsNb
10178 || aLightCurr.IsNull()
10179 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10180 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
10182 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10186 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
10187 anAtten[1] = Atof (theArgVec[anArgIt]);
10188 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
10190 else if (anArgCase.IsEqual ("EXP")
10191 || anArgCase.IsEqual ("EXPONENT")
10192 || anArgCase.IsEqual ("SPOTEXP")
10193 || anArgCase.IsEqual ("SPOTEXPONENT")
10194 || anArgCase.IsEqual ("-EXP")
10195 || anArgCase.IsEqual ("-EXPONENT")
10196 || anArgCase.IsEqual ("-SPOTEXP")
10197 || anArgCase.IsEqual ("-SPOTEXPONENT"))
10199 if (++anArgIt >= theArgsNb
10200 || aLightCurr.IsNull()
10201 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
10203 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10207 aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt]));
10209 else if (anArgCase.IsEqual ("HEAD")
10210 || anArgCase.IsEqual ("HEADLIGHT")
10211 || anArgCase.IsEqual ("-HEAD")
10212 || anArgCase.IsEqual ("-HEADLIGHT"))
10214 if (aLightCurr.IsNull()
10215 || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
10217 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10221 Standard_Boolean isHeadLight = Standard_True;
10222 if (anArgIt + 1 < theArgsNb
10223 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight))
10227 aLightCurr->SetHeadlight (isHeadLight);
10231 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
10235 addLight (aLightNew, aLayer, isGlobal);
10239 //! Read Graphic3d_RenderingParams::PerfCounters flag.
10240 static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue,
10241 Standard_Boolean& theToReset,
10242 Graphic3d_RenderingParams::PerfCounters& theFlagsRem,
10243 Graphic3d_RenderingParams::PerfCounters& theFlagsAdd)
10245 Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE;
10246 TCollection_AsciiString aVal = theValue;
10247 Standard_Boolean toReverse = Standard_False;
10248 if (aVal == "none")
10250 theToReset = Standard_True;
10251 return Standard_True;
10253 else if (aVal.StartsWith ("-"))
10255 toReverse = Standard_True;
10256 aVal = aVal.SubString (2, aVal.Length());
10258 else if (aVal.StartsWith ("no"))
10260 toReverse = Standard_True;
10261 aVal = aVal.SubString (3, aVal.Length());
10263 else if (aVal.StartsWith ("+"))
10265 aVal = aVal.SubString (2, aVal.Length());
10269 theToReset = Standard_True;
10273 || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate;
10274 else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU;
10275 else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers;
10276 else if (aVal == "structs"
10277 || aVal == "structures"
10278 || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures;
10279 else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups;
10280 else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
10281 else if (aVal == "tris"
10282 || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles;
10283 else if (aVal == "pnts"
10284 || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points;
10285 else if (aVal == "mem"
10286 || aVal == "gpumem"
10287 || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem;
10288 else if (aVal == "skipimmediate"
10289 || aVal == "noimmediate") aFlag = Graphic3d_RenderingParams::PerfCounters_SkipImmediate;
10290 else if (aVal == "frametime"
10291 || aVal == "frametimers"
10292 || aVal == "time") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameTime;
10293 else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic;
10294 else if (aVal == "extended"
10295 || aVal == "verbose"
10296 || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended;
10297 else if (aVal == "full"
10298 || aVal == "all") aFlag = Graphic3d_RenderingParams::PerfCounters_All;
10301 return Standard_False;
10306 theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag);
10310 theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag);
10312 return Standard_True;
10315 //! Read Graphic3d_RenderingParams::PerfCounters flags.
10316 static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue,
10317 Graphic3d_RenderingParams::PerfCounters& theFlags)
10319 TCollection_AsciiString aValue = theValue;
10320 Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE;
10321 Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE;
10322 Standard_Boolean toReset = Standard_False;
10325 Standard_Integer aSplitPos = aValue.Search ("|");
10326 if (aSplitPos <= 0)
10328 if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd))
10330 return Standard_False;
10334 theFlags = Graphic3d_RenderingParams::PerfCounters_NONE;
10336 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd);
10337 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem);
10338 return Standard_True;
10343 TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1);
10344 if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd))
10346 return Standard_False;
10349 aValue = aValue.SubString (aSplitPos + 1, aValue.Length());
10353 //=======================================================================
10354 //function : VRenderParams
10355 //purpose : Enables/disables rendering features
10356 //=======================================================================
10358 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
10359 Standard_Integer theArgNb,
10360 const char** theArgVec)
10362 Handle(V3d_View) aView = ViewerTest::CurrentView();
10363 if (aView.IsNull())
10365 std::cerr << "Error: no active viewer!\n";
10369 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
10370 TCollection_AsciiString aCmdName (theArgVec[0]);
10371 aCmdName.LowerCase();
10372 if (aCmdName == "vraytrace")
10376 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
10379 else if (theArgNb == 2)
10381 TCollection_AsciiString aValue (theArgVec[1]);
10382 aValue.LowerCase();
10386 aParams.Method = Graphic3d_RM_RAYTRACING;
10390 else if (aValue == "off"
10393 aParams.Method = Graphic3d_RM_RASTERIZATION;
10399 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
10405 std::cout << "Error: wrong number of arguments\n";
10412 theDI << "renderMode: ";
10413 switch (aParams.Method)
10415 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
10416 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
10419 theDI << "transparency: ";
10420 switch (aParams.TransparencyMethod)
10422 case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break;
10423 case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: "
10424 << TCollection_AsciiString (aParams.OitDepthFactor); break;
10427 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
10428 theDI << "rendScale: " << aParams.RenderResolutionScale << "\n";
10429 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
10430 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
10431 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
10432 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
10433 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
10434 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
10435 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
10436 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
10437 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
10438 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
10439 theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
10440 theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n";
10441 theDI << "tile size (iss):" << aParams.RayTracingTileSize << "x" << aParams.RayTracingTileSize << "\n";
10442 theDI << "shadingModel: ";
10443 switch (aView->ShadingModel())
10445 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
10446 case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break;
10447 case Graphic3d_TOSM_FACET: theDI << "flat"; break;
10448 case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break;
10449 case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break;
10452 theDI << "perfCounters:";
10453 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0)
10457 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
10461 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
10463 theDI << " structs";
10465 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0)
10467 theDI << " groups";
10469 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0)
10471 theDI << " arrays";
10473 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0)
10477 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
10481 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0)
10483 theDI << " gpumem";
10485 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameTime) != 0)
10487 theDI << " frameTime";
10489 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_SkipImmediate) != 0)
10491 theDI << " skipimmediate";
10493 if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE)
10499 theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n";
10500 theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n";
10501 theDI << "frustum culling: " << (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On ? "on" :
10502 aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off ? "off" :
10503 "noUpdate") << "\n";
10508 Standard_Boolean toPrint = Standard_False;
10509 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10510 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
10512 Standard_CString anArg (theArgVec[anArgIter]);
10513 TCollection_AsciiString aFlag (anArg);
10515 if (anUpdateTool.parseRedrawMode (aFlag))
10519 else if (aFlag == "-echo"
10520 || aFlag == "-print")
10522 toPrint = Standard_True;
10523 anUpdateTool.Invalidate();
10525 else if (aFlag == "-mode"
10526 || aFlag == "-rendermode"
10527 || aFlag == "-render_mode")
10531 switch (aParams.Method)
10533 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
10534 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
10540 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10544 else if (aFlag == "-ray"
10545 || aFlag == "-raytrace")
10549 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
10553 aParams.Method = Graphic3d_RM_RAYTRACING;
10555 else if (aFlag == "-rast"
10556 || aFlag == "-raster"
10557 || aFlag == "-rasterization")
10561 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
10565 aParams.Method = Graphic3d_RM_RASTERIZATION;
10567 else if (aFlag == "-msaa")
10571 theDI << aParams.NbMsaaSamples << " ";
10574 else if (++anArgIter >= theArgNb)
10576 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10580 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
10581 if (aNbSamples < 0)
10583 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
10588 aParams.NbMsaaSamples = aNbSamples;
10591 else if (aFlag == "-linefeather"
10592 || aFlag == "-edgefeather"
10593 || aFlag == "-feather")
10597 theDI << " " << aParams.LineFeather << " ";
10600 else if (++anArgIter >= theArgNb)
10602 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10606 TCollection_AsciiString aParam = theArgVec[anArgIter];
10607 const Standard_ShortReal aFeather = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
10608 if (aFeather <= 0.0f)
10610 std::cerr << "Error: invalid value of line width feather " << aFeather << ". Should be > 0\n";
10613 aParams.LineFeather = aFeather;
10615 else if (aFlag == "-oit")
10619 if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
10621 theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " ";
10625 theDI << "off" << " ";
10629 else if (++anArgIter >= theArgNb)
10631 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10635 TCollection_AsciiString aParam = theArgVec[anArgIter];
10636 aParam.LowerCase();
10637 if (aParam.IsRealValue())
10639 const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
10640 if (aWeight < 0.f || aWeight > 1.f)
10642 std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n";
10646 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
10647 aParams.OitDepthFactor = aWeight;
10649 else if (aParam == "off")
10651 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED;
10655 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10659 else if (aFlag == "-depthprepass")
10663 theDI << (aParams.ToEnableDepthPrepass ? "on " : "off ");
10666 aParams.ToEnableDepthPrepass = Standard_True;
10667 if (anArgIter + 1 < theArgNb
10668 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass))
10673 else if (aFlag == "-samplealphatocoverage"
10674 || aFlag == "-alphatocoverage")
10678 theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off ");
10681 aParams.ToEnableAlphaToCoverage = Standard_True;
10682 if (anArgIter + 1 < theArgNb
10683 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage))
10688 else if (aFlag == "-rendscale"
10689 || aFlag == "-renderscale"
10690 || aFlag == "-renderresolutionscale")
10694 theDI << aParams.RenderResolutionScale << " ";
10697 else if (++anArgIter >= theArgNb)
10699 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10703 const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
10706 std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n";
10711 aParams.RenderResolutionScale = Standard_ShortReal(aScale);
10714 else if (aFlag == "-raydepth"
10715 || aFlag == "-ray_depth")
10719 theDI << aParams.RaytracingDepth << " ";
10722 else if (++anArgIter >= theArgNb)
10724 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10728 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
10730 // We allow RaytracingDepth be more than 10 in case of GI enabled
10731 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
10733 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
10738 aParams.RaytracingDepth = aDepth;
10741 else if (aFlag == "-shad"
10742 || aFlag == "-shadows")
10746 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
10750 Standard_Boolean toEnable = Standard_True;
10751 if (++anArgIter < theArgNb
10752 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10756 aParams.IsShadowEnabled = toEnable;
10758 else if (aFlag == "-refl"
10759 || aFlag == "-reflections")
10763 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
10767 Standard_Boolean toEnable = Standard_True;
10768 if (++anArgIter < theArgNb
10769 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10773 aParams.IsReflectionEnabled = toEnable;
10775 else if (aFlag == "-fsaa")
10779 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
10783 Standard_Boolean toEnable = Standard_True;
10784 if (++anArgIter < theArgNb
10785 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10789 aParams.IsAntialiasingEnabled = toEnable;
10791 else if (aFlag == "-gleam")
10795 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
10799 Standard_Boolean toEnable = Standard_True;
10800 if (++anArgIter < theArgNb
10801 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10805 aParams.IsTransparentShadowEnabled = toEnable;
10807 else if (aFlag == "-gi")
10811 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
10815 Standard_Boolean toEnable = Standard_True;
10816 if (++anArgIter < theArgNb
10817 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10821 aParams.IsGlobalIlluminationEnabled = toEnable;
10824 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
10827 else if (aFlag == "-blockedrng"
10828 || aFlag == "-brng")
10832 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
10836 Standard_Boolean toEnable = Standard_True;
10837 if (++anArgIter < theArgNb
10838 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10842 aParams.CoherentPathTracingMode = toEnable;
10844 else if (aFlag == "-maxrad")
10848 theDI << aParams.RadianceClampingValue << " ";
10851 else if (++anArgIter >= theArgNb)
10853 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10857 const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
10858 if (!aMaxRadStr.IsRealValue())
10860 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10864 const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
10865 if (aMaxRadiance <= 0.0)
10867 std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n";
10872 aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
10875 else if (aFlag == "-iss")
10879 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
10883 Standard_Boolean toEnable = Standard_True;
10884 if (++anArgIter < theArgNb
10885 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10889 aParams.AdaptiveScreenSampling = toEnable;
10891 else if (aFlag == "-issatomic")
10895 theDI << (aParams.AdaptiveScreenSamplingAtomic ? "on" : "off") << " ";
10899 Standard_Boolean toEnable = Standard_True;
10900 if (++anArgIter < theArgNb
10901 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10905 aParams.AdaptiveScreenSamplingAtomic = toEnable;
10907 else if (aFlag == "-issd")
10911 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
10915 Standard_Boolean toEnable = Standard_True;
10916 if (++anArgIter < theArgNb
10917 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10921 aParams.ShowSamplingTiles = toEnable;
10923 else if (aFlag == "-tilesize")
10927 theDI << aParams.RayTracingTileSize << " ";
10930 else if (++anArgIter >= theArgNb)
10932 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10936 const Standard_Integer aTileSize = Draw::Atoi (theArgVec[anArgIter]);
10939 std::cerr << "Error: invalid size of ISS tile " << aTileSize << ".\n";
10942 aParams.RayTracingTileSize = aTileSize;
10944 else if (aFlag == "-nbtiles")
10948 theDI << aParams.NbRayTracingTiles << " ";
10951 else if (++anArgIter >= theArgNb)
10953 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10957 const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]);
10960 std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n";
10963 else if (aNbTiles > 0
10965 || aNbTiles > 1024))
10967 std::cerr << "Warning: suboptimal number of ISS tiles " << aNbTiles << ". Recommended range: [64, 1024].\n";
10969 aParams.NbRayTracingTiles = aNbTiles;
10971 else if (aFlag == "-env")
10975 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
10979 Standard_Boolean toEnable = Standard_True;
10980 if (++anArgIter < theArgNb
10981 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10985 aParams.UseEnvironmentMapBackground = toEnable;
10987 else if (aFlag == "-twoside")
10991 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
10995 Standard_Boolean toEnable = Standard_True;
10996 if (++anArgIter < theArgNb
10997 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11001 aParams.TwoSidedBsdfModels = toEnable;
11003 else if (aFlag == "-shademodel"
11004 || aFlag == "-shadingmodel"
11005 || aFlag == "-shading")
11009 switch (aView->ShadingModel())
11011 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
11012 case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break;
11013 case Graphic3d_TOSM_FACET: theDI << "flat "; break;
11014 case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break;
11015 case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break;
11020 if (++anArgIter >= theArgNb)
11022 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11025 Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT;
11026 if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel)
11027 && aModel != Graphic3d_TOSM_DEFAULT)
11029 aView->SetShadingModel (aModel);
11033 std::cout << "Error: unknown shading model '" << theArgVec[anArgIter] << "'\n";
11037 else if (aFlag == "-resolution")
11039 if (++anArgIter >= theArgNb)
11041 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
11045 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
11046 if (aResolution.IsIntegerValue())
11048 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
11052 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11056 else if (aFlag == "-rebuildglsl"
11057 || aFlag == "-rebuild")
11061 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
11065 Standard_Boolean toEnable = Standard_True;
11066 if (++anArgIter < theArgNb
11067 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
11071 aParams.RebuildRayTracingShaders = toEnable;
11073 else if (aFlag == "-focal")
11075 if (++anArgIter >= theArgNb)
11077 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11081 TCollection_AsciiString aParam (theArgVec[anArgIter]);
11082 if (aParam.IsRealValue())
11084 float aFocalDist = static_cast<float> (aParam.RealValue());
11085 if (aFocalDist < 0)
11087 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
11090 aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist;
11094 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11098 else if (aFlag == "-aperture")
11100 if (++anArgIter >= theArgNb)
11102 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11106 TCollection_AsciiString aParam(theArgVec[anArgIter]);
11107 if (aParam.IsRealValue())
11109 float aApertureSize = static_cast<float> (aParam.RealValue());
11110 if (aApertureSize < 0)
11112 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
11115 aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize;
11119 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11123 else if (aFlag == "-exposure")
11125 if (++anArgIter >= theArgNb)
11127 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11131 TCollection_AsciiString anExposure (theArgVec[anArgIter]);
11132 if (anExposure.IsRealValue())
11134 aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
11138 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11142 else if (aFlag == "-whitepoint")
11144 if (++anArgIter >= theArgNb)
11146 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11150 TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
11151 if (aWhitePoint.IsRealValue())
11153 aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
11157 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11161 else if (aFlag == "-tonemapping")
11163 if (++anArgIter >= theArgNb)
11165 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11169 TCollection_AsciiString aMode (theArgVec[anArgIter]);
11172 if (aMode == "disabled")
11174 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled;
11176 else if (aMode == "filmic")
11178 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;
11182 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11186 else if (aFlag == "-performancestats"
11187 || aFlag == "-performancecounters"
11188 || aFlag == "-perfstats"
11189 || aFlag == "-perfcounters"
11190 || aFlag == "-stats")
11192 if (++anArgIter >= theArgNb)
11194 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11198 TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]);
11199 aFlagsStr.LowerCase();
11200 Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats;
11201 if (!convertToPerfStatsFlags (aFlagsStr, aFlags))
11203 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11206 aView->ChangeRenderingParams().CollectedStats = aFlags;
11207 aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE;
11209 else if (aFlag == "-perfupdateinterval"
11210 || aFlag == "-statsupdateinterval")
11212 if (++anArgIter >= theArgNb)
11214 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11217 aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
11219 else if (aFlag == "-perfchart"
11220 || aFlag == "-statschart")
11222 if (++anArgIter >= theArgNb)
11224 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11227 aView->ChangeRenderingParams().StatsNbFrames = Draw::Atoi (theArgVec[anArgIter]);
11229 else if (aFlag == "-perfchartmax"
11230 || aFlag == "-statschartmax")
11232 if (++anArgIter >= theArgNb)
11234 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11237 aView->ChangeRenderingParams().StatsMaxChartTime = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
11239 else if (aFlag == "-frustumculling"
11240 || aFlag == "-culling")
11244 theDI << ((aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On) ? "on" :
11245 (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off) ? "off" :
11246 "noUpdate") << " ";
11250 Graphic3d_RenderingParams::FrustumCulling aState = Graphic3d_RenderingParams::FrustumCulling_On;
11251 if (++anArgIter < theArgNb)
11253 TCollection_AsciiString aStateStr(theArgVec[anArgIter]);
11254 aStateStr.LowerCase();
11255 bool toEnable = true;
11256 if (ViewerTest::ParseOnOff (aStateStr.ToCString(), toEnable))
11258 aState = toEnable ? Graphic3d_RenderingParams::FrustumCulling_On : Graphic3d_RenderingParams::FrustumCulling_Off;
11260 else if (aStateStr == "noupdate"
11261 || aStateStr == "freeze")
11263 aState = Graphic3d_RenderingParams::FrustumCulling_NoUpdate;
11270 aParams.FrustumCullingState = aState;
11274 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
11282 //=======================================================================
11283 //function : searchInfo
11285 //=======================================================================
11286 inline TCollection_AsciiString searchInfo (const TColStd_IndexedDataMapOfStringString& theDict,
11287 const TCollection_AsciiString& theKey)
11289 for (TColStd_IndexedDataMapOfStringString::Iterator anIter (theDict); anIter.More(); anIter.Next())
11291 if (TCollection_AsciiString::IsSameString (anIter.Key(), theKey, Standard_False))
11293 return anIter.Value();
11296 return TCollection_AsciiString();
11299 //=======================================================================
11300 //function : VStatProfiler
11302 //=======================================================================
11303 static Standard_Integer VStatProfiler (Draw_Interpretor& theDI,
11304 Standard_Integer theArgNb,
11305 const char** theArgVec)
11307 Handle(V3d_View) aView = ViewerTest::CurrentView();
11308 if (aView.IsNull())
11310 std::cerr << "Error: no active viewer!\n";
11314 Standard_Boolean toRedraw = Standard_True;
11315 Graphic3d_RenderingParams::PerfCounters aPrevCounters = aView->ChangeRenderingParams().CollectedStats;
11316 Standard_ShortReal aPrevUpdInterval = aView->ChangeRenderingParams().StatsUpdateInterval;
11317 Graphic3d_RenderingParams::PerfCounters aRenderParams = Graphic3d_RenderingParams::PerfCounters_NONE;
11318 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
11320 Standard_CString anArg (theArgVec[anArgIter]);
11321 TCollection_AsciiString aFlag (anArg);
11323 if (aFlag == "-noredraw")
11325 toRedraw = Standard_False;
11329 Graphic3d_RenderingParams::PerfCounters aParam = Graphic3d_RenderingParams::PerfCounters_NONE;
11330 if (aFlag == "fps") aParam = Graphic3d_RenderingParams::PerfCounters_FrameRate;
11331 else if (aFlag == "cpu") aParam = Graphic3d_RenderingParams::PerfCounters_CPU;
11332 else if (aFlag == "alllayers"
11333 || aFlag == "layers") aParam = Graphic3d_RenderingParams::PerfCounters_Layers;
11334 else if (aFlag == "allstructs"
11335 || aFlag == "structs") aParam = Graphic3d_RenderingParams::PerfCounters_Structures;
11336 else if (aFlag == "groups") aParam = Graphic3d_RenderingParams::PerfCounters_Groups;
11337 else if (aFlag == "allarrays"
11338 || aFlag == "fillarrays"
11339 || aFlag == "linearrays"
11340 || aFlag == "pointarrays"
11341 || aFlag == "textarrays") aParam = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
11342 else if (aFlag == "triangles") aParam = Graphic3d_RenderingParams::PerfCounters_Triangles;
11343 else if (aFlag == "points") aParam = Graphic3d_RenderingParams::PerfCounters_Points;
11344 else if (aFlag == "geommem"
11345 || aFlag == "texturemem"
11346 || aFlag == "framemem") aParam = Graphic3d_RenderingParams::PerfCounters_EstimMem;
11347 else if (aFlag == "elapsedframe"
11348 || aFlag == "cpuframeaverage"
11349 || aFlag == "cpupickingaverage"
11350 || aFlag == "cpucullingaverage"
11351 || aFlag == "cpudynaverage"
11352 || aFlag == "cpuframemax"
11353 || aFlag == "cpupickingmax"
11354 || aFlag == "cpucullingmax"
11355 || aFlag == "cpudynmax") aParam = Graphic3d_RenderingParams::PerfCounters_FrameTime;
11358 std::cerr << "Unknown argument '" << theArgVec[anArgIter] << "'!\n";
11362 aRenderParams = Graphic3d_RenderingParams::PerfCounters (aRenderParams | aParam);
11366 if (aRenderParams != Graphic3d_RenderingParams::PerfCounters_NONE)
11368 aView->ChangeRenderingParams().CollectedStats =
11369 Graphic3d_RenderingParams::PerfCounters (aView->RenderingParams().CollectedStats | aRenderParams);
11373 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
11375 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
11378 TColStd_IndexedDataMapOfStringString aDict;
11379 aView->StatisticInformation (aDict);
11381 aView->ChangeRenderingParams().CollectedStats = aPrevCounters;
11383 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
11385 Standard_CString anArg(theArgVec[anArgIter]);
11386 TCollection_AsciiString aFlag(anArg);
11388 if (aFlag == "fps")
11390 theDI << searchInfo (aDict, "FPS") << " ";
11392 else if (aFlag == "cpu")
11394 theDI << searchInfo (aDict, "CPU FPS") << " ";
11396 else if (aFlag == "alllayers")
11398 theDI << searchInfo (aDict, "Layers") << " ";
11400 else if (aFlag == "layers")
11402 theDI << searchInfo (aDict, "Rendered layers") << " ";
11404 else if (aFlag == "allstructs")
11406 theDI << searchInfo (aDict, "Structs") << " ";
11408 else if (aFlag == "structs")
11410 theDI << searchInfo (aDict, "Rendered structs") << " ";
11412 else if (aFlag == "groups")
11414 theDI << searchInfo (aDict, "Rendered groups") << " ";
11416 else if (aFlag == "allarrays")
11418 theDI << searchInfo (aDict, "Rendered arrays") << " ";
11420 else if (aFlag == "fillarrays")
11422 theDI << searchInfo (aDict, "Rendered [fill] arrays") << " ";
11424 else if (aFlag == "linearrays")
11426 theDI << searchInfo (aDict, "Rendered [line] arrays") << " ";
11428 else if (aFlag == "pointarrays")
11430 theDI << searchInfo (aDict, "Rendered [point] arrays") << " ";
11432 else if (aFlag == "textarrays")
11434 theDI << searchInfo (aDict, "Rendered [text] arrays") << " ";
11436 else if (aFlag == "triangles")
11438 theDI << searchInfo (aDict, "Rendered triangles") << " ";
11440 else if (aFlag == "points")
11442 theDI << searchInfo (aDict, "Rendered points") << " ";
11444 else if (aFlag == "geommem")
11446 theDI << searchInfo (aDict, "GPU Memory [geometry]") << " ";
11448 else if (aFlag == "texturemem")
11450 theDI << searchInfo (aDict, "GPU Memory [textures]") << " ";
11452 else if (aFlag == "framemem")
11454 theDI << searchInfo (aDict, "GPU Memory [frames]") << " ";
11456 else if (aFlag == "elapsedframe")
11458 theDI << searchInfo (aDict, "Elapsed Frame (average)") << " ";
11460 else if (aFlag == "cpuframe_average")
11462 theDI << searchInfo (aDict, "CPU Frame (average)") << " ";
11464 else if (aFlag == "cpupicking_average")
11466 theDI << searchInfo (aDict, "CPU Picking (average)") << " ";
11468 else if (aFlag == "cpuculling_average")
11470 theDI << searchInfo (aDict, "CPU Culling (average)") << " ";
11472 else if (aFlag == "cpudyn_average")
11474 theDI << searchInfo (aDict, "CPU Dynamics (average)") << " ";
11476 else if (aFlag == "cpuframe_max")
11478 theDI << searchInfo (aDict, "CPU Frame (max)") << " ";
11480 else if (aFlag == "cpupicking_max")
11482 theDI << searchInfo (aDict, "CPU Picking (max)") << " ";
11484 else if (aFlag == "cpuculling_max")
11486 theDI << searchInfo (aDict, "CPU Culling (max)") << " ";
11488 else if (aFlag == "cpudyn_max")
11490 theDI << searchInfo (aDict, "CPU Dynamics (max)") << " ";
11498 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
11500 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
11502 theDI << "Statistic info:\n" << aView->StatisticInformation();
11507 //=======================================================================
11508 //function : VProgressiveMode
11510 //=======================================================================
11511 #if defined(_WIN32)
11512 static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
11513 Standard_Integer /*theNbArgs*/,
11514 const char** /*theArgs*/)
11516 Handle(V3d_View) aView = ViewerTest::CurrentView();
11517 if (aView.IsNull())
11519 std::cerr << "Error: no active viewer!\n";
11523 std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
11529 Standard_Boolean toExit = Standard_False;
11532 while (PeekMessageW (&aMsg, NULL, 0, 0, PM_REMOVE))
11534 if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
11536 toExit = Standard_True;
11539 TranslateMessage (&aMsg);
11540 DispatchMessageW (&aMsg);
11553 //=======================================================================
11554 //function : VXRotate
11556 //=======================================================================
11557 static Standard_Integer VXRotate (Draw_Interpretor& di,
11558 Standard_Integer argc,
11559 const char ** argv)
11561 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
11562 if (aContext.IsNull())
11564 di << argv[0] << "ERROR : use 'vinit' command before \n";
11570 di << "ERROR : Usage : " << argv[0] << " name angle\n";
11574 TCollection_AsciiString aName (argv[1]);
11575 Standard_Real anAngle = Draw::Atof (argv[2]);
11578 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
11579 Handle(AIS_InteractiveObject) anIObj;
11580 if (!aMap.Find2 (aName, anIObj))
11582 di << "Use 'vdisplay' before\n";
11586 gp_Trsf aTransform;
11587 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
11588 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
11590 aContext->SetLocation (anIObj, aTransform);
11591 aContext->UpdateCurrentViewer();
11595 //===============================================================================================
11596 //class : ViewerTest_AISManipulator
11597 //purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances
11598 //===============================================================================================
11599 DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
11601 class ViewerTest_AISManipulator : public AIS_Manipulator
11605 ViewerTest_AISManipulator() : AIS_Manipulator()
11607 GetMapOfAISManipulators().Add (this);
11610 virtual ~ViewerTest_AISManipulator()
11612 GetMapOfAISManipulators().Remove (this);
11615 DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
11618 IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
11619 IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
11621 //===============================================================================================
11622 //function : VManipulator
11624 //===============================================================================================
11625 static int VManipulator (Draw_Interpretor& theDi,
11626 Standard_Integer theArgsNb,
11627 const char** theArgVec)
11629 Handle(V3d_View) aView = ViewerTest::CurrentView();
11630 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
11631 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
11633 || aViewer.IsNull())
11635 std::cerr << "No active viewer!\n";
11639 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
11640 Standard_Integer anArgIter = 1;
11641 for (; anArgIter < theArgsNb; ++anArgIter)
11643 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
11646 ViewerTest_CmdParser aCmd;
11647 aCmd.AddDescription ("Manages manipulator for interactive objects:");
11648 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
11649 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
11650 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
11651 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
11652 aCmd.AddOption ("detach", "... - detach manipulator");
11654 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
11655 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
11656 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
11658 aCmd.AddOption ("move", "... x y z - move object");
11659 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
11660 aCmd.AddOption ("scale", "... factor - scale object");
11662 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
11663 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
11664 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
11665 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
11666 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
11667 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
11668 aCmd.AddOption ("size", "... size - set size of manipulator");
11669 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
11671 aCmd.Parse (theArgsNb, theArgVec);
11673 if (aCmd.HasOption ("help"))
11675 theDi.PrintHelp (theArgVec[0]);
11679 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
11681 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
11683 if (aName.IsEmpty())
11685 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
11689 // ----------------------------------
11690 // detach existing manipulator object
11691 // ----------------------------------
11693 if (aCmd.HasOption ("detach"))
11695 if (!aMapAIS.IsBound2 (aName))
11697 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
11701 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
11702 if (aManipulator.IsNull())
11704 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
11708 aManipulator->Detach();
11709 aMapAIS.UnBind2 (aName);
11710 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True);
11715 // -----------------------------------------------
11716 // find or create manipulator if it does not exist
11717 // -----------------------------------------------
11719 Handle(AIS_Manipulator) aManipulator;
11720 if (!aMapAIS.IsBound2 (aName))
11722 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
11724 aManipulator = new ViewerTest_AISManipulator();
11725 aMapAIS.Bind (aManipulator, aName);
11729 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
11730 if (aManipulator.IsNull())
11732 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
11737 // -----------------------------------------
11738 // change properties of manipulator instance
11739 // -----------------------------------------
11741 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
11743 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
11745 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
11747 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
11749 if (aCmd.HasOption ("followRotation", 1, Standard_True))
11751 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
11753 if (aCmd.HasOption ("gap", 1, Standard_True))
11755 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
11757 if (aCmd.HasOption ("part", 3, Standard_True))
11759 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
11760 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
11761 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
11762 if (aMode < 1 || aMode > 3)
11764 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 3].\n";
11768 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
11770 if (aCmd.HasOption ("pos", 3, Standard_True))
11772 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
11773 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
11774 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
11776 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
11778 if (aCmd.HasOption ("size", 1, Standard_True))
11780 aManipulator->SetSize (aCmd.ArgFloat ("size"));
11782 if (aCmd.HasOption ("zoomable", 1, Standard_True))
11784 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
11786 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
11788 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
11789 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
11793 // ---------------------------------------------------
11794 // attach, detach or access manipulator from an object
11795 // ---------------------------------------------------
11797 if (aCmd.HasOption ("attach"))
11799 // Find an object and attach manipulator to it
11800 if (!aCmd.HasOption ("attach", 1, Standard_True))
11805 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
11806 Handle(AIS_InteractiveObject) anObject;
11807 if (!aMapAIS.Find2 (anObjName, anObject))
11809 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
11813 for (ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators()); anIt.More(); anIt.Next())
11815 if (anIt.Value()->IsAttached()
11816 && anIt.Value()->Object() == anObject)
11818 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
11823 AIS_Manipulator::OptionsForAttach anOptions;
11824 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
11826 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
11828 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
11830 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
11832 if (aCmd.HasOption ("enableModes", 1, Standard_True))
11834 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
11837 aManipulator->Attach (anObject, anOptions);
11840 // --------------------------------------
11841 // apply transformation using manipulator
11842 // --------------------------------------
11844 if (aCmd.HasOption ("startTransform", 2, Standard_True))
11846 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
11848 if (aCmd.HasOption ("transform", 2, Standard_True))
11850 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
11852 if (aCmd.HasOption ("stopTransform"))
11854 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
11856 aManipulator->StopTransform (toApply);
11860 if (aCmd.HasOption ("move", 3, Standard_True))
11862 aT.SetTranslationPart (aCmd.ArgVec ("move"));
11864 if (aCmd.HasOption ("rotate", 7, Standard_True))
11866 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
11868 if (aCmd.HasOption ("scale", 1))
11870 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
11873 if (aT.Form() != gp_Identity)
11875 aManipulator->Transform (aT);
11878 ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True);
11883 //===============================================================================================
11884 //function : VSelectionProperties
11886 //===============================================================================================
11887 static int VSelectionProperties (Draw_Interpretor& theDi,
11888 Standard_Integer theArgsNb,
11889 const char** theArgVec)
11891 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
11894 std::cerr << "No active viewer!\n";
11898 if (TCollection_AsciiString (theArgVec[0]) == "vhighlightselected")
11900 // handle obsolete alias
11901 bool toEnable = true;
11904 theDi << (aCtx->ToHilightSelected() ? "on" : "off");
11907 else if (theArgsNb != 2
11908 || !ViewerTest::ParseOnOff (theArgVec[1], toEnable))
11910 std::cout << "Syntax error: wrong number of parameters.";
11913 if (toEnable != aCtx->ToHilightSelected())
11915 aCtx->ClearDetected();
11916 aCtx->SetToHilightSelected (toEnable);
11921 Standard_Boolean toPrint = theArgsNb == 1;
11922 Standard_Boolean toRedraw = Standard_False;
11923 Standard_Integer anArgIter = 1;
11924 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
11925 if (anArgIter < theArgsNb)
11927 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
11928 anArgFirst.LowerCase();
11930 if (anArgFirst == "dynhighlight"
11931 || anArgFirst == "dynhilight"
11932 || anArgFirst == "dynamichighlight"
11933 || anArgFirst == "dynamichilight")
11935 aType = Prs3d_TypeOfHighlight_Dynamic;
11937 else if (anArgFirst == "localdynhighlight"
11938 || anArgFirst == "localdynhilight"
11939 || anArgFirst == "localdynamichighlight"
11940 || anArgFirst == "localdynamichilight")
11942 aType = Prs3d_TypeOfHighlight_LocalDynamic;
11944 else if (anArgFirst == "selhighlight"
11945 || anArgFirst == "selhilight"
11946 || anArgFirst == "selectedhighlight"
11947 || anArgFirst == "selectedhilight")
11949 aType = Prs3d_TypeOfHighlight_Selected;
11951 else if (anArgFirst == "localselhighlight"
11952 || anArgFirst == "localselhilight"
11953 || anArgFirst == "localselectedhighlight"
11954 || anArgFirst == "localselectedhilight")
11956 aType = Prs3d_TypeOfHighlight_LocalSelected;
11963 for (; anArgIter < theArgsNb; ++anArgIter)
11965 TCollection_AsciiString anArg (theArgVec[anArgIter]);
11967 if (anArg == "-help")
11969 theDi.PrintHelp (theArgVec[0]);
11972 else if (anArg == "-print")
11974 toPrint = Standard_True;
11976 else if (anArg == "-autoactivate")
11978 Standard_Boolean toEnable = Standard_True;
11979 if (anArgIter + 1 < theArgsNb
11980 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
11984 aCtx->SetAutoActivateSelection (toEnable);
11986 else if (anArg == "-automatichighlight"
11987 || anArg == "-automatichilight"
11988 || anArg == "-autohighlight"
11989 || anArg == "-autohilight")
11991 Standard_Boolean toEnable = Standard_True;
11992 if (anArgIter + 1 < theArgsNb
11993 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
11997 aCtx->ClearSelected (false);
11998 aCtx->ClearDetected();
11999 aCtx->SetAutomaticHilight (toEnable);
12002 else if (anArg == "-highlightselected"
12003 || anArg == "-hilightselected")
12005 Standard_Boolean toEnable = Standard_True;
12006 if (anArgIter + 1 < theArgsNb
12007 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
12011 aCtx->ClearDetected();
12012 aCtx->SetToHilightSelected (toEnable);
12015 else if (anArg == "-pickstrategy"
12016 || anArg == "-pickingstrategy")
12018 if (++anArgIter >= theArgsNb)
12020 std::cout << "Syntax error: type of highlighting is undefined\n";
12024 SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
12025 TCollection_AsciiString aVal (theArgVec[anArgIter]);
12027 if (aVal == "first"
12028 || aVal == "firstaccepted"
12029 || aVal == "firstacceptable")
12031 aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
12033 else if (aVal == "topmost"
12034 || aVal == "onlyTopmost")
12036 aStrategy = SelectMgr_PickingStrategy_OnlyTopmost;
12040 std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n";
12044 aCtx->SetPickingStrategy (aStrategy);
12046 else if (anArg == "-pixtol"
12047 && anArgIter + 1 < theArgsNb)
12049 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
12051 else if ((anArg == "-mode"
12052 || anArg == "-dispmode")
12053 && anArgIter + 1 < theArgsNb)
12055 if (aType == Prs3d_TypeOfHighlight_None)
12057 std::cout << "Syntax error: type of highlighting is undefined\n";
12061 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
12062 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12063 aStyle->SetDisplayMode (aDispMode);
12064 toRedraw = Standard_True;
12066 else if (anArg == "-layer"
12067 && anArgIter + 1 < theArgsNb)
12069 if (aType == Prs3d_TypeOfHighlight_None)
12071 std::cout << "Syntax error: type of highlighting is undefined\n";
12075 const Standard_Integer aNewLayer = Draw::Atoi (theArgVec[++anArgIter]);
12076 if (aNewLayer != Graphic3d_ZLayerId_UNKNOWN)
12078 TColStd_SequenceOfInteger aLayers;
12079 aCtx->CurrentViewer()->GetAllZLayers (aLayers);
12080 if (std::find (aLayers.begin(), aLayers.end(), aNewLayer) == aLayers.end())
12082 std::cout << "Syntax error: Layer " << aNewLayer << " is undefined\n";
12087 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12088 aStyle->SetZLayer (aNewLayer);
12089 toRedraw = Standard_True;
12091 else if (anArg == "-hicolor"
12092 || anArg == "-selcolor"
12093 || anArg == "-color")
12095 if (anArg.StartsWith ("-hi"))
12097 aType = Prs3d_TypeOfHighlight_Dynamic;
12099 else if (anArg.StartsWith ("-sel"))
12101 aType = Prs3d_TypeOfHighlight_Selected;
12103 else if (aType == Prs3d_TypeOfHighlight_None)
12105 std::cout << "Syntax error: type of highlighting is undefined\n";
12109 Quantity_Color aColor;
12110 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1,
12111 theArgVec + anArgIter + 1,
12113 if (aNbParsed == 0)
12115 std::cout << "Syntax error: need more arguments.\n";
12118 anArgIter += aNbParsed;
12120 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12121 aStyle->SetColor (aColor);
12122 toRedraw = Standard_True;
12124 else if ((anArg == "-transp"
12125 || anArg == "-transparency"
12126 || anArg == "-hitransp"
12127 || anArg == "-seltransp"
12128 || anArg == "-hitransplocal"
12129 || anArg == "-seltransplocal")
12130 && anArgIter + 1 < theArgsNb)
12132 if (anArg.StartsWith ("-hi"))
12134 aType = Prs3d_TypeOfHighlight_Dynamic;
12136 else if (anArg.StartsWith ("-sel"))
12138 aType = Prs3d_TypeOfHighlight_Selected;
12140 else if (aType == Prs3d_TypeOfHighlight_None)
12142 std::cout << "Syntax error: type of highlighting is undefined\n";
12146 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
12147 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12148 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
12149 toRedraw = Standard_True;
12151 else if ((anArg == "-mat"
12152 || anArg == "-material")
12153 && anArgIter + 1 < theArgsNb)
12155 if (aType == Prs3d_TypeOfHighlight_None)
12157 std::cout << "Syntax error: type of highlighting is undefined\n";
12161 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12162 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
12163 if (aMatName != Graphic3d_NOM_DEFAULT)
12166 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
12167 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
12168 Graphic3d_MaterialAspect aMat (aMatName);
12169 aMat.SetColor (aStyle->Color());
12170 aMat.SetTransparency (aStyle->Transparency());
12171 anAspect->SetFrontMaterial (aMat);
12172 anAspect->SetInteriorColor (aStyle->Color());
12173 aStyle->SetBasicFillAreaAspect (anAspect);
12177 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
12179 toRedraw = Standard_True;
12183 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
12189 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
12190 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
12191 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
12192 theDi << "Auto-highlight : " << (aCtx->AutomaticHilight() ? "On" : "Off") << "\n";
12193 theDi << "Highlight selected : " << (aCtx->ToHilightSelected() ? "On" : "Off") << "\n";
12194 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
12195 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
12196 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
12197 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
12198 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
12199 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
12200 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
12201 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
12202 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
12205 if (aCtx->NbSelected() != 0 && toRedraw)
12207 aCtx->HilightSelected (Standard_True);
12213 //===============================================================================================
12214 //function : VDumpSelectionImage
12216 //===============================================================================================
12217 static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
12218 Standard_Integer theArgsNb,
12219 const char** theArgVec)
12223 std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
12227 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
12228 if (aContext.IsNull())
12230 std::cout << "Error: no active view.\n";
12234 TCollection_AsciiString aFile;
12235 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
12236 Image_Format anImgFormat = Image_Format_BGR;
12237 Standard_Integer aPickedIndex = 1;
12238 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
12240 TCollection_AsciiString aParam (theArgVec[anArgIter]);
12241 aParam.LowerCase();
12242 if (aParam == "-type")
12244 if (++anArgIter >= theArgsNb)
12246 std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n";
12250 TCollection_AsciiString aValue (theArgVec[anArgIter]);
12251 aValue.LowerCase();
12252 if (aValue == "depth"
12253 || aValue == "normdepth"
12254 || aValue == "normalizeddepth")
12256 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
12257 anImgFormat = Image_Format_GrayF;
12259 if (aValue == "depthinverted"
12260 || aValue == "normdepthinverted"
12261 || aValue == "normalizeddepthinverted"
12262 || aValue == "inverted")
12264 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
12265 anImgFormat = Image_Format_GrayF;
12267 else if (aValue == "unnormdepth"
12268 || aValue == "unnormalizeddepth")
12270 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
12271 anImgFormat = Image_Format_GrayF;
12273 else if (aValue == "objectcolor"
12274 || aValue == "object"
12275 || aValue == "color")
12277 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
12279 else if (aValue == "entitycolor"
12280 || aValue == "entity")
12282 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
12284 else if (aValue == "ownercolor"
12285 || aValue == "owner")
12287 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
12289 else if (aValue == "selectionmodecolor"
12290 || aValue == "selectionmode"
12291 || aValue == "selmodecolor"
12292 || aValue == "selmode")
12294 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
12297 else if (aParam == "-picked"
12298 || aParam == "-pickeddepth"
12299 || aParam == "-pickedindex")
12301 if (++anArgIter >= theArgsNb)
12303 std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n";
12307 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
12309 else if (aFile.IsEmpty())
12311 aFile = theArgVec[anArgIter];
12315 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n";
12319 if (aFile.IsEmpty())
12321 std::cout << "Syntax error: image file name is missing.\n";
12325 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
12326 Standard_Integer aWidth = 0, aHeight = 0;
12327 aView->Window()->Size (aWidth, aHeight);
12329 Image_AlienPixMap aPixMap;
12330 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
12332 std::cout << "Error: can't allocate image.\n";
12335 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
12337 std::cout << "Error: can't generate selection image.\n";
12340 if (!aPixMap.Save (aFile))
12342 std::cout << "Error: can't save selection image.\n";
12348 //=======================================================================
12349 //function : ViewerCommands
12351 //=======================================================================
12353 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
12356 const char *group = "ZeViewer";
12357 theCommands.Add("vinit",
12358 "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]"
12359 "\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]"
12360 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
12361 "\n\t\t: [-display displayName]"
12363 "\n\t\t: Creates new View window with specified name viewName."
12364 "\n\t\t: By default the new view is created in the viewer and in"
12365 "\n\t\t: graphic driver shared with active view."
12366 "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}"
12367 "\n\t\t: If driverName isn't specified the driver will be shared with active view."
12368 "\n\t\t: If viewerName isn't specified the viewer will be shared with active view."
12369 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
12370 "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]"
12371 "\n\t\t: Display name will be used within creation of graphic driver, when specified."
12373 "\n\t\t: -left, -top pixel position of left top corner of the window."
12374 "\n\t\t: -width, -height width and heigth of window respectively."
12375 "\n\t\t: -cloneActive floag to copy camera and dimensions of active view."
12376 "\n\t\t: -exitOnClose when specified, closing the view will exit application."
12377 "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape."
12378 "\n\t\t: -2d_mode when on, view will not react on rotate scene events"
12379 "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.",
12380 __FILE__,VInit,group);
12381 theCommands.Add("vclose" ,
12382 "[view_id [keep_context=0|1]]\n"
12383 "or vclose ALL - to remove all created views\n"
12384 " - removes view(viewer window) defined by its view_id.\n"
12385 " - keep_context: by default 0; if 1 and the last view is deleted"
12386 " the current context is not removed.",
12387 __FILE__,VClose,group);
12388 theCommands.Add("vactivate" ,
12389 "vactivate view_id [-noUpdate]"
12390 " - activates view(viewer window) defined by its view_id",
12391 __FILE__,VActivate,group);
12392 theCommands.Add("vviewlist",
12393 "vviewlist [format={tree, long}]"
12394 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
12395 " - format: format of result output, if tree the output is a tree view;"
12396 "otherwise it's a list of full view names. By default format = tree",
12397 __FILE__,VViewList,group);
12398 theCommands.Add("vhelp" ,
12399 "vhelp : display help on the viewer commands",
12400 __FILE__,VHelp,group);
12401 theCommands.Add("vtop" ,
12402 "vtop or <T> : Top view. Orientation +X+Y" ,
12403 __FILE__,VTop,group);
12404 theCommands.Add("vbottom" ,
12405 "vbottom : Bottom view. Orientation +X-Y" ,
12406 __FILE__,VBottom,group);
12407 theCommands.Add("vleft" ,
12408 "vleft : Left view. Orientation -Y+Z" ,
12409 __FILE__,VLeft,group);
12410 theCommands.Add("vright" ,
12411 "vright : Right view. Orientation +Y+Z" ,
12412 __FILE__,VRight,group);
12413 theCommands.Add("vaxo" ,
12414 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
12415 __FILE__,VAxo,group);
12416 theCommands.Add("vfront" ,
12417 "vfront : Front view. Orientation +X+Z" ,
12418 __FILE__,VFront,group);
12419 theCommands.Add("vback" ,
12420 "vback : Back view. Orientation -X+Z" ,
12421 __FILE__,VBack,group);
12422 theCommands.Add("vpick" ,
12423 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
12425 theCommands.Add("vfit",
12426 "vfit or <F> [-selected] [-noupdate]"
12427 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
12428 __FILE__,VFit,group);
12429 theCommands.Add ("vfitarea",
12430 "vfitarea x1 y1 x2 y2"
12431 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
12432 "\n\t\t: Fit view to show area located between two points"
12433 "\n\t\t: given in world 2D or 3D corrdinates.",
12434 __FILE__, VFitArea, group);
12435 theCommands.Add ("vzfit", "vzfit [scale]\n"
12436 " Matches Z near, Z far view volume planes to the displayed objects.\n"
12437 " \"scale\" - specifies factor to scale computed z range.\n",
12438 __FILE__, VZFit, group);
12439 theCommands.Add("vrepaint",
12440 "vrepaint [-immediate]"
12441 "\n\t\t: force redraw",
12442 __FILE__,VRepaint,group);
12443 theCommands.Add("vclear",
12445 "\n\t\t: remove all the object from the viewer",
12446 __FILE__,VClear,group);
12447 theCommands.Add("vsetbg",
12448 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
12449 __FILE__,VSetBg,group);
12450 theCommands.Add("vsetbgmode",
12451 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
12452 __FILE__,VSetBgMode,group);
12453 theCommands.Add("vsetgradientbg",
12454 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
12455 __FILE__,VSetGradientBg,group);
12456 theCommands.Add("vsetgrbgmode",
12457 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
12458 __FILE__,VSetGradientBgMode,group);
12459 theCommands.Add("vsetcolorbg",
12460 "vsetcolorbg : vsetcolorbg r g b : Set background color",
12461 __FILE__,VSetColorBg,group);
12462 theCommands.Add("vsetdefaultbg",
12463 "vsetdefaultbg r g b\n"
12464 "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode"
12465 "\n\t\t: Set default viewer background fill color (flat/gradient).",
12466 __FILE__,VSetDefaultBg,group);
12467 theCommands.Add("vscale",
12468 "vscale : vscale X Y Z",
12469 __FILE__,VScale,group);
12470 theCommands.Add("vzbufftrihedron",
12471 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
12472 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
12473 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
12474 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
12475 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
12476 "\n\t\t: Displays a trihedron",
12477 __FILE__,VZBuffTrihedron,group);
12478 theCommands.Add("vrotate",
12479 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
12480 "\n : Option -mouseStart starts rotation according to the mouse position"
12481 "\n : Option -mouseMove continues rotation with angle computed"
12482 "\n : from last and new mouse position."
12483 "\n : vrotate AX AY AZ [X Y Z]",
12484 __FILE__,VRotate,group);
12485 theCommands.Add("vzoom",
12486 "vzoom : vzoom coef",
12487 __FILE__,VZoom,group);
12488 theCommands.Add("vpan",
12489 "vpan : vpan dx dy",
12490 __FILE__,VPan,group);
12491 theCommands.Add("vcolorscale",
12492 "vcolorscale name [-noupdate|-update] [-demo]"
12493 "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
12494 "\n\t\t: [-font HeightFont=20]"
12495 "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
12496 "\n\t\t: [-smoothTransition {on|off}=off]"
12497 "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
12498 "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
12499 "\n\t\t: [-textpos {left|right|center|none}=right]"
12500 "\n\t\t: [-labelAtBorder {on|off}=on]"
12501 "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
12502 "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
12503 "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
12504 "\n\t\t: [-xy Left=0 Bottom=0]"
12505 "\n\t\t: -demo - displays a color scale with demonstratio values"
12506 "\n\t\t: -colors - set colors for all intervals"
12507 "\n\t\t: -color - set color for specific interval"
12508 "\n\t\t: -textpos - horizontal label position relative to color scale bar"
12509 "\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
12510 "\n\t\t: at border means the value inbetween neighbor intervals,"
12511 "\n\t\t: at center means the center value within current interval"
12512 "\n\t\t: -labels - set labels for all intervals"
12513 "\n\t\t: -freeLabels - same as -labels but does not require"
12514 "\n\t\t: matching the number of intervals"
12515 "\n\t\t: -label - set label for specific interval"
12516 "\n\t\t: -title - set title"
12517 "\n\t\t: -reversed - setup smooth color transition between intervals"
12518 "\n\t\t: -smoothTransition - swap colorscale direction"
12519 "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values"
12520 __FILE__, VColorScale, group);
12521 theCommands.Add("vgraduatedtrihedron",
12522 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
12523 "\t[-namefont Name] [-valuesfont Name]\n"
12524 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
12525 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
12526 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
12527 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
12528 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
12529 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
12530 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
12531 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
12532 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
12533 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
12534 " - Displays or erases graduated trihedron"
12535 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
12536 " - namefont - font of axes names. Default: Arial\n"
12537 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
12538 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
12539 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
12540 " - valuesfont - font of axes values. Default: Arial\n"
12541 " - xcolor, ycolor, zcolor - color of axis and values\n"
12542 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
12543 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
12544 __FILE__,VGraduatedTrihedron,group);
12545 theCommands.Add("vtile" ,
12546 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
12547 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
12548 "\n\t\t: -totalSize the size of virtual bigger viewport"
12549 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
12550 "\n\t\t: -lowerLeft tile offset as lower left corner"
12551 "\n\t\t: -upperLeft tile offset as upper left corner",
12552 __FILE__, VTile, group);
12553 theCommands.Add("vzlayer",
12554 "vzlayer [layerId]"
12555 "\n\t\t: [-add|-delete|-get|-settings]"
12556 "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]"
12557 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
12558 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv}]"
12559 "\n\t\t: ZLayer list management:"
12560 "\n\t\t: -add add new z layer to viewer and print its id"
12561 "\n\t\t: -delete delete z layer"
12562 "\n\t\t: -get print sequence of z layers"
12563 "\n\t\t: -settings print status of z layer settings"
12564 "\n\t\t: -disable disables given setting"
12565 "\n\t\t: -enable enables given setting",
12566 __FILE__,VZLayer,group);
12567 theCommands.Add("vlayerline",
12568 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
12569 __FILE__,VLayerLine,group);
12570 theCommands.Add ("vgrid",
12571 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
12572 " : Mode - rectangular or circular"
12573 " : Type - lines or points",
12574 __FILE__, VGrid, group);
12575 theCommands.Add ("vpriviledgedplane",
12576 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
12577 "\n\t\t: Ox, Oy, Oz - plane origin"
12578 "\n\t\t: Nx, Ny, Nz - plane normal direction"
12579 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
12580 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
12581 __FILE__, VPriviledgedPlane, group);
12582 theCommands.Add ("vconvert",
12583 "vconvert v [Mode={window|view}]"
12584 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
12585 "\n\t\t: vconvert x y z [Mode={window|grid}]"
12586 "\n\t\t: window - convert to window coordinates, pixels"
12587 "\n\t\t: view - convert to view projection plane"
12588 "\n\t\t: grid - convert to model coordinates, given on grid"
12589 "\n\t\t: ray - convert projection ray to model coordiantes"
12590 "\n\t\t: - vconvert v window : convert view to window;"
12591 "\n\t\t: - vconvert v view : convert window to view;"
12592 "\n\t\t: - vconvert x y window : convert view to window;"
12593 "\n\t\t: - vconvert x y view : convert window to view;"
12594 "\n\t\t: - vconvert x y : convert window to model;"
12595 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
12596 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
12597 "\n\t\t: - vconvert x y z window : convert model to window;"
12598 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
12599 "\n\t\t: Converts the given coordinates to window/view/model space.",
12600 __FILE__, VConvert, group);
12601 theCommands.Add ("vfps",
12602 "vfps [framesNb=100] [-duration seconds] : estimate average frame rate for active view",
12603 __FILE__, VFps, group);
12604 theCommands.Add ("vgldebug",
12605 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
12606 "\n\t\t: [-glslCode {off|short|full}] [-extraMsg {0|1}] [{0|1}]"
12607 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
12608 "\n\t\t: Debug context can be requested only on Windows"
12609 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
12610 "\n\t\t: -sync - request synchronized debug GL context"
12611 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
12612 "\n\t\t: which are suppressed by default,"
12613 "\n\t\t: -glslCode - log GLSL program source code,"
12614 "\n\t\t: which are suppressed by default,"
12615 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
12616 "\n\t\t: which are suppressed by default",
12617 __FILE__, VGlDebug, group);
12618 theCommands.Add ("vvbo",
12619 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
12620 __FILE__, VVbo, group);
12621 theCommands.Add ("vstereo",
12622 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
12623 "\n\t\t: [-anaglyph Filter]"
12624 "\n\t\t: Control stereo output mode. Available modes for -mode:"
12625 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
12626 "\n\t\t: requires driver support."
12627 "\n\t\t: Should be called BEFORE vinit!"
12628 "\n\t\t: anaglyph - Anaglyph glasses"
12629 "\n\t\t: rowInterlaced - row-interlaced display"
12630 "\n\t\t: columnInterlaced - column-interlaced display"
12631 "\n\t\t: chessBoard - chess-board output"
12632 "\n\t\t: sideBySide - horizontal pair"
12633 "\n\t\t: overUnder - vertical pair"
12634 "\n\t\t: Available Anaglyph filters for -anaglyph:"
12635 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
12636 "\n\t\t: greenMagentaSimple",
12637 __FILE__, VStereo, group);
12638 theCommands.Add ("vcaps",
12639 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}] [-polygonMode {0|1}]"
12640 "\n\t\t: [-compatibleProfile {0|1}]"
12641 "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]"
12642 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
12643 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
12644 "\n\t\t: Modify particular graphic driver options:"
12645 "\n\t\t: FFP - use fixed-function pipeline instead of"
12646 "\n\t\t: built-in GLSL programs"
12647 "\n\t\t: (requires compatible profile)"
12648 "\n\t\t: polygonMode - use Polygon Mode instead of built-in GLSL programs"
12649 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
12650 "\n\t\t: arrays to GPU memory)"
12651 "\n\t\t: sprite - use textured sprites instead of bitmaps"
12652 "\n\t\t: vsync - switch VSync on or off"
12653 "\n\t\t: winBuffer - allow using window buffer for rendering"
12654 "\n\t\t: Context creation options:"
12655 "\n\t\t: softMode - software OpenGL implementation"
12656 "\n\t\t: compatibleProfile - backward-compatible profile"
12657 "\n\t\t: quadbuffer - QuadBuffer"
12658 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
12659 "\n\t\t: rendering paths producing the same visual result when"
12660 "\n\t\t: possible."
12661 "\n\t\t: Command is intended for testing old hardware compatibility.",
12662 __FILE__, VCaps, group);
12663 theCommands.Add ("vmemgpu",
12664 "vmemgpu [f]: print system-dependent GPU memory information if available;"
12665 " with f option returns free memory in bytes",
12666 __FILE__, VMemGpu, group);
12667 theCommands.Add ("vreadpixel",
12668 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
12669 " : Read pixel value for active view",
12670 __FILE__, VReadPixel, group);
12671 theCommands.Add("diffimage",
12672 "diffimage imageFile1 imageFile2 [diffImageFile]"
12673 "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]"
12674 "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]"
12675 "\n\t\t: Compare two images by content and generate difference image."
12676 "\n\t\t: When -exitOnClose is specified, closing the view will exit application."
12677 "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.",
12678 __FILE__, VDiffImage, group);
12679 theCommands.Add ("vselect",
12680 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
12681 "- emulates different types of selection:\n"
12682 "- 1) single click selection\n"
12683 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
12684 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
12685 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
12686 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
12687 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
12688 " (partial inclusion - overlap - is not allowed by default)\n"
12689 "- 5) any of these selections with shift button pressed",
12690 __FILE__, VSelect, group);
12691 theCommands.Add ("vmoveto",
12692 "vmoveto [x y] [-reset]"
12693 "\n\t\t: Emulates cursor movement to pixel position (x,y)."
12694 "\n\t\t: -reset resets current highlighting",
12695 __FILE__, VMoveTo, group);
12696 theCommands.Add ("vviewparams",
12697 "vviewparams [-args] [-scale [s]]"
12698 "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]"
12699 "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]"
12700 "\n\t\t: Manage current view parameters or prints all"
12701 "\n\t\t: current values when called without argument."
12702 "\n\t\t: -scale [s] prints or sets viewport relative scale"
12703 "\n\t\t: -eye [x y z] prints or sets eye location"
12704 "\n\t\t: -at [x y z] prints or sets center of look"
12705 "\n\t\t: -up [x y z] prints or sets direction of up vector"
12706 "\n\t\t: -proj [x y z] prints or sets direction of look"
12707 "\n\t\t: -center x y sets location of center of the screen in pixels"
12708 "\n\t\t: -size [sx] prints viewport projection width and height sizes"
12709 "\n\t\t: or changes the size of its maximum dimension"
12710 "\n\t\t: -args prints vviewparams arguments for restoring current view",
12711 __FILE__, VViewParams, group);
12713 theCommands.Add("v2dmode",
12714 "v2dmode [-name viewName] [-mode {-on|-off}=-on]"
12715 "\n\t\t: name - name of existing view, if not defined, the active view is changed"
12716 "\n\t\t: mode - switches On/Off rotation mode"
12717 "\n\t\t: Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:"
12718 "\n\t\t: - rotation of the view by 3rd mouse button with Ctrl active"
12719 "\n\t\t: - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right"
12720 "\n\t\t: View camera position might be changed only by commands.",
12721 __FILE__, V2DMode, group);
12723 theCommands.Add("vanimation", "Alias for vanim",
12724 __FILE__, VAnimation, group);
12726 theCommands.Add("vanim",
12727 "List existing animations:"
12729 "\n\t\t: Animation playback:"
12730 "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]"
12731 "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]"
12732 "\n\t\t: -speed playback speed (1.0 is normal speed)"
12733 "\n\t\t: -freeLook skip camera animations"
12734 "\n\t\t: -lockLoop disable any interactions"
12736 "\n\t\t: Animation definition:"
12737 "\n\t\t: vanim Name/sub/name [-clear] [-delete]"
12738 "\n\t\t: [start TimeSec] [duration TimeSec]"
12740 "\n\t\t: Animation name defined in path-style (anim/name or anim.name)"
12741 "\n\t\t: specifies nested animations."
12742 "\n\t\t: There is no syntax to explicitly add new animation,"
12743 "\n\t\t: and all non-existing animations within the name will be"
12744 "\n\t\t: implicitly created on first use (including parents)."
12746 "\n\t\t: Each animation might define the SINGLE action (see below),"
12747 "\n\t\t: like camera transition, object transformation or custom callback."
12748 "\n\t\t: Child animations can be used for defining concurrent actions."
12750 "\n\t\t: Camera animation:"
12751 "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]"
12752 "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]"
12753 "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]"
12754 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
12755 "\n\t\t: -eyeX camera Eye positions pair (start and end)"
12756 "\n\t\t: -atX camera Center positions pair"
12757 "\n\t\t: -upX camera Up directions pair"
12758 "\n\t\t: -scaleX camera Scale factors pair"
12759 "\n\t\t: Object animation:"
12760 "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]"
12761 "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]"
12762 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
12763 "\n\t\t: -locX object Location points pair (translation)"
12764 "\n\t\t: -rotX object Orientations pair (quaternions)"
12765 "\n\t\t: -scaleX object Scale factors pair (quaternions)"
12766 "\n\t\t: Custom callback:"
12767 "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\""
12768 "\n\t\t: %Pts overall animation presentation timestamp"
12769 "\n\t\t: %LocalPts local animation timestamp"
12770 "\n\t\t: %Normalized local animation normalized value in range 0..1"
12772 "\n\t\t: Video recording:"
12773 "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]"
12774 "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]"
12775 "\n\t\t: [-crf Value] [-preset Preset]"
12776 "\n\t\t: -fps video framerate"
12777 "\n\t\t: -format file format, container (matroska, etc.)"
12778 "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)"
12779 "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)"
12780 "\n\t\t: -crf constant rate factor (specific to codec)"
12781 "\n\t\t: -preset codec parameters preset (specific to codec)"
12782 __FILE__, VAnimation, group);
12784 theCommands.Add("vchangeselected",
12785 "vchangeselected shape"
12786 "- adds to shape to selection or remove one from it",
12787 __FILE__, VChangeSelected, group);
12788 theCommands.Add ("vnbselected",
12790 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
12791 theCommands.Add ("vcamera",
12792 "vcamera [PrsName] [-ortho] [-projtype]"
12794 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
12795 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
12796 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
12797 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
12798 "\n\t\t: Manages camera parameters."
12799 "\n\t\t: Displays frustum when presntation name PrsName is specified."
12800 "\n\t\t: Prints current value when option called without argument."
12801 "\n\t\t: Orthographic camera:"
12802 "\n\t\t: -ortho activate orthographic projection"
12803 "\n\t\t: Perspective camera:"
12804 "\n\t\t: -persp activate perspective projection (mono)"
12805 "\n\t\t: -fovy field of view in y axis, in degrees"
12806 "\n\t\t: -distance distance of eye from camera center"
12807 "\n\t\t: Stereoscopic camera:"
12808 "\n\t\t: -stereo perspective projection (stereo)"
12809 "\n\t\t: -leftEye perspective projection (left eye)"
12810 "\n\t\t: -rightEye perspective projection (right eye)"
12811 "\n\t\t: -iod intraocular distance value"
12812 "\n\t\t: -iodType distance type, absolute or relative"
12813 "\n\t\t: -zfocus stereographic focus value"
12814 "\n\t\t: -zfocusType focus type, absolute or relative",
12815 __FILE__, VCamera, group);
12816 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
12817 "- vautozfit [on={1|0}] [scale]\n"
12818 " Prints or changes parameters of automatic z-fit mode:\n"
12819 " \"on\" - turns automatic z-fit on or off\n"
12820 " \"scale\" - specifies factor to scale computed z range.\n",
12821 __FILE__, VAutoZFit, group);
12822 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
12823 " vzrange - without parameters shows current values\n"
12824 " vzrange [znear] [zfar] - applies provided values to view",
12825 __FILE__,VZRange, group);
12826 theCommands.Add ("vpurgedisplay",
12828 "- removes structures which don't belong to objects displayed in neutral point",
12829 __FILE__, VPurgeDisplay, group);
12830 theCommands.Add("vsetviewsize",
12831 "vsetviewsize size",
12832 __FILE__,VSetViewSize,group);
12833 theCommands.Add("vmoveview",
12834 "vmoveview Dx Dy Dz [Start = 1|0]",
12835 __FILE__,VMoveView,group);
12836 theCommands.Add("vtranslateview",
12837 "vtranslateview Dx Dy Dz [Start = 1|0)]",
12838 __FILE__,VTranslateView,group);
12839 theCommands.Add("vturnview",
12840 "vturnview Ax Ay Az [Start = 1|0]",
12841 __FILE__,VTurnView,group);
12842 theCommands.Add("vtextureenv",
12843 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
12844 "or user-defined file and optionally applying texture mapping parameters\n"
12846 " vtextureenv off - disables environment mapping\n"
12847 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
12848 " std_texture = (0..7)\n"
12849 " rep = {clamp|repeat}\n"
12850 " mod = {decal|modulate}\n"
12851 " flt = {nearest|bilinear|trilinear}\n"
12852 " ss, st - scale factors for s and t texture coordinates\n"
12853 " ts, tt - translation for s and t texture coordinates\n"
12854 " rot - texture rotation angle in degrees",
12855 __FILE__, VTextureEnv, group);
12856 theCommands.Add("vhlr",
12857 "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
12858 "\n\t\t: Hidden Line Removal algorithm."
12859 "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones"
12860 "\n\t\t: -algoType type of HLR algorithm.\n",
12861 __FILE__,VHLR,group);
12862 theCommands.Add("vhlrtype",
12863 "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
12864 "\n\t\t: Changes the type of HLR algorithm using for shapes:"
12865 "\n\t\t: 'algo' - exact HLR algorithm is applied"
12866 "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied"
12867 "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
12868 __FILE__,VHLRType,group);
12869 theCommands.Add("vclipplane",
12870 "vclipplane planeName [{0|1}]"
12871 "\n\t\t: [-equation1 A B C D]"
12872 "\n\t\t: [-equation2 A B C D]"
12873 "\n\t\t: [-boxInterior MinX MinY MinZ MaxX MaxY MaxZ]"
12874 "\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]"
12875 "\n\t\t: [-maxPlanes]"
12876 "\n\t\t: [-capping {0|1}]"
12877 "\n\t\t: [-color R G B] [-transparency Value] [-hatch {on|off|ID}]"
12878 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
12879 "\n\t\t: [-texRotate Angle]"
12880 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
12881 "\n\t\t: [-useObjShader {0|1}]"
12882 "\n\t\t: Clipping planes management:"
12883 "\n\t\t: -maxPlanes print plane limit for view"
12884 "\n\t\t: -delete delete plane with given name"
12885 "\n\t\t: {off|on|0|1} turn clipping on/off"
12886 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
12887 "\n\t\t: applied to active View when list is omitted"
12888 "\n\t\t: -equation A B C D change plane equation"
12889 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
12890 "\n\t\t: Capping options:"
12891 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
12892 "\n\t\t: -color R G B set capping color"
12893 "\n\t\t: -transparency Value set capping transparency 0..1"
12894 "\n\t\t: -texName Texture set capping texture"
12895 "\n\t\t: -texScale SX SY set capping tex scale"
12896 "\n\t\t: -texOrigin TX TY set capping tex origin"
12897 "\n\t\t: -texRotate Angle set capping tex rotation"
12898 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
12899 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
12900 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
12901 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
12902 __FILE__, VClipPlane, group);
12903 theCommands.Add("vdefaults",
12904 "vdefaults [-absDefl value]"
12905 "\n\t\t: [-devCoeff value]"
12906 "\n\t\t: [-angDefl value]"
12907 "\n\t\t: [-autoTriang {off/on | 0/1}]"
12908 , __FILE__, VDefaults, group);
12909 theCommands.Add("vlight",
12910 "tool to manage light sources, without arguments shows list of lights."
12911 "\n Main commands: "
12912 "\n '-clear' to clear lights"
12913 "\n '-{def}aults' to load deafault lights"
12914 "\n '-add' <type> to add any light source"
12915 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
12916 "\n 'change' <lightId> to edit light source with specified lightId"
12917 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
12919 "\n -{pos}ition X Y Z"
12920 "\n -{dir}ection X Y Z (for directional light or for spotlight)"
12921 "\n -color colorName"
12922 "\n -{head}light 0|1"
12923 "\n -{sm}oothness value"
12924 "\n -{int}ensity value"
12925 "\n -{constAtten}uation value"
12926 "\n -{linearAtten}uation value"
12927 "\n -angle angleDeg"
12928 "\n -{spotexp}onent value"
12929 "\n -local|-global"
12930 "\n\n example: vlight -add positional -head 1 -pos 0 1 1 -color red"
12931 "\n example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2",
12932 __FILE__, VLight, group);
12933 theCommands.Add("vraytrace",
12935 "\n\t\t: Turns on/off ray-tracing renderer."
12936 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
12937 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
12938 __FILE__, VRenderParams, group);
12939 theCommands.Add("vrenderparams",
12940 "\n Manages rendering parameters: "
12941 "\n '-raster' Disables GPU ray-tracing"
12942 "\n '-msaa 0..4' Specifies number of samples for MSAA"
12943 "\n '-lineFeather > 0' Sets line feather factor"
12944 "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor"
12945 "\n '-depthPrePass on|off' Enables/disables depth pre-pass"
12946 "\n '-alphatocoverage on|off' Enables/disables alpha to coverage (needs MSAA)"
12947 "\n '-rendScale value Rendering resolution scale factor"
12948 "\n '-rayTrace' Enables GPU ray-tracing"
12949 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
12950 "\n '-shadows on|off' Enables/disables shadows rendering"
12951 "\n '-reflections on|off' Enables/disables specular reflections"
12952 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
12953 "\n '-gleam on|off' Enables/disables transparency shadow effects"
12954 "\n '-gi on|off' Enables/disables global illumination effects"
12955 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
12956 "\n '-env on|off' Enables/disables environment map background"
12957 "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
12958 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
12959 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
12960 "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)"
12961 "\n '-tileSize 1..4096' Specifies size of screen tiles in ISS mode (32 by default)"
12962 "\n '-nbtiles 64..1024' Specifies number of screen tiles per Redraw in ISS mode (256 by default)"
12963 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
12964 "\n '-shadingModel model' Controls shading model from enumeration"
12965 "\n color, flat, gouraud, phong"
12966 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
12967 "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)"
12968 "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect"
12969 "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)"
12970 "\n '-whitepoint value' White point value for filmic tone mapping"
12971 "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)"
12972 "\n '-perfCounters none|fps|cpu|layers|structures|groups|arrays|triagles|points"
12973 "\n ' |gpuMem|frameTime|basic|extended|full|nofps|skipImmediate'"
12974 "\n Show/hide performance counters (flags can be combined)"
12975 "\n '-perfUpdateInterval nbSeconds' Performance counters update interval"
12976 "\n '-perfChart nbFrames' Show frame timers chart limited by specified number of frames"
12977 "\n '-perfChartMax seconds' Maximum time in seconds with the chart"
12978 "\n '-frustumCulling on|off|noupdate' Enable/disable objects frustum clipping or"
12979 "\n set state to check structures culled previously."
12980 "\n Unlike vcaps, these parameters dramatically change visual properties."
12981 "\n Command is intended to control presentation quality depending on"
12982 "\n hardware capabilities and performance.",
12983 __FILE__, VRenderParams, group);
12984 theCommands.Add("vstatprofiler",
12985 "\n vstatprofiler [fps|cpu|allLayers|layers|allstructures|structures|groups"
12986 "\n |allArrays|fillArrays|lineArrays|pointArrays|textArrays"
12987 "\n |triagles|points|geomMem|textureMem|frameMem"
12988 "\n |elapsedFrame|cpuFrameAverage|cpuPickingAverage|cpuCullingAverage|cpuDynAverage"
12989 "\n |cpuFrameMax|cpuPickingMax|cpuCullingMax|cpuDynMax]"
12991 "\n\t\t: Prints rendering statistics."
12992 "\n\t\t: If there are some parameters - print corresponding statistic counters values,"
12993 "\n\t\t: else - print all performance counters set previously."
12994 "\n\t\t: '-noredraw' Flag to avoid additional redraw call and use already collected values.\n",
12995 __FILE__, VStatProfiler, group);
12996 theCommands.Add ("vplace",
12998 "\n\t\t: Places the point (in pixels) at the center of the window",
12999 __FILE__, VPlace, group);
13000 theCommands.Add("vxrotate",
13002 __FILE__,VXRotate,group);
13004 theCommands.Add("vmanipulator",
13005 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
13006 "\n tool to create and manage AIS manipulators."
13008 "\n '-attach AISObject' attach manipulator to AISObject"
13009 "\n '-adjustPosition {0|1}' adjust position when attaching"
13010 "\n '-adjustSize {0|1}' adjust size when attaching"
13011 "\n '-enableModes {0|1}' enable modes when attaching"
13012 "\n '-detach' detach manipulator"
13013 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
13014 "\n '-transform mouse_x mouse_y' - invoke transformation"
13015 "\n '-stopTransform [abort]' - invoke stop of transformation"
13016 "\n '-move x y z' - move attached object"
13017 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
13018 "\n '-scale factor' - scale attached object"
13019 "\n '-autoActivate {0|1}' - set activation on detection"
13020 "\n '-followTranslation {0|1}' - set following translation transform"
13021 "\n '-followRotation {0|1}' - set following rotation transform"
13022 "\n '-gap value' - set gap between sub-parts"
13023 "\n '-part axis mode {0|1}' - set visual part"
13024 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
13025 "\n '-size value' - set size of manipulator"
13026 "\n '-zoomable {0|1}' - set zoom persistence",
13027 __FILE__, VManipulator, group);
13029 theCommands.Add("vselprops",
13030 "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]"
13031 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
13032 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
13033 "\n -autoHighlight {0|1} : disables|enables automatic highlighting in 3D Viewer"
13034 "\n -highlightSelected {0|1}: disables|enables highlighting of detected object in selected state"
13035 "\n -pickStrategy {first|topmost} : defines picking strategy"
13036 "\n 'first' to pick first acceptable (default)"
13037 "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)"
13038 "\n -pixTol value : sets up pixel tolerance"
13039 "\n -dispMode dispMode : sets display mode for highlighting"
13040 "\n -layer ZLayer : sets ZLayer for highlighting"
13041 "\n -color {name|r g b} : sets highlight color"
13042 "\n -transp value : sets transparency coefficient for highlight"
13043 "\n -material material : sets highlight material"
13044 "\n -print : prints current state of all mentioned parameters",
13045 __FILE__, VSelectionProperties, group);
13046 theCommands.Add ("vhighlightselected",
13047 "vhighlightselected [0|1]: alias for vselprops -highlightSelected.\n",
13048 __FILE__, VSelectionProperties, group);
13050 theCommands.Add ("vseldump",
13051 "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1"
13052 "\n\t\t: Generate an image based on detection results:"
13053 "\n\t\t: depth normalized depth values"
13054 "\n\t\t: unnormDepth unnormalized depth values"
13055 "\n\t\t: object color of detected object"
13056 "\n\t\t: owner color of detected owner"
13057 "\n\t\t: selMode color of selection mode"
13058 "\n\t\t: entity color of etected entity",
13059 __FILE__, VDumpSelectionImage, group);
13061 #if defined(_WIN32)
13062 theCommands.Add("vprogressive",
13064 __FILE__, VProgressiveMode, group);