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_ColorScale.hxx>
23 #include <AIS_Manipulator.hxx>
24 #include <AIS_RubberBand.hxx>
25 #include <AIS_Shape.hxx>
26 #include <AIS_InteractiveObject.hxx>
27 #include <AIS_ListOfInteractive.hxx>
28 #include <AIS_ListIteratorOfListOfInteractive.hxx>
29 #include <Aspect_Grid.hxx>
31 #include <Draw_ProgressIndicator.hxx>
32 #include <Graphic3d_ArrayOfPolylines.hxx>
33 #include <Graphic3d_AspectMarker3d.hxx>
34 #include <Graphic3d_NameOfTextureEnv.hxx>
35 #include <Graphic3d_GraduatedTrihedron.hxx>
36 #include <Graphic3d_TextureEnv.hxx>
37 #include <Graphic3d_TextureParams.hxx>
38 #include <Graphic3d_TypeOfTextureFilter.hxx>
39 #include <Graphic3d_AspectFillArea3d.hxx>
40 #include <ViewerTest.hxx>
41 #include <ViewerTest_AutoUpdater.hxx>
42 #include <ViewerTest_EventManager.hxx>
43 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
44 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
45 #include <ViewerTest_CmdParser.hxx>
46 #include <V3d_AmbientLight.hxx>
47 #include <V3d_DirectionalLight.hxx>
48 #include <V3d_PositionalLight.hxx>
49 #include <V3d_SpotLight.hxx>
50 #include <Message_ProgressSentry.hxx>
51 #include <NCollection_DoubleMap.hxx>
52 #include <NCollection_List.hxx>
53 #include <NCollection_Vector.hxx>
54 #include <AIS_InteractiveContext.hxx>
55 #include <Draw_Interpretor.hxx>
57 #include <Draw_Appli.hxx>
58 #include <Image_AlienPixMap.hxx>
59 #include <Image_VideoRecorder.hxx>
60 #include <OpenGl_GraphicDriver.hxx>
61 #include <OSD_Timer.hxx>
62 #include <TColStd_HSequenceOfAsciiString.hxx>
63 #include <TColStd_SequenceOfInteger.hxx>
64 #include <TColStd_HSequenceOfReal.hxx>
65 #include <TColgp_Array1OfPnt2d.hxx>
66 #include <TColStd_MapOfAsciiString.hxx>
67 #include <Aspect_TypeOfLine.hxx>
68 #include <Image_Diff.hxx>
69 #include <Aspect_DisplayConnection.hxx>
73 #include <PrsMgr_PresentableObject.hxx>
74 #include <Graphic3d_ClipPlane.hxx>
75 #include <NCollection_DataMap.hxx>
76 #include <Graphic3d_Texture2Dmanual.hxx>
77 #include <Prs3d_ShadingAspect.hxx>
78 #include <Prs3d_Drawer.hxx>
79 #include <Prs3d_LineAspect.hxx>
80 #include <Prs3d_Root.hxx>
81 #include <Prs3d_Text.hxx>
82 #include <Select3D_SensitivePrimitiveArray.hxx>
91 #include <WNT_WClass.hxx>
92 #include <WNT_Window.hxx>
93 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
94 #include <Cocoa_Window.hxx>
96 #include <Xw_Window.hxx>
97 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
98 #include <X11/Xutil.h>
102 // Auxiliary definitions
103 static const char THE_KEY_DELETE = 127;
104 static const char THE_KEY_ESCAPE = 27;
106 //==============================================================================
107 // VIEWER GLOBAL VARIABLES
108 //==============================================================================
110 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
111 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
113 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
114 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
116 extern int VErase (Draw_Interpretor& theDI,
117 Standard_Integer theArgNb,
118 const char** theArgVec);
121 static Handle(WNT_Window)& VT_GetWindow() {
122 static Handle(WNT_Window) WNTWin;
125 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
126 static Handle(Cocoa_Window)& VT_GetWindow()
128 static Handle(Cocoa_Window) aWindow;
131 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
132 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
133 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
136 static Handle(Xw_Window)& VT_GetWindow(){
137 static Handle(Xw_Window) XWWin;
141 static void VProcessEvents(ClientData,int);
144 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
146 static Handle(Aspect_DisplayConnection) aDisplayConnection;
147 return aDisplayConnection;
150 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
152 GetDisplayConnection() = theDisplayConnection;
155 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
156 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
158 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
160 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
161 if (!aWindow.IsNull())
162 return aWindow->HWindow();
163 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
164 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
165 if (!aWindow.IsNull())
166 return aWindow->XWindow();
168 return aWindowHandle;
172 //! Setting additional flag to store 2D mode of the View to avoid scene rotation by mouse/key events
173 class ViewerTest_V3dView : public V3d_View
175 DEFINE_STANDARD_RTTI_INLINE(ViewerTest_V3dView, V3d_View)
177 //! Initializes the view.
178 ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const V3d_TypeOfView theType = V3d_ORTHOGRAPHIC,
179 bool theIs2dMode = false)
180 : V3d_View (theViewer, theType), myIs2dMode (theIs2dMode) {}
182 //! Initializes the view by copying.
183 ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const Handle(V3d_View)& theView)
184 : V3d_View (theViewer, theView), myIs2dMode (false)
186 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (theView))
188 myIs2dMode = aV3dView->IsViewIn2DMode();
192 //! Returns true if 2D mode is set for the view
193 bool IsViewIn2DMode() const { return myIs2dMode; }
195 //! Sets 2D mode for the view
196 void SetView2DMode (bool the2dMode) { myIs2dMode = the2dMode; }
200 //! Returns true if active view in 2D mode.
201 static bool IsCurrentViewIn2DMode()
203 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
205 return aV3dView->IsViewIn2DMode();
210 //! Set if active view in 2D mode.
211 static void SetCurrentView2DMode (bool theIs2d)
213 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
215 aV3dView->SetView2DMode (theIs2d);
221 Standard_Boolean myIs2dMode; //!< 2D mode flag
225 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
226 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
227 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
228 static OpenGl_Caps ViewerTest_myDefaultCaps;
230 static void OSWindowSetup();
234 Quantity_Color FlatColor;
235 Quantity_Color GradientColor1;
236 Quantity_Color GradientColor2;
237 Aspect_GradientFillMethod FillMethod;
238 } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
240 //==============================================================================
241 // EVENT GLOBAL VARIABLES
242 //==============================================================================
244 static int Start_Rot = 0;
245 Standard_Boolean HasHlrOnBeforeRotation = Standard_False;
246 int X_Motion = 0; // Current cursor position
248 int X_ButtonPress = 0; // Last ButtonPress position
249 int Y_ButtonPress = 0;
250 Standard_Boolean IsDragged = Standard_False;
251 Standard_Boolean DragFirst = Standard_False;
252 Standard_Boolean TheIsAnimating = Standard_False;
253 Standard_Boolean Draw_ToExitOnCloseView = Standard_False;
254 Standard_Boolean Draw_ToCloseViewOnEsc = Standard_False;
257 Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand()
259 static Handle(AIS_RubberBand) aBand;
262 aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0);
263 aBand->SetDisplayMode (0);
268 typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators;
270 Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators()
272 static ViewerTest_MapOfAISManipulators aMap;
276 Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator()
278 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
279 for (; anIt.More(); anIt.Next())
281 if (anIt.Value()->HasActiveMode())
289 //==============================================================================
292 static LRESULT WINAPI ViewerWindowProc(
297 static LRESULT WINAPI AdvViewerWindowProc(
305 //==============================================================================
308 //==============================================================================
310 const Handle(Standard_Transient)& ViewerTest::WClass()
312 static Handle(Standard_Transient) theWClass;
314 if (theWClass.IsNull())
316 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
317 CS_VREDRAW | CS_HREDRAW, 0, 0,
318 ::LoadCursor (NULL, IDC_ARROW));
324 //==============================================================================
325 //function : CreateName
326 //purpose : Create numerical name for new object in theMap
327 //==============================================================================
328 template <typename ObjectType>
329 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
330 const TCollection_AsciiString& theDefaultString)
332 if (theObjectMap.IsEmpty())
333 return theDefaultString + TCollection_AsciiString(1);
335 Standard_Integer aNextKey = 1;
336 Standard_Boolean isFound = Standard_False;
339 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
340 // Look for objects with default names
341 if (theObjectMap.IsBound1(aStringKey))
346 isFound = Standard_True;
349 return theDefaultString + TCollection_AsciiString(aNextKey);
352 //==============================================================================
353 //structure : ViewerTest_Names
354 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
355 //==============================================================================
356 struct ViewerTest_Names
359 TCollection_AsciiString myDriverName;
360 TCollection_AsciiString myViewerName;
361 TCollection_AsciiString myViewName;
365 const TCollection_AsciiString& GetDriverName () const
369 void SetDriverName (const TCollection_AsciiString& theDriverName)
371 myDriverName = theDriverName;
373 const TCollection_AsciiString& GetViewerName () const
377 void SetViewerName (const TCollection_AsciiString& theViewerName)
379 myViewerName = theViewerName;
381 const TCollection_AsciiString& GetViewName () const
385 void SetViewName (const TCollection_AsciiString& theViewName)
387 myViewName = theViewName;
390 //===========================================================================
391 //function : Constructor for ViewerTest_Names
392 //purpose : Get view, viewer, driver names from custom string
393 //===========================================================================
395 ViewerTest_Names (const TCollection_AsciiString& theInputString)
397 TCollection_AsciiString aName(theInputString);
398 if (theInputString.IsEmpty())
400 // Get current configuration
401 if (ViewerTest_myDrivers.IsEmpty())
402 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
403 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
405 myDriverName = ViewerTest_myDrivers.Find2
406 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
408 if(ViewerTest_myContexts.IsEmpty())
410 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
411 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
415 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
418 myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
422 // There is at least view name
423 Standard_Integer aParserNumber = 0;
424 for (Standard_Integer i = 0; i < 3; ++i)
426 Standard_Integer aParserPos = aName.SearchFromEnd("/");
430 aName.Split(aParserPos-1);
435 if (aParserNumber == 0)
438 if (!ViewerTest::GetAISContext().IsNull())
440 myDriverName = ViewerTest_myDrivers.Find2
441 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
442 myViewerName = ViewerTest_myContexts.Find2
443 (ViewerTest::GetAISContext());
447 // There is no opened contexts here, need to create names for viewer and driver
448 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
449 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
451 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
452 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
454 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
456 else if (aParserNumber == 1)
458 // Here is viewerName/viewName
459 if (!ViewerTest::GetAISContext().IsNull())
460 myDriverName = ViewerTest_myDrivers.Find2
461 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
464 // There is no opened contexts here, need to create name for driver
465 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
466 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
468 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
470 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
474 //Here is driverName/viewerName/viewName
475 myDriverName = TCollection_AsciiString(aName);
477 TCollection_AsciiString aViewerName(theInputString);
478 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
479 myViewerName = TCollection_AsciiString(aViewerName);
481 myViewName = TCollection_AsciiString(theInputString);
487 //==============================================================================
488 //function : FindContextByView
489 //purpose : Find AIS_InteractiveContext by View
490 //==============================================================================
492 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
494 Handle(AIS_InteractiveContext) anAISContext;
496 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
497 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
499 if (anIter.Value()->CurrentViewer() == theView->Viewer())
500 return anIter.Key2();
506 //==============================================================================
507 //function : SetWindowTitle
508 //purpose : Set window title
509 //==============================================================================
511 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
512 Standard_CString theTitle)
515 const TCollection_ExtendedString theTitleW (theTitle);
516 SetWindowTextW ((HWND )Handle(WNT_Window)::DownCast(theWindow)->HWindow(), theTitleW.ToWideString());
517 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
518 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
520 if(GetDisplayConnection()->GetDisplay())
523 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
524 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
529 //==============================================================================
530 //function : IsWindowOverlapped
531 //purpose : Check if theWindow overlapp another view
532 //==============================================================================
534 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
535 const Standard_Integer thePxTop,
536 const Standard_Integer thePxRight,
537 const Standard_Integer thePxBottom,
538 TCollection_AsciiString& theViewId)
540 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
541 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
543 Standard_Integer aTop = 0,
547 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
548 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
549 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
550 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
551 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
553 theViewId = anIter.Key1();
554 return Standard_True;
557 return Standard_False;
560 // Workaround: to create and delete non-orthographic views outside ViewerTest
561 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
563 ViewerTest_myViews.UnBind1 (theName);
566 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
567 const Handle(V3d_View)& theView)
569 ViewerTest_myViews.Bind (theName, theView);
572 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
574 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
576 //==============================================================================
577 //function : ViewerInit
578 //purpose : Create the window viewer and initialize all the global variable
579 //==============================================================================
581 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
582 const Standard_Integer thePxTop,
583 const Standard_Integer thePxWidth,
584 const Standard_Integer thePxHeight,
585 const TCollection_AsciiString& theViewName,
586 const TCollection_AsciiString& theDisplayName,
587 const Handle(V3d_View)& theViewToClone)
589 // Default position and dimension of the viewer window.
590 // Note that left top corner is set to be sufficiently small to have
591 // window fit in the small screens (actual for remote desktops, see #23003).
592 // The position corresponds to the window's client area, thus some
593 // gap is added for window frame to be visible.
594 Standard_Integer aPxLeft = 20;
595 Standard_Integer aPxTop = 40;
596 Standard_Integer aPxWidth = 409;
597 Standard_Integer aPxHeight = 409;
598 Standard_Boolean toCreateViewer = Standard_False;
599 if (!theViewToClone.IsNull())
601 theViewToClone->Window()->Size (aPxWidth, aPxHeight);
604 Handle(OpenGl_GraphicDriver) aGraphicDriver;
605 ViewerTest_Names aViewNames(theViewName);
606 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
607 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
614 aPxWidth = thePxWidth;
615 if (thePxHeight != 0)
616 aPxHeight = thePxHeight;
618 // Get graphic driver (create it or get from another view)
619 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
621 // Get connection string
622 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
623 TCollection_AsciiString aDisplayName(theDisplayName);
624 if (!aDisplayName.IsEmpty())
625 SetDisplayConnection (new Aspect_DisplayConnection ());
627 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
629 (void)theDisplayName; // avoid warning on unused argument
630 SetDisplayConnection (new Aspect_DisplayConnection ());
633 if (Draw_VirtualWindows)
635 // don't waste the time waiting for VSync when window is not displayed on the screen
636 ViewerTest_myDefaultCaps.swapInterval = 0;
637 // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
638 //ViewerTest_myDefaultCaps.buffersNoSwap = true;
640 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
641 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
643 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
644 toCreateViewer = Standard_True;
648 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
651 //Dispose the window if input parameters are default
652 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
654 Standard_Integer aTop = 0,
661 // Get screen resolution
662 #if defined(_WIN32) || defined(__WIN32__)
664 GetClientRect(GetDesktopWindow(), &aWindowSize);
665 aScreenHeight = aWindowSize.bottom;
666 aScreenWidth = aWindowSize.right;
667 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
668 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
670 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
671 aScreenWidth = WidthOfScreen(aScreen);
672 aScreenHeight = HeightOfScreen(aScreen);
675 TCollection_AsciiString anOverlappedViewId("");
677 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
679 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
681 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
682 && aRight + 2*aPxWidth + 40 > aScreenWidth)
684 if (aBottom + aPxHeight + 40 > aScreenHeight)
691 aPxTop = aBottom + 40;
694 aPxLeft = aRight + 20;
699 TCollection_AsciiString aTitle("3D View - ");
700 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
702 // Change name of current active window
703 if (!ViewerTest::CurrentView().IsNull())
705 TCollection_AsciiString anActiveWindowTitle("3D View - ");
706 anActiveWindowTitle = anActiveWindowTitle
707 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
708 SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString());
712 Handle(V3d_Viewer) a3DViewer;
713 // If it's the single view, we first look for empty context
714 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
716 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
717 anIter(ViewerTest_myContexts);
719 ViewerTest::SetAISContext (anIter.Value());
720 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
722 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
724 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
725 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
727 else if (a3DViewer.IsNull())
729 toCreateViewer = Standard_True;
730 a3DViewer = new V3d_Viewer(aGraphicDriver);
731 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
732 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
733 ViewerTest_DefaultBackground.GradientColor2,
734 ViewerTest_DefaultBackground.FillMethod);
738 if (ViewerTest::GetAISContext().IsNull() ||
739 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
741 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
742 ViewerTest::SetAISContext (aContext);
743 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
747 ViewerTest::ResetEventManager();
752 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
753 Handle(WNT_WClass)::DownCast (WClass()),
754 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
758 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
759 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
761 aPxWidth, aPxHeight);
762 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
764 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
767 aPxWidth, aPxHeight);
769 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
772 Handle(V3d_View) aView;
773 if (!theViewToClone.IsNull())
775 aView = new ViewerTest_V3dView (a3DViewer, theViewToClone);
779 aView = new ViewerTest_V3dView (a3DViewer, a3DViewer->DefaultTypeOfView());
782 aView->SetWindow (VT_GetWindow());
783 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
785 ViewerTest::CurrentView(aView);
786 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
788 // Setup for X11 or NT
791 // Set parameters for V3d_View and V3d_Viewer
792 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
793 aV3dView->SetComputedMode(Standard_False);
795 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
798 a3DViewer->SetDefaultLights();
799 a3DViewer->SetLightOn();
802 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
803 #if TCL_MAJOR_VERSION < 8
804 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
805 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
807 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
808 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
812 VT_GetWindow()->Map();
814 // Set the handle of created view in the event manager
815 ViewerTest::ResetEventManager();
817 ViewerTest::CurrentView()->Redraw();
822 return aViewNames.GetViewName();
825 //==============================================================================
826 //function : RedrawAllViews
827 //purpose : Redraw all created views
828 //==============================================================================
829 void ViewerTest::RedrawAllViews()
831 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
832 for (; aViewIt.More(); aViewIt.Next())
834 const Handle(V3d_View)& aView = aViewIt.Key2();
839 //==============================================================================
841 //purpose : Create the window viewer and initialize all the global variable
842 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
843 //==============================================================================
845 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
847 TCollection_AsciiString aViewName, aDisplayName;
848 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
849 Handle(V3d_View) aCopyFrom;
850 TCollection_AsciiString aName, aValue;
852 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
854 const TCollection_AsciiString anArg = theArgVec[anArgIt];
855 TCollection_AsciiString anArgCase = anArg;
856 anArgCase.LowerCase();
857 if (anArgIt + 1 < theArgsNb
858 && anArgCase == "-name")
860 aViewName = theArgVec[++anArgIt];
862 else if (anArgIt + 1 < theArgsNb
863 && (anArgCase == "-left"
864 || anArgCase == "-l"))
866 aPxLeft = Draw::Atoi (theArgVec[++anArgIt]);
868 else if (anArgIt + 1 < theArgsNb
869 && (anArgCase == "-top"
870 || anArgCase == "-t"))
872 aPxTop = Draw::Atoi (theArgVec[++anArgIt]);
874 else if (anArgIt + 1 < theArgsNb
875 && (anArgCase == "-width"
876 || anArgCase == "-w"))
878 aPxWidth = Draw::Atoi (theArgVec[++anArgIt]);
880 else if (anArgIt + 1 < theArgsNb
881 && (anArgCase == "-height"
882 || anArgCase == "-h"))
884 aPxHeight = Draw::Atoi (theArgVec[++anArgIt]);
886 else if (anArgCase == "-exitonclose")
888 Draw_ToExitOnCloseView = true;
889 if (anArgIt + 1 < theArgsNb
890 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToExitOnCloseView))
895 else if (anArgCase == "-closeonescape"
896 || anArgCase == "-closeonesc")
898 Draw_ToCloseViewOnEsc = true;
899 if (anArgIt + 1 < theArgsNb
900 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToCloseViewOnEsc))
905 else if (anArgCase == "-2d_mode"
906 || anArgCase == "-2dmode"
907 || anArgCase == "-2d")
909 bool toEnable = true;
910 if (anArgIt + 1 < theArgsNb
911 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], toEnable))
915 is2dMode = toEnable ? 1 : 0;
917 else if (anArgIt + 1 < theArgsNb
918 && (anArgCase == "-disp"
919 || anArgCase == "-display"))
921 aDisplayName = theArgVec[++anArgIt];
923 else if (!ViewerTest::CurrentView().IsNull()
924 && aCopyFrom.IsNull()
925 && (anArgCase == "-copy"
926 || anArgCase == "-clone"
927 || anArgCase == "-cloneactive"
928 || anArgCase == "-cloneactiveview"))
930 aCopyFrom = ViewerTest::CurrentView();
933 else if (ViewerTest::SplitParameter (anArg, aName, aValue))
940 else if (aName == "l"
943 aPxLeft = aValue.IntegerValue();
945 else if (aName == "t"
948 aPxTop = aValue.IntegerValue();
950 else if (aName == "disp"
951 || aName == "display")
953 aDisplayName = aValue;
955 else if (aName == "w"
958 aPxWidth = aValue.IntegerValue();
960 else if (aName == "h"
961 || aName == "height")
963 aPxHeight = aValue.IntegerValue();
967 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
971 else if (aViewName.IsEmpty())
977 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
982 #if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
983 if (!aDisplayName.IsEmpty())
985 aDisplayName.Clear();
986 std::cout << "Warning: display parameter will be ignored.\n";
990 ViewerTest_Names aViewNames (aViewName);
991 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
993 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
994 theDi.Eval (aCommand.ToCString());
997 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
1002 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
1003 aViewName, aDisplayName, aCopyFrom);
1006 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
1012 //! Parse HLR algo type.
1013 static Standard_Boolean parseHlrAlgoType (const char* theName,
1014 Prs3d_TypeOfHLR& theType)
1016 TCollection_AsciiString aName (theName);
1018 if (aName == "polyalgo")
1020 theType = Prs3d_TOH_PolyAlgo;
1022 else if (aName == "algo")
1024 theType = Prs3d_TOH_Algo;
1028 return Standard_False;
1030 return Standard_True;
1033 //==============================================================================
1035 //purpose : hidden lines removal algorithm
1036 //==============================================================================
1038 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1040 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1041 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1044 std::cerr << "Error: No opened viewer!\n";
1048 Standard_Boolean hasHlrOnArg = Standard_False;
1049 Standard_Boolean hasShowHiddenArg = Standard_False;
1050 Standard_Boolean isHLROn = Standard_False;
1051 Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
1052 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1053 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1054 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
1056 TCollection_AsciiString anArg (argv[anArgIter]);
1058 if (anUpdateTool.parseRedrawMode (anArg))
1062 else if (anArg == "-showhidden"
1063 && anArgIter + 1 < argc
1064 && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden))
1067 hasShowHiddenArg = Standard_True;
1070 else if ((anArg == "-type"
1072 || anArg == "-algotype")
1073 && anArgIter + 1 < argc
1074 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1079 else if (!hasHlrOnArg
1080 && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn))
1082 hasHlrOnArg = Standard_True;
1086 else if (!hasShowHiddenArg
1087 && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden))
1089 hasShowHiddenArg = Standard_True;
1094 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
1100 di << "HLR: " << aView->ComputedMode() << "\n";
1101 di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
1103 switch (aCtx->DefaultDrawer()->TypeOfHLR())
1105 case Prs3d_TOH_NotSet: di << "NotSet\n"; break;
1106 case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
1107 case Prs3d_TOH_Algo: di << "Algo\n"; break;
1109 anUpdateTool.Invalidate();
1113 Standard_Boolean toRecompute = Standard_False;
1114 if (aTypeOfHLR != Prs3d_TOH_NotSet
1115 && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
1117 toRecompute = Standard_True;
1118 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1120 if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
1122 toRecompute = Standard_True;
1125 aCtx->DefaultDrawer()->EnableDrawHiddenLine();
1129 aCtx->DefaultDrawer()->DisableDrawHiddenLine();
1134 if (aView->ComputedMode() && isHLROn && toRecompute)
1136 AIS_ListOfInteractive aListOfShapes;
1137 aCtx->DisplayedObjects (aListOfShapes);
1138 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
1140 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
1142 aCtx->Redisplay (aShape, Standard_False);
1147 aView->SetComputedMode (isHLROn);
1151 //==============================================================================
1152 //function : VHLRType
1153 //purpose : change type of using HLR algorithm
1154 //==============================================================================
1156 static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1158 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1159 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1162 std::cerr << "Error: No opened viewer!\n";
1166 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1167 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1168 AIS_ListOfInteractive aListOfShapes;
1169 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
1171 TCollection_AsciiString anArg (argv[anArgIter]);
1173 if (anUpdateTool.parseRedrawMode (anArg))
1177 else if ((anArg == "-type"
1179 || anArg == "-algotype")
1180 && anArgIter + 1 < argc
1181 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1187 else if (aTypeOfHLR == Prs3d_TOH_NotSet
1188 && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
1194 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
1195 TCollection_AsciiString aName (argv[anArgIter]);
1196 if (!aMap.IsBound2 (aName))
1198 std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n";
1202 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
1203 if (aShape.IsNull())
1205 std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n";
1208 aListOfShapes.Append (aShape);
1212 if (aTypeOfHLR == Prs3d_TOH_NotSet)
1214 std::cout << "Syntax error: wrong number of arguments!\n";
1218 const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
1221 aCtx->DisplayedObjects (aListOfShapes);
1222 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1225 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
1227 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1228 if (aShape.IsNull())
1233 const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
1234 && aView->ComputedMode();
1236 || aShape->TypeOfHLR() != aTypeOfHLR)
1238 aShape->SetTypeOfHLR (aTypeOfHLR);
1242 aCtx->Redisplay (aShape, Standard_False);
1248 //==============================================================================
1249 //function : FindViewIdByWindowHandle
1250 //purpose : Find theView Id in the map of views by window handle
1251 //==============================================================================
1252 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1253 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
1255 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
1256 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1258 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
1259 if (aWindowHandle == theWindowHandle)
1260 return anIter.Key1();
1262 return TCollection_AsciiString("");
1266 //==============================================================================
1267 //function : ActivateView
1268 //purpose : Make the view active
1269 //==============================================================================
1271 void ActivateView (const TCollection_AsciiString& theViewName)
1273 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1274 if (!aView.IsNull())
1276 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1277 if (!anAISContext.IsNull())
1279 if (!ViewerTest::CurrentView().IsNull())
1281 TCollection_AsciiString aTitle("3D View - ");
1282 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1283 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1286 ViewerTest::CurrentView (aView);
1287 ViewerTest::SetAISContext (anAISContext);
1288 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ") + theViewName + "(*)";
1289 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1291 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1292 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1293 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1295 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1297 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1298 ViewerTest::CurrentView()->Redraw();
1303 //==============================================================================
1304 //function : RemoveView
1306 //==============================================================================
1307 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1308 const Standard_Boolean theToRemoveContext)
1310 if (!ViewerTest_myViews.IsBound2 (theView))
1315 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1316 RemoveView (aViewName, theToRemoveContext);
1319 //==============================================================================
1320 //function : RemoveView
1321 //purpose : Close and remove view from display, clear maps if neccessary
1322 //==============================================================================
1323 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1325 if (!ViewerTest_myViews.IsBound1(theViewName))
1327 cout << "Wrong view name\n";
1331 // Activate another view if it's active now
1332 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1334 if (ViewerTest_myViews.Extent() > 1)
1336 TCollection_AsciiString aNewViewName;
1337 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1338 anIter.More(); anIter.Next())
1340 if (anIter.Key1() != theViewName)
1342 aNewViewName = anIter.Key1();
1346 ActivateView (aNewViewName);
1350 Handle(V3d_View) anEmptyView;
1351 #if defined(_WIN32) || defined(__WIN32__)
1352 Handle(WNT_Window) anEmptyWindow;
1353 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1354 Handle(Cocoa_Window) anEmptyWindow;
1356 Handle(Xw_Window) anEmptyWindow;
1358 VT_GetWindow() = anEmptyWindow;
1359 ViewerTest::CurrentView (anEmptyView);
1360 if (isContextRemoved)
1362 Handle(AIS_InteractiveContext) anEmptyContext;
1363 ViewerTest::SetAISContext(anEmptyContext);
1369 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1370 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1372 // Remove view resources
1373 ViewerTest_myViews.UnBind1(theViewName);
1374 aView->Window()->Unmap();
1377 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1378 XFlush (GetDisplayConnection()->GetDisplay());
1381 // Keep context opened only if the closed view is last to avoid
1382 // unused empty contexts
1383 if (!aCurrentContext.IsNull())
1385 // Check if there are more difined views in the viewer
1386 aCurrentContext->CurrentViewer()->InitDefinedViews();
1387 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1389 // Remove driver if there is no viewers that use it
1390 Standard_Boolean isRemoveDriver = Standard_True;
1391 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1392 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1394 if (aCurrentContext != anIter.Key2() &&
1395 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1397 isRemoveDriver = Standard_False;
1402 aCurrentContext->RemoveAll (Standard_False);
1405 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1406 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1407 #if TCL_MAJOR_VERSION < 8
1408 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1410 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1415 ViewerTest_myContexts.UnBind2(aCurrentContext);
1418 cout << "3D View - " << theViewName << " was deleted.\n";
1419 if (Draw_ToExitOnCloseView)
1421 Draw_Interprete ("exit");
1425 //==============================================================================
1427 //purpose : Remove the view defined by its name
1428 //==============================================================================
1430 static int VClose (Draw_Interpretor& /*theDi*/,
1431 Standard_Integer theArgsNb,
1432 const char** theArgVec)
1434 NCollection_List<TCollection_AsciiString> aViewList;
1437 TCollection_AsciiString anArg (theArgVec[1]);
1439 if (anArg.IsEqual ("ALL")
1440 || anArg.IsEqual ("*"))
1442 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1443 anIter.More(); anIter.Next())
1445 aViewList.Append (anIter.Key1());
1447 if (aViewList.IsEmpty())
1449 std::cout << "No view to close\n";
1455 ViewerTest_Names aViewName (theArgVec[1]);
1456 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1458 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1461 aViewList.Append (aViewName.GetViewName());
1466 // close active view
1467 if (ViewerTest::CurrentView().IsNull())
1469 std::cerr << "No active view!\n";
1472 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1475 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1476 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1477 anIter.More(); anIter.Next())
1479 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1485 //==============================================================================
1486 //function : VActivate
1487 //purpose : Activate the view defined by its ID
1488 //==============================================================================
1490 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1494 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1495 << "Usage: " << theArgVec[0] << " ViewID\n";
1500 theDi.Eval("vviewlist");
1504 TCollection_AsciiString aNameString(theArgVec[1]);
1505 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1507 TCollection_AsciiString aTitle("3D View - ");
1508 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1509 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1510 Handle(V3d_View) anEmptyView;
1511 #if defined(_WIN32) || defined(__WIN32__)
1512 Handle(WNT_Window) anEmptyWindow;
1513 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1514 Handle(Cocoa_Window) anEmptyWindow;
1516 Handle(Xw_Window) anEmptyWindow;
1518 VT_GetWindow() = anEmptyWindow;
1519 ViewerTest::CurrentView (anEmptyView);
1520 ViewerTest::ResetEventManager();
1521 theDi << theArgVec[0] << ": all views are inactive\n";
1525 ViewerTest_Names aViewNames(aNameString);
1527 // Check if this view exists in the viewer with the driver
1528 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1530 theDi << "Wrong view name\n";
1534 // Check if it is active already
1535 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1537 theDi << theArgVec[0] << ": the view is active already\n";
1541 ActivateView (aViewNames.GetViewName());
1545 //==============================================================================
1546 //function : VViewList
1547 //purpose : Print current list of views per viewer and graphic driver ID
1548 // shared between viewers
1549 //==============================================================================
1551 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1555 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1556 << "Usage: " << theArgVec[0] << " name";
1559 if (ViewerTest_myContexts.Size() < 1)
1562 Standard_Boolean isTreeView =
1563 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1567 theDi << theArgVec[0] <<":\n";
1570 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers);
1571 aDriverIter.More(); aDriverIter.Next())
1574 theDi << aDriverIter.Key1() << ":\n";
1576 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1577 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1579 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1583 TCollection_AsciiString aContextName(aContextIter.Key1());
1584 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
1587 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews);
1588 aViewIter.More(); aViewIter.Next())
1590 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1592 TCollection_AsciiString aViewName(aViewIter.Key1());
1595 if (aViewIter.Value() == ViewerTest::CurrentView())
1596 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
1598 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1602 theDi << aViewName << " ";
1612 //==============================================================================
1613 //function : VT_ProcessKeyPress
1614 //purpose : Handle KeyPress event from a CString
1615 //==============================================================================
1616 void VT_ProcessKeyPress (const char* buf_ret)
1618 //cout << "KeyPress" << endl;
1619 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1620 // Letter in alphabetic order
1622 if (!strcasecmp (buf_ret, "A")
1623 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1626 aView->SetProj(V3d_XposYnegZpos);
1628 else if (!strcasecmp (buf_ret, "D")
1629 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1634 else if (!strcasecmp (buf_ret, "F"))
1636 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1638 ViewerTest::GetAISContext()->FitSelected (aView);
1646 else if (!strcasecmp (buf_ret, "H"))
1649 std::cout << "HLR" << std::endl;
1650 aView->SetComputedMode (!aView->ComputedMode());
1653 else if (!strcasecmp (buf_ret, "P"))
1656 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1657 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1658 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1660 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1661 if (aContext->NbSelected()==0)
1663 AIS_ListOfInteractive aListOfShapes;
1664 aContext->DisplayedObjects(aListOfShapes);
1665 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1666 anIter.More(); anIter.Next())
1668 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1669 if (aShape.IsNull())
1671 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1672 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1674 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1675 aContext->Redisplay (aShape, Standard_False);
1680 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
1682 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
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);
1693 aContext->UpdateCurrentViewer();
1696 else if (!strcasecmp (buf_ret, "S"))
1698 std::cout << "setup Shaded display mode" << std::endl;
1700 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1701 if(Ctx->NbSelected()==0)
1702 Ctx->SetDisplayMode (AIS_Shaded, Standard_True);
1704 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1705 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
1706 Ctx->UpdateCurrentViewer();
1709 else if (!strcasecmp (buf_ret, "U"))
1711 // Unset display mode
1712 std::cout << "reset display mode to defaults" << std::endl;
1714 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1715 if(Ctx->NbSelected()==0)
1716 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
1718 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1719 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
1720 Ctx->UpdateCurrentViewer();
1724 else if (!strcasecmp (buf_ret, "T")
1725 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1728 aView->SetProj(V3d_Zpos);
1730 else if (!strcasecmp (buf_ret, "B")
1731 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1734 aView->SetProj(V3d_Zneg);
1736 else if (!strcasecmp (buf_ret, "L")
1737 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1740 aView->SetProj(V3d_Xneg);
1742 else if (!strcasecmp (buf_ret, "R")
1743 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1746 aView->SetProj(V3d_Xpos);
1748 else if (!strcasecmp (buf_ret, "W"))
1750 std::cout << "setup WireFrame display mode" << std::endl;
1751 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1752 if(Ctx->NbSelected()==0)
1753 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
1755 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1756 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
1757 Ctx->UpdateCurrentViewer();
1760 else if (!strcasecmp (buf_ret, ","))
1762 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1764 else if (!strcasecmp (buf_ret, "."))
1766 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1768 else if (!strcasecmp (buf_ret, "/"))
1770 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1771 if (aCamera->IsStereo())
1773 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1777 else if (!strcasecmp (buf_ret, "*"))
1779 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1780 if (aCamera->IsStereo())
1782 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1786 else if (*buf_ret == THE_KEY_DELETE)
1788 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1790 && aCtx->NbSelected() > 0)
1792 Draw_Interprete ("verase");
1795 else if (*buf_ret == THE_KEY_ESCAPE)
1797 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1799 && Draw_ToCloseViewOnEsc)
1801 Draw_Interprete (Draw_ToExitOnCloseView ? "exit" : "vclose");
1807 const Standard_Integer aSelMode = Draw::Atoi(buf_ret);
1808 if (aSelMode >= 0 && aSelMode <= 7)
1810 bool toEnable = true;
1811 if (const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext())
1813 AIS_ListOfInteractive aPrsList;
1814 aCtx->DisplayedObjects (aPrsList);
1815 for (AIS_ListOfInteractive::Iterator aPrsIter (aPrsList); aPrsIter.More() && toEnable; aPrsIter.Next())
1817 TColStd_ListOfInteger aModes;
1818 aCtx->ActivatedModes (aPrsIter.Value(), aModes);
1819 for (TColStd_ListOfInteger::Iterator aModeIter (aModes); aModeIter.More() && toEnable; aModeIter.Next())
1821 if (aModeIter.Value() == aSelMode)
1828 TCollection_AsciiString aCmd = TCollection_AsciiString ("vselmode ") + aSelMode + (toEnable ? " 1" : " 0");
1829 Draw_Interprete (aCmd.ToCString());
1834 //==============================================================================
1835 //function : VT_ProcessExpose
1836 //purpose : Redraw the View on an Expose Event
1837 //==============================================================================
1838 void VT_ProcessExpose()
1840 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1841 if (!aView3d.IsNull())
1847 //==============================================================================
1848 //function : VT_ProcessConfigure
1849 //purpose : Resize the View on an Configure Event
1850 //==============================================================================
1851 void VT_ProcessConfigure()
1853 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1854 if (aView3d.IsNull())
1859 aView3d->MustBeResized();
1864 //==============================================================================
1865 //function : VT_ProcessButton1Press
1867 //==============================================================================
1868 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1869 const char** theArgVec,
1870 Standard_Boolean theToPick,
1871 Standard_Boolean theIsShift)
1875 TheIsAnimating = Standard_False;
1876 return Standard_False;
1881 Standard_Real X, Y, Z;
1882 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1884 Draw::Set (theArgVec[1], X);
1885 Draw::Set (theArgVec[2], Y);
1886 Draw::Set (theArgVec[3], Z);
1891 ViewerTest::CurrentEventManager()->ShiftSelect();
1895 ViewerTest::CurrentEventManager()->Select();
1898 return Standard_False;
1901 //==============================================================================
1902 //function : VT_ProcessButton1Release
1903 //purpose : End selecting
1904 //==============================================================================
1905 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1909 IsDragged = Standard_False;
1910 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1913 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1914 X_Motion, Y_Motion);
1918 EM->Select (X_ButtonPress, Y_ButtonPress,
1919 X_Motion, Y_Motion);
1924 //==============================================================================
1925 //function : VT_ProcessButton3Press
1926 //purpose : Start Rotation
1927 //==============================================================================
1928 void VT_ProcessButton3Press()
1930 if (ViewerTest_V3dView::IsCurrentViewIn2DMode())
1936 HasHlrOnBeforeRotation = ViewerTest::CurrentView()->ComputedMode();
1937 if (HasHlrOnBeforeRotation)
1939 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1941 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1944 //==============================================================================
1945 //function : VT_ProcessButton3Release
1946 //purpose : End rotation
1947 //==============================================================================
1948 void VT_ProcessButton3Release()
1953 if (HasHlrOnBeforeRotation)
1955 HasHlrOnBeforeRotation = Standard_False;
1956 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1957 ViewerTest::CurrentView()->Redraw();
1962 //==============================================================================
1963 //function : ProcessControlButton1Motion
1965 //==============================================================================
1967 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1968 static void ProcessControlButton1Motion()
1970 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1972 X_ButtonPress = X_Motion;
1973 Y_ButtonPress = Y_Motion;
1977 //==============================================================================
1978 //function : VT_ProcessControlButton2Motion
1980 //==============================================================================
1981 void VT_ProcessControlButton2Motion()
1983 Standard_Integer aDx = X_Motion - X_ButtonPress;
1984 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1986 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1988 ViewerTest::CurrentView()->Pan (aDx, aDy);
1990 X_ButtonPress = X_Motion;
1991 Y_ButtonPress = Y_Motion;
1994 //==============================================================================
1995 //function : VT_ProcessControlButton3Motion
1996 //purpose : Rotation
1997 //==============================================================================
1998 void VT_ProcessControlButton3Motion()
2002 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
2006 //==============================================================================
2007 //function : VT_ProcessMotion
2009 //==============================================================================
2010 void VT_ProcessMotion()
2012 //pre-hilights detected objects at mouse position
2014 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
2015 EM->MoveTo(X_Motion, Y_Motion);
2019 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
2021 Xpix = X_Motion;Ypix=Y_Motion;
2024 //==============================================================================
2025 //function : ViewProject: implements VAxo, VTop, VLeft, ...
2026 //purpose : Switches to an axonometric, top, left and other views
2027 //==============================================================================
2029 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
2031 if ( ViewerTest::CurrentView().IsNull() )
2033 di<<"Call vinit before this command, please\n";
2037 ViewerTest::CurrentView()->SetProj(ori);
2041 //==============================================================================
2043 //purpose : Switch to an Axonometric view
2044 //Draw arg : No args
2045 //==============================================================================
2047 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
2049 return ViewProject(di, V3d_XposYnegZpos);
2052 //==============================================================================
2054 //purpose : Switch to a Top View
2055 //Draw arg : No args
2056 //==============================================================================
2058 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
2060 return ViewProject(di, V3d_Zpos);
2063 //==============================================================================
2064 //function : VBottom
2065 //purpose : Switch to a Bottom View
2066 //Draw arg : No args
2067 //==============================================================================
2069 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
2071 return ViewProject(di, V3d_Zneg);
2074 //==============================================================================
2076 //purpose : Switch to a Left View
2077 //Draw arg : No args
2078 //==============================================================================
2080 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
2082 return ViewProject(di, V3d_Xneg);
2085 //==============================================================================
2087 //purpose : Switch to a Right View
2088 //Draw arg : No args
2089 //==============================================================================
2091 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
2093 return ViewProject(di, V3d_Xpos);
2096 //==============================================================================
2098 //purpose : Switch to a Front View
2099 //Draw arg : No args
2100 //==============================================================================
2102 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
2104 return ViewProject(di, V3d_Yneg);
2107 //==============================================================================
2109 //purpose : Switch to a Back View
2110 //Draw arg : No args
2111 //==============================================================================
2113 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
2115 return ViewProject(di, V3d_Ypos);
2118 //==============================================================================
2120 //purpose : Dsiplay help on viewer Keyboead and mouse commands
2121 //Draw arg : No args
2122 //==============================================================================
2124 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
2127 di << "Q : Quit the application\n";
2129 di << "=========================\n";
2130 di << "F : FitAll\n";
2131 di << "T : TopView\n";
2132 di << "B : BottomView\n";
2133 di << "R : RightView\n";
2134 di << "L : LeftView\n";
2135 di << "A : AxonometricView\n";
2136 di << "D : ResetView\n";
2138 di << "=========================\n";
2139 di << "S : Shading\n";
2140 di << "W : Wireframe\n";
2141 di << "H : HidelLineRemoval\n";
2142 di << "U : Unset display mode\n";
2143 di << "Delete : Remove selection from viewer\n";
2145 di << "=========================\n";
2146 di << "Selection mode \n";
2147 di << "0 : Shape\n";
2148 di << "1 : Vertex\n";
2152 di << "5 : Shell\n";
2153 di << "6 : Solid\n";
2154 di << "7 : Compound\n";
2156 di << "=========================\n";
2157 di << "Z : Switch Z clipping On/Off\n";
2158 di << ", : Hilight next detected\n";
2159 di << ". : Hilight previous detected\n";
2166 static Standard_Boolean Ppick = 0;
2167 static Standard_Integer Pargc = 0;
2168 static const char** Pargv = NULL;
2171 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
2176 if (!ViewerTest_myViews.IsEmpty()) {
2178 WPARAM fwKeys = wParam;
2183 // Delete view from map of views
2184 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
2189 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
2190 || ViewerTest::CurrentView().IsNull())
2192 // Activate inactive window
2193 if(GetWindowHandle(VT_GetWindow()) != hwnd)
2195 ActivateView (FindViewIdByWindowHandle(hwnd));
2201 if (IsDragged && !DragFirst)
2203 if (!GetActiveAISManipulator().IsNull())
2205 GetActiveAISManipulator()->StopTransform();
2206 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
2209 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2211 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2212 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2215 VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0);
2217 IsDragged = Standard_False;
2218 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2221 if (IsDragged && !DragFirst)
2223 if (!GetActiveAISManipulator().IsNull())
2225 GetActiveAISManipulator()->StopTransform (Standard_False);
2226 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
2228 IsDragged = Standard_False;
2230 return ViewerWindowProc (hwnd, Msg, wParam, lParam);
2232 case WM_LBUTTONDOWN:
2233 if (!GetActiveAISManipulator().IsNull())
2235 IsDragged = ( fwKeys == MK_LBUTTON );
2239 IsDragged = ( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) );
2244 DragFirst = Standard_True;
2245 X_ButtonPress = LOWORD(lParam);
2246 Y_ButtonPress = HIWORD(lParam);
2248 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2253 X_Motion = LOWORD (lParam);
2254 Y_Motion = HIWORD (lParam);
2255 if (!GetActiveAISManipulator().IsNull())
2259 GetActiveAISManipulator()->StartTransform (X_ButtonPress, Y_ButtonPress, ViewerTest::CurrentView());
2263 GetActiveAISManipulator()->Transform (X_Motion, Y_Motion, ViewerTest::CurrentView());
2264 ViewerTest::GetAISContext()->CurrentViewer()->Redraw();
2269 bool toRedraw = false;
2270 if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2272 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2277 if (GetClientRect (hwnd, &aRect))
2279 int aHeight = aRect.bottom - aRect.top;
2280 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2281 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed);
2286 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2290 DragFirst = Standard_False;
2293 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2297 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2301 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2305 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
2311 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2314 return DefWindowProcW (hwnd, Msg, wParam, lParam);
2321 BeginPaint(hwnd, &ps);
2322 EndPaint(hwnd, &ps);
2327 VT_ProcessConfigure();
2332 switch (aView->RenderingParams().StereoMode)
2334 case Graphic3d_StereoMode_RowInterlaced:
2335 case Graphic3d_StereoMode_ColumnInterlaced:
2336 case Graphic3d_StereoMode_ChessBoard:
2337 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2345 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2348 c[0] = (char) wParam;
2350 if (wParam == VK_DELETE)
2352 c[0] = THE_KEY_DELETE;
2354 else if (wParam == VK_ESCAPE)
2356 c[0] = THE_KEY_ESCAPE;
2359 else if (wParam == VK_OEM_COMMA)
2364 else if (wParam == VK_OEM_PERIOD)
2368 else if (wParam == VK_DIVIDE)
2373 else if (wParam == VK_MULTIPLY)
2377 VT_ProcessKeyPress (c);
2385 VT_ProcessButton3Release();
2388 case WM_LBUTTONDOWN:
2389 case WM_MBUTTONDOWN:
2390 case WM_RBUTTONDOWN:
2392 WPARAM fwKeys = wParam;
2396 X_ButtonPress = LOWORD(lParam);
2397 Y_ButtonPress = HIWORD(lParam);
2399 if (Msg == WM_LBUTTONDOWN)
2401 if ((fwKeys & MK_CONTROL) != 0)
2403 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2407 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2410 else if (Msg == WM_RBUTTONDOWN)
2413 VT_ProcessButton3Press();
2420 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2421 if (wParam & MK_CONTROL)
2423 if (aView->Camera()->IsStereo())
2425 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2429 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2436 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2443 //cout << "\t WM_MOUSEMOVE" << endl;
2444 WPARAM fwKeys = wParam;
2445 X_Motion = LOWORD(lParam);
2446 Y_Motion = HIWORD(lParam);
2449 (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 )
2452 X_ButtonPress = LOWORD(lParam);
2453 Y_ButtonPress = HIWORD(lParam);
2455 if ((fwKeys & MK_RBUTTON) != 0) {
2457 VT_ProcessButton3Press();
2461 if ((fwKeys & MK_CONTROL) != 0)
2463 if ((fwKeys & MK_LBUTTON) != 0)
2465 ProcessControlButton1Motion();
2467 else if ((fwKeys & MK_MBUTTON) != 0
2468 || ((fwKeys & MK_LBUTTON) != 0
2469 && (fwKeys & MK_RBUTTON) != 0))
2471 VT_ProcessControlButton2Motion();
2473 else if ((fwKeys & MK_RBUTTON) != 0)
2475 VT_ProcessControlButton3Motion();
2478 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2486 return DefWindowProcW (hwnd, Msg, wParam, lParam);
2491 //==============================================================================
2492 //function : ViewerMainLoop
2493 //purpose : Get a Event on the view and dispatch it
2494 //==============================================================================
2497 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2499 Ppick = (argc > 0)? 1 : 0;
2507 cout << "Start picking" << endl;
2509 while ( Ppick == 1 ) {
2510 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2511 if (GetMessageW (&msg, NULL, 0, 0))
2513 TranslateMessage (&msg);
2514 DispatchMessageW (&msg);
2518 cout << "Picking done" << endl;
2524 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2526 int min( int a, int b )
2534 int max( int a, int b )
2542 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2545 static XEvent aReport;
2546 Standard_Boolean pick = argc > 0;
2547 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2548 XNextEvent (aDisplay, &aReport);
2550 // Handle event for the chosen display connection
2551 switch (aReport.type) {
2554 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2557 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2563 // Activate inactive view
2564 Window aWindow = GetWindowHandle(VT_GetWindow());
2565 if(aWindow != aReport.xfocus.window)
2567 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2576 case ConfigureNotify:
2578 VT_ProcessConfigure();
2587 XComposeStatus status_in_out;
2589 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2590 (char *) buf_ret , 10 ,
2591 &ks_ret , &status_in_out ) ;
2594 buf_ret[ret_len] = '\0' ;
2598 VT_ProcessKeyPress (buf_ret);
2604 X_ButtonPress = aReport.xbutton.x;
2605 Y_ButtonPress = aReport.xbutton.y;
2607 if (aReport.xbutton.button == Button1)
2609 if (aReport.xbutton.state & ControlMask)
2611 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2615 IsDragged = Standard_True;
2616 DragFirst = Standard_True;
2619 else if (aReport.xbutton.button == Button3)
2622 VT_ProcessButton3Press();
2632 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2634 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2635 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2639 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2640 if( aContext.IsNull() )
2642 cout << "The context is null. Please use vinit before createmesh" << endl;
2646 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2647 if( aReport.xbutton.button==1 )
2651 aContext->ShiftSelect (Standard_True);
2655 aContext->Select (Standard_True);
2660 aContext->ShiftSelect(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2661 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2662 ViewerTest::CurrentView(), Standard_True);
2666 aContext->Select(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2667 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2668 ViewerTest::CurrentView(), Standard_True);
2671 VT_ProcessButton3Release();
2673 IsDragged = Standard_False;
2676 VT_ProcessButton3Release();
2681 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2689 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2691 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2695 X_Motion = aReport.xmotion.x;
2696 Y_Motion = aReport.xmotion.y;
2697 DragFirst = Standard_False;
2699 Window aWindow = GetWindowHandle(VT_GetWindow());
2702 unsigned int aWidth, aHeight, aBorderWidth, aDepth;
2703 XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth);
2704 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2705 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed);
2706 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2710 X_Motion = aReport.xmotion.x;
2711 Y_Motion = aReport.xmotion.y;
2713 // remove all the ButtonMotionMaskr
2714 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2716 if ( aReport.xmotion.state & ControlMask ) {
2717 if ( aReport.xmotion.state & Button1Mask ) {
2718 ProcessControlButton1Motion();
2720 else if ( aReport.xmotion.state & Button2Mask ) {
2721 VT_ProcessControlButton2Motion();
2723 else if ( aReport.xmotion.state & Button3Mask ) {
2724 VT_ProcessControlButton3Motion();
2738 //==============================================================================
2739 //function : VProcessEvents
2740 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2741 // event in the Viewer window
2742 //==============================================================================
2744 static void VProcessEvents(ClientData,int)
2746 NCollection_Vector<int> anEventNumbers;
2747 // Get number of messages from every display
2748 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2749 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2751 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2753 // Handle events for every display
2754 int anEventIter = 0;
2755 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2756 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2758 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2759 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2761 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2762 int anEventResult = ViewerMainLoop( 0, NULL);
2763 // If window is closed or context was not found finish current event processing loop
2769 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2774 //==============================================================================
2775 //function : OSWindowSetup
2776 //purpose : Setup for the X11 window to be able to cath the event
2777 //==============================================================================
2780 static void OSWindowSetup()
2782 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2785 Window window = VT_GetWindow()->XWindow();
2786 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2787 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2788 XSynchronize(aDisplay, 1);
2790 // X11 : For keyboard on SUN
2792 wmhints.flags = InputHint;
2795 XSetWMHints( aDisplay, window, &wmhints);
2797 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2798 ButtonPressMask | ButtonReleaseMask |
2799 StructureNotifyMask |
2801 Button1MotionMask | Button2MotionMask |
2802 Button3MotionMask | FocusChangeMask
2804 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2805 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2807 XSynchronize(aDisplay, 0);
2815 //==============================================================================
2818 //==============================================================================
2820 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
2822 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2825 std::cout << "Error: no active viewer!\n";
2829 Standard_Boolean toFit = Standard_True;
2830 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2831 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2833 TCollection_AsciiString anArg (theArgv[anArgIter]);
2835 if (anUpdateTool.parseRedrawMode (anArg))
2839 else if (anArg == "-selected")
2841 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
2842 toFit = Standard_False;
2846 std::cout << "Syntax error at '" << anArg << "'\n";
2852 aView->FitAll (0.01, Standard_False);
2857 //=======================================================================
2858 //function : VFitArea
2859 //purpose : Fit view to show area located between two points
2860 // : given in world 2D or 3D coordinates.
2861 //=======================================================================
2862 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2864 Handle(V3d_View) aView = ViewerTest::CurrentView();
2867 std::cerr << theArgVec[0] << "Error: No active view.\n";
2872 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2873 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2877 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2878 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2879 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2880 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2882 else if (theArgNb == 7)
2884 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2885 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2886 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2887 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2888 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2889 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2893 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2894 theDI.PrintHelp(theArgVec[0]);
2898 // Convert model coordinates to view space
2899 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2900 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2901 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2903 // Determine fit area
2904 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2905 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2907 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2909 if (aDiagonal < Precision::Confusion())
2911 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2915 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2919 //==============================================================================
2921 //purpose : ZFitall, no DRAW arguments
2922 //Draw arg : No args
2923 //==============================================================================
2924 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2926 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2928 if (aCurrentView.IsNull())
2930 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2936 aCurrentView->ZFitAll();
2937 aCurrentView->Redraw();
2941 Standard_Real aScale = 1.0;
2945 aScale = Draw::Atoi (theArgVec[1]);
2948 aCurrentView->ZFitAll (aScale);
2949 aCurrentView->Redraw();
2954 //==============================================================================
2955 //function : VRepaint
2957 //==============================================================================
2958 static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
2960 Handle(V3d_View) aView = ViewerTest::CurrentView();
2963 std::cout << "Error: no active viewer!\n";
2967 Standard_Boolean isImmediateUpdate = Standard_False;
2968 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2970 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2972 if (anArg == "-immediate")
2974 isImmediateUpdate = Standard_True;
2975 if (anArgIter + 1 < theArgNb
2976 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
2983 std::cout << "Syntax error at '" << anArg << "'\n";
2987 if (isImmediateUpdate)
2989 aView->RedrawImmediate();
2998 //==============================================================================
3000 //purpose : Remove all the object from the viewer
3001 //Draw arg : No args
3002 //==============================================================================
3004 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
3006 Handle(V3d_View) V = ViewerTest::CurrentView();
3008 ViewerTest::Clear();
3012 //==============================================================================
3015 //==============================================================================
3017 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3018 { if (ViewerTest::CurrentView().IsNull() ) return 1;
3021 di << argv[0] << "Invalid number of arguments\n";
3025 while (ViewerMainLoop( argc, argv)) {
3031 //==============================================================================
3033 //purpose : Load image as background
3034 //==============================================================================
3036 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3038 if (argc < 2 || argc > 3)
3040 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n";
3041 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n";
3045 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3046 if(AISContext.IsNull())
3048 di << "use 'vinit' command before " << argv[0] << "\n";
3052 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
3055 const char* szType = argv[2];
3056 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
3057 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
3058 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
3059 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
3062 di << "Wrong fill type : " << szType << "\n";
3063 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
3068 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3069 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
3074 //==============================================================================
3075 //function : VSetBgMode
3076 //purpose : Change background image fill type
3077 //==============================================================================
3079 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3083 di << "Usage : " << argv[0] << " filltype : Change background image mode\n";
3084 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n";
3088 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3089 if(AISContext.IsNull())
3091 di << "use 'vinit' command before " << argv[0] << "\n";
3094 Aspect_FillMethod aFillType = Aspect_FM_NONE;
3095 const char* szType = argv[1];
3096 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
3097 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
3098 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
3099 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
3102 di << "Wrong fill type : " << szType << "\n";
3103 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
3106 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3107 V3dView->SetBgImageStyle(aFillType, Standard_True);
3111 //==============================================================================
3112 //function : VSetGradientBg
3113 //purpose : Mount gradient background
3114 //==============================================================================
3115 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3119 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background\n";
3120 di << "R1,G1,B1,R2,G2,B2 = [0..255]\n";
3121 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3122 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3126 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3127 if(AISContext.IsNull())
3129 di << "use 'vinit' command before " << argv[0] << "\n";
3135 Standard_Real R1 = Draw::Atof(argv[1])/255.;
3136 Standard_Real G1 = Draw::Atof(argv[2])/255.;
3137 Standard_Real B1 = Draw::Atof(argv[3])/255.;
3138 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
3140 Standard_Real R2 = Draw::Atof(argv[4])/255.;
3141 Standard_Real G2 = Draw::Atof(argv[5])/255.;
3142 Standard_Real B2 = Draw::Atof(argv[6])/255.;
3144 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
3145 int aType = Draw::Atoi(argv[7]);
3146 if( aType < 0 || aType > 8 )
3148 di << "Wrong fill type \n";
3149 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3150 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3154 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
3156 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3157 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
3163 //==============================================================================
3164 //function : VSetGradientBgMode
3165 //purpose : Change gradient background fill style
3166 //==============================================================================
3167 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3171 di << "Usage : " << argv[0] << " Type : Change gradient background fill type\n";
3172 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3173 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3177 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3178 if(AISContext.IsNull())
3180 di << "use 'vinit' command before " << argv[0] << "\n";
3185 int aType = Draw::Atoi(argv[1]);
3186 if( aType < 0 || aType > 8 )
3188 di << "Wrong fill type \n";
3189 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3190 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3194 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
3196 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3197 V3dView->SetBgGradientStyle( aMethod, 1 );
3203 //==============================================================================
3204 //function : VSetColorBg
3205 //purpose : Set color background
3206 //==============================================================================
3207 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3211 di << "Usage : " << argv[0] << " R G B : Set color background\n";
3212 di << "R,G,B = [0..255]\n";
3216 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3217 if(AISContext.IsNull())
3219 di << "use 'vinit' command before " << argv[0] << "\n";
3225 Standard_Real R = Draw::Atof(argv[1])/255.;
3226 Standard_Real G = Draw::Atof(argv[2])/255.;
3227 Standard_Real B = Draw::Atof(argv[3])/255.;
3228 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
3230 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3231 V3dView->SetBackgroundColor( aColor );
3238 //==============================================================================
3239 //function : VSetDefaultBg
3240 //purpose : Set default viewer background fill color
3241 //==============================================================================
3242 static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3247 std::cout << "Error: wrong syntax! See usage:\n";
3248 theDI.PrintHelp (theArgVec[0]);
3252 ViewerTest_DefaultBackground.FillMethod =
3253 theArgNb == 4 ? Aspect_GFM_NONE
3254 : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]);
3258 Standard_Real R = Draw::Atof (theArgVec[1]) / 255.;
3259 Standard_Real G = Draw::Atof (theArgVec[2]) / 255.;
3260 Standard_Real B = Draw::Atof (theArgVec[3]) / 255.;
3261 ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB);
3265 Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.;
3266 Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.;
3267 Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.;
3268 ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB);
3270 Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.;
3271 Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.;
3272 Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.;
3273 ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB);
3276 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
3277 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
3279 const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer();
3280 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
3281 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
3282 ViewerTest_DefaultBackground.GradientColor2,
3283 ViewerTest_DefaultBackground.FillMethod);
3289 //==============================================================================
3291 //purpose : View Scaling
3292 //==============================================================================
3294 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3296 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3297 if ( V3dView.IsNull() ) return 1;
3300 di << argv[0] << "Invalid number of arguments\n";
3303 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
3306 //==============================================================================
3307 //function : VZBuffTrihedron
3309 //==============================================================================
3311 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
3312 Standard_Integer theArgNb,
3313 const char** theArgVec)
3315 Handle(V3d_View) aView = ViewerTest::CurrentView();
3318 std::cout << "Error: no active viewer!\n";
3322 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
3324 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
3325 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
3326 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
3327 Quantity_Color anArrowColorX = Quantity_NOC_RED;
3328 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
3329 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
3330 Standard_Real aScale = 0.1;
3331 Standard_Real aSizeRatio = 0.8;
3332 Standard_Real anArrowDiam = 0.05;
3333 Standard_Integer aNbFacets = 12;
3334 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3336 Standard_CString anArg = theArgVec[anArgIter];
3337 TCollection_AsciiString aFlag (anArg);
3339 if (anUpdateTool.parseRedrawMode (aFlag))
3343 else if (aFlag == "-on")
3347 else if (aFlag == "-off")
3349 aView->TriedronErase();
3352 else if (aFlag == "-pos"
3353 || aFlag == "-position"
3354 || aFlag == "-corner")
3356 if (++anArgIter >= theArgNb)
3358 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3362 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3363 aPosName.LowerCase();
3364 if (aPosName == "center")
3366 aPosition = Aspect_TOTP_CENTER;
3368 else if (aPosName == "left_lower"
3369 || aPosName == "lower_left"
3370 || aPosName == "leftlower"
3371 || aPosName == "lowerleft")
3373 aPosition = Aspect_TOTP_LEFT_LOWER;
3375 else if (aPosName == "left_upper"
3376 || aPosName == "upper_left"
3377 || aPosName == "leftupper"
3378 || aPosName == "upperleft")
3380 aPosition = Aspect_TOTP_LEFT_UPPER;
3382 else if (aPosName == "right_lower"
3383 || aPosName == "lower_right"
3384 || aPosName == "rightlower"
3385 || aPosName == "lowerright")
3387 aPosition = Aspect_TOTP_RIGHT_LOWER;
3389 else if (aPosName == "right_upper"
3390 || aPosName == "upper_right"
3391 || aPosName == "rightupper"
3392 || aPosName == "upperright")
3394 aPosition = Aspect_TOTP_RIGHT_UPPER;
3398 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3402 else if (aFlag == "-type")
3404 if (++anArgIter >= theArgNb)
3406 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3410 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3411 aTypeName.LowerCase();
3412 if (aTypeName == "wireframe"
3413 || aTypeName == "wire")
3415 aVisType = V3d_WIREFRAME;
3417 else if (aTypeName == "zbuffer"
3418 || aTypeName == "shaded")
3420 aVisType = V3d_ZBUFFER;
3424 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3427 else if (aFlag == "-scale")
3429 if (++anArgIter >= theArgNb)
3431 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3435 aScale = Draw::Atof (theArgVec[anArgIter]);
3437 else if (aFlag == "-size"
3438 || aFlag == "-sizeratio")
3440 if (++anArgIter >= theArgNb)
3442 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3446 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3448 else if (aFlag == "-arrowdiam"
3449 || aFlag == "-arrowdiameter")
3451 if (++anArgIter >= theArgNb)
3453 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3457 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3459 else if (aFlag == "-nbfacets")
3461 if (++anArgIter >= theArgNb)
3463 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3467 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3469 else if (aFlag == "-colorlabel"
3470 || aFlag == "-colorlabels")
3472 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3473 theArgVec + anArgIter + 1,
3477 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3480 anArgIter += aNbParsed;
3482 else if (aFlag == "-colorarrowx")
3484 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3485 theArgVec + anArgIter + 1,
3489 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3492 anArgIter += aNbParsed;
3494 else if (aFlag == "-colorarrowy")
3496 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3497 theArgVec + anArgIter + 1,
3501 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3504 anArgIter += aNbParsed;
3506 else if (aFlag == "-colorarrowz")
3508 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3509 theArgVec + anArgIter + 1,
3513 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3516 anArgIter += aNbParsed;
3520 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3525 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3526 aSizeRatio, anArrowDiam, aNbFacets);
3527 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
3532 //==============================================================================
3533 //function : VRotate
3534 //purpose : Camera Rotating
3535 //==============================================================================
3537 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3539 Handle(V3d_View) aView = ViewerTest::CurrentView();
3542 std::cout << "No active view!\n";
3546 Standard_Boolean hasFlags = Standard_False;
3547 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3549 Standard_CString anArg (theArgVec[anArgIter]);
3550 TCollection_AsciiString aFlag (anArg);
3552 if (aFlag == "-mousestart"
3553 || aFlag == "-mousefrom")
3555 hasFlags = Standard_True;
3556 if (anArgIter + 2 >= theArgNb)
3558 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3562 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3563 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3564 aView->StartRotation (anX, anY);
3566 else if (aFlag == "-mousemove")
3568 hasFlags = Standard_True;
3569 if (anArgIter + 2 >= theArgNb)
3571 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3575 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3576 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3577 aView->Rotation (anX, anY);
3579 else if (theArgNb != 4
3582 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3591 else if (theArgNb == 4)
3593 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3594 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3595 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3596 aView->Rotate (anAX, anAY, anAZ);
3599 else if (theArgNb == 7)
3601 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3602 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3603 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3605 Standard_Real anX = Draw::Atof (theArgVec[4]);
3606 Standard_Real anY = Draw::Atof (theArgVec[5]);
3607 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3609 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3613 std::cout << "Error: Invalid number of arguments\n";
3617 //==============================================================================
3619 //purpose : View zoom in / out (relative to current zoom)
3620 //==============================================================================
3622 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3623 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3624 if ( V3dView.IsNull() ) {
3629 Standard_Real coef = Draw::Atof(argv[1]);
3630 if ( coef <= 0.0 ) {
3631 di << argv[1] << "Invalid value\n";
3634 V3dView->SetZoom( Draw::Atof(argv[1]) );
3637 di << argv[0] << " Invalid number of arguments\n";
3642 //==============================================================================
3644 //purpose : View panning (in pixels)
3645 //==============================================================================
3647 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3648 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3649 if ( V3dView.IsNull() ) return 1;
3652 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
3655 di << argv[0] << " Invalid number of arguments\n";
3660 //==============================================================================
3662 //purpose : Place the point (in pixels) at the center of the window
3663 //==============================================================================
3664 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3666 Handle(V3d_View) aView = ViewerTest::CurrentView();
3669 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3675 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3679 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3684 static int VColorScale (Draw_Interpretor& theDI,
3685 Standard_Integer theArgNb,
3686 const char** theArgVec)
3688 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3689 Handle(V3d_View) aView = ViewerTest::CurrentView();
3690 if (aContext.IsNull())
3692 std::cout << "Error: no active view!\n";
3697 std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n";
3701 Handle(AIS_ColorScale) aColorScale;
3702 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
3704 // find existing object
3705 aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
3706 if (aColorScale.IsNull())
3708 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
3715 if (aColorScale.IsNull())
3717 std::cout << "Syntax error: colorscale with a given name does not exist.\n";
3721 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
3722 << "Min range: " << aColorScale->GetMin() << "\n"
3723 << "Max range: " << aColorScale->GetMax() << "\n"
3724 << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n"
3725 << "Text height: " << aColorScale->GetTextHeight() << "\n"
3726 << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n"
3727 << "Color scale title: " << aColorScale->GetTitle() << "\n"
3728 << "Label position: ";
3729 switch (aColorScale->GetLabelPosition())
3731 case Aspect_TOCSP_NONE:
3734 case Aspect_TOCSP_LEFT:
3737 case Aspect_TOCSP_RIGHT:
3740 case Aspect_TOCSP_CENTER:
3741 theDI << "Center\n";
3747 if (aColorScale.IsNull())
3749 aColorScale = new AIS_ColorScale();
3750 aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
3751 aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
3754 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
3755 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
3757 Standard_CString anArg = theArgVec[anArgIter];
3758 TCollection_AsciiString aFlag (anArg);
3760 if (anUpdateTool.parseRedrawMode (aFlag))
3764 else if (aFlag == "-range")
3766 if (anArgIter + 3 >= theArgNb)
3768 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3772 const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]);
3773 const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]);
3774 const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]);
3775 if (!aRangeMin.IsRealValue()
3776 || !aRangeMax.IsRealValue())
3778 std::cout << "Error: the range values should be real!\n";
3781 else if (!aNbIntervals.IsIntegerValue())
3783 std::cout << "Error: the number of intervals should be integer!\n";
3787 aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue());
3788 aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue());
3790 else if (aFlag == "-font")
3792 if (anArgIter + 1 >= theArgNb)
3794 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3797 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
3798 if (!aFontArg.IsIntegerValue())
3800 std::cout << "Error: HeightFont value should be integer!\n";
3804 aColorScale->SetTextHeight (aFontArg.IntegerValue());
3807 else if (aFlag == "-textpos")
3809 if (anArgIter + 1 >= theArgNb)
3811 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3815 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
3816 aTextPosArg.LowerCase();
3817 Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE;
3818 if (aTextPosArg == "none")
3820 aLabPosition = Aspect_TOCSP_NONE;
3822 else if (aTextPosArg == "left")
3824 aLabPosition = Aspect_TOCSP_LEFT;
3826 else if (aTextPosArg == "right")
3828 aLabPosition = Aspect_TOCSP_RIGHT;
3830 else if (aTextPosArg == "center")
3832 aLabPosition = Aspect_TOCSP_CENTER;
3836 std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
3839 aColorScale->SetLabelPosition (aLabPosition);
3841 else if (aFlag == "-logarithmic"
3844 if (anArgIter + 1 >= theArgNb)
3846 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3850 Standard_Boolean IsLog;
3851 if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
3853 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3856 aColorScale->SetLogarithmic (IsLog);
3858 else if (aFlag == "-huerange"
3861 if (anArgIter + 2 >= theArgNb)
3863 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3867 const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]);
3868 const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]);
3869 aColorScale->SetHueRange (aHueMin, aHueMax);
3871 else if (aFlag == "-colorrange")
3873 Quantity_Color aColorMin, aColorMax;
3874 Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3875 theArgVec + (anArgIter + 1),
3877 anArgIter += aNbParsed1;
3878 Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3879 theArgVec + (anArgIter + 1),
3881 anArgIter += aNbParsed2;
3885 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3889 aColorScale->SetColorRange (aColorMin, aColorMax);
3891 else if (aFlag == "-reversed"
3892 || aFlag == "-inverted"
3893 || aFlag == "-topdown"
3894 || aFlag == "-bottomup")
3896 Standard_Boolean toEnable = Standard_True;
3897 if (anArgIter + 1 < theArgNb
3898 && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable))
3902 aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable);
3904 else if (aFlag == "-smooth"
3905 || aFlag == "-smoothtransition")
3907 Standard_Boolean toEnable = Standard_True;
3908 if (anArgIter + 1 < theArgNb
3909 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
3913 aColorScale->SetSmoothTransition (toEnable);
3915 else if (aFlag == "-xy")
3917 if (anArgIter + 2 >= theArgNb)
3919 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3923 const TCollection_AsciiString anX (theArgVec[++anArgIter]);
3924 const TCollection_AsciiString anY (theArgVec[++anArgIter]);
3925 if (!anX.IsIntegerValue()
3926 || !anY.IsIntegerValue())
3928 std::cout << "Error: coordinates should be integer values!\n";
3932 aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue());
3934 else if (aFlag == "-width"
3936 || aFlag == "-breadth")
3938 if (anArgIter + 1 >= theArgNb)
3940 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3944 const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]);
3945 if (!aBreadth.IsIntegerValue())
3947 std::cout << "Error: a width should be an integer value!\n";
3950 aColorScale->SetBreadth (aBreadth.IntegerValue());
3952 else if (aFlag == "-height"
3955 if (anArgIter + 1 >= theArgNb)
3957 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3961 const TCollection_AsciiString aHeight (theArgVec[++anArgIter]);
3962 if (!aHeight.IsIntegerValue())
3964 std::cout << "Error: a width should be an integer value!\n";
3967 aColorScale->SetHeight (aHeight.IntegerValue());
3969 else if (aFlag == "-color")
3971 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
3973 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3976 else if (anArgIter + 2 >= theArgNb)
3978 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3982 const TCollection_AsciiString anInd (theArgVec[++anArgIter]);
3983 if (!anInd.IsIntegerValue())
3985 std::cout << "Error: Index value should be integer!\n";
3988 const Standard_Integer anIndex = anInd.IntegerValue();
3989 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals())
3991 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() <<"!\n";
3995 Quantity_Color aColor;
3996 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3997 theArgVec + (anArgIter + 1),
4001 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4004 aColorScale->SetIntervalColor (aColor, anIndex);
4005 aColorScale->SetColorType (Aspect_TOCSD_USER);
4006 anArgIter += aNbParsed;
4008 else if (aFlag == "-label")
4010 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
4012 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
4015 else if (anArgIter + 2 >= theArgNb)
4017 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4021 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
4022 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1)
4024 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() + 1 <<"!\n";
4028 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
4029 aColorScale->SetLabel (aText, anIndex);
4030 aColorScale->SetLabelType (Aspect_TOCSD_USER);
4033 else if (aFlag == "-labelat"
4034 || aFlag == "-labat"
4035 || aFlag == "-labelatborder"
4036 || aFlag == "-labatborder"
4037 || aFlag == "-labelatcenter"
4038 || aFlag == "-labatcenter")
4040 Standard_Boolean toEnable = Standard_True;
4041 if (aFlag == "-labelat"
4042 || aFlag == "-labat")
4044 Standard_Integer aLabAtBorder = -1;
4045 if (++anArgIter >= theArgNb)
4047 TCollection_AsciiString anAtBorder (theArgVec[anArgIter]);
4048 anAtBorder.LowerCase();
4049 if (anAtBorder == "border")
4053 else if (anAtBorder == "center")
4058 if (aLabAtBorder == -1)
4060 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4063 toEnable = (aLabAtBorder == 1);
4065 else if (anArgIter + 1 < theArgNb
4066 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
4070 aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter"
4071 || aFlag == "-labatcenter"
4075 else if (aFlag == "-colors")
4077 Aspect_SequenceOfColor aSeq;
4080 Quantity_Color aColor;
4081 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4082 theArgVec + (anArgIter + 1),
4088 anArgIter += aNbParsed;
4089 aSeq.Append (aColor);
4091 if (aSeq.Length() != aColorScale->GetNumberOfIntervals())
4093 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
4094 << aColorScale->GetNumberOfIntervals() << " intervals\n";
4098 aColorScale->SetColors (aSeq);
4099 aColorScale->SetColorType (Aspect_TOCSD_USER);
4101 else if (aFlag == "-labels"
4102 || aFlag == "-freelabels")
4104 if (anArgIter + 1 >= theArgNb)
4106 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4110 Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder()
4111 ? aColorScale->GetNumberOfIntervals() + 1
4112 : aColorScale->GetNumberOfIntervals();
4113 if (aFlag == "-freelabels")
4116 aNbLabels = Draw::Atoi (theArgVec[anArgIter]);
4118 if (anArgIter + aNbLabels >= theArgNb)
4120 std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n";
4124 TColStd_SequenceOfExtendedString aSeq;
4125 for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter)
4127 aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter]));
4129 aColorScale->SetLabels (aSeq);
4130 aColorScale->SetLabelType (Aspect_TOCSD_USER);
4132 else if (aFlag == "-title")
4134 if (anArgIter + 1 >= theArgNb)
4136 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4140 Standard_Boolean isTwoArgs = Standard_False;
4141 if (anArgIter + 2 < theArgNb)
4143 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
4144 aSecondArg.LowerCase();
4145 Standard_DISABLE_DEPRECATION_WARNINGS
4146 if (aSecondArg == "none")
4148 aColorScale->SetTitlePosition (Aspect_TOCSP_NONE);
4149 isTwoArgs = Standard_True;
4151 else if (aSecondArg == "left")
4153 aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT);
4154 isTwoArgs = Standard_True;
4156 else if (aSecondArg == "right")
4158 aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT);
4159 isTwoArgs = Standard_True;
4161 else if (aSecondArg == "center")
4163 aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER);
4164 isTwoArgs = Standard_True;
4166 Standard_ENABLE_DEPRECATION_WARNINGS
4169 aColorScale->SetTitle (theArgVec[anArgIter + 1]);
4176 else if (aFlag == "-demoversion"
4177 || aFlag == "-demo")
4179 aColorScale->SetPosition (0, 0);
4180 aColorScale->SetTextHeight (16);
4181 aColorScale->SetRange (0.0, 100.0);
4182 aColorScale->SetNumberOfIntervals (10);
4183 aColorScale->SetBreadth (0);
4184 aColorScale->SetHeight (0);
4185 aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT);
4186 aColorScale->SetColorType (Aspect_TOCSD_AUTO);
4187 aColorScale->SetLabelType (Aspect_TOCSD_AUTO);
4189 else if (aFlag == "-findcolor")
4191 if (anArgIter + 1 >= theArgNb)
4193 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4197 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
4199 if (!anArg1.IsRealValue())
4201 std::cout << "Error: the value should be real!\n";
4205 Quantity_Color aColor;
4206 aColorScale->FindColor (anArg1.RealValue(), aColor);
4207 theDI << Quantity_Color::StringName (aColor.Name());
4212 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
4217 Standard_Integer aWinWidth = 0, aWinHeight = 0;
4218 aView->Window()->Size (aWinWidth, aWinHeight);
4219 if (aColorScale->GetBreadth() == 0)
4221 aColorScale->SetBreadth (aWinWidth);
4223 if (aColorScale->GetHeight() == 0)
4225 aColorScale->SetHeight (aWinHeight);
4227 aColorScale->SetToUpdate();
4228 ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True);
4232 //==============================================================================
4233 //function : VGraduatedTrihedron
4234 //purpose : Displays or hides a graduated trihedron
4235 //==============================================================================
4236 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
4237 Quantity_Color& theColor)
4239 Quantity_NameOfColor aColorName;
4240 TCollection_AsciiString aVal = theValue;
4242 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
4244 return Standard_False;
4246 theColor = Quantity_Color (aColorName);
4247 return Standard_True;
4250 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
4254 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
4255 << theArgs[0] <<"' for more information.\n";
4256 return 1; //TCL_ERROR
4259 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
4260 TCollection_AsciiString aParseKey;
4261 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
4263 TCollection_AsciiString anArg (theArgs [anArgIt]);
4265 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
4268 aParseKey.Remove (1);
4269 aParseKey.LowerCase();
4270 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
4274 if (aParseKey.IsEmpty())
4279 aMapOfArgs(aParseKey)->Append (anArg);
4283 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
4284 aMapIt.More(); aMapIt.Next())
4286 const TCollection_AsciiString& aKey = aMapIt.Key();
4287 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
4289 // Bool key, without arguments
4290 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
4291 && anArgs->IsEmpty())
4297 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
4298 && anArgs->Length() == 1)
4304 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
4305 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
4306 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
4307 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
4308 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
4313 // One string argument
4314 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
4315 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
4316 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4321 // One integer argument
4322 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
4323 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
4324 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
4325 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
4326 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
4331 // One real argument
4332 if ( aKey.IsEqual ("arrowlength")
4333 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
4338 // Two string arguments
4339 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
4340 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4345 TCollection_AsciiString aLowerKey;
4348 aLowerKey.LowerCase();
4349 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
4350 std::cout << "Type help for more information.\n";
4354 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4355 if (anAISContext.IsNull())
4357 std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n";
4361 Standard_Boolean toDisplay = Standard_True;
4362 Quantity_Color aColor;
4363 Graphic3d_GraduatedTrihedron aTrihedronData;
4364 // Process parameters
4365 Handle(TColStd_HSequenceOfAsciiString) aValues;
4366 if (aMapOfArgs.Find ("off", aValues))
4368 toDisplay = Standard_False;
4372 if (aMapOfArgs.Find ("xname", aValues))
4374 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
4376 if (aMapOfArgs.Find ("yname", aValues))
4378 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
4380 if (aMapOfArgs.Find ("zname", aValues))
4382 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
4384 if (aMapOfArgs.Find ("xdrawname", aValues))
4386 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4388 if (aMapOfArgs.Find ("ydrawname", aValues))
4390 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4392 if (aMapOfArgs.Find ("zdrawname", aValues))
4394 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4396 if (aMapOfArgs.Find ("xnameoffset", aValues))
4398 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4400 if (aMapOfArgs.Find ("ynameoffset", aValues))
4402 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4404 if (aMapOfArgs.Find ("znameoffset", aValues))
4406 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4410 if (aMapOfArgs.Find ("xnamecolor", aValues))
4412 if (!GetColor (aValues->Value(1), aColor))
4414 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
4417 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
4419 if (aMapOfArgs.Find ("ynamecolor", aValues))
4421 if (!GetColor (aValues->Value(1), aColor))
4423 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
4426 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
4428 if (aMapOfArgs.Find ("znamecolor", aValues))
4430 if (!GetColor (aValues->Value(1), aColor))
4432 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
4435 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
4437 if (aMapOfArgs.Find ("xcolor", aValues))
4439 if (!GetColor (aValues->Value(1), aColor))
4441 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
4444 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
4446 if (aMapOfArgs.Find ("ycolor", aValues))
4448 if (!GetColor (aValues->Value(1), aColor))
4450 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
4453 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
4455 if (aMapOfArgs.Find ("zcolor", aValues))
4457 if (!GetColor (aValues->Value(1), aColor))
4459 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
4462 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
4466 if (aMapOfArgs.Find ("xticks", aValues))
4468 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4470 if (aMapOfArgs.Find ("yticks", aValues))
4472 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4474 if (aMapOfArgs.Find ("zticks", aValues))
4476 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4478 if (aMapOfArgs.Find ("xticklength", aValues))
4480 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4482 if (aMapOfArgs.Find ("yticklength", aValues))
4484 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4486 if (aMapOfArgs.Find ("zticklength", aValues))
4488 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4490 if (aMapOfArgs.Find ("xdrawticks", aValues))
4492 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4494 if (aMapOfArgs.Find ("ydrawticks", aValues))
4496 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4498 if (aMapOfArgs.Find ("zdrawticks", aValues))
4500 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4504 if (aMapOfArgs.Find ("xdrawvalues", aValues))
4506 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4508 if (aMapOfArgs.Find ("ydrawvalues", aValues))
4510 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4512 if (aMapOfArgs.Find ("zdrawvalues", aValues))
4514 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4516 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
4518 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4520 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
4522 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4524 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
4526 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4530 if (aMapOfArgs.Find ("arrowlength", aValues))
4532 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
4536 if (aMapOfArgs.Find ("namefont", aValues))
4538 aTrihedronData.SetNamesFont (aValues->Value(1));
4540 if (aMapOfArgs.Find ("valuesfont", aValues))
4542 aTrihedronData.SetValuesFont (aValues->Value(1));
4545 if (aMapOfArgs.Find ("drawgrid", aValues))
4547 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
4549 if (aMapOfArgs.Find ("drawaxes", aValues))
4551 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
4554 // The final step: display of erase trihedron
4557 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
4561 ViewerTest::CurrentView()->GraduatedTrihedronErase();
4564 ViewerTest::GetAISContext()->UpdateCurrentViewer();
4565 ViewerTest::CurrentView()->Redraw();
4570 //==============================================================================
4573 //==============================================================================
4574 static int VTile (Draw_Interpretor& theDI,
4575 Standard_Integer theArgNb,
4576 const char** theArgVec)
4578 Handle(V3d_View) aView = ViewerTest::CurrentView();
4581 std::cerr << "Error: no active viewer.\n";
4585 Graphic3d_CameraTile aTile = aView->Camera()->Tile();
4588 theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
4589 << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n"
4590 << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n";
4594 aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
4595 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4597 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4599 if (anArg == "-lowerleft"
4600 || anArg == "-upperleft")
4602 if (anArgIter + 3 < theArgNb)
4604 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4607 aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
4608 aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4609 aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4611 else if (anArg == "-total"
4612 || anArg == "-totalsize"
4613 || anArg == "-viewsize")
4615 if (anArgIter + 3 < theArgNb)
4617 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4620 aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4621 aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4622 if (aTile.TotalSize.x() < 1
4623 || aTile.TotalSize.y() < 1)
4625 std::cerr << "Error: total size is incorrect.\n";
4629 else if (anArg == "-tilesize")
4631 if (anArgIter + 3 < theArgNb)
4633 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4637 aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4638 aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4639 if (aTile.TileSize.x() < 1
4640 || aTile.TileSize.y() < 1)
4642 std::cerr << "Error: tile size is incorrect.\n";
4646 else if (anArg == "-unset")
4648 aView->Camera()->SetTile (Graphic3d_CameraTile());
4654 if (aTile.TileSize.x() < 1
4655 || aTile.TileSize.y() < 1)
4657 std::cerr << "Error: tile size is undefined.\n";
4660 else if (aTile.TotalSize.x() < 1
4661 || aTile.TotalSize.y() < 1)
4663 std::cerr << "Error: total size is undefined.\n";
4667 aView->Camera()->SetTile (aTile);
4672 //! Format ZLayer ID.
4673 inline const char* formZLayerId (const Standard_Integer theLayerId)
4677 case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]";
4678 case Graphic3d_ZLayerId_Default: return "[DEFAULT]";
4679 case Graphic3d_ZLayerId_Top: return "[TOP]";
4680 case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]";
4681 case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]";
4682 case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]";
4687 //! Print the ZLayer information.
4688 inline void printZLayerInfo (Draw_Interpretor& theDI,
4689 const Graphic3d_ZLayerSettings& theLayer)
4691 if (!theLayer.Name().IsEmpty())
4693 theDI << " Name: " << theLayer.Name() << "\n";
4695 if (theLayer.IsImmediate())
4697 theDI << " Immediate: TRUE\n";
4699 theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n";
4700 theDI << " Culling distance: " << theLayer.CullingDistance() << "\n";
4701 theDI << " Culling size: " << theLayer.CullingSize() << "\n";
4702 theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n";
4703 theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n";
4704 theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n";
4705 if (theLayer.PolygonOffset().Mode != Aspect_POM_None)
4707 theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n";
4711 //==============================================================================
4712 //function : VZLayer
4713 //purpose : Test z layer operations for v3d viewer
4714 //==============================================================================
4715 static int VZLayer (Draw_Interpretor& theDI,
4716 Standard_Integer theArgNb,
4717 const char** theArgVec)
4719 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4720 if (aContextAIS.IsNull())
4722 std::cout << "No active viewer!\n";
4726 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
4729 TColStd_SequenceOfInteger aLayers;
4730 aViewer->GetAllZLayers (aLayers);
4731 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4733 theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n";
4734 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4735 printZLayerInfo (theDI, aSettings);
4740 Standard_Integer anArgIter = 1;
4741 Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4742 ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView());
4743 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
4748 TCollection_AsciiString aFirstArg (theArgVec[anArgIter]);
4749 if (aFirstArg.IsIntegerValue())
4752 aLayerId = aFirstArg.IntegerValue();
4756 aFirstArg.LowerCase();
4757 if (aFirstArg == "default"
4758 || aFirstArg == "def")
4760 aLayerId = Graphic3d_ZLayerId_Default;
4763 else if (aFirstArg == "top")
4765 aLayerId = Graphic3d_ZLayerId_Top;
4768 else if (aFirstArg == "topmost")
4770 aLayerId = Graphic3d_ZLayerId_Topmost;
4773 else if (aFirstArg == "overlay"
4774 || aFirstArg == "toposd")
4776 aLayerId = Graphic3d_ZLayerId_TopOSD;
4779 else if (aFirstArg == "underlay"
4780 || aFirstArg == "botosd")
4782 aLayerId = Graphic3d_ZLayerId_BotOSD;
4787 TColStd_SequenceOfInteger aLayers;
4788 aViewer->GetAllZLayers (aLayers);
4789 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4791 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4792 if (TCollection_AsciiString::IsSameString (aSettings.Name(), aFirstArg, Standard_False))
4794 aLayerId = aLayeriter.Value();
4802 for (; anArgIter < theArgNb; ++anArgIter)
4804 // perform operation
4805 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4807 if (anUpdateTool.parseRedrawMode (anArg))
4811 else if (anArg == "-add"
4814 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4815 if (!aViewer->AddZLayer (aLayerId))
4817 std::cout << "Error: can not add a new z layer!\n";
4823 else if (anArg == "-del"
4824 || anArg == "-delete"
4827 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4829 if (++anArgIter >= theArgNb)
4831 std::cout << "Syntax error: id of z layer to remove is missing\n";
4835 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4838 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN
4839 || aLayerId == Graphic3d_ZLayerId_Default
4840 || aLayerId == Graphic3d_ZLayerId_Top
4841 || aLayerId == Graphic3d_ZLayerId_Topmost
4842 || aLayerId == Graphic3d_ZLayerId_TopOSD
4843 || aLayerId == Graphic3d_ZLayerId_BotOSD)
4845 std::cout << "Syntax error: standard Z layer can not be removed\n";
4849 // move all object displayed in removing layer to default layer
4850 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4851 anObjIter.More(); anObjIter.Next())
4853 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1());
4855 || aPrs->ZLayer() != aLayerId)
4859 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4862 if (!aViewer->RemoveZLayer (aLayerId))
4864 std::cout << "Z layer can not be removed!\n";
4868 theDI << aLayerId << " ";
4871 else if (anArg == "-get"
4874 TColStd_SequenceOfInteger aLayers;
4875 aViewer->GetAllZLayers (aLayers);
4876 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4878 theDI << aLayeriter.Value() << " ";
4883 else if (anArg == "-name")
4885 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4887 std::cout << "Syntax error: id of Z layer is missing\n";
4891 if (++anArgIter >= theArgNb)
4893 std::cout << "Syntax error: name is missing\n";
4897 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4898 aSettings.SetName (theArgVec[anArgIter]);
4899 aViewer->SetZLayerSettings (aLayerId, aSettings);
4901 else if (anArg == "-origin")
4903 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4905 std::cout << "Syntax error: id of Z layer is missing\n";
4909 if (anArgIter + 2 >= theArgNb)
4911 std::cout << "Syntax error: origin coordinates are missing\n";
4915 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4917 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1]));
4918 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2]));
4919 anOrigin.SetZ (0.0);
4920 if (anArgIter + 3 < theArgNb)
4922 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3]));
4929 aSettings.SetOrigin (anOrigin);
4930 aViewer->SetZLayerSettings (aLayerId, aSettings);
4932 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
4933 && anArgIter + 1 < theArgNb
4934 && (anArg == "-cullingdistance"
4935 || anArg == "-cullingdist"
4936 || anArg == "-culldistance"
4937 || anArg == "-culldist"
4938 || anArg == "-distcull"
4939 || anArg == "-distculling"
4940 || anArg == "-distanceculling"))
4942 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4943 const Standard_Real aDist = Draw::Atof (theArgVec[++anArgIter]);
4944 aSettings.SetCullingDistance (aDist);
4945 aViewer->SetZLayerSettings (aLayerId, aSettings);
4947 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
4948 && anArgIter + 1 < theArgNb
4949 && (anArg == "-cullingsize"
4950 || anArg == "-cullsize"
4951 || anArg == "-sizecull"
4952 || anArg == "-sizeculling"))
4954 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4955 const Standard_Real aSize = Draw::Atof (theArgVec[++anArgIter]);
4956 aSettings.SetCullingSize (aSize);
4957 aViewer->SetZLayerSettings (aLayerId, aSettings);
4959 else if (anArg == "-settings"
4960 || anArg == "settings")
4962 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4964 if (++anArgIter >= theArgNb)
4966 std::cout << "Syntax error: id of Z layer is missing\n";
4970 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4973 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4974 printZLayerInfo (theDI, aSettings);
4976 else if (anArg == "-enable"
4977 || anArg == "enable"
4978 || anArg == "-disable"
4979 || anArg == "disable")
4981 const Standard_Boolean toEnable = anArg == "-enable"
4982 || anArg == "enable";
4983 if (++anArgIter >= theArgNb)
4985 std::cout << "Syntax error: option name is missing\n";
4989 TCollection_AsciiString aSubOp (theArgVec[anArgIter]);
4991 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4993 if (++anArgIter >= theArgNb)
4995 std::cout << "Syntax error: id of Z layer is missing\n";
4999 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5002 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5003 if (aSubOp == "depthtest"
5004 || aSubOp == "test")
5006 aSettings.SetEnableDepthTest (toEnable);
5008 else if (aSubOp == "depthwrite"
5009 || aSubOp == "write")
5011 aSettings.SetEnableDepthWrite (toEnable);
5013 else if (aSubOp == "depthclear"
5014 || aSubOp == "clear")
5016 aSettings.SetClearDepth (toEnable);
5018 else if (aSubOp == "depthoffset"
5019 || aSubOp == "offset")
5021 Graphic3d_PolygonOffset aParams;
5022 aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None;
5025 if (anArgIter + 2 >= theArgNb)
5027 std::cout << "Syntax error: factor and units values for depth offset are missing\n";
5031 aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5032 aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5034 aSettings.SetPolygonOffset (aParams);
5036 else if (aSubOp == "positiveoffset"
5037 || aSubOp == "poffset")
5041 aSettings.SetDepthOffsetPositive();
5045 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
5048 else if (aSubOp == "negativeoffset"
5049 || aSubOp == "noffset")
5053 aSettings.SetDepthOffsetNegative();
5057 aSettings.SetPolygonOffset(Graphic3d_PolygonOffset());
5060 else if (aSubOp == "textureenv")
5062 aSettings.SetEnvironmentTexture (toEnable);
5065 aViewer->SetZLayerSettings (aLayerId, aSettings);
5069 std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n";
5077 // The interactive presentation of 2d layer item
5078 // for "vlayerline" command it provides a presentation of
5079 // line with user-defined linewidth, linetype and transparency.
5080 class V3d_LineItem : public AIS_InteractiveObject
5084 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
5087 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5088 Standard_Real X2, Standard_Real Y2,
5089 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
5090 Standard_Real theWidth = 0.5,
5091 Standard_Real theTransp = 1.0);
5095 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
5096 const Handle(Prs3d_Presentation)& thePresentation,
5097 const Standard_Integer theMode) Standard_OVERRIDE;
5099 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
5100 const Standard_Integer /*aMode*/) Standard_OVERRIDE
5105 Standard_Real myX1, myY1, myX2, myY2;
5106 Aspect_TypeOfLine myType;
5107 Standard_Real myWidth;
5110 // default constructor for line item
5111 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5112 Standard_Real X2, Standard_Real Y2,
5113 Aspect_TypeOfLine theType,
5114 Standard_Real theWidth,
5115 Standard_Real theTransp) :
5116 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
5117 myType(theType), myWidth(theWidth)
5119 SetTransparency (1-theTransp);
5123 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
5124 const Handle(Prs3d_Presentation)& thePresentation,
5125 const Standard_Integer /*theMode*/)
5127 thePresentation->Clear();
5128 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
5129 Standard_Integer aWidth, aHeight;
5130 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
5131 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
5132 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
5133 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
5134 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
5135 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
5136 aGroup->SetPrimitivesAspect (anAspect->Aspect());
5137 aGroup->AddPrimitiveArray (aPrim);
5140 //=============================================================================
5141 //function : VLayerLine
5142 //purpose : Draws line in the v3d view layer with given attributes: linetype,
5143 // : linewidth, transparency coefficient
5144 //============================================================================
5145 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5147 // get the active view
5148 Handle(V3d_View) aView = ViewerTest::CurrentView();
5151 di << "Call vinit before!\n";
5156 di << "Use: " << argv[0];
5157 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
5158 di << " linetype : { 0 | 1 | 2 | 3 } \n";
5159 di << " 0 - solid \n";
5160 di << " 1 - dashed \n";
5161 di << " 2 - dot \n";
5162 di << " 3 - dashdot\n";
5163 di << " transparency : { 0.0 - 1.0 } \n";
5164 di << " 0.0 - transparent\n";
5165 di << " 1.0 - visible \n";
5169 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5170 // get the input params
5171 Standard_Real X1 = Draw::Atof(argv[1]);
5172 Standard_Real Y1 = Draw::Atof(argv[2]);
5173 Standard_Real X2 = Draw::Atof(argv[3]);
5174 Standard_Real Y2 = Draw::Atof(argv[4]);
5176 Standard_Real aWidth = 0.5;
5177 Standard_Real aTransparency = 1.0;
5181 aWidth = Draw::Atof(argv[5]);
5183 // select appropriate line type
5184 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
5186 && !ViewerTest::ParseLineType (argv[6], aLineType))
5188 std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n";
5195 aTransparency = Draw::Atof(argv[7]);
5196 if (aTransparency < 0 || aTransparency > 1.0)
5197 aTransparency = 1.0;
5200 static Handle (V3d_LineItem) aLine;
5201 if (!aLine.IsNull())
5203 aContext->Erase (aLine, Standard_False);
5205 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
5209 aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
5210 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
5211 aLine->SetToUpdate();
5212 aContext->Display (aLine, Standard_True);
5218 //==============================================================================
5221 //==============================================================================
5223 static int VGrid (Draw_Interpretor& /*theDI*/,
5224 Standard_Integer theArgNb,
5225 const char** theArgVec)
5227 // get the active view
5228 Handle(V3d_View) aView = ViewerTest::CurrentView();
5229 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5230 if (aView.IsNull() || aViewer.IsNull())
5232 std::cerr << "No active view. Please call vinit.\n";
5236 Aspect_GridType aType = aViewer->GridType();
5237 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
5238 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
5239 Standard_Integer anIter = 1;
5240 for (; anIter < theArgNb; ++anIter)
5242 const char* aValue = theArgVec[anIter];
5243 if (anUpdateTool.parseRedrawMode (aValue))
5247 else if (*aValue == 'r')
5249 aType = Aspect_GT_Rectangular;
5251 else if (*aValue == 'c')
5253 aType = Aspect_GT_Circular;
5255 else if (*aValue == 'l')
5257 aMode = Aspect_GDM_Lines;
5259 else if (*aValue == 'p')
5261 aMode = Aspect_GDM_Points;
5263 else if (strcmp (aValue, "off" ) == 0)
5265 aViewer->DeactivateGrid();
5274 Standard_Integer aTail = (theArgNb - anIter);
5277 aViewer->ActivateGrid (aType, aMode);
5280 else if (aTail != 2 && aTail != 5)
5282 std::cerr << "Incorrect arguments number! Usage:\n"
5283 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
5287 Standard_Real anOriginX, anOriginY, aRotAngle;
5288 if (aType == Aspect_GT_Rectangular)
5290 Standard_Real aRStepX, aRStepY;
5291 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
5293 anOriginX = Draw::Atof (theArgVec[anIter++]);
5294 anOriginY = Draw::Atof (theArgVec[anIter++]);
5297 aRStepX = Draw::Atof (theArgVec[anIter++]);
5298 aRStepY = Draw::Atof (theArgVec[anIter++]);
5299 aRotAngle = Draw::Atof (theArgVec[anIter++]);
5301 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
5302 aViewer->ActivateGrid (aType, aMode);
5304 else if (aType == Aspect_GT_Circular)
5306 Standard_Real aRadiusStep;
5307 Standard_Integer aDivisionNumber;
5308 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
5310 anOriginX = Draw::Atof (theArgVec[anIter++]);
5311 anOriginY = Draw::Atof (theArgVec[anIter++]);
5314 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
5315 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
5316 aRotAngle = Draw::Atof (theArgVec[anIter++]);
5319 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
5320 aViewer->ActivateGrid (aType, aMode);
5326 //==============================================================================
5327 //function : VPriviledgedPlane
5329 //==============================================================================
5331 static int VPriviledgedPlane (Draw_Interpretor& theDI,
5332 Standard_Integer theArgNb,
5333 const char** theArgVec)
5335 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
5337 std::cerr << "Error: wrong number of arguments! See usage:\n";
5338 theDI.PrintHelp (theArgVec[0]);
5342 // get the active viewer
5343 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5344 if (aViewer.IsNull())
5346 std::cerr << "Error: no active viewer. Please call vinit.\n";
5352 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
5353 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
5354 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
5355 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
5356 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
5357 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
5358 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
5362 Standard_Integer anArgIdx = 1;
5363 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
5364 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
5365 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
5366 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
5367 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
5368 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
5370 gp_Ax3 aPriviledgedPlane;
5371 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
5372 gp_Dir aNorm (aNormX, aNormY, aNormZ);
5375 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
5376 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
5377 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
5378 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
5379 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
5383 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
5386 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
5391 //==============================================================================
5392 //function : VConvert
5394 //==============================================================================
5396 static int VConvert (Draw_Interpretor& theDI,
5397 Standard_Integer theArgNb,
5398 const char** theArgVec)
5400 // get the active view
5401 Handle(V3d_View) aView = ViewerTest::CurrentView();
5404 std::cerr << "Error: no active view. Please call vinit.\n";
5408 enum { Model, Ray, View, Window, Grid } aMode = Model;
5410 // access coordinate arguments
5411 TColStd_SequenceOfReal aCoord;
5412 Standard_Integer anArgIdx = 1;
5413 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
5415 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5416 if (!anArg.IsRealValue())
5420 aCoord.Append (anArg.RealValue());
5423 // non-numeric argument too early
5424 if (aCoord.IsEmpty())
5426 std::cerr << "Error: wrong number of arguments! See usage:\n";
5427 theDI.PrintHelp (theArgVec[0]);
5431 // collect all other arguments and options
5432 for (; anArgIdx < theArgNb; ++anArgIdx)
5434 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5436 if (anArg == "window") aMode = Window;
5437 else if (anArg == "view") aMode = View;
5438 else if (anArg == "grid") aMode = Grid;
5439 else if (anArg == "ray") aMode = Ray;
5442 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
5443 theDI.PrintHelp (theArgVec[0]);
5448 // complete input checks
5449 if ((aCoord.Length() == 1 && theArgNb > 3) ||
5450 (aCoord.Length() == 2 && theArgNb > 4) ||
5451 (aCoord.Length() == 3 && theArgNb > 5))
5453 std::cerr << "Error: wrong number of arguments! See usage:\n";
5454 theDI.PrintHelp (theArgVec[0]);
5458 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
5459 Standard_Integer aXYp[2] = {0, 0};
5461 // convert one-dimensional coordinate
5462 if (aCoord.Length() == 1)
5466 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0;
5467 case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0;
5469 std::cerr << "Error: wrong arguments! See usage:\n";
5470 theDI.PrintHelp (theArgVec[0]);
5475 // convert 2D coordinates from projection or view reference space
5476 if (aCoord.Length() == 2)
5481 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5482 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5486 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5487 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5491 aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]);
5492 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5496 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5497 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5498 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5502 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5503 (Standard_Integer) aCoord (2),
5504 aXYZ[0], aXYZ[1], aXYZ[2],
5505 aXYZ[3], aXYZ[4], aXYZ[5]);
5506 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5510 std::cerr << "Error: wrong arguments! See usage:\n";
5511 theDI.PrintHelp (theArgVec[0]);
5516 // convert 3D coordinates from view reference space
5517 else if (aCoord.Length() == 3)
5522 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5523 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5527 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5528 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5532 std::cerr << "Error: wrong arguments! See usage:\n";
5533 theDI.PrintHelp (theArgVec[0]);
5541 //==============================================================================
5544 //==============================================================================
5546 static int VFps (Draw_Interpretor& theDI,
5547 Standard_Integer theArgNb,
5548 const char** theArgVec)
5550 // get the active view
5551 Handle(V3d_View) aView = ViewerTest::CurrentView();
5554 std::cerr << "No active view. Please call vinit.\n";
5558 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
5561 std::cerr << "Incorrect arguments!\n";
5565 // the time is meaningless for first call
5566 // due to async OpenGl rendering
5569 // redraw view in loop to estimate average values
5572 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
5578 const Standard_Real aTime = aTimer.ElapsedTime();
5579 aTimer.OSD_Chronometer::Show (aCpu);
5581 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
5582 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
5584 // return statistics
5585 theDI << "FPS: " << aFpsAver << "\n"
5586 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5588 // compute additional statistics in ray-tracing mode
5589 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
5591 if (aParams.Method == Graphic3d_RM_RAYTRACING)
5593 Standard_Integer aSizeX;
5594 Standard_Integer aSizeY;
5596 aView->Window()->Size (aSizeX, aSizeY);
5598 // 1 shadow ray and 1 secondary ray pew each bounce
5599 const Standard_Real aMRays = aSizeX * aSizeY * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
5601 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
5607 //==============================================================================
5608 //function : VGlDebug
5610 //==============================================================================
5612 static int VGlDebug (Draw_Interpretor& theDI,
5613 Standard_Integer theArgNb,
5614 const char** theArgVec)
5616 Handle(OpenGl_GraphicDriver) aDriver;
5617 Handle(V3d_View) aView = ViewerTest::CurrentView();
5618 if (!aView.IsNull())
5620 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5622 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
5623 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
5627 TCollection_AsciiString aDebActive, aSyncActive;
5634 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
5635 "GL_ARB_debug_output");
5636 aDebActive = isActive ? " (active)" : " (inactive)";
5639 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
5640 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
5644 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
5645 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
5646 << "glslWarn:" << (aCaps->glslWarnings ? "1" : "0") << "\n"
5647 << "extraMsg:" << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
5651 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5653 Standard_CString anArg = theArgVec[anArgIter];
5654 TCollection_AsciiString anArgCase (anArg);
5655 anArgCase.LowerCase();
5656 Standard_Boolean toEnableDebug = Standard_True;
5657 if (anArgCase == "-glsl"
5658 || anArgCase == "-glslwarn"
5659 || anArgCase == "-glslwarns"
5660 || anArgCase == "-glslwarnings")
5662 Standard_Boolean toShowWarns = Standard_True;
5663 if (++anArgIter < theArgNb
5664 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
5668 aDefCaps->glslWarnings = toShowWarns;
5671 aCaps->glslWarnings = toShowWarns;
5674 else if (anArgCase == "-extra"
5675 || anArgCase == "-extramsg"
5676 || anArgCase == "-extramessages")
5678 Standard_Boolean toShow = Standard_True;
5679 if (++anArgIter < theArgNb
5680 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
5684 aDefCaps->suppressExtraMsg = !toShow;
5687 aCaps->suppressExtraMsg = !toShow;
5690 else if (anArgCase == "-noextra"
5691 || anArgCase == "-noextramsg"
5692 || anArgCase == "-noextramessages")
5694 Standard_Boolean toSuppress = Standard_True;
5695 if (++anArgIter < theArgNb
5696 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
5700 aDefCaps->suppressExtraMsg = toSuppress;
5703 aCaps->suppressExtraMsg = toSuppress;
5706 else if (anArgCase == "-sync")
5708 Standard_Boolean toSync = Standard_True;
5709 if (++anArgIter < theArgNb
5710 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
5714 aDefCaps->contextSyncDebug = toSync;
5717 aDefCaps->contextDebug = Standard_True;
5720 else if (anArgCase == "-debug")
5722 if (++anArgIter < theArgNb
5723 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
5727 aDefCaps->contextDebug = toEnableDebug;
5729 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
5730 && (anArgIter + 1 == theArgNb))
5732 // simple alias to turn on almost everything
5733 aDefCaps->contextDebug = toEnableDebug;
5734 aDefCaps->contextSyncDebug = toEnableDebug;
5735 aDefCaps->glslWarnings = toEnableDebug;
5739 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
5747 //==============================================================================
5750 //==============================================================================
5752 static int VVbo (Draw_Interpretor& theDI,
5753 Standard_Integer theArgNb,
5754 const char** theArgVec)
5756 const Standard_Boolean toSet = (theArgNb > 1);
5757 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
5760 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
5764 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5765 if (aContextAIS.IsNull())
5769 std::cerr << "No active view!\n";
5773 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5774 if (!aDriver.IsNull())
5778 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
5782 aDriver->ChangeOptions().vboDisable = toUseVbo;
5789 //==============================================================================
5792 //==============================================================================
5794 static int VCaps (Draw_Interpretor& theDI,
5795 Standard_Integer theArgNb,
5796 const char** theArgVec)
5798 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
5799 Handle(OpenGl_GraphicDriver) aDriver;
5800 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5801 if (!aContext.IsNull())
5803 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
5804 aCaps = &aDriver->ChangeOptions();
5809 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
5810 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
5811 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
5812 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
5813 theDI << "VSync: " << aCaps->swapInterval << "\n";
5814 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
5815 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
5816 theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n";
5820 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5821 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5823 Standard_CString anArg = theArgVec[anArgIter];
5824 TCollection_AsciiString anArgCase (anArg);
5825 anArgCase.LowerCase();
5826 if (anUpdateTool.parseRedrawMode (anArg))
5830 else if (anArgCase == "-vsync"
5831 || anArgCase == "-swapinterval")
5833 Standard_Boolean toEnable = Standard_True;
5834 if (++anArgIter < theArgNb
5835 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5839 aCaps->swapInterval = toEnable;
5841 else if (anArgCase == "-ffp")
5843 Standard_Boolean toEnable = Standard_True;
5844 if (++anArgIter < theArgNb
5845 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5849 aCaps->ffpEnable = toEnable;
5851 else if (anArgCase == "-vbo")
5853 Standard_Boolean toEnable = Standard_True;
5854 if (++anArgIter < theArgNb
5855 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5859 aCaps->vboDisable = !toEnable;
5861 else if (anArgCase == "-sprite"
5862 || anArgCase == "-sprites")
5864 Standard_Boolean toEnable = Standard_True;
5865 if (++anArgIter < theArgNb
5866 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5870 aCaps->pntSpritesDisable = !toEnable;
5872 else if (anArgCase == "-softmode")
5874 Standard_Boolean toEnable = Standard_True;
5875 if (++anArgIter < theArgNb
5876 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5880 aCaps->contextNoAccel = toEnable;
5882 else if (anArgCase == "-winbuffer"
5883 || anArgCase == "-windowbuffer"
5884 || anArgCase == "-usewinbuffer"
5885 || anArgCase == "-usewindowbuffer"
5886 || anArgCase == "-usesystembuffer")
5888 Standard_Boolean toEnable = Standard_True;
5889 if (++anArgIter < theArgNb
5890 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5894 aCaps->useSystemBuffer = toEnable;
5896 else if (anArgCase == "-accel"
5897 || anArgCase == "-acceleration")
5899 Standard_Boolean toEnable = Standard_True;
5900 if (++anArgIter < theArgNb
5901 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5905 aCaps->contextNoAccel = !toEnable;
5907 else if (anArgCase == "-compat"
5908 || anArgCase == "-compatprofile"
5909 || anArgCase == "-compatible"
5910 || anArgCase == "-compatibleprofile")
5912 Standard_Boolean toEnable = Standard_True;
5913 if (++anArgIter < theArgNb
5914 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5918 aCaps->contextCompatible = toEnable;
5919 if (!aCaps->contextCompatible)
5921 aCaps->ffpEnable = Standard_False;
5924 else if (anArgCase == "-core"
5925 || anArgCase == "-coreprofile")
5927 Standard_Boolean toEnable = Standard_True;
5928 if (++anArgIter < theArgNb
5929 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5933 aCaps->contextCompatible = !toEnable;
5934 if (!aCaps->contextCompatible)
5936 aCaps->ffpEnable = Standard_False;
5939 else if (anArgCase == "-stereo"
5940 || anArgCase == "-quadbuffer")
5942 Standard_Boolean toEnable = Standard_True;
5943 if (++anArgIter < theArgNb
5944 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5948 aCaps->contextStereo = toEnable;
5952 std::cout << "Error: unknown argument '" << anArg << "'\n";
5956 if (aCaps != &ViewerTest_myDefaultCaps)
5958 ViewerTest_myDefaultCaps = *aCaps;
5963 //==============================================================================
5964 //function : VMemGpu
5966 //==============================================================================
5968 static int VMemGpu (Draw_Interpretor& theDI,
5969 Standard_Integer theArgNb,
5970 const char** theArgVec)
5973 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5974 if (aContextAIS.IsNull())
5976 std::cerr << "No active view. Please call vinit.\n";
5980 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
5981 if (aDriver.IsNull())
5983 std::cerr << "Graphic driver not available.\n";
5987 Standard_Size aFreeBytes = 0;
5988 TCollection_AsciiString anInfo;
5989 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
5991 std::cerr << "Information not available.\n";
5995 if (theArgNb > 1 && *theArgVec[1] == 'f')
5997 theDI << Standard_Real (aFreeBytes);
6007 // ==============================================================================
6008 // function : VReadPixel
6010 // ==============================================================================
6011 static int VReadPixel (Draw_Interpretor& theDI,
6012 Standard_Integer theArgNb,
6013 const char** theArgVec)
6015 // get the active view
6016 Handle(V3d_View) aView = ViewerTest::CurrentView();
6019 std::cerr << "No active view. Please call vinit.\n";
6022 else if (theArgNb < 3)
6024 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
6028 Image_Format aFormat = Image_Format_RGBA;
6029 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
6031 Standard_Integer aWidth, aHeight;
6032 aView->Window()->Size (aWidth, aHeight);
6033 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
6034 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
6035 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
6037 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
6041 Standard_Boolean toShowName = Standard_False;
6042 Standard_Boolean toShowHls = Standard_False;
6043 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
6045 TCollection_AsciiString aParam (theArgVec[anIter]);
6047 if (aParam == "rgb")
6049 aFormat = Image_Format_RGB;
6050 aBufferType = Graphic3d_BT_RGB;
6052 else if (aParam == "hls")
6054 aFormat = Image_Format_RGB;
6055 aBufferType = Graphic3d_BT_RGB;
6056 toShowHls = Standard_True;
6058 else if (aParam == "rgbf")
6060 aFormat = Image_Format_RGBF;
6061 aBufferType = Graphic3d_BT_RGB;
6063 else if (aParam == "rgba")
6065 aFormat = Image_Format_RGBA;
6066 aBufferType = Graphic3d_BT_RGBA;
6068 else if (aParam == "rgbaf")
6070 aFormat = Image_Format_RGBAF;
6071 aBufferType = Graphic3d_BT_RGBA;
6073 else if (aParam == "depth")
6075 aFormat = Image_Format_GrayF;
6076 aBufferType = Graphic3d_BT_Depth;
6078 else if (aParam == "name")
6080 toShowName = Standard_True;
6084 Image_PixMap anImage;
6085 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
6087 std::cerr << "Image allocation failed\n";
6090 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
6092 std::cerr << "Image dump failed\n";
6096 // redirect possible warning messages that could have been added by ToPixMap
6097 // into the Tcl interpretor (via DefaultMessenger) to cout, so that they do not
6098 // contaminate result of the command
6099 Standard_CString aWarnLog = theDI.Result();
6100 if (aWarnLog != NULL && aWarnLog[0] != '\0')
6102 std::cout << aWarnLog << std::endl;
6106 Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY);
6109 if (aBufferType == Graphic3d_BT_RGBA)
6111 theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha();
6115 theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
6120 switch (aBufferType)
6123 case Graphic3d_BT_RGB:
6127 theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation();
6131 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue();
6135 case Graphic3d_BT_RGBA:
6137 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue() << " " << aColor.Alpha();
6140 case Graphic3d_BT_Depth:
6142 theDI << aColor.GetRGB().Red();
6151 //! Auxiliary presentation for an image plane.
6152 class ViewerTest_ImagePrs : public AIS_InteractiveObject
6155 //! Main constructor.
6156 ViewerTest_ImagePrs (const Handle(Image_PixMap)& theImage,
6157 const Standard_Real theWidth,
6158 const Standard_Real theHeight,
6159 const TCollection_AsciiString& theLabel)
6160 : myLabel (theLabel), myWidth (theWidth), myHeight(theHeight)
6164 myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost);
6166 myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
6167 const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect();
6168 Graphic3d_MaterialAspect aMat;
6169 aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC);
6170 aMat.SetAmbient (1.0);
6171 aMat.SetDiffuse (1.0);
6172 aMat.SetSpecular (1.0);
6173 aMat.SetEmissive (1.0);
6174 aMat.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
6175 aMat.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
6176 aMat.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
6177 aMat.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
6178 aMat.SetAmbientColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6179 aMat.SetDiffuseColor (Quantity_Color (1.0, 1.0, 1.0, Quantity_TOC_RGB));
6180 aMat.SetSpecularColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6181 aMat.SetEmissiveColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6182 aFillAspect->SetFrontMaterial (aMat);
6183 aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage));
6184 aFillAspect->SetTextureMapOn();
6187 Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect();
6188 aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER);
6189 aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER);
6190 myDrawer->SetTextAspect (aTextAspect);
6193 const gp_Dir aNorm (0.0, 0.0, 1.0);
6194 myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true);
6195 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0));
6196 myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0));
6197 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0));
6198 myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0));
6199 myTris->AddEdge (1);
6200 myTris->AddEdge (2);
6201 myTris->AddEdge (3);
6202 myTris->AddEdge (3);
6203 myTris->AddEdge (2);
6204 myTris->AddEdge (4);
6206 myRect = new Graphic3d_ArrayOfPolylines (4);
6207 myRect->AddVertex (myTris->Vertice (1));
6208 myRect->AddVertex (myTris->Vertice (3));
6209 myRect->AddVertex (myTris->Vertice (4));
6210 myRect->AddVertex (myTris->Vertice (2));
6214 //! Returns TRUE for accepted display modes.
6215 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; }
6217 //! Compute presentation.
6218 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& , const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) Standard_OVERRIDE
6224 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
6225 aGroup->AddPrimitiveArray (myTris);
6226 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
6227 aGroup->AddPrimitiveArray (myRect);
6228 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
6233 Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0));
6234 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
6235 aGroup->AddPrimitiveArray (myRect);
6236 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
6242 //! Compute selection.
6243 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE
6247 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5);
6248 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner);
6249 aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location());
6250 theSel->Add (aSensitive);
6255 Handle(Graphic3d_ArrayOfTriangles) myTris;
6256 Handle(Graphic3d_ArrayOfPolylines) myRect;
6257 TCollection_AsciiString myLabel;
6258 Standard_Real myWidth;
6259 Standard_Real myHeight;
6262 //==============================================================================
6263 //function : VDiffImage
6264 //purpose : The draw-command compares two images.
6265 //==============================================================================
6267 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
6271 std::cout << "Syntax error: not enough arguments.\n";
6275 Standard_Integer anArgIter = 1;
6276 TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]);
6277 TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]);
6278 TCollection_AsciiString aDiffImagePath;
6279 Standard_Real aTolColor = -1.0;
6280 Standard_Integer toBlackWhite = -1;
6281 Standard_Integer isBorderFilterOn = -1;
6282 Standard_Boolean isOldSyntax = Standard_False;
6283 TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff;
6284 for (; anArgIter < theArgNb; ++anArgIter)
6286 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6288 if (anArgIter + 1 < theArgNb
6289 && (anArg == "-toleranceofcolor"
6290 || anArg == "-tolerancecolor"
6291 || anArg == "-tolerance"
6292 || anArg == "-toler"))
6294 aTolColor = Atof (theArgVec[++anArgIter]);
6295 if (aTolColor < 0.0 || aTolColor > 1.0)
6297 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
6301 else if (anArg == "-blackwhite")
6303 Standard_Boolean toEnable = Standard_True;
6304 if (anArgIter + 1 < theArgNb
6305 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6309 toBlackWhite = toEnable ? 1 : 0;
6311 else if (anArg == "-borderfilter")
6313 Standard_Boolean toEnable = Standard_True;
6314 if (anArgIter + 1 < theArgNb
6315 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6319 isBorderFilterOn = toEnable ? 1 : 0;
6321 else if (anArg == "-exitonclose")
6323 Draw_ToExitOnCloseView = true;
6324 if (anArgIter + 1 < theArgNb
6325 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToExitOnCloseView))
6330 else if (anArg == "-closeonescape"
6331 || anArg == "-closeonesc")
6333 Draw_ToCloseViewOnEsc = true;
6334 if (anArgIter + 1 < theArgNb
6335 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToCloseViewOnEsc))
6340 else if (anArgIter + 3 < theArgNb
6341 && anArg == "-display")
6343 aViewName = theArgVec[++anArgIter];
6344 aPrsNameRef = theArgVec[++anArgIter];
6345 aPrsNameNew = theArgVec[++anArgIter];
6346 if (anArgIter + 1 < theArgNb
6347 && *theArgVec[anArgIter + 1] != '-')
6349 aPrsNameDiff = theArgVec[++anArgIter];
6352 else if (aTolColor < 0.0
6353 && anArg.IsRealValue())
6355 isOldSyntax = Standard_True;
6356 aTolColor = anArg.RealValue();
6357 if (aTolColor < 0.0 || aTolColor > 1.0)
6359 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
6363 else if (isOldSyntax
6364 && toBlackWhite == -1
6365 && (anArg == "0" || anArg == "1"))
6367 toBlackWhite = anArg == "1" ? 1 : 0;
6369 else if (isOldSyntax
6370 && isBorderFilterOn == -1
6371 && (anArg == "0" || anArg == "1"))
6373 isBorderFilterOn = anArg == "1" ? 1 : 0;
6375 else if (aDiffImagePath.IsEmpty())
6377 aDiffImagePath = theArgVec[anArgIter];
6381 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
6386 Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap();
6387 Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap();
6388 if (!anImgRef->Load (anImgPathRef))
6390 std::cout << "Error: image file '" << anImgPathRef << "' cannot be read\n";
6393 if (!anImgNew->Load (anImgPathNew))
6395 std::cout << "Error: image file '" << anImgPathNew << "' cannot be read\n";
6399 // compare the images
6400 Image_Diff aComparer;
6401 Standard_Integer aDiffColorsNb = -1;
6402 if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1))
6404 aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0);
6405 aComparer.SetBorderFilterOn (isBorderFilterOn == 1);
6406 aDiffColorsNb = aComparer.Compare();
6407 theDI << aDiffColorsNb << "\n";
6410 // save image of difference
6411 Handle(Image_AlienPixMap) aDiff;
6412 if (aDiffColorsNb > 0
6413 && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty()))
6415 aDiff = new Image_AlienPixMap();
6416 if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY()))
6418 std::cout << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY() << "\n";
6421 aComparer.SaveDiffImage (*aDiff);
6422 if (!aDiffImagePath.IsEmpty()
6423 && !aDiff->Save (aDiffImagePath))
6425 std::cout << "Error: diff image file '" << aDiffImagePath << "' cannot be written\n";
6430 if (aViewName.IsEmpty())
6435 ViewerTest_Names aViewNames (aViewName);
6436 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
6438 TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName();
6439 theDI.Eval (aCommand.ToCString());
6442 Standard_Integer aPxLeft = 0;
6443 Standard_Integer aPxTop = 0;
6444 Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2);
6445 Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty()
6446 ? int(anImgRef->SizeY() * 2)
6447 : int(anImgRef->SizeY());
6448 TCollection_AsciiString aDisplayName;
6449 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aWinSizeX, aWinSizeY,
6450 aViewName, aDisplayName);
6452 Standard_Real aRatio = anImgRef->Ratio();
6453 Standard_Real aSizeX = 1.0;
6454 Standard_Real aSizeY = aSizeX / aRatio;
6456 OSD_Path aPath (anImgPathRef);
6457 TCollection_AsciiString aLabelRef;
6458 if (!aPath.Name().IsEmpty())
6460 aLabelRef = aPath.Name() + aPath.Extension();
6462 aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY());
6464 Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef);
6466 aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0));
6467 anImgRefPrs->SetLocalTransformation (aTrsfRef);
6468 ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true);
6471 OSD_Path aPath (anImgPathNew);
6472 TCollection_AsciiString aLabelNew;
6473 if (!aPath.Name().IsEmpty())
6475 aLabelNew = aPath.Name() + aPath.Extension();
6477 aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY());
6479 Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew);
6481 aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0));
6482 anImgNewPrs->SetLocalTransformation (aTrsfRef);
6483 ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true);
6485 Handle(ViewerTest_ImagePrs) anImgDiffPrs;
6486 if (!aDiff.IsNull())
6488 anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels");
6490 aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0));
6491 anImgDiffPrs->SetLocalTransformation (aTrsfDiff);
6493 if (!aPrsNameDiff.IsEmpty())
6495 ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true);
6497 ViewerTest::CurrentView()->SetProj (V3d_Zpos);
6498 ViewerTest::CurrentView()->FitAll();
6502 //=======================================================================
6503 //function : VSelect
6504 //purpose : Emulates different types of selection by mouse:
6505 // 1) single click selection
6506 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
6507 // 3) selection with polygon having corners at
6508 // pixel positions (x1,y1),...,(xn,yn)
6509 // 4) any of these selections with shift button pressed
6510 //=======================================================================
6511 static Standard_Integer VSelect (Draw_Interpretor& di,
6512 Standard_Integer argc,
6517 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]\n";
6521 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
6522 if(myAIScontext.IsNull())
6524 di << "use 'vinit' command before " << argv[0] << "\n";
6528 const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1));
6529 Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1;
6530 TCollection_AsciiString anArg;
6531 anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2];
6533 if (anArg == "-allowoverlap")
6535 Standard_Boolean isValidated = isShiftSelection ? argc == 8
6539 di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection";
6543 Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
6544 myAIScontext->MainSelector()->AllowOverlapDetection (isToAllow != 0);
6548 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
6549 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
6552 if(isShiftSelection)
6553 aCurrentEventManager->ShiftSelect();
6555 aCurrentEventManager->Select();
6557 else if(aCoordsNb == 4)
6559 if(isShiftSelection)
6560 aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
6562 aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
6566 TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2);
6568 for(Standard_Integer i=1;i<=aCoordsNb / 2;++i)
6569 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
6571 if(isShiftSelection)
6572 aCurrentEventManager->ShiftSelect(aPolyline);
6574 aCurrentEventManager->Select(aPolyline);
6579 //=======================================================================
6580 //function : VMoveTo
6581 //purpose : Emulates cursor movement to defined pixel position
6582 //=======================================================================
6583 static Standard_Integer VMoveTo (Draw_Interpretor& ,
6584 Standard_Integer theNbArgs,
6585 const char** theArgVec)
6587 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
6588 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
6589 if (aContext.IsNull())
6591 std::cout << "Error: no active View\n";
6595 Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast());
6596 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
6598 TCollection_AsciiString anArgStr (theArgVec[anArgIter]);
6599 anArgStr.LowerCase();
6600 if (anArgStr == "-reset"
6601 || anArgStr == "-clear")
6603 if (anArgIter + 1 < theNbArgs)
6605 std::cout << "Syntax error at '" << theArgVec[anArgIter + 1] << "'\n";
6609 const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive()
6610 && aContext->CurrentViewer()->GridEcho();
6613 aContext->CurrentViewer()->HideGridEcho (aView);
6615 if (aContext->ClearDetected() || toEchoGrid)
6617 aContext->CurrentViewer()->RedrawImmediate();
6621 else if (aMousePos.x() == IntegerLast()
6622 && anArgStr.IsIntegerValue())
6624 aMousePos.x() = anArgStr.IntegerValue();
6626 else if (aMousePos.y() == IntegerLast()
6627 && anArgStr.IsIntegerValue())
6629 aMousePos.y() = anArgStr.IntegerValue();
6633 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
6638 if (aMousePos.x() == IntegerLast()
6639 || aMousePos.y() == IntegerLast())
6641 std::cout << "Syntax error: wrong number of arguments\n";
6645 ViewerTest::CurrentEventManager()->MoveTo (aMousePos.x(), aMousePos.y());
6651 //! Global map storing all animations registered in ViewerTest.
6652 static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap;
6654 //! The animation calling the Draw Harness command.
6655 class ViewerTest_AnimationProc : public AIS_Animation
6659 //! Main constructor.
6660 ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName,
6661 Draw_Interpretor* theDI,
6662 const TCollection_AsciiString& theCommand)
6663 : AIS_Animation (theAnimationName),
6665 myCommand (theCommand)
6672 //! Evaluate the command.
6673 virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE
6675 TCollection_AsciiString aCmd = myCommand;
6676 replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts));
6677 replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts));
6678 replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts));
6679 replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized));
6680 replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized));
6681 myDrawInter->Eval (aCmd.ToCString());
6684 //! Find the keyword in the command and replace it with value.
6685 //! @return the position of the keyword to pass value
6686 void replace (TCollection_AsciiString& theCmd,
6687 const TCollection_AsciiString& theKey,
6688 const TCollection_AsciiString& theVal)
6690 TCollection_AsciiString aCmd (theCmd);
6692 const Standard_Integer aPos = aCmd.Search (theKey);
6698 TCollection_AsciiString aPart1, aPart2;
6699 Standard_Integer aPart1To = aPos - 1;
6701 && aPart1To <= theCmd.Length())
6703 aPart1 = theCmd.SubString (1, aPart1To);
6706 Standard_Integer aPart2From = aPos + theKey.Length();
6708 && aPart2From <= theCmd.Length())
6710 aPart2 = theCmd.SubString (aPart2From, theCmd.Length());
6713 theCmd = aPart1 + theVal + aPart2;
6718 Draw_Interpretor* myDrawInter;
6719 TCollection_AsciiString myCommand;
6723 //! Replace the animation with the new one.
6724 static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation,
6725 Handle(AIS_Animation)& theAnimation,
6726 const Handle(AIS_Animation)& theAnimationNew)
6728 theAnimationNew->CopyFrom (theAnimation);
6729 if (!theParentAnimation.IsNull())
6731 theParentAnimation->Replace (theAnimation, theAnimationNew);
6735 ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name());
6736 ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew);
6738 theAnimation = theAnimationNew;
6741 //! Parse the point.
6742 static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
6744 const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
6745 if (!anXYZ[0].IsRealValue()
6746 || !anXYZ[1].IsRealValue()
6747 || !anXYZ[2].IsRealValue())
6749 return Standard_False;
6752 thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue());
6753 return Standard_True;
6756 //! Parse the quaternion.
6757 static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
6759 const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
6760 if (!anXYZW[0].IsRealValue()
6761 || !anXYZW[1].IsRealValue()
6762 || !anXYZW[2].IsRealValue()
6763 || !anXYZW[3].IsRealValue())
6765 return Standard_False;
6768 theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue());
6769 return Standard_True;
6772 //! Auxiliary class for flipping image upside-down.
6777 //! Empty constructor.
6778 ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {}
6780 //! Perform flipping.
6781 Standard_Boolean FlipY (Image_PixMap& theImage)
6783 if (theImage.IsEmpty()
6784 || theImage.SizeX() == 0
6785 || theImage.SizeY() == 0)
6787 return Standard_False;
6790 const Standard_Size aRowSize = theImage.SizeRowBytes();
6791 if (myTmp.Size() < aRowSize
6792 && !myTmp.Allocate (aRowSize))
6794 return Standard_False;
6797 // for odd height middle row should be left as is
6798 Standard_Size aNbRowsHalf = theImage.SizeY() / 2;
6799 for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB)
6801 Standard_Byte* aTop = theImage.ChangeRow (aRowT);
6802 Standard_Byte* aBot = theImage.ChangeRow (aRowB);
6803 memcpy (myTmp.ChangeData(), aTop, aRowSize);
6804 memcpy (aTop, aBot, aRowSize);
6805 memcpy (aBot, myTmp.Data(), aRowSize);
6807 return Standard_True;
6811 NCollection_Buffer myTmp;
6816 //=================================================================================================
6817 //function : VViewParams
6818 //purpose : Gets or sets AIS View characteristics
6819 //=================================================================================================
6820 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6822 Handle(V3d_View) aView = ViewerTest::CurrentView();
6825 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
6829 Standard_Boolean toSetProj = Standard_False;
6830 Standard_Boolean toSetUp = Standard_False;
6831 Standard_Boolean toSetAt = Standard_False;
6832 Standard_Boolean toSetEye = Standard_False;
6833 Standard_Boolean toSetScale = Standard_False;
6834 Standard_Boolean toSetSize = Standard_False;
6835 Standard_Boolean toSetCenter2d = Standard_False;
6836 Standard_Real aViewScale = aView->Scale();
6837 Standard_Real aViewSize = 1.0;
6838 Graphic3d_Vec2i aCenter2d;
6839 gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
6840 aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3));
6841 aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
6842 aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
6843 aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
6846 // print all of the available view parameters
6850 "Proj: %12g %12g %12g\n"
6851 "Up: %12g %12g %12g\n"
6852 "At: %12g %12g %12g\n"
6853 "Eye: %12g %12g %12g\n",
6855 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
6856 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
6857 aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
6858 aViewEye.X(), aViewEye.Y(), aViewEye.Z());
6863 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
6864 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
6866 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6868 if (anUpdateTool.parseRedrawMode (anArg))
6872 else if (anArg == "-cmd"
6873 || anArg == "-command"
6874 || anArg == "-args")
6883 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
6884 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
6885 aViewAt.X(), aViewAt.Y(), aViewAt.Z());
6888 else if (anArg == "-scale"
6889 || anArg == "-size")
6891 if (anArgIter + 1 < theArgsNb
6892 && *theArgVec[anArgIter + 1] != '-')
6894 const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
6895 if (aValueArg.IsRealValue())
6898 if (anArg == "-scale")
6900 toSetScale = Standard_True;
6901 aViewScale = aValueArg.RealValue();
6903 else if (anArg == "-size")
6905 toSetSize = Standard_True;
6906 aViewSize = aValueArg.RealValue();
6911 if (anArg == "-scale")
6913 theDi << "Scale: " << aView->Scale() << "\n";
6915 else if (anArg == "-size")
6917 Graphic3d_Vec2d aSizeXY;
6918 aView->Size (aSizeXY.x(), aSizeXY.y());
6919 theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n";
6922 else if (anArg == "-eye"
6925 || anArg == "-proj")
6927 if (anArgIter + 3 < theArgsNb)
6930 if (parseXYZ (theArgVec + anArgIter + 1, anXYZ))
6933 if (anArg == "-eye")
6935 toSetEye = Standard_True;
6938 else if (anArg == "-at")
6940 toSetAt = Standard_True;
6943 else if (anArg == "-up")
6945 toSetUp = Standard_True;
6948 else if (anArg == "-proj")
6950 toSetProj = Standard_True;
6957 if (anArg == "-eye")
6959 theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n";
6961 else if (anArg == "-at")
6963 theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n";
6965 else if (anArg == "-up")
6967 theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n";
6969 else if (anArg == "-proj")
6971 theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n";
6974 else if (anArg == "-center")
6976 if (anArgIter + 2 < theArgsNb)
6978 const TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
6979 const TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
6980 if (anX.IsIntegerValue()
6981 && anY.IsIntegerValue())
6983 toSetCenter2d = Standard_True;
6984 aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue());
6990 std::cout << "Syntax error at '" << anArg << "'\n";
6995 // change view parameters in proper order
6998 aView->SetScale (aViewScale);
7002 aView->SetSize (aViewSize);
7006 aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z());
7010 aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z());
7014 aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z());
7018 aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z());
7022 aView->SetCenter (aCenter2d.x(), aCenter2d.y());
7028 //==============================================================================
7029 //function : V2DMode
7031 //==============================================================================
7032 static Standard_Integer V2DMode (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec)
7034 bool is2dMode = true;
7035 Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView());
7036 if (aV3dView.IsNull())
7038 std::cout << "Error: no active view.\n";
7041 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
7043 const TCollection_AsciiString anArg = theArgVec[anArgIt];
7044 TCollection_AsciiString anArgCase = anArg;
7045 anArgCase.LowerCase();
7046 if (anArgIt + 1 < theArgsNb
7047 && anArgCase == "-name")
7049 ViewerTest_Names aViewNames (theArgVec[++anArgIt]);
7050 TCollection_AsciiString aViewName = aViewNames.GetViewName();
7051 if (!ViewerTest_myViews.IsBound1 (aViewName))
7053 std::cout << "Syntax error: unknown view '" << theArgVec[anArgIt - 1] << "'.\n";
7056 aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest_myViews.Find1 (aViewName));
7058 else if (anArgCase == "-mode")
7060 if (anArgIt + 1 < theArgsNb
7061 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], is2dMode))
7066 else if (ViewerTest::ParseOnOff (theArgVec[anArgIt], is2dMode))
7072 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
7077 aV3dView->SetView2DMode (is2dMode);
7081 //==============================================================================
7082 //function : VAnimation
7084 //==============================================================================
7085 static Standard_Integer VAnimation (Draw_Interpretor& theDI,
7086 Standard_Integer theArgNb,
7087 const char** theArgVec)
7089 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
7092 for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator
7093 anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next())
7095 theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n";
7101 std::cout << "Error: no active view\n";
7105 Standard_Integer anArgIter = 1;
7106 TCollection_AsciiString aNameArg (theArgVec[anArgIter++]);
7107 if (aNameArg.IsEmpty())
7109 std::cout << "Syntax error: animation name is not defined.\n";
7113 TCollection_AsciiString aNameArgLower = aNameArg;
7114 aNameArgLower.LowerCase();
7115 if (aNameArgLower == "-reset"
7116 || aNameArgLower == "-clear")
7118 ViewerTest_AnimationTimelineMap.Clear();
7121 else if (aNameArg.Value (1) == '-')
7123 std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n";
7127 const char* aNameSplitter = "/";
7128 Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter);
7129 if (aSplitPos == -1)
7131 aNameSplitter = ".";
7132 aSplitPos = aNameArg.Search (aNameSplitter);
7135 // find existing or create a new animation by specified name within syntax "parent.child".
7136 Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation;
7137 for (; !aNameArg.IsEmpty();)
7139 TCollection_AsciiString aNameParent;
7140 if (aSplitPos != -1)
7142 if (aSplitPos == aNameArg.Length())
7144 std::cout << "Syntax error: animation name is not defined.\n";
7148 aNameParent = aNameArg.SubString ( 1, aSplitPos - 1);
7149 aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length());
7151 aSplitPos = aNameArg.Search (aNameSplitter);
7155 aNameParent = aNameArg;
7159 if (anAnimation.IsNull())
7161 if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation))
7163 anAnimation = new AIS_Animation (aNameParent);
7164 ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation);
7166 aRootAnimation = anAnimation;
7170 aParentAnimation = anAnimation;
7171 anAnimation = aParentAnimation->Find (aNameParent);
7172 if (anAnimation.IsNull())
7174 anAnimation = new AIS_Animation (aNameParent);
7175 aParentAnimation->Add (anAnimation);
7180 if (anArgIter >= theArgNb)
7182 // just print the list of children
7183 for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next())
7185 theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n";
7190 // animation parameters
7191 Standard_Boolean toPlay = Standard_False;
7192 Standard_Real aPlaySpeed = 1.0;
7193 Standard_Real aPlayStartTime = anAnimation->StartPts();
7194 Standard_Real aPlayDuration = anAnimation->Duration();
7195 Standard_Boolean isFreeCamera = Standard_False;
7196 Standard_Boolean isLockLoop = Standard_False;
7198 // video recording parameters
7199 TCollection_AsciiString aRecFile;
7200 Image_VideoParams aRecParams;
7202 Handle(V3d_View) aView = ViewerTest::CurrentView();
7203 for (; anArgIter < theArgNb; ++anArgIter)
7205 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7208 if (anArg == "-reset"
7209 || anArg == "-clear")
7211 anAnimation->Clear();
7213 else if (anArg == "-remove"
7215 || anArg == "-delete")
7217 if (!aParentAnimation.IsNull())
7219 ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name());
7223 aParentAnimation->Remove (anAnimation);
7227 else if (anArg == "-play")
7229 toPlay = Standard_True;
7230 if (++anArgIter < theArgNb)
7232 if (*theArgVec[anArgIter] == '-')
7237 aPlayStartTime = Draw::Atof (theArgVec[anArgIter]);
7239 if (++anArgIter < theArgNb)
7241 if (*theArgVec[anArgIter] == '-')
7246 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
7250 else if (anArg == "-resume")
7252 toPlay = Standard_True;
7253 aPlayStartTime = anAnimation->ElapsedTime();
7254 if (++anArgIter < theArgNb)
7256 if (*theArgVec[anArgIter] == '-')
7262 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
7265 else if (anArg == "-playspeed"
7266 || anArg == "-speed")
7268 if (++anArgIter >= theArgNb)
7270 std::cout << "Syntax error at " << anArg << ".\n";
7273 aPlaySpeed = Draw::Atof (theArgVec[anArgIter]);
7275 else if (anArg == "-lock"
7276 || anArg == "-lockloop"
7277 || anArg == "-playlockloop")
7279 isLockLoop = Standard_True;
7281 else if (anArg == "-freecamera"
7282 || anArg == "-playfreecamera"
7283 || anArg == "-freelook")
7285 isFreeCamera = Standard_True;
7287 // video recodring options
7288 else if (anArg == "-rec"
7289 || anArg == "-record")
7291 if (++anArgIter >= theArgNb)
7293 std::cout << "Syntax error at " << anArg << ".\n";
7297 aRecFile = theArgVec[anArgIter];
7298 if (aRecParams.FpsNum <= 0)
7300 aRecParams.FpsNum = 24;
7303 if (anArgIter + 2 < theArgNb
7304 && *theArgVec[anArgIter + 1] != '-'
7305 && *theArgVec[anArgIter + 2] != '-')
7307 TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]);
7308 TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]);
7309 if (aWidthArg .IsIntegerValue()
7310 && aHeightArg.IsIntegerValue())
7312 aRecParams.Width = aWidthArg .IntegerValue();
7313 aRecParams.Height = aHeightArg.IntegerValue();
7318 else if (anArg == "-fps")
7320 if (++anArgIter >= theArgNb)
7322 std::cout << "Syntax error at " << anArg << ".\n";
7326 TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
7327 Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
7328 if (aSplitIndex == 0)
7330 aRecParams.FpsNum = aFpsArg.IntegerValue();
7334 const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
7335 aFpsArg.Split (aFpsArg.Length() - 1);
7336 const TCollection_AsciiString aNumStr = aFpsArg;
7337 aRecParams.FpsNum = aNumStr.IntegerValue();
7338 aRecParams.FpsDen = aDenStr.IntegerValue();
7339 if (aRecParams.FpsDen < 1)
7341 std::cout << "Syntax error at " << anArg << ".\n";
7346 else if (anArg == "-format")
7348 if (++anArgIter >= theArgNb)
7350 std::cout << "Syntax error at " << anArg << ".\n";
7353 aRecParams.Format = theArgVec[anArgIter];
7355 else if (anArg == "-pix_fmt"
7356 || anArg == "-pixfmt"
7357 || anArg == "-pixelformat")
7359 if (++anArgIter >= theArgNb)
7361 std::cout << "Syntax error at " << anArg << ".\n";
7364 aRecParams.PixelFormat = theArgVec[anArgIter];
7366 else if (anArg == "-codec"
7367 || anArg == "-vcodec"
7368 || anArg == "-videocodec")
7370 if (++anArgIter >= theArgNb)
7372 std::cout << "Syntax error at " << anArg << ".\n";
7375 aRecParams.VideoCodec = theArgVec[anArgIter];
7377 else if (anArg == "-crf"
7378 || anArg == "-preset"
7381 const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length());
7382 if (++anArgIter >= theArgNb)
7384 std::cout << "Syntax error at " << anArg << ".\n";
7388 aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]);
7390 // animation definition options
7391 else if (anArg == "-start"
7392 || anArg == "-starttime"
7393 || anArg == "-startpts")
7395 if (++anArgIter >= theArgNb)
7397 std::cout << "Syntax error at " << anArg << ".\n";
7401 anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter]));
7402 aRootAnimation->UpdateTotalDuration();
7404 else if (anArg == "-end"
7405 || anArg == "-endtime"
7406 || anArg == "-endpts")
7408 if (++anArgIter >= theArgNb)
7410 std::cout << "Syntax error at " << anArg << ".\n";
7414 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts());
7415 aRootAnimation->UpdateTotalDuration();
7417 else if (anArg == "-dur"
7418 || anArg == "-duration")
7420 if (++anArgIter >= theArgNb)
7422 std::cout << "Syntax error at " << anArg << ".\n";
7426 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]));
7427 aRootAnimation->UpdateTotalDuration();
7429 else if (anArg == "-command"
7431 || anArg == "-invoke"
7433 || anArg == "-proc")
7435 if (++anArgIter >= theArgNb)
7437 std::cout << "Syntax error at " << anArg << ".\n";
7441 Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]);
7442 replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation);
7444 else if (anArg == "-objecttrsf"
7445 || anArg == "-objectransformation"
7446 || anArg == "-objtransformation"
7447 || anArg == "-objtrsf"
7448 || anArg == "-object"
7451 if (++anArgIter >= theArgNb)
7453 std::cout << "Syntax error at " << anArg << ".\n";
7457 TCollection_AsciiString anObjName (theArgVec[anArgIter]);
7458 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS();
7459 if (!aMapOfAIS.IsBound2 (anObjName))
7461 std::cout << "Syntax error: wrong object name at " << anArg << "\n";
7465 Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (aMapOfAIS.Find2 (anObjName));
7466 gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() };
7467 gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() };
7468 gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
7469 Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
7470 Standard_Boolean isTrsfSet = Standard_False;
7471 Standard_Integer aTrsfArgIter = anArgIter + 1;
7472 for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
7474 TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]);
7475 aTrsfArg.LowerCase();
7476 const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1;
7477 if (aTrsfArg.StartsWith ("-rotation")
7478 || aTrsfArg.StartsWith ("-rot"))
7480 isTrsfSet = Standard_True;
7481 if (aTrsfArgIter + 4 >= theArgNb
7482 || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex]))
7484 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7489 else if (aTrsfArg.StartsWith ("-location")
7490 || aTrsfArg.StartsWith ("-loc"))
7492 isTrsfSet = Standard_True;
7493 if (aTrsfArgIter + 3 >= theArgNb
7494 || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex]))
7496 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7501 else if (aTrsfArg.StartsWith ("-scale"))
7503 isTrsfSet = Standard_True;
7504 if (++aTrsfArgIter >= theArgNb)
7506 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7510 const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
7511 if (!aScaleStr.IsRealValue())
7513 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7516 aScales[anIndex] = aScaleStr.RealValue();
7520 anArgIter = aTrsfArgIter - 1;
7526 std::cout << "Syntax error at " << anArg << ".\n";
7529 else if (aTrsfArgIter >= theArgNb)
7531 anArgIter = theArgNb;
7534 aTrsfs[0].SetRotation (aRotQuats[0]);
7535 aTrsfs[1].SetRotation (aRotQuats[1]);
7536 aTrsfs[0].SetTranslationPart (aLocPnts[0]);
7537 aTrsfs[1].SetTranslationPart (aLocPnts[1]);
7538 aTrsfs[0].SetScaleFactor (aScales[0]);
7539 aTrsfs[1].SetScaleFactor (aScales[1]);
7541 Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
7542 replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
7544 else if (anArg == "-viewtrsf"
7545 || anArg == "-view")
7547 Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation);
7548 if (aCamAnimation.IsNull())
7550 aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView);
7551 replaceAnimation (aParentAnimation, anAnimation, aCamAnimation);
7554 Handle(Graphic3d_Camera) aCams[2] =
7556 new Graphic3d_Camera (aCamAnimation->View()->Camera()),
7557 new Graphic3d_Camera (aCamAnimation->View()->Camera())
7560 Standard_Boolean isTrsfSet = Standard_False;
7561 Standard_Integer aViewArgIter = anArgIter + 1;
7562 for (; aViewArgIter < theArgNb; ++aViewArgIter)
7564 TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]);
7565 aViewArg.LowerCase();
7566 const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1;
7567 if (aViewArg.StartsWith ("-scale"))
7569 isTrsfSet = Standard_True;
7570 if (++aViewArgIter >= theArgNb)
7572 std::cout << "Syntax error at " << anArg << ".\n";
7576 const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
7577 if (!aScaleStr.IsRealValue())
7579 std::cout << "Syntax error at " << aViewArg << ".\n";
7582 Standard_Real aScale = aScaleStr.RealValue();
7583 aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale;
7584 aCams[anIndex]->SetScale (aScale);
7586 else if (aViewArg.StartsWith ("-eye")
7587 || aViewArg.StartsWith ("-center")
7588 || aViewArg.StartsWith ("-at")
7589 || aViewArg.StartsWith ("-up"))
7591 isTrsfSet = Standard_True;
7593 if (aViewArgIter + 3 >= theArgNb
7594 || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ))
7596 std::cout << "Syntax error at " << aViewArg << ".\n";
7601 if (aViewArg.StartsWith ("-eye"))
7603 aCams[anIndex]->SetEye (anXYZ);
7605 else if (aViewArg.StartsWith ("-center")
7606 || aViewArg.StartsWith ("-at"))
7608 aCams[anIndex]->SetCenter (anXYZ);
7610 else if (aViewArg.StartsWith ("-up"))
7612 aCams[anIndex]->SetUp (anXYZ);
7617 anArgIter = aViewArgIter - 1;
7623 std::cout << "Syntax error at " << anArg << ".\n";
7626 else if (aViewArgIter >= theArgNb)
7628 anArgIter = theArgNb;
7631 aCamAnimation->SetCameraStart(aCams[0]);
7632 aCamAnimation->SetCameraEnd (aCams[1]);
7636 std::cout << "Syntax error at " << anArg << ".\n";
7641 if (!toPlay && aRecFile.IsEmpty())
7646 // Start animation timeline and process frame updating.
7647 TheIsAnimating = Standard_True;
7648 const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
7649 Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera());
7650 anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
7653 aView->Camera()->Copy (aCameraBack);
7656 const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
7657 if (aRecParams.FpsNum <= 0)
7659 while (!anAnimation->IsStopped())
7661 aCameraBack->Copy (aView->Camera());
7662 const Standard_Real aPts = anAnimation->UpdateTimer();
7665 aView->Camera()->Copy (aCameraBack);
7668 if (aPts >= anUpperPts)
7670 anAnimation->Pause();
7674 if (aView->IsInvalidated())
7680 aView->RedrawImmediate();
7685 // handle user events
7686 theDI.Eval ("after 1 set waiter 1");
7687 theDI.Eval ("vwait waiter");
7689 if (!TheIsAnimating)
7691 anAnimation->Pause();
7697 if (aView->IsInvalidated())
7703 aView->RedrawImmediate();
7708 OSD_Timer aPerfTimer;
7711 Handle(Image_VideoRecorder) aRecorder;
7712 ImageFlipper aFlipper;
7713 Handle(Draw_ProgressIndicator) aProgress;
7714 if (!aRecFile.IsEmpty())
7716 if (aRecParams.Width <= 0
7717 || aRecParams.Height <= 0)
7719 aView->Window()->Size (aRecParams.Width, aRecParams.Height);
7722 aRecorder = new Image_VideoRecorder();
7723 if (!aRecorder->Open (aRecFile.ToCString(), aRecParams))
7725 std::cout << "Error: failed to open video file for recording\n";
7729 aProgress = new Draw_ProgressIndicator (theDI, 1);
7732 // Manage frame-rated animation here
7733 Standard_Real aPts = aPlayStartTime;
7734 int64_t aNbFrames = 0;
7735 Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1);
7736 Standard_Integer aSecondsProgress = 0;
7737 for (; aPts <= anUpperPts && aPSentry.More();)
7739 const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames));
7740 aPts = aPlayStartTime + aRecPts;
7742 if (!anAnimation->Update (aPts))
7747 if (!aRecorder.IsNull())
7749 V3d_ImageDumpOptions aDumpParams;
7750 aDumpParams.Width = aRecParams.Width;
7751 aDumpParams.Height = aRecParams.Height;
7752 aDumpParams.BufferType = Graphic3d_BT_RGBA;
7753 aDumpParams.StereoOptions = V3d_SDO_MONO;
7754 aDumpParams.ToAdjustAspect = Standard_True;
7755 if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams))
7757 std::cout << "Error: view dump is failed!\n";
7760 aFlipper.FlipY (aRecorder->ChangeFrame());
7761 if (!aRecorder->PushFrame())
7771 while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed))
7779 anAnimation->Stop();
7780 const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
7781 theDI << "Average FPS: " << aRecFps << "\n"
7782 << "Nb. Frames: " << Standard_Real(aNbFrames);
7787 aView->SetImmediateUpdate (wasImmediateUpdate);
7788 TheIsAnimating = Standard_False;
7793 //=======================================================================
7794 //function : VChangeSelected
7795 //purpose : Adds the shape to selection or remove one from it
7796 //=======================================================================
7797 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
7798 Standard_Integer argc,
7803 di<<"Usage : " << argv[0] << " shape \n";
7807 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7808 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
7809 TCollection_AsciiString aName(argv[1]);
7810 Handle(AIS_InteractiveObject) anAISObject;
7812 if(!aMap.IsBound2(aName))
7814 di<<"Use 'vdisplay' before";
7819 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
7820 if(anAISObject.IsNull()){
7821 di<<"No interactive object \n";
7825 aContext->AddOrRemoveSelected(anAISObject, Standard_True);
7830 //=======================================================================
7831 //function : VNbSelected
7832 //purpose : Returns number of selected objects
7833 //=======================================================================
7834 static Standard_Integer VNbSelected (Draw_Interpretor& di,
7835 Standard_Integer argc,
7840 di << "Usage : " << argv[0] << "\n";
7843 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7844 if(aContext.IsNull())
7846 di << "use 'vinit' command before " << argv[0] << "\n";
7849 di << aContext->NbSelected() << "\n";
7853 //=======================================================================
7854 //function : VPurgeDisplay
7855 //purpose : Switches altialiasing on or off
7856 //=======================================================================
7857 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
7858 Standard_Integer argc,
7863 di << "Usage : " << argv[0] << "\n";
7866 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7867 if (aContext.IsNull())
7869 di << "use 'vinit' command before " << argv[0] << "\n";
7873 di << aContext->PurgeDisplay() << "\n";
7877 //=======================================================================
7878 //function : VSetViewSize
7880 //=======================================================================
7881 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
7882 Standard_Integer argc,
7885 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7886 if(aContext.IsNull())
7888 di << "use 'vinit' command before " << argv[0] << "\n";
7893 di<<"Usage : " << argv[0] << " Size\n";
7896 Standard_Real aSize = Draw::Atof (argv[1]);
7899 di<<"Bad Size value : " << aSize << "\n";
7903 Handle(V3d_View) aView = ViewerTest::CurrentView();
7904 aView->SetSize(aSize);
7908 //=======================================================================
7909 //function : VMoveView
7911 //=======================================================================
7912 static Standard_Integer VMoveView (Draw_Interpretor& di,
7913 Standard_Integer argc,
7916 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7917 if(aContext.IsNull())
7919 di << "use 'vinit' command before " << argv[0] << "\n";
7922 if(argc < 4 || argc > 5)
7924 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
7927 Standard_Real Dx = Draw::Atof (argv[1]);
7928 Standard_Real Dy = Draw::Atof (argv[2]);
7929 Standard_Real Dz = Draw::Atof (argv[3]);
7930 Standard_Boolean aStart = Standard_True;
7933 aStart = (Draw::Atoi (argv[4]) > 0);
7936 Handle(V3d_View) aView = ViewerTest::CurrentView();
7937 aView->Move(Dx,Dy,Dz,aStart);
7941 //=======================================================================
7942 //function : VTranslateView
7944 //=======================================================================
7945 static Standard_Integer VTranslateView (Draw_Interpretor& di,
7946 Standard_Integer argc,
7949 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7950 if(aContext.IsNull())
7952 di << "use 'vinit' command before " << argv[0] << "\n";
7955 if(argc < 4 || argc > 5)
7957 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
7960 Standard_Real Dx = Draw::Atof (argv[1]);
7961 Standard_Real Dy = Draw::Atof (argv[2]);
7962 Standard_Real Dz = Draw::Atof (argv[3]);
7963 Standard_Boolean aStart = Standard_True;
7966 aStart = (Draw::Atoi (argv[4]) > 0);
7969 Handle(V3d_View) aView = ViewerTest::CurrentView();
7970 aView->Translate(Dx,Dy,Dz,aStart);
7974 //=======================================================================
7975 //function : VTurnView
7977 //=======================================================================
7978 static Standard_Integer VTurnView (Draw_Interpretor& di,
7979 Standard_Integer argc,
7982 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7983 if(aContext.IsNull()) {
7984 di << "use 'vinit' command before " << argv[0] << "\n";
7987 if(argc < 4 || argc > 5){
7988 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
7991 Standard_Real Ax = Draw::Atof (argv[1]);
7992 Standard_Real Ay = Draw::Atof (argv[2]);
7993 Standard_Real Az = Draw::Atof (argv[3]);
7994 Standard_Boolean aStart = Standard_True;
7997 aStart = (Draw::Atoi (argv[4]) > 0);
8000 Handle(V3d_View) aView = ViewerTest::CurrentView();
8001 aView->Turn(Ax,Ay,Az,aStart);
8005 //==============================================================================
8006 //function : VTextureEnv
8007 //purpose : ENables or disables environment mapping
8008 //==============================================================================
8009 class OCC_TextureEnv : public Graphic3d_TextureEnv
8012 OCC_TextureEnv(const Standard_CString FileName);
8013 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
8014 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
8015 const Standard_Boolean theModulateFlag,
8016 const Graphic3d_TypeOfTextureFilter theFilter,
8017 const Standard_ShortReal theXScale,
8018 const Standard_ShortReal theYScale,
8019 const Standard_ShortReal theXShift,
8020 const Standard_ShortReal theYShift,
8021 const Standard_ShortReal theAngle);
8022 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
8024 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
8026 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
8027 : Graphic3d_TextureEnv(theFileName)
8031 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
8032 : Graphic3d_TextureEnv(theTexId)
8036 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
8037 const Standard_Boolean theModulateFlag,
8038 const Graphic3d_TypeOfTextureFilter theFilter,
8039 const Standard_ShortReal theXScale,
8040 const Standard_ShortReal theYScale,
8041 const Standard_ShortReal theXShift,
8042 const Standard_ShortReal theYShift,
8043 const Standard_ShortReal theAngle)
8045 myParams->SetRepeat (theRepeatFlag);
8046 myParams->SetModulate (theModulateFlag);
8047 myParams->SetFilter (theFilter);
8048 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
8049 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
8050 myParams->SetRotation (theAngle);
8053 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
8055 // get the active view
8056 Handle(V3d_View) aView = ViewerTest::CurrentView();
8059 std::cerr << "No active view. Please call vinit.\n";
8063 // Checking the input arguments
8064 Standard_Boolean anEnableFlag = Standard_False;
8065 Standard_Boolean isOk = theArgNb >= 2;
8068 TCollection_AsciiString anEnableOpt(theArgVec[1]);
8069 anEnableFlag = anEnableOpt.IsEqual("on");
8070 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
8074 isOk = (theArgNb == 3 || theArgNb == 11);
8077 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8078 isOk = (!aTextureOpt.IsIntegerValue() ||
8079 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
8081 if (isOk && theArgNb == 11)
8083 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
8084 aModulateOpt(theArgVec[4]),
8085 aFilterOpt (theArgVec[5]),
8086 aSScaleOpt (theArgVec[6]),
8087 aTScaleOpt (theArgVec[7]),
8088 aSTransOpt (theArgVec[8]),
8089 aTTransOpt (theArgVec[9]),
8090 anAngleOpt (theArgVec[10]);
8091 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
8092 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
8093 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
8094 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
8095 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
8096 anAngleOpt.IsRealValue());
8103 std::cerr << "Usage :" << std::endl;
8104 std::cerr << theArgVec[0] << " off" << std::endl;
8105 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;
8111 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8112 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
8113 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
8114 new OCC_TextureEnv(theArgVec[2]);
8118 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
8119 aTexEnv->SetTextureParameters(
8120 aRepeatOpt. IsEqual("repeat"),
8121 aModulateOpt.IsEqual("modulate"),
8122 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
8123 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
8124 Graphic3d_TOTF_TRILINEAR,
8125 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
8126 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
8127 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
8128 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
8129 (Standard_ShortReal)Draw::Atof(theArgVec[10])
8132 aView->SetTextureEnv(aTexEnv);
8134 else // Disabling environment mapping
8136 Handle(Graphic3d_TextureEnv) aTexture;
8137 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
8146 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
8148 //! Remove registered clipping plane from all views and objects.
8149 static void removePlane (MapOfPlanes& theRegPlanes,
8150 const TCollection_AsciiString& theName)
8152 Handle(Graphic3d_ClipPlane) aClipPlane;
8153 if (!theRegPlanes.Find (theName, aClipPlane))
8155 std::cout << "Warning: no such plane.\n";
8159 theRegPlanes.UnBind (theName);
8160 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
8161 anIObjIt.More(); anIObjIt.Next())
8163 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
8164 aPrs->RemoveClipPlane (aClipPlane);
8167 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
8168 aViewIt.More(); aViewIt.Next())
8170 const Handle(V3d_View)& aView = aViewIt.Key2();
8171 aView->RemoveClipPlane(aClipPlane);
8174 ViewerTest::RedrawAllViews();
8178 //===============================================================================================
8179 //function : VClipPlane
8181 //===============================================================================================
8182 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8184 // use short-cut for created clip planes map of created (or "registered by name") clip planes
8185 static MapOfPlanes aRegPlanes;
8189 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
8191 theDi << aPlaneIter.Key() << " ";
8196 TCollection_AsciiString aCommand (theArgVec[1]);
8197 aCommand.LowerCase();
8198 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
8199 if (anActiveView.IsNull())
8201 std::cout << "Error: no active view.\n";
8205 // print maximum number of planes for current viewer
8206 if (aCommand == "-maxplanes"
8207 || aCommand == "maxplanes")
8209 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
8210 << " plane slots provided by driver.\n";
8214 // create / delete plane instance
8215 if (aCommand == "-create"
8216 || aCommand == "create"
8217 || aCommand == "-delete"
8218 || aCommand == "delete"
8219 || aCommand == "-clone"
8220 || aCommand == "clone")
8224 std::cout << "Syntax error: plane name is required.\n";
8228 Standard_Boolean toCreate = aCommand == "-create"
8229 || aCommand == "create";
8230 Standard_Boolean toClone = aCommand == "-clone"
8231 || aCommand == "clone";
8232 Standard_Boolean toDelete = aCommand == "-delete"
8233 || aCommand == "delete";
8234 TCollection_AsciiString aPlane (theArgVec[2]);
8238 if (aRegPlanes.IsBound (aPlane))
8240 std::cout << "Warning: existing plane has been overridden.\n";
8245 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8249 else if (toClone) // toClone
8251 if (!aRegPlanes.IsBound (aPlane))
8253 std::cout << "Error: no such plane.\n";
8256 else if (theArgsNb < 4)
8258 std::cout << "Syntax error: enter name for new plane.\n";
8262 TCollection_AsciiString aClone (theArgVec[3]);
8263 if (aRegPlanes.IsBound (aClone))
8265 std::cout << "Error: plane name is in use.\n";
8269 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
8271 aRegPlanes.Bind (aClone, aClipPlane->Clone());
8281 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
8283 aPlane = aPlaneIter.Key();
8284 removePlane (aRegPlanes, aPlane);
8285 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
8290 removePlane (aRegPlanes, aPlane);
8296 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8301 // set / unset plane command
8302 if (aCommand == "set"
8303 || aCommand == "unset")
8307 std::cout << "Syntax error: need more arguments.\n";
8311 // redirect to new syntax
8312 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
8313 anArgVec.SetValue (1, theArgVec[0]);
8314 anArgVec.SetValue (2, theArgVec[2]);
8315 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
8316 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
8318 anArgVec.SetValue (anIt, theArgVec[anIt]);
8321 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
8324 // change plane command
8325 TCollection_AsciiString aPlaneName;
8326 Handle(Graphic3d_ClipPlane) aClipPlane;
8327 Standard_Integer anArgIter = 0;
8328 if (aCommand == "-change"
8329 || aCommand == "change")
8331 // old syntax support
8334 std::cout << "Syntax error: need more arguments.\n";
8339 aPlaneName = theArgVec[2];
8340 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
8342 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
8346 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
8349 aPlaneName = theArgVec[1];
8354 aPlaneName = theArgVec[1];
8355 aClipPlane = new Graphic3d_ClipPlane();
8356 aRegPlanes.Bind (aPlaneName, aClipPlane);
8357 theDi << "Created new plane " << aPlaneName << ".\n";
8360 if (theArgsNb - anArgIter < 1)
8362 std::cout << "Syntax error: need more arguments.\n";
8366 for (; anArgIter < theArgsNb; ++anArgIter)
8368 const char** aChangeArgs = theArgVec + anArgIter;
8369 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
8370 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
8371 aChangeArg.LowerCase();
8373 Standard_Boolean toEnable = Standard_True;
8374 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
8376 aClipPlane->SetOn (toEnable);
8378 else if (aChangeArg == "-equation"
8379 || aChangeArg == "equation")
8381 if (aNbChangeArgs < 5)
8383 std::cout << "Syntax error: need more arguments.\n";
8387 Standard_Real aCoeffA = Draw::Atof (aChangeArgs [1]);
8388 Standard_Real aCoeffB = Draw::Atof (aChangeArgs [2]);
8389 Standard_Real aCoeffC = Draw::Atof (aChangeArgs [3]);
8390 Standard_Real aCoeffD = Draw::Atof (aChangeArgs [4]);
8391 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
8394 else if (aChangeArg == "-capping"
8395 || aChangeArg == "capping")
8397 if (aNbChangeArgs < 2)
8399 std::cout << "Syntax error: need more arguments.\n";
8403 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8405 aClipPlane->SetCapping (toEnable);
8410 // just skip otherwise (old syntax)
8413 else if (aChangeArg == "-useobjectmaterial"
8414 || aChangeArg == "-useobjectmat"
8415 || aChangeArg == "-useobjmat"
8416 || aChangeArg == "-useobjmaterial")
8418 if (aNbChangeArgs < 2)
8420 std::cout << "Syntax error: need more arguments.\n";
8424 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8426 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
8430 else if (aChangeArg == "-useobjecttexture"
8431 || aChangeArg == "-useobjecttex"
8432 || aChangeArg == "-useobjtexture"
8433 || aChangeArg == "-useobjtex")
8435 if (aNbChangeArgs < 2)
8437 std::cout << "Syntax error: need more arguments.\n";
8441 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8443 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
8447 else if (aChangeArg == "-useobjectshader"
8448 || aChangeArg == "-useobjshader")
8450 if (aNbChangeArgs < 2)
8452 std::cout << "Syntax error: need more arguments.\n";
8456 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8458 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
8462 else if (aChangeArg == "-color"
8463 || aChangeArg == "color")
8465 Quantity_Color aColor;
8466 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
8471 std::cout << "Syntax error: need more arguments.\n";
8475 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
8476 aMat.SetAmbientColor (aColor);
8477 aMat.SetDiffuseColor (aColor);
8478 aClipPlane->SetCappingMaterial (aMat);
8479 anArgIter += aNbParsed;
8481 else if (aChangeArg == "-texname"
8482 || aChangeArg == "texname")
8484 if (aNbChangeArgs < 2)
8486 std::cout << "Syntax error: need more arguments.\n";
8490 TCollection_AsciiString aTextureName (aChangeArgs[1]);
8491 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
8492 if (!aTexture->IsDone())
8494 aClipPlane->SetCappingTexture (NULL);
8498 aTexture->EnableModulate();
8499 aTexture->EnableRepeat();
8500 aClipPlane->SetCappingTexture (aTexture);
8504 else if (aChangeArg == "-texscale"
8505 || aChangeArg == "texscale")
8507 if (aClipPlane->CappingTexture().IsNull())
8509 std::cout << "Error: no texture is set.\n";
8513 if (aNbChangeArgs < 3)
8515 std::cout << "Syntax error: need more arguments.\n";
8519 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8520 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8521 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
8524 else if (aChangeArg == "-texorigin"
8525 || aChangeArg == "texorigin") // texture origin
8527 if (aClipPlane->CappingTexture().IsNull())
8529 std::cout << "Error: no texture is set.\n";
8533 if (aNbChangeArgs < 3)
8535 std::cout << "Syntax error: need more arguments.\n";
8539 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8540 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8542 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
8545 else if (aChangeArg == "-texrotate"
8546 || aChangeArg == "texrotate") // texture rotation
8548 if (aClipPlane->CappingTexture().IsNull())
8550 std::cout << "Error: no texture is set.\n";
8554 if (aNbChangeArgs < 2)
8556 std::cout << "Syntax error: need more arguments.\n";
8560 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8561 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
8564 else if (aChangeArg == "-hatch"
8565 || aChangeArg == "hatch")
8567 if (aNbChangeArgs < 2)
8569 std::cout << "Syntax error: need more arguments.\n";
8573 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
8574 aHatchStr.LowerCase();
8575 if (aHatchStr == "on")
8577 aClipPlane->SetCappingHatchOn();
8579 else if (aHatchStr == "off")
8581 aClipPlane->SetCappingHatchOff();
8585 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
8589 else if (aChangeArg == "-delete"
8590 || aChangeArg == "delete")
8592 removePlane (aRegPlanes, aPlaneName);
8595 else if (aChangeArg == "-set"
8596 || aChangeArg == "-unset"
8597 || aChangeArg == "-setoverrideglobal")
8599 // set / unset plane command
8600 const Standard_Boolean toSet = aChangeArg.StartsWith ("-set");
8601 const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal";
8602 Standard_Integer anIt = 1;
8603 for (; anIt < aNbChangeArgs; ++anIt)
8605 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
8606 if (anEntityName.IsEmpty()
8607 || anEntityName.Value (1) == '-')
8611 else if (!toOverrideGlobal
8612 && ViewerTest_myViews.IsBound1 (anEntityName))
8614 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
8617 aView->AddClipPlane (aClipPlane);
8621 aView->RemoveClipPlane (aClipPlane);
8625 else if (GetMapOfAIS().IsBound2 (anEntityName))
8627 Handle(AIS_InteractiveObject) aIObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
8630 aIObj->AddClipPlane (aClipPlane);
8634 aIObj->RemoveClipPlane (aClipPlane);
8636 if (!aIObj->ClipPlanes().IsNull())
8638 aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal);
8643 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
8650 // apply to active view
8653 anActiveView->AddClipPlane (aClipPlane);
8657 anActiveView->RemoveClipPlane (aClipPlane);
8662 anArgIter = anArgIter + anIt - 1;
8667 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
8672 ViewerTest::RedrawAllViews();
8676 //===============================================================================================
8677 //function : VZRange
8679 //===============================================================================================
8680 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8682 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
8684 if (aCurrentView.IsNull())
8686 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
8690 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
8694 theDi << "ZNear: " << aCamera->ZNear() << "\n";
8695 theDi << "ZFar: " << aCamera->ZFar() << "\n";
8701 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
8702 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
8704 if (aNewZNear >= aNewZFar)
8706 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
8710 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
8712 std::cout << theArgVec[0] << ": invalid arguments: ";
8713 std::cout << "znear, zfar should be positive for perspective camera.\n";
8717 aCamera->SetZRange (aNewZNear, aNewZFar);
8721 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
8725 aCurrentView->Redraw();
8730 //===============================================================================================
8731 //function : VAutoZFit
8733 //===============================================================================================
8734 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8736 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
8738 if (aCurrentView.IsNull())
8740 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
8744 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
8748 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
8754 theDi << "Auto z-fit mode: \n"
8755 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
8756 << "Scale: " << aScale << "\n";
8760 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
8764 aScale = Draw::Atoi (theArgVec[2]);
8767 aCurrentView->SetAutoZFitMode (isOn, aScale);
8768 aCurrentView->AutoZFit();
8769 aCurrentView->Redraw();
8774 //! Auxiliary function to print projection type
8775 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
8777 switch (theProjType)
8779 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
8780 case Graphic3d_Camera::Projection_Perspective: return "perspective";
8781 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
8782 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
8783 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
8788 //===============================================================================================
8789 //function : VCamera
8791 //===============================================================================================
8792 static int VCamera (Draw_Interpretor& theDI,
8793 Standard_Integer theArgsNb,
8794 const char** theArgVec)
8796 Handle(V3d_View) aView = ViewerTest::CurrentView();
8799 std::cout << "Error: no active view.\n";
8803 Handle(Graphic3d_Camera) aCamera = aView->Camera();
8806 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
8807 theDI << "FOVy: " << aCamera->FOVy() << "\n";
8808 theDI << "Distance: " << aCamera->Distance() << "\n";
8809 theDI << "IOD: " << aCamera->IOD() << "\n";
8810 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
8811 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
8812 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
8816 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
8818 Standard_CString anArg = theArgVec[anArgIter];
8819 TCollection_AsciiString anArgCase (anArg);
8820 anArgCase.LowerCase();
8821 if (anArgCase == "-proj"
8822 || anArgCase == "-projection"
8823 || anArgCase == "-projtype"
8824 || anArgCase == "-projectiontype")
8826 theDI << projTypeName (aCamera->ProjectionType()) << " ";
8828 else if (anArgCase == "-ortho"
8829 || anArgCase == "-orthographic")
8831 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
8833 else if (anArgCase == "-persp"
8834 || anArgCase == "-perspective"
8835 || anArgCase == "-perspmono"
8836 || anArgCase == "-perspectivemono"
8837 || anArgCase == "-mono")
8839 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
8841 else if (anArgCase == "-stereo"
8842 || anArgCase == "-stereoscopic"
8843 || anArgCase == "-perspstereo"
8844 || anArgCase == "-perspectivestereo")
8846 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
8848 else if (anArgCase == "-left"
8849 || anArgCase == "-lefteye"
8850 || anArgCase == "-monoleft"
8851 || anArgCase == "-monolefteye"
8852 || anArgCase == "-perpsleft"
8853 || anArgCase == "-perpslefteye")
8855 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
8857 else if (anArgCase == "-right"
8858 || anArgCase == "-righteye"
8859 || anArgCase == "-monoright"
8860 || anArgCase == "-monorighteye"
8861 || anArgCase == "-perpsright")
8863 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
8865 else if (anArgCase == "-dist"
8866 || anArgCase == "-distance")
8868 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8869 if (anArgValue != NULL
8870 && *anArgValue != '-')
8873 aCamera->SetDistance (Draw::Atof (anArgValue));
8876 theDI << aCamera->Distance() << " ";
8878 else if (anArgCase == "-iod")
8880 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8881 if (anArgValue != NULL
8882 && *anArgValue != '-')
8885 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
8888 theDI << aCamera->IOD() << " ";
8890 else if (anArgCase == "-iodtype")
8892 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
8893 TCollection_AsciiString anValueCase (anArgValue);
8894 anValueCase.LowerCase();
8895 if (anValueCase == "abs"
8896 || anValueCase == "absolute")
8899 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
8902 else if (anValueCase == "rel"
8903 || anValueCase == "relative")
8906 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
8909 else if (*anArgValue != '-')
8911 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
8914 switch (aCamera->GetIODType())
8916 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
8917 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
8920 else if (anArgCase == "-zfocus")
8922 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8923 if (anArgValue != NULL
8924 && *anArgValue != '-')
8927 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
8930 theDI << aCamera->ZFocus() << " ";
8932 else if (anArgCase == "-zfocustype")
8934 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
8935 TCollection_AsciiString anValueCase (anArgValue);
8936 anValueCase.LowerCase();
8937 if (anValueCase == "abs"
8938 || anValueCase == "absolute")
8941 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
8944 else if (anValueCase == "rel"
8945 || anValueCase == "relative")
8948 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
8951 else if (*anArgValue != '-')
8953 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
8956 switch (aCamera->ZFocusType())
8958 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
8959 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
8962 else if (anArgCase == "-fov"
8963 || anArgCase == "-fovy")
8965 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8966 if (anArgValue != NULL
8967 && *anArgValue != '-')
8970 aCamera->SetFOVy (Draw::Atof (anArgValue));
8973 theDI << aCamera->FOVy() << " ";
8977 std::cout << "Error: unknown argument '" << anArg << "'\n";
8988 //! Parse stereo output mode
8989 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
8990 Graphic3d_StereoMode& theMode)
8992 TCollection_AsciiString aFlag (theArg);
8994 if (aFlag == "quadbuffer")
8996 theMode = Graphic3d_StereoMode_QuadBuffer;
8998 else if (aFlag == "anaglyph")
9000 theMode = Graphic3d_StereoMode_Anaglyph;
9002 else if (aFlag == "row"
9003 || aFlag == "rowinterlaced")
9005 theMode = Graphic3d_StereoMode_RowInterlaced;
9007 else if (aFlag == "col"
9008 || aFlag == "colinterlaced"
9009 || aFlag == "columninterlaced")
9011 theMode = Graphic3d_StereoMode_ColumnInterlaced;
9013 else if (aFlag == "chess"
9014 || aFlag == "chessboard")
9016 theMode = Graphic3d_StereoMode_ChessBoard;
9018 else if (aFlag == "sbs"
9019 || aFlag == "sidebyside")
9021 theMode = Graphic3d_StereoMode_SideBySide;
9023 else if (aFlag == "ou"
9024 || aFlag == "overunder")
9026 theMode = Graphic3d_StereoMode_OverUnder;
9028 else if (aFlag == "pageflip"
9029 || aFlag == "softpageflip")
9031 theMode = Graphic3d_StereoMode_SoftPageFlip;
9035 return Standard_False;
9037 return Standard_True;
9040 //! Parse anaglyph filter
9041 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
9042 Graphic3d_RenderingParams::Anaglyph& theFilter)
9044 TCollection_AsciiString aFlag (theArg);
9046 if (aFlag == "redcyansimple")
9048 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9050 else if (aFlag == "redcyan"
9051 || aFlag == "redcyanoptimized")
9053 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
9055 else if (aFlag == "yellowbluesimple")
9057 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
9059 else if (aFlag == "yellowblue"
9060 || aFlag == "yellowblueoptimized")
9062 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
9064 else if (aFlag == "greenmagenta"
9065 || aFlag == "greenmagentasimple")
9067 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
9071 return Standard_False;
9073 return Standard_True;
9076 //==============================================================================
9077 //function : VStereo
9079 //==============================================================================
9081 static int VStereo (Draw_Interpretor& theDI,
9082 Standard_Integer theArgNb,
9083 const char** theArgVec)
9085 Handle(V3d_View) aView = ViewerTest::CurrentView();
9090 std::cout << "Error: no active viewer!\n";
9094 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
9095 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
9098 TCollection_AsciiString aMode;
9099 switch (aView->RenderingParams().StereoMode)
9101 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
9102 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
9103 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
9104 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
9105 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
9106 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
9107 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
9108 case Graphic3d_StereoMode_Anaglyph :
9110 switch (aView->RenderingParams().AnaglyphFilter)
9112 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
9113 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
9114 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
9115 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
9116 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
9121 theDI << "Mode " << aMode << "\n";
9126 Handle(Graphic3d_Camera) aCamera;
9127 Graphic3d_RenderingParams* aParams = NULL;
9128 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
9129 if (!aView.IsNull())
9131 aParams = &aView->ChangeRenderingParams();
9132 aMode = aParams->StereoMode;
9133 aCamera = aView->Camera();
9136 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
9137 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
9139 Standard_CString anArg = theArgVec[anArgIter];
9140 TCollection_AsciiString aFlag (anArg);
9142 if (anUpdateTool.parseRedrawMode (aFlag))
9146 else if (aFlag == "0"
9149 if (++anArgIter < theArgNb)
9151 std::cout << "Error: wrong number of arguments!\n";
9155 if (!aCamera.IsNull()
9156 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
9158 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
9160 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
9163 else if (aFlag == "1"
9166 if (++anArgIter < theArgNb)
9168 std::cout << "Error: wrong number of arguments!\n";
9172 if (!aCamera.IsNull())
9174 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9176 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9179 else if (aFlag == "-reverse"
9180 || aFlag == "-reversed"
9181 || aFlag == "-swap")
9183 Standard_Boolean toEnable = Standard_True;
9184 if (++anArgIter < theArgNb
9185 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9189 aParams->ToReverseStereo = toEnable;
9191 else if (aFlag == "-noreverse"
9192 || aFlag == "-noswap")
9194 Standard_Boolean toDisable = Standard_True;
9195 if (++anArgIter < theArgNb
9196 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
9200 aParams->ToReverseStereo = !toDisable;
9202 else if (aFlag == "-mode"
9203 || aFlag == "-stereomode")
9205 if (++anArgIter >= theArgNb
9206 || !parseStereoMode (theArgVec[anArgIter], aMode))
9208 std::cout << "Error: syntax error at '" << anArg << "'\n";
9212 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9214 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9217 else if (aFlag == "-anaglyph"
9218 || aFlag == "-anaglyphfilter")
9220 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9221 if (++anArgIter >= theArgNb
9222 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
9224 std::cout << "Error: syntax error at '" << anArg << "'\n";
9228 aMode = Graphic3d_StereoMode_Anaglyph;
9229 aParams->AnaglyphFilter = aFilter;
9231 else if (parseStereoMode (anArg, aMode)) // short syntax
9233 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9235 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9240 std::cout << "Error: syntax error at '" << anArg << "'\n";
9245 if (!aView.IsNull())
9247 aParams->StereoMode = aMode;
9248 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9253 //===============================================================================================
9254 //function : VDefaults
9256 //===============================================================================================
9257 static int VDefaults (Draw_Interpretor& theDi,
9258 Standard_Integer theArgsNb,
9259 const char** theArgVec)
9261 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
9264 std::cerr << "No active viewer!\n";
9268 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
9271 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
9273 theDi << "DeflType: relative\n"
9274 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
9278 theDi << "DeflType: absolute\n"
9279 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
9281 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
9282 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
9286 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
9288 TCollection_AsciiString anArg (theArgVec[anArgIter]);
9290 if (anArg == "-ABSDEFL"
9291 || anArg == "-ABSOLUTEDEFLECTION"
9293 || anArg == "-DEFLECTION")
9295 if (++anArgIter >= theArgsNb)
9297 std::cout << "Error: wrong syntax at " << anArg << "\n";
9300 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
9301 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
9303 else if (anArg == "-RELDEFL"
9304 || anArg == "-RELATIVEDEFLECTION"
9305 || anArg == "-DEVCOEFF"
9306 || anArg == "-DEVIATIONCOEFF"
9307 || anArg == "-DEVIATIONCOEFFICIENT")
9309 if (++anArgIter >= theArgsNb)
9311 std::cout << "Error: wrong syntax at " << anArg << "\n";
9314 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
9315 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
9317 else if (anArg == "-ANGDEFL"
9318 || anArg == "-ANGULARDEFL"
9319 || anArg == "-ANGULARDEFLECTION")
9321 if (++anArgIter >= theArgsNb)
9323 std::cout << "Error: wrong syntax at " << anArg << "\n";
9326 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
9327 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
9329 else if (anArg == "-AUTOTR"
9330 || anArg == "-AUTOTRIANG"
9331 || anArg == "-AUTOTRIANGULATION")
9333 if (++anArgIter >= theArgsNb)
9335 std::cout << "Error: wrong syntax at " << anArg << "\n";
9338 TCollection_AsciiString aValue (theArgVec[anArgIter]);
9343 aDefParams->SetAutoTriangulation (Standard_True);
9345 else if (aValue == "off"
9348 aDefParams->SetAutoTriangulation (Standard_False);
9353 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
9360 //! Auxiliary method
9361 inline void addLight (const Handle(V3d_Light)& theLightNew,
9362 const Graphic3d_ZLayerId theLayer,
9363 const Standard_Boolean theIsGlobal)
9365 if (theLightNew.IsNull())
9370 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9371 if (theLayer == Graphic3d_ZLayerId_UNKNOWN)
9373 aViewer->AddLight (theLightNew);
9376 aViewer->SetLightOn (theLightNew);
9380 ViewerTest::CurrentView()->SetLightOn (theLightNew);
9385 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer);
9386 if (aSettings.Lights().IsNull())
9388 aSettings.SetLights (new Graphic3d_LightSet());
9390 aSettings.Lights()->Add (theLightNew);
9391 aViewer->SetZLayerSettings (theLayer, aSettings);
9395 //! Auxiliary method
9396 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
9398 TCollection_AsciiString anArgNextCase (theArgNext);
9399 anArgNextCase.UpperCase();
9400 if (anArgNextCase.Length() > 5
9401 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
9403 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
9407 return theArgNext.IntegerValue();
9411 //===============================================================================================
9414 //===============================================================================================
9415 static int VLight (Draw_Interpretor& theDi,
9416 Standard_Integer theArgsNb,
9417 const char** theArgVec)
9419 Handle(V3d_View) aView = ViewerTest::CurrentView();
9420 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9422 || aViewer.IsNull())
9424 std::cerr << "No active viewer!\n";
9428 Standard_Real anXYZ[3] = {};
9429 Standard_Real anAtten[2] = {};
9432 // print lights info
9433 Standard_Integer aLightId = 0;
9434 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
9436 Handle(V3d_Light) aLight = aLightIter.Value();
9437 const Quantity_Color aColor = aLight->Color();
9438 theDi << "Light #" << aLightId
9439 << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "")
9440 << " [" << aLight->GetId() << "]" << "\n";
9441 switch (aLight->Type())
9445 theDi << " Type: Ambient\n";
9446 theDi << " Intensity: " << aLight->Intensity() << "\n";
9449 case V3d_DIRECTIONAL:
9451 theDi << " Type: Directional\n";
9452 theDi << " Intensity: " << aLight->Intensity() << "\n";
9453 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9454 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
9455 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
9456 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9459 case V3d_POSITIONAL:
9461 theDi << " Type: Positional\n";
9462 theDi << " Intensity: " << aLight->Intensity() << "\n";
9463 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9464 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
9465 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9466 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9467 aLight->Attenuation (anAtten[0], anAtten[1]);
9468 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
9473 theDi << " Type: Spot\n";
9474 theDi << " Intensity: " << aLight->Intensity() << "\n";
9475 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9476 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9477 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9478 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
9479 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9480 aLight->Attenuation (anAtten[0], anAtten[1]);
9481 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
9482 theDi << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n";
9483 theDi << " Exponent: " << aLight->Concentration() << "\n";
9488 theDi << " Type: UNKNOWN\n";
9492 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n";
9496 Handle(V3d_Light) aLightNew;
9497 Handle(V3d_Light) aLightOld;
9498 Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN;
9499 Standard_Boolean isGlobal = Standard_True;
9500 Standard_Boolean toCreate = Standard_False;
9501 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
9502 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
9504 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
9506 TCollection_AsciiString aName, aValue;
9507 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
9508 TCollection_AsciiString anArgCase (anArg);
9509 anArgCase.UpperCase();
9510 if (anUpdateTool.parseRedrawMode (anArg))
9515 if (anArgCase.IsEqual ("NEW")
9516 || anArgCase.IsEqual ("ADD")
9517 || anArgCase.IsEqual ("CREATE")
9518 || anArgCase.IsEqual ("-NEW")
9519 || anArgCase.IsEqual ("-ADD")
9520 || anArgCase.IsEqual ("-CREATE"))
9522 toCreate = Standard_True;
9524 else if (anArgCase.IsEqual ("-LAYER")
9525 || anArgCase.IsEqual ("-ZLAYER"))
9527 if (++anArgIt >= theArgsNb)
9529 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9533 TCollection_AsciiString aValStr (theArgVec[anArgIt]);
9534 aValStr.LowerCase();
9535 if (aValStr == "default"
9536 || aValStr == "def")
9538 aLayer = Graphic3d_ZLayerId_Default;
9540 else if (aValStr == "top")
9542 aLayer = Graphic3d_ZLayerId_Top;
9544 else if (aValStr == "topmost")
9546 aLayer = Graphic3d_ZLayerId_Topmost;
9548 else if (aValStr == "toposd"
9549 || aValStr == "osd")
9551 aLayer = Graphic3d_ZLayerId_TopOSD;
9553 else if (aValStr == "botosd"
9554 || aValStr == "bottom")
9556 aLayer = Graphic3d_ZLayerId_BotOSD;
9558 else if (aValStr.IsIntegerValue())
9560 aLayer = Draw::Atoi (theArgVec[anArgIt]);
9564 std::cout << "Wrong syntax at argument '" << anArg << "'!\n";
9568 else if (anArgCase.IsEqual ("GLOB")
9569 || anArgCase.IsEqual ("GLOBAL")
9570 || anArgCase.IsEqual ("-GLOB")
9571 || anArgCase.IsEqual ("-GLOBAL"))
9573 isGlobal = Standard_True;
9575 else if (anArgCase.IsEqual ("LOC")
9576 || anArgCase.IsEqual ("LOCAL")
9577 || anArgCase.IsEqual ("-LOC")
9578 || anArgCase.IsEqual ("-LOCAL"))
9580 isGlobal = Standard_False;
9582 else if (anArgCase.IsEqual ("DEF")
9583 || anArgCase.IsEqual ("DEFAULTS")
9584 || anArgCase.IsEqual ("-DEF")
9585 || anArgCase.IsEqual ("-DEFAULTS"))
9587 toCreate = Standard_False;
9588 aViewer->SetDefaultLights();
9590 else if (anArgCase.IsEqual ("CLR")
9591 || anArgCase.IsEqual ("CLEAR")
9592 || anArgCase.IsEqual ("-CLR")
9593 || anArgCase.IsEqual ("-CLEAR"))
9595 toCreate = Standard_False;
9597 TColStd_SequenceOfInteger aLayers;
9598 aViewer->GetAllZLayers (aLayers);
9599 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
9601 if (aLayeriter.Value() == aLayer
9602 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
9604 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
9605 aSettings.SetLights (Handle(Graphic3d_LightSet)());
9606 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
9607 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
9614 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
9616 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
9618 Handle(V3d_Light) aLight = aLightIter.Value();
9619 aViewer->DelLight (aLight);
9620 aLightIter = aView->ActiveLightIterator();
9624 else if (anArgCase.IsEqual ("AMB")
9625 || anArgCase.IsEqual ("AMBIENT")
9626 || anArgCase.IsEqual ("AMBLIGHT"))
9630 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9634 addLight (aLightNew, aLayer, isGlobal);
9635 toCreate = Standard_False;
9636 aLightNew = new V3d_AmbientLight();
9638 else if (anArgCase.IsEqual ("DIRECTIONAL")
9639 || anArgCase.IsEqual ("DIRLIGHT"))
9643 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9647 addLight (aLightNew, aLayer, isGlobal);
9648 toCreate = Standard_False;
9649 aLightNew = new V3d_DirectionalLight();
9651 else if (anArgCase.IsEqual ("SPOT")
9652 || anArgCase.IsEqual ("SPOTLIGHT"))
9656 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9660 addLight (aLightNew, aLayer, isGlobal);
9661 toCreate = Standard_False;
9662 aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0));
9664 else if (anArgCase.IsEqual ("POSLIGHT")
9665 || anArgCase.IsEqual ("POSITIONAL"))
9669 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9673 addLight (aLightNew, aLayer, isGlobal);
9674 toCreate = Standard_False;
9675 aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0));
9677 else if (anArgCase.IsEqual ("CHANGE")
9678 || anArgCase.IsEqual ("-CHANGE"))
9680 if (++anArgIt >= theArgsNb)
9682 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9686 addLight (aLightNew, aLayer, isGlobal);
9687 aLightNew.Nullify();
9688 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
9689 Standard_Integer aLightIt = 0;
9690 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
9692 if (aLightIt == aLightId)
9694 aLightOld = aLightIter.Value();
9699 if (aLightOld.IsNull())
9701 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
9705 else if (anArgCase.IsEqual ("DEL")
9706 || anArgCase.IsEqual ("DELETE")
9707 || anArgCase.IsEqual ("-DEL")
9708 || anArgCase.IsEqual ("-DELETE"))
9710 Handle(V3d_Light) aLightDel;
9711 if (++anArgIt >= theArgsNb)
9713 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9717 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
9718 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
9719 Standard_Integer aLightIt = 0;
9720 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
9722 aLightDel = aLightIter.Value();
9723 if (aLightIt == aLightDelId)
9728 if (aLightDel.IsNull())
9733 TColStd_SequenceOfInteger aLayers;
9734 aViewer->GetAllZLayers (aLayers);
9735 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
9737 if (aLayeriter.Value() == aLayer
9738 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
9740 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
9741 if (!aSettings.Lights().IsNull())
9743 aSettings.Lights()->Remove (aLightDel);
9744 if (aSettings.Lights()->IsEmpty())
9746 aSettings.SetLights (Handle(Graphic3d_LightSet)());
9749 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
9750 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
9757 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
9759 aViewer->DelLight (aLightDel);
9762 else if (anArgCase.IsEqual ("COLOR")
9763 || anArgCase.IsEqual ("COLOUR")
9764 || anArgCase.IsEqual ("-COLOR")
9765 || anArgCase.IsEqual ("-COLOUR"))
9767 if (++anArgIt >= theArgsNb
9768 || aLightCurr.IsNull())
9770 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9774 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
9775 anArgNext.UpperCase();
9776 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
9777 aLightCurr->SetColor (aColor);
9779 else if (anArgCase.IsEqual ("POS")
9780 || anArgCase.IsEqual ("POSITION")
9781 || anArgCase.IsEqual ("-POS")
9782 || anArgCase.IsEqual ("-POSITION"))
9784 if ((anArgIt + 3) >= theArgsNb
9785 || aLightCurr.IsNull()
9786 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
9787 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
9789 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9793 anXYZ[0] = Atof (theArgVec[++anArgIt]);
9794 anXYZ[1] = Atof (theArgVec[++anArgIt]);
9795 anXYZ[2] = Atof (theArgVec[++anArgIt]);
9796 aLightCurr->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
9798 else if (anArgCase.IsEqual ("DIR")
9799 || anArgCase.IsEqual ("DIRECTION")
9800 || anArgCase.IsEqual ("-DIR")
9801 || anArgCase.IsEqual ("-DIRECTION"))
9803 if ((anArgIt + 3) >= theArgsNb
9804 || aLightCurr.IsNull()
9805 || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL
9806 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
9808 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9812 anXYZ[0] = Atof (theArgVec[++anArgIt]);
9813 anXYZ[1] = Atof (theArgVec[++anArgIt]);
9814 anXYZ[2] = Atof (theArgVec[++anArgIt]);
9815 aLightCurr->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
9817 else if (anArgCase.IsEqual ("SM")
9818 || anArgCase.IsEqual ("SMOOTHNESS")
9819 || anArgCase.IsEqual ("-SM")
9820 || anArgCase.IsEqual ("-SMOOTHNESS"))
9822 if (++anArgIt >= theArgsNb
9823 || aLightCurr.IsNull())
9825 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9829 Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
9830 if (Abs (aSmoothness) <= ShortRealEpsilon())
9832 aLightCurr->SetIntensity (1.f);
9834 else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon())
9836 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
9840 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
9841 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
9844 if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL)
9846 aLightCurr->SetSmoothRadius (aSmoothness);
9848 else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
9850 aLightCurr->SetSmoothAngle (aSmoothness);
9853 else if (anArgCase.IsEqual ("INT")
9854 || anArgCase.IsEqual ("INTENSITY")
9855 || anArgCase.IsEqual ("-INT")
9856 || anArgCase.IsEqual ("-INTENSITY"))
9858 if (++anArgIt >= theArgsNb
9859 || aLightCurr.IsNull())
9861 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9865 Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
9866 aLightCurr->SetIntensity (aIntensity);
9868 else if (anArgCase.IsEqual ("ANG")
9869 || anArgCase.IsEqual ("ANGLE")
9870 || anArgCase.IsEqual ("-ANG")
9871 || anArgCase.IsEqual ("-ANGLE"))
9873 if (++anArgIt >= theArgsNb
9874 || aLightCurr.IsNull()
9875 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
9877 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9881 Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
9882 aLightCurr->SetAngle (Standard_ShortReal (anAngle / 180.0 * M_PI));
9884 else if (anArgCase.IsEqual ("CONSTATTEN")
9885 || anArgCase.IsEqual ("CONSTATTENUATION")
9886 || anArgCase.IsEqual ("-CONSTATTEN")
9887 || anArgCase.IsEqual ("-CONSTATTENUATION"))
9889 if (++anArgIt >= theArgsNb
9890 || aLightCurr.IsNull()
9891 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
9892 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
9894 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9898 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
9899 anAtten[0] = Atof (theArgVec[anArgIt]);
9900 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
9902 else if (anArgCase.IsEqual ("LINATTEN")
9903 || anArgCase.IsEqual ("LINEARATTEN")
9904 || anArgCase.IsEqual ("LINEARATTENUATION")
9905 || anArgCase.IsEqual ("-LINATTEN")
9906 || anArgCase.IsEqual ("-LINEARATTEN")
9907 || anArgCase.IsEqual ("-LINEARATTENUATION"))
9909 if (++anArgIt >= theArgsNb
9910 || aLightCurr.IsNull()
9911 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
9912 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
9914 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9918 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
9919 anAtten[1] = Atof (theArgVec[anArgIt]);
9920 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
9922 else if (anArgCase.IsEqual ("EXP")
9923 || anArgCase.IsEqual ("EXPONENT")
9924 || anArgCase.IsEqual ("SPOTEXP")
9925 || anArgCase.IsEqual ("SPOTEXPONENT")
9926 || anArgCase.IsEqual ("-EXP")
9927 || anArgCase.IsEqual ("-EXPONENT")
9928 || anArgCase.IsEqual ("-SPOTEXP")
9929 || anArgCase.IsEqual ("-SPOTEXPONENT"))
9931 if (++anArgIt >= theArgsNb
9932 || aLightCurr.IsNull()
9933 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
9935 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9939 aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt]));
9941 else if (anArgCase.IsEqual ("HEAD")
9942 || anArgCase.IsEqual ("HEADLIGHT")
9943 || anArgCase.IsEqual ("-HEAD")
9944 || anArgCase.IsEqual ("-HEADLIGHT"))
9946 if (aLightCurr.IsNull()
9947 || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
9949 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9953 Standard_Boolean isHeadLight = Standard_True;
9954 if (anArgIt + 1 < theArgsNb
9955 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight))
9959 aLightCurr->SetHeadlight (isHeadLight);
9963 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
9967 addLight (aLightNew, aLayer, isGlobal);
9971 //! Read Graphic3d_RenderingParams::PerfCounters flag.
9972 static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue,
9973 Standard_Boolean& theToReset,
9974 Graphic3d_RenderingParams::PerfCounters& theFlagsRem,
9975 Graphic3d_RenderingParams::PerfCounters& theFlagsAdd)
9977 Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE;
9978 TCollection_AsciiString aVal = theValue;
9979 Standard_Boolean toReverse = Standard_False;
9982 theToReset = Standard_True;
9983 return Standard_True;
9985 else if (aVal.StartsWith ("-"))
9987 toReverse = Standard_True;
9988 aVal = aVal.SubString (2, aVal.Length());
9990 else if (aVal.StartsWith ("no"))
9992 toReverse = Standard_True;
9993 aVal = aVal.SubString (3, aVal.Length());
9995 else if (aVal.StartsWith ("+"))
9997 aVal = aVal.SubString (2, aVal.Length());
10001 theToReset = Standard_True;
10005 || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate;
10006 else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU;
10007 else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers;
10008 else if (aVal == "structs"
10009 || aVal == "structures"
10010 || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures;
10011 else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups;
10012 else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
10013 else if (aVal == "tris"
10014 || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles;
10015 else if (aVal == "pnts"
10016 || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points;
10017 else if (aVal == "mem"
10018 || aVal == "gpumem"
10019 || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem;
10020 else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic;
10021 else if (aVal == "extended"
10022 || aVal == "verbose"
10023 || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended;
10026 return Standard_False;
10031 theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag);
10035 theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag);
10037 return Standard_True;
10040 //! Read Graphic3d_RenderingParams::PerfCounters flags.
10041 static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue,
10042 Graphic3d_RenderingParams::PerfCounters& theFlags)
10044 TCollection_AsciiString aValue = theValue;
10045 Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE;
10046 Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE;
10047 Standard_Boolean toReset = Standard_False;
10050 Standard_Integer aSplitPos = aValue.Search ("|");
10051 if (aSplitPos <= 0)
10053 if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd))
10055 return Standard_False;
10059 theFlags = Graphic3d_RenderingParams::PerfCounters_NONE;
10061 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd);
10062 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem);
10063 return Standard_True;
10068 TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1);
10069 if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd))
10071 return Standard_False;
10074 aValue = aValue.SubString (aSplitPos + 1, aValue.Length());
10078 //=======================================================================
10079 //function : VRenderParams
10080 //purpose : Enables/disables rendering features
10081 //=======================================================================
10083 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
10084 Standard_Integer theArgNb,
10085 const char** theArgVec)
10087 Handle(V3d_View) aView = ViewerTest::CurrentView();
10088 if (aView.IsNull())
10090 std::cerr << "Error: no active viewer!\n";
10094 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
10095 TCollection_AsciiString aCmdName (theArgVec[0]);
10096 aCmdName.LowerCase();
10097 if (aCmdName == "vraytrace")
10101 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
10104 else if (theArgNb == 2)
10106 TCollection_AsciiString aValue (theArgVec[1]);
10107 aValue.LowerCase();
10111 aParams.Method = Graphic3d_RM_RAYTRACING;
10115 else if (aValue == "off"
10118 aParams.Method = Graphic3d_RM_RASTERIZATION;
10124 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
10130 std::cout << "Error: wrong number of arguments\n";
10137 theDI << "renderMode: ";
10138 switch (aParams.Method)
10140 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
10141 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
10144 theDI << "transparency: ";
10145 switch (aParams.TransparencyMethod)
10147 case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break;
10148 case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: "
10149 << TCollection_AsciiString (aParams.OitDepthFactor); break;
10152 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
10153 theDI << "rendScale: " << aParams.RenderResolutionScale << "\n";
10154 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
10155 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
10156 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
10157 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
10158 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
10159 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
10160 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
10161 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
10162 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
10163 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
10164 theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
10165 theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n";
10166 theDI << "shadingModel: ";
10167 switch (aView->ShadingModel())
10169 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
10170 case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break;
10171 case Graphic3d_TOSM_FACET: theDI << "flat"; break;
10172 case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break;
10173 case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break;
10176 theDI << "perfCounters:";
10177 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0)
10181 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
10185 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
10187 theDI << " structs";
10189 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0)
10191 theDI << " groups";
10193 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0)
10195 theDI << " arrays";
10197 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0)
10201 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
10205 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0)
10207 theDI << " gpumem";
10209 if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE)
10215 theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n";
10216 theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n";
10221 Standard_Boolean toPrint = Standard_False;
10222 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10223 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
10225 Standard_CString anArg (theArgVec[anArgIter]);
10226 TCollection_AsciiString aFlag (anArg);
10228 if (anUpdateTool.parseRedrawMode (aFlag))
10232 else if (aFlag == "-echo"
10233 || aFlag == "-print")
10235 toPrint = Standard_True;
10236 anUpdateTool.Invalidate();
10238 else if (aFlag == "-mode"
10239 || aFlag == "-rendermode"
10240 || aFlag == "-render_mode")
10244 switch (aParams.Method)
10246 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
10247 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
10253 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10257 else if (aFlag == "-ray"
10258 || aFlag == "-raytrace")
10262 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
10266 aParams.Method = Graphic3d_RM_RAYTRACING;
10268 else if (aFlag == "-rast"
10269 || aFlag == "-raster"
10270 || aFlag == "-rasterization")
10274 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
10278 aParams.Method = Graphic3d_RM_RASTERIZATION;
10280 else if (aFlag == "-msaa")
10284 theDI << aParams.NbMsaaSamples << " ";
10287 else if (++anArgIter >= theArgNb)
10289 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10293 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
10294 if (aNbSamples < 0)
10296 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
10301 aParams.NbMsaaSamples = aNbSamples;
10304 else if (aFlag == "-oit")
10308 if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
10310 theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " ";
10314 theDI << "off" << " ";
10318 else if (++anArgIter >= theArgNb)
10320 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10324 TCollection_AsciiString aParam = theArgVec[anArgIter];
10325 aParam.LowerCase();
10326 if (aParam.IsRealValue())
10328 const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
10329 if (aWeight < 0.f || aWeight > 1.f)
10331 std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n";
10335 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
10336 aParams.OitDepthFactor = aWeight;
10338 else if (aParam == "off")
10340 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED;
10344 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10348 else if (aFlag == "-depthprepass")
10352 theDI << (aParams.ToEnableDepthPrepass ? "on " : "off ");
10355 aParams.ToEnableDepthPrepass = Standard_True;
10356 if (anArgIter + 1 < theArgNb
10357 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass))
10362 else if (aFlag == "-samplealphatocoverage"
10363 || aFlag == "-alphatocoverage")
10367 theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off ");
10370 aParams.ToEnableAlphaToCoverage = Standard_True;
10371 if (anArgIter + 1 < theArgNb
10372 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage))
10377 else if (aFlag == "-rendscale"
10378 || aFlag == "-renderscale"
10379 || aFlag == "-renderresolutionscale")
10383 theDI << aParams.RenderResolutionScale << " ";
10386 else if (++anArgIter >= theArgNb)
10388 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10392 const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
10395 std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n";
10400 aParams.RenderResolutionScale = Standard_ShortReal(aScale);
10403 else if (aFlag == "-raydepth"
10404 || aFlag == "-ray_depth")
10408 theDI << aParams.RaytracingDepth << " ";
10411 else if (++anArgIter >= theArgNb)
10413 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10417 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
10419 // We allow RaytracingDepth be more than 10 in case of GI enabled
10420 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
10422 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
10427 aParams.RaytracingDepth = aDepth;
10430 else if (aFlag == "-shad"
10431 || aFlag == "-shadows")
10435 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
10439 Standard_Boolean toEnable = Standard_True;
10440 if (++anArgIter < theArgNb
10441 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10445 aParams.IsShadowEnabled = toEnable;
10447 else if (aFlag == "-refl"
10448 || aFlag == "-reflections")
10452 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
10456 Standard_Boolean toEnable = Standard_True;
10457 if (++anArgIter < theArgNb
10458 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10462 aParams.IsReflectionEnabled = toEnable;
10464 else if (aFlag == "-fsaa")
10468 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
10472 Standard_Boolean toEnable = Standard_True;
10473 if (++anArgIter < theArgNb
10474 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10478 aParams.IsAntialiasingEnabled = toEnable;
10480 else if (aFlag == "-gleam")
10484 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
10488 Standard_Boolean toEnable = Standard_True;
10489 if (++anArgIter < theArgNb
10490 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10494 aParams.IsTransparentShadowEnabled = toEnable;
10496 else if (aFlag == "-gi")
10500 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
10504 Standard_Boolean toEnable = Standard_True;
10505 if (++anArgIter < theArgNb
10506 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10510 aParams.IsGlobalIlluminationEnabled = toEnable;
10513 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
10516 else if (aFlag == "-blockedrng"
10517 || aFlag == "-brng")
10521 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
10525 Standard_Boolean toEnable = Standard_True;
10526 if (++anArgIter < theArgNb
10527 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10531 aParams.CoherentPathTracingMode = toEnable;
10533 else if (aFlag == "-maxrad")
10537 theDI << aParams.RadianceClampingValue << " ";
10540 else if (++anArgIter >= theArgNb)
10542 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10546 const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
10547 if (!aMaxRadStr.IsRealValue())
10549 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10553 const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
10554 if (aMaxRadiance <= 0.0)
10556 std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n";
10561 aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
10564 else if (aFlag == "-iss")
10568 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
10572 Standard_Boolean toEnable = Standard_True;
10573 if (++anArgIter < theArgNb
10574 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10578 aParams.AdaptiveScreenSampling = toEnable;
10580 else if (aFlag == "-issd")
10584 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
10588 Standard_Boolean toEnable = Standard_True;
10589 if (++anArgIter < theArgNb
10590 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10594 aParams.ShowSamplingTiles = toEnable;
10596 else if (aFlag == "-nbtiles")
10600 theDI << aParams.NbRayTracingTiles << " ";
10603 else if (++anArgIter >= theArgNb)
10605 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10609 const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]);
10613 std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n";
10614 std::cerr << "Specify value in range [64, 1024].\n";
10619 aParams.NbRayTracingTiles = aNbTiles;
10622 else if (aFlag == "-env")
10626 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
10630 Standard_Boolean toEnable = Standard_True;
10631 if (++anArgIter < theArgNb
10632 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10636 aParams.UseEnvironmentMapBackground = toEnable;
10638 else if (aFlag == "-twoside")
10642 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
10646 Standard_Boolean toEnable = Standard_True;
10647 if (++anArgIter < theArgNb
10648 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10652 aParams.TwoSidedBsdfModels = toEnable;
10654 else if (aFlag == "-shademodel"
10655 || aFlag == "-shadingmodel"
10656 || aFlag == "-shading")
10660 switch (aView->ShadingModel())
10662 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
10663 case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break;
10664 case Graphic3d_TOSM_FACET: theDI << "flat "; break;
10665 case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break;
10666 case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break;
10671 if (++anArgIter >= theArgNb)
10673 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10676 Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT;
10677 if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel)
10678 && aModel != Graphic3d_TOSM_DEFAULT)
10680 aView->SetShadingModel (aModel);
10684 std::cout << "Error: unknown shading model '" << theArgVec[anArgIter] << "'\n";
10688 else if (aFlag == "-resolution")
10690 if (++anArgIter >= theArgNb)
10692 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10696 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
10697 if (aResolution.IsIntegerValue())
10699 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
10703 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10707 else if (aFlag == "-rebuildglsl"
10708 || aFlag == "-rebuild")
10712 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
10716 Standard_Boolean toEnable = Standard_True;
10717 if (++anArgIter < theArgNb
10718 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10722 aParams.RebuildRayTracingShaders = toEnable;
10724 else if (aFlag == "-focal")
10726 if (++anArgIter >= theArgNb)
10728 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10732 TCollection_AsciiString aParam (theArgVec[anArgIter]);
10733 if (aParam.IsRealValue())
10735 float aFocalDist = static_cast<float> (aParam.RealValue());
10736 if (aFocalDist < 0)
10738 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
10741 aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist;
10745 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10749 else if (aFlag == "-aperture")
10751 if (++anArgIter >= theArgNb)
10753 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10757 TCollection_AsciiString aParam(theArgVec[anArgIter]);
10758 if (aParam.IsRealValue())
10760 float aApertureSize = static_cast<float> (aParam.RealValue());
10761 if (aApertureSize < 0)
10763 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
10766 aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize;
10770 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10774 else if (aFlag == "-exposure")
10776 if (++anArgIter >= theArgNb)
10778 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10782 TCollection_AsciiString anExposure (theArgVec[anArgIter]);
10783 if (anExposure.IsRealValue())
10785 aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
10789 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10793 else if (aFlag == "-whitepoint")
10795 if (++anArgIter >= theArgNb)
10797 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10801 TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
10802 if (aWhitePoint.IsRealValue())
10804 aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
10808 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10812 else if (aFlag == "-tonemapping")
10814 if (++anArgIter >= theArgNb)
10816 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10820 TCollection_AsciiString aMode (theArgVec[anArgIter]);
10823 if (aMode == "disabled")
10825 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled;
10827 else if (aMode == "filmic")
10829 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;
10833 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10837 else if (aFlag == "-performancestats"
10838 || aFlag == "-performancecounters"
10839 || aFlag == "-perfstats"
10840 || aFlag == "-perfcounters"
10841 || aFlag == "-stats")
10843 if (++anArgIter >= theArgNb)
10845 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10849 TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]);
10850 aFlagsStr.LowerCase();
10851 Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats;
10852 if (!convertToPerfStatsFlags (aFlagsStr, aFlags))
10854 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10857 aView->ChangeRenderingParams().CollectedStats = aFlags;
10858 aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE;
10860 else if (aFlag == "-perfupdateinterval"
10861 || aFlag == "-statsupdateinterval")
10863 if (++anArgIter >= theArgNb)
10865 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10868 aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
10872 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
10880 //=======================================================================
10881 //function : VProgressiveMode
10883 //=======================================================================
10884 #if defined(_WIN32)
10885 static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
10886 Standard_Integer /*theNbArgs*/,
10887 const char** /*theArgs*/)
10889 Handle(V3d_View) aView = ViewerTest::CurrentView();
10890 if (aView.IsNull())
10892 std::cerr << "Error: no active viewer!\n";
10896 std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
10902 Standard_Boolean toExit = Standard_False;
10905 while (PeekMessageW (&aMsg, NULL, 0, 0, PM_REMOVE))
10907 if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
10909 toExit = Standard_True;
10912 TranslateMessage (&aMsg);
10913 DispatchMessageW (&aMsg);
10926 //=======================================================================
10927 //function : VFrustumCulling
10928 //purpose : enables/disables view volume's culling.
10929 //=======================================================================
10930 static int VFrustumCulling (Draw_Interpretor& theDI,
10931 Standard_Integer theArgNb,
10932 const char** theArgVec)
10934 Handle(V3d_View) aView = ViewerTest::CurrentView();
10935 if (aView.IsNull())
10937 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
10943 theDI << (aView->IsCullingEnabled() ? "on" : "off");
10946 else if (theArgNb != 2)
10948 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
10952 TCollection_AsciiString aModeStr (theArgVec[1]);
10953 aModeStr.LowerCase();
10954 Standard_Boolean toEnable = 0;
10955 if (aModeStr == "on")
10959 else if (aModeStr == "off")
10965 toEnable = Draw::Atoi (theArgVec[1]) != 0;
10968 aView->SetFrustumCulling (toEnable);
10973 //=======================================================================
10974 //function : VHighlightSelected
10976 //=======================================================================
10977 static int VHighlightSelected (Draw_Interpretor& theDI,
10978 Standard_Integer theArgNb,
10979 const char** theArgVec)
10981 if (ViewerTest::GetAISContext().IsNull())
10983 std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n";
10987 const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
10991 theDI << (aContext->ToHilightSelected() ? "on" : "off");
10997 std::cout << theArgVec[0] << " error : wrong number of parameters."
10998 << "Type 'help" << theArgVec[0] << "' for more information.";
11003 TCollection_AsciiString aMode (theArgVec[1]);
11005 Standard_Boolean toEnable = Standard_False;
11006 if (aMode.IsEqual ("on"))
11008 toEnable = Standard_True;
11010 else if (aMode.IsEqual ("off"))
11012 toEnable = Standard_False;
11016 toEnable = Draw::Atoi (theArgVec[1]) != 0;
11019 if (toEnable != aContext->ToHilightSelected())
11021 aContext->SetToHilightSelected (toEnable);
11023 // Move cursor to null position and back to process updating of detection
11024 // and highlighting of selected object immediatly.
11025 Standard_Integer aPixX = 0;
11026 Standard_Integer aPixY = 0;
11027 const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager();
11029 anEventManager->GetCurrentPosition (aPixX, aPixY);
11030 anEventManager->MoveTo (0, 0);
11031 anEventManager->MoveTo (aPixX, aPixY);
11037 //=======================================================================
11038 //function : VXRotate
11040 //=======================================================================
11041 static Standard_Integer VXRotate (Draw_Interpretor& di,
11042 Standard_Integer argc,
11043 const char ** argv)
11045 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
11046 if (aContext.IsNull())
11048 di << argv[0] << "ERROR : use 'vinit' command before \n";
11054 di << "ERROR : Usage : " << argv[0] << " name angle\n";
11058 TCollection_AsciiString aName (argv[1]);
11059 Standard_Real anAngle = Draw::Atof (argv[2]);
11062 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
11063 Handle(AIS_InteractiveObject) anIObj;
11064 if (!aMap.IsBound2 (aName) )
11066 di << "Use 'vdisplay' before\n";
11071 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
11073 gp_Trsf aTransform;
11074 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
11075 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
11077 aContext->SetLocation (anIObj, aTransform);
11078 aContext->UpdateCurrentViewer();
11084 //===============================================================================================
11085 //class : ViewerTest_AISManipulator
11086 //purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances
11087 //===============================================================================================
11088 DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
11090 class ViewerTest_AISManipulator : public AIS_Manipulator
11094 ViewerTest_AISManipulator() : AIS_Manipulator()
11096 GetMapOfAISManipulators().Add (this);
11099 virtual ~ViewerTest_AISManipulator()
11101 GetMapOfAISManipulators().Remove (this);
11104 DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
11107 IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
11108 IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
11110 //===============================================================================================
11111 //function : VManipulator
11113 //===============================================================================================
11114 static int VManipulator (Draw_Interpretor& theDi,
11115 Standard_Integer theArgsNb,
11116 const char** theArgVec)
11118 Handle(V3d_View) aView = ViewerTest::CurrentView();
11119 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
11120 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
11122 || aViewer.IsNull())
11124 std::cerr << "No active viewer!\n";
11128 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
11129 Standard_Integer anArgIter = 1;
11130 for (; anArgIter < theArgsNb; ++anArgIter)
11132 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
11135 ViewerTest_CmdParser aCmd;
11136 aCmd.AddDescription ("Manages manipulator for interactive objects:");
11137 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
11138 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
11139 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
11140 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
11141 aCmd.AddOption ("detach", "... - detach manipulator");
11143 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
11144 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
11145 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
11147 aCmd.AddOption ("move", "... x y z - move object");
11148 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
11149 aCmd.AddOption ("scale", "... factor - scale object");
11151 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
11152 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
11153 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
11154 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
11155 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
11156 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
11157 aCmd.AddOption ("size", "... size - set size of manipulator");
11158 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
11160 aCmd.Parse (theArgsNb, theArgVec);
11162 if (aCmd.HasOption ("help"))
11164 theDi.PrintHelp (theArgVec[0]);
11168 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
11170 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
11172 if (aName.IsEmpty())
11174 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
11178 // ----------------------------------
11179 // detach existing manipulator object
11180 // ----------------------------------
11182 if (aCmd.HasOption ("detach"))
11184 if (!aMapAIS.IsBound2 (aName))
11186 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
11190 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
11191 if (aManipulator.IsNull())
11193 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
11197 aManipulator->Detach();
11198 aMapAIS.UnBind2 (aName);
11199 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True);
11204 // -----------------------------------------------
11205 // find or create manipulator if it does not exist
11206 // -----------------------------------------------
11208 Handle(AIS_Manipulator) aManipulator;
11209 if (!aMapAIS.IsBound2 (aName))
11211 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
11213 aManipulator = new ViewerTest_AISManipulator();
11214 aMapAIS.Bind (aManipulator, aName);
11218 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
11219 if (aManipulator.IsNull())
11221 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
11226 // -----------------------------------------
11227 // change properties of manipulator instance
11228 // -----------------------------------------
11230 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
11232 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
11234 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
11236 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
11238 if (aCmd.HasOption ("followRotation", 1, Standard_True))
11240 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
11242 if (aCmd.HasOption ("gap", 1, Standard_True))
11244 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
11246 if (aCmd.HasOption ("part", 3, Standard_True))
11248 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
11249 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
11250 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
11251 if (aMode < 1 || aMode > 3)
11253 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 3].\n";
11257 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
11259 if (aCmd.HasOption ("pos", 3, Standard_True))
11261 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
11262 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
11263 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
11265 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
11267 if (aCmd.HasOption ("size", 1, Standard_True))
11269 aManipulator->SetSize (aCmd.ArgFloat ("size"));
11271 if (aCmd.HasOption ("zoomable", 1, Standard_True))
11273 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
11275 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
11277 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
11278 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
11282 // ---------------------------------------------------
11283 // attach, detach or access manipulator from an object
11284 // ---------------------------------------------------
11286 if (aCmd.HasOption ("attach"))
11288 // Find an object and attach manipulator to it
11289 if (!aCmd.HasOption ("attach", 1, Standard_True))
11294 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
11295 if (!aMapAIS.IsBound2 (anObjName))
11297 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
11301 Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (aMapAIS.Find2 (anObjName));
11302 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
11303 for (; anIt.More(); anIt.Next())
11305 if (anIt.Value()->IsAttached()
11306 && anIt.Value()->Object() == anObject)
11308 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
11313 AIS_Manipulator::OptionsForAttach anOptions;
11314 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
11316 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
11318 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
11320 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
11322 if (aCmd.HasOption ("enableModes", 1, Standard_True))
11324 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
11327 aManipulator->Attach (anObject, anOptions);
11330 // --------------------------------------
11331 // apply transformation using manipulator
11332 // --------------------------------------
11334 if (aCmd.HasOption ("startTransform", 2, Standard_True))
11336 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
11338 if (aCmd.HasOption ("transform", 2, Standard_True))
11340 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
11342 if (aCmd.HasOption ("stopTransform"))
11344 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
11346 aManipulator->StopTransform (toApply);
11350 if (aCmd.HasOption ("move", 3, Standard_True))
11352 aT.SetTranslationPart (aCmd.ArgVec ("move"));
11354 if (aCmd.HasOption ("rotate", 7, Standard_True))
11356 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
11358 if (aCmd.HasOption ("scale", 1))
11360 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
11363 if (aT.Form() != gp_Identity)
11365 aManipulator->Transform (aT);
11368 ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True);
11373 //===============================================================================================
11374 //function : VSelectionProperties
11376 //===============================================================================================
11377 static int VSelectionProperties (Draw_Interpretor& theDi,
11378 Standard_Integer theArgsNb,
11379 const char** theArgVec)
11381 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
11384 std::cerr << "No active viewer!\n";
11388 Standard_Boolean toPrint = theArgsNb == 1;
11389 Standard_Boolean toRedraw = Standard_False;
11390 Standard_Integer anArgIter = 1;
11391 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
11392 if (anArgIter < theArgsNb)
11394 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
11395 anArgFirst.LowerCase();
11397 if (anArgFirst == "dynhighlight"
11398 || anArgFirst == "dynhilight"
11399 || anArgFirst == "dynamichighlight"
11400 || anArgFirst == "dynamichilight")
11402 aType = Prs3d_TypeOfHighlight_Dynamic;
11404 else if (anArgFirst == "localdynhighlight"
11405 || anArgFirst == "localdynhilight"
11406 || anArgFirst == "localdynamichighlight"
11407 || anArgFirst == "localdynamichilight")
11409 aType = Prs3d_TypeOfHighlight_LocalDynamic;
11411 else if (anArgFirst == "selhighlight"
11412 || anArgFirst == "selhilight"
11413 || anArgFirst == "selectedhighlight"
11414 || anArgFirst == "selectedhilight")
11416 aType = Prs3d_TypeOfHighlight_Selected;
11418 else if (anArgFirst == "localselhighlight"
11419 || anArgFirst == "localselhilight"
11420 || anArgFirst == "localselectedhighlight"
11421 || anArgFirst == "localselectedhilight")
11423 aType = Prs3d_TypeOfHighlight_LocalSelected;
11430 for (; anArgIter < theArgsNb; ++anArgIter)
11432 TCollection_AsciiString anArg (theArgVec[anArgIter]);
11434 if (anArg == "-help")
11436 theDi.PrintHelp (theArgVec[0]);
11439 else if (anArg == "-print")
11441 toPrint = Standard_True;
11443 else if (anArg == "-autoactivate")
11445 Standard_Boolean toEnable = Standard_True;
11446 if (anArgIter + 1 < theArgsNb
11447 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
11451 aCtx->SetAutoActivateSelection (toEnable);
11453 else if (anArg == "-pickstrategy"
11454 || anArg == "-pickingstrategy")
11456 if (++anArgIter >= theArgsNb)
11458 std::cout << "Syntax error: type of highlighting is undefined\n";
11462 SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
11463 TCollection_AsciiString aVal (theArgVec[anArgIter]);
11465 if (aVal == "first"
11466 || aVal == "firstaccepted"
11467 || aVal == "firstacceptable")
11469 aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
11471 else if (aVal == "topmost"
11472 || aVal == "onlyTopmost")
11474 aStrategy = SelectMgr_PickingStrategy_OnlyTopmost;
11478 std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n";
11482 aCtx->SetPickingStrategy (aStrategy);
11484 else if (anArg == "-pixtol"
11485 && anArgIter + 1 < theArgsNb)
11487 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
11489 else if ((anArg == "-mode"
11490 || anArg == "-dispmode")
11491 && anArgIter + 1 < theArgsNb)
11493 if (aType == Prs3d_TypeOfHighlight_None)
11495 std::cout << "Syntax error: type of highlighting is undefined\n";
11499 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
11500 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11501 aStyle->SetDisplayMode (aDispMode);
11502 toRedraw = Standard_True;
11504 else if (anArg == "-layer"
11505 && anArgIter + 1 < theArgsNb)
11507 if (aType == Prs3d_TypeOfHighlight_None)
11509 std::cout << "Syntax error: type of highlighting is undefined\n";
11513 const Standard_Integer aNewLayer = Draw::Atoi (theArgVec[++anArgIter]);
11514 if (aNewLayer != Graphic3d_ZLayerId_UNKNOWN)
11516 TColStd_SequenceOfInteger aLayers;
11517 aCtx->CurrentViewer()->GetAllZLayers (aLayers);
11518 if (std::find (aLayers.begin(), aLayers.end(), aNewLayer) == aLayers.end())
11520 std::cout << "Syntax error: Layer " << aNewLayer << " is undefined\n";
11525 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11526 aStyle->SetZLayer (aNewLayer);
11527 toRedraw = Standard_True;
11529 else if (anArg == "-hicolor"
11530 || anArg == "-selcolor"
11531 || anArg == "-color")
11533 if (anArg.StartsWith ("-hi"))
11535 aType = Prs3d_TypeOfHighlight_Dynamic;
11537 else if (anArg.StartsWith ("-sel"))
11539 aType = Prs3d_TypeOfHighlight_Selected;
11541 else if (aType == Prs3d_TypeOfHighlight_None)
11543 std::cout << "Syntax error: type of highlighting is undefined\n";
11547 Quantity_Color aColor;
11548 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1,
11549 theArgVec + anArgIter + 1,
11551 if (aNbParsed == 0)
11553 std::cout << "Syntax error: need more arguments.\n";
11556 anArgIter += aNbParsed;
11558 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11559 aStyle->SetColor (aColor);
11560 toRedraw = Standard_True;
11562 else if ((anArg == "-transp"
11563 || anArg == "-transparency"
11564 || anArg == "-hitransp"
11565 || anArg == "-seltransp"
11566 || anArg == "-hitransplocal"
11567 || anArg == "-seltransplocal")
11568 && anArgIter + 1 < theArgsNb)
11570 if (anArg.StartsWith ("-hi"))
11572 aType = Prs3d_TypeOfHighlight_Dynamic;
11574 else if (anArg.StartsWith ("-sel"))
11576 aType = Prs3d_TypeOfHighlight_Selected;
11578 else if (aType == Prs3d_TypeOfHighlight_None)
11580 std::cout << "Syntax error: type of highlighting is undefined\n";
11584 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
11585 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11586 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
11587 toRedraw = Standard_True;
11589 else if ((anArg == "-mat"
11590 || anArg == "-material")
11591 && anArgIter + 1 < theArgsNb)
11593 if (aType == Prs3d_TypeOfHighlight_None)
11595 std::cout << "Syntax error: type of highlighting is undefined\n";
11599 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11600 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
11601 if (aMatName != Graphic3d_NOM_DEFAULT)
11604 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
11605 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
11606 Graphic3d_MaterialAspect aMat (aMatName);
11607 aMat.SetColor (aStyle->Color());
11608 aMat.SetTransparency (aStyle->Transparency());
11609 anAspect->SetFrontMaterial (aMat);
11610 anAspect->SetInteriorColor (aStyle->Color());
11611 aStyle->SetBasicFillAreaAspect (anAspect);
11615 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
11617 toRedraw = Standard_True;
11621 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
11627 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
11628 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
11629 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
11630 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
11631 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
11632 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
11633 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
11634 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
11635 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
11636 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
11637 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
11638 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
11641 if (aCtx->NbSelected() != 0 && toRedraw)
11643 aCtx->HilightSelected (Standard_True);
11649 //===============================================================================================
11650 //function : VDumpSelectionImage
11652 //===============================================================================================
11653 static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
11654 Standard_Integer theArgsNb,
11655 const char** theArgVec)
11659 std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
11663 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
11664 if (aContext.IsNull())
11666 std::cout << "Error: no active view.\n";
11670 TCollection_AsciiString aFile;
11671 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
11672 Image_Format anImgFormat = Image_Format_BGR;
11673 Standard_Integer aPickedIndex = 1;
11674 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
11676 TCollection_AsciiString aParam (theArgVec[anArgIter]);
11677 aParam.LowerCase();
11678 if (aParam == "-type")
11680 if (++anArgIter >= theArgsNb)
11682 std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n";
11686 TCollection_AsciiString aValue (theArgVec[anArgIter]);
11687 aValue.LowerCase();
11688 if (aValue == "depth"
11689 || aValue == "normdepth"
11690 || aValue == "normalizeddepth")
11692 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
11693 anImgFormat = Image_Format_GrayF;
11695 if (aValue == "depthinverted"
11696 || aValue == "normdepthinverted"
11697 || aValue == "normalizeddepthinverted"
11698 || aValue == "inverted")
11700 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
11701 anImgFormat = Image_Format_GrayF;
11703 else if (aValue == "unnormdepth"
11704 || aValue == "unnormalizeddepth")
11706 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
11707 anImgFormat = Image_Format_GrayF;
11709 else if (aValue == "objectcolor"
11710 || aValue == "object"
11711 || aValue == "color")
11713 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
11715 else if (aValue == "entitycolor"
11716 || aValue == "entity")
11718 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
11720 else if (aValue == "ownercolor"
11721 || aValue == "owner")
11723 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
11725 else if (aValue == "selectionmodecolor"
11726 || aValue == "selectionmode"
11727 || aValue == "selmodecolor"
11728 || aValue == "selmode")
11730 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
11733 else if (aParam == "-picked"
11734 || aParam == "-pickeddepth"
11735 || aParam == "-pickedindex")
11737 if (++anArgIter >= theArgsNb)
11739 std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n";
11743 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
11745 else if (aFile.IsEmpty())
11747 aFile = theArgVec[anArgIter];
11751 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n";
11755 if (aFile.IsEmpty())
11757 std::cout << "Syntax error: image file name is missing.\n";
11761 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
11762 Standard_Integer aWidth = 0, aHeight = 0;
11763 aView->Window()->Size (aWidth, aHeight);
11765 Image_AlienPixMap aPixMap;
11766 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
11768 std::cout << "Error: can't allocate image.\n";
11771 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
11773 std::cout << "Error: can't generate selection image.\n";
11776 if (!aPixMap.Save (aFile))
11778 std::cout << "Error: can't save selection image.\n";
11784 //=======================================================================
11785 //function : ViewerCommands
11787 //=======================================================================
11789 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
11792 const char *group = "ZeViewer";
11793 theCommands.Add("vinit",
11794 "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]"
11795 "\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]"
11796 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
11797 "\n\t\t: [-display displayName]"
11799 "\n\t\t: Creates new View window with specified name viewName."
11800 "\n\t\t: By default the new view is created in the viewer and in"
11801 "\n\t\t: graphic driver shared with active view."
11802 "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}"
11803 "\n\t\t: If driverName isn't specified the driver will be shared with active view."
11804 "\n\t\t: If viewerName isn't specified the viewer will be shared with active view."
11805 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
11806 "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]"
11807 "\n\t\t: Display name will be used within creation of graphic driver, when specified."
11809 "\n\t\t: -left, -top pixel position of left top corner of the window."
11810 "\n\t\t: -width, -height width and heigth of window respectively."
11811 "\n\t\t: -cloneActive floag to copy camera and dimensions of active view."
11812 "\n\t\t: -exitOnClose when specified, closing the view will exit application."
11813 "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape."
11814 "\n\t\t: -2d_mode when on, view will not react on rotate scene events"
11815 "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.",
11816 __FILE__,VInit,group);
11817 theCommands.Add("vclose" ,
11818 "[view_id [keep_context=0|1]]\n"
11819 "or vclose ALL - to remove all created views\n"
11820 " - removes view(viewer window) defined by its view_id.\n"
11821 " - keep_context: by default 0; if 1 and the last view is deleted"
11822 " the current context is not removed.",
11823 __FILE__,VClose,group);
11824 theCommands.Add("vactivate" ,
11826 " - activates view(viewer window) defined by its view_id",
11827 __FILE__,VActivate,group);
11828 theCommands.Add("vviewlist",
11829 "vviewlist [format={tree, long}]"
11830 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
11831 " - format: format of result output, if tree the output is a tree view;"
11832 "otherwise it's a list of full view names. By default format = tree",
11833 __FILE__,VViewList,group);
11834 theCommands.Add("vhelp" ,
11835 "vhelp : display help on the viewer commands",
11836 __FILE__,VHelp,group);
11837 theCommands.Add("vtop" ,
11838 "vtop or <T> : Top view. Orientation +X+Y" ,
11839 __FILE__,VTop,group);
11840 theCommands.Add("vbottom" ,
11841 "vbottom : Bottom view. Orientation +X-Y" ,
11842 __FILE__,VBottom,group);
11843 theCommands.Add("vleft" ,
11844 "vleft : Left view. Orientation -Y+Z" ,
11845 __FILE__,VLeft,group);
11846 theCommands.Add("vright" ,
11847 "vright : Right view. Orientation +Y+Z" ,
11848 __FILE__,VRight,group);
11849 theCommands.Add("vaxo" ,
11850 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
11851 __FILE__,VAxo,group);
11852 theCommands.Add("vfront" ,
11853 "vfront : Front view. Orientation +X+Z" ,
11854 __FILE__,VFront,group);
11855 theCommands.Add("vback" ,
11856 "vback : Back view. Orientation -X+Z" ,
11857 __FILE__,VBack,group);
11858 theCommands.Add("vpick" ,
11859 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
11861 theCommands.Add("vfit",
11862 "vfit or <F> [-selected] [-noupdate]"
11863 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
11864 __FILE__,VFit,group);
11865 theCommands.Add ("vfitarea",
11866 "vfitarea x1 y1 x2 y2"
11867 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
11868 "\n\t\t: Fit view to show area located between two points"
11869 "\n\t\t: given in world 2D or 3D corrdinates.",
11870 __FILE__, VFitArea, group);
11871 theCommands.Add ("vzfit", "vzfit [scale]\n"
11872 " Matches Z near, Z far view volume planes to the displayed objects.\n"
11873 " \"scale\" - specifies factor to scale computed z range.\n",
11874 __FILE__, VZFit, group);
11875 theCommands.Add("vrepaint",
11876 "vrepaint [-immediate]"
11877 "\n\t\t: force redraw",
11878 __FILE__,VRepaint,group);
11879 theCommands.Add("vclear",
11881 "\n\t\t: remove all the object from the viewer",
11882 __FILE__,VClear,group);
11883 theCommands.Add("vsetbg",
11884 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
11885 __FILE__,VSetBg,group);
11886 theCommands.Add("vsetbgmode",
11887 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
11888 __FILE__,VSetBgMode,group);
11889 theCommands.Add("vsetgradientbg",
11890 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
11891 __FILE__,VSetGradientBg,group);
11892 theCommands.Add("vsetgrbgmode",
11893 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
11894 __FILE__,VSetGradientBgMode,group);
11895 theCommands.Add("vsetcolorbg",
11896 "vsetcolorbg : vsetcolorbg r g b : Set background color",
11897 __FILE__,VSetColorBg,group);
11898 theCommands.Add("vsetdefaultbg",
11899 "vsetdefaultbg r g b\n"
11900 "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode"
11901 "\n\t\t: Set default viewer background fill color (flat/gradient).",
11902 __FILE__,VSetDefaultBg,group);
11903 theCommands.Add("vscale",
11904 "vscale : vscale X Y Z",
11905 __FILE__,VScale,group);
11906 theCommands.Add("vzbufftrihedron",
11907 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
11908 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
11909 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
11910 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
11911 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
11912 "\n\t\t: Displays a trihedron",
11913 __FILE__,VZBuffTrihedron,group);
11914 theCommands.Add("vrotate",
11915 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
11916 "\n : Option -mouseStart starts rotation according to the mouse position"
11917 "\n : Option -mouseMove continues rotation with angle computed"
11918 "\n : from last and new mouse position."
11919 "\n : vrotate AX AY AZ [X Y Z]",
11920 __FILE__,VRotate,group);
11921 theCommands.Add("vzoom",
11922 "vzoom : vzoom coef",
11923 __FILE__,VZoom,group);
11924 theCommands.Add("vpan",
11925 "vpan : vpan dx dy",
11926 __FILE__,VPan,group);
11927 theCommands.Add("vcolorscale",
11928 "vcolorscale name [-noupdate|-update] [-demo]"
11929 "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
11930 "\n\t\t: [-font HeightFont=20]"
11931 "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
11932 "\n\t\t: [-smoothTransition {on|off}=off]"
11933 "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
11934 "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
11935 "\n\t\t: [-textpos {left|right|center|none}=right]"
11936 "\n\t\t: [-labelAtBorder {on|off}=on]"
11937 "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
11938 "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
11939 "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
11940 "\n\t\t: [-xy Left=0 Bottom=0]"
11941 "\n\t\t: -demo - displays a color scale with demonstratio values"
11942 "\n\t\t: -colors - set colors for all intervals"
11943 "\n\t\t: -color - set color for specific interval"
11944 "\n\t\t: -textpos - horizontal label position relative to color scale bar"
11945 "\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
11946 "\n\t\t: at border means the value inbetween neighbor intervals,"
11947 "\n\t\t: at center means the center value within current interval"
11948 "\n\t\t: -labels - set labels for all intervals"
11949 "\n\t\t: -freeLabels - same as -labels but does not require"
11950 "\n\t\t: matching the number of intervals"
11951 "\n\t\t: -label - set label for specific interval"
11952 "\n\t\t: -title - set title"
11953 "\n\t\t: -reversed - setup smooth color transition between intervals"
11954 "\n\t\t: -smoothTransition - swap colorscale direction"
11955 "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values"
11956 __FILE__, VColorScale, group);
11957 theCommands.Add("vgraduatedtrihedron",
11958 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
11959 "\t[-namefont Name] [-valuesfont Name]\n"
11960 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
11961 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
11962 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
11963 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
11964 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
11965 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
11966 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
11967 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
11968 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
11969 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
11970 " - Displays or erases graduated trihedron"
11971 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
11972 " - namefont - font of axes names. Default: Arial\n"
11973 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
11974 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
11975 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
11976 " - valuesfont - font of axes values. Default: Arial\n"
11977 " - xcolor, ycolor, zcolor - color of axis and values\n"
11978 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
11979 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
11980 __FILE__,VGraduatedTrihedron,group);
11981 theCommands.Add("vtile" ,
11982 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
11983 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
11984 "\n\t\t: -totalSize the size of virtual bigger viewport"
11985 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
11986 "\n\t\t: -lowerLeft tile offset as lower left corner"
11987 "\n\t\t: -upperLeft tile offset as upper left corner",
11988 __FILE__, VTile, group);
11989 theCommands.Add("vzlayer",
11990 "vzlayer [layerId]"
11991 "\n\t\t: [-add|-delete|-get|-settings]"
11992 "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]"
11993 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
11994 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv}]"
11995 "\n\t\t: ZLayer list management:"
11996 "\n\t\t: -add add new z layer to viewer and print its id"
11997 "\n\t\t: -delete delete z layer"
11998 "\n\t\t: -get print sequence of z layers"
11999 "\n\t\t: -settings print status of z layer settings"
12000 "\n\t\t: -disable disables given setting"
12001 "\n\t\t: -enable enables given setting",
12002 __FILE__,VZLayer,group);
12003 theCommands.Add("vlayerline",
12004 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
12005 __FILE__,VLayerLine,group);
12006 theCommands.Add ("vgrid",
12007 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
12008 " : Mode - rectangular or circular"
12009 " : Type - lines or points",
12010 __FILE__, VGrid, group);
12011 theCommands.Add ("vpriviledgedplane",
12012 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
12013 "\n\t\t: Ox, Oy, Oz - plane origin"
12014 "\n\t\t: Nx, Ny, Nz - plane normal direction"
12015 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
12016 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
12017 __FILE__, VPriviledgedPlane, group);
12018 theCommands.Add ("vconvert",
12019 "vconvert v [Mode={window|view}]"
12020 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
12021 "\n\t\t: vconvert x y z [Mode={window|grid}]"
12022 "\n\t\t: window - convert to window coordinates, pixels"
12023 "\n\t\t: view - convert to view projection plane"
12024 "\n\t\t: grid - convert to model coordinates, given on grid"
12025 "\n\t\t: ray - convert projection ray to model coordiantes"
12026 "\n\t\t: - vconvert v window : convert view to window;"
12027 "\n\t\t: - vconvert v view : convert window to view;"
12028 "\n\t\t: - vconvert x y window : convert view to window;"
12029 "\n\t\t: - vconvert x y view : convert window to view;"
12030 "\n\t\t: - vconvert x y : convert window to model;"
12031 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
12032 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
12033 "\n\t\t: - vconvert x y z window : convert model to window;"
12034 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
12035 "\n\t\t: Converts the given coordinates to window/view/model space.",
12036 __FILE__, VConvert, group);
12037 theCommands.Add ("vfps",
12038 "vfps [framesNb=100] : estimate average frame rate for active view",
12039 __FILE__, VFps, group);
12040 theCommands.Add ("vgldebug",
12041 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
12042 "\n\t\t: [-extraMsg {0|1}] [{0|1}]"
12043 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
12044 "\n\t\t: Debug context can be requested only on Windows"
12045 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
12046 "\n\t\t: -sync - request synchronized debug GL context"
12047 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
12048 "\n\t\t: which are suppressed by default,"
12049 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
12050 "\n\t\t: which are suppressed by default",
12051 __FILE__, VGlDebug, group);
12052 theCommands.Add ("vvbo",
12053 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
12054 __FILE__, VVbo, group);
12055 theCommands.Add ("vstereo",
12056 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
12057 "\n\t\t: [-anaglyph Filter]"
12058 "\n\t\t: Control stereo output mode. Available modes for -mode:"
12059 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
12060 "\n\t\t: requires driver support."
12061 "\n\t\t: Should be called BEFORE vinit!"
12062 "\n\t\t: anaglyph - Anaglyph glasses"
12063 "\n\t\t: rowInterlaced - row-interlaced display"
12064 "\n\t\t: columnInterlaced - column-interlaced display"
12065 "\n\t\t: chessBoard - chess-board output"
12066 "\n\t\t: sideBySide - horizontal pair"
12067 "\n\t\t: overUnder - vertical pair"
12068 "\n\t\t: Available Anaglyph filters for -anaglyph:"
12069 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
12070 "\n\t\t: greenMagentaSimple",
12071 __FILE__, VStereo, group);
12072 theCommands.Add ("vcaps",
12073 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
12074 "\n\t\t: [-compatibleProfile {0|1}]"
12075 "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]"
12076 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
12077 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
12078 "\n\t\t: Modify particular graphic driver options:"
12079 "\n\t\t: FFP - use fixed-function pipeline instead of"
12080 "\n\t\t: built-in GLSL programs"
12081 "\n\t\t: (requires compatible profile)"
12082 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
12083 "\n\t\t: arrays to GPU memory)"
12084 "\n\t\t: sprite - use textured sprites instead of bitmaps"
12085 "\n\t\t: vsync - switch VSync on or off"
12086 "\n\t\t: winBuffer - allow using window buffer for rendering"
12087 "\n\t\t: Context creation options:"
12088 "\n\t\t: softMode - software OpenGL implementation"
12089 "\n\t\t: compatibleProfile - backward-compatible profile"
12090 "\n\t\t: quadbuffer - QuadBuffer"
12091 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
12092 "\n\t\t: rendering paths producing the same visual result when"
12093 "\n\t\t: possible."
12094 "\n\t\t: Command is intended for testing old hardware compatibility.",
12095 __FILE__, VCaps, group);
12096 theCommands.Add ("vmemgpu",
12097 "vmemgpu [f]: print system-dependent GPU memory information if available;"
12098 " with f option returns free memory in bytes",
12099 __FILE__, VMemGpu, group);
12100 theCommands.Add ("vreadpixel",
12101 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
12102 " : Read pixel value for active view",
12103 __FILE__, VReadPixel, group);
12104 theCommands.Add("diffimage",
12105 "diffimage imageFile1 imageFile2 [diffImageFile]"
12106 "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]"
12107 "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]"
12108 "\n\t\t: Compare two images by content and generate difference image."
12109 "\n\t\t: When -exitOnClose is specified, closing the view will exit application."
12110 "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.",
12111 __FILE__, VDiffImage, group);
12112 theCommands.Add ("vselect",
12113 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
12114 "- emulates different types of selection:\n"
12115 "- 1) single click selection\n"
12116 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
12117 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
12118 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
12119 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
12120 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
12121 " (partial inclusion - overlap - is not allowed by default)\n"
12122 "- 5) any of these selections with shift button pressed",
12123 __FILE__, VSelect, group);
12124 theCommands.Add ("vmoveto",
12125 "vmoveto [x y] [-reset]"
12126 "\n\t\t: Emulates cursor movement to pixel position (x,y)."
12127 "\n\t\t: -reset resets current highlighting",
12128 __FILE__, VMoveTo, group);
12129 theCommands.Add ("vviewparams",
12130 "vviewparams [-args] [-scale [s]]"
12131 "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]"
12132 "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]"
12133 "\n\t\t: Manage current view parameters or prints all"
12134 "\n\t\t: current values when called without argument."
12135 "\n\t\t: -scale [s] prints or sets viewport relative scale"
12136 "\n\t\t: -eye [x y z] prints or sets eye location"
12137 "\n\t\t: -at [x y z] prints or sets center of look"
12138 "\n\t\t: -up [x y z] prints or sets direction of up vector"
12139 "\n\t\t: -proj [x y z] prints or sets direction of look"
12140 "\n\t\t: -center x y sets location of center of the screen in pixels"
12141 "\n\t\t: -size [sx] prints viewport projection width and height sizes"
12142 "\n\t\t: or changes the size of its maximum dimension"
12143 "\n\t\t: -args prints vviewparams arguments for restoring current view",
12144 __FILE__, VViewParams, group);
12146 theCommands.Add("v2dmode",
12147 "v2dmode [-name viewName] [-mode {-on|-off}=-on]"
12148 "\n\t\t: name - name of existing view, if not defined, the active view is changed"
12149 "\n\t\t: mode - switches On/Off rotation mode"
12150 "\n\t\t: Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:"
12151 "\n\t\t: - rotation of the view by 3rd mouse button with Ctrl active"
12152 "\n\t\t: - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right"
12153 "\n\t\t: View camera position might be changed only by commands.",
12154 __FILE__, V2DMode, group);
12156 theCommands.Add("vanimation", "Alias for vanim",
12157 __FILE__, VAnimation, group);
12159 theCommands.Add("vanim",
12160 "List existing animations:"
12162 "\n\t\t: Animation playback:"
12163 "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]"
12164 "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]"
12165 "\n\t\t: -speed playback speed (1.0 is normal speed)"
12166 "\n\t\t: -freeLook skip camera animations"
12167 "\n\t\t: -lockLoop disable any interactions"
12169 "\n\t\t: Animation definition:"
12170 "\n\t\t: vanim Name/sub/name [-clear] [-delete]"
12171 "\n\t\t: [start TimeSec] [duration TimeSec]"
12173 "\n\t\t: Animation name defined in path-style (anim/name or anim.name)"
12174 "\n\t\t: specifies nested animations."
12175 "\n\t\t: There is no syntax to explicitly add new animation,"
12176 "\n\t\t: and all non-existing animations within the name will be"
12177 "\n\t\t: implicitly created on first use (including parents)."
12179 "\n\t\t: Each animation might define the SINGLE action (see below),"
12180 "\n\t\t: like camera transition, object transformation or custom callback."
12181 "\n\t\t: Child animations can be used for defining concurrent actions."
12183 "\n\t\t: Camera animation:"
12184 "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]"
12185 "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]"
12186 "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]"
12187 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
12188 "\n\t\t: -eyeX camera Eye positions pair (start and end)"
12189 "\n\t\t: -atX camera Center positions pair"
12190 "\n\t\t: -upX camera Up directions pair"
12191 "\n\t\t: -scaleX camera Scale factors pair"
12192 "\n\t\t: Object animation:"
12193 "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]"
12194 "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]"
12195 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
12196 "\n\t\t: -locX object Location points pair (translation)"
12197 "\n\t\t: -rotX object Orientations pair (quaternions)"
12198 "\n\t\t: -scaleX object Scale factors pair (quaternions)"
12199 "\n\t\t: Custom callback:"
12200 "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\""
12201 "\n\t\t: %Pts overall animation presentation timestamp"
12202 "\n\t\t: %LocalPts local animation timestamp"
12203 "\n\t\t: %Normalized local animation normalized value in range 0..1"
12205 "\n\t\t: Video recording:"
12206 "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]"
12207 "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]"
12208 "\n\t\t: [-crf Value] [-preset Preset]"
12209 "\n\t\t: -fps video framerate"
12210 "\n\t\t: -format file format, container (matroska, etc.)"
12211 "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)"
12212 "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)"
12213 "\n\t\t: -crf constant rate factor (specific to codec)"
12214 "\n\t\t: -preset codec parameters preset (specific to codec)"
12215 __FILE__, VAnimation, group);
12217 theCommands.Add("vchangeselected",
12218 "vchangeselected shape"
12219 "- adds to shape to selection or remove one from it",
12220 __FILE__, VChangeSelected, group);
12221 theCommands.Add ("vnbselected",
12223 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
12224 theCommands.Add ("vcamera",
12225 "vcamera [-ortho] [-projtype]"
12227 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
12228 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
12229 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
12230 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
12231 "\n\t\t: Manage camera parameters."
12232 "\n\t\t: Prints current value when option called without argument."
12233 "\n\t\t: Orthographic camera:"
12234 "\n\t\t: -ortho activate orthographic projection"
12235 "\n\t\t: Perspective camera:"
12236 "\n\t\t: -persp activate perspective projection (mono)"
12237 "\n\t\t: -fovy field of view in y axis, in degrees"
12238 "\n\t\t: -distance distance of eye from camera center"
12239 "\n\t\t: Stereoscopic camera:"
12240 "\n\t\t: -stereo perspective projection (stereo)"
12241 "\n\t\t: -leftEye perspective projection (left eye)"
12242 "\n\t\t: -rightEye perspective projection (right eye)"
12243 "\n\t\t: -iod intraocular distance value"
12244 "\n\t\t: -iodType distance type, absolute or relative"
12245 "\n\t\t: -zfocus stereographic focus value"
12246 "\n\t\t: -zfocusType focus type, absolute or relative",
12247 __FILE__, VCamera, group);
12248 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
12249 "- vautozfit [on={1|0}] [scale]\n"
12250 " Prints or changes parameters of automatic z-fit mode:\n"
12251 " \"on\" - turns automatic z-fit on or off\n"
12252 " \"scale\" - specifies factor to scale computed z range.\n",
12253 __FILE__, VAutoZFit, group);
12254 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
12255 " vzrange - without parameters shows current values\n"
12256 " vzrange [znear] [zfar] - applies provided values to view",
12257 __FILE__,VZRange, group);
12258 theCommands.Add ("vpurgedisplay",
12260 "- removes structures which don't belong to objects displayed in neutral point",
12261 __FILE__, VPurgeDisplay, group);
12262 theCommands.Add("vsetviewsize",
12263 "vsetviewsize size",
12264 __FILE__,VSetViewSize,group);
12265 theCommands.Add("vmoveview",
12266 "vmoveview Dx Dy Dz [Start = 1|0]",
12267 __FILE__,VMoveView,group);
12268 theCommands.Add("vtranslateview",
12269 "vtranslateview Dx Dy Dz [Start = 1|0)]",
12270 __FILE__,VTranslateView,group);
12271 theCommands.Add("vturnview",
12272 "vturnview Ax Ay Az [Start = 1|0]",
12273 __FILE__,VTurnView,group);
12274 theCommands.Add("vtextureenv",
12275 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
12276 "or user-defined file and optionally applying texture mapping parameters\n"
12278 " vtextureenv off - disables environment mapping\n"
12279 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
12280 " std_texture = (0..7)\n"
12281 " rep = {clamp|repeat}\n"
12282 " mod = {decal|modulate}\n"
12283 " flt = {nearest|bilinear|trilinear}\n"
12284 " ss, st - scale factors for s and t texture coordinates\n"
12285 " ts, tt - translation for s and t texture coordinates\n"
12286 " rot - texture rotation angle in degrees",
12287 __FILE__, VTextureEnv, group);
12288 theCommands.Add("vhlr",
12289 "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
12290 "\n\t\t: Hidden Line Removal algorithm."
12291 "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones"
12292 "\n\t\t: -algoType type of HLR algorithm.\n",
12293 __FILE__,VHLR,group);
12294 theCommands.Add("vhlrtype",
12295 "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
12296 "\n\t\t: Changes the type of HLR algorithm using for shapes:"
12297 "\n\t\t: 'algo' - exact HLR algorithm is applied"
12298 "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied"
12299 "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
12300 __FILE__,VHLRType,group);
12301 theCommands.Add("vclipplane",
12302 "vclipplane planeName [{0|1}]"
12303 "\n\t\t: [-equation A B C D]"
12304 "\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]"
12305 "\n\t\t: [-maxPlanes]"
12306 "\n\t\t: [-capping {0|1}]"
12307 "\n\t\t: [-color R G B] [-hatch {on|off|ID}]"
12308 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
12309 "\n\t\t: [-texRotate Angle]"
12310 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
12311 "\n\t\t: [-useObjShader {0|1}]"
12312 "\n\t\t: Clipping planes management:"
12313 "\n\t\t: -maxPlanes print plane limit for view"
12314 "\n\t\t: -delete delete plane with given name"
12315 "\n\t\t: {off|on|0|1} turn clipping on/off"
12316 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
12317 "\n\t\t: applied to active View when list is omitted"
12318 "\n\t\t: -equation A B C D change plane equation"
12319 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
12320 "\n\t\t: Capping options:"
12321 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
12322 "\n\t\t: -color R G B set capping color"
12323 "\n\t\t: -texName Texture set capping texture"
12324 "\n\t\t: -texScale SX SY set capping tex scale"
12325 "\n\t\t: -texOrigin TX TY set capping tex origin"
12326 "\n\t\t: -texRotate Angle set capping tex rotation"
12327 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
12328 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
12329 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
12330 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
12331 __FILE__, VClipPlane, group);
12332 theCommands.Add("vdefaults",
12333 "vdefaults [-absDefl value]"
12334 "\n\t\t: [-devCoeff value]"
12335 "\n\t\t: [-angDefl value]"
12336 "\n\t\t: [-autoTriang {off/on | 0/1}]"
12337 , __FILE__, VDefaults, group);
12338 theCommands.Add("vlight",
12339 "tool to manage light sources, without arguments shows list of lights."
12340 "\n Main commands: "
12341 "\n '-clear' to clear lights"
12342 "\n '-{def}aults' to load deafault lights"
12343 "\n '-add' <type> to add any light source"
12344 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
12345 "\n 'change' <lightId> to edit light source with specified lightId"
12346 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
12348 "\n -{pos}ition X Y Z"
12349 "\n -{dir}ection X Y Z (for directional light or for spotlight)"
12350 "\n -color colorName"
12351 "\n -{head}light 0|1"
12352 "\n -{sm}oothness value"
12353 "\n -{int}ensity value"
12354 "\n -{constAtten}uation value"
12355 "\n -{linearAtten}uation value"
12356 "\n -angle angleDeg"
12357 "\n -{spotexp}onent value"
12358 "\n -local|-global"
12359 "\n\n example: vlight -add positional -head 1 -pos 0 1 1 -color red"
12360 "\n example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2",
12361 __FILE__, VLight, group);
12362 theCommands.Add("vraytrace",
12364 "\n\t\t: Turns on/off ray-tracing renderer."
12365 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
12366 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
12367 __FILE__, VRenderParams, group);
12368 theCommands.Add("vrenderparams",
12369 "\n Manages rendering parameters: "
12370 "\n '-raster' Disables GPU ray-tracing"
12371 "\n '-msaa 0..4' Specifies number of samples for MSAA"
12372 "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor"
12373 "\n '-depthPrePass on|off' Enables/disables depth pre-pass"
12374 "\n '-alphatocoverage on|off' Enables/disables alpha to coverage (needs MSAA)"
12375 "\n '-rendScale value Rendering resolution scale factor"
12376 "\n '-rayTrace' Enables GPU ray-tracing"
12377 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
12378 "\n '-shadows on|off' Enables/disables shadows rendering"
12379 "\n '-reflections on|off' Enables/disables specular reflections"
12380 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
12381 "\n '-gleam on|off' Enables/disables transparency shadow effects"
12382 "\n '-gi on|off' Enables/disables global illumination effects"
12383 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
12384 "\n '-env on|off' Enables/disables environment map background"
12385 "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
12386 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
12387 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
12388 "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)"
12389 "\n '-nbtiles 64..1024' Specifies number of screen tiles in ISS mode"
12390 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
12391 "\n '-shadingModel model' Controls shading model from enumeration"
12392 "\n color, flat, gouraud, phong"
12393 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
12394 "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)"
12395 "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect"
12396 "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)"
12397 "\n '-whitepoint value' White point value for filmic tone mapping"
12398 "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)"
12399 "\n '-perfCounters none|fps|cpu|layers|structures|groups|arrays|triagles|points|gpuMem|basic|extended|nofps'"
12400 "\n Show/hide performance counters (flags can be combined)"
12401 "\n '-perfUpdateInterval nbSeconds' Performance counters update interval"
12402 "\n Unlike vcaps, these parameters dramatically change visual properties."
12403 "\n Command is intended to control presentation quality depending on"
12404 "\n hardware capabilities and performance.",
12405 __FILE__, VRenderParams, group);
12406 theCommands.Add("vfrustumculling",
12407 "vfrustumculling [toEnable]: enables/disables objects clipping",
12408 __FILE__,VFrustumCulling,group);
12409 theCommands.Add("vhighlightselected",
12410 "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n"
12411 "Without arguments it shows if highlighting of selected objects is enabled now.",
12412 __FILE__,VHighlightSelected,group);
12413 theCommands.Add ("vplace",
12415 "\n\t\t: Places the point (in pixels) at the center of the window",
12416 __FILE__, VPlace, group);
12417 theCommands.Add("vxrotate",
12419 __FILE__,VXRotate,group);
12421 theCommands.Add("vmanipulator",
12422 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
12423 "\n tool to create and manage AIS manipulators."
12425 "\n '-attach AISObject' attach manipulator to AISObject"
12426 "\n '-adjustPosition {0|1}' adjust position when attaching"
12427 "\n '-adjustSize {0|1}' adjust size when attaching"
12428 "\n '-enableModes {0|1}' enable modes when attaching"
12429 "\n '-detach' detach manipulator"
12430 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
12431 "\n '-transform mouse_x mouse_y' - invoke transformation"
12432 "\n '-stopTransform [abort]' - invoke stop of transformation"
12433 "\n '-move x y z' - move attached object"
12434 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
12435 "\n '-scale factor' - scale attached object"
12436 "\n '-autoActivate {0|1}' - set activation on detection"
12437 "\n '-followTranslation {0|1}' - set following translation transform"
12438 "\n '-followRotation {0|1}' - set following rotation transform"
12439 "\n '-gap value' - set gap between sub-parts"
12440 "\n '-part axis mode {0|1}' - set visual part"
12441 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
12442 "\n '-size value' - set size of manipulator"
12443 "\n '-zoomable {0|1}' - set zoom persistence",
12444 __FILE__, VManipulator, group);
12446 theCommands.Add("vselprops",
12447 "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]"
12448 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
12449 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
12450 "\n -pickStrategy {first|topmost} : defines picking strategy"
12451 "\n 'first' to pick first acceptable (default)"
12452 "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)"
12453 "\n -pixTol value : sets up pixel tolerance"
12454 "\n -dispMode dispMode : sets display mode for highlighting"
12455 "\n -layer ZLayer : sets ZLayer for highlighting"
12456 "\n -color {name|r g b} : sets highlight color"
12457 "\n -transp value : sets transparency coefficient for highlight"
12458 "\n -material material : sets highlight material"
12459 "\n -print : prints current state of all mentioned parameters",
12460 __FILE__, VSelectionProperties, group);
12462 theCommands.Add ("vseldump",
12463 "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1"
12464 "\n\t\t: Generate an image based on detection results:"
12465 "\n\t\t: depth normalized depth values"
12466 "\n\t\t: unnormDepth unnormalized depth values"
12467 "\n\t\t: object color of detected object"
12468 "\n\t\t: owner color of detected owner"
12469 "\n\t\t: selMode color of selection mode"
12470 "\n\t\t: entity color of etected entity",
12471 __FILE__, VDumpSelectionImage, group);
12473 #if defined(_WIN32)
12474 theCommands.Add("vprogressive",
12476 __FILE__, VProgressiveMode, group);