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, 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, 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 const Handle(AIS_InteractiveObject)& aPrs = 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 Handle(AIS_InteractiveObject) anObject;
7460 if (!aMapOfAIS.Find2 (anObjName, anObject))
7462 std::cout << "Syntax error: wrong object name at " << anArg << "\n";
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 TCollection_AsciiString aName(argv[1]);
7808 Handle(AIS_InteractiveObject) anAISObject;
7809 if (!GetMapOfAIS().Find2 (aName, anAISObject)
7810 || anAISObject.IsNull())
7812 di<<"Use 'vdisplay' before";
7816 ViewerTest::GetAISContext()->AddOrRemoveSelected(anAISObject, Standard_True);
7820 //=======================================================================
7821 //function : VNbSelected
7822 //purpose : Returns number of selected objects
7823 //=======================================================================
7824 static Standard_Integer VNbSelected (Draw_Interpretor& di,
7825 Standard_Integer argc,
7830 di << "Usage : " << argv[0] << "\n";
7833 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7834 if(aContext.IsNull())
7836 di << "use 'vinit' command before " << argv[0] << "\n";
7839 di << aContext->NbSelected() << "\n";
7843 //=======================================================================
7844 //function : VPurgeDisplay
7845 //purpose : Switches altialiasing on or off
7846 //=======================================================================
7847 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
7848 Standard_Integer argc,
7853 di << "Usage : " << argv[0] << "\n";
7856 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7857 if (aContext.IsNull())
7859 di << "use 'vinit' command before " << argv[0] << "\n";
7863 di << aContext->PurgeDisplay() << "\n";
7867 //=======================================================================
7868 //function : VSetViewSize
7870 //=======================================================================
7871 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
7872 Standard_Integer argc,
7875 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7876 if(aContext.IsNull())
7878 di << "use 'vinit' command before " << argv[0] << "\n";
7883 di<<"Usage : " << argv[0] << " Size\n";
7886 Standard_Real aSize = Draw::Atof (argv[1]);
7889 di<<"Bad Size value : " << aSize << "\n";
7893 Handle(V3d_View) aView = ViewerTest::CurrentView();
7894 aView->SetSize(aSize);
7898 //=======================================================================
7899 //function : VMoveView
7901 //=======================================================================
7902 static Standard_Integer VMoveView (Draw_Interpretor& di,
7903 Standard_Integer argc,
7906 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7907 if(aContext.IsNull())
7909 di << "use 'vinit' command before " << argv[0] << "\n";
7912 if(argc < 4 || argc > 5)
7914 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
7917 Standard_Real Dx = Draw::Atof (argv[1]);
7918 Standard_Real Dy = Draw::Atof (argv[2]);
7919 Standard_Real Dz = Draw::Atof (argv[3]);
7920 Standard_Boolean aStart = Standard_True;
7923 aStart = (Draw::Atoi (argv[4]) > 0);
7926 Handle(V3d_View) aView = ViewerTest::CurrentView();
7927 aView->Move(Dx,Dy,Dz,aStart);
7931 //=======================================================================
7932 //function : VTranslateView
7934 //=======================================================================
7935 static Standard_Integer VTranslateView (Draw_Interpretor& di,
7936 Standard_Integer argc,
7939 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7940 if(aContext.IsNull())
7942 di << "use 'vinit' command before " << argv[0] << "\n";
7945 if(argc < 4 || argc > 5)
7947 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
7950 Standard_Real Dx = Draw::Atof (argv[1]);
7951 Standard_Real Dy = Draw::Atof (argv[2]);
7952 Standard_Real Dz = Draw::Atof (argv[3]);
7953 Standard_Boolean aStart = Standard_True;
7956 aStart = (Draw::Atoi (argv[4]) > 0);
7959 Handle(V3d_View) aView = ViewerTest::CurrentView();
7960 aView->Translate(Dx,Dy,Dz,aStart);
7964 //=======================================================================
7965 //function : VTurnView
7967 //=======================================================================
7968 static Standard_Integer VTurnView (Draw_Interpretor& di,
7969 Standard_Integer argc,
7972 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7973 if(aContext.IsNull()) {
7974 di << "use 'vinit' command before " << argv[0] << "\n";
7977 if(argc < 4 || argc > 5){
7978 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
7981 Standard_Real Ax = Draw::Atof (argv[1]);
7982 Standard_Real Ay = Draw::Atof (argv[2]);
7983 Standard_Real Az = Draw::Atof (argv[3]);
7984 Standard_Boolean aStart = Standard_True;
7987 aStart = (Draw::Atoi (argv[4]) > 0);
7990 Handle(V3d_View) aView = ViewerTest::CurrentView();
7991 aView->Turn(Ax,Ay,Az,aStart);
7995 //==============================================================================
7996 //function : VTextureEnv
7997 //purpose : ENables or disables environment mapping
7998 //==============================================================================
7999 class OCC_TextureEnv : public Graphic3d_TextureEnv
8002 OCC_TextureEnv(const Standard_CString FileName);
8003 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
8004 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
8005 const Standard_Boolean theModulateFlag,
8006 const Graphic3d_TypeOfTextureFilter theFilter,
8007 const Standard_ShortReal theXScale,
8008 const Standard_ShortReal theYScale,
8009 const Standard_ShortReal theXShift,
8010 const Standard_ShortReal theYShift,
8011 const Standard_ShortReal theAngle);
8012 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
8014 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
8016 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
8017 : Graphic3d_TextureEnv(theFileName)
8021 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
8022 : Graphic3d_TextureEnv(theTexId)
8026 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
8027 const Standard_Boolean theModulateFlag,
8028 const Graphic3d_TypeOfTextureFilter theFilter,
8029 const Standard_ShortReal theXScale,
8030 const Standard_ShortReal theYScale,
8031 const Standard_ShortReal theXShift,
8032 const Standard_ShortReal theYShift,
8033 const Standard_ShortReal theAngle)
8035 myParams->SetRepeat (theRepeatFlag);
8036 myParams->SetModulate (theModulateFlag);
8037 myParams->SetFilter (theFilter);
8038 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
8039 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
8040 myParams->SetRotation (theAngle);
8043 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
8045 // get the active view
8046 Handle(V3d_View) aView = ViewerTest::CurrentView();
8049 std::cerr << "No active view. Please call vinit.\n";
8053 // Checking the input arguments
8054 Standard_Boolean anEnableFlag = Standard_False;
8055 Standard_Boolean isOk = theArgNb >= 2;
8058 TCollection_AsciiString anEnableOpt(theArgVec[1]);
8059 anEnableFlag = anEnableOpt.IsEqual("on");
8060 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
8064 isOk = (theArgNb == 3 || theArgNb == 11);
8067 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8068 isOk = (!aTextureOpt.IsIntegerValue() ||
8069 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
8071 if (isOk && theArgNb == 11)
8073 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
8074 aModulateOpt(theArgVec[4]),
8075 aFilterOpt (theArgVec[5]),
8076 aSScaleOpt (theArgVec[6]),
8077 aTScaleOpt (theArgVec[7]),
8078 aSTransOpt (theArgVec[8]),
8079 aTTransOpt (theArgVec[9]),
8080 anAngleOpt (theArgVec[10]);
8081 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
8082 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
8083 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
8084 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
8085 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
8086 anAngleOpt.IsRealValue());
8093 std::cerr << "Usage :" << std::endl;
8094 std::cerr << theArgVec[0] << " off" << std::endl;
8095 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;
8101 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8102 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
8103 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
8104 new OCC_TextureEnv(theArgVec[2]);
8108 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
8109 aTexEnv->SetTextureParameters(
8110 aRepeatOpt. IsEqual("repeat"),
8111 aModulateOpt.IsEqual("modulate"),
8112 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
8113 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
8114 Graphic3d_TOTF_TRILINEAR,
8115 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
8116 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
8117 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
8118 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
8119 (Standard_ShortReal)Draw::Atof(theArgVec[10])
8122 aView->SetTextureEnv(aTexEnv);
8124 else // Disabling environment mapping
8126 Handle(Graphic3d_TextureEnv) aTexture;
8127 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
8136 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
8138 //! Remove registered clipping plane from all views and objects.
8139 static void removePlane (MapOfPlanes& theRegPlanes,
8140 const TCollection_AsciiString& theName)
8142 Handle(Graphic3d_ClipPlane) aClipPlane;
8143 if (!theRegPlanes.Find (theName, aClipPlane))
8145 std::cout << "Warning: no such plane.\n";
8149 theRegPlanes.UnBind (theName);
8150 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
8151 anIObjIt.More(); anIObjIt.Next())
8153 const Handle(AIS_InteractiveObject)& aPrs = anIObjIt.Key1();
8154 aPrs->RemoveClipPlane (aClipPlane);
8157 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
8158 aViewIt.More(); aViewIt.Next())
8160 const Handle(V3d_View)& aView = aViewIt.Key2();
8161 aView->RemoveClipPlane(aClipPlane);
8164 ViewerTest::RedrawAllViews();
8168 //===============================================================================================
8169 //function : VClipPlane
8171 //===============================================================================================
8172 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8174 // use short-cut for created clip planes map of created (or "registered by name") clip planes
8175 static MapOfPlanes aRegPlanes;
8179 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
8181 theDi << aPlaneIter.Key() << " ";
8186 TCollection_AsciiString aCommand (theArgVec[1]);
8187 aCommand.LowerCase();
8188 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
8189 if (anActiveView.IsNull())
8191 std::cout << "Error: no active view.\n";
8195 // print maximum number of planes for current viewer
8196 if (aCommand == "-maxplanes"
8197 || aCommand == "maxplanes")
8199 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
8200 << " plane slots provided by driver.\n";
8204 // create / delete plane instance
8205 if (aCommand == "-create"
8206 || aCommand == "create"
8207 || aCommand == "-delete"
8208 || aCommand == "delete"
8209 || aCommand == "-clone"
8210 || aCommand == "clone")
8214 std::cout << "Syntax error: plane name is required.\n";
8218 Standard_Boolean toCreate = aCommand == "-create"
8219 || aCommand == "create";
8220 Standard_Boolean toClone = aCommand == "-clone"
8221 || aCommand == "clone";
8222 Standard_Boolean toDelete = aCommand == "-delete"
8223 || aCommand == "delete";
8224 TCollection_AsciiString aPlane (theArgVec[2]);
8228 if (aRegPlanes.IsBound (aPlane))
8230 std::cout << "Warning: existing plane has been overridden.\n";
8235 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8239 else if (toClone) // toClone
8241 if (!aRegPlanes.IsBound (aPlane))
8243 std::cout << "Error: no such plane.\n";
8246 else if (theArgsNb < 4)
8248 std::cout << "Syntax error: enter name for new plane.\n";
8252 TCollection_AsciiString aClone (theArgVec[3]);
8253 if (aRegPlanes.IsBound (aClone))
8255 std::cout << "Error: plane name is in use.\n";
8259 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
8261 aRegPlanes.Bind (aClone, aClipPlane->Clone());
8271 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
8273 aPlane = aPlaneIter.Key();
8274 removePlane (aRegPlanes, aPlane);
8275 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
8280 removePlane (aRegPlanes, aPlane);
8286 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8291 // set / unset plane command
8292 if (aCommand == "set"
8293 || aCommand == "unset")
8297 std::cout << "Syntax error: need more arguments.\n";
8301 // redirect to new syntax
8302 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
8303 anArgVec.SetValue (1, theArgVec[0]);
8304 anArgVec.SetValue (2, theArgVec[2]);
8305 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
8306 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
8308 anArgVec.SetValue (anIt, theArgVec[anIt]);
8311 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
8314 // change plane command
8315 TCollection_AsciiString aPlaneName;
8316 Handle(Graphic3d_ClipPlane) aClipPlane;
8317 Standard_Integer anArgIter = 0;
8318 if (aCommand == "-change"
8319 || aCommand == "change")
8321 // old syntax support
8324 std::cout << "Syntax error: need more arguments.\n";
8329 aPlaneName = theArgVec[2];
8330 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
8332 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
8336 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
8339 aPlaneName = theArgVec[1];
8344 aPlaneName = theArgVec[1];
8345 aClipPlane = new Graphic3d_ClipPlane();
8346 aRegPlanes.Bind (aPlaneName, aClipPlane);
8347 theDi << "Created new plane " << aPlaneName << ".\n";
8350 if (theArgsNb - anArgIter < 1)
8352 std::cout << "Syntax error: need more arguments.\n";
8356 for (; anArgIter < theArgsNb; ++anArgIter)
8358 const char** aChangeArgs = theArgVec + anArgIter;
8359 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
8360 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
8361 aChangeArg.LowerCase();
8363 Standard_Boolean toEnable = Standard_True;
8364 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
8366 aClipPlane->SetOn (toEnable);
8368 else if (aChangeArg.StartsWith ("-equation")
8369 || aChangeArg.StartsWith ("equation"))
8371 if (aNbChangeArgs < 5)
8373 std::cout << "Syntax error: need more arguments.\n";
8377 Standard_Integer aSubIndex = 1;
8378 Standard_Integer aPrefixLen = 8 + (aChangeArg.Value (1) == '-' ? 1 : 0);
8379 if (aPrefixLen < aChangeArg.Length())
8381 TCollection_AsciiString aSubStr = aChangeArg.SubString (aPrefixLen + 1, aChangeArg.Length());
8382 if (!aSubStr.IsIntegerValue()
8383 || aSubStr.IntegerValue() <= 0)
8385 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
8388 aSubIndex = aSubStr.IntegerValue();
8391 Standard_Real aCoeffA = Draw::Atof (aChangeArgs[1]);
8392 Standard_Real aCoeffB = Draw::Atof (aChangeArgs[2]);
8393 Standard_Real aCoeffC = Draw::Atof (aChangeArgs[3]);
8394 Standard_Real aCoeffD = Draw::Atof (aChangeArgs[4]);
8395 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
8396 for (Standard_Integer aSubPlaneIter = 1; aSubPlaneIter < aSubIndex; ++aSubPlaneIter)
8398 if (aSubPln->ChainNextPlane().IsNull())
8400 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
8402 aSubPln = aSubPln->ChainNextPlane();
8404 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
8405 aSubPln->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
8408 else if ((aChangeArg == "-boxinterior"
8409 || aChangeArg == "-boxint"
8410 || aChangeArg == "-box")
8411 && aNbChangeArgs >= 7)
8413 Graphic3d_BndBox3d aBndBox;
8414 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[1]), Draw::Atof (aChangeArgs[2]), Draw::Atof (aChangeArgs[3])));
8415 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[4]), Draw::Atof (aChangeArgs[5]), Draw::Atof (aChangeArgs[6])));
8418 Standard_Integer aNbSubPlanes = 6;
8419 const Graphic3d_Vec3d aDirArray[6] =
8421 Graphic3d_Vec3d (-1, 0, 0),
8422 Graphic3d_Vec3d ( 1, 0, 0),
8423 Graphic3d_Vec3d ( 0,-1, 0),
8424 Graphic3d_Vec3d ( 0, 1, 0),
8425 Graphic3d_Vec3d ( 0, 0,-1),
8426 Graphic3d_Vec3d ( 0, 0, 1),
8428 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
8429 for (Standard_Integer aSubPlaneIter = 0; aSubPlaneIter < aNbSubPlanes; ++aSubPlaneIter)
8431 const Graphic3d_Vec3d& aDir = aDirArray[aSubPlaneIter];
8432 const Standard_Real aW = -aDir.Dot ((aSubPlaneIter % 2 == 1) ? aBndBox.CornerMax() : aBndBox.CornerMin());
8433 aSubPln->SetEquation (gp_Pln (aDir.x(), aDir.y(), aDir.z(), aW));
8434 if (aSubPlaneIter + 1 == aNbSubPlanes)
8436 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
8440 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
8442 aSubPln = aSubPln->ChainNextPlane();
8445 else if (aChangeArg == "-capping"
8446 || aChangeArg == "capping")
8448 if (aNbChangeArgs < 2)
8450 std::cout << "Syntax error: need more arguments.\n";
8454 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8456 aClipPlane->SetCapping (toEnable);
8461 // just skip otherwise (old syntax)
8464 else if (aChangeArg == "-useobjectmaterial"
8465 || aChangeArg == "-useobjectmat"
8466 || aChangeArg == "-useobjmat"
8467 || aChangeArg == "-useobjmaterial")
8469 if (aNbChangeArgs < 2)
8471 std::cout << "Syntax error: need more arguments.\n";
8475 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8477 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
8481 else if (aChangeArg == "-useobjecttexture"
8482 || aChangeArg == "-useobjecttex"
8483 || aChangeArg == "-useobjtexture"
8484 || aChangeArg == "-useobjtex")
8486 if (aNbChangeArgs < 2)
8488 std::cout << "Syntax error: need more arguments.\n";
8492 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8494 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
8498 else if (aChangeArg == "-useobjectshader"
8499 || aChangeArg == "-useobjshader")
8501 if (aNbChangeArgs < 2)
8503 std::cout << "Syntax error: need more arguments.\n";
8507 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8509 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
8513 else if (aChangeArg == "-color"
8514 || aChangeArg == "color")
8516 Quantity_Color aColor;
8517 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
8522 std::cout << "Syntax error: need more arguments.\n";
8526 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
8527 aMat.SetAmbientColor (aColor);
8528 aMat.SetDiffuseColor (aColor);
8529 aClipPlane->SetCappingMaterial (aMat);
8530 anArgIter += aNbParsed;
8532 else if ((aChangeArg == "-transparency"
8533 || aChangeArg == "-transp")
8534 && aNbChangeArgs >= 2)
8536 TCollection_AsciiString aValStr (aChangeArgs[1]);
8537 Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect();
8538 if (aValStr.IsRealValue())
8540 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
8541 aMat.SetTransparency ((float )aValStr.RealValue());
8542 anAspect->SetAlphaMode (Graphic3d_AlphaMode_BlendAuto);
8543 aClipPlane->SetCappingMaterial (aMat);
8547 aValStr.LowerCase();
8548 Graphic3d_AlphaMode aMode = Graphic3d_AlphaMode_BlendAuto;
8549 if (aValStr == "opaque")
8551 aMode = Graphic3d_AlphaMode_Opaque;
8553 else if (aValStr == "mask")
8555 aMode = Graphic3d_AlphaMode_Mask;
8557 else if (aValStr == "blend")
8559 aMode = Graphic3d_AlphaMode_Blend;
8561 else if (aValStr == "blendauto")
8563 aMode = Graphic3d_AlphaMode_BlendAuto;
8567 std::cout << "Syntax error at '" << aValStr << "'\n";
8570 anAspect->SetAlphaMode (aMode);
8571 aClipPlane->SetCappingAspect (anAspect);
8575 else if (aChangeArg == "-texname"
8576 || aChangeArg == "texname")
8578 if (aNbChangeArgs < 2)
8580 std::cout << "Syntax error: need more arguments.\n";
8584 TCollection_AsciiString aTextureName (aChangeArgs[1]);
8585 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
8586 if (!aTexture->IsDone())
8588 aClipPlane->SetCappingTexture (NULL);
8592 aTexture->EnableModulate();
8593 aTexture->EnableRepeat();
8594 aClipPlane->SetCappingTexture (aTexture);
8598 else if (aChangeArg == "-texscale"
8599 || aChangeArg == "texscale")
8601 if (aClipPlane->CappingTexture().IsNull())
8603 std::cout << "Error: no texture is set.\n";
8607 if (aNbChangeArgs < 3)
8609 std::cout << "Syntax error: need more arguments.\n";
8613 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8614 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8615 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
8618 else if (aChangeArg == "-texorigin"
8619 || aChangeArg == "texorigin") // texture origin
8621 if (aClipPlane->CappingTexture().IsNull())
8623 std::cout << "Error: no texture is set.\n";
8627 if (aNbChangeArgs < 3)
8629 std::cout << "Syntax error: need more arguments.\n";
8633 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8634 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8636 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
8639 else if (aChangeArg == "-texrotate"
8640 || aChangeArg == "texrotate") // texture rotation
8642 if (aClipPlane->CappingTexture().IsNull())
8644 std::cout << "Error: no texture is set.\n";
8648 if (aNbChangeArgs < 2)
8650 std::cout << "Syntax error: need more arguments.\n";
8654 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8655 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
8658 else if (aChangeArg == "-hatch"
8659 || aChangeArg == "hatch")
8661 if (aNbChangeArgs < 2)
8663 std::cout << "Syntax error: need more arguments.\n";
8667 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
8668 aHatchStr.LowerCase();
8669 if (aHatchStr == "on")
8671 aClipPlane->SetCappingHatchOn();
8673 else if (aHatchStr == "off")
8675 aClipPlane->SetCappingHatchOff();
8679 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
8683 else if (aChangeArg == "-delete"
8684 || aChangeArg == "delete")
8686 removePlane (aRegPlanes, aPlaneName);
8689 else if (aChangeArg == "-set"
8690 || aChangeArg == "-unset"
8691 || aChangeArg == "-setoverrideglobal")
8693 // set / unset plane command
8694 const Standard_Boolean toSet = aChangeArg.StartsWith ("-set");
8695 const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal";
8696 Standard_Integer anIt = 1;
8697 for (; anIt < aNbChangeArgs; ++anIt)
8699 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
8700 if (anEntityName.IsEmpty()
8701 || anEntityName.Value (1) == '-')
8705 else if (!toOverrideGlobal
8706 && ViewerTest_myViews.IsBound1 (anEntityName))
8708 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
8711 aView->AddClipPlane (aClipPlane);
8715 aView->RemoveClipPlane (aClipPlane);
8719 else if (GetMapOfAIS().IsBound2 (anEntityName))
8721 Handle(AIS_InteractiveObject) aIObj = GetMapOfAIS().Find2 (anEntityName);
8724 aIObj->AddClipPlane (aClipPlane);
8728 aIObj->RemoveClipPlane (aClipPlane);
8730 if (!aIObj->ClipPlanes().IsNull())
8732 aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal);
8737 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
8744 // apply to active view
8747 anActiveView->AddClipPlane (aClipPlane);
8751 anActiveView->RemoveClipPlane (aClipPlane);
8756 anArgIter = anArgIter + anIt - 1;
8761 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
8766 ViewerTest::RedrawAllViews();
8770 //===============================================================================================
8771 //function : VZRange
8773 //===============================================================================================
8774 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8776 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
8778 if (aCurrentView.IsNull())
8780 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
8784 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
8788 theDi << "ZNear: " << aCamera->ZNear() << "\n";
8789 theDi << "ZFar: " << aCamera->ZFar() << "\n";
8795 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
8796 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
8798 if (aNewZNear >= aNewZFar)
8800 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
8804 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
8806 std::cout << theArgVec[0] << ": invalid arguments: ";
8807 std::cout << "znear, zfar should be positive for perspective camera.\n";
8811 aCamera->SetZRange (aNewZNear, aNewZFar);
8815 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
8819 aCurrentView->Redraw();
8824 //===============================================================================================
8825 //function : VAutoZFit
8827 //===============================================================================================
8828 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8830 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
8832 if (aCurrentView.IsNull())
8834 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
8838 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
8842 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
8848 theDi << "Auto z-fit mode: \n"
8849 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
8850 << "Scale: " << aScale << "\n";
8854 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
8858 aScale = Draw::Atoi (theArgVec[2]);
8861 aCurrentView->SetAutoZFitMode (isOn, aScale);
8862 aCurrentView->AutoZFit();
8863 aCurrentView->Redraw();
8868 //! Auxiliary function to print projection type
8869 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
8871 switch (theProjType)
8873 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
8874 case Graphic3d_Camera::Projection_Perspective: return "perspective";
8875 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
8876 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
8877 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
8882 //===============================================================================================
8883 //function : VCamera
8885 //===============================================================================================
8886 static int VCamera (Draw_Interpretor& theDI,
8887 Standard_Integer theArgsNb,
8888 const char** theArgVec)
8890 Handle(V3d_View) aView = ViewerTest::CurrentView();
8893 std::cout << "Error: no active view.\n";
8897 Handle(Graphic3d_Camera) aCamera = aView->Camera();
8900 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
8901 theDI << "FOVy: " << aCamera->FOVy() << "\n";
8902 theDI << "Distance: " << aCamera->Distance() << "\n";
8903 theDI << "IOD: " << aCamera->IOD() << "\n";
8904 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
8905 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
8906 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
8910 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
8912 Standard_CString anArg = theArgVec[anArgIter];
8913 TCollection_AsciiString anArgCase (anArg);
8914 anArgCase.LowerCase();
8915 if (anArgCase == "-proj"
8916 || anArgCase == "-projection"
8917 || anArgCase == "-projtype"
8918 || anArgCase == "-projectiontype")
8920 theDI << projTypeName (aCamera->ProjectionType()) << " ";
8922 else if (anArgCase == "-ortho"
8923 || anArgCase == "-orthographic")
8925 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
8927 else if (anArgCase == "-persp"
8928 || anArgCase == "-perspective"
8929 || anArgCase == "-perspmono"
8930 || anArgCase == "-perspectivemono"
8931 || anArgCase == "-mono")
8933 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
8935 else if (anArgCase == "-stereo"
8936 || anArgCase == "-stereoscopic"
8937 || anArgCase == "-perspstereo"
8938 || anArgCase == "-perspectivestereo")
8940 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
8942 else if (anArgCase == "-left"
8943 || anArgCase == "-lefteye"
8944 || anArgCase == "-monoleft"
8945 || anArgCase == "-monolefteye"
8946 || anArgCase == "-perpsleft"
8947 || anArgCase == "-perpslefteye")
8949 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
8951 else if (anArgCase == "-right"
8952 || anArgCase == "-righteye"
8953 || anArgCase == "-monoright"
8954 || anArgCase == "-monorighteye"
8955 || anArgCase == "-perpsright")
8957 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
8959 else if (anArgCase == "-dist"
8960 || anArgCase == "-distance")
8962 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8963 if (anArgValue != NULL
8964 && *anArgValue != '-')
8967 aCamera->SetDistance (Draw::Atof (anArgValue));
8970 theDI << aCamera->Distance() << " ";
8972 else if (anArgCase == "-iod")
8974 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8975 if (anArgValue != NULL
8976 && *anArgValue != '-')
8979 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
8982 theDI << aCamera->IOD() << " ";
8984 else if (anArgCase == "-iodtype")
8986 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
8987 TCollection_AsciiString anValueCase (anArgValue);
8988 anValueCase.LowerCase();
8989 if (anValueCase == "abs"
8990 || anValueCase == "absolute")
8993 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
8996 else if (anValueCase == "rel"
8997 || anValueCase == "relative")
9000 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
9003 else if (*anArgValue != '-')
9005 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
9008 switch (aCamera->GetIODType())
9010 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
9011 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
9014 else if (anArgCase == "-zfocus")
9016 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9017 if (anArgValue != NULL
9018 && *anArgValue != '-')
9021 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
9024 theDI << aCamera->ZFocus() << " ";
9026 else if (anArgCase == "-zfocustype")
9028 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
9029 TCollection_AsciiString anValueCase (anArgValue);
9030 anValueCase.LowerCase();
9031 if (anValueCase == "abs"
9032 || anValueCase == "absolute")
9035 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
9038 else if (anValueCase == "rel"
9039 || anValueCase == "relative")
9042 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
9045 else if (*anArgValue != '-')
9047 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
9050 switch (aCamera->ZFocusType())
9052 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
9053 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
9056 else if (anArgCase == "-fov"
9057 || anArgCase == "-fovy")
9059 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9060 if (anArgValue != NULL
9061 && *anArgValue != '-')
9064 aCamera->SetFOVy (Draw::Atof (anArgValue));
9067 theDI << aCamera->FOVy() << " ";
9071 std::cout << "Error: unknown argument '" << anArg << "'\n";
9082 //! Parse stereo output mode
9083 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
9084 Graphic3d_StereoMode& theMode)
9086 TCollection_AsciiString aFlag (theArg);
9088 if (aFlag == "quadbuffer")
9090 theMode = Graphic3d_StereoMode_QuadBuffer;
9092 else if (aFlag == "anaglyph")
9094 theMode = Graphic3d_StereoMode_Anaglyph;
9096 else if (aFlag == "row"
9097 || aFlag == "rowinterlaced")
9099 theMode = Graphic3d_StereoMode_RowInterlaced;
9101 else if (aFlag == "col"
9102 || aFlag == "colinterlaced"
9103 || aFlag == "columninterlaced")
9105 theMode = Graphic3d_StereoMode_ColumnInterlaced;
9107 else if (aFlag == "chess"
9108 || aFlag == "chessboard")
9110 theMode = Graphic3d_StereoMode_ChessBoard;
9112 else if (aFlag == "sbs"
9113 || aFlag == "sidebyside")
9115 theMode = Graphic3d_StereoMode_SideBySide;
9117 else if (aFlag == "ou"
9118 || aFlag == "overunder")
9120 theMode = Graphic3d_StereoMode_OverUnder;
9122 else if (aFlag == "pageflip"
9123 || aFlag == "softpageflip")
9125 theMode = Graphic3d_StereoMode_SoftPageFlip;
9129 return Standard_False;
9131 return Standard_True;
9134 //! Parse anaglyph filter
9135 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
9136 Graphic3d_RenderingParams::Anaglyph& theFilter)
9138 TCollection_AsciiString aFlag (theArg);
9140 if (aFlag == "redcyansimple")
9142 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9144 else if (aFlag == "redcyan"
9145 || aFlag == "redcyanoptimized")
9147 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
9149 else if (aFlag == "yellowbluesimple")
9151 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
9153 else if (aFlag == "yellowblue"
9154 || aFlag == "yellowblueoptimized")
9156 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
9158 else if (aFlag == "greenmagenta"
9159 || aFlag == "greenmagentasimple")
9161 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
9165 return Standard_False;
9167 return Standard_True;
9170 //==============================================================================
9171 //function : VStereo
9173 //==============================================================================
9175 static int VStereo (Draw_Interpretor& theDI,
9176 Standard_Integer theArgNb,
9177 const char** theArgVec)
9179 Handle(V3d_View) aView = ViewerTest::CurrentView();
9184 std::cout << "Error: no active viewer!\n";
9188 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
9189 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
9192 TCollection_AsciiString aMode;
9193 switch (aView->RenderingParams().StereoMode)
9195 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
9196 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
9197 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
9198 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
9199 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
9200 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
9201 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
9202 case Graphic3d_StereoMode_Anaglyph :
9204 switch (aView->RenderingParams().AnaglyphFilter)
9206 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
9207 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
9208 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
9209 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
9210 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
9215 theDI << "Mode " << aMode << "\n";
9220 Handle(Graphic3d_Camera) aCamera;
9221 Graphic3d_RenderingParams* aParams = NULL;
9222 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
9223 if (!aView.IsNull())
9225 aParams = &aView->ChangeRenderingParams();
9226 aMode = aParams->StereoMode;
9227 aCamera = aView->Camera();
9230 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
9231 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
9233 Standard_CString anArg = theArgVec[anArgIter];
9234 TCollection_AsciiString aFlag (anArg);
9236 if (anUpdateTool.parseRedrawMode (aFlag))
9240 else if (aFlag == "0"
9243 if (++anArgIter < theArgNb)
9245 std::cout << "Error: wrong number of arguments!\n";
9249 if (!aCamera.IsNull()
9250 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
9252 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
9254 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
9257 else if (aFlag == "1"
9260 if (++anArgIter < theArgNb)
9262 std::cout << "Error: wrong number of arguments!\n";
9266 if (!aCamera.IsNull())
9268 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9270 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9273 else if (aFlag == "-reverse"
9274 || aFlag == "-reversed"
9275 || aFlag == "-swap")
9277 Standard_Boolean toEnable = Standard_True;
9278 if (++anArgIter < theArgNb
9279 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9283 aParams->ToReverseStereo = toEnable;
9285 else if (aFlag == "-noreverse"
9286 || aFlag == "-noswap")
9288 Standard_Boolean toDisable = Standard_True;
9289 if (++anArgIter < theArgNb
9290 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
9294 aParams->ToReverseStereo = !toDisable;
9296 else if (aFlag == "-mode"
9297 || aFlag == "-stereomode")
9299 if (++anArgIter >= theArgNb
9300 || !parseStereoMode (theArgVec[anArgIter], aMode))
9302 std::cout << "Error: syntax error at '" << anArg << "'\n";
9306 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9308 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9311 else if (aFlag == "-anaglyph"
9312 || aFlag == "-anaglyphfilter")
9314 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9315 if (++anArgIter >= theArgNb
9316 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
9318 std::cout << "Error: syntax error at '" << anArg << "'\n";
9322 aMode = Graphic3d_StereoMode_Anaglyph;
9323 aParams->AnaglyphFilter = aFilter;
9325 else if (parseStereoMode (anArg, aMode)) // short syntax
9327 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9329 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9334 std::cout << "Error: syntax error at '" << anArg << "'\n";
9339 if (!aView.IsNull())
9341 aParams->StereoMode = aMode;
9342 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9347 //===============================================================================================
9348 //function : VDefaults
9350 //===============================================================================================
9351 static int VDefaults (Draw_Interpretor& theDi,
9352 Standard_Integer theArgsNb,
9353 const char** theArgVec)
9355 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
9358 std::cerr << "No active viewer!\n";
9362 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
9365 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
9367 theDi << "DeflType: relative\n"
9368 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
9372 theDi << "DeflType: absolute\n"
9373 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
9375 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
9376 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
9380 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
9382 TCollection_AsciiString anArg (theArgVec[anArgIter]);
9384 if (anArg == "-ABSDEFL"
9385 || anArg == "-ABSOLUTEDEFLECTION"
9387 || anArg == "-DEFLECTION")
9389 if (++anArgIter >= theArgsNb)
9391 std::cout << "Error: wrong syntax at " << anArg << "\n";
9394 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
9395 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
9397 else if (anArg == "-RELDEFL"
9398 || anArg == "-RELATIVEDEFLECTION"
9399 || anArg == "-DEVCOEFF"
9400 || anArg == "-DEVIATIONCOEFF"
9401 || anArg == "-DEVIATIONCOEFFICIENT")
9403 if (++anArgIter >= theArgsNb)
9405 std::cout << "Error: wrong syntax at " << anArg << "\n";
9408 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
9409 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
9411 else if (anArg == "-ANGDEFL"
9412 || anArg == "-ANGULARDEFL"
9413 || anArg == "-ANGULARDEFLECTION")
9415 if (++anArgIter >= theArgsNb)
9417 std::cout << "Error: wrong syntax at " << anArg << "\n";
9420 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
9421 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
9423 else if (anArg == "-AUTOTR"
9424 || anArg == "-AUTOTRIANG"
9425 || anArg == "-AUTOTRIANGULATION")
9427 if (++anArgIter >= theArgsNb)
9429 std::cout << "Error: wrong syntax at " << anArg << "\n";
9432 TCollection_AsciiString aValue (theArgVec[anArgIter]);
9437 aDefParams->SetAutoTriangulation (Standard_True);
9439 else if (aValue == "off"
9442 aDefParams->SetAutoTriangulation (Standard_False);
9447 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
9454 //! Auxiliary method
9455 inline void addLight (const Handle(V3d_Light)& theLightNew,
9456 const Graphic3d_ZLayerId theLayer,
9457 const Standard_Boolean theIsGlobal)
9459 if (theLightNew.IsNull())
9464 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9465 if (theLayer == Graphic3d_ZLayerId_UNKNOWN)
9467 aViewer->AddLight (theLightNew);
9470 aViewer->SetLightOn (theLightNew);
9474 ViewerTest::CurrentView()->SetLightOn (theLightNew);
9479 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer);
9480 if (aSettings.Lights().IsNull())
9482 aSettings.SetLights (new Graphic3d_LightSet());
9484 aSettings.Lights()->Add (theLightNew);
9485 aViewer->SetZLayerSettings (theLayer, aSettings);
9489 //! Auxiliary method
9490 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
9492 TCollection_AsciiString anArgNextCase (theArgNext);
9493 anArgNextCase.UpperCase();
9494 if (anArgNextCase.Length() > 5
9495 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
9497 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
9501 return theArgNext.IntegerValue();
9505 //===============================================================================================
9508 //===============================================================================================
9509 static int VLight (Draw_Interpretor& theDi,
9510 Standard_Integer theArgsNb,
9511 const char** theArgVec)
9513 Handle(V3d_View) aView = ViewerTest::CurrentView();
9514 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9516 || aViewer.IsNull())
9518 std::cerr << "No active viewer!\n";
9522 Standard_Real anXYZ[3] = {};
9523 Standard_Real anAtten[2] = {};
9526 // print lights info
9527 Standard_Integer aLightId = 0;
9528 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
9530 Handle(V3d_Light) aLight = aLightIter.Value();
9531 const Quantity_Color aColor = aLight->Color();
9532 theDi << "Light #" << aLightId
9533 << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "")
9534 << " [" << aLight->GetId() << "]" << "\n";
9535 switch (aLight->Type())
9539 theDi << " Type: Ambient\n";
9540 theDi << " Intensity: " << aLight->Intensity() << "\n";
9543 case V3d_DIRECTIONAL:
9545 theDi << " Type: Directional\n";
9546 theDi << " Intensity: " << aLight->Intensity() << "\n";
9547 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9548 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
9549 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
9550 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9553 case V3d_POSITIONAL:
9555 theDi << " Type: Positional\n";
9556 theDi << " Intensity: " << aLight->Intensity() << "\n";
9557 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9558 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
9559 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9560 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9561 aLight->Attenuation (anAtten[0], anAtten[1]);
9562 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
9567 theDi << " Type: Spot\n";
9568 theDi << " Intensity: " << aLight->Intensity() << "\n";
9569 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9570 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9571 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9572 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
9573 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9574 aLight->Attenuation (anAtten[0], anAtten[1]);
9575 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
9576 theDi << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n";
9577 theDi << " Exponent: " << aLight->Concentration() << "\n";
9582 theDi << " Type: UNKNOWN\n";
9586 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n";
9590 Handle(V3d_Light) aLightNew;
9591 Handle(V3d_Light) aLightOld;
9592 Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN;
9593 Standard_Boolean isGlobal = Standard_True;
9594 Standard_Boolean toCreate = Standard_False;
9595 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
9596 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
9598 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
9600 TCollection_AsciiString aName, aValue;
9601 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
9602 TCollection_AsciiString anArgCase (anArg);
9603 anArgCase.UpperCase();
9604 if (anUpdateTool.parseRedrawMode (anArg))
9609 if (anArgCase.IsEqual ("NEW")
9610 || anArgCase.IsEqual ("ADD")
9611 || anArgCase.IsEqual ("CREATE")
9612 || anArgCase.IsEqual ("-NEW")
9613 || anArgCase.IsEqual ("-ADD")
9614 || anArgCase.IsEqual ("-CREATE"))
9616 toCreate = Standard_True;
9618 else if (anArgCase.IsEqual ("-LAYER")
9619 || anArgCase.IsEqual ("-ZLAYER"))
9621 if (++anArgIt >= theArgsNb)
9623 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9627 TCollection_AsciiString aValStr (theArgVec[anArgIt]);
9628 aValStr.LowerCase();
9629 if (aValStr == "default"
9630 || aValStr == "def")
9632 aLayer = Graphic3d_ZLayerId_Default;
9634 else if (aValStr == "top")
9636 aLayer = Graphic3d_ZLayerId_Top;
9638 else if (aValStr == "topmost")
9640 aLayer = Graphic3d_ZLayerId_Topmost;
9642 else if (aValStr == "toposd"
9643 || aValStr == "osd")
9645 aLayer = Graphic3d_ZLayerId_TopOSD;
9647 else if (aValStr == "botosd"
9648 || aValStr == "bottom")
9650 aLayer = Graphic3d_ZLayerId_BotOSD;
9652 else if (aValStr.IsIntegerValue())
9654 aLayer = Draw::Atoi (theArgVec[anArgIt]);
9658 std::cout << "Wrong syntax at argument '" << anArg << "'!\n";
9662 else if (anArgCase.IsEqual ("GLOB")
9663 || anArgCase.IsEqual ("GLOBAL")
9664 || anArgCase.IsEqual ("-GLOB")
9665 || anArgCase.IsEqual ("-GLOBAL"))
9667 isGlobal = Standard_True;
9669 else if (anArgCase.IsEqual ("LOC")
9670 || anArgCase.IsEqual ("LOCAL")
9671 || anArgCase.IsEqual ("-LOC")
9672 || anArgCase.IsEqual ("-LOCAL"))
9674 isGlobal = Standard_False;
9676 else if (anArgCase.IsEqual ("DEF")
9677 || anArgCase.IsEqual ("DEFAULTS")
9678 || anArgCase.IsEqual ("-DEF")
9679 || anArgCase.IsEqual ("-DEFAULTS"))
9681 toCreate = Standard_False;
9682 aViewer->SetDefaultLights();
9684 else if (anArgCase.IsEqual ("CLR")
9685 || anArgCase.IsEqual ("CLEAR")
9686 || anArgCase.IsEqual ("-CLR")
9687 || anArgCase.IsEqual ("-CLEAR"))
9689 toCreate = Standard_False;
9691 TColStd_SequenceOfInteger aLayers;
9692 aViewer->GetAllZLayers (aLayers);
9693 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
9695 if (aLayeriter.Value() == aLayer
9696 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
9698 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
9699 aSettings.SetLights (Handle(Graphic3d_LightSet)());
9700 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
9701 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
9708 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
9710 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
9712 Handle(V3d_Light) aLight = aLightIter.Value();
9713 aViewer->DelLight (aLight);
9714 aLightIter = aView->ActiveLightIterator();
9718 else if (anArgCase.IsEqual ("AMB")
9719 || anArgCase.IsEqual ("AMBIENT")
9720 || anArgCase.IsEqual ("AMBLIGHT"))
9724 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9728 addLight (aLightNew, aLayer, isGlobal);
9729 toCreate = Standard_False;
9730 aLightNew = new V3d_AmbientLight();
9732 else if (anArgCase.IsEqual ("DIRECTIONAL")
9733 || anArgCase.IsEqual ("DIRLIGHT"))
9737 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9741 addLight (aLightNew, aLayer, isGlobal);
9742 toCreate = Standard_False;
9743 aLightNew = new V3d_DirectionalLight();
9745 else if (anArgCase.IsEqual ("SPOT")
9746 || anArgCase.IsEqual ("SPOTLIGHT"))
9750 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9754 addLight (aLightNew, aLayer, isGlobal);
9755 toCreate = Standard_False;
9756 aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0));
9758 else if (anArgCase.IsEqual ("POSLIGHT")
9759 || anArgCase.IsEqual ("POSITIONAL"))
9763 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9767 addLight (aLightNew, aLayer, isGlobal);
9768 toCreate = Standard_False;
9769 aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0));
9771 else if (anArgCase.IsEqual ("CHANGE")
9772 || anArgCase.IsEqual ("-CHANGE"))
9774 if (++anArgIt >= theArgsNb)
9776 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9780 addLight (aLightNew, aLayer, isGlobal);
9781 aLightNew.Nullify();
9782 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
9783 Standard_Integer aLightIt = 0;
9784 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
9786 if (aLightIt == aLightId)
9788 aLightOld = aLightIter.Value();
9793 if (aLightOld.IsNull())
9795 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
9799 else if (anArgCase.IsEqual ("DEL")
9800 || anArgCase.IsEqual ("DELETE")
9801 || anArgCase.IsEqual ("-DEL")
9802 || anArgCase.IsEqual ("-DELETE"))
9804 Handle(V3d_Light) aLightDel;
9805 if (++anArgIt >= theArgsNb)
9807 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9811 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
9812 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
9813 Standard_Integer aLightIt = 0;
9814 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
9816 aLightDel = aLightIter.Value();
9817 if (aLightIt == aLightDelId)
9822 if (aLightDel.IsNull())
9827 TColStd_SequenceOfInteger aLayers;
9828 aViewer->GetAllZLayers (aLayers);
9829 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
9831 if (aLayeriter.Value() == aLayer
9832 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
9834 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
9835 if (!aSettings.Lights().IsNull())
9837 aSettings.Lights()->Remove (aLightDel);
9838 if (aSettings.Lights()->IsEmpty())
9840 aSettings.SetLights (Handle(Graphic3d_LightSet)());
9843 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
9844 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
9851 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
9853 aViewer->DelLight (aLightDel);
9856 else if (anArgCase.IsEqual ("COLOR")
9857 || anArgCase.IsEqual ("COLOUR")
9858 || anArgCase.IsEqual ("-COLOR")
9859 || anArgCase.IsEqual ("-COLOUR"))
9861 if (++anArgIt >= theArgsNb
9862 || aLightCurr.IsNull())
9864 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9868 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
9869 anArgNext.UpperCase();
9870 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
9871 aLightCurr->SetColor (aColor);
9873 else if (anArgCase.IsEqual ("POS")
9874 || anArgCase.IsEqual ("POSITION")
9875 || anArgCase.IsEqual ("-POS")
9876 || anArgCase.IsEqual ("-POSITION"))
9878 if ((anArgIt + 3) >= theArgsNb
9879 || aLightCurr.IsNull()
9880 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
9881 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
9883 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9887 anXYZ[0] = Atof (theArgVec[++anArgIt]);
9888 anXYZ[1] = Atof (theArgVec[++anArgIt]);
9889 anXYZ[2] = Atof (theArgVec[++anArgIt]);
9890 aLightCurr->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
9892 else if (anArgCase.IsEqual ("DIR")
9893 || anArgCase.IsEqual ("DIRECTION")
9894 || anArgCase.IsEqual ("-DIR")
9895 || anArgCase.IsEqual ("-DIRECTION"))
9897 if ((anArgIt + 3) >= theArgsNb
9898 || aLightCurr.IsNull()
9899 || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL
9900 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
9902 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9906 anXYZ[0] = Atof (theArgVec[++anArgIt]);
9907 anXYZ[1] = Atof (theArgVec[++anArgIt]);
9908 anXYZ[2] = Atof (theArgVec[++anArgIt]);
9909 aLightCurr->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
9911 else if (anArgCase.IsEqual ("SM")
9912 || anArgCase.IsEqual ("SMOOTHNESS")
9913 || anArgCase.IsEqual ("-SM")
9914 || anArgCase.IsEqual ("-SMOOTHNESS"))
9916 if (++anArgIt >= theArgsNb
9917 || aLightCurr.IsNull())
9919 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9923 Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
9924 if (Abs (aSmoothness) <= ShortRealEpsilon())
9926 aLightCurr->SetIntensity (1.f);
9928 else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon())
9930 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
9934 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
9935 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
9938 if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL)
9940 aLightCurr->SetSmoothRadius (aSmoothness);
9942 else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
9944 aLightCurr->SetSmoothAngle (aSmoothness);
9947 else if (anArgCase.IsEqual ("INT")
9948 || anArgCase.IsEqual ("INTENSITY")
9949 || anArgCase.IsEqual ("-INT")
9950 || anArgCase.IsEqual ("-INTENSITY"))
9952 if (++anArgIt >= theArgsNb
9953 || aLightCurr.IsNull())
9955 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9959 Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
9960 aLightCurr->SetIntensity (aIntensity);
9962 else if (anArgCase.IsEqual ("ANG")
9963 || anArgCase.IsEqual ("ANGLE")
9964 || anArgCase.IsEqual ("-ANG")
9965 || anArgCase.IsEqual ("-ANGLE"))
9967 if (++anArgIt >= theArgsNb
9968 || aLightCurr.IsNull()
9969 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
9971 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9975 Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
9976 aLightCurr->SetAngle (Standard_ShortReal (anAngle / 180.0 * M_PI));
9978 else if (anArgCase.IsEqual ("CONSTATTEN")
9979 || anArgCase.IsEqual ("CONSTATTENUATION")
9980 || anArgCase.IsEqual ("-CONSTATTEN")
9981 || anArgCase.IsEqual ("-CONSTATTENUATION"))
9983 if (++anArgIt >= theArgsNb
9984 || aLightCurr.IsNull()
9985 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
9986 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
9988 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9992 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
9993 anAtten[0] = Atof (theArgVec[anArgIt]);
9994 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
9996 else if (anArgCase.IsEqual ("LINATTEN")
9997 || anArgCase.IsEqual ("LINEARATTEN")
9998 || anArgCase.IsEqual ("LINEARATTENUATION")
9999 || anArgCase.IsEqual ("-LINATTEN")
10000 || anArgCase.IsEqual ("-LINEARATTEN")
10001 || anArgCase.IsEqual ("-LINEARATTENUATION"))
10003 if (++anArgIt >= theArgsNb
10004 || aLightCurr.IsNull()
10005 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10006 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
10008 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10012 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
10013 anAtten[1] = Atof (theArgVec[anArgIt]);
10014 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
10016 else if (anArgCase.IsEqual ("EXP")
10017 || anArgCase.IsEqual ("EXPONENT")
10018 || anArgCase.IsEqual ("SPOTEXP")
10019 || anArgCase.IsEqual ("SPOTEXPONENT")
10020 || anArgCase.IsEqual ("-EXP")
10021 || anArgCase.IsEqual ("-EXPONENT")
10022 || anArgCase.IsEqual ("-SPOTEXP")
10023 || anArgCase.IsEqual ("-SPOTEXPONENT"))
10025 if (++anArgIt >= theArgsNb
10026 || aLightCurr.IsNull()
10027 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
10029 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10033 aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt]));
10035 else if (anArgCase.IsEqual ("HEAD")
10036 || anArgCase.IsEqual ("HEADLIGHT")
10037 || anArgCase.IsEqual ("-HEAD")
10038 || anArgCase.IsEqual ("-HEADLIGHT"))
10040 if (aLightCurr.IsNull()
10041 || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
10043 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10047 Standard_Boolean isHeadLight = Standard_True;
10048 if (anArgIt + 1 < theArgsNb
10049 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight))
10053 aLightCurr->SetHeadlight (isHeadLight);
10057 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
10061 addLight (aLightNew, aLayer, isGlobal);
10065 //! Read Graphic3d_RenderingParams::PerfCounters flag.
10066 static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue,
10067 Standard_Boolean& theToReset,
10068 Graphic3d_RenderingParams::PerfCounters& theFlagsRem,
10069 Graphic3d_RenderingParams::PerfCounters& theFlagsAdd)
10071 Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE;
10072 TCollection_AsciiString aVal = theValue;
10073 Standard_Boolean toReverse = Standard_False;
10074 if (aVal == "none")
10076 theToReset = Standard_True;
10077 return Standard_True;
10079 else if (aVal.StartsWith ("-"))
10081 toReverse = Standard_True;
10082 aVal = aVal.SubString (2, aVal.Length());
10084 else if (aVal.StartsWith ("no"))
10086 toReverse = Standard_True;
10087 aVal = aVal.SubString (3, aVal.Length());
10089 else if (aVal.StartsWith ("+"))
10091 aVal = aVal.SubString (2, aVal.Length());
10095 theToReset = Standard_True;
10099 || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate;
10100 else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU;
10101 else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers;
10102 else if (aVal == "structs"
10103 || aVal == "structures"
10104 || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures;
10105 else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups;
10106 else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
10107 else if (aVal == "tris"
10108 || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles;
10109 else if (aVal == "pnts"
10110 || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points;
10111 else if (aVal == "mem"
10112 || aVal == "gpumem"
10113 || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem;
10114 else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic;
10115 else if (aVal == "extended"
10116 || aVal == "verbose"
10117 || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended;
10120 return Standard_False;
10125 theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag);
10129 theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag);
10131 return Standard_True;
10134 //! Read Graphic3d_RenderingParams::PerfCounters flags.
10135 static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue,
10136 Graphic3d_RenderingParams::PerfCounters& theFlags)
10138 TCollection_AsciiString aValue = theValue;
10139 Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE;
10140 Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE;
10141 Standard_Boolean toReset = Standard_False;
10144 Standard_Integer aSplitPos = aValue.Search ("|");
10145 if (aSplitPos <= 0)
10147 if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd))
10149 return Standard_False;
10153 theFlags = Graphic3d_RenderingParams::PerfCounters_NONE;
10155 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd);
10156 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem);
10157 return Standard_True;
10162 TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1);
10163 if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd))
10165 return Standard_False;
10168 aValue = aValue.SubString (aSplitPos + 1, aValue.Length());
10172 //=======================================================================
10173 //function : VRenderParams
10174 //purpose : Enables/disables rendering features
10175 //=======================================================================
10177 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
10178 Standard_Integer theArgNb,
10179 const char** theArgVec)
10181 Handle(V3d_View) aView = ViewerTest::CurrentView();
10182 if (aView.IsNull())
10184 std::cerr << "Error: no active viewer!\n";
10188 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
10189 TCollection_AsciiString aCmdName (theArgVec[0]);
10190 aCmdName.LowerCase();
10191 if (aCmdName == "vraytrace")
10195 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
10198 else if (theArgNb == 2)
10200 TCollection_AsciiString aValue (theArgVec[1]);
10201 aValue.LowerCase();
10205 aParams.Method = Graphic3d_RM_RAYTRACING;
10209 else if (aValue == "off"
10212 aParams.Method = Graphic3d_RM_RASTERIZATION;
10218 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
10224 std::cout << "Error: wrong number of arguments\n";
10231 theDI << "renderMode: ";
10232 switch (aParams.Method)
10234 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
10235 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
10238 theDI << "transparency: ";
10239 switch (aParams.TransparencyMethod)
10241 case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break;
10242 case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: "
10243 << TCollection_AsciiString (aParams.OitDepthFactor); break;
10246 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
10247 theDI << "rendScale: " << aParams.RenderResolutionScale << "\n";
10248 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
10249 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
10250 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
10251 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
10252 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
10253 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
10254 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
10255 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
10256 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
10257 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
10258 theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
10259 theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n";
10260 theDI << "shadingModel: ";
10261 switch (aView->ShadingModel())
10263 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
10264 case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break;
10265 case Graphic3d_TOSM_FACET: theDI << "flat"; break;
10266 case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break;
10267 case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break;
10270 theDI << "perfCounters:";
10271 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0)
10275 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
10279 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
10281 theDI << " structs";
10283 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0)
10285 theDI << " groups";
10287 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0)
10289 theDI << " arrays";
10291 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0)
10295 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
10299 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0)
10301 theDI << " gpumem";
10303 if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE)
10309 theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n";
10310 theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n";
10315 Standard_Boolean toPrint = Standard_False;
10316 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10317 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
10319 Standard_CString anArg (theArgVec[anArgIter]);
10320 TCollection_AsciiString aFlag (anArg);
10322 if (anUpdateTool.parseRedrawMode (aFlag))
10326 else if (aFlag == "-echo"
10327 || aFlag == "-print")
10329 toPrint = Standard_True;
10330 anUpdateTool.Invalidate();
10332 else if (aFlag == "-mode"
10333 || aFlag == "-rendermode"
10334 || aFlag == "-render_mode")
10338 switch (aParams.Method)
10340 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
10341 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
10347 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10351 else if (aFlag == "-ray"
10352 || aFlag == "-raytrace")
10356 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
10360 aParams.Method = Graphic3d_RM_RAYTRACING;
10362 else if (aFlag == "-rast"
10363 || aFlag == "-raster"
10364 || aFlag == "-rasterization")
10368 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
10372 aParams.Method = Graphic3d_RM_RASTERIZATION;
10374 else if (aFlag == "-msaa")
10378 theDI << aParams.NbMsaaSamples << " ";
10381 else if (++anArgIter >= theArgNb)
10383 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10387 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
10388 if (aNbSamples < 0)
10390 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
10395 aParams.NbMsaaSamples = aNbSamples;
10398 else if (aFlag == "-oit")
10402 if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
10404 theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " ";
10408 theDI << "off" << " ";
10412 else if (++anArgIter >= theArgNb)
10414 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10418 TCollection_AsciiString aParam = theArgVec[anArgIter];
10419 aParam.LowerCase();
10420 if (aParam.IsRealValue())
10422 const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
10423 if (aWeight < 0.f || aWeight > 1.f)
10425 std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n";
10429 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
10430 aParams.OitDepthFactor = aWeight;
10432 else if (aParam == "off")
10434 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED;
10438 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10442 else if (aFlag == "-depthprepass")
10446 theDI << (aParams.ToEnableDepthPrepass ? "on " : "off ");
10449 aParams.ToEnableDepthPrepass = Standard_True;
10450 if (anArgIter + 1 < theArgNb
10451 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass))
10456 else if (aFlag == "-samplealphatocoverage"
10457 || aFlag == "-alphatocoverage")
10461 theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off ");
10464 aParams.ToEnableAlphaToCoverage = Standard_True;
10465 if (anArgIter + 1 < theArgNb
10466 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage))
10471 else if (aFlag == "-rendscale"
10472 || aFlag == "-renderscale"
10473 || aFlag == "-renderresolutionscale")
10477 theDI << aParams.RenderResolutionScale << " ";
10480 else if (++anArgIter >= theArgNb)
10482 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10486 const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
10489 std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n";
10494 aParams.RenderResolutionScale = Standard_ShortReal(aScale);
10497 else if (aFlag == "-raydepth"
10498 || aFlag == "-ray_depth")
10502 theDI << aParams.RaytracingDepth << " ";
10505 else if (++anArgIter >= theArgNb)
10507 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10511 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
10513 // We allow RaytracingDepth be more than 10 in case of GI enabled
10514 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
10516 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
10521 aParams.RaytracingDepth = aDepth;
10524 else if (aFlag == "-shad"
10525 || aFlag == "-shadows")
10529 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
10533 Standard_Boolean toEnable = Standard_True;
10534 if (++anArgIter < theArgNb
10535 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10539 aParams.IsShadowEnabled = toEnable;
10541 else if (aFlag == "-refl"
10542 || aFlag == "-reflections")
10546 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
10550 Standard_Boolean toEnable = Standard_True;
10551 if (++anArgIter < theArgNb
10552 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10556 aParams.IsReflectionEnabled = toEnable;
10558 else if (aFlag == "-fsaa")
10562 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
10566 Standard_Boolean toEnable = Standard_True;
10567 if (++anArgIter < theArgNb
10568 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10572 aParams.IsAntialiasingEnabled = toEnable;
10574 else if (aFlag == "-gleam")
10578 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
10582 Standard_Boolean toEnable = Standard_True;
10583 if (++anArgIter < theArgNb
10584 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10588 aParams.IsTransparentShadowEnabled = toEnable;
10590 else if (aFlag == "-gi")
10594 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
10598 Standard_Boolean toEnable = Standard_True;
10599 if (++anArgIter < theArgNb
10600 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10604 aParams.IsGlobalIlluminationEnabled = toEnable;
10607 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
10610 else if (aFlag == "-blockedrng"
10611 || aFlag == "-brng")
10615 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
10619 Standard_Boolean toEnable = Standard_True;
10620 if (++anArgIter < theArgNb
10621 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10625 aParams.CoherentPathTracingMode = toEnable;
10627 else if (aFlag == "-maxrad")
10631 theDI << aParams.RadianceClampingValue << " ";
10634 else if (++anArgIter >= theArgNb)
10636 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10640 const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
10641 if (!aMaxRadStr.IsRealValue())
10643 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10647 const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
10648 if (aMaxRadiance <= 0.0)
10650 std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n";
10655 aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
10658 else if (aFlag == "-iss")
10662 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
10666 Standard_Boolean toEnable = Standard_True;
10667 if (++anArgIter < theArgNb
10668 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10672 aParams.AdaptiveScreenSampling = toEnable;
10674 else if (aFlag == "-issd")
10678 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
10682 Standard_Boolean toEnable = Standard_True;
10683 if (++anArgIter < theArgNb
10684 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10688 aParams.ShowSamplingTiles = toEnable;
10690 else if (aFlag == "-nbtiles")
10694 theDI << aParams.NbRayTracingTiles << " ";
10697 else if (++anArgIter >= theArgNb)
10699 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10703 const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]);
10707 std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n";
10708 std::cerr << "Specify value in range [64, 1024].\n";
10713 aParams.NbRayTracingTiles = aNbTiles;
10716 else if (aFlag == "-env")
10720 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
10724 Standard_Boolean toEnable = Standard_True;
10725 if (++anArgIter < theArgNb
10726 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10730 aParams.UseEnvironmentMapBackground = toEnable;
10732 else if (aFlag == "-twoside")
10736 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
10740 Standard_Boolean toEnable = Standard_True;
10741 if (++anArgIter < theArgNb
10742 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10746 aParams.TwoSidedBsdfModels = toEnable;
10748 else if (aFlag == "-shademodel"
10749 || aFlag == "-shadingmodel"
10750 || aFlag == "-shading")
10754 switch (aView->ShadingModel())
10756 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
10757 case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break;
10758 case Graphic3d_TOSM_FACET: theDI << "flat "; break;
10759 case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break;
10760 case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break;
10765 if (++anArgIter >= theArgNb)
10767 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10770 Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT;
10771 if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel)
10772 && aModel != Graphic3d_TOSM_DEFAULT)
10774 aView->SetShadingModel (aModel);
10778 std::cout << "Error: unknown shading model '" << theArgVec[anArgIter] << "'\n";
10782 else if (aFlag == "-resolution")
10784 if (++anArgIter >= theArgNb)
10786 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10790 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
10791 if (aResolution.IsIntegerValue())
10793 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
10797 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10801 else if (aFlag == "-rebuildglsl"
10802 || aFlag == "-rebuild")
10806 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
10810 Standard_Boolean toEnable = Standard_True;
10811 if (++anArgIter < theArgNb
10812 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10816 aParams.RebuildRayTracingShaders = toEnable;
10818 else if (aFlag == "-focal")
10820 if (++anArgIter >= theArgNb)
10822 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10826 TCollection_AsciiString aParam (theArgVec[anArgIter]);
10827 if (aParam.IsRealValue())
10829 float aFocalDist = static_cast<float> (aParam.RealValue());
10830 if (aFocalDist < 0)
10832 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
10835 aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist;
10839 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10843 else if (aFlag == "-aperture")
10845 if (++anArgIter >= theArgNb)
10847 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10851 TCollection_AsciiString aParam(theArgVec[anArgIter]);
10852 if (aParam.IsRealValue())
10854 float aApertureSize = static_cast<float> (aParam.RealValue());
10855 if (aApertureSize < 0)
10857 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
10860 aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize;
10864 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10868 else if (aFlag == "-exposure")
10870 if (++anArgIter >= theArgNb)
10872 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10876 TCollection_AsciiString anExposure (theArgVec[anArgIter]);
10877 if (anExposure.IsRealValue())
10879 aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
10883 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10887 else if (aFlag == "-whitepoint")
10889 if (++anArgIter >= theArgNb)
10891 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10895 TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
10896 if (aWhitePoint.IsRealValue())
10898 aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
10902 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10906 else if (aFlag == "-tonemapping")
10908 if (++anArgIter >= theArgNb)
10910 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10914 TCollection_AsciiString aMode (theArgVec[anArgIter]);
10917 if (aMode == "disabled")
10919 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled;
10921 else if (aMode == "filmic")
10923 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;
10927 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10931 else if (aFlag == "-performancestats"
10932 || aFlag == "-performancecounters"
10933 || aFlag == "-perfstats"
10934 || aFlag == "-perfcounters"
10935 || aFlag == "-stats")
10937 if (++anArgIter >= theArgNb)
10939 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10943 TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]);
10944 aFlagsStr.LowerCase();
10945 Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats;
10946 if (!convertToPerfStatsFlags (aFlagsStr, aFlags))
10948 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10951 aView->ChangeRenderingParams().CollectedStats = aFlags;
10952 aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE;
10954 else if (aFlag == "-perfupdateinterval"
10955 || aFlag == "-statsupdateinterval")
10957 if (++anArgIter >= theArgNb)
10959 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10962 aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
10966 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
10974 //=======================================================================
10975 //function : VProgressiveMode
10977 //=======================================================================
10978 #if defined(_WIN32)
10979 static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
10980 Standard_Integer /*theNbArgs*/,
10981 const char** /*theArgs*/)
10983 Handle(V3d_View) aView = ViewerTest::CurrentView();
10984 if (aView.IsNull())
10986 std::cerr << "Error: no active viewer!\n";
10990 std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
10996 Standard_Boolean toExit = Standard_False;
10999 while (PeekMessageW (&aMsg, NULL, 0, 0, PM_REMOVE))
11001 if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
11003 toExit = Standard_True;
11006 TranslateMessage (&aMsg);
11007 DispatchMessageW (&aMsg);
11020 //=======================================================================
11021 //function : VFrustumCulling
11022 //purpose : enables/disables view volume's culling.
11023 //=======================================================================
11024 static int VFrustumCulling (Draw_Interpretor& theDI,
11025 Standard_Integer theArgNb,
11026 const char** theArgVec)
11028 Handle(V3d_View) aView = ViewerTest::CurrentView();
11029 if (aView.IsNull())
11031 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
11037 theDI << (aView->IsCullingEnabled() ? "on" : "off");
11040 else if (theArgNb != 2)
11042 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
11046 TCollection_AsciiString aModeStr (theArgVec[1]);
11047 aModeStr.LowerCase();
11048 Standard_Boolean toEnable = 0;
11049 if (aModeStr == "on")
11053 else if (aModeStr == "off")
11059 toEnable = Draw::Atoi (theArgVec[1]) != 0;
11062 aView->SetFrustumCulling (toEnable);
11067 //=======================================================================
11068 //function : VXRotate
11070 //=======================================================================
11071 static Standard_Integer VXRotate (Draw_Interpretor& di,
11072 Standard_Integer argc,
11073 const char ** argv)
11075 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
11076 if (aContext.IsNull())
11078 di << argv[0] << "ERROR : use 'vinit' command before \n";
11084 di << "ERROR : Usage : " << argv[0] << " name angle\n";
11088 TCollection_AsciiString aName (argv[1]);
11089 Standard_Real anAngle = Draw::Atof (argv[2]);
11092 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
11093 Handle(AIS_InteractiveObject) anIObj;
11094 if (!aMap.Find2 (aName, anIObj))
11096 di << "Use 'vdisplay' before\n";
11100 gp_Trsf aTransform;
11101 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
11102 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
11104 aContext->SetLocation (anIObj, aTransform);
11105 aContext->UpdateCurrentViewer();
11109 //===============================================================================================
11110 //class : ViewerTest_AISManipulator
11111 //purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances
11112 //===============================================================================================
11113 DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
11115 class ViewerTest_AISManipulator : public AIS_Manipulator
11119 ViewerTest_AISManipulator() : AIS_Manipulator()
11121 GetMapOfAISManipulators().Add (this);
11124 virtual ~ViewerTest_AISManipulator()
11126 GetMapOfAISManipulators().Remove (this);
11129 DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
11132 IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
11133 IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
11135 //===============================================================================================
11136 //function : VManipulator
11138 //===============================================================================================
11139 static int VManipulator (Draw_Interpretor& theDi,
11140 Standard_Integer theArgsNb,
11141 const char** theArgVec)
11143 Handle(V3d_View) aView = ViewerTest::CurrentView();
11144 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
11145 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
11147 || aViewer.IsNull())
11149 std::cerr << "No active viewer!\n";
11153 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
11154 Standard_Integer anArgIter = 1;
11155 for (; anArgIter < theArgsNb; ++anArgIter)
11157 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
11160 ViewerTest_CmdParser aCmd;
11161 aCmd.AddDescription ("Manages manipulator for interactive objects:");
11162 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
11163 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
11164 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
11165 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
11166 aCmd.AddOption ("detach", "... - detach manipulator");
11168 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
11169 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
11170 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
11172 aCmd.AddOption ("move", "... x y z - move object");
11173 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
11174 aCmd.AddOption ("scale", "... factor - scale object");
11176 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
11177 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
11178 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
11179 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
11180 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
11181 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
11182 aCmd.AddOption ("size", "... size - set size of manipulator");
11183 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
11185 aCmd.Parse (theArgsNb, theArgVec);
11187 if (aCmd.HasOption ("help"))
11189 theDi.PrintHelp (theArgVec[0]);
11193 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
11195 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
11197 if (aName.IsEmpty())
11199 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
11203 // ----------------------------------
11204 // detach existing manipulator object
11205 // ----------------------------------
11207 if (aCmd.HasOption ("detach"))
11209 if (!aMapAIS.IsBound2 (aName))
11211 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
11215 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
11216 if (aManipulator.IsNull())
11218 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
11222 aManipulator->Detach();
11223 aMapAIS.UnBind2 (aName);
11224 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True);
11229 // -----------------------------------------------
11230 // find or create manipulator if it does not exist
11231 // -----------------------------------------------
11233 Handle(AIS_Manipulator) aManipulator;
11234 if (!aMapAIS.IsBound2 (aName))
11236 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
11238 aManipulator = new ViewerTest_AISManipulator();
11239 aMapAIS.Bind (aManipulator, aName);
11243 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
11244 if (aManipulator.IsNull())
11246 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
11251 // -----------------------------------------
11252 // change properties of manipulator instance
11253 // -----------------------------------------
11255 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
11257 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
11259 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
11261 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
11263 if (aCmd.HasOption ("followRotation", 1, Standard_True))
11265 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
11267 if (aCmd.HasOption ("gap", 1, Standard_True))
11269 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
11271 if (aCmd.HasOption ("part", 3, Standard_True))
11273 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
11274 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
11275 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
11276 if (aMode < 1 || aMode > 3)
11278 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 3].\n";
11282 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
11284 if (aCmd.HasOption ("pos", 3, Standard_True))
11286 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
11287 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
11288 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
11290 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
11292 if (aCmd.HasOption ("size", 1, Standard_True))
11294 aManipulator->SetSize (aCmd.ArgFloat ("size"));
11296 if (aCmd.HasOption ("zoomable", 1, Standard_True))
11298 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
11300 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
11302 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
11303 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
11307 // ---------------------------------------------------
11308 // attach, detach or access manipulator from an object
11309 // ---------------------------------------------------
11311 if (aCmd.HasOption ("attach"))
11313 // Find an object and attach manipulator to it
11314 if (!aCmd.HasOption ("attach", 1, Standard_True))
11319 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
11320 Handle(AIS_InteractiveObject) anObject;
11321 if (!aMapAIS.Find2 (anObjName, anObject))
11323 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
11327 for (ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators()); anIt.More(); anIt.Next())
11329 if (anIt.Value()->IsAttached()
11330 && anIt.Value()->Object() == anObject)
11332 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
11337 AIS_Manipulator::OptionsForAttach anOptions;
11338 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
11340 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
11342 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
11344 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
11346 if (aCmd.HasOption ("enableModes", 1, Standard_True))
11348 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
11351 aManipulator->Attach (anObject, anOptions);
11354 // --------------------------------------
11355 // apply transformation using manipulator
11356 // --------------------------------------
11358 if (aCmd.HasOption ("startTransform", 2, Standard_True))
11360 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
11362 if (aCmd.HasOption ("transform", 2, Standard_True))
11364 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
11366 if (aCmd.HasOption ("stopTransform"))
11368 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
11370 aManipulator->StopTransform (toApply);
11374 if (aCmd.HasOption ("move", 3, Standard_True))
11376 aT.SetTranslationPart (aCmd.ArgVec ("move"));
11378 if (aCmd.HasOption ("rotate", 7, Standard_True))
11380 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
11382 if (aCmd.HasOption ("scale", 1))
11384 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
11387 if (aT.Form() != gp_Identity)
11389 aManipulator->Transform (aT);
11392 ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True);
11397 //===============================================================================================
11398 //function : VSelectionProperties
11400 //===============================================================================================
11401 static int VSelectionProperties (Draw_Interpretor& theDi,
11402 Standard_Integer theArgsNb,
11403 const char** theArgVec)
11405 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
11408 std::cerr << "No active viewer!\n";
11412 if (TCollection_AsciiString (theArgVec[0]) == "vhighlightselected")
11414 // handle obsolete alias
11415 bool toEnable = true;
11418 theDi << (aCtx->ToHilightSelected() ? "on" : "off");
11421 else if (theArgsNb != 2
11422 || !ViewerTest::ParseOnOff (theArgVec[1], toEnable))
11424 std::cout << "Syntax error: wrong number of parameters.";
11427 if (toEnable != aCtx->ToHilightSelected())
11429 aCtx->ClearDetected();
11430 aCtx->SetToHilightSelected (toEnable);
11435 Standard_Boolean toPrint = theArgsNb == 1;
11436 Standard_Boolean toRedraw = Standard_False;
11437 Standard_Integer anArgIter = 1;
11438 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
11439 if (anArgIter < theArgsNb)
11441 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
11442 anArgFirst.LowerCase();
11444 if (anArgFirst == "dynhighlight"
11445 || anArgFirst == "dynhilight"
11446 || anArgFirst == "dynamichighlight"
11447 || anArgFirst == "dynamichilight")
11449 aType = Prs3d_TypeOfHighlight_Dynamic;
11451 else if (anArgFirst == "localdynhighlight"
11452 || anArgFirst == "localdynhilight"
11453 || anArgFirst == "localdynamichighlight"
11454 || anArgFirst == "localdynamichilight")
11456 aType = Prs3d_TypeOfHighlight_LocalDynamic;
11458 else if (anArgFirst == "selhighlight"
11459 || anArgFirst == "selhilight"
11460 || anArgFirst == "selectedhighlight"
11461 || anArgFirst == "selectedhilight")
11463 aType = Prs3d_TypeOfHighlight_Selected;
11465 else if (anArgFirst == "localselhighlight"
11466 || anArgFirst == "localselhilight"
11467 || anArgFirst == "localselectedhighlight"
11468 || anArgFirst == "localselectedhilight")
11470 aType = Prs3d_TypeOfHighlight_LocalSelected;
11477 for (; anArgIter < theArgsNb; ++anArgIter)
11479 TCollection_AsciiString anArg (theArgVec[anArgIter]);
11481 if (anArg == "-help")
11483 theDi.PrintHelp (theArgVec[0]);
11486 else if (anArg == "-print")
11488 toPrint = Standard_True;
11490 else if (anArg == "-autoactivate")
11492 Standard_Boolean toEnable = Standard_True;
11493 if (anArgIter + 1 < theArgsNb
11494 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
11498 aCtx->SetAutoActivateSelection (toEnable);
11500 else if (anArg == "-automatichighlight"
11501 || anArg == "-automatichilight"
11502 || anArg == "-autohighlight"
11503 || anArg == "-autohilight")
11505 Standard_Boolean toEnable = Standard_True;
11506 if (anArgIter + 1 < theArgsNb
11507 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
11511 aCtx->ClearSelected (false);
11512 aCtx->ClearDetected();
11513 aCtx->SetAutomaticHilight (toEnable);
11516 else if (anArg == "-highlightselected"
11517 || anArg == "-hilightselected")
11519 Standard_Boolean toEnable = Standard_True;
11520 if (anArgIter + 1 < theArgsNb
11521 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
11525 aCtx->ClearDetected();
11526 aCtx->SetToHilightSelected (toEnable);
11529 else if (anArg == "-pickstrategy"
11530 || anArg == "-pickingstrategy")
11532 if (++anArgIter >= theArgsNb)
11534 std::cout << "Syntax error: type of highlighting is undefined\n";
11538 SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
11539 TCollection_AsciiString aVal (theArgVec[anArgIter]);
11541 if (aVal == "first"
11542 || aVal == "firstaccepted"
11543 || aVal == "firstacceptable")
11545 aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
11547 else if (aVal == "topmost"
11548 || aVal == "onlyTopmost")
11550 aStrategy = SelectMgr_PickingStrategy_OnlyTopmost;
11554 std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n";
11558 aCtx->SetPickingStrategy (aStrategy);
11560 else if (anArg == "-pixtol"
11561 && anArgIter + 1 < theArgsNb)
11563 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
11565 else if ((anArg == "-mode"
11566 || anArg == "-dispmode")
11567 && anArgIter + 1 < theArgsNb)
11569 if (aType == Prs3d_TypeOfHighlight_None)
11571 std::cout << "Syntax error: type of highlighting is undefined\n";
11575 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
11576 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11577 aStyle->SetDisplayMode (aDispMode);
11578 toRedraw = Standard_True;
11580 else if (anArg == "-layer"
11581 && anArgIter + 1 < theArgsNb)
11583 if (aType == Prs3d_TypeOfHighlight_None)
11585 std::cout << "Syntax error: type of highlighting is undefined\n";
11589 const Standard_Integer aNewLayer = Draw::Atoi (theArgVec[++anArgIter]);
11590 if (aNewLayer != Graphic3d_ZLayerId_UNKNOWN)
11592 TColStd_SequenceOfInteger aLayers;
11593 aCtx->CurrentViewer()->GetAllZLayers (aLayers);
11594 if (std::find (aLayers.begin(), aLayers.end(), aNewLayer) == aLayers.end())
11596 std::cout << "Syntax error: Layer " << aNewLayer << " is undefined\n";
11601 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11602 aStyle->SetZLayer (aNewLayer);
11603 toRedraw = Standard_True;
11605 else if (anArg == "-hicolor"
11606 || anArg == "-selcolor"
11607 || anArg == "-color")
11609 if (anArg.StartsWith ("-hi"))
11611 aType = Prs3d_TypeOfHighlight_Dynamic;
11613 else if (anArg.StartsWith ("-sel"))
11615 aType = Prs3d_TypeOfHighlight_Selected;
11617 else if (aType == Prs3d_TypeOfHighlight_None)
11619 std::cout << "Syntax error: type of highlighting is undefined\n";
11623 Quantity_Color aColor;
11624 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1,
11625 theArgVec + anArgIter + 1,
11627 if (aNbParsed == 0)
11629 std::cout << "Syntax error: need more arguments.\n";
11632 anArgIter += aNbParsed;
11634 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11635 aStyle->SetColor (aColor);
11636 toRedraw = Standard_True;
11638 else if ((anArg == "-transp"
11639 || anArg == "-transparency"
11640 || anArg == "-hitransp"
11641 || anArg == "-seltransp"
11642 || anArg == "-hitransplocal"
11643 || anArg == "-seltransplocal")
11644 && anArgIter + 1 < theArgsNb)
11646 if (anArg.StartsWith ("-hi"))
11648 aType = Prs3d_TypeOfHighlight_Dynamic;
11650 else if (anArg.StartsWith ("-sel"))
11652 aType = Prs3d_TypeOfHighlight_Selected;
11654 else if (aType == Prs3d_TypeOfHighlight_None)
11656 std::cout << "Syntax error: type of highlighting is undefined\n";
11660 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
11661 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11662 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
11663 toRedraw = Standard_True;
11665 else if ((anArg == "-mat"
11666 || anArg == "-material")
11667 && anArgIter + 1 < theArgsNb)
11669 if (aType == Prs3d_TypeOfHighlight_None)
11671 std::cout << "Syntax error: type of highlighting is undefined\n";
11675 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11676 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
11677 if (aMatName != Graphic3d_NOM_DEFAULT)
11680 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
11681 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
11682 Graphic3d_MaterialAspect aMat (aMatName);
11683 aMat.SetColor (aStyle->Color());
11684 aMat.SetTransparency (aStyle->Transparency());
11685 anAspect->SetFrontMaterial (aMat);
11686 anAspect->SetInteriorColor (aStyle->Color());
11687 aStyle->SetBasicFillAreaAspect (anAspect);
11691 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
11693 toRedraw = Standard_True;
11697 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
11703 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
11704 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
11705 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
11706 theDi << "Auto-highlight : " << (aCtx->AutomaticHilight() ? "On" : "Off") << "\n";
11707 theDi << "Highlight selected : " << (aCtx->ToHilightSelected() ? "On" : "Off") << "\n";
11708 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
11709 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
11710 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
11711 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
11712 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
11713 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
11714 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
11715 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
11716 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
11719 if (aCtx->NbSelected() != 0 && toRedraw)
11721 aCtx->HilightSelected (Standard_True);
11727 //===============================================================================================
11728 //function : VDumpSelectionImage
11730 //===============================================================================================
11731 static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
11732 Standard_Integer theArgsNb,
11733 const char** theArgVec)
11737 std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
11741 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
11742 if (aContext.IsNull())
11744 std::cout << "Error: no active view.\n";
11748 TCollection_AsciiString aFile;
11749 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
11750 Image_Format anImgFormat = Image_Format_BGR;
11751 Standard_Integer aPickedIndex = 1;
11752 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
11754 TCollection_AsciiString aParam (theArgVec[anArgIter]);
11755 aParam.LowerCase();
11756 if (aParam == "-type")
11758 if (++anArgIter >= theArgsNb)
11760 std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n";
11764 TCollection_AsciiString aValue (theArgVec[anArgIter]);
11765 aValue.LowerCase();
11766 if (aValue == "depth"
11767 || aValue == "normdepth"
11768 || aValue == "normalizeddepth")
11770 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
11771 anImgFormat = Image_Format_GrayF;
11773 if (aValue == "depthinverted"
11774 || aValue == "normdepthinverted"
11775 || aValue == "normalizeddepthinverted"
11776 || aValue == "inverted")
11778 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
11779 anImgFormat = Image_Format_GrayF;
11781 else if (aValue == "unnormdepth"
11782 || aValue == "unnormalizeddepth")
11784 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
11785 anImgFormat = Image_Format_GrayF;
11787 else if (aValue == "objectcolor"
11788 || aValue == "object"
11789 || aValue == "color")
11791 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
11793 else if (aValue == "entitycolor"
11794 || aValue == "entity")
11796 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
11798 else if (aValue == "ownercolor"
11799 || aValue == "owner")
11801 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
11803 else if (aValue == "selectionmodecolor"
11804 || aValue == "selectionmode"
11805 || aValue == "selmodecolor"
11806 || aValue == "selmode")
11808 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
11811 else if (aParam == "-picked"
11812 || aParam == "-pickeddepth"
11813 || aParam == "-pickedindex")
11815 if (++anArgIter >= theArgsNb)
11817 std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n";
11821 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
11823 else if (aFile.IsEmpty())
11825 aFile = theArgVec[anArgIter];
11829 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n";
11833 if (aFile.IsEmpty())
11835 std::cout << "Syntax error: image file name is missing.\n";
11839 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
11840 Standard_Integer aWidth = 0, aHeight = 0;
11841 aView->Window()->Size (aWidth, aHeight);
11843 Image_AlienPixMap aPixMap;
11844 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
11846 std::cout << "Error: can't allocate image.\n";
11849 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
11851 std::cout << "Error: can't generate selection image.\n";
11854 if (!aPixMap.Save (aFile))
11856 std::cout << "Error: can't save selection image.\n";
11862 //=======================================================================
11863 //function : ViewerCommands
11865 //=======================================================================
11867 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
11870 const char *group = "ZeViewer";
11871 theCommands.Add("vinit",
11872 "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]"
11873 "\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]"
11874 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
11875 "\n\t\t: [-display displayName]"
11877 "\n\t\t: Creates new View window with specified name viewName."
11878 "\n\t\t: By default the new view is created in the viewer and in"
11879 "\n\t\t: graphic driver shared with active view."
11880 "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}"
11881 "\n\t\t: If driverName isn't specified the driver will be shared with active view."
11882 "\n\t\t: If viewerName isn't specified the viewer will be shared with active view."
11883 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
11884 "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]"
11885 "\n\t\t: Display name will be used within creation of graphic driver, when specified."
11887 "\n\t\t: -left, -top pixel position of left top corner of the window."
11888 "\n\t\t: -width, -height width and heigth of window respectively."
11889 "\n\t\t: -cloneActive floag to copy camera and dimensions of active view."
11890 "\n\t\t: -exitOnClose when specified, closing the view will exit application."
11891 "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape."
11892 "\n\t\t: -2d_mode when on, view will not react on rotate scene events"
11893 "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.",
11894 __FILE__,VInit,group);
11895 theCommands.Add("vclose" ,
11896 "[view_id [keep_context=0|1]]\n"
11897 "or vclose ALL - to remove all created views\n"
11898 " - removes view(viewer window) defined by its view_id.\n"
11899 " - keep_context: by default 0; if 1 and the last view is deleted"
11900 " the current context is not removed.",
11901 __FILE__,VClose,group);
11902 theCommands.Add("vactivate" ,
11904 " - activates view(viewer window) defined by its view_id",
11905 __FILE__,VActivate,group);
11906 theCommands.Add("vviewlist",
11907 "vviewlist [format={tree, long}]"
11908 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
11909 " - format: format of result output, if tree the output is a tree view;"
11910 "otherwise it's a list of full view names. By default format = tree",
11911 __FILE__,VViewList,group);
11912 theCommands.Add("vhelp" ,
11913 "vhelp : display help on the viewer commands",
11914 __FILE__,VHelp,group);
11915 theCommands.Add("vtop" ,
11916 "vtop or <T> : Top view. Orientation +X+Y" ,
11917 __FILE__,VTop,group);
11918 theCommands.Add("vbottom" ,
11919 "vbottom : Bottom view. Orientation +X-Y" ,
11920 __FILE__,VBottom,group);
11921 theCommands.Add("vleft" ,
11922 "vleft : Left view. Orientation -Y+Z" ,
11923 __FILE__,VLeft,group);
11924 theCommands.Add("vright" ,
11925 "vright : Right view. Orientation +Y+Z" ,
11926 __FILE__,VRight,group);
11927 theCommands.Add("vaxo" ,
11928 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
11929 __FILE__,VAxo,group);
11930 theCommands.Add("vfront" ,
11931 "vfront : Front view. Orientation +X+Z" ,
11932 __FILE__,VFront,group);
11933 theCommands.Add("vback" ,
11934 "vback : Back view. Orientation -X+Z" ,
11935 __FILE__,VBack,group);
11936 theCommands.Add("vpick" ,
11937 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
11939 theCommands.Add("vfit",
11940 "vfit or <F> [-selected] [-noupdate]"
11941 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
11942 __FILE__,VFit,group);
11943 theCommands.Add ("vfitarea",
11944 "vfitarea x1 y1 x2 y2"
11945 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
11946 "\n\t\t: Fit view to show area located between two points"
11947 "\n\t\t: given in world 2D or 3D corrdinates.",
11948 __FILE__, VFitArea, group);
11949 theCommands.Add ("vzfit", "vzfit [scale]\n"
11950 " Matches Z near, Z far view volume planes to the displayed objects.\n"
11951 " \"scale\" - specifies factor to scale computed z range.\n",
11952 __FILE__, VZFit, group);
11953 theCommands.Add("vrepaint",
11954 "vrepaint [-immediate]"
11955 "\n\t\t: force redraw",
11956 __FILE__,VRepaint,group);
11957 theCommands.Add("vclear",
11959 "\n\t\t: remove all the object from the viewer",
11960 __FILE__,VClear,group);
11961 theCommands.Add("vsetbg",
11962 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
11963 __FILE__,VSetBg,group);
11964 theCommands.Add("vsetbgmode",
11965 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
11966 __FILE__,VSetBgMode,group);
11967 theCommands.Add("vsetgradientbg",
11968 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
11969 __FILE__,VSetGradientBg,group);
11970 theCommands.Add("vsetgrbgmode",
11971 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
11972 __FILE__,VSetGradientBgMode,group);
11973 theCommands.Add("vsetcolorbg",
11974 "vsetcolorbg : vsetcolorbg r g b : Set background color",
11975 __FILE__,VSetColorBg,group);
11976 theCommands.Add("vsetdefaultbg",
11977 "vsetdefaultbg r g b\n"
11978 "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode"
11979 "\n\t\t: Set default viewer background fill color (flat/gradient).",
11980 __FILE__,VSetDefaultBg,group);
11981 theCommands.Add("vscale",
11982 "vscale : vscale X Y Z",
11983 __FILE__,VScale,group);
11984 theCommands.Add("vzbufftrihedron",
11985 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
11986 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
11987 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
11988 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
11989 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
11990 "\n\t\t: Displays a trihedron",
11991 __FILE__,VZBuffTrihedron,group);
11992 theCommands.Add("vrotate",
11993 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
11994 "\n : Option -mouseStart starts rotation according to the mouse position"
11995 "\n : Option -mouseMove continues rotation with angle computed"
11996 "\n : from last and new mouse position."
11997 "\n : vrotate AX AY AZ [X Y Z]",
11998 __FILE__,VRotate,group);
11999 theCommands.Add("vzoom",
12000 "vzoom : vzoom coef",
12001 __FILE__,VZoom,group);
12002 theCommands.Add("vpan",
12003 "vpan : vpan dx dy",
12004 __FILE__,VPan,group);
12005 theCommands.Add("vcolorscale",
12006 "vcolorscale name [-noupdate|-update] [-demo]"
12007 "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
12008 "\n\t\t: [-font HeightFont=20]"
12009 "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
12010 "\n\t\t: [-smoothTransition {on|off}=off]"
12011 "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
12012 "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
12013 "\n\t\t: [-textpos {left|right|center|none}=right]"
12014 "\n\t\t: [-labelAtBorder {on|off}=on]"
12015 "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
12016 "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
12017 "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
12018 "\n\t\t: [-xy Left=0 Bottom=0]"
12019 "\n\t\t: -demo - displays a color scale with demonstratio values"
12020 "\n\t\t: -colors - set colors for all intervals"
12021 "\n\t\t: -color - set color for specific interval"
12022 "\n\t\t: -textpos - horizontal label position relative to color scale bar"
12023 "\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
12024 "\n\t\t: at border means the value inbetween neighbor intervals,"
12025 "\n\t\t: at center means the center value within current interval"
12026 "\n\t\t: -labels - set labels for all intervals"
12027 "\n\t\t: -freeLabels - same as -labels but does not require"
12028 "\n\t\t: matching the number of intervals"
12029 "\n\t\t: -label - set label for specific interval"
12030 "\n\t\t: -title - set title"
12031 "\n\t\t: -reversed - setup smooth color transition between intervals"
12032 "\n\t\t: -smoothTransition - swap colorscale direction"
12033 "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values"
12034 __FILE__, VColorScale, group);
12035 theCommands.Add("vgraduatedtrihedron",
12036 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
12037 "\t[-namefont Name] [-valuesfont Name]\n"
12038 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
12039 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
12040 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
12041 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
12042 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
12043 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
12044 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
12045 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
12046 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
12047 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
12048 " - Displays or erases graduated trihedron"
12049 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
12050 " - namefont - font of axes names. Default: Arial\n"
12051 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
12052 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
12053 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
12054 " - valuesfont - font of axes values. Default: Arial\n"
12055 " - xcolor, ycolor, zcolor - color of axis and values\n"
12056 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
12057 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
12058 __FILE__,VGraduatedTrihedron,group);
12059 theCommands.Add("vtile" ,
12060 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
12061 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
12062 "\n\t\t: -totalSize the size of virtual bigger viewport"
12063 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
12064 "\n\t\t: -lowerLeft tile offset as lower left corner"
12065 "\n\t\t: -upperLeft tile offset as upper left corner",
12066 __FILE__, VTile, group);
12067 theCommands.Add("vzlayer",
12068 "vzlayer [layerId]"
12069 "\n\t\t: [-add|-delete|-get|-settings]"
12070 "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]"
12071 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
12072 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv}]"
12073 "\n\t\t: ZLayer list management:"
12074 "\n\t\t: -add add new z layer to viewer and print its id"
12075 "\n\t\t: -delete delete z layer"
12076 "\n\t\t: -get print sequence of z layers"
12077 "\n\t\t: -settings print status of z layer settings"
12078 "\n\t\t: -disable disables given setting"
12079 "\n\t\t: -enable enables given setting",
12080 __FILE__,VZLayer,group);
12081 theCommands.Add("vlayerline",
12082 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
12083 __FILE__,VLayerLine,group);
12084 theCommands.Add ("vgrid",
12085 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
12086 " : Mode - rectangular or circular"
12087 " : Type - lines or points",
12088 __FILE__, VGrid, group);
12089 theCommands.Add ("vpriviledgedplane",
12090 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
12091 "\n\t\t: Ox, Oy, Oz - plane origin"
12092 "\n\t\t: Nx, Ny, Nz - plane normal direction"
12093 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
12094 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
12095 __FILE__, VPriviledgedPlane, group);
12096 theCommands.Add ("vconvert",
12097 "vconvert v [Mode={window|view}]"
12098 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
12099 "\n\t\t: vconvert x y z [Mode={window|grid}]"
12100 "\n\t\t: window - convert to window coordinates, pixels"
12101 "\n\t\t: view - convert to view projection plane"
12102 "\n\t\t: grid - convert to model coordinates, given on grid"
12103 "\n\t\t: ray - convert projection ray to model coordiantes"
12104 "\n\t\t: - vconvert v window : convert view to window;"
12105 "\n\t\t: - vconvert v view : convert window to view;"
12106 "\n\t\t: - vconvert x y window : convert view to window;"
12107 "\n\t\t: - vconvert x y view : convert window to view;"
12108 "\n\t\t: - vconvert x y : convert window to model;"
12109 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
12110 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
12111 "\n\t\t: - vconvert x y z window : convert model to window;"
12112 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
12113 "\n\t\t: Converts the given coordinates to window/view/model space.",
12114 __FILE__, VConvert, group);
12115 theCommands.Add ("vfps",
12116 "vfps [framesNb=100] : estimate average frame rate for active view",
12117 __FILE__, VFps, group);
12118 theCommands.Add ("vgldebug",
12119 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
12120 "\n\t\t: [-extraMsg {0|1}] [{0|1}]"
12121 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
12122 "\n\t\t: Debug context can be requested only on Windows"
12123 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
12124 "\n\t\t: -sync - request synchronized debug GL context"
12125 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
12126 "\n\t\t: which are suppressed by default,"
12127 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
12128 "\n\t\t: which are suppressed by default",
12129 __FILE__, VGlDebug, group);
12130 theCommands.Add ("vvbo",
12131 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
12132 __FILE__, VVbo, group);
12133 theCommands.Add ("vstereo",
12134 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
12135 "\n\t\t: [-anaglyph Filter]"
12136 "\n\t\t: Control stereo output mode. Available modes for -mode:"
12137 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
12138 "\n\t\t: requires driver support."
12139 "\n\t\t: Should be called BEFORE vinit!"
12140 "\n\t\t: anaglyph - Anaglyph glasses"
12141 "\n\t\t: rowInterlaced - row-interlaced display"
12142 "\n\t\t: columnInterlaced - column-interlaced display"
12143 "\n\t\t: chessBoard - chess-board output"
12144 "\n\t\t: sideBySide - horizontal pair"
12145 "\n\t\t: overUnder - vertical pair"
12146 "\n\t\t: Available Anaglyph filters for -anaglyph:"
12147 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
12148 "\n\t\t: greenMagentaSimple",
12149 __FILE__, VStereo, group);
12150 theCommands.Add ("vcaps",
12151 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
12152 "\n\t\t: [-compatibleProfile {0|1}]"
12153 "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]"
12154 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
12155 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
12156 "\n\t\t: Modify particular graphic driver options:"
12157 "\n\t\t: FFP - use fixed-function pipeline instead of"
12158 "\n\t\t: built-in GLSL programs"
12159 "\n\t\t: (requires compatible profile)"
12160 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
12161 "\n\t\t: arrays to GPU memory)"
12162 "\n\t\t: sprite - use textured sprites instead of bitmaps"
12163 "\n\t\t: vsync - switch VSync on or off"
12164 "\n\t\t: winBuffer - allow using window buffer for rendering"
12165 "\n\t\t: Context creation options:"
12166 "\n\t\t: softMode - software OpenGL implementation"
12167 "\n\t\t: compatibleProfile - backward-compatible profile"
12168 "\n\t\t: quadbuffer - QuadBuffer"
12169 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
12170 "\n\t\t: rendering paths producing the same visual result when"
12171 "\n\t\t: possible."
12172 "\n\t\t: Command is intended for testing old hardware compatibility.",
12173 __FILE__, VCaps, group);
12174 theCommands.Add ("vmemgpu",
12175 "vmemgpu [f]: print system-dependent GPU memory information if available;"
12176 " with f option returns free memory in bytes",
12177 __FILE__, VMemGpu, group);
12178 theCommands.Add ("vreadpixel",
12179 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
12180 " : Read pixel value for active view",
12181 __FILE__, VReadPixel, group);
12182 theCommands.Add("diffimage",
12183 "diffimage imageFile1 imageFile2 [diffImageFile]"
12184 "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]"
12185 "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]"
12186 "\n\t\t: Compare two images by content and generate difference image."
12187 "\n\t\t: When -exitOnClose is specified, closing the view will exit application."
12188 "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.",
12189 __FILE__, VDiffImage, group);
12190 theCommands.Add ("vselect",
12191 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
12192 "- emulates different types of selection:\n"
12193 "- 1) single click selection\n"
12194 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
12195 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
12196 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
12197 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
12198 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
12199 " (partial inclusion - overlap - is not allowed by default)\n"
12200 "- 5) any of these selections with shift button pressed",
12201 __FILE__, VSelect, group);
12202 theCommands.Add ("vmoveto",
12203 "vmoveto [x y] [-reset]"
12204 "\n\t\t: Emulates cursor movement to pixel position (x,y)."
12205 "\n\t\t: -reset resets current highlighting",
12206 __FILE__, VMoveTo, group);
12207 theCommands.Add ("vviewparams",
12208 "vviewparams [-args] [-scale [s]]"
12209 "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]"
12210 "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]"
12211 "\n\t\t: Manage current view parameters or prints all"
12212 "\n\t\t: current values when called without argument."
12213 "\n\t\t: -scale [s] prints or sets viewport relative scale"
12214 "\n\t\t: -eye [x y z] prints or sets eye location"
12215 "\n\t\t: -at [x y z] prints or sets center of look"
12216 "\n\t\t: -up [x y z] prints or sets direction of up vector"
12217 "\n\t\t: -proj [x y z] prints or sets direction of look"
12218 "\n\t\t: -center x y sets location of center of the screen in pixels"
12219 "\n\t\t: -size [sx] prints viewport projection width and height sizes"
12220 "\n\t\t: or changes the size of its maximum dimension"
12221 "\n\t\t: -args prints vviewparams arguments for restoring current view",
12222 __FILE__, VViewParams, group);
12224 theCommands.Add("v2dmode",
12225 "v2dmode [-name viewName] [-mode {-on|-off}=-on]"
12226 "\n\t\t: name - name of existing view, if not defined, the active view is changed"
12227 "\n\t\t: mode - switches On/Off rotation mode"
12228 "\n\t\t: Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:"
12229 "\n\t\t: - rotation of the view by 3rd mouse button with Ctrl active"
12230 "\n\t\t: - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right"
12231 "\n\t\t: View camera position might be changed only by commands.",
12232 __FILE__, V2DMode, group);
12234 theCommands.Add("vanimation", "Alias for vanim",
12235 __FILE__, VAnimation, group);
12237 theCommands.Add("vanim",
12238 "List existing animations:"
12240 "\n\t\t: Animation playback:"
12241 "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]"
12242 "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]"
12243 "\n\t\t: -speed playback speed (1.0 is normal speed)"
12244 "\n\t\t: -freeLook skip camera animations"
12245 "\n\t\t: -lockLoop disable any interactions"
12247 "\n\t\t: Animation definition:"
12248 "\n\t\t: vanim Name/sub/name [-clear] [-delete]"
12249 "\n\t\t: [start TimeSec] [duration TimeSec]"
12251 "\n\t\t: Animation name defined in path-style (anim/name or anim.name)"
12252 "\n\t\t: specifies nested animations."
12253 "\n\t\t: There is no syntax to explicitly add new animation,"
12254 "\n\t\t: and all non-existing animations within the name will be"
12255 "\n\t\t: implicitly created on first use (including parents)."
12257 "\n\t\t: Each animation might define the SINGLE action (see below),"
12258 "\n\t\t: like camera transition, object transformation or custom callback."
12259 "\n\t\t: Child animations can be used for defining concurrent actions."
12261 "\n\t\t: Camera animation:"
12262 "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]"
12263 "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]"
12264 "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]"
12265 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
12266 "\n\t\t: -eyeX camera Eye positions pair (start and end)"
12267 "\n\t\t: -atX camera Center positions pair"
12268 "\n\t\t: -upX camera Up directions pair"
12269 "\n\t\t: -scaleX camera Scale factors pair"
12270 "\n\t\t: Object animation:"
12271 "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]"
12272 "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]"
12273 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
12274 "\n\t\t: -locX object Location points pair (translation)"
12275 "\n\t\t: -rotX object Orientations pair (quaternions)"
12276 "\n\t\t: -scaleX object Scale factors pair (quaternions)"
12277 "\n\t\t: Custom callback:"
12278 "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\""
12279 "\n\t\t: %Pts overall animation presentation timestamp"
12280 "\n\t\t: %LocalPts local animation timestamp"
12281 "\n\t\t: %Normalized local animation normalized value in range 0..1"
12283 "\n\t\t: Video recording:"
12284 "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]"
12285 "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]"
12286 "\n\t\t: [-crf Value] [-preset Preset]"
12287 "\n\t\t: -fps video framerate"
12288 "\n\t\t: -format file format, container (matroska, etc.)"
12289 "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)"
12290 "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)"
12291 "\n\t\t: -crf constant rate factor (specific to codec)"
12292 "\n\t\t: -preset codec parameters preset (specific to codec)"
12293 __FILE__, VAnimation, group);
12295 theCommands.Add("vchangeselected",
12296 "vchangeselected shape"
12297 "- adds to shape to selection or remove one from it",
12298 __FILE__, VChangeSelected, group);
12299 theCommands.Add ("vnbselected",
12301 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
12302 theCommands.Add ("vcamera",
12303 "vcamera [-ortho] [-projtype]"
12305 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
12306 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
12307 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
12308 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
12309 "\n\t\t: Manage camera parameters."
12310 "\n\t\t: Prints current value when option called without argument."
12311 "\n\t\t: Orthographic camera:"
12312 "\n\t\t: -ortho activate orthographic projection"
12313 "\n\t\t: Perspective camera:"
12314 "\n\t\t: -persp activate perspective projection (mono)"
12315 "\n\t\t: -fovy field of view in y axis, in degrees"
12316 "\n\t\t: -distance distance of eye from camera center"
12317 "\n\t\t: Stereoscopic camera:"
12318 "\n\t\t: -stereo perspective projection (stereo)"
12319 "\n\t\t: -leftEye perspective projection (left eye)"
12320 "\n\t\t: -rightEye perspective projection (right eye)"
12321 "\n\t\t: -iod intraocular distance value"
12322 "\n\t\t: -iodType distance type, absolute or relative"
12323 "\n\t\t: -zfocus stereographic focus value"
12324 "\n\t\t: -zfocusType focus type, absolute or relative",
12325 __FILE__, VCamera, group);
12326 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
12327 "- vautozfit [on={1|0}] [scale]\n"
12328 " Prints or changes parameters of automatic z-fit mode:\n"
12329 " \"on\" - turns automatic z-fit on or off\n"
12330 " \"scale\" - specifies factor to scale computed z range.\n",
12331 __FILE__, VAutoZFit, group);
12332 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
12333 " vzrange - without parameters shows current values\n"
12334 " vzrange [znear] [zfar] - applies provided values to view",
12335 __FILE__,VZRange, group);
12336 theCommands.Add ("vpurgedisplay",
12338 "- removes structures which don't belong to objects displayed in neutral point",
12339 __FILE__, VPurgeDisplay, group);
12340 theCommands.Add("vsetviewsize",
12341 "vsetviewsize size",
12342 __FILE__,VSetViewSize,group);
12343 theCommands.Add("vmoveview",
12344 "vmoveview Dx Dy Dz [Start = 1|0]",
12345 __FILE__,VMoveView,group);
12346 theCommands.Add("vtranslateview",
12347 "vtranslateview Dx Dy Dz [Start = 1|0)]",
12348 __FILE__,VTranslateView,group);
12349 theCommands.Add("vturnview",
12350 "vturnview Ax Ay Az [Start = 1|0]",
12351 __FILE__,VTurnView,group);
12352 theCommands.Add("vtextureenv",
12353 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
12354 "or user-defined file and optionally applying texture mapping parameters\n"
12356 " vtextureenv off - disables environment mapping\n"
12357 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
12358 " std_texture = (0..7)\n"
12359 " rep = {clamp|repeat}\n"
12360 " mod = {decal|modulate}\n"
12361 " flt = {nearest|bilinear|trilinear}\n"
12362 " ss, st - scale factors for s and t texture coordinates\n"
12363 " ts, tt - translation for s and t texture coordinates\n"
12364 " rot - texture rotation angle in degrees",
12365 __FILE__, VTextureEnv, group);
12366 theCommands.Add("vhlr",
12367 "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
12368 "\n\t\t: Hidden Line Removal algorithm."
12369 "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones"
12370 "\n\t\t: -algoType type of HLR algorithm.\n",
12371 __FILE__,VHLR,group);
12372 theCommands.Add("vhlrtype",
12373 "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
12374 "\n\t\t: Changes the type of HLR algorithm using for shapes:"
12375 "\n\t\t: 'algo' - exact HLR algorithm is applied"
12376 "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied"
12377 "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
12378 __FILE__,VHLRType,group);
12379 theCommands.Add("vclipplane",
12380 "vclipplane planeName [{0|1}]"
12381 "\n\t\t: [-equation1 A B C D]"
12382 "\n\t\t: [-equation2 A B C D]"
12383 "\n\t\t: [-boxInterior MinX MinY MinZ MaxX MaxY MaxZ]"
12384 "\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]"
12385 "\n\t\t: [-maxPlanes]"
12386 "\n\t\t: [-capping {0|1}]"
12387 "\n\t\t: [-color R G B] [-transparency Value] [-hatch {on|off|ID}]"
12388 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
12389 "\n\t\t: [-texRotate Angle]"
12390 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
12391 "\n\t\t: [-useObjShader {0|1}]"
12392 "\n\t\t: Clipping planes management:"
12393 "\n\t\t: -maxPlanes print plane limit for view"
12394 "\n\t\t: -delete delete plane with given name"
12395 "\n\t\t: {off|on|0|1} turn clipping on/off"
12396 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
12397 "\n\t\t: applied to active View when list is omitted"
12398 "\n\t\t: -equation A B C D change plane equation"
12399 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
12400 "\n\t\t: Capping options:"
12401 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
12402 "\n\t\t: -color R G B set capping color"
12403 "\n\t\t: -transparency Value set capping transparency 0..1"
12404 "\n\t\t: -texName Texture set capping texture"
12405 "\n\t\t: -texScale SX SY set capping tex scale"
12406 "\n\t\t: -texOrigin TX TY set capping tex origin"
12407 "\n\t\t: -texRotate Angle set capping tex rotation"
12408 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
12409 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
12410 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
12411 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
12412 __FILE__, VClipPlane, group);
12413 theCommands.Add("vdefaults",
12414 "vdefaults [-absDefl value]"
12415 "\n\t\t: [-devCoeff value]"
12416 "\n\t\t: [-angDefl value]"
12417 "\n\t\t: [-autoTriang {off/on | 0/1}]"
12418 , __FILE__, VDefaults, group);
12419 theCommands.Add("vlight",
12420 "tool to manage light sources, without arguments shows list of lights."
12421 "\n Main commands: "
12422 "\n '-clear' to clear lights"
12423 "\n '-{def}aults' to load deafault lights"
12424 "\n '-add' <type> to add any light source"
12425 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
12426 "\n 'change' <lightId> to edit light source with specified lightId"
12427 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
12429 "\n -{pos}ition X Y Z"
12430 "\n -{dir}ection X Y Z (for directional light or for spotlight)"
12431 "\n -color colorName"
12432 "\n -{head}light 0|1"
12433 "\n -{sm}oothness value"
12434 "\n -{int}ensity value"
12435 "\n -{constAtten}uation value"
12436 "\n -{linearAtten}uation value"
12437 "\n -angle angleDeg"
12438 "\n -{spotexp}onent value"
12439 "\n -local|-global"
12440 "\n\n example: vlight -add positional -head 1 -pos 0 1 1 -color red"
12441 "\n example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2",
12442 __FILE__, VLight, group);
12443 theCommands.Add("vraytrace",
12445 "\n\t\t: Turns on/off ray-tracing renderer."
12446 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
12447 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
12448 __FILE__, VRenderParams, group);
12449 theCommands.Add("vrenderparams",
12450 "\n Manages rendering parameters: "
12451 "\n '-raster' Disables GPU ray-tracing"
12452 "\n '-msaa 0..4' Specifies number of samples for MSAA"
12453 "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor"
12454 "\n '-depthPrePass on|off' Enables/disables depth pre-pass"
12455 "\n '-alphatocoverage on|off' Enables/disables alpha to coverage (needs MSAA)"
12456 "\n '-rendScale value Rendering resolution scale factor"
12457 "\n '-rayTrace' Enables GPU ray-tracing"
12458 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
12459 "\n '-shadows on|off' Enables/disables shadows rendering"
12460 "\n '-reflections on|off' Enables/disables specular reflections"
12461 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
12462 "\n '-gleam on|off' Enables/disables transparency shadow effects"
12463 "\n '-gi on|off' Enables/disables global illumination effects"
12464 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
12465 "\n '-env on|off' Enables/disables environment map background"
12466 "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
12467 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
12468 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
12469 "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)"
12470 "\n '-nbtiles 64..1024' Specifies number of screen tiles in ISS mode"
12471 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
12472 "\n '-shadingModel model' Controls shading model from enumeration"
12473 "\n color, flat, gouraud, phong"
12474 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
12475 "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)"
12476 "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect"
12477 "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)"
12478 "\n '-whitepoint value' White point value for filmic tone mapping"
12479 "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)"
12480 "\n '-perfCounters none|fps|cpu|layers|structures|groups|arrays|triagles|points|gpuMem|basic|extended|nofps'"
12481 "\n Show/hide performance counters (flags can be combined)"
12482 "\n '-perfUpdateInterval nbSeconds' Performance counters update interval"
12483 "\n Unlike vcaps, these parameters dramatically change visual properties."
12484 "\n Command is intended to control presentation quality depending on"
12485 "\n hardware capabilities and performance.",
12486 __FILE__, VRenderParams, group);
12487 theCommands.Add("vfrustumculling",
12488 "vfrustumculling [toEnable]: enables/disables objects clipping",
12489 __FILE__,VFrustumCulling,group);
12490 theCommands.Add ("vplace",
12492 "\n\t\t: Places the point (in pixels) at the center of the window",
12493 __FILE__, VPlace, group);
12494 theCommands.Add("vxrotate",
12496 __FILE__,VXRotate,group);
12498 theCommands.Add("vmanipulator",
12499 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
12500 "\n tool to create and manage AIS manipulators."
12502 "\n '-attach AISObject' attach manipulator to AISObject"
12503 "\n '-adjustPosition {0|1}' adjust position when attaching"
12504 "\n '-adjustSize {0|1}' adjust size when attaching"
12505 "\n '-enableModes {0|1}' enable modes when attaching"
12506 "\n '-detach' detach manipulator"
12507 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
12508 "\n '-transform mouse_x mouse_y' - invoke transformation"
12509 "\n '-stopTransform [abort]' - invoke stop of transformation"
12510 "\n '-move x y z' - move attached object"
12511 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
12512 "\n '-scale factor' - scale attached object"
12513 "\n '-autoActivate {0|1}' - set activation on detection"
12514 "\n '-followTranslation {0|1}' - set following translation transform"
12515 "\n '-followRotation {0|1}' - set following rotation transform"
12516 "\n '-gap value' - set gap between sub-parts"
12517 "\n '-part axis mode {0|1}' - set visual part"
12518 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
12519 "\n '-size value' - set size of manipulator"
12520 "\n '-zoomable {0|1}' - set zoom persistence",
12521 __FILE__, VManipulator, group);
12523 theCommands.Add("vselprops",
12524 "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]"
12525 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
12526 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
12527 "\n -autoHighlight {0|1} : disables|enables automatic highlighting in 3D Viewer"
12528 "\n -highlightSelected {0|1}: disables|enables highlighting of detected object in selected state"
12529 "\n -pickStrategy {first|topmost} : defines picking strategy"
12530 "\n 'first' to pick first acceptable (default)"
12531 "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)"
12532 "\n -pixTol value : sets up pixel tolerance"
12533 "\n -dispMode dispMode : sets display mode for highlighting"
12534 "\n -layer ZLayer : sets ZLayer for highlighting"
12535 "\n -color {name|r g b} : sets highlight color"
12536 "\n -transp value : sets transparency coefficient for highlight"
12537 "\n -material material : sets highlight material"
12538 "\n -print : prints current state of all mentioned parameters",
12539 __FILE__, VSelectionProperties, group);
12540 theCommands.Add ("vhighlightselected",
12541 "vhighlightselected [0|1]: alias for vselprops -highlightSelected.\n",
12542 __FILE__, VSelectionProperties, group);
12544 theCommands.Add ("vseldump",
12545 "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1"
12546 "\n\t\t: Generate an image based on detection results:"
12547 "\n\t\t: depth normalized depth values"
12548 "\n\t\t: unnormDepth unnormalized depth values"
12549 "\n\t\t: object color of detected object"
12550 "\n\t\t: owner color of detected owner"
12551 "\n\t\t: selMode color of selection mode"
12552 "\n\t\t: entity color of etected entity",
12553 __FILE__, VDumpSelectionImage, group);
12555 #if defined(_WIN32)
12556 theCommands.Add("vprogressive",
12558 __FILE__, VProgressiveMode, group);