1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <OpenGl_GlCore20.hxx>
19 #include <AIS_Animation.hxx>
20 #include <AIS_AnimationCamera.hxx>
21 #include <AIS_AnimationObject.hxx>
22 #include <AIS_CameraFrustum.hxx>
23 #include <AIS_ColorScale.hxx>
24 #include <AIS_Manipulator.hxx>
25 #include <AIS_RubberBand.hxx>
26 #include <AIS_Shape.hxx>
27 #include <AIS_InteractiveObject.hxx>
28 #include <AIS_ListOfInteractive.hxx>
29 #include <AIS_ListIteratorOfListOfInteractive.hxx>
30 #include <Aspect_Grid.hxx>
32 #include <Draw_ProgressIndicator.hxx>
33 #include <Graphic3d_ArrayOfPolylines.hxx>
34 #include <Graphic3d_AspectMarker3d.hxx>
35 #include <Graphic3d_NameOfTextureEnv.hxx>
36 #include <Graphic3d_GraduatedTrihedron.hxx>
37 #include <Graphic3d_TextureEnv.hxx>
38 #include <Graphic3d_TextureParams.hxx>
39 #include <Graphic3d_TypeOfTextureFilter.hxx>
40 #include <Graphic3d_AspectFillArea3d.hxx>
41 #include <ViewerTest.hxx>
42 #include <ViewerTest_AutoUpdater.hxx>
43 #include <ViewerTest_EventManager.hxx>
44 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
45 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
46 #include <ViewerTest_CmdParser.hxx>
47 #include <V3d_AmbientLight.hxx>
48 #include <V3d_DirectionalLight.hxx>
49 #include <V3d_PositionalLight.hxx>
50 #include <V3d_SpotLight.hxx>
51 #include <Message_ProgressSentry.hxx>
52 #include <NCollection_DoubleMap.hxx>
53 #include <NCollection_List.hxx>
54 #include <NCollection_Vector.hxx>
55 #include <AIS_InteractiveContext.hxx>
56 #include <Draw_Interpretor.hxx>
58 #include <Draw_Appli.hxx>
59 #include <Image_AlienPixMap.hxx>
60 #include <Image_VideoRecorder.hxx>
61 #include <OpenGl_GraphicDriver.hxx>
62 #include <OSD_Timer.hxx>
63 #include <TColStd_HSequenceOfAsciiString.hxx>
64 #include <TColStd_SequenceOfInteger.hxx>
65 #include <TColStd_HSequenceOfReal.hxx>
66 #include <TColgp_Array1OfPnt2d.hxx>
67 #include <TColStd_MapOfAsciiString.hxx>
68 #include <Aspect_TypeOfLine.hxx>
69 #include <Image_Diff.hxx>
70 #include <Aspect_DisplayConnection.hxx>
74 #include <PrsMgr_PresentableObject.hxx>
75 #include <Graphic3d_ClipPlane.hxx>
76 #include <NCollection_DataMap.hxx>
77 #include <Graphic3d_Texture2Dmanual.hxx>
78 #include <Prs3d_ShadingAspect.hxx>
79 #include <Prs3d_Drawer.hxx>
80 #include <Prs3d_LineAspect.hxx>
81 #include <Prs3d_Root.hxx>
82 #include <Prs3d_Text.hxx>
83 #include <Select3D_SensitivePrimitiveArray.hxx>
92 #include <WNT_WClass.hxx>
93 #include <WNT_Window.hxx>
94 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
95 #include <Cocoa_Window.hxx>
97 #include <Xw_Window.hxx>
98 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
99 #include <X11/Xutil.h>
103 // Auxiliary definitions
104 static const char THE_KEY_DELETE = 127;
105 static const char THE_KEY_ESCAPE = 27;
107 //==============================================================================
108 // VIEWER GLOBAL VARIABLES
109 //==============================================================================
111 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
112 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
114 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
115 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
117 extern int VErase (Draw_Interpretor& theDI,
118 Standard_Integer theArgNb,
119 const char** theArgVec);
122 static Handle(WNT_Window)& VT_GetWindow() {
123 static Handle(WNT_Window) WNTWin;
126 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
127 static Handle(Cocoa_Window)& VT_GetWindow()
129 static Handle(Cocoa_Window) aWindow;
132 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
133 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
134 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
137 static Handle(Xw_Window)& VT_GetWindow(){
138 static Handle(Xw_Window) XWWin;
142 static void VProcessEvents(ClientData,int);
145 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
147 static Handle(Aspect_DisplayConnection) aDisplayConnection;
148 return aDisplayConnection;
151 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
153 GetDisplayConnection() = theDisplayConnection;
156 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
157 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
159 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
161 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
162 if (!aWindow.IsNull())
163 return aWindow->HWindow();
164 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
165 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
166 if (!aWindow.IsNull())
167 return aWindow->XWindow();
169 return aWindowHandle;
173 //! Setting additional flag to store 2D mode of the View to avoid scene rotation by mouse/key events
174 class ViewerTest_V3dView : public V3d_View
176 DEFINE_STANDARD_RTTI_INLINE(ViewerTest_V3dView, V3d_View)
178 //! Initializes the view.
179 ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const V3d_TypeOfView theType = V3d_ORTHOGRAPHIC,
180 bool theIs2dMode = false)
181 : V3d_View (theViewer, theType), myIs2dMode (theIs2dMode) {}
183 //! Initializes the view by copying.
184 ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer, const Handle(V3d_View)& theView)
185 : V3d_View (theViewer, theView), myIs2dMode (false)
187 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (theView))
189 myIs2dMode = aV3dView->IsViewIn2DMode();
193 //! Returns true if 2D mode is set for the view
194 bool IsViewIn2DMode() const { return myIs2dMode; }
196 //! Sets 2D mode for the view
197 void SetView2DMode (bool the2dMode) { myIs2dMode = the2dMode; }
201 //! Returns true if active view in 2D mode.
202 static bool IsCurrentViewIn2DMode()
204 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
206 return aV3dView->IsViewIn2DMode();
211 //! Set if active view in 2D mode.
212 static void SetCurrentView2DMode (bool theIs2d)
214 if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
216 aV3dView->SetView2DMode (theIs2d);
222 Standard_Boolean myIs2dMode; //!< 2D mode flag
226 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
227 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
228 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
229 static OpenGl_Caps ViewerTest_myDefaultCaps;
231 static void OSWindowSetup();
235 Quantity_Color FlatColor;
236 Quantity_Color GradientColor1;
237 Quantity_Color GradientColor2;
238 Aspect_GradientFillMethod FillMethod;
239 } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
241 //==============================================================================
242 // EVENT GLOBAL VARIABLES
243 //==============================================================================
245 static int Start_Rot = 0;
246 Standard_Boolean HasHlrOnBeforeRotation = Standard_False;
247 int X_Motion = 0; // Current cursor position
249 int X_ButtonPress = 0; // Last ButtonPress position
250 int Y_ButtonPress = 0;
251 Standard_Boolean IsDragged = Standard_False;
252 Standard_Boolean DragFirst = Standard_False;
253 Standard_Boolean TheIsAnimating = Standard_False;
254 Standard_Boolean Draw_ToExitOnCloseView = Standard_False;
255 Standard_Boolean Draw_ToCloseViewOnEsc = Standard_False;
258 Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand()
260 static Handle(AIS_RubberBand) aBand;
263 aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0);
264 aBand->SetDisplayMode (0);
269 typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators;
271 Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators()
273 static ViewerTest_MapOfAISManipulators aMap;
277 Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator()
279 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
280 for (; anIt.More(); anIt.Next())
282 if (anIt.Value()->HasActiveMode())
290 //==============================================================================
293 static LRESULT WINAPI ViewerWindowProc(
298 static LRESULT WINAPI AdvViewerWindowProc(
306 //==============================================================================
309 //==============================================================================
311 const Handle(Standard_Transient)& ViewerTest::WClass()
313 static Handle(Standard_Transient) theWClass;
315 if (theWClass.IsNull())
317 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
318 CS_VREDRAW | CS_HREDRAW, 0, 0,
319 ::LoadCursor (NULL, IDC_ARROW));
325 //==============================================================================
326 //function : CreateName
327 //purpose : Create numerical name for new object in theMap
328 //==============================================================================
329 template <typename ObjectType>
330 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
331 const TCollection_AsciiString& theDefaultString)
333 if (theObjectMap.IsEmpty())
334 return theDefaultString + TCollection_AsciiString(1);
336 Standard_Integer aNextKey = 1;
337 Standard_Boolean isFound = Standard_False;
340 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
341 // Look for objects with default names
342 if (theObjectMap.IsBound1(aStringKey))
347 isFound = Standard_True;
350 return theDefaultString + TCollection_AsciiString(aNextKey);
353 //==============================================================================
354 //structure : ViewerTest_Names
355 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
356 //==============================================================================
357 struct ViewerTest_Names
360 TCollection_AsciiString myDriverName;
361 TCollection_AsciiString myViewerName;
362 TCollection_AsciiString myViewName;
366 const TCollection_AsciiString& GetDriverName () const
370 void SetDriverName (const TCollection_AsciiString& theDriverName)
372 myDriverName = theDriverName;
374 const TCollection_AsciiString& GetViewerName () const
378 void SetViewerName (const TCollection_AsciiString& theViewerName)
380 myViewerName = theViewerName;
382 const TCollection_AsciiString& GetViewName () const
386 void SetViewName (const TCollection_AsciiString& theViewName)
388 myViewName = theViewName;
391 //===========================================================================
392 //function : Constructor for ViewerTest_Names
393 //purpose : Get view, viewer, driver names from custom string
394 //===========================================================================
396 ViewerTest_Names (const TCollection_AsciiString& theInputString)
398 TCollection_AsciiString aName(theInputString);
399 if (theInputString.IsEmpty())
401 // Get current configuration
402 if (ViewerTest_myDrivers.IsEmpty())
403 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
404 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
406 myDriverName = ViewerTest_myDrivers.Find2
407 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
409 if(ViewerTest_myContexts.IsEmpty())
411 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
412 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
416 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
419 myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
423 // There is at least view name
424 Standard_Integer aParserNumber = 0;
425 for (Standard_Integer i = 0; i < 3; ++i)
427 Standard_Integer aParserPos = aName.SearchFromEnd("/");
431 aName.Split(aParserPos-1);
436 if (aParserNumber == 0)
439 if (!ViewerTest::GetAISContext().IsNull())
441 myDriverName = ViewerTest_myDrivers.Find2
442 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
443 myViewerName = ViewerTest_myContexts.Find2
444 (ViewerTest::GetAISContext());
448 // There is no opened contexts here, need to create names for viewer and driver
449 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
450 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
452 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
453 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
455 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
457 else if (aParserNumber == 1)
459 // Here is viewerName/viewName
460 if (!ViewerTest::GetAISContext().IsNull())
461 myDriverName = ViewerTest_myDrivers.Find2
462 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
465 // There is no opened contexts here, need to create name for driver
466 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
467 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
469 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
471 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
475 //Here is driverName/viewerName/viewName
476 myDriverName = TCollection_AsciiString(aName);
478 TCollection_AsciiString aViewerName(theInputString);
479 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
480 myViewerName = TCollection_AsciiString(aViewerName);
482 myViewName = TCollection_AsciiString(theInputString);
488 //==============================================================================
489 //function : FindContextByView
490 //purpose : Find AIS_InteractiveContext by View
491 //==============================================================================
493 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
495 Handle(AIS_InteractiveContext) anAISContext;
497 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
498 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
500 if (anIter.Value()->CurrentViewer() == theView->Viewer())
501 return anIter.Key2();
507 //==============================================================================
508 //function : SetWindowTitle
509 //purpose : Set window title
510 //==============================================================================
512 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
513 Standard_CString theTitle)
516 const TCollection_ExtendedString theTitleW (theTitle);
517 SetWindowTextW ((HWND )Handle(WNT_Window)::DownCast(theWindow)->HWindow(), theTitleW.ToWideString());
518 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
519 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
521 if(GetDisplayConnection()->GetDisplay())
524 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
525 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
530 //==============================================================================
531 //function : IsWindowOverlapped
532 //purpose : Check if theWindow overlapp another view
533 //==============================================================================
535 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
536 const Standard_Integer thePxTop,
537 const Standard_Integer thePxRight,
538 const Standard_Integer thePxBottom,
539 TCollection_AsciiString& theViewId)
541 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
542 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
544 Standard_Integer aTop = 0,
548 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
549 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
550 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
551 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
552 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
554 theViewId = anIter.Key1();
555 return Standard_True;
558 return Standard_False;
561 // Workaround: to create and delete non-orthographic views outside ViewerTest
562 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
564 ViewerTest_myViews.UnBind1 (theName);
567 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
568 const Handle(V3d_View)& theView)
570 ViewerTest_myViews.Bind (theName, theView);
573 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
575 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
577 //==============================================================================
578 //function : ViewerInit
579 //purpose : Create the window viewer and initialize all the global variable
580 //==============================================================================
582 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
583 const Standard_Integer thePxTop,
584 const Standard_Integer thePxWidth,
585 const Standard_Integer thePxHeight,
586 const TCollection_AsciiString& theViewName,
587 const TCollection_AsciiString& theDisplayName,
588 const Handle(V3d_View)& theViewToClone)
590 // Default position and dimension of the viewer window.
591 // Note that left top corner is set to be sufficiently small to have
592 // window fit in the small screens (actual for remote desktops, see #23003).
593 // The position corresponds to the window's client area, thus some
594 // gap is added for window frame to be visible.
595 Standard_Integer aPxLeft = 20;
596 Standard_Integer aPxTop = 40;
597 Standard_Integer aPxWidth = 409;
598 Standard_Integer aPxHeight = 409;
599 Standard_Boolean toCreateViewer = Standard_False;
600 if (!theViewToClone.IsNull())
602 theViewToClone->Window()->Size (aPxWidth, aPxHeight);
605 Handle(OpenGl_GraphicDriver) aGraphicDriver;
606 ViewerTest_Names aViewNames(theViewName);
607 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
608 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
615 aPxWidth = thePxWidth;
616 if (thePxHeight != 0)
617 aPxHeight = thePxHeight;
619 // Get graphic driver (create it or get from another view)
620 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
622 // Get connection string
623 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
624 TCollection_AsciiString aDisplayName(theDisplayName);
625 if (!aDisplayName.IsEmpty())
626 SetDisplayConnection (new Aspect_DisplayConnection ());
628 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
630 (void)theDisplayName; // avoid warning on unused argument
631 SetDisplayConnection (new Aspect_DisplayConnection ());
634 if (Draw_VirtualWindows)
636 // don't waste the time waiting for VSync when window is not displayed on the screen
637 ViewerTest_myDefaultCaps.swapInterval = 0;
638 // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
639 //ViewerTest_myDefaultCaps.buffersNoSwap = true;
641 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
642 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
644 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
645 toCreateViewer = Standard_True;
649 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
652 //Dispose the window if input parameters are default
653 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
655 Standard_Integer aTop = 0,
662 // Get screen resolution
663 #if defined(_WIN32) || defined(__WIN32__)
665 GetClientRect(GetDesktopWindow(), &aWindowSize);
666 aScreenHeight = aWindowSize.bottom;
667 aScreenWidth = aWindowSize.right;
668 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
669 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
671 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
672 aScreenWidth = WidthOfScreen(aScreen);
673 aScreenHeight = HeightOfScreen(aScreen);
676 TCollection_AsciiString anOverlappedViewId("");
678 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
680 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
682 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
683 && aRight + 2*aPxWidth + 40 > aScreenWidth)
685 if (aBottom + aPxHeight + 40 > aScreenHeight)
692 aPxTop = aBottom + 40;
695 aPxLeft = aRight + 20;
700 TCollection_AsciiString aTitle("3D View - ");
701 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
703 // Change name of current active window
704 if (!ViewerTest::CurrentView().IsNull())
706 TCollection_AsciiString anActiveWindowTitle("3D View - ");
707 anActiveWindowTitle = anActiveWindowTitle
708 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
709 SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString());
713 Handle(V3d_Viewer) a3DViewer;
714 // If it's the single view, we first look for empty context
715 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
717 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
718 anIter(ViewerTest_myContexts);
720 ViewerTest::SetAISContext (anIter.Value());
721 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
723 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
725 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
726 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
728 else if (a3DViewer.IsNull())
730 toCreateViewer = Standard_True;
731 a3DViewer = new V3d_Viewer(aGraphicDriver);
732 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
733 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
734 ViewerTest_DefaultBackground.GradientColor2,
735 ViewerTest_DefaultBackground.FillMethod);
739 if (ViewerTest::GetAISContext().IsNull() ||
740 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
742 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
743 ViewerTest::SetAISContext (aContext);
744 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
748 ViewerTest::ResetEventManager();
753 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
754 Handle(WNT_WClass)::DownCast (WClass()),
755 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
759 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
760 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
762 aPxWidth, aPxHeight);
763 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
765 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
768 aPxWidth, aPxHeight);
770 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
773 Handle(V3d_View) aView;
774 if (!theViewToClone.IsNull())
776 aView = new ViewerTest_V3dView (a3DViewer, theViewToClone);
780 aView = new ViewerTest_V3dView (a3DViewer, a3DViewer->DefaultTypeOfView());
783 aView->SetWindow (VT_GetWindow());
784 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
786 ViewerTest::CurrentView(aView);
787 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
789 // Setup for X11 or NT
792 // Set parameters for V3d_View and V3d_Viewer
793 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
794 aV3dView->SetComputedMode(Standard_False);
796 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
799 a3DViewer->SetDefaultLights();
800 a3DViewer->SetLightOn();
803 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
804 #if TCL_MAJOR_VERSION < 8
805 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
806 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
808 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
809 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
813 VT_GetWindow()->Map();
815 // Set the handle of created view in the event manager
816 ViewerTest::ResetEventManager();
818 ViewerTest::CurrentView()->Redraw();
823 return aViewNames.GetViewName();
826 //==============================================================================
827 //function : RedrawAllViews
828 //purpose : Redraw all created views
829 //==============================================================================
830 void ViewerTest::RedrawAllViews()
832 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
833 for (; aViewIt.More(); aViewIt.Next())
835 const Handle(V3d_View)& aView = aViewIt.Key2();
840 //==============================================================================
842 //purpose : Create the window viewer and initialize all the global variable
843 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
844 //==============================================================================
846 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
848 TCollection_AsciiString aViewName, aDisplayName;
849 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
850 Handle(V3d_View) aCopyFrom;
851 TCollection_AsciiString aName, aValue;
853 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
855 const TCollection_AsciiString anArg = theArgVec[anArgIt];
856 TCollection_AsciiString anArgCase = anArg;
857 anArgCase.LowerCase();
858 if (anArgIt + 1 < theArgsNb
859 && anArgCase == "-name")
861 aViewName = theArgVec[++anArgIt];
863 else if (anArgIt + 1 < theArgsNb
864 && (anArgCase == "-left"
865 || anArgCase == "-l"))
867 aPxLeft = Draw::Atoi (theArgVec[++anArgIt]);
869 else if (anArgIt + 1 < theArgsNb
870 && (anArgCase == "-top"
871 || anArgCase == "-t"))
873 aPxTop = Draw::Atoi (theArgVec[++anArgIt]);
875 else if (anArgIt + 1 < theArgsNb
876 && (anArgCase == "-width"
877 || anArgCase == "-w"))
879 aPxWidth = Draw::Atoi (theArgVec[++anArgIt]);
881 else if (anArgIt + 1 < theArgsNb
882 && (anArgCase == "-height"
883 || anArgCase == "-h"))
885 aPxHeight = Draw::Atoi (theArgVec[++anArgIt]);
887 else if (anArgCase == "-exitonclose")
889 Draw_ToExitOnCloseView = true;
890 if (anArgIt + 1 < theArgsNb
891 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToExitOnCloseView))
896 else if (anArgCase == "-closeonescape"
897 || anArgCase == "-closeonesc")
899 Draw_ToCloseViewOnEsc = true;
900 if (anArgIt + 1 < theArgsNb
901 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToCloseViewOnEsc))
906 else if (anArgCase == "-2d_mode"
907 || anArgCase == "-2dmode"
908 || anArgCase == "-2d")
910 bool toEnable = true;
911 if (anArgIt + 1 < theArgsNb
912 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], toEnable))
916 is2dMode = toEnable ? 1 : 0;
918 else if (anArgIt + 1 < theArgsNb
919 && (anArgCase == "-disp"
920 || anArgCase == "-display"))
922 aDisplayName = theArgVec[++anArgIt];
924 else if (!ViewerTest::CurrentView().IsNull()
925 && aCopyFrom.IsNull()
926 && (anArgCase == "-copy"
927 || anArgCase == "-clone"
928 || anArgCase == "-cloneactive"
929 || anArgCase == "-cloneactiveview"))
931 aCopyFrom = ViewerTest::CurrentView();
934 else if (ViewerTest::SplitParameter (anArg, aName, aValue))
941 else if (aName == "l"
944 aPxLeft = aValue.IntegerValue();
946 else if (aName == "t"
949 aPxTop = aValue.IntegerValue();
951 else if (aName == "disp"
952 || aName == "display")
954 aDisplayName = aValue;
956 else if (aName == "w"
959 aPxWidth = aValue.IntegerValue();
961 else if (aName == "h"
962 || aName == "height")
964 aPxHeight = aValue.IntegerValue();
968 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
972 else if (aViewName.IsEmpty())
978 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
983 #if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
984 if (!aDisplayName.IsEmpty())
986 aDisplayName.Clear();
987 std::cout << "Warning: display parameter will be ignored.\n";
991 ViewerTest_Names aViewNames (aViewName);
992 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
994 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
995 theDi.Eval (aCommand.ToCString());
998 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
1003 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
1004 aViewName, aDisplayName, aCopyFrom);
1007 ViewerTest_V3dView::SetCurrentView2DMode (is2dMode == 1);
1013 //! Parse HLR algo type.
1014 static Standard_Boolean parseHlrAlgoType (const char* theName,
1015 Prs3d_TypeOfHLR& theType)
1017 TCollection_AsciiString aName (theName);
1019 if (aName == "polyalgo")
1021 theType = Prs3d_TOH_PolyAlgo;
1023 else if (aName == "algo")
1025 theType = Prs3d_TOH_Algo;
1029 return Standard_False;
1031 return Standard_True;
1034 //==============================================================================
1036 //purpose : hidden lines removal algorithm
1037 //==============================================================================
1039 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1041 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1042 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1045 std::cerr << "Error: No opened viewer!\n";
1049 Standard_Boolean hasHlrOnArg = Standard_False;
1050 Standard_Boolean hasShowHiddenArg = Standard_False;
1051 Standard_Boolean isHLROn = Standard_False;
1052 Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
1053 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1054 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1055 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
1057 TCollection_AsciiString anArg (argv[anArgIter]);
1059 if (anUpdateTool.parseRedrawMode (anArg))
1063 else if (anArg == "-showhidden"
1064 && anArgIter + 1 < argc
1065 && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden))
1068 hasShowHiddenArg = Standard_True;
1071 else if ((anArg == "-type"
1073 || anArg == "-algotype")
1074 && anArgIter + 1 < argc
1075 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1080 else if (!hasHlrOnArg
1081 && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn))
1083 hasHlrOnArg = Standard_True;
1087 else if (!hasShowHiddenArg
1088 && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden))
1090 hasShowHiddenArg = Standard_True;
1095 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
1101 di << "HLR: " << aView->ComputedMode() << "\n";
1102 di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
1104 switch (aCtx->DefaultDrawer()->TypeOfHLR())
1106 case Prs3d_TOH_NotSet: di << "NotSet\n"; break;
1107 case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
1108 case Prs3d_TOH_Algo: di << "Algo\n"; break;
1110 anUpdateTool.Invalidate();
1114 Standard_Boolean toRecompute = Standard_False;
1115 if (aTypeOfHLR != Prs3d_TOH_NotSet
1116 && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
1118 toRecompute = Standard_True;
1119 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1121 if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
1123 toRecompute = Standard_True;
1126 aCtx->DefaultDrawer()->EnableDrawHiddenLine();
1130 aCtx->DefaultDrawer()->DisableDrawHiddenLine();
1135 if (aView->ComputedMode() && isHLROn && toRecompute)
1137 AIS_ListOfInteractive aListOfShapes;
1138 aCtx->DisplayedObjects (aListOfShapes);
1139 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
1141 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
1143 aCtx->Redisplay (aShape, Standard_False);
1148 aView->SetComputedMode (isHLROn);
1152 //==============================================================================
1153 //function : VHLRType
1154 //purpose : change type of using HLR algorithm
1155 //==============================================================================
1157 static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1159 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1160 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1163 std::cerr << "Error: No opened viewer!\n";
1167 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1168 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1169 AIS_ListOfInteractive aListOfShapes;
1170 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
1172 TCollection_AsciiString anArg (argv[anArgIter]);
1174 if (anUpdateTool.parseRedrawMode (anArg))
1178 else if ((anArg == "-type"
1180 || anArg == "-algotype")
1181 && anArgIter + 1 < argc
1182 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1188 else if (aTypeOfHLR == Prs3d_TOH_NotSet
1189 && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
1195 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
1196 TCollection_AsciiString aName (argv[anArgIter]);
1197 if (!aMap.IsBound2 (aName))
1199 std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n";
1203 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
1204 if (aShape.IsNull())
1206 std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n";
1209 aListOfShapes.Append (aShape);
1213 if (aTypeOfHLR == Prs3d_TOH_NotSet)
1215 std::cout << "Syntax error: wrong number of arguments!\n";
1219 const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
1222 aCtx->DisplayedObjects (aListOfShapes);
1223 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1226 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
1228 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1229 if (aShape.IsNull())
1234 const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
1235 && aView->ComputedMode();
1237 || aShape->TypeOfHLR() != aTypeOfHLR)
1239 aShape->SetTypeOfHLR (aTypeOfHLR);
1243 aCtx->Redisplay (aShape, Standard_False);
1249 //==============================================================================
1250 //function : FindViewIdByWindowHandle
1251 //purpose : Find theView Id in the map of views by window handle
1252 //==============================================================================
1253 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1254 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
1256 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
1257 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1259 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
1260 if (aWindowHandle == theWindowHandle)
1261 return anIter.Key1();
1263 return TCollection_AsciiString("");
1267 //==============================================================================
1268 //function : ActivateView
1269 //purpose : Make the view active
1270 //==============================================================================
1272 void ActivateView (const TCollection_AsciiString& theViewName)
1274 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1275 if (!aView.IsNull())
1277 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1278 if (!anAISContext.IsNull())
1280 if (!ViewerTest::CurrentView().IsNull())
1282 TCollection_AsciiString aTitle("3D View - ");
1283 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1284 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1287 ViewerTest::CurrentView (aView);
1288 ViewerTest::SetAISContext (anAISContext);
1289 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ") + theViewName + "(*)";
1290 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1292 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1293 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1294 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1296 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1298 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1299 ViewerTest::CurrentView()->Redraw();
1304 //==============================================================================
1305 //function : RemoveView
1307 //==============================================================================
1308 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1309 const Standard_Boolean theToRemoveContext)
1311 if (!ViewerTest_myViews.IsBound2 (theView))
1316 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1317 RemoveView (aViewName, theToRemoveContext);
1320 //==============================================================================
1321 //function : RemoveView
1322 //purpose : Close and remove view from display, clear maps if neccessary
1323 //==============================================================================
1324 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1326 if (!ViewerTest_myViews.IsBound1(theViewName))
1328 cout << "Wrong view name\n";
1332 // Activate another view if it's active now
1333 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1335 if (ViewerTest_myViews.Extent() > 1)
1337 TCollection_AsciiString aNewViewName;
1338 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1339 anIter.More(); anIter.Next())
1341 if (anIter.Key1() != theViewName)
1343 aNewViewName = anIter.Key1();
1347 ActivateView (aNewViewName);
1351 Handle(V3d_View) anEmptyView;
1352 #if defined(_WIN32) || defined(__WIN32__)
1353 Handle(WNT_Window) anEmptyWindow;
1354 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1355 Handle(Cocoa_Window) anEmptyWindow;
1357 Handle(Xw_Window) anEmptyWindow;
1359 VT_GetWindow() = anEmptyWindow;
1360 ViewerTest::CurrentView (anEmptyView);
1361 if (isContextRemoved)
1363 Handle(AIS_InteractiveContext) anEmptyContext;
1364 ViewerTest::SetAISContext(anEmptyContext);
1370 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1371 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1373 // Remove view resources
1374 ViewerTest_myViews.UnBind1(theViewName);
1375 aView->Window()->Unmap();
1378 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1379 XFlush (GetDisplayConnection()->GetDisplay());
1382 // Keep context opened only if the closed view is last to avoid
1383 // unused empty contexts
1384 if (!aCurrentContext.IsNull())
1386 // Check if there are more difined views in the viewer
1387 aCurrentContext->CurrentViewer()->InitDefinedViews();
1388 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1390 // Remove driver if there is no viewers that use it
1391 Standard_Boolean isRemoveDriver = Standard_True;
1392 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1393 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1395 if (aCurrentContext != anIter.Key2() &&
1396 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1398 isRemoveDriver = Standard_False;
1403 aCurrentContext->RemoveAll (Standard_False);
1406 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1407 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1408 #if TCL_MAJOR_VERSION < 8
1409 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1411 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1416 ViewerTest_myContexts.UnBind2(aCurrentContext);
1419 cout << "3D View - " << theViewName << " was deleted.\n";
1420 if (Draw_ToExitOnCloseView)
1422 Draw_Interprete ("exit");
1426 //==============================================================================
1428 //purpose : Remove the view defined by its name
1429 //==============================================================================
1431 static int VClose (Draw_Interpretor& /*theDi*/,
1432 Standard_Integer theArgsNb,
1433 const char** theArgVec)
1435 NCollection_List<TCollection_AsciiString> aViewList;
1438 TCollection_AsciiString anArg (theArgVec[1]);
1440 if (anArg.IsEqual ("ALL")
1441 || anArg.IsEqual ("*"))
1443 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1444 anIter.More(); anIter.Next())
1446 aViewList.Append (anIter.Key1());
1448 if (aViewList.IsEmpty())
1450 std::cout << "No view to close\n";
1456 ViewerTest_Names aViewName (theArgVec[1]);
1457 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1459 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1462 aViewList.Append (aViewName.GetViewName());
1467 // close active view
1468 if (ViewerTest::CurrentView().IsNull())
1470 std::cerr << "No active view!\n";
1473 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1476 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1477 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1478 anIter.More(); anIter.Next())
1480 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1486 //==============================================================================
1487 //function : VActivate
1488 //purpose : Activate the view defined by its ID
1489 //==============================================================================
1491 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1495 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1496 << "Usage: " << theArgVec[0] << " ViewID\n";
1501 theDi.Eval("vviewlist");
1505 TCollection_AsciiString aNameString(theArgVec[1]);
1506 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1508 TCollection_AsciiString aTitle("3D View - ");
1509 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1510 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1511 Handle(V3d_View) anEmptyView;
1512 #if defined(_WIN32) || defined(__WIN32__)
1513 Handle(WNT_Window) anEmptyWindow;
1514 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1515 Handle(Cocoa_Window) anEmptyWindow;
1517 Handle(Xw_Window) anEmptyWindow;
1519 VT_GetWindow() = anEmptyWindow;
1520 ViewerTest::CurrentView (anEmptyView);
1521 ViewerTest::ResetEventManager();
1522 theDi << theArgVec[0] << ": all views are inactive\n";
1526 ViewerTest_Names aViewNames(aNameString);
1528 // Check if this view exists in the viewer with the driver
1529 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1531 theDi << "Wrong view name\n";
1535 // Check if it is active already
1536 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1538 theDi << theArgVec[0] << ": the view is active already\n";
1542 ActivateView (aViewNames.GetViewName());
1546 //==============================================================================
1547 //function : VViewList
1548 //purpose : Print current list of views per viewer and graphic driver ID
1549 // shared between viewers
1550 //==============================================================================
1552 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1556 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1557 << "Usage: " << theArgVec[0] << " name";
1560 if (ViewerTest_myContexts.Size() < 1)
1563 Standard_Boolean isTreeView =
1564 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1568 theDi << theArgVec[0] <<":\n";
1571 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers);
1572 aDriverIter.More(); aDriverIter.Next())
1575 theDi << aDriverIter.Key1() << ":\n";
1577 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1578 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1580 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1584 TCollection_AsciiString aContextName(aContextIter.Key1());
1585 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
1588 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews);
1589 aViewIter.More(); aViewIter.Next())
1591 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1593 TCollection_AsciiString aViewName(aViewIter.Key1());
1596 if (aViewIter.Value() == ViewerTest::CurrentView())
1597 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
1599 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1603 theDi << aViewName << " ";
1613 //==============================================================================
1614 //function : VT_ProcessKeyPress
1615 //purpose : Handle KeyPress event from a CString
1616 //==============================================================================
1617 void VT_ProcessKeyPress (const char* buf_ret)
1619 //cout << "KeyPress" << endl;
1620 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1621 // Letter in alphabetic order
1623 if (!strcasecmp (buf_ret, "A")
1624 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1627 aView->SetProj(V3d_XposYnegZpos);
1629 else if (!strcasecmp (buf_ret, "D")
1630 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1635 else if (!strcasecmp (buf_ret, "F"))
1637 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1639 ViewerTest::GetAISContext()->FitSelected (aView);
1647 else if (!strcasecmp (buf_ret, "H"))
1650 std::cout << "HLR" << std::endl;
1651 aView->SetComputedMode (!aView->ComputedMode());
1654 else if (!strcasecmp (buf_ret, "P"))
1657 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1658 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1659 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1661 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1662 if (aContext->NbSelected()==0)
1664 AIS_ListOfInteractive aListOfShapes;
1665 aContext->DisplayedObjects(aListOfShapes);
1666 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1667 anIter.More(); anIter.Next())
1669 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1670 if (aShape.IsNull())
1672 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1673 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1675 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1676 aContext->Redisplay (aShape, Standard_False);
1681 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
1683 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
1684 if (aShape.IsNull())
1686 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1687 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1689 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1690 aContext->Redisplay (aShape, Standard_False);
1694 aContext->UpdateCurrentViewer();
1697 else if (!strcasecmp (buf_ret, "S"))
1699 std::cout << "setup Shaded display mode" << std::endl;
1701 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1702 if(Ctx->NbSelected()==0)
1703 Ctx->SetDisplayMode (AIS_Shaded, Standard_True);
1705 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1706 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
1707 Ctx->UpdateCurrentViewer();
1710 else if (!strcasecmp (buf_ret, "U"))
1712 // Unset display mode
1713 std::cout << "reset display mode to defaults" << std::endl;
1715 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1716 if(Ctx->NbSelected()==0)
1717 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
1719 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1720 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
1721 Ctx->UpdateCurrentViewer();
1725 else if (!strcasecmp (buf_ret, "T")
1726 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1729 aView->SetProj(V3d_Zpos);
1731 else if (!strcasecmp (buf_ret, "B")
1732 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1735 aView->SetProj(V3d_Zneg);
1737 else if (!strcasecmp (buf_ret, "L")
1738 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1741 aView->SetProj(V3d_Xneg);
1743 else if (!strcasecmp (buf_ret, "R")
1744 && !ViewerTest_V3dView::IsCurrentViewIn2DMode())
1747 aView->SetProj(V3d_Xpos);
1749 else if (!strcasecmp (buf_ret, "W"))
1751 std::cout << "setup WireFrame display mode" << std::endl;
1752 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1753 if(Ctx->NbSelected()==0)
1754 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
1756 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1757 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
1758 Ctx->UpdateCurrentViewer();
1761 else if (!strcasecmp (buf_ret, ","))
1763 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1765 else if (!strcasecmp (buf_ret, "."))
1767 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1769 else if (!strcasecmp (buf_ret, "/"))
1771 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1772 if (aCamera->IsStereo())
1774 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1778 else if (!strcasecmp (buf_ret, "*"))
1780 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1781 if (aCamera->IsStereo())
1783 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1787 else if (*buf_ret == THE_KEY_DELETE)
1789 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1791 && aCtx->NbSelected() > 0)
1793 Draw_Interprete ("verase");
1796 else if (*buf_ret == THE_KEY_ESCAPE)
1798 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1800 && Draw_ToCloseViewOnEsc)
1802 Draw_Interprete (Draw_ToExitOnCloseView ? "exit" : "vclose");
1808 const Standard_Integer aSelMode = Draw::Atoi(buf_ret);
1809 if (aSelMode >= 0 && aSelMode <= 7)
1811 bool toEnable = true;
1812 if (const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext())
1814 AIS_ListOfInteractive aPrsList;
1815 aCtx->DisplayedObjects (aPrsList);
1816 for (AIS_ListOfInteractive::Iterator aPrsIter (aPrsList); aPrsIter.More() && toEnable; aPrsIter.Next())
1818 TColStd_ListOfInteger aModes;
1819 aCtx->ActivatedModes (aPrsIter.Value(), aModes);
1820 for (TColStd_ListOfInteger::Iterator aModeIter (aModes); aModeIter.More() && toEnable; aModeIter.Next())
1822 if (aModeIter.Value() == aSelMode)
1829 TCollection_AsciiString aCmd = TCollection_AsciiString ("vselmode ") + aSelMode + (toEnable ? " 1" : " 0");
1830 Draw_Interprete (aCmd.ToCString());
1835 //==============================================================================
1836 //function : VT_ProcessExpose
1837 //purpose : Redraw the View on an Expose Event
1838 //==============================================================================
1839 void VT_ProcessExpose()
1841 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1842 if (!aView3d.IsNull())
1848 //==============================================================================
1849 //function : VT_ProcessConfigure
1850 //purpose : Resize the View on an Configure Event
1851 //==============================================================================
1852 void VT_ProcessConfigure()
1854 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1855 if (aView3d.IsNull())
1860 aView3d->MustBeResized();
1865 //==============================================================================
1866 //function : VT_ProcessButton1Press
1868 //==============================================================================
1869 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1870 const char** theArgVec,
1871 Standard_Boolean theToPick,
1872 Standard_Boolean theIsShift)
1876 TheIsAnimating = Standard_False;
1877 return Standard_False;
1882 Standard_Real X, Y, Z;
1883 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1885 Draw::Set (theArgVec[1], X);
1886 Draw::Set (theArgVec[2], Y);
1887 Draw::Set (theArgVec[3], Z);
1892 ViewerTest::CurrentEventManager()->ShiftSelect();
1896 ViewerTest::CurrentEventManager()->Select();
1899 return Standard_False;
1902 //==============================================================================
1903 //function : VT_ProcessButton1Release
1904 //purpose : End selecting
1905 //==============================================================================
1906 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1910 IsDragged = Standard_False;
1911 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1914 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1915 X_Motion, Y_Motion);
1919 EM->Select (X_ButtonPress, Y_ButtonPress,
1920 X_Motion, Y_Motion);
1925 //==============================================================================
1926 //function : VT_ProcessButton3Press
1927 //purpose : Start Rotation
1928 //==============================================================================
1929 void VT_ProcessButton3Press()
1931 if (ViewerTest_V3dView::IsCurrentViewIn2DMode())
1937 HasHlrOnBeforeRotation = ViewerTest::CurrentView()->ComputedMode();
1938 if (HasHlrOnBeforeRotation)
1940 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1942 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1945 //==============================================================================
1946 //function : VT_ProcessButton3Release
1947 //purpose : End rotation
1948 //==============================================================================
1949 void VT_ProcessButton3Release()
1954 if (HasHlrOnBeforeRotation)
1956 HasHlrOnBeforeRotation = Standard_False;
1957 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1958 ViewerTest::CurrentView()->Redraw();
1963 //==============================================================================
1964 //function : ProcessControlButton1Motion
1966 //==============================================================================
1968 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1969 static void ProcessControlButton1Motion()
1971 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1973 X_ButtonPress = X_Motion;
1974 Y_ButtonPress = Y_Motion;
1978 //==============================================================================
1979 //function : VT_ProcessControlButton2Motion
1981 //==============================================================================
1982 void VT_ProcessControlButton2Motion()
1984 Standard_Integer aDx = X_Motion - X_ButtonPress;
1985 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1987 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1989 ViewerTest::CurrentView()->Pan (aDx, aDy);
1991 X_ButtonPress = X_Motion;
1992 Y_ButtonPress = Y_Motion;
1995 //==============================================================================
1996 //function : VT_ProcessControlButton3Motion
1997 //purpose : Rotation
1998 //==============================================================================
1999 void VT_ProcessControlButton3Motion()
2003 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
2007 //==============================================================================
2008 //function : VT_ProcessMotion
2010 //==============================================================================
2011 void VT_ProcessMotion()
2013 //pre-hilights detected objects at mouse position
2015 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
2016 EM->MoveTo(X_Motion, Y_Motion);
2020 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
2022 Xpix = X_Motion;Ypix=Y_Motion;
2025 //==============================================================================
2026 //function : ViewProject: implements VAxo, VTop, VLeft, ...
2027 //purpose : Switches to an axonometric, top, left and other views
2028 //==============================================================================
2030 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
2032 if ( ViewerTest::CurrentView().IsNull() )
2034 di<<"Call vinit before this command, please\n";
2038 ViewerTest::CurrentView()->SetProj(ori);
2042 //==============================================================================
2044 //purpose : Switch to an Axonometric view
2045 //Draw arg : No args
2046 //==============================================================================
2048 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
2050 return ViewProject(di, V3d_XposYnegZpos);
2053 //==============================================================================
2055 //purpose : Switch to a Top View
2056 //Draw arg : No args
2057 //==============================================================================
2059 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
2061 return ViewProject(di, V3d_Zpos);
2064 //==============================================================================
2065 //function : VBottom
2066 //purpose : Switch to a Bottom View
2067 //Draw arg : No args
2068 //==============================================================================
2070 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
2072 return ViewProject(di, V3d_Zneg);
2075 //==============================================================================
2077 //purpose : Switch to a Left View
2078 //Draw arg : No args
2079 //==============================================================================
2081 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
2083 return ViewProject(di, V3d_Xneg);
2086 //==============================================================================
2088 //purpose : Switch to a Right View
2089 //Draw arg : No args
2090 //==============================================================================
2092 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
2094 return ViewProject(di, V3d_Xpos);
2097 //==============================================================================
2099 //purpose : Switch to a Front View
2100 //Draw arg : No args
2101 //==============================================================================
2103 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
2105 return ViewProject(di, V3d_Yneg);
2108 //==============================================================================
2110 //purpose : Switch to a Back View
2111 //Draw arg : No args
2112 //==============================================================================
2114 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
2116 return ViewProject(di, V3d_Ypos);
2119 //==============================================================================
2121 //purpose : Dsiplay help on viewer Keyboead and mouse commands
2122 //Draw arg : No args
2123 //==============================================================================
2125 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
2128 di << "Q : Quit the application\n";
2130 di << "=========================\n";
2131 di << "F : FitAll\n";
2132 di << "T : TopView\n";
2133 di << "B : BottomView\n";
2134 di << "R : RightView\n";
2135 di << "L : LeftView\n";
2136 di << "A : AxonometricView\n";
2137 di << "D : ResetView\n";
2139 di << "=========================\n";
2140 di << "S : Shading\n";
2141 di << "W : Wireframe\n";
2142 di << "H : HidelLineRemoval\n";
2143 di << "U : Unset display mode\n";
2144 di << "Delete : Remove selection from viewer\n";
2146 di << "=========================\n";
2147 di << "Selection mode \n";
2148 di << "0 : Shape\n";
2149 di << "1 : Vertex\n";
2153 di << "5 : Shell\n";
2154 di << "6 : Solid\n";
2155 di << "7 : Compound\n";
2157 di << "=========================\n";
2158 di << "Z : Switch Z clipping On/Off\n";
2159 di << ", : Hilight next detected\n";
2160 di << ". : Hilight previous detected\n";
2167 static Standard_Boolean Ppick = 0;
2168 static Standard_Integer Pargc = 0;
2169 static const char** Pargv = NULL;
2172 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
2177 if (!ViewerTest_myViews.IsEmpty()) {
2179 WPARAM fwKeys = wParam;
2184 // Delete view from map of views
2185 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
2190 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
2191 || ViewerTest::CurrentView().IsNull())
2193 // Activate inactive window
2194 if(GetWindowHandle(VT_GetWindow()) != hwnd)
2196 ActivateView (FindViewIdByWindowHandle(hwnd));
2202 if (IsDragged && !DragFirst)
2204 if (!GetActiveAISManipulator().IsNull())
2206 GetActiveAISManipulator()->StopTransform();
2207 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
2210 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2212 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2213 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2216 VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0);
2218 IsDragged = Standard_False;
2219 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2222 if (IsDragged && !DragFirst)
2224 if (!GetActiveAISManipulator().IsNull())
2226 GetActiveAISManipulator()->StopTransform (Standard_False);
2227 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
2229 IsDragged = Standard_False;
2231 return ViewerWindowProc (hwnd, Msg, wParam, lParam);
2233 case WM_LBUTTONDOWN:
2234 if (!GetActiveAISManipulator().IsNull())
2236 IsDragged = ( fwKeys == MK_LBUTTON );
2240 IsDragged = ( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) );
2245 DragFirst = Standard_True;
2246 X_ButtonPress = LOWORD(lParam);
2247 Y_ButtonPress = HIWORD(lParam);
2249 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2254 X_Motion = LOWORD (lParam);
2255 Y_Motion = HIWORD (lParam);
2256 if (!GetActiveAISManipulator().IsNull())
2260 GetActiveAISManipulator()->StartTransform (X_ButtonPress, Y_ButtonPress, ViewerTest::CurrentView());
2264 GetActiveAISManipulator()->Transform (X_Motion, Y_Motion, ViewerTest::CurrentView());
2265 ViewerTest::GetAISContext()->CurrentViewer()->Redraw();
2270 bool toRedraw = false;
2271 if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2273 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2278 if (GetClientRect (hwnd, &aRect))
2280 int aHeight = aRect.bottom - aRect.top;
2281 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2282 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed);
2287 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2291 DragFirst = Standard_False;
2294 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2298 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2302 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2306 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
2312 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2315 return DefWindowProcW (hwnd, Msg, wParam, lParam);
2322 BeginPaint(hwnd, &ps);
2323 EndPaint(hwnd, &ps);
2328 VT_ProcessConfigure();
2333 switch (aView->RenderingParams().StereoMode)
2335 case Graphic3d_StereoMode_RowInterlaced:
2336 case Graphic3d_StereoMode_ColumnInterlaced:
2337 case Graphic3d_StereoMode_ChessBoard:
2338 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2346 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2349 c[0] = (char) wParam;
2351 if (wParam == VK_DELETE)
2353 c[0] = THE_KEY_DELETE;
2355 else if (wParam == VK_ESCAPE)
2357 c[0] = THE_KEY_ESCAPE;
2360 else if (wParam == VK_OEM_COMMA)
2365 else if (wParam == VK_OEM_PERIOD)
2369 else if (wParam == VK_DIVIDE)
2374 else if (wParam == VK_MULTIPLY)
2378 VT_ProcessKeyPress (c);
2386 VT_ProcessButton3Release();
2389 case WM_LBUTTONDOWN:
2390 case WM_MBUTTONDOWN:
2391 case WM_RBUTTONDOWN:
2393 WPARAM fwKeys = wParam;
2397 X_ButtonPress = LOWORD(lParam);
2398 Y_ButtonPress = HIWORD(lParam);
2400 if (Msg == WM_LBUTTONDOWN)
2402 if ((fwKeys & MK_CONTROL) != 0)
2404 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2408 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2411 else if (Msg == WM_RBUTTONDOWN)
2414 VT_ProcessButton3Press();
2421 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2422 if (wParam & MK_CONTROL)
2424 if (aView->Camera()->IsStereo())
2426 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2430 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2437 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2444 //cout << "\t WM_MOUSEMOVE" << endl;
2445 WPARAM fwKeys = wParam;
2446 X_Motion = LOWORD(lParam);
2447 Y_Motion = HIWORD(lParam);
2450 (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 )
2453 X_ButtonPress = LOWORD(lParam);
2454 Y_ButtonPress = HIWORD(lParam);
2456 if ((fwKeys & MK_RBUTTON) != 0) {
2458 VT_ProcessButton3Press();
2462 if ((fwKeys & MK_CONTROL) != 0)
2464 if ((fwKeys & MK_LBUTTON) != 0)
2466 ProcessControlButton1Motion();
2468 else if ((fwKeys & MK_MBUTTON) != 0
2469 || ((fwKeys & MK_LBUTTON) != 0
2470 && (fwKeys & MK_RBUTTON) != 0))
2472 VT_ProcessControlButton2Motion();
2474 else if ((fwKeys & MK_RBUTTON) != 0)
2476 VT_ProcessControlButton3Motion();
2479 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2487 return DefWindowProcW (hwnd, Msg, wParam, lParam);
2492 //==============================================================================
2493 //function : ViewerMainLoop
2494 //purpose : Get a Event on the view and dispatch it
2495 //==============================================================================
2498 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2500 Ppick = (argc > 0)? 1 : 0;
2508 cout << "Start picking" << endl;
2510 while ( Ppick == 1 ) {
2511 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2512 if (GetMessageW (&msg, NULL, 0, 0))
2514 TranslateMessage (&msg);
2515 DispatchMessageW (&msg);
2519 cout << "Picking done" << endl;
2525 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2527 int min( int a, int b )
2535 int max( int a, int b )
2543 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2546 static XEvent aReport;
2547 Standard_Boolean pick = argc > 0;
2548 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2549 XNextEvent (aDisplay, &aReport);
2551 // Handle event for the chosen display connection
2552 switch (aReport.type) {
2555 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2558 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2564 // Activate inactive view
2565 Window aWindow = GetWindowHandle(VT_GetWindow());
2566 if(aWindow != aReport.xfocus.window)
2568 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2577 case ConfigureNotify:
2579 VT_ProcessConfigure();
2588 XComposeStatus status_in_out;
2590 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2591 (char *) buf_ret , 10 ,
2592 &ks_ret , &status_in_out ) ;
2595 buf_ret[ret_len] = '\0' ;
2599 VT_ProcessKeyPress (buf_ret);
2605 X_ButtonPress = aReport.xbutton.x;
2606 Y_ButtonPress = aReport.xbutton.y;
2608 if (aReport.xbutton.button == Button1)
2610 if (aReport.xbutton.state & ControlMask)
2612 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2616 IsDragged = Standard_True;
2617 DragFirst = Standard_True;
2620 else if (aReport.xbutton.button == Button3)
2623 VT_ProcessButton3Press();
2633 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2635 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2636 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2640 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2641 if( aContext.IsNull() )
2643 cout << "The context is null. Please use vinit before createmesh" << endl;
2647 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2648 if( aReport.xbutton.button==1 )
2652 aContext->ShiftSelect (Standard_True);
2656 aContext->Select (Standard_True);
2661 aContext->ShiftSelect(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2662 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2663 ViewerTest::CurrentView(), Standard_True);
2667 aContext->Select(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2668 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2669 ViewerTest::CurrentView(), Standard_True);
2672 VT_ProcessButton3Release();
2674 IsDragged = Standard_False;
2677 VT_ProcessButton3Release();
2682 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2690 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2692 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2696 X_Motion = aReport.xmotion.x;
2697 Y_Motion = aReport.xmotion.y;
2698 DragFirst = Standard_False;
2700 Window aWindow = GetWindowHandle(VT_GetWindow());
2703 unsigned int aWidth, aHeight, aBorderWidth, aDepth;
2704 XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth);
2705 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2706 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, AIS_DS_Displayed);
2707 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2711 X_Motion = aReport.xmotion.x;
2712 Y_Motion = aReport.xmotion.y;
2714 // remove all the ButtonMotionMaskr
2715 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2717 if ( aReport.xmotion.state & ControlMask ) {
2718 if ( aReport.xmotion.state & Button1Mask ) {
2719 ProcessControlButton1Motion();
2721 else if ( aReport.xmotion.state & Button2Mask ) {
2722 VT_ProcessControlButton2Motion();
2724 else if ( aReport.xmotion.state & Button3Mask ) {
2725 VT_ProcessControlButton3Motion();
2739 //==============================================================================
2740 //function : VProcessEvents
2741 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2742 // event in the Viewer window
2743 //==============================================================================
2745 static void VProcessEvents(ClientData,int)
2747 NCollection_Vector<int> anEventNumbers;
2748 // Get number of messages from every display
2749 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2750 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2752 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2754 // Handle events for every display
2755 int anEventIter = 0;
2756 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2757 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2759 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2760 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2762 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2763 int anEventResult = ViewerMainLoop( 0, NULL);
2764 // If window is closed or context was not found finish current event processing loop
2770 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2775 //==============================================================================
2776 //function : OSWindowSetup
2777 //purpose : Setup for the X11 window to be able to cath the event
2778 //==============================================================================
2781 static void OSWindowSetup()
2783 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2786 Window window = VT_GetWindow()->XWindow();
2787 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2788 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2789 XSynchronize(aDisplay, 1);
2791 // X11 : For keyboard on SUN
2793 wmhints.flags = InputHint;
2796 XSetWMHints( aDisplay, window, &wmhints);
2798 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2799 ButtonPressMask | ButtonReleaseMask |
2800 StructureNotifyMask |
2802 Button1MotionMask | Button2MotionMask |
2803 Button3MotionMask | FocusChangeMask
2805 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2806 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2808 XSynchronize(aDisplay, 0);
2816 //==============================================================================
2819 //==============================================================================
2821 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
2823 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2826 std::cout << "Error: no active viewer!\n";
2830 Standard_Boolean toFit = Standard_True;
2831 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2832 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2834 TCollection_AsciiString anArg (theArgv[anArgIter]);
2836 if (anUpdateTool.parseRedrawMode (anArg))
2840 else if (anArg == "-selected")
2842 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
2843 toFit = Standard_False;
2847 std::cout << "Syntax error at '" << anArg << "'\n";
2853 aView->FitAll (0.01, Standard_False);
2858 //=======================================================================
2859 //function : VFitArea
2860 //purpose : Fit view to show area located between two points
2861 // : given in world 2D or 3D coordinates.
2862 //=======================================================================
2863 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2865 Handle(V3d_View) aView = ViewerTest::CurrentView();
2868 std::cerr << theArgVec[0] << "Error: No active view.\n";
2873 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2874 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2878 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2879 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2880 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2881 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2883 else if (theArgNb == 7)
2885 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2886 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2887 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2888 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2889 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2890 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2894 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2895 theDI.PrintHelp(theArgVec[0]);
2899 // Convert model coordinates to view space
2900 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2901 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2902 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2904 // Determine fit area
2905 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2906 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2908 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2910 if (aDiagonal < Precision::Confusion())
2912 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2916 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2920 //==============================================================================
2922 //purpose : ZFitall, no DRAW arguments
2923 //Draw arg : No args
2924 //==============================================================================
2925 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2927 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2929 if (aCurrentView.IsNull())
2931 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2937 aCurrentView->ZFitAll();
2938 aCurrentView->Redraw();
2942 Standard_Real aScale = 1.0;
2946 aScale = Draw::Atoi (theArgVec[1]);
2949 aCurrentView->ZFitAll (aScale);
2950 aCurrentView->Redraw();
2955 //==============================================================================
2956 //function : VRepaint
2958 //==============================================================================
2959 static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
2961 Handle(V3d_View) aView = ViewerTest::CurrentView();
2964 std::cout << "Error: no active viewer!\n";
2968 Standard_Boolean isImmediateUpdate = Standard_False;
2969 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2971 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2973 if (anArg == "-immediate")
2975 isImmediateUpdate = Standard_True;
2976 if (anArgIter + 1 < theArgNb
2977 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
2984 std::cout << "Syntax error at '" << anArg << "'\n";
2988 if (isImmediateUpdate)
2990 aView->RedrawImmediate();
2999 //==============================================================================
3001 //purpose : Remove all the object from the viewer
3002 //Draw arg : No args
3003 //==============================================================================
3005 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
3007 Handle(V3d_View) V = ViewerTest::CurrentView();
3009 ViewerTest::Clear();
3013 //==============================================================================
3016 //==============================================================================
3018 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3019 { if (ViewerTest::CurrentView().IsNull() ) return 1;
3022 di << argv[0] << "Invalid number of arguments\n";
3026 while (ViewerMainLoop( argc, argv)) {
3032 //==============================================================================
3034 //purpose : Load image as background
3035 //==============================================================================
3037 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3039 if (argc < 2 || argc > 3)
3041 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n";
3042 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n";
3046 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3047 if(AISContext.IsNull())
3049 di << "use 'vinit' command before " << argv[0] << "\n";
3053 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
3056 const char* szType = argv[2];
3057 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
3058 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
3059 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
3060 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
3063 di << "Wrong fill type : " << szType << "\n";
3064 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
3069 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3070 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
3075 //==============================================================================
3076 //function : VSetBgMode
3077 //purpose : Change background image fill type
3078 //==============================================================================
3080 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3084 di << "Usage : " << argv[0] << " filltype : Change background image mode\n";
3085 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n";
3089 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3090 if(AISContext.IsNull())
3092 di << "use 'vinit' command before " << argv[0] << "\n";
3095 Aspect_FillMethod aFillType = Aspect_FM_NONE;
3096 const char* szType = argv[1];
3097 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
3098 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
3099 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
3100 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
3103 di << "Wrong fill type : " << szType << "\n";
3104 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
3107 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3108 V3dView->SetBgImageStyle(aFillType, Standard_True);
3112 //==============================================================================
3113 //function : VSetGradientBg
3114 //purpose : Mount gradient background
3115 //==============================================================================
3116 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3120 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background\n";
3121 di << "R1,G1,B1,R2,G2,B2 = [0..255]\n";
3122 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3123 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3127 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3128 if(AISContext.IsNull())
3130 di << "use 'vinit' command before " << argv[0] << "\n";
3136 Standard_Real R1 = Draw::Atof(argv[1])/255.;
3137 Standard_Real G1 = Draw::Atof(argv[2])/255.;
3138 Standard_Real B1 = Draw::Atof(argv[3])/255.;
3139 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
3141 Standard_Real R2 = Draw::Atof(argv[4])/255.;
3142 Standard_Real G2 = Draw::Atof(argv[5])/255.;
3143 Standard_Real B2 = Draw::Atof(argv[6])/255.;
3145 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
3146 int aType = Draw::Atoi(argv[7]);
3147 if( aType < 0 || aType > 8 )
3149 di << "Wrong fill type \n";
3150 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3151 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3155 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
3157 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3158 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
3164 //==============================================================================
3165 //function : VSetGradientBgMode
3166 //purpose : Change gradient background fill style
3167 //==============================================================================
3168 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3172 di << "Usage : " << argv[0] << " Type : Change gradient background fill type\n";
3173 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3174 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3178 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3179 if(AISContext.IsNull())
3181 di << "use 'vinit' command before " << argv[0] << "\n";
3186 int aType = Draw::Atoi(argv[1]);
3187 if( aType < 0 || aType > 8 )
3189 di << "Wrong fill type \n";
3190 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3191 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3195 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
3197 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3198 V3dView->SetBgGradientStyle( aMethod, 1 );
3204 //==============================================================================
3205 //function : VSetColorBg
3206 //purpose : Set color background
3207 //==============================================================================
3208 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3212 di << "Usage : " << argv[0] << " R G B : Set color background\n";
3213 di << "R,G,B = [0..255]\n";
3217 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3218 if(AISContext.IsNull())
3220 di << "use 'vinit' command before " << argv[0] << "\n";
3226 Standard_Real R = Draw::Atof(argv[1])/255.;
3227 Standard_Real G = Draw::Atof(argv[2])/255.;
3228 Standard_Real B = Draw::Atof(argv[3])/255.;
3229 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
3231 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3232 V3dView->SetBackgroundColor( aColor );
3239 //==============================================================================
3240 //function : VSetDefaultBg
3241 //purpose : Set default viewer background fill color
3242 //==============================================================================
3243 static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3248 std::cout << "Error: wrong syntax! See usage:\n";
3249 theDI.PrintHelp (theArgVec[0]);
3253 ViewerTest_DefaultBackground.FillMethod =
3254 theArgNb == 4 ? Aspect_GFM_NONE
3255 : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]);
3259 Standard_Real R = Draw::Atof (theArgVec[1]) / 255.;
3260 Standard_Real G = Draw::Atof (theArgVec[2]) / 255.;
3261 Standard_Real B = Draw::Atof (theArgVec[3]) / 255.;
3262 ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB);
3266 Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.;
3267 Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.;
3268 Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.;
3269 ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB);
3271 Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.;
3272 Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.;
3273 Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.;
3274 ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB);
3277 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
3278 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
3280 const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer();
3281 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
3282 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
3283 ViewerTest_DefaultBackground.GradientColor2,
3284 ViewerTest_DefaultBackground.FillMethod);
3290 //==============================================================================
3292 //purpose : View Scaling
3293 //==============================================================================
3295 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3297 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3298 if ( V3dView.IsNull() ) return 1;
3301 di << argv[0] << "Invalid number of arguments\n";
3304 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
3307 //==============================================================================
3308 //function : VZBuffTrihedron
3310 //==============================================================================
3312 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
3313 Standard_Integer theArgNb,
3314 const char** theArgVec)
3316 Handle(V3d_View) aView = ViewerTest::CurrentView();
3319 std::cout << "Error: no active viewer!\n";
3323 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
3325 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
3326 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
3327 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
3328 Quantity_Color anArrowColorX = Quantity_NOC_RED;
3329 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
3330 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
3331 Standard_Real aScale = 0.1;
3332 Standard_Real aSizeRatio = 0.8;
3333 Standard_Real anArrowDiam = 0.05;
3334 Standard_Integer aNbFacets = 12;
3335 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3337 Standard_CString anArg = theArgVec[anArgIter];
3338 TCollection_AsciiString aFlag (anArg);
3340 if (anUpdateTool.parseRedrawMode (aFlag))
3344 else if (aFlag == "-on")
3348 else if (aFlag == "-off")
3350 aView->TriedronErase();
3353 else if (aFlag == "-pos"
3354 || aFlag == "-position"
3355 || aFlag == "-corner")
3357 if (++anArgIter >= theArgNb)
3359 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3363 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3364 aPosName.LowerCase();
3365 if (aPosName == "center")
3367 aPosition = Aspect_TOTP_CENTER;
3369 else if (aPosName == "left_lower"
3370 || aPosName == "lower_left"
3371 || aPosName == "leftlower"
3372 || aPosName == "lowerleft")
3374 aPosition = Aspect_TOTP_LEFT_LOWER;
3376 else if (aPosName == "left_upper"
3377 || aPosName == "upper_left"
3378 || aPosName == "leftupper"
3379 || aPosName == "upperleft")
3381 aPosition = Aspect_TOTP_LEFT_UPPER;
3383 else if (aPosName == "right_lower"
3384 || aPosName == "lower_right"
3385 || aPosName == "rightlower"
3386 || aPosName == "lowerright")
3388 aPosition = Aspect_TOTP_RIGHT_LOWER;
3390 else if (aPosName == "right_upper"
3391 || aPosName == "upper_right"
3392 || aPosName == "rightupper"
3393 || aPosName == "upperright")
3395 aPosition = Aspect_TOTP_RIGHT_UPPER;
3399 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3403 else if (aFlag == "-type")
3405 if (++anArgIter >= theArgNb)
3407 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3411 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3412 aTypeName.LowerCase();
3413 if (aTypeName == "wireframe"
3414 || aTypeName == "wire")
3416 aVisType = V3d_WIREFRAME;
3418 else if (aTypeName == "zbuffer"
3419 || aTypeName == "shaded")
3421 aVisType = V3d_ZBUFFER;
3425 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3428 else if (aFlag == "-scale")
3430 if (++anArgIter >= theArgNb)
3432 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3436 aScale = Draw::Atof (theArgVec[anArgIter]);
3438 else if (aFlag == "-size"
3439 || aFlag == "-sizeratio")
3441 if (++anArgIter >= theArgNb)
3443 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3447 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3449 else if (aFlag == "-arrowdiam"
3450 || aFlag == "-arrowdiameter")
3452 if (++anArgIter >= theArgNb)
3454 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3458 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3460 else if (aFlag == "-nbfacets")
3462 if (++anArgIter >= theArgNb)
3464 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3468 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3470 else if (aFlag == "-colorlabel"
3471 || aFlag == "-colorlabels")
3473 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3474 theArgVec + anArgIter + 1,
3478 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3481 anArgIter += aNbParsed;
3483 else if (aFlag == "-colorarrowx")
3485 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3486 theArgVec + anArgIter + 1,
3490 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3493 anArgIter += aNbParsed;
3495 else if (aFlag == "-colorarrowy")
3497 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3498 theArgVec + anArgIter + 1,
3502 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3505 anArgIter += aNbParsed;
3507 else if (aFlag == "-colorarrowz")
3509 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3510 theArgVec + anArgIter + 1,
3514 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3517 anArgIter += aNbParsed;
3521 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3526 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3527 aSizeRatio, anArrowDiam, aNbFacets);
3528 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
3533 //==============================================================================
3534 //function : VRotate
3535 //purpose : Camera Rotating
3536 //==============================================================================
3538 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3540 Handle(V3d_View) aView = ViewerTest::CurrentView();
3543 std::cout << "No active view!\n";
3547 Standard_Boolean hasFlags = Standard_False;
3548 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3550 Standard_CString anArg (theArgVec[anArgIter]);
3551 TCollection_AsciiString aFlag (anArg);
3553 if (aFlag == "-mousestart"
3554 || aFlag == "-mousefrom")
3556 hasFlags = Standard_True;
3557 if (anArgIter + 2 >= theArgNb)
3559 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3563 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3564 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3565 aView->StartRotation (anX, anY);
3567 else if (aFlag == "-mousemove")
3569 hasFlags = Standard_True;
3570 if (anArgIter + 2 >= theArgNb)
3572 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3576 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3577 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3578 aView->Rotation (anX, anY);
3580 else if (theArgNb != 4
3583 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3592 else if (theArgNb == 4)
3594 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3595 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3596 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3597 aView->Rotate (anAX, anAY, anAZ);
3600 else if (theArgNb == 7)
3602 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3603 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3604 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3606 Standard_Real anX = Draw::Atof (theArgVec[4]);
3607 Standard_Real anY = Draw::Atof (theArgVec[5]);
3608 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3610 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3614 std::cout << "Error: Invalid number of arguments\n";
3618 //==============================================================================
3620 //purpose : View zoom in / out (relative to current zoom)
3621 //==============================================================================
3623 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3624 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3625 if ( V3dView.IsNull() ) {
3630 Standard_Real coef = Draw::Atof(argv[1]);
3631 if ( coef <= 0.0 ) {
3632 di << argv[1] << "Invalid value\n";
3635 V3dView->SetZoom( Draw::Atof(argv[1]) );
3638 di << argv[0] << " Invalid number of arguments\n";
3643 //==============================================================================
3645 //purpose : View panning (in pixels)
3646 //==============================================================================
3648 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3649 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3650 if ( V3dView.IsNull() ) return 1;
3653 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
3656 di << argv[0] << " Invalid number of arguments\n";
3661 //==============================================================================
3663 //purpose : Place the point (in pixels) at the center of the window
3664 //==============================================================================
3665 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3667 Handle(V3d_View) aView = ViewerTest::CurrentView();
3670 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3676 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3680 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3685 static int VColorScale (Draw_Interpretor& theDI,
3686 Standard_Integer theArgNb,
3687 const char** theArgVec)
3689 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3690 Handle(V3d_View) aView = ViewerTest::CurrentView();
3691 if (aContext.IsNull())
3693 std::cout << "Error: no active view!\n";
3698 std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n";
3702 Handle(AIS_ColorScale) aColorScale;
3703 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
3705 // find existing object
3706 aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
3707 if (aColorScale.IsNull())
3709 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
3716 if (aColorScale.IsNull())
3718 std::cout << "Syntax error: colorscale with a given name does not exist.\n";
3722 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
3723 << "Min range: " << aColorScale->GetMin() << "\n"
3724 << "Max range: " << aColorScale->GetMax() << "\n"
3725 << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n"
3726 << "Text height: " << aColorScale->GetTextHeight() << "\n"
3727 << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n"
3728 << "Color scale title: " << aColorScale->GetTitle() << "\n"
3729 << "Label position: ";
3730 switch (aColorScale->GetLabelPosition())
3732 case Aspect_TOCSP_NONE:
3735 case Aspect_TOCSP_LEFT:
3738 case Aspect_TOCSP_RIGHT:
3741 case Aspect_TOCSP_CENTER:
3742 theDI << "Center\n";
3748 if (aColorScale.IsNull())
3750 aColorScale = new AIS_ColorScale();
3751 aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
3752 aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
3755 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
3756 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
3758 Standard_CString anArg = theArgVec[anArgIter];
3759 TCollection_AsciiString aFlag (anArg);
3761 if (anUpdateTool.parseRedrawMode (aFlag))
3765 else if (aFlag == "-range")
3767 if (anArgIter + 3 >= theArgNb)
3769 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3773 const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]);
3774 const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]);
3775 const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]);
3776 if (!aRangeMin.IsRealValue()
3777 || !aRangeMax.IsRealValue())
3779 std::cout << "Error: the range values should be real!\n";
3782 else if (!aNbIntervals.IsIntegerValue())
3784 std::cout << "Error: the number of intervals should be integer!\n";
3788 aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue());
3789 aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue());
3791 else if (aFlag == "-font")
3793 if (anArgIter + 1 >= theArgNb)
3795 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3798 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
3799 if (!aFontArg.IsIntegerValue())
3801 std::cout << "Error: HeightFont value should be integer!\n";
3805 aColorScale->SetTextHeight (aFontArg.IntegerValue());
3808 else if (aFlag == "-textpos")
3810 if (anArgIter + 1 >= theArgNb)
3812 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3816 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
3817 aTextPosArg.LowerCase();
3818 Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE;
3819 if (aTextPosArg == "none")
3821 aLabPosition = Aspect_TOCSP_NONE;
3823 else if (aTextPosArg == "left")
3825 aLabPosition = Aspect_TOCSP_LEFT;
3827 else if (aTextPosArg == "right")
3829 aLabPosition = Aspect_TOCSP_RIGHT;
3831 else if (aTextPosArg == "center")
3833 aLabPosition = Aspect_TOCSP_CENTER;
3837 std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
3840 aColorScale->SetLabelPosition (aLabPosition);
3842 else if (aFlag == "-logarithmic"
3845 if (anArgIter + 1 >= theArgNb)
3847 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3851 Standard_Boolean IsLog;
3852 if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
3854 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3857 aColorScale->SetLogarithmic (IsLog);
3859 else if (aFlag == "-huerange"
3862 if (anArgIter + 2 >= theArgNb)
3864 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3868 const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]);
3869 const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]);
3870 aColorScale->SetHueRange (aHueMin, aHueMax);
3872 else if (aFlag == "-colorrange")
3874 Quantity_Color aColorMin, aColorMax;
3875 Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3876 theArgVec + (anArgIter + 1),
3878 anArgIter += aNbParsed1;
3879 Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3880 theArgVec + (anArgIter + 1),
3882 anArgIter += aNbParsed2;
3886 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3890 aColorScale->SetColorRange (aColorMin, aColorMax);
3892 else if (aFlag == "-reversed"
3893 || aFlag == "-inverted"
3894 || aFlag == "-topdown"
3895 || aFlag == "-bottomup")
3897 Standard_Boolean toEnable = Standard_True;
3898 if (anArgIter + 1 < theArgNb
3899 && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable))
3903 aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable);
3905 else if (aFlag == "-smooth"
3906 || aFlag == "-smoothtransition")
3908 Standard_Boolean toEnable = Standard_True;
3909 if (anArgIter + 1 < theArgNb
3910 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
3914 aColorScale->SetSmoothTransition (toEnable);
3916 else if (aFlag == "-xy")
3918 if (anArgIter + 2 >= theArgNb)
3920 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3924 const TCollection_AsciiString anX (theArgVec[++anArgIter]);
3925 const TCollection_AsciiString anY (theArgVec[++anArgIter]);
3926 if (!anX.IsIntegerValue()
3927 || !anY.IsIntegerValue())
3929 std::cout << "Error: coordinates should be integer values!\n";
3933 aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue());
3935 else if (aFlag == "-width"
3937 || aFlag == "-breadth")
3939 if (anArgIter + 1 >= theArgNb)
3941 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3945 const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]);
3946 if (!aBreadth.IsIntegerValue())
3948 std::cout << "Error: a width should be an integer value!\n";
3951 aColorScale->SetBreadth (aBreadth.IntegerValue());
3953 else if (aFlag == "-height"
3956 if (anArgIter + 1 >= theArgNb)
3958 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3962 const TCollection_AsciiString aHeight (theArgVec[++anArgIter]);
3963 if (!aHeight.IsIntegerValue())
3965 std::cout << "Error: a width should be an integer value!\n";
3968 aColorScale->SetHeight (aHeight.IntegerValue());
3970 else if (aFlag == "-color")
3972 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
3974 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3977 else if (anArgIter + 2 >= theArgNb)
3979 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3983 const TCollection_AsciiString anInd (theArgVec[++anArgIter]);
3984 if (!anInd.IsIntegerValue())
3986 std::cout << "Error: Index value should be integer!\n";
3989 const Standard_Integer anIndex = anInd.IntegerValue();
3990 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals())
3992 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() <<"!\n";
3996 Quantity_Color aColor;
3997 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3998 theArgVec + (anArgIter + 1),
4002 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
4005 aColorScale->SetIntervalColor (aColor, anIndex);
4006 aColorScale->SetColorType (Aspect_TOCSD_USER);
4007 anArgIter += aNbParsed;
4009 else if (aFlag == "-label")
4011 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
4013 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
4016 else if (anArgIter + 2 >= theArgNb)
4018 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4022 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
4023 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1)
4025 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() + 1 <<"!\n";
4029 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
4030 aColorScale->SetLabel (aText, anIndex);
4031 aColorScale->SetLabelType (Aspect_TOCSD_USER);
4034 else if (aFlag == "-labelat"
4035 || aFlag == "-labat"
4036 || aFlag == "-labelatborder"
4037 || aFlag == "-labatborder"
4038 || aFlag == "-labelatcenter"
4039 || aFlag == "-labatcenter")
4041 Standard_Boolean toEnable = Standard_True;
4042 if (aFlag == "-labelat"
4043 || aFlag == "-labat")
4045 Standard_Integer aLabAtBorder = -1;
4046 if (++anArgIter >= theArgNb)
4048 TCollection_AsciiString anAtBorder (theArgVec[anArgIter]);
4049 anAtBorder.LowerCase();
4050 if (anAtBorder == "border")
4054 else if (anAtBorder == "center")
4059 if (aLabAtBorder == -1)
4061 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4064 toEnable = (aLabAtBorder == 1);
4066 else if (anArgIter + 1 < theArgNb
4067 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
4071 aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter"
4072 || aFlag == "-labatcenter"
4076 else if (aFlag == "-colors")
4078 Aspect_SequenceOfColor aSeq;
4081 Quantity_Color aColor;
4082 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4083 theArgVec + (anArgIter + 1),
4089 anArgIter += aNbParsed;
4090 aSeq.Append (aColor);
4092 if (aSeq.Length() != aColorScale->GetNumberOfIntervals())
4094 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
4095 << aColorScale->GetNumberOfIntervals() << " intervals\n";
4099 aColorScale->SetColors (aSeq);
4100 aColorScale->SetColorType (Aspect_TOCSD_USER);
4102 else if (aFlag == "-labels"
4103 || aFlag == "-freelabels")
4105 if (anArgIter + 1 >= theArgNb)
4107 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4111 Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder()
4112 ? aColorScale->GetNumberOfIntervals() + 1
4113 : aColorScale->GetNumberOfIntervals();
4114 if (aFlag == "-freelabels")
4117 aNbLabels = Draw::Atoi (theArgVec[anArgIter]);
4119 if (anArgIter + aNbLabels >= theArgNb)
4121 std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n";
4125 TColStd_SequenceOfExtendedString aSeq;
4126 for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter)
4128 aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter]));
4130 aColorScale->SetLabels (aSeq);
4131 aColorScale->SetLabelType (Aspect_TOCSD_USER);
4133 else if (aFlag == "-title")
4135 if (anArgIter + 1 >= theArgNb)
4137 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4141 Standard_Boolean isTwoArgs = Standard_False;
4142 if (anArgIter + 2 < theArgNb)
4144 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
4145 aSecondArg.LowerCase();
4146 Standard_DISABLE_DEPRECATION_WARNINGS
4147 if (aSecondArg == "none")
4149 aColorScale->SetTitlePosition (Aspect_TOCSP_NONE);
4150 isTwoArgs = Standard_True;
4152 else if (aSecondArg == "left")
4154 aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT);
4155 isTwoArgs = Standard_True;
4157 else if (aSecondArg == "right")
4159 aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT);
4160 isTwoArgs = Standard_True;
4162 else if (aSecondArg == "center")
4164 aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER);
4165 isTwoArgs = Standard_True;
4167 Standard_ENABLE_DEPRECATION_WARNINGS
4170 aColorScale->SetTitle (theArgVec[anArgIter + 1]);
4177 else if (aFlag == "-demoversion"
4178 || aFlag == "-demo")
4180 aColorScale->SetPosition (0, 0);
4181 aColorScale->SetTextHeight (16);
4182 aColorScale->SetRange (0.0, 100.0);
4183 aColorScale->SetNumberOfIntervals (10);
4184 aColorScale->SetBreadth (0);
4185 aColorScale->SetHeight (0);
4186 aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT);
4187 aColorScale->SetColorType (Aspect_TOCSD_AUTO);
4188 aColorScale->SetLabelType (Aspect_TOCSD_AUTO);
4190 else if (aFlag == "-findcolor")
4192 if (anArgIter + 1 >= theArgNb)
4194 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4198 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
4200 if (!anArg1.IsRealValue())
4202 std::cout << "Error: the value should be real!\n";
4206 Quantity_Color aColor;
4207 aColorScale->FindColor (anArg1.RealValue(), aColor);
4208 theDI << Quantity_Color::StringName (aColor.Name());
4213 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
4218 Standard_Integer aWinWidth = 0, aWinHeight = 0;
4219 aView->Window()->Size (aWinWidth, aWinHeight);
4220 if (aColorScale->GetBreadth() == 0)
4222 aColorScale->SetBreadth (aWinWidth);
4224 if (aColorScale->GetHeight() == 0)
4226 aColorScale->SetHeight (aWinHeight);
4228 aColorScale->SetToUpdate();
4229 ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True);
4233 //==============================================================================
4234 //function : VGraduatedTrihedron
4235 //purpose : Displays or hides a graduated trihedron
4236 //==============================================================================
4237 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
4238 Quantity_Color& theColor)
4240 Quantity_NameOfColor aColorName;
4241 TCollection_AsciiString aVal = theValue;
4243 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
4245 return Standard_False;
4247 theColor = Quantity_Color (aColorName);
4248 return Standard_True;
4251 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
4255 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
4256 << theArgs[0] <<"' for more information.\n";
4257 return 1; //TCL_ERROR
4260 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
4261 TCollection_AsciiString aParseKey;
4262 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
4264 TCollection_AsciiString anArg (theArgs [anArgIt]);
4266 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
4269 aParseKey.Remove (1);
4270 aParseKey.LowerCase();
4271 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
4275 if (aParseKey.IsEmpty())
4280 aMapOfArgs(aParseKey)->Append (anArg);
4284 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
4285 aMapIt.More(); aMapIt.Next())
4287 const TCollection_AsciiString& aKey = aMapIt.Key();
4288 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
4290 // Bool key, without arguments
4291 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
4292 && anArgs->IsEmpty())
4298 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
4299 && anArgs->Length() == 1)
4305 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
4306 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
4307 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
4308 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
4309 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
4314 // One string argument
4315 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
4316 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
4317 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4322 // One integer argument
4323 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
4324 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
4325 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
4326 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
4327 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
4332 // One real argument
4333 if ( aKey.IsEqual ("arrowlength")
4334 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
4339 // Two string arguments
4340 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
4341 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4346 TCollection_AsciiString aLowerKey;
4349 aLowerKey.LowerCase();
4350 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
4351 std::cout << "Type help for more information.\n";
4355 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4356 if (anAISContext.IsNull())
4358 std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n";
4362 Standard_Boolean toDisplay = Standard_True;
4363 Quantity_Color aColor;
4364 Graphic3d_GraduatedTrihedron aTrihedronData;
4365 // Process parameters
4366 Handle(TColStd_HSequenceOfAsciiString) aValues;
4367 if (aMapOfArgs.Find ("off", aValues))
4369 toDisplay = Standard_False;
4373 if (aMapOfArgs.Find ("xname", aValues))
4375 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
4377 if (aMapOfArgs.Find ("yname", aValues))
4379 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
4381 if (aMapOfArgs.Find ("zname", aValues))
4383 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
4385 if (aMapOfArgs.Find ("xdrawname", aValues))
4387 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4389 if (aMapOfArgs.Find ("ydrawname", aValues))
4391 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4393 if (aMapOfArgs.Find ("zdrawname", aValues))
4395 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4397 if (aMapOfArgs.Find ("xnameoffset", aValues))
4399 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4401 if (aMapOfArgs.Find ("ynameoffset", aValues))
4403 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4405 if (aMapOfArgs.Find ("znameoffset", aValues))
4407 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4411 if (aMapOfArgs.Find ("xnamecolor", aValues))
4413 if (!GetColor (aValues->Value(1), aColor))
4415 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
4418 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
4420 if (aMapOfArgs.Find ("ynamecolor", aValues))
4422 if (!GetColor (aValues->Value(1), aColor))
4424 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
4427 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
4429 if (aMapOfArgs.Find ("znamecolor", aValues))
4431 if (!GetColor (aValues->Value(1), aColor))
4433 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
4436 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
4438 if (aMapOfArgs.Find ("xcolor", aValues))
4440 if (!GetColor (aValues->Value(1), aColor))
4442 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
4445 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
4447 if (aMapOfArgs.Find ("ycolor", aValues))
4449 if (!GetColor (aValues->Value(1), aColor))
4451 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
4454 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
4456 if (aMapOfArgs.Find ("zcolor", aValues))
4458 if (!GetColor (aValues->Value(1), aColor))
4460 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
4463 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
4467 if (aMapOfArgs.Find ("xticks", aValues))
4469 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4471 if (aMapOfArgs.Find ("yticks", aValues))
4473 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4475 if (aMapOfArgs.Find ("zticks", aValues))
4477 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4479 if (aMapOfArgs.Find ("xticklength", aValues))
4481 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4483 if (aMapOfArgs.Find ("yticklength", aValues))
4485 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4487 if (aMapOfArgs.Find ("zticklength", aValues))
4489 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4491 if (aMapOfArgs.Find ("xdrawticks", aValues))
4493 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4495 if (aMapOfArgs.Find ("ydrawticks", aValues))
4497 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4499 if (aMapOfArgs.Find ("zdrawticks", aValues))
4501 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4505 if (aMapOfArgs.Find ("xdrawvalues", aValues))
4507 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4509 if (aMapOfArgs.Find ("ydrawvalues", aValues))
4511 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4513 if (aMapOfArgs.Find ("zdrawvalues", aValues))
4515 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4517 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
4519 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4521 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
4523 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4525 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
4527 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4531 if (aMapOfArgs.Find ("arrowlength", aValues))
4533 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
4537 if (aMapOfArgs.Find ("namefont", aValues))
4539 aTrihedronData.SetNamesFont (aValues->Value(1));
4541 if (aMapOfArgs.Find ("valuesfont", aValues))
4543 aTrihedronData.SetValuesFont (aValues->Value(1));
4546 if (aMapOfArgs.Find ("drawgrid", aValues))
4548 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
4550 if (aMapOfArgs.Find ("drawaxes", aValues))
4552 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
4555 // The final step: display of erase trihedron
4558 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
4562 ViewerTest::CurrentView()->GraduatedTrihedronErase();
4565 ViewerTest::GetAISContext()->UpdateCurrentViewer();
4566 ViewerTest::CurrentView()->Redraw();
4571 //==============================================================================
4574 //==============================================================================
4575 static int VTile (Draw_Interpretor& theDI,
4576 Standard_Integer theArgNb,
4577 const char** theArgVec)
4579 Handle(V3d_View) aView = ViewerTest::CurrentView();
4582 std::cerr << "Error: no active viewer.\n";
4586 Graphic3d_CameraTile aTile = aView->Camera()->Tile();
4589 theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
4590 << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n"
4591 << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n";
4595 aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
4596 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4598 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4600 if (anArg == "-lowerleft"
4601 || anArg == "-upperleft")
4603 if (anArgIter + 3 < theArgNb)
4605 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4608 aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
4609 aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4610 aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4612 else if (anArg == "-total"
4613 || anArg == "-totalsize"
4614 || anArg == "-viewsize")
4616 if (anArgIter + 3 < theArgNb)
4618 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4621 aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4622 aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4623 if (aTile.TotalSize.x() < 1
4624 || aTile.TotalSize.y() < 1)
4626 std::cerr << "Error: total size is incorrect.\n";
4630 else if (anArg == "-tilesize")
4632 if (anArgIter + 3 < theArgNb)
4634 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4638 aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4639 aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4640 if (aTile.TileSize.x() < 1
4641 || aTile.TileSize.y() < 1)
4643 std::cerr << "Error: tile size is incorrect.\n";
4647 else if (anArg == "-unset")
4649 aView->Camera()->SetTile (Graphic3d_CameraTile());
4655 if (aTile.TileSize.x() < 1
4656 || aTile.TileSize.y() < 1)
4658 std::cerr << "Error: tile size is undefined.\n";
4661 else if (aTile.TotalSize.x() < 1
4662 || aTile.TotalSize.y() < 1)
4664 std::cerr << "Error: total size is undefined.\n";
4668 aView->Camera()->SetTile (aTile);
4673 //! Format ZLayer ID.
4674 inline const char* formZLayerId (const Standard_Integer theLayerId)
4678 case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]";
4679 case Graphic3d_ZLayerId_Default: return "[DEFAULT]";
4680 case Graphic3d_ZLayerId_Top: return "[TOP]";
4681 case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]";
4682 case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]";
4683 case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]";
4688 //! Print the ZLayer information.
4689 inline void printZLayerInfo (Draw_Interpretor& theDI,
4690 const Graphic3d_ZLayerSettings& theLayer)
4692 if (!theLayer.Name().IsEmpty())
4694 theDI << " Name: " << theLayer.Name() << "\n";
4696 if (theLayer.IsImmediate())
4698 theDI << " Immediate: TRUE\n";
4700 theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n";
4701 theDI << " Culling distance: " << theLayer.CullingDistance() << "\n";
4702 theDI << " Culling size: " << theLayer.CullingSize() << "\n";
4703 theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n";
4704 theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n";
4705 theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n";
4706 if (theLayer.PolygonOffset().Mode != Aspect_POM_None)
4708 theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n";
4712 //==============================================================================
4713 //function : VZLayer
4714 //purpose : Test z layer operations for v3d viewer
4715 //==============================================================================
4716 static int VZLayer (Draw_Interpretor& theDI,
4717 Standard_Integer theArgNb,
4718 const char** theArgVec)
4720 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4721 if (aContextAIS.IsNull())
4723 std::cout << "No active viewer!\n";
4727 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
4730 TColStd_SequenceOfInteger aLayers;
4731 aViewer->GetAllZLayers (aLayers);
4732 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4734 theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n";
4735 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4736 printZLayerInfo (theDI, aSettings);
4741 Standard_Integer anArgIter = 1;
4742 Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4743 ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView());
4744 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
4749 TCollection_AsciiString aFirstArg (theArgVec[anArgIter]);
4750 if (aFirstArg.IsIntegerValue())
4753 aLayerId = aFirstArg.IntegerValue();
4757 aFirstArg.LowerCase();
4758 if (aFirstArg == "default"
4759 || aFirstArg == "def")
4761 aLayerId = Graphic3d_ZLayerId_Default;
4764 else if (aFirstArg == "top")
4766 aLayerId = Graphic3d_ZLayerId_Top;
4769 else if (aFirstArg == "topmost")
4771 aLayerId = Graphic3d_ZLayerId_Topmost;
4774 else if (aFirstArg == "overlay"
4775 || aFirstArg == "toposd")
4777 aLayerId = Graphic3d_ZLayerId_TopOSD;
4780 else if (aFirstArg == "underlay"
4781 || aFirstArg == "botosd")
4783 aLayerId = Graphic3d_ZLayerId_BotOSD;
4788 TColStd_SequenceOfInteger aLayers;
4789 aViewer->GetAllZLayers (aLayers);
4790 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4792 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4793 if (TCollection_AsciiString::IsSameString (aSettings.Name(), aFirstArg, Standard_False))
4795 aLayerId = aLayeriter.Value();
4803 for (; anArgIter < theArgNb; ++anArgIter)
4805 // perform operation
4806 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4808 if (anUpdateTool.parseRedrawMode (anArg))
4812 else if (anArg == "-add"
4815 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4816 if (!aViewer->AddZLayer (aLayerId))
4818 std::cout << "Error: can not add a new z layer!\n";
4824 else if (anArg == "-del"
4825 || anArg == "-delete"
4828 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4830 if (++anArgIter >= theArgNb)
4832 std::cout << "Syntax error: id of z layer to remove is missing\n";
4836 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4839 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN
4840 || aLayerId == Graphic3d_ZLayerId_Default
4841 || aLayerId == Graphic3d_ZLayerId_Top
4842 || aLayerId == Graphic3d_ZLayerId_Topmost
4843 || aLayerId == Graphic3d_ZLayerId_TopOSD
4844 || aLayerId == Graphic3d_ZLayerId_BotOSD)
4846 std::cout << "Syntax error: standard Z layer can not be removed\n";
4850 // move all object displayed in removing layer to default layer
4851 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4852 anObjIter.More(); anObjIter.Next())
4854 const Handle(AIS_InteractiveObject)& aPrs = anObjIter.Key1();
4856 || aPrs->ZLayer() != aLayerId)
4860 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4863 if (!aViewer->RemoveZLayer (aLayerId))
4865 std::cout << "Z layer can not be removed!\n";
4869 theDI << aLayerId << " ";
4872 else if (anArg == "-get"
4875 TColStd_SequenceOfInteger aLayers;
4876 aViewer->GetAllZLayers (aLayers);
4877 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4879 theDI << aLayeriter.Value() << " ";
4884 else if (anArg == "-name")
4886 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4888 std::cout << "Syntax error: id of Z layer is missing\n";
4892 if (++anArgIter >= theArgNb)
4894 std::cout << "Syntax error: name is missing\n";
4898 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4899 aSettings.SetName (theArgVec[anArgIter]);
4900 aViewer->SetZLayerSettings (aLayerId, aSettings);
4902 else if (anArg == "-origin")
4904 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4906 std::cout << "Syntax error: id of Z layer is missing\n";
4910 if (anArgIter + 2 >= theArgNb)
4912 std::cout << "Syntax error: origin coordinates are missing\n";
4916 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4918 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1]));
4919 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2]));
4920 anOrigin.SetZ (0.0);
4921 if (anArgIter + 3 < theArgNb)
4923 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3]));
4930 aSettings.SetOrigin (anOrigin);
4931 aViewer->SetZLayerSettings (aLayerId, aSettings);
4933 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
4934 && anArgIter + 1 < theArgNb
4935 && (anArg == "-cullingdistance"
4936 || anArg == "-cullingdist"
4937 || anArg == "-culldistance"
4938 || anArg == "-culldist"
4939 || anArg == "-distcull"
4940 || anArg == "-distculling"
4941 || anArg == "-distanceculling"))
4943 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4944 const Standard_Real aDist = Draw::Atof (theArgVec[++anArgIter]);
4945 aSettings.SetCullingDistance (aDist);
4946 aViewer->SetZLayerSettings (aLayerId, aSettings);
4948 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
4949 && anArgIter + 1 < theArgNb
4950 && (anArg == "-cullingsize"
4951 || anArg == "-cullsize"
4952 || anArg == "-sizecull"
4953 || anArg == "-sizeculling"))
4955 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4956 const Standard_Real aSize = Draw::Atof (theArgVec[++anArgIter]);
4957 aSettings.SetCullingSize (aSize);
4958 aViewer->SetZLayerSettings (aLayerId, aSettings);
4960 else if (anArg == "-settings"
4961 || anArg == "settings")
4963 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4965 if (++anArgIter >= theArgNb)
4967 std::cout << "Syntax error: id of Z layer is missing\n";
4971 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4974 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4975 printZLayerInfo (theDI, aSettings);
4977 else if (anArg == "-enable"
4978 || anArg == "enable"
4979 || anArg == "-disable"
4980 || anArg == "disable")
4982 const Standard_Boolean toEnable = anArg == "-enable"
4983 || anArg == "enable";
4984 if (++anArgIter >= theArgNb)
4986 std::cout << "Syntax error: option name is missing\n";
4990 TCollection_AsciiString aSubOp (theArgVec[anArgIter]);
4992 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4994 if (++anArgIter >= theArgNb)
4996 std::cout << "Syntax error: id of Z layer is missing\n";
5000 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
5003 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
5004 if (aSubOp == "depthtest"
5005 || aSubOp == "test")
5007 aSettings.SetEnableDepthTest (toEnable);
5009 else if (aSubOp == "depthwrite"
5010 || aSubOp == "write")
5012 aSettings.SetEnableDepthWrite (toEnable);
5014 else if (aSubOp == "depthclear"
5015 || aSubOp == "clear")
5017 aSettings.SetClearDepth (toEnable);
5019 else if (aSubOp == "depthoffset"
5020 || aSubOp == "offset")
5022 Graphic3d_PolygonOffset aParams;
5023 aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None;
5026 if (anArgIter + 2 >= theArgNb)
5028 std::cout << "Syntax error: factor and units values for depth offset are missing\n";
5032 aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5033 aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
5035 aSettings.SetPolygonOffset (aParams);
5037 else if (aSubOp == "positiveoffset"
5038 || aSubOp == "poffset")
5042 aSettings.SetDepthOffsetPositive();
5046 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
5049 else if (aSubOp == "negativeoffset"
5050 || aSubOp == "noffset")
5054 aSettings.SetDepthOffsetNegative();
5058 aSettings.SetPolygonOffset(Graphic3d_PolygonOffset());
5061 else if (aSubOp == "textureenv")
5063 aSettings.SetEnvironmentTexture (toEnable);
5066 aViewer->SetZLayerSettings (aLayerId, aSettings);
5070 std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n";
5078 // The interactive presentation of 2d layer item
5079 // for "vlayerline" command it provides a presentation of
5080 // line with user-defined linewidth, linetype and transparency.
5081 class V3d_LineItem : public AIS_InteractiveObject
5085 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
5088 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5089 Standard_Real X2, Standard_Real Y2,
5090 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
5091 Standard_Real theWidth = 0.5,
5092 Standard_Real theTransp = 1.0);
5096 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
5097 const Handle(Prs3d_Presentation)& thePresentation,
5098 const Standard_Integer theMode) Standard_OVERRIDE;
5100 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
5101 const Standard_Integer /*aMode*/) Standard_OVERRIDE
5106 Standard_Real myX1, myY1, myX2, myY2;
5107 Aspect_TypeOfLine myType;
5108 Standard_Real myWidth;
5111 // default constructor for line item
5112 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5113 Standard_Real X2, Standard_Real Y2,
5114 Aspect_TypeOfLine theType,
5115 Standard_Real theWidth,
5116 Standard_Real theTransp) :
5117 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
5118 myType(theType), myWidth(theWidth)
5120 SetTransparency (1-theTransp);
5124 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
5125 const Handle(Prs3d_Presentation)& thePresentation,
5126 const Standard_Integer /*theMode*/)
5128 thePresentation->Clear();
5129 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
5130 Standard_Integer aWidth, aHeight;
5131 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
5132 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
5133 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
5134 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
5135 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
5136 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
5137 aGroup->SetPrimitivesAspect (anAspect->Aspect());
5138 aGroup->AddPrimitiveArray (aPrim);
5141 //=============================================================================
5142 //function : VLayerLine
5143 //purpose : Draws line in the v3d view layer with given attributes: linetype,
5144 // : linewidth, transparency coefficient
5145 //============================================================================
5146 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5148 // get the active view
5149 Handle(V3d_View) aView = ViewerTest::CurrentView();
5152 di << "Call vinit before!\n";
5157 di << "Use: " << argv[0];
5158 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
5159 di << " linetype : { 0 | 1 | 2 | 3 } \n";
5160 di << " 0 - solid \n";
5161 di << " 1 - dashed \n";
5162 di << " 2 - dot \n";
5163 di << " 3 - dashdot\n";
5164 di << " transparency : { 0.0 - 1.0 } \n";
5165 di << " 0.0 - transparent\n";
5166 di << " 1.0 - visible \n";
5170 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5171 // get the input params
5172 Standard_Real X1 = Draw::Atof(argv[1]);
5173 Standard_Real Y1 = Draw::Atof(argv[2]);
5174 Standard_Real X2 = Draw::Atof(argv[3]);
5175 Standard_Real Y2 = Draw::Atof(argv[4]);
5177 Standard_Real aWidth = 0.5;
5178 Standard_Real aTransparency = 1.0;
5182 aWidth = Draw::Atof(argv[5]);
5184 // select appropriate line type
5185 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
5187 && !ViewerTest::ParseLineType (argv[6], aLineType))
5189 std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n";
5196 aTransparency = Draw::Atof(argv[7]);
5197 if (aTransparency < 0 || aTransparency > 1.0)
5198 aTransparency = 1.0;
5201 static Handle (V3d_LineItem) aLine;
5202 if (!aLine.IsNull())
5204 aContext->Erase (aLine, Standard_False);
5206 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
5210 aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
5211 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
5212 aLine->SetToUpdate();
5213 aContext->Display (aLine, Standard_True);
5219 //==============================================================================
5222 //==============================================================================
5224 static int VGrid (Draw_Interpretor& /*theDI*/,
5225 Standard_Integer theArgNb,
5226 const char** theArgVec)
5228 // get the active view
5229 Handle(V3d_View) aView = ViewerTest::CurrentView();
5230 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5231 if (aView.IsNull() || aViewer.IsNull())
5233 std::cerr << "No active view. Please call vinit.\n";
5237 Aspect_GridType aType = aViewer->GridType();
5238 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
5239 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
5240 Standard_Integer anIter = 1;
5241 for (; anIter < theArgNb; ++anIter)
5243 const char* aValue = theArgVec[anIter];
5244 if (anUpdateTool.parseRedrawMode (aValue))
5248 else if (*aValue == 'r')
5250 aType = Aspect_GT_Rectangular;
5252 else if (*aValue == 'c')
5254 aType = Aspect_GT_Circular;
5256 else if (*aValue == 'l')
5258 aMode = Aspect_GDM_Lines;
5260 else if (*aValue == 'p')
5262 aMode = Aspect_GDM_Points;
5264 else if (strcmp (aValue, "off" ) == 0)
5266 aViewer->DeactivateGrid();
5275 Standard_Integer aTail = (theArgNb - anIter);
5278 aViewer->ActivateGrid (aType, aMode);
5281 else if (aTail != 2 && aTail != 5)
5283 std::cerr << "Incorrect arguments number! Usage:\n"
5284 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
5288 Standard_Real anOriginX, anOriginY, aRotAngle;
5289 if (aType == Aspect_GT_Rectangular)
5291 Standard_Real aRStepX, aRStepY;
5292 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
5294 anOriginX = Draw::Atof (theArgVec[anIter++]);
5295 anOriginY = Draw::Atof (theArgVec[anIter++]);
5298 aRStepX = Draw::Atof (theArgVec[anIter++]);
5299 aRStepY = Draw::Atof (theArgVec[anIter++]);
5300 aRotAngle = Draw::Atof (theArgVec[anIter++]);
5302 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
5303 aViewer->ActivateGrid (aType, aMode);
5305 else if (aType == Aspect_GT_Circular)
5307 Standard_Real aRadiusStep;
5308 Standard_Integer aDivisionNumber;
5309 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
5311 anOriginX = Draw::Atof (theArgVec[anIter++]);
5312 anOriginY = Draw::Atof (theArgVec[anIter++]);
5315 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
5316 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
5317 aRotAngle = Draw::Atof (theArgVec[anIter++]);
5320 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
5321 aViewer->ActivateGrid (aType, aMode);
5327 //==============================================================================
5328 //function : VPriviledgedPlane
5330 //==============================================================================
5332 static int VPriviledgedPlane (Draw_Interpretor& theDI,
5333 Standard_Integer theArgNb,
5334 const char** theArgVec)
5336 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
5338 std::cerr << "Error: wrong number of arguments! See usage:\n";
5339 theDI.PrintHelp (theArgVec[0]);
5343 // get the active viewer
5344 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5345 if (aViewer.IsNull())
5347 std::cerr << "Error: no active viewer. Please call vinit.\n";
5353 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
5354 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
5355 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
5356 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
5357 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
5358 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
5359 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
5363 Standard_Integer anArgIdx = 1;
5364 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
5365 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
5366 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
5367 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
5368 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
5369 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
5371 gp_Ax3 aPriviledgedPlane;
5372 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
5373 gp_Dir aNorm (aNormX, aNormY, aNormZ);
5376 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
5377 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
5378 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
5379 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
5380 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
5384 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
5387 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
5392 //==============================================================================
5393 //function : VConvert
5395 //==============================================================================
5397 static int VConvert (Draw_Interpretor& theDI,
5398 Standard_Integer theArgNb,
5399 const char** theArgVec)
5401 // get the active view
5402 Handle(V3d_View) aView = ViewerTest::CurrentView();
5405 std::cerr << "Error: no active view. Please call vinit.\n";
5409 enum { Model, Ray, View, Window, Grid } aMode = Model;
5411 // access coordinate arguments
5412 TColStd_SequenceOfReal aCoord;
5413 Standard_Integer anArgIdx = 1;
5414 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
5416 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5417 if (!anArg.IsRealValue())
5421 aCoord.Append (anArg.RealValue());
5424 // non-numeric argument too early
5425 if (aCoord.IsEmpty())
5427 std::cerr << "Error: wrong number of arguments! See usage:\n";
5428 theDI.PrintHelp (theArgVec[0]);
5432 // collect all other arguments and options
5433 for (; anArgIdx < theArgNb; ++anArgIdx)
5435 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5437 if (anArg == "window") aMode = Window;
5438 else if (anArg == "view") aMode = View;
5439 else if (anArg == "grid") aMode = Grid;
5440 else if (anArg == "ray") aMode = Ray;
5443 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
5444 theDI.PrintHelp (theArgVec[0]);
5449 // complete input checks
5450 if ((aCoord.Length() == 1 && theArgNb > 3) ||
5451 (aCoord.Length() == 2 && theArgNb > 4) ||
5452 (aCoord.Length() == 3 && theArgNb > 5))
5454 std::cerr << "Error: wrong number of arguments! See usage:\n";
5455 theDI.PrintHelp (theArgVec[0]);
5459 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
5460 Standard_Integer aXYp[2] = {0, 0};
5462 // convert one-dimensional coordinate
5463 if (aCoord.Length() == 1)
5467 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0;
5468 case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0;
5470 std::cerr << "Error: wrong arguments! See usage:\n";
5471 theDI.PrintHelp (theArgVec[0]);
5476 // convert 2D coordinates from projection or view reference space
5477 if (aCoord.Length() == 2)
5482 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5483 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5487 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5488 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5492 aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]);
5493 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5497 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5498 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5499 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5503 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5504 (Standard_Integer) aCoord (2),
5505 aXYZ[0], aXYZ[1], aXYZ[2],
5506 aXYZ[3], aXYZ[4], aXYZ[5]);
5507 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5511 std::cerr << "Error: wrong arguments! See usage:\n";
5512 theDI.PrintHelp (theArgVec[0]);
5517 // convert 3D coordinates from view reference space
5518 else if (aCoord.Length() == 3)
5523 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5524 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5528 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5529 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5533 std::cerr << "Error: wrong arguments! See usage:\n";
5534 theDI.PrintHelp (theArgVec[0]);
5542 //==============================================================================
5545 //==============================================================================
5547 static int VFps (Draw_Interpretor& theDI,
5548 Standard_Integer theArgNb,
5549 const char** theArgVec)
5551 // get the active view
5552 Handle(V3d_View) aView = ViewerTest::CurrentView();
5555 std::cerr << "No active view. Please call vinit.\n";
5559 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
5562 std::cerr << "Incorrect arguments!\n";
5566 // the time is meaningless for first call
5567 // due to async OpenGl rendering
5570 // redraw view in loop to estimate average values
5573 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
5579 const Standard_Real aTime = aTimer.ElapsedTime();
5580 aTimer.OSD_Chronometer::Show (aCpu);
5582 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
5583 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
5585 // return statistics
5586 theDI << "FPS: " << aFpsAver << "\n"
5587 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5589 // compute additional statistics in ray-tracing mode
5590 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
5592 if (aParams.Method == Graphic3d_RM_RAYTRACING)
5594 Standard_Integer aSizeX;
5595 Standard_Integer aSizeY;
5597 aView->Window()->Size (aSizeX, aSizeY);
5599 // 1 shadow ray and 1 secondary ray pew each bounce
5600 const Standard_Real aMRays = aSizeX * aSizeY * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
5602 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
5608 //! Auxiliary function for parsing glsl dump level argument.
5609 static Standard_Boolean parseGlslSourceFlag (Standard_CString theArg,
5610 OpenGl_ShaderProgramDumpLevel& theGlslDumpLevel)
5612 TCollection_AsciiString aTypeStr (theArg);
5613 aTypeStr.LowerCase();
5614 if (aTypeStr == "off"
5617 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
5619 else if (aTypeStr == "short")
5621 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Short;
5623 else if (aTypeStr == "full"
5626 theGlslDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
5630 return Standard_False;
5632 return Standard_True;
5635 //==============================================================================
5636 //function : VGlDebug
5638 //==============================================================================
5640 static int VGlDebug (Draw_Interpretor& theDI,
5641 Standard_Integer theArgNb,
5642 const char** theArgVec)
5644 Handle(OpenGl_GraphicDriver) aDriver;
5645 Handle(V3d_View) aView = ViewerTest::CurrentView();
5646 if (!aView.IsNull())
5648 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5650 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
5651 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
5655 TCollection_AsciiString aDebActive, aSyncActive;
5662 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
5663 "GL_ARB_debug_output");
5664 aDebActive = isActive ? " (active)" : " (inactive)";
5667 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
5668 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
5672 TCollection_AsciiString aGlslCodeDebugStatus = TCollection_AsciiString()
5673 + "glslSourceCode: "
5674 + (aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Off
5676 : aCaps->glslDumpLevel == OpenGl_ShaderProgramDumpLevel_Short
5680 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
5681 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
5682 << "glslWarn: " << (aCaps->glslWarnings ? "1" : "0") << "\n"
5683 << aGlslCodeDebugStatus
5684 << "extraMsg: " << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
5688 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5690 Standard_CString anArg = theArgVec[anArgIter];
5691 TCollection_AsciiString anArgCase (anArg);
5692 anArgCase.LowerCase();
5693 Standard_Boolean toEnableDebug = Standard_True;
5694 if (anArgCase == "-glsl"
5695 || anArgCase == "-glslwarn"
5696 || anArgCase == "-glslwarns"
5697 || anArgCase == "-glslwarnings")
5699 Standard_Boolean toShowWarns = Standard_True;
5700 if (++anArgIter < theArgNb
5701 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
5705 aDefCaps->glslWarnings = toShowWarns;
5708 aCaps->glslWarnings = toShowWarns;
5711 else if (anArgCase == "-extra"
5712 || anArgCase == "-extramsg"
5713 || anArgCase == "-extramessages")
5715 Standard_Boolean toShow = Standard_True;
5716 if (++anArgIter < theArgNb
5717 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
5721 aDefCaps->suppressExtraMsg = !toShow;
5724 aCaps->suppressExtraMsg = !toShow;
5727 else if (anArgCase == "-noextra"
5728 || anArgCase == "-noextramsg"
5729 || anArgCase == "-noextramessages")
5731 Standard_Boolean toSuppress = Standard_True;
5732 if (++anArgIter < theArgNb
5733 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
5737 aDefCaps->suppressExtraMsg = toSuppress;
5740 aCaps->suppressExtraMsg = toSuppress;
5743 else if (anArgCase == "-sync")
5745 Standard_Boolean toSync = Standard_True;
5746 if (++anArgIter < theArgNb
5747 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
5751 aDefCaps->contextSyncDebug = toSync;
5754 aDefCaps->contextDebug = Standard_True;
5757 else if (anArgCase == "-glslsourcecode"
5758 || anArgCase == "-glslcode")
5760 OpenGl_ShaderProgramDumpLevel aGslsDumpLevel = OpenGl_ShaderProgramDumpLevel_Full;
5761 if (++anArgIter < theArgNb
5762 && !parseGlslSourceFlag (theArgVec[anArgIter], aGslsDumpLevel))
5766 aDefCaps->glslDumpLevel = aGslsDumpLevel;
5769 aCaps->glslDumpLevel = aGslsDumpLevel;
5772 else if (anArgCase == "-debug")
5774 if (++anArgIter < theArgNb
5775 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
5779 aDefCaps->contextDebug = toEnableDebug;
5781 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
5782 && (anArgIter + 1 == theArgNb))
5784 // simple alias to turn on almost everything
5785 aDefCaps->contextDebug = toEnableDebug;
5786 aDefCaps->contextSyncDebug = toEnableDebug;
5787 aDefCaps->glslWarnings = toEnableDebug;
5790 aDefCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
5792 aDefCaps->suppressExtraMsg = !toEnableDebug;
5795 aCaps->contextDebug = toEnableDebug;
5796 aCaps->contextSyncDebug = toEnableDebug;
5797 aCaps->glslWarnings = toEnableDebug;
5800 aCaps->glslDumpLevel = OpenGl_ShaderProgramDumpLevel_Off;
5802 aCaps->suppressExtraMsg = !toEnableDebug;
5807 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
5815 //==============================================================================
5818 //==============================================================================
5820 static int VVbo (Draw_Interpretor& theDI,
5821 Standard_Integer theArgNb,
5822 const char** theArgVec)
5824 const Standard_Boolean toSet = (theArgNb > 1);
5825 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
5828 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
5832 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5833 if (aContextAIS.IsNull())
5837 std::cerr << "No active view!\n";
5841 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5842 if (!aDriver.IsNull())
5846 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
5850 aDriver->ChangeOptions().vboDisable = toUseVbo;
5857 //==============================================================================
5860 //==============================================================================
5862 static int VCaps (Draw_Interpretor& theDI,
5863 Standard_Integer theArgNb,
5864 const char** theArgVec)
5866 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
5867 Handle(OpenGl_GraphicDriver) aDriver;
5868 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5869 if (!aContext.IsNull())
5871 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
5872 aCaps = &aDriver->ChangeOptions();
5877 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
5878 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
5879 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
5880 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
5881 theDI << "VSync: " << aCaps->swapInterval << "\n";
5882 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
5883 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
5884 theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n";
5888 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5889 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5891 Standard_CString anArg = theArgVec[anArgIter];
5892 TCollection_AsciiString anArgCase (anArg);
5893 anArgCase.LowerCase();
5894 if (anUpdateTool.parseRedrawMode (anArg))
5898 else if (anArgCase == "-vsync"
5899 || anArgCase == "-swapinterval")
5901 Standard_Boolean toEnable = Standard_True;
5902 if (++anArgIter < theArgNb
5903 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5907 aCaps->swapInterval = toEnable;
5909 else if (anArgCase == "-ffp")
5911 Standard_Boolean toEnable = Standard_True;
5912 if (++anArgIter < theArgNb
5913 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5917 aCaps->ffpEnable = toEnable;
5919 else if (anArgCase == "-vbo")
5921 Standard_Boolean toEnable = Standard_True;
5922 if (++anArgIter < theArgNb
5923 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5927 aCaps->vboDisable = !toEnable;
5929 else if (anArgCase == "-sprite"
5930 || anArgCase == "-sprites")
5932 Standard_Boolean toEnable = Standard_True;
5933 if (++anArgIter < theArgNb
5934 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5938 aCaps->pntSpritesDisable = !toEnable;
5940 else if (anArgCase == "-softmode")
5942 Standard_Boolean toEnable = Standard_True;
5943 if (++anArgIter < theArgNb
5944 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5948 aCaps->contextNoAccel = toEnable;
5950 else if (anArgCase == "-winbuffer"
5951 || anArgCase == "-windowbuffer"
5952 || anArgCase == "-usewinbuffer"
5953 || anArgCase == "-usewindowbuffer"
5954 || anArgCase == "-usesystembuffer")
5956 Standard_Boolean toEnable = Standard_True;
5957 if (++anArgIter < theArgNb
5958 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5962 aCaps->useSystemBuffer = toEnable;
5964 else if (anArgCase == "-accel"
5965 || anArgCase == "-acceleration")
5967 Standard_Boolean toEnable = Standard_True;
5968 if (++anArgIter < theArgNb
5969 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5973 aCaps->contextNoAccel = !toEnable;
5975 else if (anArgCase == "-compat"
5976 || anArgCase == "-compatprofile"
5977 || anArgCase == "-compatible"
5978 || anArgCase == "-compatibleprofile")
5980 Standard_Boolean toEnable = Standard_True;
5981 if (++anArgIter < theArgNb
5982 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5986 aCaps->contextCompatible = toEnable;
5987 if (!aCaps->contextCompatible)
5989 aCaps->ffpEnable = Standard_False;
5992 else if (anArgCase == "-core"
5993 || anArgCase == "-coreprofile")
5995 Standard_Boolean toEnable = Standard_True;
5996 if (++anArgIter < theArgNb
5997 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6001 aCaps->contextCompatible = !toEnable;
6002 if (!aCaps->contextCompatible)
6004 aCaps->ffpEnable = Standard_False;
6007 else if (anArgCase == "-stereo"
6008 || anArgCase == "-quadbuffer")
6010 Standard_Boolean toEnable = Standard_True;
6011 if (++anArgIter < theArgNb
6012 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
6016 aCaps->contextStereo = toEnable;
6020 std::cout << "Error: unknown argument '" << anArg << "'\n";
6024 if (aCaps != &ViewerTest_myDefaultCaps)
6026 ViewerTest_myDefaultCaps = *aCaps;
6031 //==============================================================================
6032 //function : VMemGpu
6034 //==============================================================================
6036 static int VMemGpu (Draw_Interpretor& theDI,
6037 Standard_Integer theArgNb,
6038 const char** theArgVec)
6041 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
6042 if (aContextAIS.IsNull())
6044 std::cerr << "No active view. Please call vinit.\n";
6048 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
6049 if (aDriver.IsNull())
6051 std::cerr << "Graphic driver not available.\n";
6055 Standard_Size aFreeBytes = 0;
6056 TCollection_AsciiString anInfo;
6057 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
6059 std::cerr << "Information not available.\n";
6063 if (theArgNb > 1 && *theArgVec[1] == 'f')
6065 theDI << Standard_Real (aFreeBytes);
6075 // ==============================================================================
6076 // function : VReadPixel
6078 // ==============================================================================
6079 static int VReadPixel (Draw_Interpretor& theDI,
6080 Standard_Integer theArgNb,
6081 const char** theArgVec)
6083 // get the active view
6084 Handle(V3d_View) aView = ViewerTest::CurrentView();
6087 std::cerr << "No active view. Please call vinit.\n";
6090 else if (theArgNb < 3)
6092 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
6096 Image_Format aFormat = Image_Format_RGBA;
6097 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
6099 Standard_Integer aWidth, aHeight;
6100 aView->Window()->Size (aWidth, aHeight);
6101 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
6102 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
6103 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
6105 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
6109 Standard_Boolean toShowName = Standard_False;
6110 Standard_Boolean toShowHls = Standard_False;
6111 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
6113 TCollection_AsciiString aParam (theArgVec[anIter]);
6115 if (aParam == "rgb")
6117 aFormat = Image_Format_RGB;
6118 aBufferType = Graphic3d_BT_RGB;
6120 else if (aParam == "hls")
6122 aFormat = Image_Format_RGB;
6123 aBufferType = Graphic3d_BT_RGB;
6124 toShowHls = Standard_True;
6126 else if (aParam == "rgbf")
6128 aFormat = Image_Format_RGBF;
6129 aBufferType = Graphic3d_BT_RGB;
6131 else if (aParam == "rgba")
6133 aFormat = Image_Format_RGBA;
6134 aBufferType = Graphic3d_BT_RGBA;
6136 else if (aParam == "rgbaf")
6138 aFormat = Image_Format_RGBAF;
6139 aBufferType = Graphic3d_BT_RGBA;
6141 else if (aParam == "depth")
6143 aFormat = Image_Format_GrayF;
6144 aBufferType = Graphic3d_BT_Depth;
6146 else if (aParam == "name")
6148 toShowName = Standard_True;
6152 Image_PixMap anImage;
6153 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
6155 std::cerr << "Image allocation failed\n";
6158 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
6160 std::cerr << "Image dump failed\n";
6164 // redirect possible warning messages that could have been added by ToPixMap
6165 // into the Tcl interpretor (via DefaultMessenger) to cout, so that they do not
6166 // contaminate result of the command
6167 Standard_CString aWarnLog = theDI.Result();
6168 if (aWarnLog != NULL && aWarnLog[0] != '\0')
6170 std::cout << aWarnLog << std::endl;
6174 Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY);
6177 if (aBufferType == Graphic3d_BT_RGBA)
6179 theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha();
6183 theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
6188 switch (aBufferType)
6191 case Graphic3d_BT_RGB:
6195 theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation();
6199 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue();
6203 case Graphic3d_BT_RGBA:
6205 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue() << " " << aColor.Alpha();
6208 case Graphic3d_BT_Depth:
6210 theDI << aColor.GetRGB().Red();
6219 //! Auxiliary presentation for an image plane.
6220 class ViewerTest_ImagePrs : public AIS_InteractiveObject
6223 //! Main constructor.
6224 ViewerTest_ImagePrs (const Handle(Image_PixMap)& theImage,
6225 const Standard_Real theWidth,
6226 const Standard_Real theHeight,
6227 const TCollection_AsciiString& theLabel)
6228 : myLabel (theLabel), myWidth (theWidth), myHeight(theHeight)
6232 myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost);
6234 myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
6235 const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect();
6236 Graphic3d_MaterialAspect aMat;
6237 aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC);
6238 aMat.SetAmbient (1.0);
6239 aMat.SetDiffuse (1.0);
6240 aMat.SetSpecular (1.0);
6241 aMat.SetEmissive (1.0);
6242 aMat.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
6243 aMat.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
6244 aMat.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
6245 aMat.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
6246 aMat.SetAmbientColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6247 aMat.SetDiffuseColor (Quantity_Color (1.0, 1.0, 1.0, Quantity_TOC_RGB));
6248 aMat.SetSpecularColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6249 aMat.SetEmissiveColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6250 aFillAspect->SetFrontMaterial (aMat);
6251 aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage));
6252 aFillAspect->SetTextureMapOn();
6255 Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect();
6256 aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER);
6257 aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER);
6258 myDrawer->SetTextAspect (aTextAspect);
6261 const gp_Dir aNorm (0.0, 0.0, 1.0);
6262 myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true);
6263 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0));
6264 myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0));
6265 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0));
6266 myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0));
6267 myTris->AddEdge (1);
6268 myTris->AddEdge (2);
6269 myTris->AddEdge (3);
6270 myTris->AddEdge (3);
6271 myTris->AddEdge (2);
6272 myTris->AddEdge (4);
6274 myRect = new Graphic3d_ArrayOfPolylines (4);
6275 myRect->AddVertex (myTris->Vertice (1));
6276 myRect->AddVertex (myTris->Vertice (3));
6277 myRect->AddVertex (myTris->Vertice (4));
6278 myRect->AddVertex (myTris->Vertice (2));
6282 //! Returns TRUE for accepted display modes.
6283 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; }
6285 //! Compute presentation.
6286 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& , const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) Standard_OVERRIDE
6292 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
6293 aGroup->AddPrimitiveArray (myTris);
6294 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
6295 aGroup->AddPrimitiveArray (myRect);
6296 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
6301 Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0));
6302 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
6303 aGroup->AddPrimitiveArray (myRect);
6304 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
6310 //! Compute selection.
6311 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE
6315 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5);
6316 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner);
6317 aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location());
6318 theSel->Add (aSensitive);
6323 Handle(Graphic3d_ArrayOfTriangles) myTris;
6324 Handle(Graphic3d_ArrayOfPolylines) myRect;
6325 TCollection_AsciiString myLabel;
6326 Standard_Real myWidth;
6327 Standard_Real myHeight;
6330 //==============================================================================
6331 //function : VDiffImage
6332 //purpose : The draw-command compares two images.
6333 //==============================================================================
6335 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
6339 std::cout << "Syntax error: not enough arguments.\n";
6343 Standard_Integer anArgIter = 1;
6344 TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]);
6345 TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]);
6346 TCollection_AsciiString aDiffImagePath;
6347 Standard_Real aTolColor = -1.0;
6348 Standard_Integer toBlackWhite = -1;
6349 Standard_Integer isBorderFilterOn = -1;
6350 Standard_Boolean isOldSyntax = Standard_False;
6351 TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff;
6352 for (; anArgIter < theArgNb; ++anArgIter)
6354 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6356 if (anArgIter + 1 < theArgNb
6357 && (anArg == "-toleranceofcolor"
6358 || anArg == "-tolerancecolor"
6359 || anArg == "-tolerance"
6360 || anArg == "-toler"))
6362 aTolColor = Atof (theArgVec[++anArgIter]);
6363 if (aTolColor < 0.0 || aTolColor > 1.0)
6365 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
6369 else if (anArg == "-blackwhite")
6371 Standard_Boolean toEnable = Standard_True;
6372 if (anArgIter + 1 < theArgNb
6373 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6377 toBlackWhite = toEnable ? 1 : 0;
6379 else if (anArg == "-borderfilter")
6381 Standard_Boolean toEnable = Standard_True;
6382 if (anArgIter + 1 < theArgNb
6383 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6387 isBorderFilterOn = toEnable ? 1 : 0;
6389 else if (anArg == "-exitonclose")
6391 Draw_ToExitOnCloseView = true;
6392 if (anArgIter + 1 < theArgNb
6393 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToExitOnCloseView))
6398 else if (anArg == "-closeonescape"
6399 || anArg == "-closeonesc")
6401 Draw_ToCloseViewOnEsc = true;
6402 if (anArgIter + 1 < theArgNb
6403 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToCloseViewOnEsc))
6408 else if (anArgIter + 3 < theArgNb
6409 && anArg == "-display")
6411 aViewName = theArgVec[++anArgIter];
6412 aPrsNameRef = theArgVec[++anArgIter];
6413 aPrsNameNew = theArgVec[++anArgIter];
6414 if (anArgIter + 1 < theArgNb
6415 && *theArgVec[anArgIter + 1] != '-')
6417 aPrsNameDiff = theArgVec[++anArgIter];
6420 else if (aTolColor < 0.0
6421 && anArg.IsRealValue())
6423 isOldSyntax = Standard_True;
6424 aTolColor = anArg.RealValue();
6425 if (aTolColor < 0.0 || aTolColor > 1.0)
6427 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
6431 else if (isOldSyntax
6432 && toBlackWhite == -1
6433 && (anArg == "0" || anArg == "1"))
6435 toBlackWhite = anArg == "1" ? 1 : 0;
6437 else if (isOldSyntax
6438 && isBorderFilterOn == -1
6439 && (anArg == "0" || anArg == "1"))
6441 isBorderFilterOn = anArg == "1" ? 1 : 0;
6443 else if (aDiffImagePath.IsEmpty())
6445 aDiffImagePath = theArgVec[anArgIter];
6449 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
6454 Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap();
6455 Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap();
6456 if (!anImgRef->Load (anImgPathRef))
6458 std::cout << "Error: image file '" << anImgPathRef << "' cannot be read\n";
6461 if (!anImgNew->Load (anImgPathNew))
6463 std::cout << "Error: image file '" << anImgPathNew << "' cannot be read\n";
6467 // compare the images
6468 Image_Diff aComparer;
6469 Standard_Integer aDiffColorsNb = -1;
6470 if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1))
6472 aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0);
6473 aComparer.SetBorderFilterOn (isBorderFilterOn == 1);
6474 aDiffColorsNb = aComparer.Compare();
6475 theDI << aDiffColorsNb << "\n";
6478 // save image of difference
6479 Handle(Image_AlienPixMap) aDiff;
6480 if (aDiffColorsNb > 0
6481 && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty()))
6483 aDiff = new Image_AlienPixMap();
6484 if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY()))
6486 std::cout << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY() << "\n";
6489 aComparer.SaveDiffImage (*aDiff);
6490 if (!aDiffImagePath.IsEmpty()
6491 && !aDiff->Save (aDiffImagePath))
6493 std::cout << "Error: diff image file '" << aDiffImagePath << "' cannot be written\n";
6498 if (aViewName.IsEmpty())
6503 ViewerTest_Names aViewNames (aViewName);
6504 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
6506 TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName();
6507 theDI.Eval (aCommand.ToCString());
6510 Standard_Integer aPxLeft = 0;
6511 Standard_Integer aPxTop = 0;
6512 Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2);
6513 Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty()
6514 ? int(anImgRef->SizeY() * 2)
6515 : int(anImgRef->SizeY());
6516 TCollection_AsciiString aDisplayName;
6517 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aWinSizeX, aWinSizeY,
6518 aViewName, aDisplayName);
6520 Standard_Real aRatio = anImgRef->Ratio();
6521 Standard_Real aSizeX = 1.0;
6522 Standard_Real aSizeY = aSizeX / aRatio;
6524 OSD_Path aPath (anImgPathRef);
6525 TCollection_AsciiString aLabelRef;
6526 if (!aPath.Name().IsEmpty())
6528 aLabelRef = aPath.Name() + aPath.Extension();
6530 aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY());
6532 Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef);
6534 aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0));
6535 anImgRefPrs->SetLocalTransformation (aTrsfRef);
6536 ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true);
6539 OSD_Path aPath (anImgPathNew);
6540 TCollection_AsciiString aLabelNew;
6541 if (!aPath.Name().IsEmpty())
6543 aLabelNew = aPath.Name() + aPath.Extension();
6545 aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY());
6547 Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew);
6549 aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0));
6550 anImgNewPrs->SetLocalTransformation (aTrsfRef);
6551 ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true);
6553 Handle(ViewerTest_ImagePrs) anImgDiffPrs;
6554 if (!aDiff.IsNull())
6556 anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels");
6558 aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0));
6559 anImgDiffPrs->SetLocalTransformation (aTrsfDiff);
6561 if (!aPrsNameDiff.IsEmpty())
6563 ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true);
6565 ViewerTest::CurrentView()->SetProj (V3d_Zpos);
6566 ViewerTest::CurrentView()->FitAll();
6570 //=======================================================================
6571 //function : VSelect
6572 //purpose : Emulates different types of selection by mouse:
6573 // 1) single click selection
6574 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
6575 // 3) selection with polygon having corners at
6576 // pixel positions (x1,y1),...,(xn,yn)
6577 // 4) any of these selections with shift button pressed
6578 //=======================================================================
6579 static Standard_Integer VSelect (Draw_Interpretor& di,
6580 Standard_Integer argc,
6585 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]\n";
6589 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
6590 if(myAIScontext.IsNull())
6592 di << "use 'vinit' command before " << argv[0] << "\n";
6596 const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1));
6597 Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1;
6598 TCollection_AsciiString anArg;
6599 anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2];
6601 if (anArg == "-allowoverlap")
6603 Standard_Boolean isValidated = isShiftSelection ? argc == 8
6607 di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection";
6611 Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
6612 myAIScontext->MainSelector()->AllowOverlapDetection (isToAllow != 0);
6616 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
6617 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
6620 if(isShiftSelection)
6621 aCurrentEventManager->ShiftSelect();
6623 aCurrentEventManager->Select();
6625 else if(aCoordsNb == 4)
6627 if(isShiftSelection)
6628 aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
6630 aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
6634 TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2);
6636 for(Standard_Integer i=1;i<=aCoordsNb / 2;++i)
6637 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
6639 if(isShiftSelection)
6640 aCurrentEventManager->ShiftSelect(aPolyline);
6642 aCurrentEventManager->Select(aPolyline);
6647 //=======================================================================
6648 //function : VMoveTo
6649 //purpose : Emulates cursor movement to defined pixel position
6650 //=======================================================================
6651 static Standard_Integer VMoveTo (Draw_Interpretor& ,
6652 Standard_Integer theNbArgs,
6653 const char** theArgVec)
6655 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
6656 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
6657 if (aContext.IsNull())
6659 std::cout << "Error: no active View\n";
6663 Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast());
6664 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
6666 TCollection_AsciiString anArgStr (theArgVec[anArgIter]);
6667 anArgStr.LowerCase();
6668 if (anArgStr == "-reset"
6669 || anArgStr == "-clear")
6671 if (anArgIter + 1 < theNbArgs)
6673 std::cout << "Syntax error at '" << theArgVec[anArgIter + 1] << "'\n";
6677 const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive()
6678 && aContext->CurrentViewer()->GridEcho();
6681 aContext->CurrentViewer()->HideGridEcho (aView);
6683 if (aContext->ClearDetected() || toEchoGrid)
6685 aContext->CurrentViewer()->RedrawImmediate();
6689 else if (aMousePos.x() == IntegerLast()
6690 && anArgStr.IsIntegerValue())
6692 aMousePos.x() = anArgStr.IntegerValue();
6694 else if (aMousePos.y() == IntegerLast()
6695 && anArgStr.IsIntegerValue())
6697 aMousePos.y() = anArgStr.IntegerValue();
6701 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
6706 if (aMousePos.x() == IntegerLast()
6707 || aMousePos.y() == IntegerLast())
6709 std::cout << "Syntax error: wrong number of arguments\n";
6713 ViewerTest::CurrentEventManager()->MoveTo (aMousePos.x(), aMousePos.y());
6719 //! Global map storing all animations registered in ViewerTest.
6720 static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap;
6722 //! The animation calling the Draw Harness command.
6723 class ViewerTest_AnimationProc : public AIS_Animation
6727 //! Main constructor.
6728 ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName,
6729 Draw_Interpretor* theDI,
6730 const TCollection_AsciiString& theCommand)
6731 : AIS_Animation (theAnimationName),
6733 myCommand (theCommand)
6740 //! Evaluate the command.
6741 virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE
6743 TCollection_AsciiString aCmd = myCommand;
6744 replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts));
6745 replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts));
6746 replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts));
6747 replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized));
6748 replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized));
6749 myDrawInter->Eval (aCmd.ToCString());
6752 //! Find the keyword in the command and replace it with value.
6753 //! @return the position of the keyword to pass value
6754 void replace (TCollection_AsciiString& theCmd,
6755 const TCollection_AsciiString& theKey,
6756 const TCollection_AsciiString& theVal)
6758 TCollection_AsciiString aCmd (theCmd);
6760 const Standard_Integer aPos = aCmd.Search (theKey);
6766 TCollection_AsciiString aPart1, aPart2;
6767 Standard_Integer aPart1To = aPos - 1;
6769 && aPart1To <= theCmd.Length())
6771 aPart1 = theCmd.SubString (1, aPart1To);
6774 Standard_Integer aPart2From = aPos + theKey.Length();
6776 && aPart2From <= theCmd.Length())
6778 aPart2 = theCmd.SubString (aPart2From, theCmd.Length());
6781 theCmd = aPart1 + theVal + aPart2;
6786 Draw_Interpretor* myDrawInter;
6787 TCollection_AsciiString myCommand;
6791 //! Replace the animation with the new one.
6792 static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation,
6793 Handle(AIS_Animation)& theAnimation,
6794 const Handle(AIS_Animation)& theAnimationNew)
6796 theAnimationNew->CopyFrom (theAnimation);
6797 if (!theParentAnimation.IsNull())
6799 theParentAnimation->Replace (theAnimation, theAnimationNew);
6803 ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name());
6804 ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew);
6806 theAnimation = theAnimationNew;
6809 //! Parse the point.
6810 static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
6812 const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
6813 if (!anXYZ[0].IsRealValue()
6814 || !anXYZ[1].IsRealValue()
6815 || !anXYZ[2].IsRealValue())
6817 return Standard_False;
6820 thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue());
6821 return Standard_True;
6824 //! Parse the quaternion.
6825 static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
6827 const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
6828 if (!anXYZW[0].IsRealValue()
6829 || !anXYZW[1].IsRealValue()
6830 || !anXYZW[2].IsRealValue()
6831 || !anXYZW[3].IsRealValue())
6833 return Standard_False;
6836 theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue());
6837 return Standard_True;
6840 //! Auxiliary class for flipping image upside-down.
6845 //! Empty constructor.
6846 ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {}
6848 //! Perform flipping.
6849 Standard_Boolean FlipY (Image_PixMap& theImage)
6851 if (theImage.IsEmpty()
6852 || theImage.SizeX() == 0
6853 || theImage.SizeY() == 0)
6855 return Standard_False;
6858 const Standard_Size aRowSize = theImage.SizeRowBytes();
6859 if (myTmp.Size() < aRowSize
6860 && !myTmp.Allocate (aRowSize))
6862 return Standard_False;
6865 // for odd height middle row should be left as is
6866 Standard_Size aNbRowsHalf = theImage.SizeY() / 2;
6867 for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB)
6869 Standard_Byte* aTop = theImage.ChangeRow (aRowT);
6870 Standard_Byte* aBot = theImage.ChangeRow (aRowB);
6871 memcpy (myTmp.ChangeData(), aTop, aRowSize);
6872 memcpy (aTop, aBot, aRowSize);
6873 memcpy (aBot, myTmp.Data(), aRowSize);
6875 return Standard_True;
6879 NCollection_Buffer myTmp;
6884 //=================================================================================================
6885 //function : VViewParams
6886 //purpose : Gets or sets AIS View characteristics
6887 //=================================================================================================
6888 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6890 Handle(V3d_View) aView = ViewerTest::CurrentView();
6893 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
6897 Standard_Boolean toSetProj = Standard_False;
6898 Standard_Boolean toSetUp = Standard_False;
6899 Standard_Boolean toSetAt = Standard_False;
6900 Standard_Boolean toSetEye = Standard_False;
6901 Standard_Boolean toSetScale = Standard_False;
6902 Standard_Boolean toSetSize = Standard_False;
6903 Standard_Boolean toSetCenter2d = Standard_False;
6904 Standard_Real aViewScale = aView->Scale();
6905 Standard_Real aViewSize = 1.0;
6906 Graphic3d_Vec2i aCenter2d;
6907 gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
6908 aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3));
6909 aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
6910 aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
6911 aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
6914 // print all of the available view parameters
6918 "Proj: %12g %12g %12g\n"
6919 "Up: %12g %12g %12g\n"
6920 "At: %12g %12g %12g\n"
6921 "Eye: %12g %12g %12g\n",
6923 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
6924 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
6925 aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
6926 aViewEye.X(), aViewEye.Y(), aViewEye.Z());
6931 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
6932 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
6934 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6936 if (anUpdateTool.parseRedrawMode (anArg))
6940 else if (anArg == "-cmd"
6941 || anArg == "-command"
6942 || anArg == "-args")
6951 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
6952 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
6953 aViewAt.X(), aViewAt.Y(), aViewAt.Z());
6956 else if (anArg == "-scale"
6957 || anArg == "-size")
6959 if (anArgIter + 1 < theArgsNb
6960 && *theArgVec[anArgIter + 1] != '-')
6962 const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
6963 if (aValueArg.IsRealValue())
6966 if (anArg == "-scale")
6968 toSetScale = Standard_True;
6969 aViewScale = aValueArg.RealValue();
6971 else if (anArg == "-size")
6973 toSetSize = Standard_True;
6974 aViewSize = aValueArg.RealValue();
6979 if (anArg == "-scale")
6981 theDi << "Scale: " << aView->Scale() << "\n";
6983 else if (anArg == "-size")
6985 Graphic3d_Vec2d aSizeXY;
6986 aView->Size (aSizeXY.x(), aSizeXY.y());
6987 theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n";
6990 else if (anArg == "-eye"
6993 || anArg == "-proj")
6995 if (anArgIter + 3 < theArgsNb)
6998 if (parseXYZ (theArgVec + anArgIter + 1, anXYZ))
7001 if (anArg == "-eye")
7003 toSetEye = Standard_True;
7006 else if (anArg == "-at")
7008 toSetAt = Standard_True;
7011 else if (anArg == "-up")
7013 toSetUp = Standard_True;
7016 else if (anArg == "-proj")
7018 toSetProj = Standard_True;
7025 if (anArg == "-eye")
7027 theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n";
7029 else if (anArg == "-at")
7031 theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n";
7033 else if (anArg == "-up")
7035 theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n";
7037 else if (anArg == "-proj")
7039 theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n";
7042 else if (anArg == "-center")
7044 if (anArgIter + 2 < theArgsNb)
7046 const TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
7047 const TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
7048 if (anX.IsIntegerValue()
7049 && anY.IsIntegerValue())
7051 toSetCenter2d = Standard_True;
7052 aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue());
7058 std::cout << "Syntax error at '" << anArg << "'\n";
7063 // change view parameters in proper order
7066 aView->SetScale (aViewScale);
7070 aView->SetSize (aViewSize);
7074 aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z());
7078 aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z());
7082 aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z());
7086 aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z());
7090 aView->SetCenter (aCenter2d.x(), aCenter2d.y());
7096 //==============================================================================
7097 //function : V2DMode
7099 //==============================================================================
7100 static Standard_Integer V2DMode (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec)
7102 bool is2dMode = true;
7103 Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView());
7104 if (aV3dView.IsNull())
7106 std::cout << "Error: no active view.\n";
7109 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
7111 const TCollection_AsciiString anArg = theArgVec[anArgIt];
7112 TCollection_AsciiString anArgCase = anArg;
7113 anArgCase.LowerCase();
7114 if (anArgIt + 1 < theArgsNb
7115 && anArgCase == "-name")
7117 ViewerTest_Names aViewNames (theArgVec[++anArgIt]);
7118 TCollection_AsciiString aViewName = aViewNames.GetViewName();
7119 if (!ViewerTest_myViews.IsBound1 (aViewName))
7121 std::cout << "Syntax error: unknown view '" << theArgVec[anArgIt - 1] << "'.\n";
7124 aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest_myViews.Find1 (aViewName));
7126 else if (anArgCase == "-mode")
7128 if (anArgIt + 1 < theArgsNb
7129 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], is2dMode))
7134 else if (ViewerTest::ParseOnOff (theArgVec[anArgIt], is2dMode))
7140 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
7145 aV3dView->SetView2DMode (is2dMode);
7149 //==============================================================================
7150 //function : VAnimation
7152 //==============================================================================
7153 static Standard_Integer VAnimation (Draw_Interpretor& theDI,
7154 Standard_Integer theArgNb,
7155 const char** theArgVec)
7157 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
7160 for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator
7161 anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next())
7163 theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n";
7169 std::cout << "Error: no active view\n";
7173 Standard_Integer anArgIter = 1;
7174 TCollection_AsciiString aNameArg (theArgVec[anArgIter++]);
7175 if (aNameArg.IsEmpty())
7177 std::cout << "Syntax error: animation name is not defined.\n";
7181 TCollection_AsciiString aNameArgLower = aNameArg;
7182 aNameArgLower.LowerCase();
7183 if (aNameArgLower == "-reset"
7184 || aNameArgLower == "-clear")
7186 ViewerTest_AnimationTimelineMap.Clear();
7189 else if (aNameArg.Value (1) == '-')
7191 std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n";
7195 const char* aNameSplitter = "/";
7196 Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter);
7197 if (aSplitPos == -1)
7199 aNameSplitter = ".";
7200 aSplitPos = aNameArg.Search (aNameSplitter);
7203 // find existing or create a new animation by specified name within syntax "parent.child".
7204 Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation;
7205 for (; !aNameArg.IsEmpty();)
7207 TCollection_AsciiString aNameParent;
7208 if (aSplitPos != -1)
7210 if (aSplitPos == aNameArg.Length())
7212 std::cout << "Syntax error: animation name is not defined.\n";
7216 aNameParent = aNameArg.SubString ( 1, aSplitPos - 1);
7217 aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length());
7219 aSplitPos = aNameArg.Search (aNameSplitter);
7223 aNameParent = aNameArg;
7227 if (anAnimation.IsNull())
7229 if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation))
7231 anAnimation = new AIS_Animation (aNameParent);
7232 ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation);
7234 aRootAnimation = anAnimation;
7238 aParentAnimation = anAnimation;
7239 anAnimation = aParentAnimation->Find (aNameParent);
7240 if (anAnimation.IsNull())
7242 anAnimation = new AIS_Animation (aNameParent);
7243 aParentAnimation->Add (anAnimation);
7248 if (anArgIter >= theArgNb)
7250 // just print the list of children
7251 for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next())
7253 theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n";
7258 // animation parameters
7259 Standard_Boolean toPlay = Standard_False;
7260 Standard_Real aPlaySpeed = 1.0;
7261 Standard_Real aPlayStartTime = anAnimation->StartPts();
7262 Standard_Real aPlayDuration = anAnimation->Duration();
7263 Standard_Boolean isFreeCamera = Standard_False;
7264 Standard_Boolean isLockLoop = Standard_False;
7266 // video recording parameters
7267 TCollection_AsciiString aRecFile;
7268 Image_VideoParams aRecParams;
7270 Handle(V3d_View) aView = ViewerTest::CurrentView();
7271 for (; anArgIter < theArgNb; ++anArgIter)
7273 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7276 if (anArg == "-reset"
7277 || anArg == "-clear")
7279 anAnimation->Clear();
7281 else if (anArg == "-remove"
7283 || anArg == "-delete")
7285 if (!aParentAnimation.IsNull())
7287 ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name());
7291 aParentAnimation->Remove (anAnimation);
7295 else if (anArg == "-play")
7297 toPlay = Standard_True;
7298 if (++anArgIter < theArgNb)
7300 if (*theArgVec[anArgIter] == '-')
7305 aPlayStartTime = Draw::Atof (theArgVec[anArgIter]);
7307 if (++anArgIter < theArgNb)
7309 if (*theArgVec[anArgIter] == '-')
7314 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
7318 else if (anArg == "-resume")
7320 toPlay = Standard_True;
7321 aPlayStartTime = anAnimation->ElapsedTime();
7322 if (++anArgIter < theArgNb)
7324 if (*theArgVec[anArgIter] == '-')
7330 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
7333 else if (anArg == "-playspeed"
7334 || anArg == "-speed")
7336 if (++anArgIter >= theArgNb)
7338 std::cout << "Syntax error at " << anArg << ".\n";
7341 aPlaySpeed = Draw::Atof (theArgVec[anArgIter]);
7343 else if (anArg == "-lock"
7344 || anArg == "-lockloop"
7345 || anArg == "-playlockloop")
7347 isLockLoop = Standard_True;
7349 else if (anArg == "-freecamera"
7350 || anArg == "-playfreecamera"
7351 || anArg == "-freelook")
7353 isFreeCamera = Standard_True;
7355 // video recodring options
7356 else if (anArg == "-rec"
7357 || anArg == "-record")
7359 if (++anArgIter >= theArgNb)
7361 std::cout << "Syntax error at " << anArg << ".\n";
7365 aRecFile = theArgVec[anArgIter];
7366 if (aRecParams.FpsNum <= 0)
7368 aRecParams.FpsNum = 24;
7371 if (anArgIter + 2 < theArgNb
7372 && *theArgVec[anArgIter + 1] != '-'
7373 && *theArgVec[anArgIter + 2] != '-')
7375 TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]);
7376 TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]);
7377 if (aWidthArg .IsIntegerValue()
7378 && aHeightArg.IsIntegerValue())
7380 aRecParams.Width = aWidthArg .IntegerValue();
7381 aRecParams.Height = aHeightArg.IntegerValue();
7386 else if (anArg == "-fps")
7388 if (++anArgIter >= theArgNb)
7390 std::cout << "Syntax error at " << anArg << ".\n";
7394 TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
7395 Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
7396 if (aSplitIndex == 0)
7398 aRecParams.FpsNum = aFpsArg.IntegerValue();
7402 const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
7403 aFpsArg.Split (aFpsArg.Length() - 1);
7404 const TCollection_AsciiString aNumStr = aFpsArg;
7405 aRecParams.FpsNum = aNumStr.IntegerValue();
7406 aRecParams.FpsDen = aDenStr.IntegerValue();
7407 if (aRecParams.FpsDen < 1)
7409 std::cout << "Syntax error at " << anArg << ".\n";
7414 else if (anArg == "-format")
7416 if (++anArgIter >= theArgNb)
7418 std::cout << "Syntax error at " << anArg << ".\n";
7421 aRecParams.Format = theArgVec[anArgIter];
7423 else if (anArg == "-pix_fmt"
7424 || anArg == "-pixfmt"
7425 || anArg == "-pixelformat")
7427 if (++anArgIter >= theArgNb)
7429 std::cout << "Syntax error at " << anArg << ".\n";
7432 aRecParams.PixelFormat = theArgVec[anArgIter];
7434 else if (anArg == "-codec"
7435 || anArg == "-vcodec"
7436 || anArg == "-videocodec")
7438 if (++anArgIter >= theArgNb)
7440 std::cout << "Syntax error at " << anArg << ".\n";
7443 aRecParams.VideoCodec = theArgVec[anArgIter];
7445 else if (anArg == "-crf"
7446 || anArg == "-preset"
7449 const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length());
7450 if (++anArgIter >= theArgNb)
7452 std::cout << "Syntax error at " << anArg << ".\n";
7456 aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]);
7458 // animation definition options
7459 else if (anArg == "-start"
7460 || anArg == "-starttime"
7461 || anArg == "-startpts")
7463 if (++anArgIter >= theArgNb)
7465 std::cout << "Syntax error at " << anArg << ".\n";
7469 anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter]));
7470 aRootAnimation->UpdateTotalDuration();
7472 else if (anArg == "-end"
7473 || anArg == "-endtime"
7474 || anArg == "-endpts")
7476 if (++anArgIter >= theArgNb)
7478 std::cout << "Syntax error at " << anArg << ".\n";
7482 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts());
7483 aRootAnimation->UpdateTotalDuration();
7485 else if (anArg == "-dur"
7486 || anArg == "-duration")
7488 if (++anArgIter >= theArgNb)
7490 std::cout << "Syntax error at " << anArg << ".\n";
7494 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]));
7495 aRootAnimation->UpdateTotalDuration();
7497 else if (anArg == "-command"
7499 || anArg == "-invoke"
7501 || anArg == "-proc")
7503 if (++anArgIter >= theArgNb)
7505 std::cout << "Syntax error at " << anArg << ".\n";
7509 Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]);
7510 replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation);
7512 else if (anArg == "-objecttrsf"
7513 || anArg == "-objectransformation"
7514 || anArg == "-objtransformation"
7515 || anArg == "-objtrsf"
7516 || anArg == "-object"
7519 if (++anArgIter >= theArgNb)
7521 std::cout << "Syntax error at " << anArg << ".\n";
7525 TCollection_AsciiString anObjName (theArgVec[anArgIter]);
7526 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS();
7527 Handle(AIS_InteractiveObject) anObject;
7528 if (!aMapOfAIS.Find2 (anObjName, anObject))
7530 std::cout << "Syntax error: wrong object name at " << anArg << "\n";
7534 gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() };
7535 gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() };
7536 gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
7537 Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
7538 Standard_Boolean isTrsfSet = Standard_False;
7539 Standard_Integer aTrsfArgIter = anArgIter + 1;
7540 for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
7542 TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]);
7543 aTrsfArg.LowerCase();
7544 const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1;
7545 if (aTrsfArg.StartsWith ("-rotation")
7546 || aTrsfArg.StartsWith ("-rot"))
7548 isTrsfSet = Standard_True;
7549 if (aTrsfArgIter + 4 >= theArgNb
7550 || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex]))
7552 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7557 else if (aTrsfArg.StartsWith ("-location")
7558 || aTrsfArg.StartsWith ("-loc"))
7560 isTrsfSet = Standard_True;
7561 if (aTrsfArgIter + 3 >= theArgNb
7562 || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex]))
7564 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7569 else if (aTrsfArg.StartsWith ("-scale"))
7571 isTrsfSet = Standard_True;
7572 if (++aTrsfArgIter >= theArgNb)
7574 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7578 const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
7579 if (!aScaleStr.IsRealValue())
7581 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7584 aScales[anIndex] = aScaleStr.RealValue();
7588 anArgIter = aTrsfArgIter - 1;
7594 std::cout << "Syntax error at " << anArg << ".\n";
7597 else if (aTrsfArgIter >= theArgNb)
7599 anArgIter = theArgNb;
7602 aTrsfs[0].SetRotation (aRotQuats[0]);
7603 aTrsfs[1].SetRotation (aRotQuats[1]);
7604 aTrsfs[0].SetTranslationPart (aLocPnts[0]);
7605 aTrsfs[1].SetTranslationPart (aLocPnts[1]);
7606 aTrsfs[0].SetScaleFactor (aScales[0]);
7607 aTrsfs[1].SetScaleFactor (aScales[1]);
7609 Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
7610 replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
7612 else if (anArg == "-viewtrsf"
7613 || anArg == "-view")
7615 Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation);
7616 if (aCamAnimation.IsNull())
7618 aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView);
7619 replaceAnimation (aParentAnimation, anAnimation, aCamAnimation);
7622 Handle(Graphic3d_Camera) aCams[2] =
7624 new Graphic3d_Camera (aCamAnimation->View()->Camera()),
7625 new Graphic3d_Camera (aCamAnimation->View()->Camera())
7628 Standard_Boolean isTrsfSet = Standard_False;
7629 Standard_Integer aViewArgIter = anArgIter + 1;
7630 for (; aViewArgIter < theArgNb; ++aViewArgIter)
7632 TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]);
7633 aViewArg.LowerCase();
7634 const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1;
7635 if (aViewArg.StartsWith ("-scale"))
7637 isTrsfSet = Standard_True;
7638 if (++aViewArgIter >= theArgNb)
7640 std::cout << "Syntax error at " << anArg << ".\n";
7644 const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
7645 if (!aScaleStr.IsRealValue())
7647 std::cout << "Syntax error at " << aViewArg << ".\n";
7650 Standard_Real aScale = aScaleStr.RealValue();
7651 aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale;
7652 aCams[anIndex]->SetScale (aScale);
7654 else if (aViewArg.StartsWith ("-eye")
7655 || aViewArg.StartsWith ("-center")
7656 || aViewArg.StartsWith ("-at")
7657 || aViewArg.StartsWith ("-up"))
7659 isTrsfSet = Standard_True;
7661 if (aViewArgIter + 3 >= theArgNb
7662 || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ))
7664 std::cout << "Syntax error at " << aViewArg << ".\n";
7669 if (aViewArg.StartsWith ("-eye"))
7671 aCams[anIndex]->SetEye (anXYZ);
7673 else if (aViewArg.StartsWith ("-center")
7674 || aViewArg.StartsWith ("-at"))
7676 aCams[anIndex]->SetCenter (anXYZ);
7678 else if (aViewArg.StartsWith ("-up"))
7680 aCams[anIndex]->SetUp (anXYZ);
7685 anArgIter = aViewArgIter - 1;
7691 std::cout << "Syntax error at " << anArg << ".\n";
7694 else if (aViewArgIter >= theArgNb)
7696 anArgIter = theArgNb;
7699 aCamAnimation->SetCameraStart(aCams[0]);
7700 aCamAnimation->SetCameraEnd (aCams[1]);
7704 std::cout << "Syntax error at " << anArg << ".\n";
7709 if (!toPlay && aRecFile.IsEmpty())
7714 // Start animation timeline and process frame updating.
7715 TheIsAnimating = Standard_True;
7716 const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
7717 Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera());
7718 anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
7721 aView->Camera()->Copy (aCameraBack);
7724 const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
7725 if (aRecParams.FpsNum <= 0)
7727 while (!anAnimation->IsStopped())
7729 aCameraBack->Copy (aView->Camera());
7730 const Standard_Real aPts = anAnimation->UpdateTimer();
7733 aView->Camera()->Copy (aCameraBack);
7736 if (aPts >= anUpperPts)
7738 anAnimation->Pause();
7742 if (aView->IsInvalidated())
7748 aView->RedrawImmediate();
7753 // handle user events
7754 theDI.Eval ("after 1 set waiter 1");
7755 theDI.Eval ("vwait waiter");
7757 if (!TheIsAnimating)
7759 anAnimation->Pause();
7765 if (aView->IsInvalidated())
7771 aView->RedrawImmediate();
7776 OSD_Timer aPerfTimer;
7779 Handle(Image_VideoRecorder) aRecorder;
7780 ImageFlipper aFlipper;
7781 Handle(Draw_ProgressIndicator) aProgress;
7782 if (!aRecFile.IsEmpty())
7784 if (aRecParams.Width <= 0
7785 || aRecParams.Height <= 0)
7787 aView->Window()->Size (aRecParams.Width, aRecParams.Height);
7790 aRecorder = new Image_VideoRecorder();
7791 if (!aRecorder->Open (aRecFile.ToCString(), aRecParams))
7793 std::cout << "Error: failed to open video file for recording\n";
7797 aProgress = new Draw_ProgressIndicator (theDI, 1);
7800 // Manage frame-rated animation here
7801 Standard_Real aPts = aPlayStartTime;
7802 int64_t aNbFrames = 0;
7803 Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1);
7804 Standard_Integer aSecondsProgress = 0;
7805 for (; aPts <= anUpperPts && aPSentry.More();)
7807 const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames));
7808 aPts = aPlayStartTime + aRecPts;
7810 if (!anAnimation->Update (aPts))
7815 if (!aRecorder.IsNull())
7817 V3d_ImageDumpOptions aDumpParams;
7818 aDumpParams.Width = aRecParams.Width;
7819 aDumpParams.Height = aRecParams.Height;
7820 aDumpParams.BufferType = Graphic3d_BT_RGBA;
7821 aDumpParams.StereoOptions = V3d_SDO_MONO;
7822 aDumpParams.ToAdjustAspect = Standard_True;
7823 if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams))
7825 std::cout << "Error: view dump is failed!\n";
7828 aFlipper.FlipY (aRecorder->ChangeFrame());
7829 if (!aRecorder->PushFrame())
7839 while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed))
7847 anAnimation->Stop();
7848 const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
7849 theDI << "Average FPS: " << aRecFps << "\n"
7850 << "Nb. Frames: " << Standard_Real(aNbFrames);
7855 aView->SetImmediateUpdate (wasImmediateUpdate);
7856 TheIsAnimating = Standard_False;
7861 //=======================================================================
7862 //function : VChangeSelected
7863 //purpose : Adds the shape to selection or remove one from it
7864 //=======================================================================
7865 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
7866 Standard_Integer argc,
7871 di<<"Usage : " << argv[0] << " shape \n";
7875 TCollection_AsciiString aName(argv[1]);
7876 Handle(AIS_InteractiveObject) anAISObject;
7877 if (!GetMapOfAIS().Find2 (aName, anAISObject)
7878 || anAISObject.IsNull())
7880 di<<"Use 'vdisplay' before";
7884 ViewerTest::GetAISContext()->AddOrRemoveSelected(anAISObject, Standard_True);
7888 //=======================================================================
7889 //function : VNbSelected
7890 //purpose : Returns number of selected objects
7891 //=======================================================================
7892 static Standard_Integer VNbSelected (Draw_Interpretor& di,
7893 Standard_Integer argc,
7898 di << "Usage : " << argv[0] << "\n";
7901 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7902 if(aContext.IsNull())
7904 di << "use 'vinit' command before " << argv[0] << "\n";
7907 di << aContext->NbSelected() << "\n";
7911 //=======================================================================
7912 //function : VPurgeDisplay
7913 //purpose : Switches altialiasing on or off
7914 //=======================================================================
7915 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
7916 Standard_Integer argc,
7921 di << "Usage : " << argv[0] << "\n";
7924 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7925 if (aContext.IsNull())
7927 di << "use 'vinit' command before " << argv[0] << "\n";
7931 di << aContext->PurgeDisplay() << "\n";
7935 //=======================================================================
7936 //function : VSetViewSize
7938 //=======================================================================
7939 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
7940 Standard_Integer argc,
7943 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7944 if(aContext.IsNull())
7946 di << "use 'vinit' command before " << argv[0] << "\n";
7951 di<<"Usage : " << argv[0] << " Size\n";
7954 Standard_Real aSize = Draw::Atof (argv[1]);
7957 di<<"Bad Size value : " << aSize << "\n";
7961 Handle(V3d_View) aView = ViewerTest::CurrentView();
7962 aView->SetSize(aSize);
7966 //=======================================================================
7967 //function : VMoveView
7969 //=======================================================================
7970 static Standard_Integer VMoveView (Draw_Interpretor& di,
7971 Standard_Integer argc,
7974 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7975 if(aContext.IsNull())
7977 di << "use 'vinit' command before " << argv[0] << "\n";
7980 if(argc < 4 || argc > 5)
7982 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
7985 Standard_Real Dx = Draw::Atof (argv[1]);
7986 Standard_Real Dy = Draw::Atof (argv[2]);
7987 Standard_Real Dz = Draw::Atof (argv[3]);
7988 Standard_Boolean aStart = Standard_True;
7991 aStart = (Draw::Atoi (argv[4]) > 0);
7994 Handle(V3d_View) aView = ViewerTest::CurrentView();
7995 aView->Move(Dx,Dy,Dz,aStart);
7999 //=======================================================================
8000 //function : VTranslateView
8002 //=======================================================================
8003 static Standard_Integer VTranslateView (Draw_Interpretor& di,
8004 Standard_Integer argc,
8007 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8008 if(aContext.IsNull())
8010 di << "use 'vinit' command before " << argv[0] << "\n";
8013 if(argc < 4 || argc > 5)
8015 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
8018 Standard_Real Dx = Draw::Atof (argv[1]);
8019 Standard_Real Dy = Draw::Atof (argv[2]);
8020 Standard_Real Dz = Draw::Atof (argv[3]);
8021 Standard_Boolean aStart = Standard_True;
8024 aStart = (Draw::Atoi (argv[4]) > 0);
8027 Handle(V3d_View) aView = ViewerTest::CurrentView();
8028 aView->Translate(Dx,Dy,Dz,aStart);
8032 //=======================================================================
8033 //function : VTurnView
8035 //=======================================================================
8036 static Standard_Integer VTurnView (Draw_Interpretor& di,
8037 Standard_Integer argc,
8040 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8041 if(aContext.IsNull()) {
8042 di << "use 'vinit' command before " << argv[0] << "\n";
8045 if(argc < 4 || argc > 5){
8046 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
8049 Standard_Real Ax = Draw::Atof (argv[1]);
8050 Standard_Real Ay = Draw::Atof (argv[2]);
8051 Standard_Real Az = Draw::Atof (argv[3]);
8052 Standard_Boolean aStart = Standard_True;
8055 aStart = (Draw::Atoi (argv[4]) > 0);
8058 Handle(V3d_View) aView = ViewerTest::CurrentView();
8059 aView->Turn(Ax,Ay,Az,aStart);
8063 //==============================================================================
8064 //function : VTextureEnv
8065 //purpose : ENables or disables environment mapping
8066 //==============================================================================
8067 class OCC_TextureEnv : public Graphic3d_TextureEnv
8070 OCC_TextureEnv(const Standard_CString FileName);
8071 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
8072 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
8073 const Standard_Boolean theModulateFlag,
8074 const Graphic3d_TypeOfTextureFilter theFilter,
8075 const Standard_ShortReal theXScale,
8076 const Standard_ShortReal theYScale,
8077 const Standard_ShortReal theXShift,
8078 const Standard_ShortReal theYShift,
8079 const Standard_ShortReal theAngle);
8080 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
8082 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
8084 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
8085 : Graphic3d_TextureEnv(theFileName)
8089 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
8090 : Graphic3d_TextureEnv(theTexId)
8094 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
8095 const Standard_Boolean theModulateFlag,
8096 const Graphic3d_TypeOfTextureFilter theFilter,
8097 const Standard_ShortReal theXScale,
8098 const Standard_ShortReal theYScale,
8099 const Standard_ShortReal theXShift,
8100 const Standard_ShortReal theYShift,
8101 const Standard_ShortReal theAngle)
8103 myParams->SetRepeat (theRepeatFlag);
8104 myParams->SetModulate (theModulateFlag);
8105 myParams->SetFilter (theFilter);
8106 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
8107 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
8108 myParams->SetRotation (theAngle);
8111 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
8113 // get the active view
8114 Handle(V3d_View) aView = ViewerTest::CurrentView();
8117 std::cerr << "No active view. Please call vinit.\n";
8121 // Checking the input arguments
8122 Standard_Boolean anEnableFlag = Standard_False;
8123 Standard_Boolean isOk = theArgNb >= 2;
8126 TCollection_AsciiString anEnableOpt(theArgVec[1]);
8127 anEnableFlag = anEnableOpt.IsEqual("on");
8128 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
8132 isOk = (theArgNb == 3 || theArgNb == 11);
8135 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8136 isOk = (!aTextureOpt.IsIntegerValue() ||
8137 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
8139 if (isOk && theArgNb == 11)
8141 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
8142 aModulateOpt(theArgVec[4]),
8143 aFilterOpt (theArgVec[5]),
8144 aSScaleOpt (theArgVec[6]),
8145 aTScaleOpt (theArgVec[7]),
8146 aSTransOpt (theArgVec[8]),
8147 aTTransOpt (theArgVec[9]),
8148 anAngleOpt (theArgVec[10]);
8149 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
8150 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
8151 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
8152 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
8153 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
8154 anAngleOpt.IsRealValue());
8161 std::cerr << "Usage :" << std::endl;
8162 std::cerr << theArgVec[0] << " off" << std::endl;
8163 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;
8169 TCollection_AsciiString aTextureOpt(theArgVec[2]);
8170 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
8171 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
8172 new OCC_TextureEnv(theArgVec[2]);
8176 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
8177 aTexEnv->SetTextureParameters(
8178 aRepeatOpt. IsEqual("repeat"),
8179 aModulateOpt.IsEqual("modulate"),
8180 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
8181 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
8182 Graphic3d_TOTF_TRILINEAR,
8183 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
8184 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
8185 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
8186 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
8187 (Standard_ShortReal)Draw::Atof(theArgVec[10])
8190 aView->SetTextureEnv(aTexEnv);
8192 else // Disabling environment mapping
8194 Handle(Graphic3d_TextureEnv) aTexture;
8195 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
8204 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
8206 //! Remove registered clipping plane from all views and objects.
8207 static void removePlane (MapOfPlanes& theRegPlanes,
8208 const TCollection_AsciiString& theName)
8210 Handle(Graphic3d_ClipPlane) aClipPlane;
8211 if (!theRegPlanes.Find (theName, aClipPlane))
8213 std::cout << "Warning: no such plane.\n";
8217 theRegPlanes.UnBind (theName);
8218 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
8219 anIObjIt.More(); anIObjIt.Next())
8221 const Handle(AIS_InteractiveObject)& aPrs = anIObjIt.Key1();
8222 aPrs->RemoveClipPlane (aClipPlane);
8225 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
8226 aViewIt.More(); aViewIt.Next())
8228 const Handle(V3d_View)& aView = aViewIt.Key2();
8229 aView->RemoveClipPlane(aClipPlane);
8232 ViewerTest::RedrawAllViews();
8236 //===============================================================================================
8237 //function : VClipPlane
8239 //===============================================================================================
8240 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8242 // use short-cut for created clip planes map of created (or "registered by name") clip planes
8243 static MapOfPlanes aRegPlanes;
8247 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
8249 theDi << aPlaneIter.Key() << " ";
8254 TCollection_AsciiString aCommand (theArgVec[1]);
8255 aCommand.LowerCase();
8256 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
8257 if (anActiveView.IsNull())
8259 std::cout << "Error: no active view.\n";
8263 // print maximum number of planes for current viewer
8264 if (aCommand == "-maxplanes"
8265 || aCommand == "maxplanes")
8267 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
8268 << " plane slots provided by driver.\n";
8272 // create / delete plane instance
8273 if (aCommand == "-create"
8274 || aCommand == "create"
8275 || aCommand == "-delete"
8276 || aCommand == "delete"
8277 || aCommand == "-clone"
8278 || aCommand == "clone")
8282 std::cout << "Syntax error: plane name is required.\n";
8286 Standard_Boolean toCreate = aCommand == "-create"
8287 || aCommand == "create";
8288 Standard_Boolean toClone = aCommand == "-clone"
8289 || aCommand == "clone";
8290 Standard_Boolean toDelete = aCommand == "-delete"
8291 || aCommand == "delete";
8292 TCollection_AsciiString aPlane (theArgVec[2]);
8296 if (aRegPlanes.IsBound (aPlane))
8298 std::cout << "Warning: existing plane has been overridden.\n";
8303 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8307 else if (toClone) // toClone
8309 if (!aRegPlanes.IsBound (aPlane))
8311 std::cout << "Error: no such plane.\n";
8314 else if (theArgsNb < 4)
8316 std::cout << "Syntax error: enter name for new plane.\n";
8320 TCollection_AsciiString aClone (theArgVec[3]);
8321 if (aRegPlanes.IsBound (aClone))
8323 std::cout << "Error: plane name is in use.\n";
8327 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
8329 aRegPlanes.Bind (aClone, aClipPlane->Clone());
8339 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
8341 aPlane = aPlaneIter.Key();
8342 removePlane (aRegPlanes, aPlane);
8343 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
8348 removePlane (aRegPlanes, aPlane);
8354 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8359 // set / unset plane command
8360 if (aCommand == "set"
8361 || aCommand == "unset")
8365 std::cout << "Syntax error: need more arguments.\n";
8369 // redirect to new syntax
8370 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
8371 anArgVec.SetValue (1, theArgVec[0]);
8372 anArgVec.SetValue (2, theArgVec[2]);
8373 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
8374 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
8376 anArgVec.SetValue (anIt, theArgVec[anIt]);
8379 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
8382 // change plane command
8383 TCollection_AsciiString aPlaneName;
8384 Handle(Graphic3d_ClipPlane) aClipPlane;
8385 Standard_Integer anArgIter = 0;
8386 if (aCommand == "-change"
8387 || aCommand == "change")
8389 // old syntax support
8392 std::cout << "Syntax error: need more arguments.\n";
8397 aPlaneName = theArgVec[2];
8398 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
8400 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
8404 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
8407 aPlaneName = theArgVec[1];
8412 aPlaneName = theArgVec[1];
8413 aClipPlane = new Graphic3d_ClipPlane();
8414 aRegPlanes.Bind (aPlaneName, aClipPlane);
8415 theDi << "Created new plane " << aPlaneName << ".\n";
8418 if (theArgsNb - anArgIter < 1)
8420 std::cout << "Syntax error: need more arguments.\n";
8424 for (; anArgIter < theArgsNb; ++anArgIter)
8426 const char** aChangeArgs = theArgVec + anArgIter;
8427 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
8428 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
8429 aChangeArg.LowerCase();
8431 Standard_Boolean toEnable = Standard_True;
8432 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
8434 aClipPlane->SetOn (toEnable);
8436 else if (aChangeArg.StartsWith ("-equation")
8437 || aChangeArg.StartsWith ("equation"))
8439 if (aNbChangeArgs < 5)
8441 std::cout << "Syntax error: need more arguments.\n";
8445 Standard_Integer aSubIndex = 1;
8446 Standard_Integer aPrefixLen = 8 + (aChangeArg.Value (1) == '-' ? 1 : 0);
8447 if (aPrefixLen < aChangeArg.Length())
8449 TCollection_AsciiString aSubStr = aChangeArg.SubString (aPrefixLen + 1, aChangeArg.Length());
8450 if (!aSubStr.IsIntegerValue()
8451 || aSubStr.IntegerValue() <= 0)
8453 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
8456 aSubIndex = aSubStr.IntegerValue();
8459 Standard_Real aCoeffA = Draw::Atof (aChangeArgs[1]);
8460 Standard_Real aCoeffB = Draw::Atof (aChangeArgs[2]);
8461 Standard_Real aCoeffC = Draw::Atof (aChangeArgs[3]);
8462 Standard_Real aCoeffD = Draw::Atof (aChangeArgs[4]);
8463 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
8464 for (Standard_Integer aSubPlaneIter = 1; aSubPlaneIter < aSubIndex; ++aSubPlaneIter)
8466 if (aSubPln->ChainNextPlane().IsNull())
8468 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
8470 aSubPln = aSubPln->ChainNextPlane();
8472 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
8473 aSubPln->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
8476 else if ((aChangeArg == "-boxinterior"
8477 || aChangeArg == "-boxint"
8478 || aChangeArg == "-box")
8479 && aNbChangeArgs >= 7)
8481 Graphic3d_BndBox3d aBndBox;
8482 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[1]), Draw::Atof (aChangeArgs[2]), Draw::Atof (aChangeArgs[3])));
8483 aBndBox.Add (Graphic3d_Vec3d (Draw::Atof (aChangeArgs[4]), Draw::Atof (aChangeArgs[5]), Draw::Atof (aChangeArgs[6])));
8486 Standard_Integer aNbSubPlanes = 6;
8487 const Graphic3d_Vec3d aDirArray[6] =
8489 Graphic3d_Vec3d (-1, 0, 0),
8490 Graphic3d_Vec3d ( 1, 0, 0),
8491 Graphic3d_Vec3d ( 0,-1, 0),
8492 Graphic3d_Vec3d ( 0, 1, 0),
8493 Graphic3d_Vec3d ( 0, 0,-1),
8494 Graphic3d_Vec3d ( 0, 0, 1),
8496 Handle(Graphic3d_ClipPlane) aSubPln = aClipPlane;
8497 for (Standard_Integer aSubPlaneIter = 0; aSubPlaneIter < aNbSubPlanes; ++aSubPlaneIter)
8499 const Graphic3d_Vec3d& aDir = aDirArray[aSubPlaneIter];
8500 const Standard_Real aW = -aDir.Dot ((aSubPlaneIter % 2 == 1) ? aBndBox.CornerMax() : aBndBox.CornerMin());
8501 aSubPln->SetEquation (gp_Pln (aDir.x(), aDir.y(), aDir.z(), aW));
8502 if (aSubPlaneIter + 1 == aNbSubPlanes)
8504 aSubPln->SetChainNextPlane (Handle(Graphic3d_ClipPlane)());
8508 aSubPln->SetChainNextPlane (new Graphic3d_ClipPlane (*aSubPln));
8510 aSubPln = aSubPln->ChainNextPlane();
8513 else if (aChangeArg == "-capping"
8514 || aChangeArg == "capping")
8516 if (aNbChangeArgs < 2)
8518 std::cout << "Syntax error: need more arguments.\n";
8522 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8524 aClipPlane->SetCapping (toEnable);
8529 // just skip otherwise (old syntax)
8532 else if (aChangeArg == "-useobjectmaterial"
8533 || aChangeArg == "-useobjectmat"
8534 || aChangeArg == "-useobjmat"
8535 || aChangeArg == "-useobjmaterial")
8537 if (aNbChangeArgs < 2)
8539 std::cout << "Syntax error: need more arguments.\n";
8543 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8545 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
8549 else if (aChangeArg == "-useobjecttexture"
8550 || aChangeArg == "-useobjecttex"
8551 || aChangeArg == "-useobjtexture"
8552 || aChangeArg == "-useobjtex")
8554 if (aNbChangeArgs < 2)
8556 std::cout << "Syntax error: need more arguments.\n";
8560 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8562 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
8566 else if (aChangeArg == "-useobjectshader"
8567 || aChangeArg == "-useobjshader")
8569 if (aNbChangeArgs < 2)
8571 std::cout << "Syntax error: need more arguments.\n";
8575 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8577 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
8581 else if (aChangeArg == "-color"
8582 || aChangeArg == "color")
8584 Quantity_Color aColor;
8585 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
8590 std::cout << "Syntax error: need more arguments.\n";
8594 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
8595 aMat.SetAmbientColor (aColor);
8596 aMat.SetDiffuseColor (aColor);
8597 aClipPlane->SetCappingMaterial (aMat);
8598 anArgIter += aNbParsed;
8600 else if ((aChangeArg == "-transparency"
8601 || aChangeArg == "-transp")
8602 && aNbChangeArgs >= 2)
8604 TCollection_AsciiString aValStr (aChangeArgs[1]);
8605 Handle(Graphic3d_AspectFillArea3d) anAspect = aClipPlane->CappingAspect();
8606 if (aValStr.IsRealValue())
8608 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
8609 aMat.SetTransparency ((float )aValStr.RealValue());
8610 anAspect->SetAlphaMode (Graphic3d_AlphaMode_BlendAuto);
8611 aClipPlane->SetCappingMaterial (aMat);
8615 aValStr.LowerCase();
8616 Graphic3d_AlphaMode aMode = Graphic3d_AlphaMode_BlendAuto;
8617 if (aValStr == "opaque")
8619 aMode = Graphic3d_AlphaMode_Opaque;
8621 else if (aValStr == "mask")
8623 aMode = Graphic3d_AlphaMode_Mask;
8625 else if (aValStr == "blend")
8627 aMode = Graphic3d_AlphaMode_Blend;
8629 else if (aValStr == "blendauto")
8631 aMode = Graphic3d_AlphaMode_BlendAuto;
8635 std::cout << "Syntax error at '" << aValStr << "'\n";
8638 anAspect->SetAlphaMode (aMode);
8639 aClipPlane->SetCappingAspect (anAspect);
8643 else if (aChangeArg == "-texname"
8644 || aChangeArg == "texname")
8646 if (aNbChangeArgs < 2)
8648 std::cout << "Syntax error: need more arguments.\n";
8652 TCollection_AsciiString aTextureName (aChangeArgs[1]);
8653 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
8654 if (!aTexture->IsDone())
8656 aClipPlane->SetCappingTexture (NULL);
8660 aTexture->EnableModulate();
8661 aTexture->EnableRepeat();
8662 aClipPlane->SetCappingTexture (aTexture);
8666 else if (aChangeArg == "-texscale"
8667 || aChangeArg == "texscale")
8669 if (aClipPlane->CappingTexture().IsNull())
8671 std::cout << "Error: no texture is set.\n";
8675 if (aNbChangeArgs < 3)
8677 std::cout << "Syntax error: need more arguments.\n";
8681 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8682 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8683 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
8686 else if (aChangeArg == "-texorigin"
8687 || aChangeArg == "texorigin") // texture origin
8689 if (aClipPlane->CappingTexture().IsNull())
8691 std::cout << "Error: no texture is set.\n";
8695 if (aNbChangeArgs < 3)
8697 std::cout << "Syntax error: need more arguments.\n";
8701 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8702 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8704 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
8707 else if (aChangeArg == "-texrotate"
8708 || aChangeArg == "texrotate") // texture rotation
8710 if (aClipPlane->CappingTexture().IsNull())
8712 std::cout << "Error: no texture is set.\n";
8716 if (aNbChangeArgs < 2)
8718 std::cout << "Syntax error: need more arguments.\n";
8722 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8723 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
8726 else if (aChangeArg == "-hatch"
8727 || aChangeArg == "hatch")
8729 if (aNbChangeArgs < 2)
8731 std::cout << "Syntax error: need more arguments.\n";
8735 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
8736 aHatchStr.LowerCase();
8737 if (aHatchStr == "on")
8739 aClipPlane->SetCappingHatchOn();
8741 else if (aHatchStr == "off")
8743 aClipPlane->SetCappingHatchOff();
8747 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
8751 else if (aChangeArg == "-delete"
8752 || aChangeArg == "delete")
8754 removePlane (aRegPlanes, aPlaneName);
8757 else if (aChangeArg == "-set"
8758 || aChangeArg == "-unset"
8759 || aChangeArg == "-setoverrideglobal")
8761 // set / unset plane command
8762 const Standard_Boolean toSet = aChangeArg.StartsWith ("-set");
8763 const Standard_Boolean toOverrideGlobal = aChangeArg == "-setoverrideglobal";
8764 Standard_Integer anIt = 1;
8765 for (; anIt < aNbChangeArgs; ++anIt)
8767 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
8768 if (anEntityName.IsEmpty()
8769 || anEntityName.Value (1) == '-')
8773 else if (!toOverrideGlobal
8774 && ViewerTest_myViews.IsBound1 (anEntityName))
8776 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
8779 aView->AddClipPlane (aClipPlane);
8783 aView->RemoveClipPlane (aClipPlane);
8787 else if (GetMapOfAIS().IsBound2 (anEntityName))
8789 Handle(AIS_InteractiveObject) aIObj = GetMapOfAIS().Find2 (anEntityName);
8792 aIObj->AddClipPlane (aClipPlane);
8796 aIObj->RemoveClipPlane (aClipPlane);
8798 if (!aIObj->ClipPlanes().IsNull())
8800 aIObj->ClipPlanes()->SetOverrideGlobal (toOverrideGlobal);
8805 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
8812 // apply to active view
8815 anActiveView->AddClipPlane (aClipPlane);
8819 anActiveView->RemoveClipPlane (aClipPlane);
8824 anArgIter = anArgIter + anIt - 1;
8829 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
8834 ViewerTest::RedrawAllViews();
8838 //===============================================================================================
8839 //function : VZRange
8841 //===============================================================================================
8842 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8844 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
8846 if (aCurrentView.IsNull())
8848 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
8852 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
8856 theDi << "ZNear: " << aCamera->ZNear() << "\n";
8857 theDi << "ZFar: " << aCamera->ZFar() << "\n";
8863 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
8864 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
8866 if (aNewZNear >= aNewZFar)
8868 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
8872 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
8874 std::cout << theArgVec[0] << ": invalid arguments: ";
8875 std::cout << "znear, zfar should be positive for perspective camera.\n";
8879 aCamera->SetZRange (aNewZNear, aNewZFar);
8883 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
8887 aCurrentView->Redraw();
8892 //===============================================================================================
8893 //function : VAutoZFit
8895 //===============================================================================================
8896 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8898 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
8900 if (aCurrentView.IsNull())
8902 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
8906 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
8910 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
8916 theDi << "Auto z-fit mode: \n"
8917 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
8918 << "Scale: " << aScale << "\n";
8922 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
8926 aScale = Draw::Atoi (theArgVec[2]);
8929 aCurrentView->SetAutoZFitMode (isOn, aScale);
8930 aCurrentView->AutoZFit();
8931 aCurrentView->Redraw();
8936 //! Auxiliary function to print projection type
8937 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
8939 switch (theProjType)
8941 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
8942 case Graphic3d_Camera::Projection_Perspective: return "perspective";
8943 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
8944 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
8945 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
8950 //===============================================================================================
8951 //function : VCamera
8953 //===============================================================================================
8954 static int VCamera (Draw_Interpretor& theDI,
8955 Standard_Integer theArgsNb,
8956 const char** theArgVec)
8958 Handle(V3d_View) aView = ViewerTest::CurrentView();
8961 std::cout << "Error: no active view.\n";
8965 Handle(Graphic3d_Camera) aCamera = aView->Camera();
8968 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
8969 theDI << "FOVy: " << aCamera->FOVy() << "\n";
8970 theDI << "Distance: " << aCamera->Distance() << "\n";
8971 theDI << "IOD: " << aCamera->IOD() << "\n";
8972 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
8973 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
8974 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
8978 TCollection_AsciiString aPrsName;
8979 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
8981 Standard_CString anArg = theArgVec[anArgIter];
8982 TCollection_AsciiString anArgCase (anArg);
8983 anArgCase.LowerCase();
8984 if (anArgCase == "-proj"
8985 || anArgCase == "-projection"
8986 || anArgCase == "-projtype"
8987 || anArgCase == "-projectiontype")
8989 theDI << projTypeName (aCamera->ProjectionType()) << " ";
8991 else if (anArgCase == "-ortho"
8992 || anArgCase == "-orthographic")
8994 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
8996 else if (anArgCase == "-persp"
8997 || anArgCase == "-perspective"
8998 || anArgCase == "-perspmono"
8999 || anArgCase == "-perspectivemono"
9000 || anArgCase == "-mono")
9002 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
9004 else if (anArgCase == "-stereo"
9005 || anArgCase == "-stereoscopic"
9006 || anArgCase == "-perspstereo"
9007 || anArgCase == "-perspectivestereo")
9009 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9011 else if (anArgCase == "-left"
9012 || anArgCase == "-lefteye"
9013 || anArgCase == "-monoleft"
9014 || anArgCase == "-monolefteye"
9015 || anArgCase == "-perpsleft"
9016 || anArgCase == "-perpslefteye")
9018 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
9020 else if (anArgCase == "-right"
9021 || anArgCase == "-righteye"
9022 || anArgCase == "-monoright"
9023 || anArgCase == "-monorighteye"
9024 || anArgCase == "-perpsright")
9026 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
9028 else if (anArgCase == "-dist"
9029 || anArgCase == "-distance")
9031 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9032 if (anArgValue != NULL
9033 && *anArgValue != '-')
9036 aCamera->SetDistance (Draw::Atof (anArgValue));
9039 theDI << aCamera->Distance() << " ";
9041 else if (anArgCase == "-iod")
9043 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9044 if (anArgValue != NULL
9045 && *anArgValue != '-')
9048 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
9051 theDI << aCamera->IOD() << " ";
9053 else if (anArgCase == "-iodtype")
9055 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
9056 TCollection_AsciiString anValueCase (anArgValue);
9057 anValueCase.LowerCase();
9058 if (anValueCase == "abs"
9059 || anValueCase == "absolute")
9062 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
9065 else if (anValueCase == "rel"
9066 || anValueCase == "relative")
9069 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
9072 else if (*anArgValue != '-')
9074 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
9077 switch (aCamera->GetIODType())
9079 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
9080 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
9083 else if (anArgCase == "-zfocus")
9085 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9086 if (anArgValue != NULL
9087 && *anArgValue != '-')
9090 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
9093 theDI << aCamera->ZFocus() << " ";
9095 else if (anArgCase == "-zfocustype")
9097 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
9098 TCollection_AsciiString anValueCase (anArgValue);
9099 anValueCase.LowerCase();
9100 if (anValueCase == "abs"
9101 || anValueCase == "absolute")
9104 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
9107 else if (anValueCase == "rel"
9108 || anValueCase == "relative")
9111 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
9114 else if (*anArgValue != '-')
9116 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
9119 switch (aCamera->ZFocusType())
9121 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
9122 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
9125 else if (anArgCase == "-fov"
9126 || anArgCase == "-fovy")
9128 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
9129 if (anArgValue != NULL
9130 && *anArgValue != '-')
9133 aCamera->SetFOVy (Draw::Atof (anArgValue));
9136 theDI << aCamera->FOVy() << " ";
9138 else if (aPrsName.IsEmpty()
9139 && !anArgCase.StartsWith ("-"))
9145 std::cout << "Error: unknown argument '" << anArg << "'\n";
9150 if (aPrsName.IsEmpty()
9157 if (!aPrsName.IsEmpty())
9159 Handle(AIS_CameraFrustum) aCameraFrustum;
9160 if (GetMapOfAIS().IsBound2 (aPrsName))
9162 // find existing object
9163 aCameraFrustum = Handle(AIS_CameraFrustum)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
9164 if (aCameraFrustum.IsNull())
9166 std::cout << "Error: object '" << aPrsName << "'is already defined and is not a camera frustum!\n";
9171 if (aCameraFrustum.IsNull())
9173 aCameraFrustum = new AIS_CameraFrustum();
9177 // not include displayed object of old camera frustum in the new one.
9178 ViewerTest::GetAISContext()->Erase (aCameraFrustum, false);
9181 aCameraFrustum->SetCameraFrustum (aView->Camera());
9183 ViewerTest::Display (aPrsName, aCameraFrustum);
9189 //! Parse stereo output mode
9190 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
9191 Graphic3d_StereoMode& theMode)
9193 TCollection_AsciiString aFlag (theArg);
9195 if (aFlag == "quadbuffer")
9197 theMode = Graphic3d_StereoMode_QuadBuffer;
9199 else if (aFlag == "anaglyph")
9201 theMode = Graphic3d_StereoMode_Anaglyph;
9203 else if (aFlag == "row"
9204 || aFlag == "rowinterlaced")
9206 theMode = Graphic3d_StereoMode_RowInterlaced;
9208 else if (aFlag == "col"
9209 || aFlag == "colinterlaced"
9210 || aFlag == "columninterlaced")
9212 theMode = Graphic3d_StereoMode_ColumnInterlaced;
9214 else if (aFlag == "chess"
9215 || aFlag == "chessboard")
9217 theMode = Graphic3d_StereoMode_ChessBoard;
9219 else if (aFlag == "sbs"
9220 || aFlag == "sidebyside")
9222 theMode = Graphic3d_StereoMode_SideBySide;
9224 else if (aFlag == "ou"
9225 || aFlag == "overunder")
9227 theMode = Graphic3d_StereoMode_OverUnder;
9229 else if (aFlag == "pageflip"
9230 || aFlag == "softpageflip")
9232 theMode = Graphic3d_StereoMode_SoftPageFlip;
9236 return Standard_False;
9238 return Standard_True;
9241 //! Parse anaglyph filter
9242 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
9243 Graphic3d_RenderingParams::Anaglyph& theFilter)
9245 TCollection_AsciiString aFlag (theArg);
9247 if (aFlag == "redcyansimple")
9249 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9251 else if (aFlag == "redcyan"
9252 || aFlag == "redcyanoptimized")
9254 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
9256 else if (aFlag == "yellowbluesimple")
9258 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
9260 else if (aFlag == "yellowblue"
9261 || aFlag == "yellowblueoptimized")
9263 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
9265 else if (aFlag == "greenmagenta"
9266 || aFlag == "greenmagentasimple")
9268 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
9272 return Standard_False;
9274 return Standard_True;
9277 //==============================================================================
9278 //function : VStereo
9280 //==============================================================================
9282 static int VStereo (Draw_Interpretor& theDI,
9283 Standard_Integer theArgNb,
9284 const char** theArgVec)
9286 Handle(V3d_View) aView = ViewerTest::CurrentView();
9291 std::cout << "Error: no active viewer!\n";
9295 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
9296 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
9299 TCollection_AsciiString aMode;
9300 switch (aView->RenderingParams().StereoMode)
9302 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
9303 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
9304 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
9305 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
9306 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
9307 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
9308 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
9309 case Graphic3d_StereoMode_Anaglyph :
9311 switch (aView->RenderingParams().AnaglyphFilter)
9313 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
9314 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
9315 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
9316 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
9317 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
9322 theDI << "Mode " << aMode << "\n";
9327 Handle(Graphic3d_Camera) aCamera;
9328 Graphic3d_RenderingParams* aParams = NULL;
9329 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
9330 if (!aView.IsNull())
9332 aParams = &aView->ChangeRenderingParams();
9333 aMode = aParams->StereoMode;
9334 aCamera = aView->Camera();
9337 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
9338 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
9340 Standard_CString anArg = theArgVec[anArgIter];
9341 TCollection_AsciiString aFlag (anArg);
9343 if (anUpdateTool.parseRedrawMode (aFlag))
9347 else if (aFlag == "0"
9350 if (++anArgIter < theArgNb)
9352 std::cout << "Error: wrong number of arguments!\n";
9356 if (!aCamera.IsNull()
9357 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
9359 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
9361 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
9364 else if (aFlag == "1"
9367 if (++anArgIter < theArgNb)
9369 std::cout << "Error: wrong number of arguments!\n";
9373 if (!aCamera.IsNull())
9375 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9377 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9380 else if (aFlag == "-reverse"
9381 || aFlag == "-reversed"
9382 || aFlag == "-swap")
9384 Standard_Boolean toEnable = Standard_True;
9385 if (++anArgIter < theArgNb
9386 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9390 aParams->ToReverseStereo = toEnable;
9392 else if (aFlag == "-noreverse"
9393 || aFlag == "-noswap")
9395 Standard_Boolean toDisable = Standard_True;
9396 if (++anArgIter < theArgNb
9397 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
9401 aParams->ToReverseStereo = !toDisable;
9403 else if (aFlag == "-mode"
9404 || aFlag == "-stereomode")
9406 if (++anArgIter >= theArgNb
9407 || !parseStereoMode (theArgVec[anArgIter], aMode))
9409 std::cout << "Error: syntax error at '" << anArg << "'\n";
9413 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9415 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9418 else if (aFlag == "-anaglyph"
9419 || aFlag == "-anaglyphfilter")
9421 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9422 if (++anArgIter >= theArgNb
9423 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
9425 std::cout << "Error: syntax error at '" << anArg << "'\n";
9429 aMode = Graphic3d_StereoMode_Anaglyph;
9430 aParams->AnaglyphFilter = aFilter;
9432 else if (parseStereoMode (anArg, aMode)) // short syntax
9434 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9436 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9441 std::cout << "Error: syntax error at '" << anArg << "'\n";
9446 if (!aView.IsNull())
9448 aParams->StereoMode = aMode;
9449 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9454 //===============================================================================================
9455 //function : VDefaults
9457 //===============================================================================================
9458 static int VDefaults (Draw_Interpretor& theDi,
9459 Standard_Integer theArgsNb,
9460 const char** theArgVec)
9462 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
9465 std::cerr << "No active viewer!\n";
9469 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
9472 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
9474 theDi << "DeflType: relative\n"
9475 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
9479 theDi << "DeflType: absolute\n"
9480 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
9482 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
9483 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
9487 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
9489 TCollection_AsciiString anArg (theArgVec[anArgIter]);
9491 if (anArg == "-ABSDEFL"
9492 || anArg == "-ABSOLUTEDEFLECTION"
9494 || anArg == "-DEFLECTION")
9496 if (++anArgIter >= theArgsNb)
9498 std::cout << "Error: wrong syntax at " << anArg << "\n";
9501 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
9502 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
9504 else if (anArg == "-RELDEFL"
9505 || anArg == "-RELATIVEDEFLECTION"
9506 || anArg == "-DEVCOEFF"
9507 || anArg == "-DEVIATIONCOEFF"
9508 || anArg == "-DEVIATIONCOEFFICIENT")
9510 if (++anArgIter >= theArgsNb)
9512 std::cout << "Error: wrong syntax at " << anArg << "\n";
9515 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
9516 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
9518 else if (anArg == "-ANGDEFL"
9519 || anArg == "-ANGULARDEFL"
9520 || anArg == "-ANGULARDEFLECTION")
9522 if (++anArgIter >= theArgsNb)
9524 std::cout << "Error: wrong syntax at " << anArg << "\n";
9527 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
9528 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
9530 else if (anArg == "-AUTOTR"
9531 || anArg == "-AUTOTRIANG"
9532 || anArg == "-AUTOTRIANGULATION")
9534 if (++anArgIter >= theArgsNb)
9536 std::cout << "Error: wrong syntax at " << anArg << "\n";
9539 TCollection_AsciiString aValue (theArgVec[anArgIter]);
9544 aDefParams->SetAutoTriangulation (Standard_True);
9546 else if (aValue == "off"
9549 aDefParams->SetAutoTriangulation (Standard_False);
9554 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
9561 //! Auxiliary method
9562 inline void addLight (const Handle(V3d_Light)& theLightNew,
9563 const Graphic3d_ZLayerId theLayer,
9564 const Standard_Boolean theIsGlobal)
9566 if (theLightNew.IsNull())
9571 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9572 if (theLayer == Graphic3d_ZLayerId_UNKNOWN)
9574 aViewer->AddLight (theLightNew);
9577 aViewer->SetLightOn (theLightNew);
9581 ViewerTest::CurrentView()->SetLightOn (theLightNew);
9586 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer);
9587 if (aSettings.Lights().IsNull())
9589 aSettings.SetLights (new Graphic3d_LightSet());
9591 aSettings.Lights()->Add (theLightNew);
9592 aViewer->SetZLayerSettings (theLayer, aSettings);
9596 //! Auxiliary method
9597 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
9599 TCollection_AsciiString anArgNextCase (theArgNext);
9600 anArgNextCase.UpperCase();
9601 if (anArgNextCase.Length() > 5
9602 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
9604 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
9608 return theArgNext.IntegerValue();
9612 //===============================================================================================
9615 //===============================================================================================
9616 static int VLight (Draw_Interpretor& theDi,
9617 Standard_Integer theArgsNb,
9618 const char** theArgVec)
9620 Handle(V3d_View) aView = ViewerTest::CurrentView();
9621 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9623 || aViewer.IsNull())
9625 std::cerr << "No active viewer!\n";
9629 Standard_Real anXYZ[3] = {};
9630 Standard_Real anAtten[2] = {};
9633 // print lights info
9634 Standard_Integer aLightId = 0;
9635 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
9637 Handle(V3d_Light) aLight = aLightIter.Value();
9638 const Quantity_Color aColor = aLight->Color();
9639 theDi << "Light #" << aLightId
9640 << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "")
9641 << " [" << aLight->GetId() << "]" << "\n";
9642 switch (aLight->Type())
9646 theDi << " Type: Ambient\n";
9647 theDi << " Intensity: " << aLight->Intensity() << "\n";
9650 case V3d_DIRECTIONAL:
9652 theDi << " Type: Directional\n";
9653 theDi << " Intensity: " << aLight->Intensity() << "\n";
9654 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9655 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
9656 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
9657 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9660 case V3d_POSITIONAL:
9662 theDi << " Type: Positional\n";
9663 theDi << " Intensity: " << aLight->Intensity() << "\n";
9664 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9665 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
9666 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9667 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9668 aLight->Attenuation (anAtten[0], anAtten[1]);
9669 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
9674 theDi << " Type: Spot\n";
9675 theDi << " Intensity: " << aLight->Intensity() << "\n";
9676 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9677 aLight->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9678 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9679 aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
9680 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9681 aLight->Attenuation (anAtten[0], anAtten[1]);
9682 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
9683 theDi << " Angle: " << (aLight->Angle() * 180.0 / M_PI) << "\n";
9684 theDi << " Exponent: " << aLight->Concentration() << "\n";
9689 theDi << " Type: UNKNOWN\n";
9693 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n";
9697 Handle(V3d_Light) aLightNew;
9698 Handle(V3d_Light) aLightOld;
9699 Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN;
9700 Standard_Boolean isGlobal = Standard_True;
9701 Standard_Boolean toCreate = Standard_False;
9702 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
9703 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
9705 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
9707 TCollection_AsciiString aName, aValue;
9708 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
9709 TCollection_AsciiString anArgCase (anArg);
9710 anArgCase.UpperCase();
9711 if (anUpdateTool.parseRedrawMode (anArg))
9716 if (anArgCase.IsEqual ("NEW")
9717 || anArgCase.IsEqual ("ADD")
9718 || anArgCase.IsEqual ("CREATE")
9719 || anArgCase.IsEqual ("-NEW")
9720 || anArgCase.IsEqual ("-ADD")
9721 || anArgCase.IsEqual ("-CREATE"))
9723 toCreate = Standard_True;
9725 else if (anArgCase.IsEqual ("-LAYER")
9726 || anArgCase.IsEqual ("-ZLAYER"))
9728 if (++anArgIt >= theArgsNb)
9730 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9734 TCollection_AsciiString aValStr (theArgVec[anArgIt]);
9735 aValStr.LowerCase();
9736 if (aValStr == "default"
9737 || aValStr == "def")
9739 aLayer = Graphic3d_ZLayerId_Default;
9741 else if (aValStr == "top")
9743 aLayer = Graphic3d_ZLayerId_Top;
9745 else if (aValStr == "topmost")
9747 aLayer = Graphic3d_ZLayerId_Topmost;
9749 else if (aValStr == "toposd"
9750 || aValStr == "osd")
9752 aLayer = Graphic3d_ZLayerId_TopOSD;
9754 else if (aValStr == "botosd"
9755 || aValStr == "bottom")
9757 aLayer = Graphic3d_ZLayerId_BotOSD;
9759 else if (aValStr.IsIntegerValue())
9761 aLayer = Draw::Atoi (theArgVec[anArgIt]);
9765 std::cout << "Wrong syntax at argument '" << anArg << "'!\n";
9769 else if (anArgCase.IsEqual ("GLOB")
9770 || anArgCase.IsEqual ("GLOBAL")
9771 || anArgCase.IsEqual ("-GLOB")
9772 || anArgCase.IsEqual ("-GLOBAL"))
9774 isGlobal = Standard_True;
9776 else if (anArgCase.IsEqual ("LOC")
9777 || anArgCase.IsEqual ("LOCAL")
9778 || anArgCase.IsEqual ("-LOC")
9779 || anArgCase.IsEqual ("-LOCAL"))
9781 isGlobal = Standard_False;
9783 else if (anArgCase.IsEqual ("DEF")
9784 || anArgCase.IsEqual ("DEFAULTS")
9785 || anArgCase.IsEqual ("-DEF")
9786 || anArgCase.IsEqual ("-DEFAULTS"))
9788 toCreate = Standard_False;
9789 aViewer->SetDefaultLights();
9791 else if (anArgCase.IsEqual ("CLR")
9792 || anArgCase.IsEqual ("CLEAR")
9793 || anArgCase.IsEqual ("-CLR")
9794 || anArgCase.IsEqual ("-CLEAR"))
9796 toCreate = Standard_False;
9798 TColStd_SequenceOfInteger aLayers;
9799 aViewer->GetAllZLayers (aLayers);
9800 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
9802 if (aLayeriter.Value() == aLayer
9803 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
9805 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
9806 aSettings.SetLights (Handle(Graphic3d_LightSet)());
9807 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
9808 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
9815 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
9817 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
9819 Handle(V3d_Light) aLight = aLightIter.Value();
9820 aViewer->DelLight (aLight);
9821 aLightIter = aView->ActiveLightIterator();
9825 else if (anArgCase.IsEqual ("AMB")
9826 || anArgCase.IsEqual ("AMBIENT")
9827 || anArgCase.IsEqual ("AMBLIGHT"))
9831 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9835 addLight (aLightNew, aLayer, isGlobal);
9836 toCreate = Standard_False;
9837 aLightNew = new V3d_AmbientLight();
9839 else if (anArgCase.IsEqual ("DIRECTIONAL")
9840 || anArgCase.IsEqual ("DIRLIGHT"))
9844 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9848 addLight (aLightNew, aLayer, isGlobal);
9849 toCreate = Standard_False;
9850 aLightNew = new V3d_DirectionalLight();
9852 else if (anArgCase.IsEqual ("SPOT")
9853 || anArgCase.IsEqual ("SPOTLIGHT"))
9857 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9861 addLight (aLightNew, aLayer, isGlobal);
9862 toCreate = Standard_False;
9863 aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0));
9865 else if (anArgCase.IsEqual ("POSLIGHT")
9866 || anArgCase.IsEqual ("POSITIONAL"))
9870 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9874 addLight (aLightNew, aLayer, isGlobal);
9875 toCreate = Standard_False;
9876 aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0));
9878 else if (anArgCase.IsEqual ("CHANGE")
9879 || anArgCase.IsEqual ("-CHANGE"))
9881 if (++anArgIt >= theArgsNb)
9883 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9887 addLight (aLightNew, aLayer, isGlobal);
9888 aLightNew.Nullify();
9889 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
9890 Standard_Integer aLightIt = 0;
9891 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
9893 if (aLightIt == aLightId)
9895 aLightOld = aLightIter.Value();
9900 if (aLightOld.IsNull())
9902 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
9906 else if (anArgCase.IsEqual ("DEL")
9907 || anArgCase.IsEqual ("DELETE")
9908 || anArgCase.IsEqual ("-DEL")
9909 || anArgCase.IsEqual ("-DELETE"))
9911 Handle(V3d_Light) aLightDel;
9912 if (++anArgIt >= theArgsNb)
9914 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9918 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
9919 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
9920 Standard_Integer aLightIt = 0;
9921 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
9923 aLightDel = aLightIter.Value();
9924 if (aLightIt == aLightDelId)
9929 if (aLightDel.IsNull())
9934 TColStd_SequenceOfInteger aLayers;
9935 aViewer->GetAllZLayers (aLayers);
9936 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
9938 if (aLayeriter.Value() == aLayer
9939 || aLayer == Graphic3d_ZLayerId_UNKNOWN)
9941 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
9942 if (!aSettings.Lights().IsNull())
9944 aSettings.Lights()->Remove (aLightDel);
9945 if (aSettings.Lights()->IsEmpty())
9947 aSettings.SetLights (Handle(Graphic3d_LightSet)());
9950 aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
9951 if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
9958 if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
9960 aViewer->DelLight (aLightDel);
9963 else if (anArgCase.IsEqual ("COLOR")
9964 || anArgCase.IsEqual ("COLOUR")
9965 || anArgCase.IsEqual ("-COLOR")
9966 || anArgCase.IsEqual ("-COLOUR"))
9968 if (++anArgIt >= theArgsNb
9969 || aLightCurr.IsNull())
9971 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9975 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
9976 anArgNext.UpperCase();
9977 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
9978 aLightCurr->SetColor (aColor);
9980 else if (anArgCase.IsEqual ("POS")
9981 || anArgCase.IsEqual ("POSITION")
9982 || anArgCase.IsEqual ("-POS")
9983 || anArgCase.IsEqual ("-POSITION"))
9985 if ((anArgIt + 3) >= theArgsNb
9986 || aLightCurr.IsNull()
9987 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
9988 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
9990 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9994 anXYZ[0] = Atof (theArgVec[++anArgIt]);
9995 anXYZ[1] = Atof (theArgVec[++anArgIt]);
9996 anXYZ[2] = Atof (theArgVec[++anArgIt]);
9997 aLightCurr->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
9999 else if (anArgCase.IsEqual ("DIR")
10000 || anArgCase.IsEqual ("DIRECTION")
10001 || anArgCase.IsEqual ("-DIR")
10002 || anArgCase.IsEqual ("-DIRECTION"))
10004 if ((anArgIt + 3) >= theArgsNb
10005 || aLightCurr.IsNull()
10006 || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL
10007 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
10009 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10013 anXYZ[0] = Atof (theArgVec[++anArgIt]);
10014 anXYZ[1] = Atof (theArgVec[++anArgIt]);
10015 anXYZ[2] = Atof (theArgVec[++anArgIt]);
10016 aLightCurr->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
10018 else if (anArgCase.IsEqual ("SM")
10019 || anArgCase.IsEqual ("SMOOTHNESS")
10020 || anArgCase.IsEqual ("-SM")
10021 || anArgCase.IsEqual ("-SMOOTHNESS"))
10023 if (++anArgIt >= theArgsNb
10024 || aLightCurr.IsNull())
10026 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10030 Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
10031 if (Abs (aSmoothness) <= ShortRealEpsilon())
10033 aLightCurr->SetIntensity (1.f);
10035 else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon())
10037 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
10041 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
10042 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
10045 if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL)
10047 aLightCurr->SetSmoothRadius (aSmoothness);
10049 else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
10051 aLightCurr->SetSmoothAngle (aSmoothness);
10054 else if (anArgCase.IsEqual ("INT")
10055 || anArgCase.IsEqual ("INTENSITY")
10056 || anArgCase.IsEqual ("-INT")
10057 || anArgCase.IsEqual ("-INTENSITY"))
10059 if (++anArgIt >= theArgsNb
10060 || aLightCurr.IsNull())
10062 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10066 Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
10067 aLightCurr->SetIntensity (aIntensity);
10069 else if (anArgCase.IsEqual ("ANG")
10070 || anArgCase.IsEqual ("ANGLE")
10071 || anArgCase.IsEqual ("-ANG")
10072 || anArgCase.IsEqual ("-ANGLE"))
10074 if (++anArgIt >= theArgsNb
10075 || aLightCurr.IsNull()
10076 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
10078 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10082 Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
10083 aLightCurr->SetAngle (Standard_ShortReal (anAngle / 180.0 * M_PI));
10085 else if (anArgCase.IsEqual ("CONSTATTEN")
10086 || anArgCase.IsEqual ("CONSTATTENUATION")
10087 || anArgCase.IsEqual ("-CONSTATTEN")
10088 || anArgCase.IsEqual ("-CONSTATTENUATION"))
10090 if (++anArgIt >= theArgsNb
10091 || aLightCurr.IsNull()
10092 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10093 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
10095 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10099 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
10100 anAtten[0] = Atof (theArgVec[anArgIt]);
10101 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
10103 else if (anArgCase.IsEqual ("LINATTEN")
10104 || anArgCase.IsEqual ("LINEARATTEN")
10105 || anArgCase.IsEqual ("LINEARATTENUATION")
10106 || anArgCase.IsEqual ("-LINATTEN")
10107 || anArgCase.IsEqual ("-LINEARATTEN")
10108 || anArgCase.IsEqual ("-LINEARATTENUATION"))
10110 if (++anArgIt >= theArgsNb
10111 || aLightCurr.IsNull()
10112 || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
10113 && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
10115 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10119 aLightCurr->Attenuation (anAtten[0], anAtten[1]);
10120 anAtten[1] = Atof (theArgVec[anArgIt]);
10121 aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
10123 else if (anArgCase.IsEqual ("EXP")
10124 || anArgCase.IsEqual ("EXPONENT")
10125 || anArgCase.IsEqual ("SPOTEXP")
10126 || anArgCase.IsEqual ("SPOTEXPONENT")
10127 || anArgCase.IsEqual ("-EXP")
10128 || anArgCase.IsEqual ("-EXPONENT")
10129 || anArgCase.IsEqual ("-SPOTEXP")
10130 || anArgCase.IsEqual ("-SPOTEXPONENT"))
10132 if (++anArgIt >= theArgsNb
10133 || aLightCurr.IsNull()
10134 || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
10136 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10140 aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt]));
10142 else if (anArgCase.IsEqual ("HEAD")
10143 || anArgCase.IsEqual ("HEADLIGHT")
10144 || anArgCase.IsEqual ("-HEAD")
10145 || anArgCase.IsEqual ("-HEADLIGHT"))
10147 if (aLightCurr.IsNull()
10148 || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
10150 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
10154 Standard_Boolean isHeadLight = Standard_True;
10155 if (anArgIt + 1 < theArgsNb
10156 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight))
10160 aLightCurr->SetHeadlight (isHeadLight);
10164 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
10168 addLight (aLightNew, aLayer, isGlobal);
10172 //! Read Graphic3d_RenderingParams::PerfCounters flag.
10173 static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theValue,
10174 Standard_Boolean& theToReset,
10175 Graphic3d_RenderingParams::PerfCounters& theFlagsRem,
10176 Graphic3d_RenderingParams::PerfCounters& theFlagsAdd)
10178 Graphic3d_RenderingParams::PerfCounters aFlag = Graphic3d_RenderingParams::PerfCounters_NONE;
10179 TCollection_AsciiString aVal = theValue;
10180 Standard_Boolean toReverse = Standard_False;
10181 if (aVal == "none")
10183 theToReset = Standard_True;
10184 return Standard_True;
10186 else if (aVal.StartsWith ("-"))
10188 toReverse = Standard_True;
10189 aVal = aVal.SubString (2, aVal.Length());
10191 else if (aVal.StartsWith ("no"))
10193 toReverse = Standard_True;
10194 aVal = aVal.SubString (3, aVal.Length());
10196 else if (aVal.StartsWith ("+"))
10198 aVal = aVal.SubString (2, aVal.Length());
10202 theToReset = Standard_True;
10206 || aVal == "framerate") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameRate;
10207 else if (aVal == "cpu") aFlag = Graphic3d_RenderingParams::PerfCounters_CPU;
10208 else if (aVal == "layers") aFlag = Graphic3d_RenderingParams::PerfCounters_Layers;
10209 else if (aVal == "structs"
10210 || aVal == "structures"
10211 || aVal == "objects") aFlag = Graphic3d_RenderingParams::PerfCounters_Structures;
10212 else if (aVal == "groups") aFlag = Graphic3d_RenderingParams::PerfCounters_Groups;
10213 else if (aVal == "arrays") aFlag = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
10214 else if (aVal == "tris"
10215 || aVal == "triangles") aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles;
10216 else if (aVal == "pnts"
10217 || aVal == "points") aFlag = Graphic3d_RenderingParams::PerfCounters_Points;
10218 else if (aVal == "mem"
10219 || aVal == "gpumem"
10220 || aVal == "estimmem") aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem;
10221 else if (aVal == "skipimmediate"
10222 || aVal == "noimmediate") aFlag = Graphic3d_RenderingParams::PerfCounters_SkipImmediate;
10223 else if (aVal == "frametime"
10224 || aVal == "frametimers"
10225 || aVal == "time") aFlag = Graphic3d_RenderingParams::PerfCounters_FrameTime;
10226 else if (aVal == "basic") aFlag = Graphic3d_RenderingParams::PerfCounters_Basic;
10227 else if (aVal == "extended"
10228 || aVal == "verbose"
10229 || aVal == "extra") aFlag = Graphic3d_RenderingParams::PerfCounters_Extended;
10230 else if (aVal == "full"
10231 || aVal == "all") aFlag = Graphic3d_RenderingParams::PerfCounters_All;
10234 return Standard_False;
10239 theFlagsRem = Graphic3d_RenderingParams::PerfCounters(theFlagsRem | aFlag);
10243 theFlagsAdd = Graphic3d_RenderingParams::PerfCounters(theFlagsAdd | aFlag);
10245 return Standard_True;
10248 //! Read Graphic3d_RenderingParams::PerfCounters flags.
10249 static Standard_Boolean convertToPerfStatsFlags (const TCollection_AsciiString& theValue,
10250 Graphic3d_RenderingParams::PerfCounters& theFlags)
10252 TCollection_AsciiString aValue = theValue;
10253 Graphic3d_RenderingParams::PerfCounters aFlagsRem = Graphic3d_RenderingParams::PerfCounters_NONE;
10254 Graphic3d_RenderingParams::PerfCounters aFlagsAdd = Graphic3d_RenderingParams::PerfCounters_NONE;
10255 Standard_Boolean toReset = Standard_False;
10258 Standard_Integer aSplitPos = aValue.Search ("|");
10259 if (aSplitPos <= 0)
10261 if (!parsePerfStatsFlag (aValue, toReset, aFlagsRem, aFlagsAdd))
10263 return Standard_False;
10267 theFlags = Graphic3d_RenderingParams::PerfCounters_NONE;
10269 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags | aFlagsAdd);
10270 theFlags = Graphic3d_RenderingParams::PerfCounters(theFlags & ~aFlagsRem);
10271 return Standard_True;
10276 TCollection_AsciiString aSubValue = aValue.SubString (1, aSplitPos - 1);
10277 if (!parsePerfStatsFlag (aSubValue, toReset, aFlagsRem, aFlagsAdd))
10279 return Standard_False;
10282 aValue = aValue.SubString (aSplitPos + 1, aValue.Length());
10286 //=======================================================================
10287 //function : VRenderParams
10288 //purpose : Enables/disables rendering features
10289 //=======================================================================
10291 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
10292 Standard_Integer theArgNb,
10293 const char** theArgVec)
10295 Handle(V3d_View) aView = ViewerTest::CurrentView();
10296 if (aView.IsNull())
10298 std::cerr << "Error: no active viewer!\n";
10302 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
10303 TCollection_AsciiString aCmdName (theArgVec[0]);
10304 aCmdName.LowerCase();
10305 if (aCmdName == "vraytrace")
10309 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
10312 else if (theArgNb == 2)
10314 TCollection_AsciiString aValue (theArgVec[1]);
10315 aValue.LowerCase();
10319 aParams.Method = Graphic3d_RM_RAYTRACING;
10323 else if (aValue == "off"
10326 aParams.Method = Graphic3d_RM_RASTERIZATION;
10332 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
10338 std::cout << "Error: wrong number of arguments\n";
10345 theDI << "renderMode: ";
10346 switch (aParams.Method)
10348 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
10349 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
10352 theDI << "transparency: ";
10353 switch (aParams.TransparencyMethod)
10355 case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break;
10356 case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: "
10357 << TCollection_AsciiString (aParams.OitDepthFactor); break;
10360 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
10361 theDI << "rendScale: " << aParams.RenderResolutionScale << "\n";
10362 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
10363 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
10364 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
10365 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
10366 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
10367 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
10368 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
10369 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
10370 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
10371 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
10372 theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
10373 theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n";
10374 theDI << "shadingModel: ";
10375 switch (aView->ShadingModel())
10377 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
10378 case Graphic3d_TOSM_UNLIT: theDI << "unlit"; break;
10379 case Graphic3d_TOSM_FACET: theDI << "flat"; break;
10380 case Graphic3d_TOSM_VERTEX: theDI << "gouraud"; break;
10381 case Graphic3d_TOSM_FRAGMENT: theDI << "phong"; break;
10384 theDI << "perfCounters:";
10385 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0)
10389 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
10393 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
10395 theDI << " structs";
10397 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Groups) != 0)
10399 theDI << " groups";
10401 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0)
10403 theDI << " arrays";
10405 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0)
10409 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
10413 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0)
10415 theDI << " gpumem";
10417 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_FrameTime) != 0)
10419 theDI << " frameTime";
10421 if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_SkipImmediate) != 0)
10423 theDI << " skipimmediate";
10425 if (aParams.CollectedStats == Graphic3d_RenderingParams::PerfCounters_NONE)
10431 theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n";
10432 theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n";
10433 theDI << "frustum culling: " << (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On ? "on" :
10434 aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off ? "off" :
10435 "noUpdate") << "\n";
10440 Standard_Boolean toPrint = Standard_False;
10441 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
10442 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
10444 Standard_CString anArg (theArgVec[anArgIter]);
10445 TCollection_AsciiString aFlag (anArg);
10447 if (anUpdateTool.parseRedrawMode (aFlag))
10451 else if (aFlag == "-echo"
10452 || aFlag == "-print")
10454 toPrint = Standard_True;
10455 anUpdateTool.Invalidate();
10457 else if (aFlag == "-mode"
10458 || aFlag == "-rendermode"
10459 || aFlag == "-render_mode")
10463 switch (aParams.Method)
10465 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
10466 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
10472 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10476 else if (aFlag == "-ray"
10477 || aFlag == "-raytrace")
10481 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
10485 aParams.Method = Graphic3d_RM_RAYTRACING;
10487 else if (aFlag == "-rast"
10488 || aFlag == "-raster"
10489 || aFlag == "-rasterization")
10493 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
10497 aParams.Method = Graphic3d_RM_RASTERIZATION;
10499 else if (aFlag == "-msaa")
10503 theDI << aParams.NbMsaaSamples << " ";
10506 else if (++anArgIter >= theArgNb)
10508 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10512 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
10513 if (aNbSamples < 0)
10515 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
10520 aParams.NbMsaaSamples = aNbSamples;
10523 else if (aFlag == "-oit")
10527 if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
10529 theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " ";
10533 theDI << "off" << " ";
10537 else if (++anArgIter >= theArgNb)
10539 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10543 TCollection_AsciiString aParam = theArgVec[anArgIter];
10544 aParam.LowerCase();
10545 if (aParam.IsRealValue())
10547 const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
10548 if (aWeight < 0.f || aWeight > 1.f)
10550 std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n";
10554 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
10555 aParams.OitDepthFactor = aWeight;
10557 else if (aParam == "off")
10559 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED;
10563 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10567 else if (aFlag == "-depthprepass")
10571 theDI << (aParams.ToEnableDepthPrepass ? "on " : "off ");
10574 aParams.ToEnableDepthPrepass = Standard_True;
10575 if (anArgIter + 1 < theArgNb
10576 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableDepthPrepass))
10581 else if (aFlag == "-samplealphatocoverage"
10582 || aFlag == "-alphatocoverage")
10586 theDI << (aParams.ToEnableAlphaToCoverage ? "on " : "off ");
10589 aParams.ToEnableAlphaToCoverage = Standard_True;
10590 if (anArgIter + 1 < theArgNb
10591 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], aParams.ToEnableAlphaToCoverage))
10596 else if (aFlag == "-rendscale"
10597 || aFlag == "-renderscale"
10598 || aFlag == "-renderresolutionscale")
10602 theDI << aParams.RenderResolutionScale << " ";
10605 else if (++anArgIter >= theArgNb)
10607 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10611 const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
10614 std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n";
10619 aParams.RenderResolutionScale = Standard_ShortReal(aScale);
10622 else if (aFlag == "-raydepth"
10623 || aFlag == "-ray_depth")
10627 theDI << aParams.RaytracingDepth << " ";
10630 else if (++anArgIter >= theArgNb)
10632 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10636 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
10638 // We allow RaytracingDepth be more than 10 in case of GI enabled
10639 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
10641 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
10646 aParams.RaytracingDepth = aDepth;
10649 else if (aFlag == "-shad"
10650 || aFlag == "-shadows")
10654 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
10658 Standard_Boolean toEnable = Standard_True;
10659 if (++anArgIter < theArgNb
10660 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10664 aParams.IsShadowEnabled = toEnable;
10666 else if (aFlag == "-refl"
10667 || aFlag == "-reflections")
10671 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
10675 Standard_Boolean toEnable = Standard_True;
10676 if (++anArgIter < theArgNb
10677 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10681 aParams.IsReflectionEnabled = toEnable;
10683 else if (aFlag == "-fsaa")
10687 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
10691 Standard_Boolean toEnable = Standard_True;
10692 if (++anArgIter < theArgNb
10693 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10697 aParams.IsAntialiasingEnabled = toEnable;
10699 else if (aFlag == "-gleam")
10703 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
10707 Standard_Boolean toEnable = Standard_True;
10708 if (++anArgIter < theArgNb
10709 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10713 aParams.IsTransparentShadowEnabled = toEnable;
10715 else if (aFlag == "-gi")
10719 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
10723 Standard_Boolean toEnable = Standard_True;
10724 if (++anArgIter < theArgNb
10725 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10729 aParams.IsGlobalIlluminationEnabled = toEnable;
10732 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
10735 else if (aFlag == "-blockedrng"
10736 || aFlag == "-brng")
10740 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
10744 Standard_Boolean toEnable = Standard_True;
10745 if (++anArgIter < theArgNb
10746 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10750 aParams.CoherentPathTracingMode = toEnable;
10752 else if (aFlag == "-maxrad")
10756 theDI << aParams.RadianceClampingValue << " ";
10759 else if (++anArgIter >= theArgNb)
10761 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10765 const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
10766 if (!aMaxRadStr.IsRealValue())
10768 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10772 const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
10773 if (aMaxRadiance <= 0.0)
10775 std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n";
10780 aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
10783 else if (aFlag == "-iss")
10787 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
10791 Standard_Boolean toEnable = Standard_True;
10792 if (++anArgIter < theArgNb
10793 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10797 aParams.AdaptiveScreenSampling = toEnable;
10799 else if (aFlag == "-issd")
10803 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
10807 Standard_Boolean toEnable = Standard_True;
10808 if (++anArgIter < theArgNb
10809 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10813 aParams.ShowSamplingTiles = toEnable;
10815 else if (aFlag == "-nbtiles")
10819 theDI << aParams.NbRayTracingTiles << " ";
10822 else if (++anArgIter >= theArgNb)
10824 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10828 const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]);
10832 std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n";
10833 std::cerr << "Specify value in range [64, 1024].\n";
10838 aParams.NbRayTracingTiles = aNbTiles;
10841 else if (aFlag == "-env")
10845 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
10849 Standard_Boolean toEnable = Standard_True;
10850 if (++anArgIter < theArgNb
10851 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10855 aParams.UseEnvironmentMapBackground = toEnable;
10857 else if (aFlag == "-twoside")
10861 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
10865 Standard_Boolean toEnable = Standard_True;
10866 if (++anArgIter < theArgNb
10867 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10871 aParams.TwoSidedBsdfModels = toEnable;
10873 else if (aFlag == "-shademodel"
10874 || aFlag == "-shadingmodel"
10875 || aFlag == "-shading")
10879 switch (aView->ShadingModel())
10881 case Graphic3d_TOSM_DEFAULT: theDI << "default"; break;
10882 case Graphic3d_TOSM_UNLIT: theDI << "unlit "; break;
10883 case Graphic3d_TOSM_FACET: theDI << "flat "; break;
10884 case Graphic3d_TOSM_VERTEX: theDI << "gouraud "; break;
10885 case Graphic3d_TOSM_FRAGMENT: theDI << "phong "; break;
10890 if (++anArgIter >= theArgNb)
10892 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10895 Graphic3d_TypeOfShadingModel aModel = Graphic3d_TOSM_DEFAULT;
10896 if (ViewerTest::ParseShadingModel (theArgVec[anArgIter], aModel)
10897 && aModel != Graphic3d_TOSM_DEFAULT)
10899 aView->SetShadingModel (aModel);
10903 std::cout << "Error: unknown shading model '" << theArgVec[anArgIter] << "'\n";
10907 else if (aFlag == "-resolution")
10909 if (++anArgIter >= theArgNb)
10911 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10915 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
10916 if (aResolution.IsIntegerValue())
10918 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
10922 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10926 else if (aFlag == "-rebuildglsl"
10927 || aFlag == "-rebuild")
10931 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
10935 Standard_Boolean toEnable = Standard_True;
10936 if (++anArgIter < theArgNb
10937 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10941 aParams.RebuildRayTracingShaders = toEnable;
10943 else if (aFlag == "-focal")
10945 if (++anArgIter >= theArgNb)
10947 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10951 TCollection_AsciiString aParam (theArgVec[anArgIter]);
10952 if (aParam.IsRealValue())
10954 float aFocalDist = static_cast<float> (aParam.RealValue());
10955 if (aFocalDist < 0)
10957 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
10960 aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist;
10964 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10968 else if (aFlag == "-aperture")
10970 if (++anArgIter >= theArgNb)
10972 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10976 TCollection_AsciiString aParam(theArgVec[anArgIter]);
10977 if (aParam.IsRealValue())
10979 float aApertureSize = static_cast<float> (aParam.RealValue());
10980 if (aApertureSize < 0)
10982 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
10985 aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize;
10989 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10993 else if (aFlag == "-exposure")
10995 if (++anArgIter >= theArgNb)
10997 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11001 TCollection_AsciiString anExposure (theArgVec[anArgIter]);
11002 if (anExposure.IsRealValue())
11004 aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
11008 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11012 else if (aFlag == "-whitepoint")
11014 if (++anArgIter >= theArgNb)
11016 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11020 TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
11021 if (aWhitePoint.IsRealValue())
11023 aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
11027 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11031 else if (aFlag == "-tonemapping")
11033 if (++anArgIter >= theArgNb)
11035 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11039 TCollection_AsciiString aMode (theArgVec[anArgIter]);
11042 if (aMode == "disabled")
11044 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled;
11046 else if (aMode == "filmic")
11048 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;
11052 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
11056 else if (aFlag == "-performancestats"
11057 || aFlag == "-performancecounters"
11058 || aFlag == "-perfstats"
11059 || aFlag == "-perfcounters"
11060 || aFlag == "-stats")
11062 if (++anArgIter >= theArgNb)
11064 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11068 TCollection_AsciiString aFlagsStr (theArgVec[anArgIter]);
11069 aFlagsStr.LowerCase();
11070 Graphic3d_RenderingParams::PerfCounters aFlags = aView->ChangeRenderingParams().CollectedStats;
11071 if (!convertToPerfStatsFlags (aFlagsStr, aFlags))
11073 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11076 aView->ChangeRenderingParams().CollectedStats = aFlags;
11077 aView->ChangeRenderingParams().ToShowStats = aFlags != Graphic3d_RenderingParams::PerfCounters_NONE;
11079 else if (aFlag == "-perfupdateinterval"
11080 || aFlag == "-statsupdateinterval")
11082 if (++anArgIter >= theArgNb)
11084 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11087 aView->ChangeRenderingParams().StatsUpdateInterval = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
11089 else if (aFlag == "-perfchart"
11090 || aFlag == "-statschart")
11092 if (++anArgIter >= theArgNb)
11094 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11097 aView->ChangeRenderingParams().StatsNbFrames = Draw::Atoi (theArgVec[anArgIter]);
11099 else if (aFlag == "-perfchartmax"
11100 || aFlag == "-statschartmax")
11102 if (++anArgIter >= theArgNb)
11104 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
11107 aView->ChangeRenderingParams().StatsMaxChartTime = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
11109 else if (aFlag == "-frustumculling"
11110 || aFlag == "-culling")
11114 theDI << ((aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On) ? "on" :
11115 (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off) ? "off" :
11116 "noUpdate") << " ";
11120 Graphic3d_RenderingParams::FrustumCulling aState = Graphic3d_RenderingParams::FrustumCulling_On;
11121 if (++anArgIter < theArgNb)
11123 TCollection_AsciiString aStateStr(theArgVec[anArgIter]);
11124 aStateStr.LowerCase();
11125 bool toEnable = true;
11126 if (ViewerTest::ParseOnOff (aStateStr.ToCString(), toEnable))
11128 aState = toEnable ? Graphic3d_RenderingParams::FrustumCulling_On : Graphic3d_RenderingParams::FrustumCulling_Off;
11130 else if (aStateStr == "noupdate"
11131 || aStateStr == "freeze")
11133 aState = Graphic3d_RenderingParams::FrustumCulling_NoUpdate;
11140 aParams.FrustumCullingState = aState;
11144 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
11152 //=======================================================================
11153 //function : searchInfo
11155 //=======================================================================
11156 inline TCollection_AsciiString searchInfo (const TColStd_IndexedDataMapOfStringString& theDict,
11157 const TCollection_AsciiString& theKey)
11159 for (TColStd_IndexedDataMapOfStringString::Iterator anIter (theDict); anIter.More(); anIter.Next())
11161 if (TCollection_AsciiString::IsSameString (anIter.Key(), theKey, Standard_False))
11163 return anIter.Value();
11166 return TCollection_AsciiString();
11169 //=======================================================================
11170 //function : VStatProfiler
11172 //=======================================================================
11173 static Standard_Integer VStatProfiler (Draw_Interpretor& theDI,
11174 Standard_Integer theArgNb,
11175 const char** theArgVec)
11177 Handle(V3d_View) aView = ViewerTest::CurrentView();
11178 if (aView.IsNull())
11180 std::cerr << "Error: no active viewer!\n";
11184 Standard_Boolean toRedraw = Standard_True;
11185 Graphic3d_RenderingParams::PerfCounters aPrevCounters = aView->ChangeRenderingParams().CollectedStats;
11186 Standard_ShortReal aPrevUpdInterval = aView->ChangeRenderingParams().StatsUpdateInterval;
11187 Graphic3d_RenderingParams::PerfCounters aRenderParams = Graphic3d_RenderingParams::PerfCounters_NONE;
11188 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
11190 Standard_CString anArg (theArgVec[anArgIter]);
11191 TCollection_AsciiString aFlag (anArg);
11193 if (aFlag == "-noredraw")
11195 toRedraw = Standard_False;
11199 Graphic3d_RenderingParams::PerfCounters aParam = Graphic3d_RenderingParams::PerfCounters_NONE;
11200 if (aFlag == "fps") aParam = Graphic3d_RenderingParams::PerfCounters_FrameRate;
11201 else if (aFlag == "cpu") aParam = Graphic3d_RenderingParams::PerfCounters_CPU;
11202 else if (aFlag == "alllayers"
11203 || aFlag == "layers") aParam = Graphic3d_RenderingParams::PerfCounters_Layers;
11204 else if (aFlag == "allstructs"
11205 || aFlag == "structs") aParam = Graphic3d_RenderingParams::PerfCounters_Structures;
11206 else if (aFlag == "groups") aParam = Graphic3d_RenderingParams::PerfCounters_Groups;
11207 else if (aFlag == "allarrays"
11208 || aFlag == "fillarrays"
11209 || aFlag == "linearrays"
11210 || aFlag == "pointarrays"
11211 || aFlag == "textarrays") aParam = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
11212 else if (aFlag == "triangles") aParam = Graphic3d_RenderingParams::PerfCounters_Triangles;
11213 else if (aFlag == "points") aParam = Graphic3d_RenderingParams::PerfCounters_Points;
11214 else if (aFlag == "geommem"
11215 || aFlag == "texturemem"
11216 || aFlag == "framemem") aParam = Graphic3d_RenderingParams::PerfCounters_EstimMem;
11217 else if (aFlag == "elapsedframe"
11218 || aFlag == "cpuframeaverage"
11219 || aFlag == "cpupickingaverage"
11220 || aFlag == "cpucullingaverage"
11221 || aFlag == "cpudynaverage"
11222 || aFlag == "cpuframemax"
11223 || aFlag == "cpupickingmax"
11224 || aFlag == "cpucullingmax"
11225 || aFlag == "cpudynmax") aParam = Graphic3d_RenderingParams::PerfCounters_FrameTime;
11228 std::cerr << "Unknown argument '" << theArgVec[anArgIter] << "'!\n";
11232 aRenderParams = Graphic3d_RenderingParams::PerfCounters (aRenderParams | aParam);
11236 if (aRenderParams != Graphic3d_RenderingParams::PerfCounters_NONE)
11238 aView->ChangeRenderingParams().CollectedStats =
11239 Graphic3d_RenderingParams::PerfCounters (aView->RenderingParams().CollectedStats | aRenderParams);
11243 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
11245 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
11248 TColStd_IndexedDataMapOfStringString aDict;
11249 aView->StatisticInformation (aDict);
11251 aView->ChangeRenderingParams().CollectedStats = aPrevCounters;
11253 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
11255 Standard_CString anArg(theArgVec[anArgIter]);
11256 TCollection_AsciiString aFlag(anArg);
11258 if (aFlag == "fps")
11260 theDI << searchInfo (aDict, "FPS") << " ";
11262 else if (aFlag == "cpu")
11264 theDI << searchInfo (aDict, "CPU FPS") << " ";
11266 else if (aFlag == "alllayers")
11268 theDI << searchInfo (aDict, "Layers") << " ";
11270 else if (aFlag == "layers")
11272 theDI << searchInfo (aDict, "Rendered layers") << " ";
11274 else if (aFlag == "allstructs")
11276 theDI << searchInfo (aDict, "Structs") << " ";
11278 else if (aFlag == "structs")
11280 theDI << searchInfo (aDict, "Rendered structs") << " ";
11282 else if (aFlag == "groups")
11284 theDI << searchInfo (aDict, "Rendered groups") << " ";
11286 else if (aFlag == "allarrays")
11288 theDI << searchInfo (aDict, "Rendered arrays") << " ";
11290 else if (aFlag == "fillarrays")
11292 theDI << searchInfo (aDict, "Rendered [fill] arrays") << " ";
11294 else if (aFlag == "linearrays")
11296 theDI << searchInfo (aDict, "Rendered [line] arrays") << " ";
11298 else if (aFlag == "pointarrays")
11300 theDI << searchInfo (aDict, "Rendered [point] arrays") << " ";
11302 else if (aFlag == "textarrays")
11304 theDI << searchInfo (aDict, "Rendered [text] arrays") << " ";
11306 else if (aFlag == "triangles")
11308 theDI << searchInfo (aDict, "Rendered triangles") << " ";
11310 else if (aFlag == "points")
11312 theDI << searchInfo (aDict, "Rendered points") << " ";
11314 else if (aFlag == "geommem")
11316 theDI << searchInfo (aDict, "GPU Memory [geometry]") << " ";
11318 else if (aFlag == "texturemem")
11320 theDI << searchInfo (aDict, "GPU Memory [textures]") << " ";
11322 else if (aFlag == "framemem")
11324 theDI << searchInfo (aDict, "GPU Memory [frames]") << " ";
11326 else if (aFlag == "elapsedframe")
11328 theDI << searchInfo (aDict, "Elapsed Frame (average)") << " ";
11330 else if (aFlag == "cpuframe_average")
11332 theDI << searchInfo (aDict, "CPU Frame (average)") << " ";
11334 else if (aFlag == "cpupicking_average")
11336 theDI << searchInfo (aDict, "CPU Picking (average)") << " ";
11338 else if (aFlag == "cpuculling_average")
11340 theDI << searchInfo (aDict, "CPU Culling (average)") << " ";
11342 else if (aFlag == "cpudyn_average")
11344 theDI << searchInfo (aDict, "CPU Dynamics (average)") << " ";
11346 else if (aFlag == "cpuframe_max")
11348 theDI << searchInfo (aDict, "CPU Frame (max)") << " ";
11350 else if (aFlag == "cpupicking_max")
11352 theDI << searchInfo (aDict, "CPU Picking (max)") << " ";
11354 else if (aFlag == "cpuculling_max")
11356 theDI << searchInfo (aDict, "CPU Culling (max)") << " ";
11358 else if (aFlag == "cpudyn_max")
11360 theDI << searchInfo (aDict, "CPU Dynamics (max)") << " ";
11368 aView->ChangeRenderingParams().StatsUpdateInterval = -1;
11370 aView->ChangeRenderingParams().StatsUpdateInterval = aPrevUpdInterval;
11372 theDI << "Statistic info:\n" << aView->StatisticInformation();
11377 //=======================================================================
11378 //function : VProgressiveMode
11380 //=======================================================================
11381 #if defined(_WIN32)
11382 static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
11383 Standard_Integer /*theNbArgs*/,
11384 const char** /*theArgs*/)
11386 Handle(V3d_View) aView = ViewerTest::CurrentView();
11387 if (aView.IsNull())
11389 std::cerr << "Error: no active viewer!\n";
11393 std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
11399 Standard_Boolean toExit = Standard_False;
11402 while (PeekMessageW (&aMsg, NULL, 0, 0, PM_REMOVE))
11404 if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
11406 toExit = Standard_True;
11409 TranslateMessage (&aMsg);
11410 DispatchMessageW (&aMsg);
11423 //=======================================================================
11424 //function : VXRotate
11426 //=======================================================================
11427 static Standard_Integer VXRotate (Draw_Interpretor& di,
11428 Standard_Integer argc,
11429 const char ** argv)
11431 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
11432 if (aContext.IsNull())
11434 di << argv[0] << "ERROR : use 'vinit' command before \n";
11440 di << "ERROR : Usage : " << argv[0] << " name angle\n";
11444 TCollection_AsciiString aName (argv[1]);
11445 Standard_Real anAngle = Draw::Atof (argv[2]);
11448 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
11449 Handle(AIS_InteractiveObject) anIObj;
11450 if (!aMap.Find2 (aName, anIObj))
11452 di << "Use 'vdisplay' before\n";
11456 gp_Trsf aTransform;
11457 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
11458 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
11460 aContext->SetLocation (anIObj, aTransform);
11461 aContext->UpdateCurrentViewer();
11465 //===============================================================================================
11466 //class : ViewerTest_AISManipulator
11467 //purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances
11468 //===============================================================================================
11469 DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
11471 class ViewerTest_AISManipulator : public AIS_Manipulator
11475 ViewerTest_AISManipulator() : AIS_Manipulator()
11477 GetMapOfAISManipulators().Add (this);
11480 virtual ~ViewerTest_AISManipulator()
11482 GetMapOfAISManipulators().Remove (this);
11485 DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
11488 IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
11489 IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
11491 //===============================================================================================
11492 //function : VManipulator
11494 //===============================================================================================
11495 static int VManipulator (Draw_Interpretor& theDi,
11496 Standard_Integer theArgsNb,
11497 const char** theArgVec)
11499 Handle(V3d_View) aView = ViewerTest::CurrentView();
11500 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
11501 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
11503 || aViewer.IsNull())
11505 std::cerr << "No active viewer!\n";
11509 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
11510 Standard_Integer anArgIter = 1;
11511 for (; anArgIter < theArgsNb; ++anArgIter)
11513 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
11516 ViewerTest_CmdParser aCmd;
11517 aCmd.AddDescription ("Manages manipulator for interactive objects:");
11518 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
11519 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
11520 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
11521 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
11522 aCmd.AddOption ("detach", "... - detach manipulator");
11524 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
11525 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
11526 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
11528 aCmd.AddOption ("move", "... x y z - move object");
11529 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
11530 aCmd.AddOption ("scale", "... factor - scale object");
11532 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
11533 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
11534 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
11535 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
11536 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
11537 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
11538 aCmd.AddOption ("size", "... size - set size of manipulator");
11539 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
11541 aCmd.Parse (theArgsNb, theArgVec);
11543 if (aCmd.HasOption ("help"))
11545 theDi.PrintHelp (theArgVec[0]);
11549 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
11551 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
11553 if (aName.IsEmpty())
11555 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
11559 // ----------------------------------
11560 // detach existing manipulator object
11561 // ----------------------------------
11563 if (aCmd.HasOption ("detach"))
11565 if (!aMapAIS.IsBound2 (aName))
11567 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
11571 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
11572 if (aManipulator.IsNull())
11574 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
11578 aManipulator->Detach();
11579 aMapAIS.UnBind2 (aName);
11580 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True);
11585 // -----------------------------------------------
11586 // find or create manipulator if it does not exist
11587 // -----------------------------------------------
11589 Handle(AIS_Manipulator) aManipulator;
11590 if (!aMapAIS.IsBound2 (aName))
11592 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
11594 aManipulator = new ViewerTest_AISManipulator();
11595 aMapAIS.Bind (aManipulator, aName);
11599 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
11600 if (aManipulator.IsNull())
11602 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
11607 // -----------------------------------------
11608 // change properties of manipulator instance
11609 // -----------------------------------------
11611 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
11613 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
11615 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
11617 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
11619 if (aCmd.HasOption ("followRotation", 1, Standard_True))
11621 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
11623 if (aCmd.HasOption ("gap", 1, Standard_True))
11625 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
11627 if (aCmd.HasOption ("part", 3, Standard_True))
11629 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
11630 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
11631 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
11632 if (aMode < 1 || aMode > 3)
11634 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 3].\n";
11638 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
11640 if (aCmd.HasOption ("pos", 3, Standard_True))
11642 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
11643 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
11644 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
11646 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
11648 if (aCmd.HasOption ("size", 1, Standard_True))
11650 aManipulator->SetSize (aCmd.ArgFloat ("size"));
11652 if (aCmd.HasOption ("zoomable", 1, Standard_True))
11654 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
11656 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
11658 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
11659 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
11663 // ---------------------------------------------------
11664 // attach, detach or access manipulator from an object
11665 // ---------------------------------------------------
11667 if (aCmd.HasOption ("attach"))
11669 // Find an object and attach manipulator to it
11670 if (!aCmd.HasOption ("attach", 1, Standard_True))
11675 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
11676 Handle(AIS_InteractiveObject) anObject;
11677 if (!aMapAIS.Find2 (anObjName, anObject))
11679 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
11683 for (ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators()); anIt.More(); anIt.Next())
11685 if (anIt.Value()->IsAttached()
11686 && anIt.Value()->Object() == anObject)
11688 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
11693 AIS_Manipulator::OptionsForAttach anOptions;
11694 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
11696 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
11698 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
11700 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
11702 if (aCmd.HasOption ("enableModes", 1, Standard_True))
11704 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
11707 aManipulator->Attach (anObject, anOptions);
11710 // --------------------------------------
11711 // apply transformation using manipulator
11712 // --------------------------------------
11714 if (aCmd.HasOption ("startTransform", 2, Standard_True))
11716 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
11718 if (aCmd.HasOption ("transform", 2, Standard_True))
11720 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
11722 if (aCmd.HasOption ("stopTransform"))
11724 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
11726 aManipulator->StopTransform (toApply);
11730 if (aCmd.HasOption ("move", 3, Standard_True))
11732 aT.SetTranslationPart (aCmd.ArgVec ("move"));
11734 if (aCmd.HasOption ("rotate", 7, Standard_True))
11736 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
11738 if (aCmd.HasOption ("scale", 1))
11740 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
11743 if (aT.Form() != gp_Identity)
11745 aManipulator->Transform (aT);
11748 ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True);
11753 //===============================================================================================
11754 //function : VSelectionProperties
11756 //===============================================================================================
11757 static int VSelectionProperties (Draw_Interpretor& theDi,
11758 Standard_Integer theArgsNb,
11759 const char** theArgVec)
11761 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
11764 std::cerr << "No active viewer!\n";
11768 if (TCollection_AsciiString (theArgVec[0]) == "vhighlightselected")
11770 // handle obsolete alias
11771 bool toEnable = true;
11774 theDi << (aCtx->ToHilightSelected() ? "on" : "off");
11777 else if (theArgsNb != 2
11778 || !ViewerTest::ParseOnOff (theArgVec[1], toEnable))
11780 std::cout << "Syntax error: wrong number of parameters.";
11783 if (toEnable != aCtx->ToHilightSelected())
11785 aCtx->ClearDetected();
11786 aCtx->SetToHilightSelected (toEnable);
11791 Standard_Boolean toPrint = theArgsNb == 1;
11792 Standard_Boolean toRedraw = Standard_False;
11793 Standard_Integer anArgIter = 1;
11794 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
11795 if (anArgIter < theArgsNb)
11797 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
11798 anArgFirst.LowerCase();
11800 if (anArgFirst == "dynhighlight"
11801 || anArgFirst == "dynhilight"
11802 || anArgFirst == "dynamichighlight"
11803 || anArgFirst == "dynamichilight")
11805 aType = Prs3d_TypeOfHighlight_Dynamic;
11807 else if (anArgFirst == "localdynhighlight"
11808 || anArgFirst == "localdynhilight"
11809 || anArgFirst == "localdynamichighlight"
11810 || anArgFirst == "localdynamichilight")
11812 aType = Prs3d_TypeOfHighlight_LocalDynamic;
11814 else if (anArgFirst == "selhighlight"
11815 || anArgFirst == "selhilight"
11816 || anArgFirst == "selectedhighlight"
11817 || anArgFirst == "selectedhilight")
11819 aType = Prs3d_TypeOfHighlight_Selected;
11821 else if (anArgFirst == "localselhighlight"
11822 || anArgFirst == "localselhilight"
11823 || anArgFirst == "localselectedhighlight"
11824 || anArgFirst == "localselectedhilight")
11826 aType = Prs3d_TypeOfHighlight_LocalSelected;
11833 for (; anArgIter < theArgsNb; ++anArgIter)
11835 TCollection_AsciiString anArg (theArgVec[anArgIter]);
11837 if (anArg == "-help")
11839 theDi.PrintHelp (theArgVec[0]);
11842 else if (anArg == "-print")
11844 toPrint = Standard_True;
11846 else if (anArg == "-autoactivate")
11848 Standard_Boolean toEnable = Standard_True;
11849 if (anArgIter + 1 < theArgsNb
11850 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
11854 aCtx->SetAutoActivateSelection (toEnable);
11856 else if (anArg == "-automatichighlight"
11857 || anArg == "-automatichilight"
11858 || anArg == "-autohighlight"
11859 || anArg == "-autohilight")
11861 Standard_Boolean toEnable = Standard_True;
11862 if (anArgIter + 1 < theArgsNb
11863 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
11867 aCtx->ClearSelected (false);
11868 aCtx->ClearDetected();
11869 aCtx->SetAutomaticHilight (toEnable);
11872 else if (anArg == "-highlightselected"
11873 || anArg == "-hilightselected")
11875 Standard_Boolean toEnable = Standard_True;
11876 if (anArgIter + 1 < theArgsNb
11877 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
11881 aCtx->ClearDetected();
11882 aCtx->SetToHilightSelected (toEnable);
11885 else if (anArg == "-pickstrategy"
11886 || anArg == "-pickingstrategy")
11888 if (++anArgIter >= theArgsNb)
11890 std::cout << "Syntax error: type of highlighting is undefined\n";
11894 SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
11895 TCollection_AsciiString aVal (theArgVec[anArgIter]);
11897 if (aVal == "first"
11898 || aVal == "firstaccepted"
11899 || aVal == "firstacceptable")
11901 aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
11903 else if (aVal == "topmost"
11904 || aVal == "onlyTopmost")
11906 aStrategy = SelectMgr_PickingStrategy_OnlyTopmost;
11910 std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n";
11914 aCtx->SetPickingStrategy (aStrategy);
11916 else if (anArg == "-pixtol"
11917 && anArgIter + 1 < theArgsNb)
11919 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
11921 else if ((anArg == "-mode"
11922 || anArg == "-dispmode")
11923 && anArgIter + 1 < theArgsNb)
11925 if (aType == Prs3d_TypeOfHighlight_None)
11927 std::cout << "Syntax error: type of highlighting is undefined\n";
11931 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
11932 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11933 aStyle->SetDisplayMode (aDispMode);
11934 toRedraw = Standard_True;
11936 else if (anArg == "-layer"
11937 && anArgIter + 1 < theArgsNb)
11939 if (aType == Prs3d_TypeOfHighlight_None)
11941 std::cout << "Syntax error: type of highlighting is undefined\n";
11945 const Standard_Integer aNewLayer = Draw::Atoi (theArgVec[++anArgIter]);
11946 if (aNewLayer != Graphic3d_ZLayerId_UNKNOWN)
11948 TColStd_SequenceOfInteger aLayers;
11949 aCtx->CurrentViewer()->GetAllZLayers (aLayers);
11950 if (std::find (aLayers.begin(), aLayers.end(), aNewLayer) == aLayers.end())
11952 std::cout << "Syntax error: Layer " << aNewLayer << " is undefined\n";
11957 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11958 aStyle->SetZLayer (aNewLayer);
11959 toRedraw = Standard_True;
11961 else if (anArg == "-hicolor"
11962 || anArg == "-selcolor"
11963 || anArg == "-color")
11965 if (anArg.StartsWith ("-hi"))
11967 aType = Prs3d_TypeOfHighlight_Dynamic;
11969 else if (anArg.StartsWith ("-sel"))
11971 aType = Prs3d_TypeOfHighlight_Selected;
11973 else if (aType == Prs3d_TypeOfHighlight_None)
11975 std::cout << "Syntax error: type of highlighting is undefined\n";
11979 Quantity_Color aColor;
11980 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1,
11981 theArgVec + anArgIter + 1,
11983 if (aNbParsed == 0)
11985 std::cout << "Syntax error: need more arguments.\n";
11988 anArgIter += aNbParsed;
11990 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11991 aStyle->SetColor (aColor);
11992 toRedraw = Standard_True;
11994 else if ((anArg == "-transp"
11995 || anArg == "-transparency"
11996 || anArg == "-hitransp"
11997 || anArg == "-seltransp"
11998 || anArg == "-hitransplocal"
11999 || anArg == "-seltransplocal")
12000 && anArgIter + 1 < theArgsNb)
12002 if (anArg.StartsWith ("-hi"))
12004 aType = Prs3d_TypeOfHighlight_Dynamic;
12006 else if (anArg.StartsWith ("-sel"))
12008 aType = Prs3d_TypeOfHighlight_Selected;
12010 else if (aType == Prs3d_TypeOfHighlight_None)
12012 std::cout << "Syntax error: type of highlighting is undefined\n";
12016 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
12017 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12018 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
12019 toRedraw = Standard_True;
12021 else if ((anArg == "-mat"
12022 || anArg == "-material")
12023 && anArgIter + 1 < theArgsNb)
12025 if (aType == Prs3d_TypeOfHighlight_None)
12027 std::cout << "Syntax error: type of highlighting is undefined\n";
12031 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
12032 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
12033 if (aMatName != Graphic3d_NOM_DEFAULT)
12036 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
12037 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
12038 Graphic3d_MaterialAspect aMat (aMatName);
12039 aMat.SetColor (aStyle->Color());
12040 aMat.SetTransparency (aStyle->Transparency());
12041 anAspect->SetFrontMaterial (aMat);
12042 anAspect->SetInteriorColor (aStyle->Color());
12043 aStyle->SetBasicFillAreaAspect (anAspect);
12047 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
12049 toRedraw = Standard_True;
12053 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
12059 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
12060 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
12061 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
12062 theDi << "Auto-highlight : " << (aCtx->AutomaticHilight() ? "On" : "Off") << "\n";
12063 theDi << "Highlight selected : " << (aCtx->ToHilightSelected() ? "On" : "Off") << "\n";
12064 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
12065 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
12066 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
12067 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
12068 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
12069 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
12070 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
12071 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
12072 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
12075 if (aCtx->NbSelected() != 0 && toRedraw)
12077 aCtx->HilightSelected (Standard_True);
12083 //===============================================================================================
12084 //function : VDumpSelectionImage
12086 //===============================================================================================
12087 static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
12088 Standard_Integer theArgsNb,
12089 const char** theArgVec)
12093 std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
12097 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
12098 if (aContext.IsNull())
12100 std::cout << "Error: no active view.\n";
12104 TCollection_AsciiString aFile;
12105 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
12106 Image_Format anImgFormat = Image_Format_BGR;
12107 Standard_Integer aPickedIndex = 1;
12108 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
12110 TCollection_AsciiString aParam (theArgVec[anArgIter]);
12111 aParam.LowerCase();
12112 if (aParam == "-type")
12114 if (++anArgIter >= theArgsNb)
12116 std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n";
12120 TCollection_AsciiString aValue (theArgVec[anArgIter]);
12121 aValue.LowerCase();
12122 if (aValue == "depth"
12123 || aValue == "normdepth"
12124 || aValue == "normalizeddepth")
12126 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
12127 anImgFormat = Image_Format_GrayF;
12129 if (aValue == "depthinverted"
12130 || aValue == "normdepthinverted"
12131 || aValue == "normalizeddepthinverted"
12132 || aValue == "inverted")
12134 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
12135 anImgFormat = Image_Format_GrayF;
12137 else if (aValue == "unnormdepth"
12138 || aValue == "unnormalizeddepth")
12140 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
12141 anImgFormat = Image_Format_GrayF;
12143 else if (aValue == "objectcolor"
12144 || aValue == "object"
12145 || aValue == "color")
12147 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
12149 else if (aValue == "entitycolor"
12150 || aValue == "entity")
12152 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
12154 else if (aValue == "ownercolor"
12155 || aValue == "owner")
12157 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
12159 else if (aValue == "selectionmodecolor"
12160 || aValue == "selectionmode"
12161 || aValue == "selmodecolor"
12162 || aValue == "selmode")
12164 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
12167 else if (aParam == "-picked"
12168 || aParam == "-pickeddepth"
12169 || aParam == "-pickedindex")
12171 if (++anArgIter >= theArgsNb)
12173 std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n";
12177 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
12179 else if (aFile.IsEmpty())
12181 aFile = theArgVec[anArgIter];
12185 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n";
12189 if (aFile.IsEmpty())
12191 std::cout << "Syntax error: image file name is missing.\n";
12195 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
12196 Standard_Integer aWidth = 0, aHeight = 0;
12197 aView->Window()->Size (aWidth, aHeight);
12199 Image_AlienPixMap aPixMap;
12200 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
12202 std::cout << "Error: can't allocate image.\n";
12205 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
12207 std::cout << "Error: can't generate selection image.\n";
12210 if (!aPixMap.Save (aFile))
12212 std::cout << "Error: can't save selection image.\n";
12218 //=======================================================================
12219 //function : ViewerCommands
12221 //=======================================================================
12223 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
12226 const char *group = "ZeViewer";
12227 theCommands.Add("vinit",
12228 "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]"
12229 "\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]"
12230 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
12231 "\n\t\t: [-display displayName]"
12233 "\n\t\t: Creates new View window with specified name viewName."
12234 "\n\t\t: By default the new view is created in the viewer and in"
12235 "\n\t\t: graphic driver shared with active view."
12236 "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}"
12237 "\n\t\t: If driverName isn't specified the driver will be shared with active view."
12238 "\n\t\t: If viewerName isn't specified the viewer will be shared with active view."
12239 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
12240 "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]"
12241 "\n\t\t: Display name will be used within creation of graphic driver, when specified."
12243 "\n\t\t: -left, -top pixel position of left top corner of the window."
12244 "\n\t\t: -width, -height width and heigth of window respectively."
12245 "\n\t\t: -cloneActive floag to copy camera and dimensions of active view."
12246 "\n\t\t: -exitOnClose when specified, closing the view will exit application."
12247 "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape."
12248 "\n\t\t: -2d_mode when on, view will not react on rotate scene events"
12249 "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.",
12250 __FILE__,VInit,group);
12251 theCommands.Add("vclose" ,
12252 "[view_id [keep_context=0|1]]\n"
12253 "or vclose ALL - to remove all created views\n"
12254 " - removes view(viewer window) defined by its view_id.\n"
12255 " - keep_context: by default 0; if 1 and the last view is deleted"
12256 " the current context is not removed.",
12257 __FILE__,VClose,group);
12258 theCommands.Add("vactivate" ,
12260 " - activates view(viewer window) defined by its view_id",
12261 __FILE__,VActivate,group);
12262 theCommands.Add("vviewlist",
12263 "vviewlist [format={tree, long}]"
12264 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
12265 " - format: format of result output, if tree the output is a tree view;"
12266 "otherwise it's a list of full view names. By default format = tree",
12267 __FILE__,VViewList,group);
12268 theCommands.Add("vhelp" ,
12269 "vhelp : display help on the viewer commands",
12270 __FILE__,VHelp,group);
12271 theCommands.Add("vtop" ,
12272 "vtop or <T> : Top view. Orientation +X+Y" ,
12273 __FILE__,VTop,group);
12274 theCommands.Add("vbottom" ,
12275 "vbottom : Bottom view. Orientation +X-Y" ,
12276 __FILE__,VBottom,group);
12277 theCommands.Add("vleft" ,
12278 "vleft : Left view. Orientation -Y+Z" ,
12279 __FILE__,VLeft,group);
12280 theCommands.Add("vright" ,
12281 "vright : Right view. Orientation +Y+Z" ,
12282 __FILE__,VRight,group);
12283 theCommands.Add("vaxo" ,
12284 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
12285 __FILE__,VAxo,group);
12286 theCommands.Add("vfront" ,
12287 "vfront : Front view. Orientation +X+Z" ,
12288 __FILE__,VFront,group);
12289 theCommands.Add("vback" ,
12290 "vback : Back view. Orientation -X+Z" ,
12291 __FILE__,VBack,group);
12292 theCommands.Add("vpick" ,
12293 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
12295 theCommands.Add("vfit",
12296 "vfit or <F> [-selected] [-noupdate]"
12297 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
12298 __FILE__,VFit,group);
12299 theCommands.Add ("vfitarea",
12300 "vfitarea x1 y1 x2 y2"
12301 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
12302 "\n\t\t: Fit view to show area located between two points"
12303 "\n\t\t: given in world 2D or 3D corrdinates.",
12304 __FILE__, VFitArea, group);
12305 theCommands.Add ("vzfit", "vzfit [scale]\n"
12306 " Matches Z near, Z far view volume planes to the displayed objects.\n"
12307 " \"scale\" - specifies factor to scale computed z range.\n",
12308 __FILE__, VZFit, group);
12309 theCommands.Add("vrepaint",
12310 "vrepaint [-immediate]"
12311 "\n\t\t: force redraw",
12312 __FILE__,VRepaint,group);
12313 theCommands.Add("vclear",
12315 "\n\t\t: remove all the object from the viewer",
12316 __FILE__,VClear,group);
12317 theCommands.Add("vsetbg",
12318 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
12319 __FILE__,VSetBg,group);
12320 theCommands.Add("vsetbgmode",
12321 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
12322 __FILE__,VSetBgMode,group);
12323 theCommands.Add("vsetgradientbg",
12324 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
12325 __FILE__,VSetGradientBg,group);
12326 theCommands.Add("vsetgrbgmode",
12327 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
12328 __FILE__,VSetGradientBgMode,group);
12329 theCommands.Add("vsetcolorbg",
12330 "vsetcolorbg : vsetcolorbg r g b : Set background color",
12331 __FILE__,VSetColorBg,group);
12332 theCommands.Add("vsetdefaultbg",
12333 "vsetdefaultbg r g b\n"
12334 "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode"
12335 "\n\t\t: Set default viewer background fill color (flat/gradient).",
12336 __FILE__,VSetDefaultBg,group);
12337 theCommands.Add("vscale",
12338 "vscale : vscale X Y Z",
12339 __FILE__,VScale,group);
12340 theCommands.Add("vzbufftrihedron",
12341 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
12342 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
12343 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
12344 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
12345 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
12346 "\n\t\t: Displays a trihedron",
12347 __FILE__,VZBuffTrihedron,group);
12348 theCommands.Add("vrotate",
12349 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
12350 "\n : Option -mouseStart starts rotation according to the mouse position"
12351 "\n : Option -mouseMove continues rotation with angle computed"
12352 "\n : from last and new mouse position."
12353 "\n : vrotate AX AY AZ [X Y Z]",
12354 __FILE__,VRotate,group);
12355 theCommands.Add("vzoom",
12356 "vzoom : vzoom coef",
12357 __FILE__,VZoom,group);
12358 theCommands.Add("vpan",
12359 "vpan : vpan dx dy",
12360 __FILE__,VPan,group);
12361 theCommands.Add("vcolorscale",
12362 "vcolorscale name [-noupdate|-update] [-demo]"
12363 "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
12364 "\n\t\t: [-font HeightFont=20]"
12365 "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
12366 "\n\t\t: [-smoothTransition {on|off}=off]"
12367 "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
12368 "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
12369 "\n\t\t: [-textpos {left|right|center|none}=right]"
12370 "\n\t\t: [-labelAtBorder {on|off}=on]"
12371 "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
12372 "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
12373 "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
12374 "\n\t\t: [-xy Left=0 Bottom=0]"
12375 "\n\t\t: -demo - displays a color scale with demonstratio values"
12376 "\n\t\t: -colors - set colors for all intervals"
12377 "\n\t\t: -color - set color for specific interval"
12378 "\n\t\t: -textpos - horizontal label position relative to color scale bar"
12379 "\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
12380 "\n\t\t: at border means the value inbetween neighbor intervals,"
12381 "\n\t\t: at center means the center value within current interval"
12382 "\n\t\t: -labels - set labels for all intervals"
12383 "\n\t\t: -freeLabels - same as -labels but does not require"
12384 "\n\t\t: matching the number of intervals"
12385 "\n\t\t: -label - set label for specific interval"
12386 "\n\t\t: -title - set title"
12387 "\n\t\t: -reversed - setup smooth color transition between intervals"
12388 "\n\t\t: -smoothTransition - swap colorscale direction"
12389 "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values"
12390 __FILE__, VColorScale, group);
12391 theCommands.Add("vgraduatedtrihedron",
12392 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
12393 "\t[-namefont Name] [-valuesfont Name]\n"
12394 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
12395 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
12396 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
12397 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
12398 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
12399 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
12400 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
12401 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
12402 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
12403 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
12404 " - Displays or erases graduated trihedron"
12405 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
12406 " - namefont - font of axes names. Default: Arial\n"
12407 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
12408 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
12409 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
12410 " - valuesfont - font of axes values. Default: Arial\n"
12411 " - xcolor, ycolor, zcolor - color of axis and values\n"
12412 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
12413 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
12414 __FILE__,VGraduatedTrihedron,group);
12415 theCommands.Add("vtile" ,
12416 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
12417 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
12418 "\n\t\t: -totalSize the size of virtual bigger viewport"
12419 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
12420 "\n\t\t: -lowerLeft tile offset as lower left corner"
12421 "\n\t\t: -upperLeft tile offset as upper left corner",
12422 __FILE__, VTile, group);
12423 theCommands.Add("vzlayer",
12424 "vzlayer [layerId]"
12425 "\n\t\t: [-add|-delete|-get|-settings]"
12426 "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]"
12427 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
12428 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv}]"
12429 "\n\t\t: ZLayer list management:"
12430 "\n\t\t: -add add new z layer to viewer and print its id"
12431 "\n\t\t: -delete delete z layer"
12432 "\n\t\t: -get print sequence of z layers"
12433 "\n\t\t: -settings print status of z layer settings"
12434 "\n\t\t: -disable disables given setting"
12435 "\n\t\t: -enable enables given setting",
12436 __FILE__,VZLayer,group);
12437 theCommands.Add("vlayerline",
12438 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
12439 __FILE__,VLayerLine,group);
12440 theCommands.Add ("vgrid",
12441 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
12442 " : Mode - rectangular or circular"
12443 " : Type - lines or points",
12444 __FILE__, VGrid, group);
12445 theCommands.Add ("vpriviledgedplane",
12446 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
12447 "\n\t\t: Ox, Oy, Oz - plane origin"
12448 "\n\t\t: Nx, Ny, Nz - plane normal direction"
12449 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
12450 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
12451 __FILE__, VPriviledgedPlane, group);
12452 theCommands.Add ("vconvert",
12453 "vconvert v [Mode={window|view}]"
12454 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
12455 "\n\t\t: vconvert x y z [Mode={window|grid}]"
12456 "\n\t\t: window - convert to window coordinates, pixels"
12457 "\n\t\t: view - convert to view projection plane"
12458 "\n\t\t: grid - convert to model coordinates, given on grid"
12459 "\n\t\t: ray - convert projection ray to model coordiantes"
12460 "\n\t\t: - vconvert v window : convert view to window;"
12461 "\n\t\t: - vconvert v view : convert window to view;"
12462 "\n\t\t: - vconvert x y window : convert view to window;"
12463 "\n\t\t: - vconvert x y view : convert window to view;"
12464 "\n\t\t: - vconvert x y : convert window to model;"
12465 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
12466 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
12467 "\n\t\t: - vconvert x y z window : convert model to window;"
12468 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
12469 "\n\t\t: Converts the given coordinates to window/view/model space.",
12470 __FILE__, VConvert, group);
12471 theCommands.Add ("vfps",
12472 "vfps [framesNb=100] : estimate average frame rate for active view",
12473 __FILE__, VFps, group);
12474 theCommands.Add ("vgldebug",
12475 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
12476 "\n\t\t: [-glslCode {off|short|full}] [-extraMsg {0|1}] [{0|1}]"
12477 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
12478 "\n\t\t: Debug context can be requested only on Windows"
12479 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
12480 "\n\t\t: -sync - request synchronized debug GL context"
12481 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
12482 "\n\t\t: which are suppressed by default,"
12483 "\n\t\t: -glslCode - log GLSL program source code,"
12484 "\n\t\t: which are suppressed by default,"
12485 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
12486 "\n\t\t: which are suppressed by default",
12487 __FILE__, VGlDebug, group);
12488 theCommands.Add ("vvbo",
12489 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
12490 __FILE__, VVbo, group);
12491 theCommands.Add ("vstereo",
12492 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
12493 "\n\t\t: [-anaglyph Filter]"
12494 "\n\t\t: Control stereo output mode. Available modes for -mode:"
12495 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
12496 "\n\t\t: requires driver support."
12497 "\n\t\t: Should be called BEFORE vinit!"
12498 "\n\t\t: anaglyph - Anaglyph glasses"
12499 "\n\t\t: rowInterlaced - row-interlaced display"
12500 "\n\t\t: columnInterlaced - column-interlaced display"
12501 "\n\t\t: chessBoard - chess-board output"
12502 "\n\t\t: sideBySide - horizontal pair"
12503 "\n\t\t: overUnder - vertical pair"
12504 "\n\t\t: Available Anaglyph filters for -anaglyph:"
12505 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
12506 "\n\t\t: greenMagentaSimple",
12507 __FILE__, VStereo, group);
12508 theCommands.Add ("vcaps",
12509 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
12510 "\n\t\t: [-compatibleProfile {0|1}]"
12511 "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]"
12512 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
12513 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
12514 "\n\t\t: Modify particular graphic driver options:"
12515 "\n\t\t: FFP - use fixed-function pipeline instead of"
12516 "\n\t\t: built-in GLSL programs"
12517 "\n\t\t: (requires compatible profile)"
12518 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
12519 "\n\t\t: arrays to GPU memory)"
12520 "\n\t\t: sprite - use textured sprites instead of bitmaps"
12521 "\n\t\t: vsync - switch VSync on or off"
12522 "\n\t\t: winBuffer - allow using window buffer for rendering"
12523 "\n\t\t: Context creation options:"
12524 "\n\t\t: softMode - software OpenGL implementation"
12525 "\n\t\t: compatibleProfile - backward-compatible profile"
12526 "\n\t\t: quadbuffer - QuadBuffer"
12527 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
12528 "\n\t\t: rendering paths producing the same visual result when"
12529 "\n\t\t: possible."
12530 "\n\t\t: Command is intended for testing old hardware compatibility.",
12531 __FILE__, VCaps, group);
12532 theCommands.Add ("vmemgpu",
12533 "vmemgpu [f]: print system-dependent GPU memory information if available;"
12534 " with f option returns free memory in bytes",
12535 __FILE__, VMemGpu, group);
12536 theCommands.Add ("vreadpixel",
12537 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
12538 " : Read pixel value for active view",
12539 __FILE__, VReadPixel, group);
12540 theCommands.Add("diffimage",
12541 "diffimage imageFile1 imageFile2 [diffImageFile]"
12542 "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]"
12543 "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]"
12544 "\n\t\t: Compare two images by content and generate difference image."
12545 "\n\t\t: When -exitOnClose is specified, closing the view will exit application."
12546 "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.",
12547 __FILE__, VDiffImage, group);
12548 theCommands.Add ("vselect",
12549 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
12550 "- emulates different types of selection:\n"
12551 "- 1) single click selection\n"
12552 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
12553 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
12554 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
12555 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
12556 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
12557 " (partial inclusion - overlap - is not allowed by default)\n"
12558 "- 5) any of these selections with shift button pressed",
12559 __FILE__, VSelect, group);
12560 theCommands.Add ("vmoveto",
12561 "vmoveto [x y] [-reset]"
12562 "\n\t\t: Emulates cursor movement to pixel position (x,y)."
12563 "\n\t\t: -reset resets current highlighting",
12564 __FILE__, VMoveTo, group);
12565 theCommands.Add ("vviewparams",
12566 "vviewparams [-args] [-scale [s]]"
12567 "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]"
12568 "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]"
12569 "\n\t\t: Manage current view parameters or prints all"
12570 "\n\t\t: current values when called without argument."
12571 "\n\t\t: -scale [s] prints or sets viewport relative scale"
12572 "\n\t\t: -eye [x y z] prints or sets eye location"
12573 "\n\t\t: -at [x y z] prints or sets center of look"
12574 "\n\t\t: -up [x y z] prints or sets direction of up vector"
12575 "\n\t\t: -proj [x y z] prints or sets direction of look"
12576 "\n\t\t: -center x y sets location of center of the screen in pixels"
12577 "\n\t\t: -size [sx] prints viewport projection width and height sizes"
12578 "\n\t\t: or changes the size of its maximum dimension"
12579 "\n\t\t: -args prints vviewparams arguments for restoring current view",
12580 __FILE__, VViewParams, group);
12582 theCommands.Add("v2dmode",
12583 "v2dmode [-name viewName] [-mode {-on|-off}=-on]"
12584 "\n\t\t: name - name of existing view, if not defined, the active view is changed"
12585 "\n\t\t: mode - switches On/Off rotation mode"
12586 "\n\t\t: Set 2D mode of the active viewer manipulating. The following mouse and key actions are disabled:"
12587 "\n\t\t: - rotation of the view by 3rd mouse button with Ctrl active"
12588 "\n\t\t: - set view projection using key buttons: A/D/T/B/L/R for AXO, Reset, Top, Bottom, Left, Right"
12589 "\n\t\t: View camera position might be changed only by commands.",
12590 __FILE__, V2DMode, group);
12592 theCommands.Add("vanimation", "Alias for vanim",
12593 __FILE__, VAnimation, group);
12595 theCommands.Add("vanim",
12596 "List existing animations:"
12598 "\n\t\t: Animation playback:"
12599 "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]"
12600 "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]"
12601 "\n\t\t: -speed playback speed (1.0 is normal speed)"
12602 "\n\t\t: -freeLook skip camera animations"
12603 "\n\t\t: -lockLoop disable any interactions"
12605 "\n\t\t: Animation definition:"
12606 "\n\t\t: vanim Name/sub/name [-clear] [-delete]"
12607 "\n\t\t: [start TimeSec] [duration TimeSec]"
12609 "\n\t\t: Animation name defined in path-style (anim/name or anim.name)"
12610 "\n\t\t: specifies nested animations."
12611 "\n\t\t: There is no syntax to explicitly add new animation,"
12612 "\n\t\t: and all non-existing animations within the name will be"
12613 "\n\t\t: implicitly created on first use (including parents)."
12615 "\n\t\t: Each animation might define the SINGLE action (see below),"
12616 "\n\t\t: like camera transition, object transformation or custom callback."
12617 "\n\t\t: Child animations can be used for defining concurrent actions."
12619 "\n\t\t: Camera animation:"
12620 "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]"
12621 "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]"
12622 "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]"
12623 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
12624 "\n\t\t: -eyeX camera Eye positions pair (start and end)"
12625 "\n\t\t: -atX camera Center positions pair"
12626 "\n\t\t: -upX camera Up directions pair"
12627 "\n\t\t: -scaleX camera Scale factors pair"
12628 "\n\t\t: Object animation:"
12629 "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]"
12630 "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]"
12631 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
12632 "\n\t\t: -locX object Location points pair (translation)"
12633 "\n\t\t: -rotX object Orientations pair (quaternions)"
12634 "\n\t\t: -scaleX object Scale factors pair (quaternions)"
12635 "\n\t\t: Custom callback:"
12636 "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\""
12637 "\n\t\t: %Pts overall animation presentation timestamp"
12638 "\n\t\t: %LocalPts local animation timestamp"
12639 "\n\t\t: %Normalized local animation normalized value in range 0..1"
12641 "\n\t\t: Video recording:"
12642 "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]"
12643 "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]"
12644 "\n\t\t: [-crf Value] [-preset Preset]"
12645 "\n\t\t: -fps video framerate"
12646 "\n\t\t: -format file format, container (matroska, etc.)"
12647 "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)"
12648 "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)"
12649 "\n\t\t: -crf constant rate factor (specific to codec)"
12650 "\n\t\t: -preset codec parameters preset (specific to codec)"
12651 __FILE__, VAnimation, group);
12653 theCommands.Add("vchangeselected",
12654 "vchangeselected shape"
12655 "- adds to shape to selection or remove one from it",
12656 __FILE__, VChangeSelected, group);
12657 theCommands.Add ("vnbselected",
12659 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
12660 theCommands.Add ("vcamera",
12661 "vcamera [PrsName] [-ortho] [-projtype]"
12663 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
12664 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
12665 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
12666 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
12667 "\n\t\t: Manages camera parameters."
12668 "\n\t\t: Displays frustum when presntation name PrsName is specified."
12669 "\n\t\t: Prints current value when option called without argument."
12670 "\n\t\t: Orthographic camera:"
12671 "\n\t\t: -ortho activate orthographic projection"
12672 "\n\t\t: Perspective camera:"
12673 "\n\t\t: -persp activate perspective projection (mono)"
12674 "\n\t\t: -fovy field of view in y axis, in degrees"
12675 "\n\t\t: -distance distance of eye from camera center"
12676 "\n\t\t: Stereoscopic camera:"
12677 "\n\t\t: -stereo perspective projection (stereo)"
12678 "\n\t\t: -leftEye perspective projection (left eye)"
12679 "\n\t\t: -rightEye perspective projection (right eye)"
12680 "\n\t\t: -iod intraocular distance value"
12681 "\n\t\t: -iodType distance type, absolute or relative"
12682 "\n\t\t: -zfocus stereographic focus value"
12683 "\n\t\t: -zfocusType focus type, absolute or relative",
12684 __FILE__, VCamera, group);
12685 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
12686 "- vautozfit [on={1|0}] [scale]\n"
12687 " Prints or changes parameters of automatic z-fit mode:\n"
12688 " \"on\" - turns automatic z-fit on or off\n"
12689 " \"scale\" - specifies factor to scale computed z range.\n",
12690 __FILE__, VAutoZFit, group);
12691 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
12692 " vzrange - without parameters shows current values\n"
12693 " vzrange [znear] [zfar] - applies provided values to view",
12694 __FILE__,VZRange, group);
12695 theCommands.Add ("vpurgedisplay",
12697 "- removes structures which don't belong to objects displayed in neutral point",
12698 __FILE__, VPurgeDisplay, group);
12699 theCommands.Add("vsetviewsize",
12700 "vsetviewsize size",
12701 __FILE__,VSetViewSize,group);
12702 theCommands.Add("vmoveview",
12703 "vmoveview Dx Dy Dz [Start = 1|0]",
12704 __FILE__,VMoveView,group);
12705 theCommands.Add("vtranslateview",
12706 "vtranslateview Dx Dy Dz [Start = 1|0)]",
12707 __FILE__,VTranslateView,group);
12708 theCommands.Add("vturnview",
12709 "vturnview Ax Ay Az [Start = 1|0]",
12710 __FILE__,VTurnView,group);
12711 theCommands.Add("vtextureenv",
12712 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
12713 "or user-defined file and optionally applying texture mapping parameters\n"
12715 " vtextureenv off - disables environment mapping\n"
12716 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
12717 " std_texture = (0..7)\n"
12718 " rep = {clamp|repeat}\n"
12719 " mod = {decal|modulate}\n"
12720 " flt = {nearest|bilinear|trilinear}\n"
12721 " ss, st - scale factors for s and t texture coordinates\n"
12722 " ts, tt - translation for s and t texture coordinates\n"
12723 " rot - texture rotation angle in degrees",
12724 __FILE__, VTextureEnv, group);
12725 theCommands.Add("vhlr",
12726 "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
12727 "\n\t\t: Hidden Line Removal algorithm."
12728 "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones"
12729 "\n\t\t: -algoType type of HLR algorithm.\n",
12730 __FILE__,VHLR,group);
12731 theCommands.Add("vhlrtype",
12732 "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
12733 "\n\t\t: Changes the type of HLR algorithm using for shapes:"
12734 "\n\t\t: 'algo' - exact HLR algorithm is applied"
12735 "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied"
12736 "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
12737 __FILE__,VHLRType,group);
12738 theCommands.Add("vclipplane",
12739 "vclipplane planeName [{0|1}]"
12740 "\n\t\t: [-equation1 A B C D]"
12741 "\n\t\t: [-equation2 A B C D]"
12742 "\n\t\t: [-boxInterior MinX MinY MinZ MaxX MaxY MaxZ]"
12743 "\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]"
12744 "\n\t\t: [-maxPlanes]"
12745 "\n\t\t: [-capping {0|1}]"
12746 "\n\t\t: [-color R G B] [-transparency Value] [-hatch {on|off|ID}]"
12747 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
12748 "\n\t\t: [-texRotate Angle]"
12749 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
12750 "\n\t\t: [-useObjShader {0|1}]"
12751 "\n\t\t: Clipping planes management:"
12752 "\n\t\t: -maxPlanes print plane limit for view"
12753 "\n\t\t: -delete delete plane with given name"
12754 "\n\t\t: {off|on|0|1} turn clipping on/off"
12755 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
12756 "\n\t\t: applied to active View when list is omitted"
12757 "\n\t\t: -equation A B C D change plane equation"
12758 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
12759 "\n\t\t: Capping options:"
12760 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
12761 "\n\t\t: -color R G B set capping color"
12762 "\n\t\t: -transparency Value set capping transparency 0..1"
12763 "\n\t\t: -texName Texture set capping texture"
12764 "\n\t\t: -texScale SX SY set capping tex scale"
12765 "\n\t\t: -texOrigin TX TY set capping tex origin"
12766 "\n\t\t: -texRotate Angle set capping tex rotation"
12767 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
12768 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
12769 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
12770 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
12771 __FILE__, VClipPlane, group);
12772 theCommands.Add("vdefaults",
12773 "vdefaults [-absDefl value]"
12774 "\n\t\t: [-devCoeff value]"
12775 "\n\t\t: [-angDefl value]"
12776 "\n\t\t: [-autoTriang {off/on | 0/1}]"
12777 , __FILE__, VDefaults, group);
12778 theCommands.Add("vlight",
12779 "tool to manage light sources, without arguments shows list of lights."
12780 "\n Main commands: "
12781 "\n '-clear' to clear lights"
12782 "\n '-{def}aults' to load deafault lights"
12783 "\n '-add' <type> to add any light source"
12784 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
12785 "\n 'change' <lightId> to edit light source with specified lightId"
12786 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
12788 "\n -{pos}ition X Y Z"
12789 "\n -{dir}ection X Y Z (for directional light or for spotlight)"
12790 "\n -color colorName"
12791 "\n -{head}light 0|1"
12792 "\n -{sm}oothness value"
12793 "\n -{int}ensity value"
12794 "\n -{constAtten}uation value"
12795 "\n -{linearAtten}uation value"
12796 "\n -angle angleDeg"
12797 "\n -{spotexp}onent value"
12798 "\n -local|-global"
12799 "\n\n example: vlight -add positional -head 1 -pos 0 1 1 -color red"
12800 "\n example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2",
12801 __FILE__, VLight, group);
12802 theCommands.Add("vraytrace",
12804 "\n\t\t: Turns on/off ray-tracing renderer."
12805 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
12806 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
12807 __FILE__, VRenderParams, group);
12808 theCommands.Add("vrenderparams",
12809 "\n Manages rendering parameters: "
12810 "\n '-raster' Disables GPU ray-tracing"
12811 "\n '-msaa 0..4' Specifies number of samples for MSAA"
12812 "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor"
12813 "\n '-depthPrePass on|off' Enables/disables depth pre-pass"
12814 "\n '-alphatocoverage on|off' Enables/disables alpha to coverage (needs MSAA)"
12815 "\n '-rendScale value Rendering resolution scale factor"
12816 "\n '-rayTrace' Enables GPU ray-tracing"
12817 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
12818 "\n '-shadows on|off' Enables/disables shadows rendering"
12819 "\n '-reflections on|off' Enables/disables specular reflections"
12820 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
12821 "\n '-gleam on|off' Enables/disables transparency shadow effects"
12822 "\n '-gi on|off' Enables/disables global illumination effects"
12823 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
12824 "\n '-env on|off' Enables/disables environment map background"
12825 "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
12826 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
12827 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
12828 "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)"
12829 "\n '-nbtiles 64..1024' Specifies number of screen tiles in ISS mode"
12830 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
12831 "\n '-shadingModel model' Controls shading model from enumeration"
12832 "\n color, flat, gouraud, phong"
12833 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
12834 "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)"
12835 "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect"
12836 "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)"
12837 "\n '-whitepoint value' White point value for filmic tone mapping"
12838 "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)"
12839 "\n '-perfCounters none|fps|cpu|layers|structures|groups|arrays|triagles|points"
12840 "\n ' |gpuMem|frameTime|basic|extended|full|nofps|skipImmediate'"
12841 "\n Show/hide performance counters (flags can be combined)"
12842 "\n '-perfUpdateInterval nbSeconds' Performance counters update interval"
12843 "\n '-perfChart nbFrames' Show frame timers chart limited by specified number of frames"
12844 "\n '-perfChartMax seconds' Maximum time in seconds with the chart"
12845 "\n '-frustumCulling on|off|noupdate' Enable/disable objects frustum clipping or"
12846 "\n set state to check structures culled previously."
12847 "\n Unlike vcaps, these parameters dramatically change visual properties."
12848 "\n Command is intended to control presentation quality depending on"
12849 "\n hardware capabilities and performance.",
12850 __FILE__, VRenderParams, group);
12851 theCommands.Add("vstatprofiler",
12852 "\n vstatprofiler [fps|cpu|allLayers|layers|allstructures|structures|groups"
12853 "\n |allArrays|fillArrays|lineArrays|pointArrays|textArrays"
12854 "\n |triagles|points|geomMem|textureMem|frameMem"
12855 "\n |elapsedFrame|cpuFrameAverage|cpuPickingAverage|cpuCullingAverage|cpuDynAverage"
12856 "\n |cpuFrameMax|cpuPickingMax|cpuCullingMax|cpuDynMax]"
12858 "\n\t\t: Prints rendering statistics."
12859 "\n\t\t: If there are some parameters - print corresponding statistic counters values,"
12860 "\n\t\t: else - print all performance counters set previously."
12861 "\n\t\t: '-noredraw' Flag to avoid additional redraw call and use already collected values.\n",
12862 __FILE__, VStatProfiler, group);
12863 theCommands.Add ("vplace",
12865 "\n\t\t: Places the point (in pixels) at the center of the window",
12866 __FILE__, VPlace, group);
12867 theCommands.Add("vxrotate",
12869 __FILE__,VXRotate,group);
12871 theCommands.Add("vmanipulator",
12872 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
12873 "\n tool to create and manage AIS manipulators."
12875 "\n '-attach AISObject' attach manipulator to AISObject"
12876 "\n '-adjustPosition {0|1}' adjust position when attaching"
12877 "\n '-adjustSize {0|1}' adjust size when attaching"
12878 "\n '-enableModes {0|1}' enable modes when attaching"
12879 "\n '-detach' detach manipulator"
12880 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
12881 "\n '-transform mouse_x mouse_y' - invoke transformation"
12882 "\n '-stopTransform [abort]' - invoke stop of transformation"
12883 "\n '-move x y z' - move attached object"
12884 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
12885 "\n '-scale factor' - scale attached object"
12886 "\n '-autoActivate {0|1}' - set activation on detection"
12887 "\n '-followTranslation {0|1}' - set following translation transform"
12888 "\n '-followRotation {0|1}' - set following rotation transform"
12889 "\n '-gap value' - set gap between sub-parts"
12890 "\n '-part axis mode {0|1}' - set visual part"
12891 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
12892 "\n '-size value' - set size of manipulator"
12893 "\n '-zoomable {0|1}' - set zoom persistence",
12894 __FILE__, VManipulator, group);
12896 theCommands.Add("vselprops",
12897 "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]"
12898 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
12899 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
12900 "\n -autoHighlight {0|1} : disables|enables automatic highlighting in 3D Viewer"
12901 "\n -highlightSelected {0|1}: disables|enables highlighting of detected object in selected state"
12902 "\n -pickStrategy {first|topmost} : defines picking strategy"
12903 "\n 'first' to pick first acceptable (default)"
12904 "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)"
12905 "\n -pixTol value : sets up pixel tolerance"
12906 "\n -dispMode dispMode : sets display mode for highlighting"
12907 "\n -layer ZLayer : sets ZLayer for highlighting"
12908 "\n -color {name|r g b} : sets highlight color"
12909 "\n -transp value : sets transparency coefficient for highlight"
12910 "\n -material material : sets highlight material"
12911 "\n -print : prints current state of all mentioned parameters",
12912 __FILE__, VSelectionProperties, group);
12913 theCommands.Add ("vhighlightselected",
12914 "vhighlightselected [0|1]: alias for vselprops -highlightSelected.\n",
12915 __FILE__, VSelectionProperties, group);
12917 theCommands.Add ("vseldump",
12918 "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1"
12919 "\n\t\t: Generate an image based on detection results:"
12920 "\n\t\t: depth normalized depth values"
12921 "\n\t\t: unnormDepth unnormalized depth values"
12922 "\n\t\t: object color of detected object"
12923 "\n\t\t: owner color of detected owner"
12924 "\n\t\t: selMode color of selection mode"
12925 "\n\t\t: entity color of etected entity",
12926 __FILE__, VDumpSelectionImage, group);
12928 #if defined(_WIN32)
12929 theCommands.Add("vprogressive",
12931 __FILE__, VProgressiveMode, group);