1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <OpenGl_GlCore20.hxx>
19 #include <AIS_Animation.hxx>
20 #include <AIS_AnimationCamera.hxx>
21 #include <AIS_AnimationObject.hxx>
22 #include <AIS_ColorScale.hxx>
23 #include <AIS_Manipulator.hxx>
24 #include <AIS_RubberBand.hxx>
25 #include <AIS_Shape.hxx>
26 #include <AIS_InteractiveObject.hxx>
27 #include <AIS_ListOfInteractive.hxx>
28 #include <AIS_ListIteratorOfListOfInteractive.hxx>
30 #include <Draw_ProgressIndicator.hxx>
31 #include <Graphic3d_ArrayOfPolylines.hxx>
32 #include <Graphic3d_AspectMarker3d.hxx>
33 #include <Graphic3d_ExportFormat.hxx>
34 #include <Graphic3d_NameOfTextureEnv.hxx>
35 #include <Graphic3d_GraduatedTrihedron.hxx>
36 #include <Graphic3d_TextureEnv.hxx>
37 #include <Graphic3d_TextureParams.hxx>
38 #include <Graphic3d_TypeOfTextureFilter.hxx>
39 #include <Graphic3d_AspectFillArea3d.hxx>
40 #include <ViewerTest.hxx>
41 #include <ViewerTest_AutoUpdater.hxx>
42 #include <ViewerTest_EventManager.hxx>
43 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
44 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
45 #include <ViewerTest_CmdParser.hxx>
46 #include <V3d_AmbientLight.hxx>
47 #include <V3d_DirectionalLight.hxx>
48 #include <V3d_PositionalLight.hxx>
49 #include <V3d_SpotLight.hxx>
50 #include <Message_ProgressSentry.hxx>
51 #include <NCollection_DoubleMap.hxx>
52 #include <NCollection_List.hxx>
53 #include <NCollection_Vector.hxx>
54 #include <AIS_InteractiveContext.hxx>
55 #include <Draw_Interpretor.hxx>
57 #include <Draw_Appli.hxx>
58 #include <Image_AlienPixMap.hxx>
59 #include <Image_VideoRecorder.hxx>
60 #include <OpenGl_GraphicDriver.hxx>
61 #include <OSD_Timer.hxx>
62 #include <TColStd_HSequenceOfAsciiString.hxx>
63 #include <TColStd_SequenceOfInteger.hxx>
64 #include <TColStd_HSequenceOfReal.hxx>
65 #include <TColgp_Array1OfPnt2d.hxx>
66 #include <TColStd_MapOfAsciiString.hxx>
67 #include <Aspect_TypeOfLine.hxx>
68 #include <Image_Diff.hxx>
69 #include <Aspect_DisplayConnection.hxx>
73 #include <PrsMgr_PresentableObject.hxx>
74 #include <Graphic3d_ClipPlane.hxx>
75 #include <NCollection_DataMap.hxx>
76 #include <Graphic3d_Texture2Dmanual.hxx>
77 #include <Prs3d_ShadingAspect.hxx>
78 #include <Prs3d_Drawer.hxx>
79 #include <Prs3d_LineAspect.hxx>
80 #include <Prs3d_Root.hxx>
81 #include <Prs3d_Text.hxx>
82 #include <Select3D_SensitivePrimitiveArray.hxx>
91 #include <WNT_WClass.hxx>
92 #include <WNT_Window.hxx>
93 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
94 #include <Cocoa_Window.hxx>
96 #include <Xw_Window.hxx>
97 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
98 #include <X11/Xutil.h>
102 // Auxiliary definitions
103 static const char THE_KEY_DELETE = 127;
104 static const char THE_KEY_ESCAPE = 27;
106 //==============================================================================
107 // VIEWER GLOBAL VARIABLES
108 //==============================================================================
110 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
111 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
113 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
114 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
116 extern int VErase (Draw_Interpretor& theDI,
117 Standard_Integer theArgNb,
118 const char** theArgVec);
121 static Handle(WNT_Window)& VT_GetWindow() {
122 static Handle(WNT_Window) WNTWin;
125 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
126 static Handle(Cocoa_Window)& VT_GetWindow()
128 static Handle(Cocoa_Window) aWindow;
131 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
132 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
133 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
136 static Handle(Xw_Window)& VT_GetWindow(){
137 static Handle(Xw_Window) XWWin;
141 static void VProcessEvents(ClientData,int);
144 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
146 static Handle(Aspect_DisplayConnection) aDisplayConnection;
147 return aDisplayConnection;
150 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
152 GetDisplayConnection() = theDisplayConnection;
155 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
156 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
158 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
160 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
161 if (!aWindow.IsNull())
162 return aWindow->HWindow();
163 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
164 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
165 if (!aWindow.IsNull())
166 return aWindow->XWindow();
168 return aWindowHandle;
172 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
173 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
174 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
175 static OpenGl_Caps ViewerTest_myDefaultCaps;
177 static void OSWindowSetup();
181 Quantity_Color FlatColor;
182 Quantity_Color GradientColor1;
183 Quantity_Color GradientColor2;
184 Aspect_GradientFillMethod FillMethod;
185 } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
187 //==============================================================================
188 // EVENT GLOBAL VARIABLES
189 //==============================================================================
191 static int Start_Rot = 0;
192 Standard_Boolean HasHlrOnBeforeRotation = Standard_False;
193 int X_Motion = 0; // Current cursor position
195 int X_ButtonPress = 0; // Last ButtonPress position
196 int Y_ButtonPress = 0;
197 Standard_Boolean IsDragged = Standard_False;
198 Standard_Boolean DragFirst = Standard_False;
199 Standard_Boolean TheIsAnimating = Standard_False;
200 Standard_Boolean Draw_ToExitOnCloseView = Standard_False;
201 Standard_Boolean Draw_ToCloseViewOnEsc = Standard_False;
204 Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand()
206 static Handle(AIS_RubberBand) aBand;
209 aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0);
210 aBand->SetDisplayMode (0);
215 typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators;
217 Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators()
219 static ViewerTest_MapOfAISManipulators aMap;
223 Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator()
225 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
226 for (; anIt.More(); anIt.Next())
228 if (anIt.Value()->HasActiveMode())
236 //==============================================================================
239 static LRESULT WINAPI ViewerWindowProc(
244 static LRESULT WINAPI AdvViewerWindowProc(
252 //==============================================================================
255 //==============================================================================
257 const Handle(Standard_Transient)& ViewerTest::WClass()
259 static Handle(Standard_Transient) theWClass;
261 if (theWClass.IsNull())
263 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
264 CS_VREDRAW | CS_HREDRAW, 0, 0,
265 ::LoadCursor (NULL, IDC_ARROW));
271 //==============================================================================
272 //function : CreateName
273 //purpose : Create numerical name for new object in theMap
274 //==============================================================================
275 template <typename ObjectType>
276 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
277 const TCollection_AsciiString& theDefaultString)
279 if (theObjectMap.IsEmpty())
280 return theDefaultString + TCollection_AsciiString(1);
282 Standard_Integer aNextKey = 1;
283 Standard_Boolean isFound = Standard_False;
286 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
287 // Look for objects with default names
288 if (theObjectMap.IsBound1(aStringKey))
293 isFound = Standard_True;
296 return theDefaultString + TCollection_AsciiString(aNextKey);
299 //==============================================================================
300 //structure : ViewerTest_Names
301 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
302 //==============================================================================
303 struct ViewerTest_Names
306 TCollection_AsciiString myDriverName;
307 TCollection_AsciiString myViewerName;
308 TCollection_AsciiString myViewName;
312 const TCollection_AsciiString& GetDriverName () const
316 void SetDriverName (const TCollection_AsciiString& theDriverName)
318 myDriverName = theDriverName;
320 const TCollection_AsciiString& GetViewerName () const
324 void SetViewerName (const TCollection_AsciiString& theViewerName)
326 myViewerName = theViewerName;
328 const TCollection_AsciiString& GetViewName () const
332 void SetViewName (const TCollection_AsciiString& theViewName)
334 myViewName = theViewName;
337 //===========================================================================
338 //function : Constructor for ViewerTest_Names
339 //purpose : Get view, viewer, driver names from custom string
340 //===========================================================================
342 ViewerTest_Names (const TCollection_AsciiString& theInputString)
344 TCollection_AsciiString aName(theInputString);
345 if (theInputString.IsEmpty())
347 // Get current configuration
348 if (ViewerTest_myDrivers.IsEmpty())
349 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
350 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
352 myDriverName = ViewerTest_myDrivers.Find2
353 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
355 if(ViewerTest_myContexts.IsEmpty())
357 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
358 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
362 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
365 myViewName = CreateName <Handle(V3d_View)> (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
369 // There is at least view name
370 Standard_Integer aParserNumber = 0;
371 for (Standard_Integer i = 0; i < 3; ++i)
373 Standard_Integer aParserPos = aName.SearchFromEnd("/");
377 aName.Split(aParserPos-1);
382 if (aParserNumber == 0)
385 if (!ViewerTest::GetAISContext().IsNull())
387 myDriverName = ViewerTest_myDrivers.Find2
388 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
389 myViewerName = ViewerTest_myContexts.Find2
390 (ViewerTest::GetAISContext());
394 // There is no opened contexts here, need to create names for viewer and driver
395 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
396 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
398 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
399 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
401 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
403 else if (aParserNumber == 1)
405 // Here is viewerName/viewName
406 if (!ViewerTest::GetAISContext().IsNull())
407 myDriverName = ViewerTest_myDrivers.Find2
408 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
411 // There is no opened contexts here, need to create name for driver
412 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
413 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
415 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
417 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
421 //Here is driverName/viewerName/viewName
422 myDriverName = TCollection_AsciiString(aName);
424 TCollection_AsciiString aViewerName(theInputString);
425 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
426 myViewerName = TCollection_AsciiString(aViewerName);
428 myViewName = TCollection_AsciiString(theInputString);
434 //==============================================================================
435 //function : FindContextByView
436 //purpose : Find AIS_InteractiveContext by View
437 //==============================================================================
439 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
441 Handle(AIS_InteractiveContext) anAISContext;
443 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
444 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
446 if (anIter.Value()->CurrentViewer() == theView->Viewer())
447 return anIter.Key2();
453 //==============================================================================
454 //function : SetWindowTitle
455 //purpose : Set window title
456 //==============================================================================
458 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
459 Standard_CString theTitle)
462 const TCollection_ExtendedString theTitleW (theTitle);
463 SetWindowTextW ((HWND )Handle(WNT_Window)::DownCast(theWindow)->HWindow(), theTitleW.ToWideString());
464 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
465 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
467 if(GetDisplayConnection()->GetDisplay())
470 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
471 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
476 //==============================================================================
477 //function : IsWindowOverlapped
478 //purpose : Check if theWindow overlapp another view
479 //==============================================================================
481 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
482 const Standard_Integer thePxTop,
483 const Standard_Integer thePxRight,
484 const Standard_Integer thePxBottom,
485 TCollection_AsciiString& theViewId)
487 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
488 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
490 Standard_Integer aTop = 0,
494 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
495 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
496 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
497 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
498 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
500 theViewId = anIter.Key1();
501 return Standard_True;
504 return Standard_False;
507 // Workaround: to create and delete non-orthographic views outside ViewerTest
508 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
510 ViewerTest_myViews.UnBind1 (theName);
513 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
514 const Handle(V3d_View)& theView)
516 ViewerTest_myViews.Bind (theName, theView);
519 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
521 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
523 //==============================================================================
524 //function : ViewerInit
525 //purpose : Create the window viewer and initialize all the global variable
526 //==============================================================================
528 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
529 const Standard_Integer thePxTop,
530 const Standard_Integer thePxWidth,
531 const Standard_Integer thePxHeight,
532 Standard_CString theViewName,
533 Standard_CString theDisplayName)
535 // Default position and dimension of the viewer window.
536 // Note that left top corner is set to be sufficiently small to have
537 // window fit in the small screens (actual for remote desktops, see #23003).
538 // The position corresponds to the window's client area, thus some
539 // gap is added for window frame to be visible.
540 Standard_Integer aPxLeft = 20;
541 Standard_Integer aPxTop = 40;
542 Standard_Integer aPxWidth = 409;
543 Standard_Integer aPxHeight = 409;
544 Standard_Boolean toCreateViewer = Standard_False;
546 Handle(OpenGl_GraphicDriver) aGraphicDriver;
547 ViewerTest_Names aViewNames(theViewName);
548 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
549 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
556 aPxWidth = thePxWidth;
557 if (thePxHeight != 0)
558 aPxHeight = thePxHeight;
560 // Get graphic driver (create it or get from another view)
561 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
563 // Get connection string
564 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
565 TCollection_AsciiString aDisplayName(theDisplayName);
566 if (!aDisplayName.IsEmpty())
567 SetDisplayConnection (new Aspect_DisplayConnection ());
569 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
571 (void)theDisplayName; // avoid warning on unused argument
572 SetDisplayConnection (new Aspect_DisplayConnection ());
575 if (Draw_VirtualWindows)
577 // don't waste the time waiting for VSync when window is not displayed on the screen
578 ViewerTest_myDefaultCaps.swapInterval = 0;
579 // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
580 //ViewerTest_myDefaultCaps.buffersNoSwap = true;
582 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
583 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
585 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
586 toCreateViewer = Standard_True;
590 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
593 //Dispose the window if input parameters are default
594 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
596 Standard_Integer aTop = 0,
603 // Get screen resolution
604 #if defined(_WIN32) || defined(__WIN32__)
606 GetClientRect(GetDesktopWindow(), &aWindowSize);
607 aScreenHeight = aWindowSize.bottom;
608 aScreenWidth = aWindowSize.right;
609 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
610 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
612 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
613 aScreenWidth = WidthOfScreen(aScreen);
614 aScreenHeight = HeightOfScreen(aScreen);
617 TCollection_AsciiString anOverlappedViewId("");
619 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
621 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
623 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
624 && aRight + 2*aPxWidth + 40 > aScreenWidth)
626 if (aBottom + aPxHeight + 40 > aScreenHeight)
633 aPxTop = aBottom + 40;
636 aPxLeft = aRight + 20;
641 TCollection_AsciiString aTitle("3D View - ");
642 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
644 // Change name of current active window
645 if (!ViewerTest::CurrentView().IsNull())
647 TCollection_AsciiString anActiveWindowTitle("3D View - ");
648 anActiveWindowTitle = anActiveWindowTitle
649 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
650 SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString());
654 Handle(V3d_Viewer) a3DViewer;
655 // If it's the single view, we first look for empty context
656 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
658 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
659 anIter(ViewerTest_myContexts);
661 ViewerTest::SetAISContext (anIter.Value());
662 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
664 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
666 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
667 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
669 else if (a3DViewer.IsNull())
671 toCreateViewer = Standard_True;
672 a3DViewer = new V3d_Viewer(aGraphicDriver);
673 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
674 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
675 ViewerTest_DefaultBackground.GradientColor2,
676 ViewerTest_DefaultBackground.FillMethod);
680 if (ViewerTest::GetAISContext().IsNull() ||
681 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
683 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
684 ViewerTest::SetAISContext (aContext);
685 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
689 ViewerTest::ResetEventManager();
694 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
695 Handle(WNT_WClass)::DownCast (WClass()),
696 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
700 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
701 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
703 aPxWidth, aPxHeight);
704 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
706 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
709 aPxWidth, aPxHeight);
711 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
714 Handle(V3d_View) aView = a3DViewer->CreateView();
715 aView->SetWindow (VT_GetWindow());
716 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
718 ViewerTest::CurrentView(aView);
719 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
721 // Setup for X11 or NT
724 // Set parameters for V3d_View and V3d_Viewer
725 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
726 aV3dView->SetComputedMode(Standard_False);
728 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
731 a3DViewer->SetDefaultLights();
732 a3DViewer->SetLightOn();
735 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
736 #if TCL_MAJOR_VERSION < 8
737 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
738 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
740 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
741 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
745 VT_GetWindow()->Map();
747 // Set the handle of created view in the event manager
748 ViewerTest::ResetEventManager();
750 ViewerTest::CurrentView()->Redraw();
755 return aViewNames.GetViewName();
758 //==============================================================================
759 //function : RedrawAllViews
760 //purpose : Redraw all created views
761 //==============================================================================
762 void ViewerTest::RedrawAllViews()
764 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
765 for (; aViewIt.More(); aViewIt.Next())
767 const Handle(V3d_View)& aView = aViewIt.Key2();
772 //==============================================================================
774 //purpose : Create the window viewer and initialize all the global variable
775 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
776 //==============================================================================
778 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
780 TCollection_AsciiString aViewName, aDisplayName;
781 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
782 TCollection_AsciiString aName, aValue;
783 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
785 const TCollection_AsciiString anArg = theArgVec[anArgIt];
786 TCollection_AsciiString anArgCase = anArg;
787 anArgCase.LowerCase();
788 if (anArgIt + 1 < theArgsNb
789 && anArgCase == "-name")
791 aViewName = theArgVec[++anArgIt];
793 else if (anArgIt + 1 < theArgsNb
794 && (anArgCase == "-left"
795 || anArgCase == "-l"))
797 aPxLeft = Draw::Atoi (theArgVec[++anArgIt]);
799 else if (anArgIt + 1 < theArgsNb
800 && (anArgCase == "-top"
801 || anArgCase == "-t"))
803 aPxTop = Draw::Atoi (theArgVec[++anArgIt]);
805 else if (anArgIt + 1 < theArgsNb
806 && (anArgCase == "-width"
807 || anArgCase == "-w"))
809 aPxWidth = Draw::Atoi (theArgVec[++anArgIt]);
811 else if (anArgIt + 1 < theArgsNb
812 && (anArgCase == "-height"
813 || anArgCase == "-h"))
815 aPxHeight = Draw::Atoi (theArgVec[++anArgIt]);
817 else if (anArgCase == "-exitonclose")
819 Draw_ToExitOnCloseView = true;
820 if (anArgIt + 1 < theArgsNb
821 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToExitOnCloseView))
826 else if (anArgCase == "-closeonescape"
827 || anArgCase == "-closeonesc")
829 Draw_ToCloseViewOnEsc = true;
830 if (anArgIt + 1 < theArgsNb
831 && ViewerTest::ParseOnOff (theArgVec[anArgIt + 1], Draw_ToCloseViewOnEsc))
836 else if (anArgIt + 1 < theArgsNb
837 && (anArgCase == "-disp"
838 || anArgCase == "-display"))
840 aDisplayName = theArgVec[++anArgIt];
843 else if (ViewerTest::SplitParameter (anArg, aName, aValue))
850 else if (aName == "l"
853 aPxLeft = aValue.IntegerValue();
855 else if (aName == "t"
858 aPxTop = aValue.IntegerValue();
860 else if (aName == "disp"
861 || aName == "display")
863 aDisplayName = aValue;
865 else if (aName == "w"
868 aPxWidth = aValue.IntegerValue();
870 else if (aName == "h"
871 || aName == "height")
873 aPxHeight = aValue.IntegerValue();
877 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
881 else if (aViewName.IsEmpty())
887 std::cout << "Syntax error: unknown argument " << anArg << ".\n";
892 #if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
893 if (!aDisplayName.IsEmpty())
895 aDisplayName.Clear();
896 std::cout << "Warning: display parameter will be ignored.\n";
900 ViewerTest_Names aViewNames (aViewName);
901 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
903 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
904 theDi.Eval (aCommand.ToCString());
908 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
909 aViewName.ToCString(),
910 aDisplayName.ToCString());
915 //! Parse HLR algo type.
916 static Standard_Boolean parseHlrAlgoType (const char* theName,
917 Prs3d_TypeOfHLR& theType)
919 TCollection_AsciiString aName (theName);
921 if (aName == "polyalgo")
923 theType = Prs3d_TOH_PolyAlgo;
925 else if (aName == "algo")
927 theType = Prs3d_TOH_Algo;
931 return Standard_False;
933 return Standard_True;
936 //==============================================================================
938 //purpose : hidden lines removal algorithm
939 //==============================================================================
941 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
943 const Handle(V3d_View) aView = ViewerTest::CurrentView();
944 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
947 std::cerr << "Error: No opened viewer!\n";
951 Standard_Boolean hasHlrOnArg = Standard_False;
952 Standard_Boolean hasShowHiddenArg = Standard_False;
953 Standard_Boolean isHLROn = Standard_False;
954 Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
955 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
956 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
957 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
959 TCollection_AsciiString anArg (argv[anArgIter]);
961 if (anUpdateTool.parseRedrawMode (anArg))
965 else if (anArg == "-showhidden"
966 && anArgIter + 1 < argc
967 && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden))
970 hasShowHiddenArg = Standard_True;
973 else if ((anArg == "-type"
975 || anArg == "-algotype")
976 && anArgIter + 1 < argc
977 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
982 else if (!hasHlrOnArg
983 && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn))
985 hasHlrOnArg = Standard_True;
989 else if (!hasShowHiddenArg
990 && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden))
992 hasShowHiddenArg = Standard_True;
997 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
1003 di << "HLR: " << aView->ComputedMode() << "\n";
1004 di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
1006 switch (aCtx->DefaultDrawer()->TypeOfHLR())
1008 case Prs3d_TOH_NotSet: di << "NotSet\n"; break;
1009 case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
1010 case Prs3d_TOH_Algo: di << "Algo\n"; break;
1012 anUpdateTool.Invalidate();
1016 Standard_Boolean toRecompute = Standard_False;
1017 if (aTypeOfHLR != Prs3d_TOH_NotSet
1018 && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
1020 toRecompute = Standard_True;
1021 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1023 if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
1025 toRecompute = Standard_True;
1028 aCtx->DefaultDrawer()->EnableDrawHiddenLine();
1032 aCtx->DefaultDrawer()->DisableDrawHiddenLine();
1037 if (aView->ComputedMode() && isHLROn && toRecompute)
1039 AIS_ListOfInteractive aListOfShapes;
1040 aCtx->DisplayedObjects (aListOfShapes);
1041 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
1043 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
1045 aCtx->Redisplay (aShape, Standard_False);
1050 aView->SetComputedMode (isHLROn);
1054 //==============================================================================
1055 //function : VHLRType
1056 //purpose : change type of using HLR algorithm
1057 //==============================================================================
1059 static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1061 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1062 const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1065 std::cerr << "Error: No opened viewer!\n";
1069 Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
1070 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
1071 AIS_ListOfInteractive aListOfShapes;
1072 for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
1074 TCollection_AsciiString anArg (argv[anArgIter]);
1076 if (anUpdateTool.parseRedrawMode (anArg))
1080 else if ((anArg == "-type"
1082 || anArg == "-algotype")
1083 && anArgIter + 1 < argc
1084 && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
1090 else if (aTypeOfHLR == Prs3d_TOH_NotSet
1091 && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
1097 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
1098 TCollection_AsciiString aName (argv[anArgIter]);
1099 if (!aMap.IsBound2 (aName))
1101 std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n";
1105 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
1106 if (aShape.IsNull())
1108 std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n";
1111 aListOfShapes.Append (aShape);
1115 if (aTypeOfHLR == Prs3d_TOH_NotSet)
1117 std::cout << "Syntax error: wrong number of arguments!\n";
1121 const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
1124 aCtx->DisplayedObjects (aListOfShapes);
1125 aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
1128 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
1130 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1131 if (aShape.IsNull())
1136 const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
1137 && aView->ComputedMode();
1139 || aShape->TypeOfHLR() != aTypeOfHLR)
1141 aShape->SetTypeOfHLR (aTypeOfHLR);
1145 aCtx->Redisplay (aShape, Standard_False);
1151 //==============================================================================
1152 //function : FindViewIdByWindowHandle
1153 //purpose : Find theView Id in the map of views by window handle
1154 //==============================================================================
1155 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1156 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
1158 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
1159 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1161 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
1162 if (aWindowHandle == theWindowHandle)
1163 return anIter.Key1();
1165 return TCollection_AsciiString("");
1169 //==============================================================================
1170 //function : ActivateView
1171 //purpose : Make the view active
1172 //==============================================================================
1174 void ActivateView (const TCollection_AsciiString& theViewName)
1176 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1177 if (!aView.IsNull())
1179 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1180 if (!anAISContext.IsNull())
1182 if (!ViewerTest::CurrentView().IsNull())
1184 TCollection_AsciiString aTitle("3D View - ");
1185 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1186 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1189 ViewerTest::CurrentView (aView);
1190 ViewerTest::SetAISContext (anAISContext);
1191 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ") + theViewName + "(*)";
1192 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1194 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1195 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1196 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1198 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1200 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1201 ViewerTest::CurrentView()->Redraw();
1206 //==============================================================================
1207 //function : RemoveView
1209 //==============================================================================
1210 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1211 const Standard_Boolean theToRemoveContext)
1213 if (!ViewerTest_myViews.IsBound2 (theView))
1218 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1219 RemoveView (aViewName, theToRemoveContext);
1222 //==============================================================================
1223 //function : RemoveView
1224 //purpose : Close and remove view from display, clear maps if neccessary
1225 //==============================================================================
1226 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1228 if (!ViewerTest_myViews.IsBound1(theViewName))
1230 cout << "Wrong view name\n";
1234 // Activate another view if it's active now
1235 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1237 if (ViewerTest_myViews.Extent() > 1)
1239 TCollection_AsciiString aNewViewName;
1240 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1241 anIter.More(); anIter.Next())
1243 if (anIter.Key1() != theViewName)
1245 aNewViewName = anIter.Key1();
1249 ActivateView (aNewViewName);
1253 Handle(V3d_View) anEmptyView;
1254 #if defined(_WIN32) || defined(__WIN32__)
1255 Handle(WNT_Window) anEmptyWindow;
1256 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1257 Handle(Cocoa_Window) anEmptyWindow;
1259 Handle(Xw_Window) anEmptyWindow;
1261 VT_GetWindow() = anEmptyWindow;
1262 ViewerTest::CurrentView (anEmptyView);
1263 if (isContextRemoved)
1265 Handle(AIS_InteractiveContext) anEmptyContext;
1266 ViewerTest::SetAISContext(anEmptyContext);
1272 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1273 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1275 // Remove view resources
1276 ViewerTest_myViews.UnBind1(theViewName);
1277 aView->Window()->Unmap();
1280 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1281 XFlush (GetDisplayConnection()->GetDisplay());
1284 // Keep context opened only if the closed view is last to avoid
1285 // unused empty contexts
1286 if (!aCurrentContext.IsNull())
1288 // Check if there are more difined views in the viewer
1289 aCurrentContext->CurrentViewer()->InitDefinedViews();
1290 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1292 // Remove driver if there is no viewers that use it
1293 Standard_Boolean isRemoveDriver = Standard_True;
1294 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1295 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1297 if (aCurrentContext != anIter.Key2() &&
1298 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1300 isRemoveDriver = Standard_False;
1305 aCurrentContext->RemoveAll (Standard_False);
1308 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1309 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1310 #if TCL_MAJOR_VERSION < 8
1311 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1313 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1318 ViewerTest_myContexts.UnBind2(aCurrentContext);
1321 cout << "3D View - " << theViewName << " was deleted.\n";
1322 if (Draw_ToExitOnCloseView)
1324 Draw_Interprete ("exit");
1328 //==============================================================================
1330 //purpose : Remove the view defined by its name
1331 //==============================================================================
1333 static int VClose (Draw_Interpretor& /*theDi*/,
1334 Standard_Integer theArgsNb,
1335 const char** theArgVec)
1337 NCollection_List<TCollection_AsciiString> aViewList;
1340 TCollection_AsciiString anArg (theArgVec[1]);
1342 if (anArg.IsEqual ("ALL")
1343 || anArg.IsEqual ("*"))
1345 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1346 anIter.More(); anIter.Next())
1348 aViewList.Append (anIter.Key1());
1350 if (aViewList.IsEmpty())
1352 std::cout << "No view to close\n";
1358 ViewerTest_Names aViewName (theArgVec[1]);
1359 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1361 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1364 aViewList.Append (aViewName.GetViewName());
1369 // close active view
1370 if (ViewerTest::CurrentView().IsNull())
1372 std::cerr << "No active view!\n";
1375 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1378 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1379 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1380 anIter.More(); anIter.Next())
1382 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1388 //==============================================================================
1389 //function : VActivate
1390 //purpose : Activate the view defined by its ID
1391 //==============================================================================
1393 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1397 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1398 << "Usage: " << theArgVec[0] << " ViewID\n";
1403 theDi.Eval("vviewlist");
1407 TCollection_AsciiString aNameString(theArgVec[1]);
1408 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1410 TCollection_AsciiString aTitle("3D View - ");
1411 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1412 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1413 Handle(V3d_View) anEmptyView;
1414 #if defined(_WIN32) || defined(__WIN32__)
1415 Handle(WNT_Window) anEmptyWindow;
1416 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1417 Handle(Cocoa_Window) anEmptyWindow;
1419 Handle(Xw_Window) anEmptyWindow;
1421 VT_GetWindow() = anEmptyWindow;
1422 ViewerTest::CurrentView (anEmptyView);
1423 ViewerTest::ResetEventManager();
1424 theDi << theArgVec[0] << ": all views are inactive\n";
1428 ViewerTest_Names aViewNames(aNameString);
1430 // Check if this view exists in the viewer with the driver
1431 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1433 theDi << "Wrong view name\n";
1437 // Check if it is active already
1438 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1440 theDi << theArgVec[0] << ": the view is active already\n";
1444 ActivateView (aViewNames.GetViewName());
1448 //==============================================================================
1449 //function : VViewList
1450 //purpose : Print current list of views per viewer and graphic driver ID
1451 // shared between viewers
1452 //==============================================================================
1454 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1458 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1459 << "Usage: " << theArgVec[0] << " name";
1462 if (ViewerTest_myContexts.Size() < 1)
1465 Standard_Boolean isTreeView =
1466 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1470 theDi << theArgVec[0] <<":\n";
1473 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator aDriverIter (ViewerTest_myDrivers);
1474 aDriverIter.More(); aDriverIter.Next())
1477 theDi << aDriverIter.Key1() << ":\n";
1479 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1480 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1482 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1486 TCollection_AsciiString aContextName(aContextIter.Key1());
1487 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
1490 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIter (ViewerTest_myViews);
1491 aViewIter.More(); aViewIter.Next())
1493 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1495 TCollection_AsciiString aViewName(aViewIter.Key1());
1498 if (aViewIter.Value() == ViewerTest::CurrentView())
1499 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
1501 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1505 theDi << aViewName << " ";
1515 //==============================================================================
1516 //function : VT_ProcessKeyPress
1517 //purpose : Handle KeyPress event from a CString
1518 //==============================================================================
1519 void VT_ProcessKeyPress (const char* buf_ret)
1521 //cout << "KeyPress" << endl;
1522 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1523 // Letter in alphabetic order
1525 if (!strcasecmp (buf_ret, "A"))
1528 aView->SetProj(V3d_XposYnegZpos);
1530 else if (!strcasecmp (buf_ret, "D"))
1535 else if (!strcasecmp (buf_ret, "F"))
1537 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1539 ViewerTest::GetAISContext()->FitSelected (aView);
1547 else if (!strcasecmp (buf_ret, "H"))
1550 std::cout << "HLR" << std::endl;
1551 aView->SetComputedMode (!aView->ComputedMode());
1554 else if (!strcasecmp (buf_ret, "P"))
1557 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1558 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1559 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1561 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1562 if (aContext->NbSelected()==0)
1564 AIS_ListOfInteractive aListOfShapes;
1565 aContext->DisplayedObjects(aListOfShapes);
1566 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1567 anIter.More(); anIter.Next())
1569 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1570 if (aShape.IsNull())
1572 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1573 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1575 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1576 aContext->Redisplay (aShape, Standard_False);
1581 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
1583 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
1584 if (aShape.IsNull())
1586 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1587 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1589 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1590 aContext->Redisplay (aShape, Standard_False);
1594 aContext->UpdateCurrentViewer();
1597 else if (!strcasecmp (buf_ret, "S"))
1599 std::cout << "setup Shaded display mode" << std::endl;
1601 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1602 if(Ctx->NbSelected()==0)
1603 Ctx->SetDisplayMode (AIS_Shaded, Standard_True);
1605 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1606 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
1607 Ctx->UpdateCurrentViewer();
1610 else if (!strcasecmp (buf_ret, "U"))
1612 // Unset display mode
1613 std::cout << "reset display mode to defaults" << std::endl;
1615 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1616 if(Ctx->NbSelected()==0)
1617 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
1619 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1620 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
1621 Ctx->UpdateCurrentViewer();
1625 else if (!strcasecmp (buf_ret, "T"))
1628 aView->SetProj(V3d_Zpos);
1630 else if (!strcasecmp (buf_ret, "B"))
1633 aView->SetProj(V3d_Zneg);
1635 else if (!strcasecmp (buf_ret, "L"))
1638 aView->SetProj(V3d_Xneg);
1640 else if (!strcasecmp (buf_ret, "R"))
1643 aView->SetProj(V3d_Xpos);
1645 else if (!strcasecmp (buf_ret, "W"))
1647 std::cout << "setup WireFrame display mode" << std::endl;
1648 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1649 if(Ctx->NbSelected()==0)
1650 Ctx->SetDisplayMode (AIS_WireFrame, Standard_True);
1652 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1653 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
1654 Ctx->UpdateCurrentViewer();
1657 else if (!strcasecmp (buf_ret, ","))
1659 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1661 else if (!strcasecmp (buf_ret, "."))
1663 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1665 else if (!strcasecmp (buf_ret, "/"))
1667 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1668 if (aCamera->IsStereo())
1670 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1674 else if (!strcasecmp (buf_ret, "*"))
1676 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1677 if (aCamera->IsStereo())
1679 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1683 else if (*buf_ret == THE_KEY_DELETE)
1685 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1687 && aCtx->NbSelected() > 0)
1689 Draw_Interprete ("verase");
1692 else if (*buf_ret == THE_KEY_ESCAPE)
1694 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1696 && Draw_ToCloseViewOnEsc)
1698 Draw_Interprete (Draw_ToExitOnCloseView ? "exit" : "vclose");
1704 Standard_Integer Num = Draw::Atoi(buf_ret);
1705 if(Num>=0 && Num<=7)
1706 ViewerTest::StandardModeActivation(Num);
1710 //==============================================================================
1711 //function : VT_ProcessExpose
1712 //purpose : Redraw the View on an Expose Event
1713 //==============================================================================
1714 void VT_ProcessExpose()
1716 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1717 if (!aView3d.IsNull())
1723 //==============================================================================
1724 //function : VT_ProcessConfigure
1725 //purpose : Resize the View on an Configure Event
1726 //==============================================================================
1727 void VT_ProcessConfigure()
1729 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1730 if (aView3d.IsNull())
1735 aView3d->MustBeResized();
1740 //==============================================================================
1741 //function : VT_ProcessButton1Press
1743 //==============================================================================
1744 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1745 const char** theArgVec,
1746 Standard_Boolean theToPick,
1747 Standard_Boolean theIsShift)
1751 TheIsAnimating = Standard_False;
1752 return Standard_False;
1757 Standard_Real X, Y, Z;
1758 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1760 Draw::Set (theArgVec[1], X);
1761 Draw::Set (theArgVec[2], Y);
1762 Draw::Set (theArgVec[3], Z);
1767 ViewerTest::CurrentEventManager()->ShiftSelect();
1771 ViewerTest::CurrentEventManager()->Select();
1774 return Standard_False;
1777 //==============================================================================
1778 //function : VT_ProcessButton1Release
1779 //purpose : End selecting
1780 //==============================================================================
1781 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1785 IsDragged = Standard_False;
1786 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1789 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1790 X_Motion, Y_Motion);
1794 EM->Select (X_ButtonPress, Y_ButtonPress,
1795 X_Motion, Y_Motion);
1800 //==============================================================================
1801 //function : VT_ProcessButton3Press
1802 //purpose : Start Rotation
1803 //==============================================================================
1804 void VT_ProcessButton3Press()
1807 HasHlrOnBeforeRotation = ViewerTest::CurrentView()->ComputedMode();
1808 if (HasHlrOnBeforeRotation)
1810 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1812 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1815 //==============================================================================
1816 //function : VT_ProcessButton3Release
1817 //purpose : End rotation
1818 //==============================================================================
1819 void VT_ProcessButton3Release()
1824 if (HasHlrOnBeforeRotation)
1826 HasHlrOnBeforeRotation = Standard_False;
1827 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1828 ViewerTest::CurrentView()->Redraw();
1833 //==============================================================================
1834 //function : ProcessControlButton1Motion
1836 //==============================================================================
1838 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1839 static void ProcessControlButton1Motion()
1841 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1843 X_ButtonPress = X_Motion;
1844 Y_ButtonPress = Y_Motion;
1848 //==============================================================================
1849 //function : VT_ProcessControlButton2Motion
1851 //==============================================================================
1852 void VT_ProcessControlButton2Motion()
1854 Standard_Integer aDx = X_Motion - X_ButtonPress;
1855 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1857 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1859 ViewerTest::CurrentView()->Pan (aDx, aDy);
1861 X_ButtonPress = X_Motion;
1862 Y_ButtonPress = Y_Motion;
1865 //==============================================================================
1866 //function : VT_ProcessControlButton3Motion
1867 //purpose : Rotation
1868 //==============================================================================
1869 void VT_ProcessControlButton3Motion()
1873 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1877 //==============================================================================
1878 //function : VT_ProcessMotion
1880 //==============================================================================
1881 void VT_ProcessMotion()
1883 //pre-hilights detected objects at mouse position
1885 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1886 EM->MoveTo(X_Motion, Y_Motion);
1890 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1892 Xpix = X_Motion;Ypix=Y_Motion;
1895 //==============================================================================
1896 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1897 //purpose : Switches to an axonometric, top, left and other views
1898 //==============================================================================
1900 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1902 if ( ViewerTest::CurrentView().IsNull() )
1904 di<<"Call vinit before this command, please\n";
1908 ViewerTest::CurrentView()->SetProj(ori);
1912 //==============================================================================
1914 //purpose : Switch to an Axonometric view
1915 //Draw arg : No args
1916 //==============================================================================
1918 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1920 return ViewProject(di, V3d_XposYnegZpos);
1923 //==============================================================================
1925 //purpose : Switch to a Top View
1926 //Draw arg : No args
1927 //==============================================================================
1929 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1931 return ViewProject(di, V3d_Zpos);
1934 //==============================================================================
1935 //function : VBottom
1936 //purpose : Switch to a Bottom View
1937 //Draw arg : No args
1938 //==============================================================================
1940 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1942 return ViewProject(di, V3d_Zneg);
1945 //==============================================================================
1947 //purpose : Switch to a Left View
1948 //Draw arg : No args
1949 //==============================================================================
1951 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1953 return ViewProject(di, V3d_Xneg);
1956 //==============================================================================
1958 //purpose : Switch to a Right View
1959 //Draw arg : No args
1960 //==============================================================================
1962 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1964 return ViewProject(di, V3d_Xpos);
1967 //==============================================================================
1969 //purpose : Switch to a Front View
1970 //Draw arg : No args
1971 //==============================================================================
1973 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1975 return ViewProject(di, V3d_Yneg);
1978 //==============================================================================
1980 //purpose : Switch to a Back View
1981 //Draw arg : No args
1982 //==============================================================================
1984 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1986 return ViewProject(di, V3d_Ypos);
1989 //==============================================================================
1991 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1992 //Draw arg : No args
1993 //==============================================================================
1995 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1998 di << "Q : Quit the application\n";
2000 di << "=========================\n";
2001 di << "F : FitAll\n";
2002 di << "T : TopView\n";
2003 di << "B : BottomView\n";
2004 di << "R : RightView\n";
2005 di << "L : LeftView\n";
2006 di << "A : AxonometricView\n";
2007 di << "D : ResetView\n";
2009 di << "=========================\n";
2010 di << "S : Shading\n";
2011 di << "W : Wireframe\n";
2012 di << "H : HidelLineRemoval\n";
2013 di << "U : Unset display mode\n";
2014 di << "Delete : Remove selection from viewer\n";
2016 di << "=========================\n";
2017 di << "Selection mode \n";
2018 di << "0 : Shape\n";
2019 di << "1 : Vertex\n";
2023 di << "5 : Shell\n";
2024 di << "6 : Solid\n";
2025 di << "7 : Compound\n";
2027 di << "=========================\n";
2028 di << "Z : Switch Z clipping On/Off\n";
2029 di << ", : Hilight next detected\n";
2030 di << ". : Hilight previous detected\n";
2037 static Standard_Boolean Ppick = 0;
2038 static Standard_Integer Pargc = 0;
2039 static const char** Pargv = NULL;
2042 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
2047 if (!ViewerTest_myViews.IsEmpty()) {
2049 WPARAM fwKeys = wParam;
2054 // Delete view from map of views
2055 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
2060 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
2061 || ViewerTest::CurrentView().IsNull())
2063 // Activate inactive window
2064 if(GetWindowHandle(VT_GetWindow()) != hwnd)
2066 ActivateView (FindViewIdByWindowHandle(hwnd));
2072 if (IsDragged && !DragFirst)
2074 if (!GetActiveAISManipulator().IsNull())
2076 GetActiveAISManipulator()->StopTransform();
2077 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
2080 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2082 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2083 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2086 VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0);
2088 IsDragged = Standard_False;
2089 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2092 if (IsDragged && !DragFirst)
2094 if (!GetActiveAISManipulator().IsNull())
2096 GetActiveAISManipulator()->StopTransform (Standard_False);
2097 ViewerTest::GetAISContext()->ClearSelected (Standard_True);
2099 IsDragged = Standard_False;
2101 return ViewerWindowProc (hwnd, Msg, wParam, lParam);
2103 case WM_LBUTTONDOWN:
2104 if (!GetActiveAISManipulator().IsNull())
2106 IsDragged = ( fwKeys == MK_LBUTTON );
2110 IsDragged = ( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) );
2115 DragFirst = Standard_True;
2116 X_ButtonPress = LOWORD(lParam);
2117 Y_ButtonPress = HIWORD(lParam);
2119 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2124 X_Motion = LOWORD (lParam);
2125 Y_Motion = HIWORD (lParam);
2126 if (!GetActiveAISManipulator().IsNull())
2130 GetActiveAISManipulator()->StartTransform (X_ButtonPress, Y_ButtonPress, ViewerTest::CurrentView());
2134 GetActiveAISManipulator()->Transform (X_Motion, Y_Motion, ViewerTest::CurrentView());
2135 ViewerTest::GetAISContext()->CurrentViewer()->Redraw();
2140 bool toRedraw = false;
2141 if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2143 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2148 if (GetClientRect (hwnd, &aRect))
2150 int aHeight = aRect.bottom - aRect.top;
2151 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2152 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed);
2157 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2161 DragFirst = Standard_False;
2164 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2168 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2172 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2176 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
2182 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2185 return DefWindowProcW (hwnd, Msg, wParam, lParam);
2192 BeginPaint(hwnd, &ps);
2193 EndPaint(hwnd, &ps);
2198 VT_ProcessConfigure();
2203 switch (aView->RenderingParams().StereoMode)
2205 case Graphic3d_StereoMode_RowInterlaced:
2206 case Graphic3d_StereoMode_ColumnInterlaced:
2207 case Graphic3d_StereoMode_ChessBoard:
2208 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2216 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2219 c[0] = (char) wParam;
2221 if (wParam == VK_DELETE)
2223 c[0] = THE_KEY_DELETE;
2225 else if (wParam == VK_ESCAPE)
2227 c[0] = THE_KEY_ESCAPE;
2230 else if (wParam == VK_OEM_COMMA)
2235 else if (wParam == VK_OEM_PERIOD)
2239 else if (wParam == VK_DIVIDE)
2244 else if (wParam == VK_MULTIPLY)
2248 VT_ProcessKeyPress (c);
2256 VT_ProcessButton3Release();
2259 case WM_LBUTTONDOWN:
2260 case WM_MBUTTONDOWN:
2261 case WM_RBUTTONDOWN:
2263 WPARAM fwKeys = wParam;
2267 X_ButtonPress = LOWORD(lParam);
2268 Y_ButtonPress = HIWORD(lParam);
2270 if (Msg == WM_LBUTTONDOWN)
2272 if ((fwKeys & MK_CONTROL) != 0)
2274 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2278 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2281 else if (Msg == WM_RBUTTONDOWN)
2284 VT_ProcessButton3Press();
2291 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2292 if (wParam & MK_CONTROL)
2294 if (aView->Camera()->IsStereo())
2296 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2300 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2307 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2314 //cout << "\t WM_MOUSEMOVE" << endl;
2315 WPARAM fwKeys = wParam;
2316 X_Motion = LOWORD(lParam);
2317 Y_Motion = HIWORD(lParam);
2320 (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 )
2323 X_ButtonPress = LOWORD(lParam);
2324 Y_ButtonPress = HIWORD(lParam);
2326 if ((fwKeys & MK_RBUTTON) != 0) {
2328 VT_ProcessButton3Press();
2332 if ((fwKeys & MK_CONTROL) != 0)
2334 if ((fwKeys & MK_LBUTTON) != 0)
2336 ProcessControlButton1Motion();
2338 else if ((fwKeys & MK_MBUTTON) != 0
2339 || ((fwKeys & MK_LBUTTON) != 0
2340 && (fwKeys & MK_RBUTTON) != 0))
2342 VT_ProcessControlButton2Motion();
2344 else if ((fwKeys & MK_RBUTTON) != 0)
2346 VT_ProcessControlButton3Motion();
2349 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2357 return DefWindowProcW (hwnd, Msg, wParam, lParam);
2362 //==============================================================================
2363 //function : ViewerMainLoop
2364 //purpose : Get a Event on the view and dispatch it
2365 //==============================================================================
2368 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2370 Ppick = (argc > 0)? 1 : 0;
2378 cout << "Start picking" << endl;
2380 while ( Ppick == 1 ) {
2381 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2382 if (GetMessageW (&msg, NULL, 0, 0))
2384 TranslateMessage (&msg);
2385 DispatchMessageW (&msg);
2389 cout << "Picking done" << endl;
2395 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2397 int min( int a, int b )
2405 int max( int a, int b )
2413 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2416 static XEvent aReport;
2417 Standard_Boolean pick = argc > 0;
2418 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2419 XNextEvent (aDisplay, &aReport);
2421 // Handle event for the chosen display connection
2422 switch (aReport.type) {
2425 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2428 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2434 // Activate inactive view
2435 Window aWindow = GetWindowHandle(VT_GetWindow());
2436 if(aWindow != aReport.xfocus.window)
2438 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2447 case ConfigureNotify:
2449 VT_ProcessConfigure();
2458 XComposeStatus status_in_out;
2460 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2461 (char *) buf_ret , 10 ,
2462 &ks_ret , &status_in_out ) ;
2465 buf_ret[ret_len] = '\0' ;
2469 VT_ProcessKeyPress (buf_ret);
2475 X_ButtonPress = aReport.xbutton.x;
2476 Y_ButtonPress = aReport.xbutton.y;
2478 if (aReport.xbutton.button == Button1)
2480 if (aReport.xbutton.state & ControlMask)
2482 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2486 IsDragged = Standard_True;
2487 DragFirst = Standard_True;
2490 else if (aReport.xbutton.button == Button3)
2493 VT_ProcessButton3Press();
2503 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2505 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2506 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2510 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2511 if( aContext.IsNull() )
2513 cout << "The context is null. Please use vinit before createmesh" << endl;
2517 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2518 if( aReport.xbutton.button==1 )
2522 aContext->ShiftSelect (Standard_True);
2526 aContext->Select (Standard_True);
2531 aContext->ShiftSelect(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2532 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2533 ViewerTest::CurrentView(), Standard_True);
2537 aContext->Select(Min(X_ButtonPress, X_Motion), Min(Y_ButtonPress, Y_Motion),
2538 Max(X_ButtonPress, X_Motion), Max(Y_ButtonPress, Y_Motion),
2539 ViewerTest::CurrentView(), Standard_True);
2542 VT_ProcessButton3Release();
2544 IsDragged = Standard_False;
2547 VT_ProcessButton3Release();
2552 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2560 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2562 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2566 X_Motion = aReport.xmotion.x;
2567 Y_Motion = aReport.xmotion.y;
2568 DragFirst = Standard_False;
2570 Window aWindow = GetWindowHandle(VT_GetWindow());
2573 unsigned int aWidth, aHeight, aBorderWidth, aDepth;
2574 XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth);
2575 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2576 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed);
2577 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2581 X_Motion = aReport.xmotion.x;
2582 Y_Motion = aReport.xmotion.y;
2584 // remove all the ButtonMotionMaskr
2585 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2587 if ( aReport.xmotion.state & ControlMask ) {
2588 if ( aReport.xmotion.state & Button1Mask ) {
2589 ProcessControlButton1Motion();
2591 else if ( aReport.xmotion.state & Button2Mask ) {
2592 VT_ProcessControlButton2Motion();
2594 else if ( aReport.xmotion.state & Button3Mask ) {
2595 VT_ProcessControlButton3Motion();
2609 //==============================================================================
2610 //function : VProcessEvents
2611 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2612 // event in the Viewer window
2613 //==============================================================================
2615 static void VProcessEvents(ClientData,int)
2617 NCollection_Vector<int> anEventNumbers;
2618 // Get number of messages from every display
2619 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2620 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2622 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2624 // Handle events for every display
2625 int anEventIter = 0;
2626 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2627 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2629 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2630 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2632 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2633 int anEventResult = ViewerMainLoop( 0, NULL);
2634 // If window is closed or context was not found finish current event processing loop
2640 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2645 //==============================================================================
2646 //function : OSWindowSetup
2647 //purpose : Setup for the X11 window to be able to cath the event
2648 //==============================================================================
2651 static void OSWindowSetup()
2653 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2656 Window window = VT_GetWindow()->XWindow();
2657 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2658 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2659 XSynchronize(aDisplay, 1);
2661 // X11 : For keyboard on SUN
2663 wmhints.flags = InputHint;
2666 XSetWMHints( aDisplay, window, &wmhints);
2668 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2669 ButtonPressMask | ButtonReleaseMask |
2670 StructureNotifyMask |
2672 Button1MotionMask | Button2MotionMask |
2673 Button3MotionMask | FocusChangeMask
2675 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2676 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2678 XSynchronize(aDisplay, 0);
2686 //==============================================================================
2689 //==============================================================================
2691 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
2693 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2696 std::cout << "Error: no active viewer!\n";
2700 Standard_Boolean toFit = Standard_True;
2701 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2702 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2704 TCollection_AsciiString anArg (theArgv[anArgIter]);
2706 if (anUpdateTool.parseRedrawMode (anArg))
2710 else if (anArg == "-selected")
2712 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
2713 toFit = Standard_False;
2717 std::cout << "Syntax error at '" << anArg << "'\n";
2723 aView->FitAll (0.01, Standard_False);
2728 //=======================================================================
2729 //function : VFitArea
2730 //purpose : Fit view to show area located between two points
2731 // : given in world 2D or 3D coordinates.
2732 //=======================================================================
2733 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2735 Handle(V3d_View) aView = ViewerTest::CurrentView();
2738 std::cerr << theArgVec[0] << "Error: No active view.\n";
2743 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2744 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2748 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2749 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2750 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2751 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2753 else if (theArgNb == 7)
2755 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2756 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2757 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2758 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2759 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2760 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2764 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2765 theDI.PrintHelp(theArgVec[0]);
2769 // Convert model coordinates to view space
2770 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2771 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2772 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2774 // Determine fit area
2775 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2776 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2778 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2780 if (aDiagonal < Precision::Confusion())
2782 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2786 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2790 //==============================================================================
2792 //purpose : ZFitall, no DRAW arguments
2793 //Draw arg : No args
2794 //==============================================================================
2795 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2797 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2799 if (aCurrentView.IsNull())
2801 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2807 aCurrentView->ZFitAll();
2808 aCurrentView->Redraw();
2812 Standard_Real aScale = 1.0;
2816 aScale = Draw::Atoi (theArgVec[1]);
2819 aCurrentView->ZFitAll (aScale);
2820 aCurrentView->Redraw();
2825 //==============================================================================
2826 //function : VRepaint
2828 //==============================================================================
2829 static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
2831 Handle(V3d_View) aView = ViewerTest::CurrentView();
2834 std::cout << "Error: no active viewer!\n";
2838 Standard_Boolean isImmediateUpdate = Standard_False;
2839 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2841 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2843 if (anArg == "-immediate")
2845 isImmediateUpdate = Standard_True;
2846 if (anArgIter + 1 < theArgNb
2847 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
2854 std::cout << "Syntax error at '" << anArg << "'\n";
2858 if (isImmediateUpdate)
2860 aView->RedrawImmediate();
2869 //==============================================================================
2871 //purpose : Remove all the object from the viewer
2872 //Draw arg : No args
2873 //==============================================================================
2875 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2877 Handle(V3d_View) V = ViewerTest::CurrentView();
2879 ViewerTest::Clear();
2883 //==============================================================================
2886 //==============================================================================
2888 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2889 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2892 di << argv[0] << "Invalid number of arguments\n";
2896 while (ViewerMainLoop( argc, argv)) {
2902 //==============================================================================
2904 //purpose : Load image as background
2905 //==============================================================================
2907 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2909 if (argc < 2 || argc > 3)
2911 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n";
2912 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n";
2916 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2917 if(AISContext.IsNull())
2919 di << "use 'vinit' command before " << argv[0] << "\n";
2923 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2926 const char* szType = argv[2];
2927 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2928 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2929 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2930 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2933 di << "Wrong fill type : " << szType << "\n";
2934 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
2939 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2940 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2945 //==============================================================================
2946 //function : VSetBgMode
2947 //purpose : Change background image fill type
2948 //==============================================================================
2950 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2954 di << "Usage : " << argv[0] << " filltype : Change background image mode\n";
2955 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n";
2959 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2960 if(AISContext.IsNull())
2962 di << "use 'vinit' command before " << argv[0] << "\n";
2965 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2966 const char* szType = argv[1];
2967 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2968 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2969 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2970 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2973 di << "Wrong fill type : " << szType << "\n";
2974 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
2977 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2978 V3dView->SetBgImageStyle(aFillType, Standard_True);
2982 //==============================================================================
2983 //function : VSetGradientBg
2984 //purpose : Mount gradient background
2985 //==============================================================================
2986 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2990 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background\n";
2991 di << "R1,G1,B1,R2,G2,B2 = [0..255]\n";
2992 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2993 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
2997 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2998 if(AISContext.IsNull())
3000 di << "use 'vinit' command before " << argv[0] << "\n";
3006 Standard_Real R1 = Draw::Atof(argv[1])/255.;
3007 Standard_Real G1 = Draw::Atof(argv[2])/255.;
3008 Standard_Real B1 = Draw::Atof(argv[3])/255.;
3009 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
3011 Standard_Real R2 = Draw::Atof(argv[4])/255.;
3012 Standard_Real G2 = Draw::Atof(argv[5])/255.;
3013 Standard_Real B2 = Draw::Atof(argv[6])/255.;
3015 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
3016 int aType = Draw::Atoi(argv[7]);
3017 if( aType < 0 || aType > 8 )
3019 di << "Wrong fill type \n";
3020 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3021 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3025 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
3027 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3028 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
3034 //==============================================================================
3035 //function : VSetGradientBgMode
3036 //purpose : Change gradient background fill style
3037 //==============================================================================
3038 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3042 di << "Usage : " << argv[0] << " Type : Change gradient background fill type\n";
3043 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3044 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3048 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3049 if(AISContext.IsNull())
3051 di << "use 'vinit' command before " << argv[0] << "\n";
3056 int aType = Draw::Atoi(argv[1]);
3057 if( aType < 0 || aType > 8 )
3059 di << "Wrong fill type \n";
3060 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
3061 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
3065 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
3067 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3068 V3dView->SetBgGradientStyle( aMethod, 1 );
3074 //==============================================================================
3075 //function : VSetColorBg
3076 //purpose : Set color background
3077 //==============================================================================
3078 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3082 di << "Usage : " << argv[0] << " R G B : Set color background\n";
3083 di << "R,G,B = [0..255]\n";
3087 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
3088 if(AISContext.IsNull())
3090 di << "use 'vinit' command before " << argv[0] << "\n";
3096 Standard_Real R = Draw::Atof(argv[1])/255.;
3097 Standard_Real G = Draw::Atof(argv[2])/255.;
3098 Standard_Real B = Draw::Atof(argv[3])/255.;
3099 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
3101 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3102 V3dView->SetBackgroundColor( aColor );
3109 //==============================================================================
3110 //function : VSetDefaultBg
3111 //purpose : Set default viewer background fill color
3112 //==============================================================================
3113 static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
3118 std::cout << "Error: wrong syntax! See usage:\n";
3119 theDI.PrintHelp (theArgVec[0]);
3123 ViewerTest_DefaultBackground.FillMethod =
3124 theArgNb == 4 ? Aspect_GFM_NONE
3125 : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]);
3129 Standard_Real R = Draw::Atof (theArgVec[1]) / 255.;
3130 Standard_Real G = Draw::Atof (theArgVec[2]) / 255.;
3131 Standard_Real B = Draw::Atof (theArgVec[3]) / 255.;
3132 ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB);
3136 Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.;
3137 Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.;
3138 Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.;
3139 ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB);
3141 Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.;
3142 Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.;
3143 Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.;
3144 ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB);
3147 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
3148 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
3150 const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer();
3151 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
3152 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
3153 ViewerTest_DefaultBackground.GradientColor2,
3154 ViewerTest_DefaultBackground.FillMethod);
3160 //==============================================================================
3162 //purpose : View Scaling
3163 //==============================================================================
3165 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3167 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3168 if ( V3dView.IsNull() ) return 1;
3171 di << argv[0] << "Invalid number of arguments\n";
3174 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
3177 //==============================================================================
3178 //function : VZBuffTrihedron
3180 //==============================================================================
3182 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
3183 Standard_Integer theArgNb,
3184 const char** theArgVec)
3186 Handle(V3d_View) aView = ViewerTest::CurrentView();
3189 std::cout << "Error: no active viewer!\n";
3193 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
3195 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
3196 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
3197 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
3198 Quantity_Color anArrowColorX = Quantity_NOC_RED;
3199 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
3200 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
3201 Standard_Real aScale = 0.1;
3202 Standard_Real aSizeRatio = 0.8;
3203 Standard_Real anArrowDiam = 0.05;
3204 Standard_Integer aNbFacets = 12;
3205 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3207 Standard_CString anArg = theArgVec[anArgIter];
3208 TCollection_AsciiString aFlag (anArg);
3210 if (anUpdateTool.parseRedrawMode (aFlag))
3214 else if (aFlag == "-on")
3218 else if (aFlag == "-off")
3220 aView->TriedronErase();
3223 else if (aFlag == "-pos"
3224 || aFlag == "-position"
3225 || aFlag == "-corner")
3227 if (++anArgIter >= theArgNb)
3229 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3233 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3234 aPosName.LowerCase();
3235 if (aPosName == "center")
3237 aPosition = Aspect_TOTP_CENTER;
3239 else if (aPosName == "left_lower"
3240 || aPosName == "lower_left"
3241 || aPosName == "leftlower"
3242 || aPosName == "lowerleft")
3244 aPosition = Aspect_TOTP_LEFT_LOWER;
3246 else if (aPosName == "left_upper"
3247 || aPosName == "upper_left"
3248 || aPosName == "leftupper"
3249 || aPosName == "upperleft")
3251 aPosition = Aspect_TOTP_LEFT_UPPER;
3253 else if (aPosName == "right_lower"
3254 || aPosName == "lower_right"
3255 || aPosName == "rightlower"
3256 || aPosName == "lowerright")
3258 aPosition = Aspect_TOTP_RIGHT_LOWER;
3260 else if (aPosName == "right_upper"
3261 || aPosName == "upper_right"
3262 || aPosName == "rightupper"
3263 || aPosName == "upperright")
3265 aPosition = Aspect_TOTP_RIGHT_UPPER;
3269 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3273 else if (aFlag == "-type")
3275 if (++anArgIter >= theArgNb)
3277 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3281 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3282 aTypeName.LowerCase();
3283 if (aTypeName == "wireframe"
3284 || aTypeName == "wire")
3286 aVisType = V3d_WIREFRAME;
3288 else if (aTypeName == "zbuffer"
3289 || aTypeName == "shaded")
3291 aVisType = V3d_ZBUFFER;
3295 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3298 else if (aFlag == "-scale")
3300 if (++anArgIter >= theArgNb)
3302 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3306 aScale = Draw::Atof (theArgVec[anArgIter]);
3308 else if (aFlag == "-size"
3309 || aFlag == "-sizeratio")
3311 if (++anArgIter >= theArgNb)
3313 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3317 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3319 else if (aFlag == "-arrowdiam"
3320 || aFlag == "-arrowdiameter")
3322 if (++anArgIter >= theArgNb)
3324 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3328 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3330 else if (aFlag == "-nbfacets")
3332 if (++anArgIter >= theArgNb)
3334 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3338 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3340 else if (aFlag == "-colorlabel"
3341 || aFlag == "-colorlabels")
3343 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3344 theArgVec + anArgIter + 1,
3348 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3351 anArgIter += aNbParsed;
3353 else if (aFlag == "-colorarrowx")
3355 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3356 theArgVec + anArgIter + 1,
3360 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3363 anArgIter += aNbParsed;
3365 else if (aFlag == "-colorarrowy")
3367 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3368 theArgVec + anArgIter + 1,
3372 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3375 anArgIter += aNbParsed;
3377 else if (aFlag == "-colorarrowz")
3379 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3380 theArgVec + anArgIter + 1,
3384 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3387 anArgIter += aNbParsed;
3391 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3396 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3397 aSizeRatio, anArrowDiam, aNbFacets);
3398 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
3403 //==============================================================================
3404 //function : VRotate
3405 //purpose : Camera Rotating
3406 //==============================================================================
3408 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3410 Handle(V3d_View) aView = ViewerTest::CurrentView();
3413 std::cout << "No active view!\n";
3417 Standard_Boolean hasFlags = Standard_False;
3418 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3420 Standard_CString anArg (theArgVec[anArgIter]);
3421 TCollection_AsciiString aFlag (anArg);
3423 if (aFlag == "-mousestart"
3424 || aFlag == "-mousefrom")
3426 hasFlags = Standard_True;
3427 if (anArgIter + 2 >= theArgNb)
3429 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3433 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3434 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3435 aView->StartRotation (anX, anY);
3437 else if (aFlag == "-mousemove")
3439 hasFlags = Standard_True;
3440 if (anArgIter + 2 >= theArgNb)
3442 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3446 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3447 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3448 aView->Rotation (anX, anY);
3450 else if (theArgNb != 4
3453 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3462 else if (theArgNb == 4)
3464 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3465 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3466 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3467 aView->Rotate (anAX, anAY, anAZ);
3470 else if (theArgNb == 7)
3472 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3473 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3474 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3476 Standard_Real anX = Draw::Atof (theArgVec[4]);
3477 Standard_Real anY = Draw::Atof (theArgVec[5]);
3478 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3480 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3484 std::cout << "Error: Invalid number of arguments\n";
3488 //==============================================================================
3490 //purpose : View zoom in / out (relative to current zoom)
3491 //==============================================================================
3493 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3494 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3495 if ( V3dView.IsNull() ) {
3500 Standard_Real coef = Draw::Atof(argv[1]);
3501 if ( coef <= 0.0 ) {
3502 di << argv[1] << "Invalid value\n";
3505 V3dView->SetZoom( Draw::Atof(argv[1]) );
3508 di << argv[0] << " Invalid number of arguments\n";
3513 //==============================================================================
3515 //purpose : View panning (in pixels)
3516 //==============================================================================
3518 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3519 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3520 if ( V3dView.IsNull() ) return 1;
3523 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
3526 di << argv[0] << " Invalid number of arguments\n";
3531 //==============================================================================
3533 //purpose : Place the point (in pixels) at the center of the window
3534 //==============================================================================
3535 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3537 Handle(V3d_View) aView = ViewerTest::CurrentView();
3540 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3546 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3550 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3555 //==============================================================================
3556 //function : VExport
3557 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
3558 //==============================================================================
3560 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3562 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3563 if (V3dView.IsNull())
3568 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
3572 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
3573 TCollection_AsciiString aFormatStr;
3575 TCollection_AsciiString aFileName (argv[1]);
3576 Standard_Integer aLen = aFileName.Length();
3580 aFormatStr = TCollection_AsciiString (argv[2]);
3584 if (aFileName.Value (aLen - 2) == '.')
3586 aFormatStr = aFileName.ToCString() + aLen - 2;
3588 else if (aFileName.Value (aLen - 3) == '.')
3590 aFormatStr = aFileName.ToCString() + aLen - 3;
3594 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3600 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3604 aFormatStr.UpperCase();
3605 if (aFormatStr == "PS")
3606 anExpFormat = Graphic3d_EF_PostScript;
3607 else if (aFormatStr == "EPS")
3608 anExpFormat = Graphic3d_EF_EnhPostScript;
3609 else if (aFormatStr == "TEX")
3610 anExpFormat = Graphic3d_EF_TEX;
3611 else if (aFormatStr == "PDF")
3612 anExpFormat = Graphic3d_EF_PDF;
3613 else if (aFormatStr == "SVG")
3614 anExpFormat = Graphic3d_EF_SVG;
3615 else if (aFormatStr == "PGF")
3616 anExpFormat = Graphic3d_EF_PGF;
3617 else if (aFormatStr == "EMF")
3618 anExpFormat = Graphic3d_EF_EMF;
3621 std::cout << "Invalid export format '" << aFormatStr << "'\n";
3625 Standard_DISABLE_DEPRECATION_WARNINGS
3628 if (!V3dView->Export (argv[1], anExpFormat))
3630 di << "Error: export of image to " << aFormatStr << " failed!\n";
3633 catch (Standard_Failure const& anException)
3635 di << "Error: export of image to " << aFormatStr << " failed";
3636 di << " (exception: " << anException.GetMessageString() << ")";
3638 Standard_ENABLE_DEPRECATION_WARNINGS
3642 static int VColorScale (Draw_Interpretor& theDI,
3643 Standard_Integer theArgNb,
3644 const char** theArgVec)
3646 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3647 Handle(V3d_View) aView = ViewerTest::CurrentView();
3648 if (aContext.IsNull())
3650 std::cout << "Error: no active view!\n";
3655 std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n";
3659 Handle(AIS_ColorScale) aColorScale;
3660 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
3662 // find existing object
3663 aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
3664 if (aColorScale.IsNull())
3666 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
3673 if (aColorScale.IsNull())
3675 std::cout << "Syntax error: colorscale with a given name does not exist.\n";
3679 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
3680 << "Min range: " << aColorScale->GetMin() << "\n"
3681 << "Max range: " << aColorScale->GetMax() << "\n"
3682 << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n"
3683 << "Text height: " << aColorScale->GetTextHeight() << "\n"
3684 << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n"
3685 << "Color scale title: " << aColorScale->GetTitle() << "\n"
3686 << "Label position: ";
3687 switch (aColorScale->GetLabelPosition())
3689 case Aspect_TOCSP_NONE:
3692 case Aspect_TOCSP_LEFT:
3695 case Aspect_TOCSP_RIGHT:
3698 case Aspect_TOCSP_CENTER:
3699 theDI << "Center\n";
3705 if (aColorScale.IsNull())
3707 aColorScale = new AIS_ColorScale();
3708 aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
3709 aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
3712 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
3713 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
3715 Standard_CString anArg = theArgVec[anArgIter];
3716 TCollection_AsciiString aFlag (anArg);
3718 if (anUpdateTool.parseRedrawMode (aFlag))
3722 else if (aFlag == "-range")
3724 if (anArgIter + 3 >= theArgNb)
3726 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3730 const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]);
3731 const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]);
3732 const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]);
3733 if (!aRangeMin.IsRealValue()
3734 || !aRangeMax.IsRealValue())
3736 std::cout << "Error: the range values should be real!\n";
3739 else if (!aNbIntervals.IsIntegerValue())
3741 std::cout << "Error: the number of intervals should be integer!\n";
3745 aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue());
3746 aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue());
3748 else if (aFlag == "-font")
3750 if (anArgIter + 1 >= theArgNb)
3752 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3755 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
3756 if (!aFontArg.IsIntegerValue())
3758 std::cout << "Error: HeightFont value should be integer!\n";
3762 aColorScale->SetTextHeight (aFontArg.IntegerValue());
3765 else if (aFlag == "-textpos")
3767 if (anArgIter + 1 >= theArgNb)
3769 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3773 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
3774 aTextPosArg.LowerCase();
3775 Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE;
3776 if (aTextPosArg == "none")
3778 aLabPosition = Aspect_TOCSP_NONE;
3780 else if (aTextPosArg == "left")
3782 aLabPosition = Aspect_TOCSP_LEFT;
3784 else if (aTextPosArg == "right")
3786 aLabPosition = Aspect_TOCSP_RIGHT;
3788 else if (aTextPosArg == "center")
3790 aLabPosition = Aspect_TOCSP_CENTER;
3794 std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
3797 aColorScale->SetLabelPosition (aLabPosition);
3799 else if (aFlag == "-logarithmic"
3802 if (anArgIter + 1 >= theArgNb)
3804 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3808 Standard_Boolean IsLog;
3809 if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
3811 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3814 aColorScale->SetLogarithmic (IsLog);
3816 else if (aFlag == "-huerange"
3819 if (anArgIter + 2 >= theArgNb)
3821 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3825 const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]);
3826 const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]);
3827 aColorScale->SetHueRange (aHueMin, aHueMax);
3829 else if (aFlag == "-colorrange")
3831 Quantity_Color aColorMin, aColorMax;
3832 Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3833 theArgVec + (anArgIter + 1),
3835 anArgIter += aNbParsed1;
3836 Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3837 theArgVec + (anArgIter + 1),
3839 anArgIter += aNbParsed2;
3843 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3847 aColorScale->SetColorRange (aColorMin, aColorMax);
3849 else if (aFlag == "-reversed"
3850 || aFlag == "-inverted"
3851 || aFlag == "-topdown"
3852 || aFlag == "-bottomup")
3854 Standard_Boolean toEnable = Standard_True;
3855 if (anArgIter + 1 < theArgNb
3856 && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable))
3860 aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable);
3862 else if (aFlag == "-smooth"
3863 || aFlag == "-smoothtransition")
3865 Standard_Boolean toEnable = Standard_True;
3866 if (anArgIter + 1 < theArgNb
3867 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
3871 aColorScale->SetSmoothTransition (toEnable);
3873 else if (aFlag == "-xy")
3875 if (anArgIter + 2 >= theArgNb)
3877 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3881 const TCollection_AsciiString anX (theArgVec[++anArgIter]);
3882 const TCollection_AsciiString anY (theArgVec[++anArgIter]);
3883 if (!anX.IsIntegerValue()
3884 || !anY.IsIntegerValue())
3886 std::cout << "Error: coordinates should be integer values!\n";
3890 aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue());
3892 else if (aFlag == "-width"
3894 || aFlag == "-breadth")
3896 if (anArgIter + 1 >= theArgNb)
3898 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3902 const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]);
3903 if (!aBreadth.IsIntegerValue())
3905 std::cout << "Error: a width should be an integer value!\n";
3908 aColorScale->SetBreadth (aBreadth.IntegerValue());
3910 else if (aFlag == "-height"
3913 if (anArgIter + 1 >= theArgNb)
3915 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3919 const TCollection_AsciiString aHeight (theArgVec[++anArgIter]);
3920 if (!aHeight.IsIntegerValue())
3922 std::cout << "Error: a width should be an integer value!\n";
3925 aColorScale->SetHeight (aHeight.IntegerValue());
3927 else if (aFlag == "-color")
3929 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
3931 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3934 else if (anArgIter + 2 >= theArgNb)
3936 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3940 const TCollection_AsciiString anInd (theArgVec[++anArgIter]);
3941 if (!anInd.IsIntegerValue())
3943 std::cout << "Error: Index value should be integer!\n";
3946 const Standard_Integer anIndex = anInd.IntegerValue();
3947 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals())
3949 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() <<"!\n";
3953 Quantity_Color aColor;
3954 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3955 theArgVec + (anArgIter + 1),
3959 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3962 aColorScale->SetIntervalColor (aColor, anIndex);
3963 aColorScale->SetColorType (Aspect_TOCSD_USER);
3964 anArgIter += aNbParsed;
3966 else if (aFlag == "-label")
3968 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
3970 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
3973 else if (anArgIter + 2 >= theArgNb)
3975 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3979 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
3980 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1)
3982 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() + 1 <<"!\n";
3986 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
3987 aColorScale->SetLabel (aText, anIndex);
3988 aColorScale->SetLabelType (Aspect_TOCSD_USER);
3991 else if (aFlag == "-labelat"
3992 || aFlag == "-labat"
3993 || aFlag == "-labelatborder"
3994 || aFlag == "-labatborder"
3995 || aFlag == "-labelatcenter"
3996 || aFlag == "-labatcenter")
3998 Standard_Boolean toEnable = Standard_True;
3999 if (aFlag == "-labelat"
4000 || aFlag == "-labat")
4002 Standard_Integer aLabAtBorder = -1;
4003 if (++anArgIter >= theArgNb)
4005 TCollection_AsciiString anAtBorder (theArgVec[anArgIter]);
4006 anAtBorder.LowerCase();
4007 if (anAtBorder == "border")
4011 else if (anAtBorder == "center")
4016 if (aLabAtBorder == -1)
4018 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4021 toEnable = (aLabAtBorder == 1);
4023 else if (anArgIter + 1 < theArgNb
4024 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
4028 aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter"
4029 || aFlag == "-labatcenter"
4033 else if (aFlag == "-colors")
4035 Aspect_SequenceOfColor aSeq;
4038 Quantity_Color aColor;
4039 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
4040 theArgVec + (anArgIter + 1),
4046 anArgIter += aNbParsed;
4047 aSeq.Append (aColor);
4049 if (aSeq.Length() != aColorScale->GetNumberOfIntervals())
4051 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
4052 << aColorScale->GetNumberOfIntervals() << " intervals\n";
4056 aColorScale->SetColors (aSeq);
4057 aColorScale->SetColorType (Aspect_TOCSD_USER);
4059 else if (aFlag == "-labels"
4060 || aFlag == "-freelabels")
4062 if (anArgIter + 1 >= theArgNb)
4064 std::cout << "Syntax error at argument '" << anArg << "'!\n";
4068 Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder()
4069 ? aColorScale->GetNumberOfIntervals() + 1
4070 : aColorScale->GetNumberOfIntervals();
4071 if (aFlag == "-freelabels")
4074 aNbLabels = Draw::Atoi (theArgVec[anArgIter]);
4076 if (anArgIter + aNbLabels >= theArgNb)
4078 std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n";
4082 TColStd_SequenceOfExtendedString aSeq;
4083 for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter)
4085 aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter]));
4087 aColorScale->SetLabels (aSeq);
4088 aColorScale->SetLabelType (Aspect_TOCSD_USER);
4090 else if (aFlag == "-title")
4092 if (anArgIter + 1 >= theArgNb)
4094 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4098 Standard_Boolean isTwoArgs = Standard_False;
4099 if (anArgIter + 2 < theArgNb)
4101 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
4102 aSecondArg.LowerCase();
4103 Standard_DISABLE_DEPRECATION_WARNINGS
4104 if (aSecondArg == "none")
4106 aColorScale->SetTitlePosition (Aspect_TOCSP_NONE);
4107 isTwoArgs = Standard_True;
4109 else if (aSecondArg == "left")
4111 aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT);
4112 isTwoArgs = Standard_True;
4114 else if (aSecondArg == "right")
4116 aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT);
4117 isTwoArgs = Standard_True;
4119 else if (aSecondArg == "center")
4121 aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER);
4122 isTwoArgs = Standard_True;
4124 Standard_ENABLE_DEPRECATION_WARNINGS
4127 aColorScale->SetTitle (theArgVec[anArgIter + 1]);
4134 else if (aFlag == "-demoversion"
4135 || aFlag == "-demo")
4137 aColorScale->SetPosition (0, 0);
4138 aColorScale->SetTextHeight (16);
4139 aColorScale->SetRange (0.0, 100.0);
4140 aColorScale->SetNumberOfIntervals (10);
4141 aColorScale->SetBreadth (0);
4142 aColorScale->SetHeight (0);
4143 aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT);
4144 aColorScale->SetColorType (Aspect_TOCSD_AUTO);
4145 aColorScale->SetLabelType (Aspect_TOCSD_AUTO);
4147 else if (aFlag == "-findcolor")
4149 if (anArgIter + 1 >= theArgNb)
4151 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
4155 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
4157 if (!anArg1.IsRealValue())
4159 std::cout << "Error: the value should be real!\n";
4163 Quantity_Color aColor;
4164 aColorScale->FindColor (anArg1.RealValue(), aColor);
4165 theDI << Quantity_Color::StringName (aColor.Name());
4170 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
4175 Standard_Integer aWinWidth = 0, aWinHeight = 0;
4176 aView->Window()->Size (aWinWidth, aWinHeight);
4177 if (aColorScale->GetBreadth() == 0)
4179 aColorScale->SetBreadth (aWinWidth);
4181 if (aColorScale->GetHeight() == 0)
4183 aColorScale->SetHeight (aWinHeight);
4185 aColorScale->SetToUpdate();
4186 ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True);
4190 //==============================================================================
4191 //function : VGraduatedTrihedron
4192 //purpose : Displays or hides a graduated trihedron
4193 //==============================================================================
4194 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
4195 Quantity_Color& theColor)
4197 Quantity_NameOfColor aColorName;
4198 TCollection_AsciiString aVal = theValue;
4200 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
4202 return Standard_False;
4204 theColor = Quantity_Color (aColorName);
4205 return Standard_True;
4208 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
4212 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
4213 << theArgs[0] <<"' for more information.\n";
4214 return 1; //TCL_ERROR
4217 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
4218 TCollection_AsciiString aParseKey;
4219 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
4221 TCollection_AsciiString anArg (theArgs [anArgIt]);
4223 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
4226 aParseKey.Remove (1);
4227 aParseKey.LowerCase();
4228 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
4232 if (aParseKey.IsEmpty())
4237 aMapOfArgs(aParseKey)->Append (anArg);
4241 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
4242 aMapIt.More(); aMapIt.Next())
4244 const TCollection_AsciiString& aKey = aMapIt.Key();
4245 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
4247 // Bool key, without arguments
4248 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
4249 && anArgs->IsEmpty())
4255 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
4256 && anArgs->Length() == 1)
4262 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
4263 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
4264 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
4265 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
4266 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
4271 // One string argument
4272 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
4273 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
4274 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4279 // One integer argument
4280 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
4281 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
4282 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
4283 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
4284 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
4289 // One real argument
4290 if ( aKey.IsEqual ("arrowlength")
4291 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
4296 // Two string arguments
4297 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
4298 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4303 TCollection_AsciiString aLowerKey;
4306 aLowerKey.LowerCase();
4307 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
4308 std::cout << "Type help for more information.\n";
4312 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4313 if (anAISContext.IsNull())
4315 std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n";
4319 Standard_Boolean toDisplay = Standard_True;
4320 Quantity_Color aColor;
4321 Graphic3d_GraduatedTrihedron aTrihedronData;
4322 // Process parameters
4323 Handle(TColStd_HSequenceOfAsciiString) aValues;
4324 if (aMapOfArgs.Find ("off", aValues))
4326 toDisplay = Standard_False;
4330 if (aMapOfArgs.Find ("xname", aValues))
4332 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
4334 if (aMapOfArgs.Find ("yname", aValues))
4336 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
4338 if (aMapOfArgs.Find ("zname", aValues))
4340 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
4342 if (aMapOfArgs.Find ("xdrawname", aValues))
4344 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4346 if (aMapOfArgs.Find ("ydrawname", aValues))
4348 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4350 if (aMapOfArgs.Find ("zdrawname", aValues))
4352 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4354 if (aMapOfArgs.Find ("xnameoffset", aValues))
4356 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4358 if (aMapOfArgs.Find ("ynameoffset", aValues))
4360 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4362 if (aMapOfArgs.Find ("znameoffset", aValues))
4364 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4368 if (aMapOfArgs.Find ("xnamecolor", aValues))
4370 if (!GetColor (aValues->Value(1), aColor))
4372 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
4375 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
4377 if (aMapOfArgs.Find ("ynamecolor", aValues))
4379 if (!GetColor (aValues->Value(1), aColor))
4381 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
4384 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
4386 if (aMapOfArgs.Find ("znamecolor", aValues))
4388 if (!GetColor (aValues->Value(1), aColor))
4390 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
4393 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
4395 if (aMapOfArgs.Find ("xcolor", aValues))
4397 if (!GetColor (aValues->Value(1), aColor))
4399 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
4402 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
4404 if (aMapOfArgs.Find ("ycolor", aValues))
4406 if (!GetColor (aValues->Value(1), aColor))
4408 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
4411 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
4413 if (aMapOfArgs.Find ("zcolor", aValues))
4415 if (!GetColor (aValues->Value(1), aColor))
4417 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
4420 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
4424 if (aMapOfArgs.Find ("xticks", aValues))
4426 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4428 if (aMapOfArgs.Find ("yticks", aValues))
4430 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4432 if (aMapOfArgs.Find ("zticks", aValues))
4434 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4436 if (aMapOfArgs.Find ("xticklength", aValues))
4438 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4440 if (aMapOfArgs.Find ("yticklength", aValues))
4442 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4444 if (aMapOfArgs.Find ("zticklength", aValues))
4446 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4448 if (aMapOfArgs.Find ("xdrawticks", aValues))
4450 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4452 if (aMapOfArgs.Find ("ydrawticks", aValues))
4454 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4456 if (aMapOfArgs.Find ("zdrawticks", aValues))
4458 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4462 if (aMapOfArgs.Find ("xdrawvalues", aValues))
4464 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4466 if (aMapOfArgs.Find ("ydrawvalues", aValues))
4468 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4470 if (aMapOfArgs.Find ("zdrawvalues", aValues))
4472 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4474 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
4476 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4478 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
4480 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4482 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
4484 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4488 if (aMapOfArgs.Find ("arrowlength", aValues))
4490 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
4494 if (aMapOfArgs.Find ("namefont", aValues))
4496 aTrihedronData.SetNamesFont (aValues->Value(1));
4498 if (aMapOfArgs.Find ("valuesfont", aValues))
4500 aTrihedronData.SetValuesFont (aValues->Value(1));
4503 if (aMapOfArgs.Find ("drawgrid", aValues))
4505 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
4507 if (aMapOfArgs.Find ("drawaxes", aValues))
4509 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
4512 // The final step: display of erase trihedron
4515 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
4519 ViewerTest::CurrentView()->GraduatedTrihedronErase();
4522 ViewerTest::GetAISContext()->UpdateCurrentViewer();
4523 ViewerTest::CurrentView()->Redraw();
4528 //==============================================================================
4531 //==============================================================================
4532 static int VTile (Draw_Interpretor& theDI,
4533 Standard_Integer theArgNb,
4534 const char** theArgVec)
4536 Handle(V3d_View) aView = ViewerTest::CurrentView();
4539 std::cerr << "Error: no active viewer.\n";
4543 Graphic3d_CameraTile aTile = aView->Camera()->Tile();
4546 theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
4547 << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n"
4548 << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n";
4552 aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
4553 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4555 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4557 if (anArg == "-lowerleft"
4558 || anArg == "-upperleft")
4560 if (anArgIter + 3 < theArgNb)
4562 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4565 aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
4566 aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4567 aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4569 else if (anArg == "-total"
4570 || anArg == "-totalsize"
4571 || anArg == "-viewsize")
4573 if (anArgIter + 3 < theArgNb)
4575 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4578 aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4579 aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4580 if (aTile.TotalSize.x() < 1
4581 || aTile.TotalSize.y() < 1)
4583 std::cerr << "Error: total size is incorrect.\n";
4587 else if (anArg == "-tilesize")
4589 if (anArgIter + 3 < theArgNb)
4591 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4595 aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4596 aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4597 if (aTile.TileSize.x() < 1
4598 || aTile.TileSize.y() < 1)
4600 std::cerr << "Error: tile size is incorrect.\n";
4604 else if (anArg == "-unset")
4606 aView->Camera()->SetTile (Graphic3d_CameraTile());
4612 if (aTile.TileSize.x() < 1
4613 || aTile.TileSize.y() < 1)
4615 std::cerr << "Error: tile size is undefined.\n";
4618 else if (aTile.TotalSize.x() < 1
4619 || aTile.TotalSize.y() < 1)
4621 std::cerr << "Error: total size is undefined.\n";
4625 aView->Camera()->SetTile (aTile);
4630 //! Format ZLayer ID.
4631 inline const char* formZLayerId (const Standard_Integer theLayerId)
4635 case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]";
4636 case Graphic3d_ZLayerId_Default: return "[DEFAULT]";
4637 case Graphic3d_ZLayerId_Top: return "[TOP]";
4638 case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]";
4639 case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]";
4640 case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]";
4645 //! Print the ZLayer information.
4646 inline void printZLayerInfo (Draw_Interpretor& theDI,
4647 const Graphic3d_ZLayerSettings& theLayer)
4649 if (!theLayer.Name().IsEmpty())
4651 theDI << " Name: " << theLayer.Name() << "\n";
4653 if (theLayer.IsImmediate())
4655 theDI << " Immediate: TRUE\n";
4657 theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n";
4658 theDI << " Culling distance: " << theLayer.CullingDistance() << "\n";
4659 theDI << " Culling size: " << theLayer.CullingSize() << "\n";
4660 theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n";
4661 theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n";
4662 theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n";
4663 if (theLayer.PolygonOffset().Mode != Aspect_POM_None)
4665 theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n";
4669 //==============================================================================
4670 //function : VZLayer
4671 //purpose : Test z layer operations for v3d viewer
4672 //==============================================================================
4673 static int VZLayer (Draw_Interpretor& theDI,
4674 Standard_Integer theArgNb,
4675 const char** theArgVec)
4677 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4678 if (aContextAIS.IsNull())
4680 std::cout << "No active viewer!\n";
4684 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
4687 TColStd_SequenceOfInteger aLayers;
4688 aViewer->GetAllZLayers (aLayers);
4689 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4691 theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n";
4692 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4693 printZLayerInfo (theDI, aSettings);
4698 Standard_Integer anArgIter = 1;
4699 Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4700 ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView());
4701 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
4706 TCollection_AsciiString aFirstArg (theArgVec[anArgIter]);
4707 if (aFirstArg.IsIntegerValue())
4710 aLayerId = aFirstArg.IntegerValue();
4714 aFirstArg.LowerCase();
4715 if (aFirstArg == "default"
4716 || aFirstArg == "def")
4718 aLayerId = Graphic3d_ZLayerId_Default;
4721 else if (aFirstArg == "top")
4723 aLayerId = Graphic3d_ZLayerId_Top;
4726 else if (aFirstArg == "topmost")
4728 aLayerId = Graphic3d_ZLayerId_Topmost;
4731 else if (aFirstArg == "overlay"
4732 || aFirstArg == "toposd")
4734 aLayerId = Graphic3d_ZLayerId_TopOSD;
4737 else if (aFirstArg == "underlay"
4738 || aFirstArg == "botosd")
4740 aLayerId = Graphic3d_ZLayerId_BotOSD;
4745 TColStd_SequenceOfInteger aLayers;
4746 aViewer->GetAllZLayers (aLayers);
4747 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4749 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4750 if (TCollection_AsciiString::IsSameString (aSettings.Name(), aFirstArg, Standard_False))
4752 aLayerId = aLayeriter.Value();
4760 for (; anArgIter < theArgNb; ++anArgIter)
4762 // perform operation
4763 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4765 if (anUpdateTool.parseRedrawMode (anArg))
4769 else if (anArg == "-add"
4772 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4773 if (!aViewer->AddZLayer (aLayerId))
4775 std::cout << "Error: can not add a new z layer!\n";
4781 else if (anArg == "-del"
4782 || anArg == "-delete"
4785 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4787 if (++anArgIter >= theArgNb)
4789 std::cout << "Syntax error: id of z layer to remove is missing\n";
4793 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4796 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN
4797 || aLayerId == Graphic3d_ZLayerId_Default
4798 || aLayerId == Graphic3d_ZLayerId_Top
4799 || aLayerId == Graphic3d_ZLayerId_Topmost
4800 || aLayerId == Graphic3d_ZLayerId_TopOSD
4801 || aLayerId == Graphic3d_ZLayerId_BotOSD)
4803 std::cout << "Syntax error: standard Z layer can not be removed\n";
4807 // move all object displayed in removing layer to default layer
4808 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4809 anObjIter.More(); anObjIter.Next())
4811 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1());
4813 || aPrs->ZLayer() != aLayerId)
4817 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4820 if (!aViewer->RemoveZLayer (aLayerId))
4822 std::cout << "Z layer can not be removed!\n";
4826 theDI << aLayerId << " ";
4829 else if (anArg == "-get"
4832 TColStd_SequenceOfInteger aLayers;
4833 aViewer->GetAllZLayers (aLayers);
4834 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4836 theDI << aLayeriter.Value() << " ";
4841 else if (anArg == "-name")
4843 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4845 std::cout << "Syntax error: id of Z layer is missing\n";
4849 if (++anArgIter >= theArgNb)
4851 std::cout << "Syntax error: name is missing\n";
4855 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4856 aSettings.SetName (theArgVec[anArgIter]);
4857 aViewer->SetZLayerSettings (aLayerId, aSettings);
4859 else if (anArg == "-origin")
4861 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4863 std::cout << "Syntax error: id of Z layer is missing\n";
4867 if (anArgIter + 2 >= theArgNb)
4869 std::cout << "Syntax error: origin coordinates are missing\n";
4873 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4875 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1]));
4876 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2]));
4877 anOrigin.SetZ (0.0);
4878 if (anArgIter + 3 < theArgNb)
4880 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3]));
4887 aSettings.SetOrigin (anOrigin);
4888 aViewer->SetZLayerSettings (aLayerId, aSettings);
4890 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
4891 && anArgIter + 1 < theArgNb
4892 && (anArg == "-cullingdistance"
4893 || anArg == "-cullingdist"
4894 || anArg == "-culldistance"
4895 || anArg == "-culldist"
4896 || anArg == "-distcull"
4897 || anArg == "-distculling"
4898 || anArg == "-distanceculling"))
4900 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4901 const Standard_Real aDist = Draw::Atof (theArgVec[++anArgIter]);
4902 aSettings.SetCullingDistance (aDist);
4903 aViewer->SetZLayerSettings (aLayerId, aSettings);
4905 else if (aLayerId != Graphic3d_ZLayerId_UNKNOWN
4906 && anArgIter + 1 < theArgNb
4907 && (anArg == "-cullingsize"
4908 || anArg == "-cullsize"
4909 || anArg == "-sizecull"
4910 || anArg == "-sizeculling"))
4912 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4913 const Standard_Real aSize = Draw::Atof (theArgVec[++anArgIter]);
4914 aSettings.SetCullingSize (aSize);
4915 aViewer->SetZLayerSettings (aLayerId, aSettings);
4917 else if (anArg == "-settings"
4918 || anArg == "settings")
4920 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4922 if (++anArgIter >= theArgNb)
4924 std::cout << "Syntax error: id of Z layer is missing\n";
4928 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4931 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4932 printZLayerInfo (theDI, aSettings);
4934 else if (anArg == "-enable"
4935 || anArg == "enable"
4936 || anArg == "-disable"
4937 || anArg == "disable")
4939 const Standard_Boolean toEnable = anArg == "-enable"
4940 || anArg == "enable";
4941 if (++anArgIter >= theArgNb)
4943 std::cout << "Syntax error: option name is missing\n";
4947 TCollection_AsciiString aSubOp (theArgVec[anArgIter]);
4949 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4951 if (++anArgIter >= theArgNb)
4953 std::cout << "Syntax error: id of Z layer is missing\n";
4957 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4960 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4961 if (aSubOp == "depthtest"
4962 || aSubOp == "test")
4964 aSettings.SetEnableDepthTest (toEnable);
4966 else if (aSubOp == "depthwrite"
4967 || aSubOp == "write")
4969 aSettings.SetEnableDepthWrite (toEnable);
4971 else if (aSubOp == "depthclear"
4972 || aSubOp == "clear")
4974 aSettings.SetClearDepth (toEnable);
4976 else if (aSubOp == "depthoffset"
4977 || aSubOp == "offset")
4979 Graphic3d_PolygonOffset aParams;
4980 aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None;
4983 if (anArgIter + 2 >= theArgNb)
4985 std::cout << "Syntax error: factor and units values for depth offset are missing\n";
4989 aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
4990 aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
4992 aSettings.SetPolygonOffset (aParams);
4994 else if (aSubOp == "positiveoffset"
4995 || aSubOp == "poffset")
4999 aSettings.SetDepthOffsetPositive();
5003 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
5006 else if (aSubOp == "negativeoffset"
5007 || aSubOp == "noffset")
5011 aSettings.SetDepthOffsetNegative();
5015 aSettings.SetPolygonOffset(Graphic3d_PolygonOffset());
5018 else if (aSubOp == "textureenv")
5020 aSettings.SetEnvironmentTexture (toEnable);
5023 aViewer->SetZLayerSettings (aLayerId, aSettings);
5027 std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n";
5035 // The interactive presentation of 2d layer item
5036 // for "vlayerline" command it provides a presentation of
5037 // line with user-defined linewidth, linetype and transparency.
5038 class V3d_LineItem : public AIS_InteractiveObject
5042 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
5045 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5046 Standard_Real X2, Standard_Real Y2,
5047 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
5048 Standard_Real theWidth = 0.5,
5049 Standard_Real theTransp = 1.0);
5053 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
5054 const Handle(Prs3d_Presentation)& thePresentation,
5055 const Standard_Integer theMode) Standard_OVERRIDE;
5057 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
5058 const Standard_Integer /*aMode*/) Standard_OVERRIDE
5063 Standard_Real myX1, myY1, myX2, myY2;
5064 Aspect_TypeOfLine myType;
5065 Standard_Real myWidth;
5068 // default constructor for line item
5069 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
5070 Standard_Real X2, Standard_Real Y2,
5071 Aspect_TypeOfLine theType,
5072 Standard_Real theWidth,
5073 Standard_Real theTransp) :
5074 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
5075 myType(theType), myWidth(theWidth)
5077 SetTransparency (1-theTransp);
5081 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
5082 const Handle(Prs3d_Presentation)& thePresentation,
5083 const Standard_Integer /*theMode*/)
5085 thePresentation->Clear();
5086 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
5087 Standard_Integer aWidth, aHeight;
5088 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
5089 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
5090 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
5091 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
5092 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
5093 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
5094 aGroup->SetPrimitivesAspect (anAspect->Aspect());
5095 aGroup->AddPrimitiveArray (aPrim);
5098 //=============================================================================
5099 //function : VLayerLine
5100 //purpose : Draws line in the v3d view layer with given attributes: linetype,
5101 // : linewidth, transparency coefficient
5102 //============================================================================
5103 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5105 // get the active view
5106 Handle(V3d_View) aView = ViewerTest::CurrentView();
5109 di << "Call vinit before!\n";
5114 di << "Use: " << argv[0];
5115 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
5116 di << " linetype : { 0 | 1 | 2 | 3 } \n";
5117 di << " 0 - solid \n";
5118 di << " 1 - dashed \n";
5119 di << " 2 - dot \n";
5120 di << " 3 - dashdot\n";
5121 di << " transparency : { 0.0 - 1.0 } \n";
5122 di << " 0.0 - transparent\n";
5123 di << " 1.0 - visible \n";
5127 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5128 // get the input params
5129 Standard_Real X1 = Draw::Atof(argv[1]);
5130 Standard_Real Y1 = Draw::Atof(argv[2]);
5131 Standard_Real X2 = Draw::Atof(argv[3]);
5132 Standard_Real Y2 = Draw::Atof(argv[4]);
5134 Standard_Real aWidth = 0.5;
5135 Standard_Real aTransparency = 1.0;
5139 aWidth = Draw::Atof(argv[5]);
5141 // select appropriate line type
5142 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
5144 && !ViewerTest::ParseLineType (argv[6], aLineType))
5146 std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n";
5153 aTransparency = Draw::Atof(argv[7]);
5154 if (aTransparency < 0 || aTransparency > 1.0)
5155 aTransparency = 1.0;
5158 static Handle (V3d_LineItem) aLine;
5159 if (!aLine.IsNull())
5161 aContext->Erase (aLine, Standard_False);
5163 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
5167 aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
5168 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
5169 aLine->SetToUpdate();
5170 aContext->Display (aLine, Standard_True);
5176 //==============================================================================
5179 //==============================================================================
5181 static int VGrid (Draw_Interpretor& /*theDI*/,
5182 Standard_Integer theArgNb,
5183 const char** theArgVec)
5185 // get the active view
5186 Handle(V3d_View) aView = ViewerTest::CurrentView();
5187 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5188 if (aView.IsNull() || aViewer.IsNull())
5190 std::cerr << "No active view. Please call vinit.\n";
5194 Aspect_GridType aType = aViewer->GridType();
5195 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
5196 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
5197 Standard_Integer anIter = 1;
5198 for (; anIter < theArgNb; ++anIter)
5200 const char* aValue = theArgVec[anIter];
5201 if (anUpdateTool.parseRedrawMode (aValue))
5205 else if (*aValue == 'r')
5207 aType = Aspect_GT_Rectangular;
5209 else if (*aValue == 'c')
5211 aType = Aspect_GT_Circular;
5213 else if (*aValue == 'l')
5215 aMode = Aspect_GDM_Lines;
5217 else if (*aValue == 'p')
5219 aMode = Aspect_GDM_Points;
5221 else if (strcmp (aValue, "off" ) == 0)
5223 aViewer->DeactivateGrid();
5232 Standard_Integer aTail = (theArgNb - anIter);
5235 aViewer->ActivateGrid (aType, aMode);
5238 else if (aTail != 2 && aTail != 5)
5240 std::cerr << "Incorrect arguments number! Usage:\n"
5241 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
5245 Standard_Real anOriginX, anOriginY, aRotAngle;
5246 if (aType == Aspect_GT_Rectangular)
5248 Standard_Real aRStepX, aRStepY;
5249 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
5251 anOriginX = Draw::Atof (theArgVec[anIter++]);
5252 anOriginY = Draw::Atof (theArgVec[anIter++]);
5255 aRStepX = Draw::Atof (theArgVec[anIter++]);
5256 aRStepY = Draw::Atof (theArgVec[anIter++]);
5257 aRotAngle = Draw::Atof (theArgVec[anIter++]);
5259 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
5260 aViewer->ActivateGrid (aType, aMode);
5262 else if (aType == Aspect_GT_Circular)
5264 Standard_Real aRadiusStep;
5265 Standard_Integer aDivisionNumber;
5266 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
5268 anOriginX = Draw::Atof (theArgVec[anIter++]);
5269 anOriginY = Draw::Atof (theArgVec[anIter++]);
5272 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
5273 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
5274 aRotAngle = Draw::Atof (theArgVec[anIter++]);
5277 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
5278 aViewer->ActivateGrid (aType, aMode);
5284 //==============================================================================
5285 //function : VPriviledgedPlane
5287 //==============================================================================
5289 static int VPriviledgedPlane (Draw_Interpretor& theDI,
5290 Standard_Integer theArgNb,
5291 const char** theArgVec)
5293 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
5295 std::cerr << "Error: wrong number of arguments! See usage:\n";
5296 theDI.PrintHelp (theArgVec[0]);
5300 // get the active viewer
5301 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5302 if (aViewer.IsNull())
5304 std::cerr << "Error: no active viewer. Please call vinit.\n";
5310 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
5311 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
5312 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
5313 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
5314 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
5315 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
5316 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
5320 Standard_Integer anArgIdx = 1;
5321 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
5322 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
5323 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
5324 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
5325 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
5326 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
5328 gp_Ax3 aPriviledgedPlane;
5329 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
5330 gp_Dir aNorm (aNormX, aNormY, aNormZ);
5333 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
5334 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
5335 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
5336 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
5337 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
5341 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
5344 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
5349 //==============================================================================
5350 //function : VConvert
5352 //==============================================================================
5354 static int VConvert (Draw_Interpretor& theDI,
5355 Standard_Integer theArgNb,
5356 const char** theArgVec)
5358 // get the active view
5359 Handle(V3d_View) aView = ViewerTest::CurrentView();
5362 std::cerr << "Error: no active view. Please call vinit.\n";
5366 enum { Model, Ray, View, Window, Grid } aMode = Model;
5368 // access coordinate arguments
5369 TColStd_SequenceOfReal aCoord;
5370 Standard_Integer anArgIdx = 1;
5371 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
5373 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5374 if (!anArg.IsRealValue())
5378 aCoord.Append (anArg.RealValue());
5381 // non-numeric argument too early
5382 if (aCoord.IsEmpty())
5384 std::cerr << "Error: wrong number of arguments! See usage:\n";
5385 theDI.PrintHelp (theArgVec[0]);
5389 // collect all other arguments and options
5390 for (; anArgIdx < theArgNb; ++anArgIdx)
5392 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5394 if (anArg == "window") aMode = Window;
5395 else if (anArg == "view") aMode = View;
5396 else if (anArg == "grid") aMode = Grid;
5397 else if (anArg == "ray") aMode = Ray;
5400 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
5401 theDI.PrintHelp (theArgVec[0]);
5406 // complete input checks
5407 if ((aCoord.Length() == 1 && theArgNb > 3) ||
5408 (aCoord.Length() == 2 && theArgNb > 4) ||
5409 (aCoord.Length() == 3 && theArgNb > 5))
5411 std::cerr << "Error: wrong number of arguments! See usage:\n";
5412 theDI.PrintHelp (theArgVec[0]);
5416 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
5417 Standard_Integer aXYp[2] = {0, 0};
5419 // convert one-dimensional coordinate
5420 if (aCoord.Length() == 1)
5424 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer)aCoord (1)); return 0;
5425 case Window : theDI << "Window Vp: " << aView->Convert (aCoord (1)); return 0;
5427 std::cerr << "Error: wrong arguments! See usage:\n";
5428 theDI.PrintHelp (theArgVec[0]);
5433 // convert 2D coordinates from projection or view reference space
5434 if (aCoord.Length() == 2)
5439 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5440 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5444 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5445 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5449 aView->Convert (aCoord (1), aCoord (2), aXYp[0], aXYp[1]);
5450 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5454 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5455 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5456 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5460 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5461 (Standard_Integer) aCoord (2),
5462 aXYZ[0], aXYZ[1], aXYZ[2],
5463 aXYZ[3], aXYZ[4], aXYZ[5]);
5464 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5468 std::cerr << "Error: wrong arguments! See usage:\n";
5469 theDI.PrintHelp (theArgVec[0]);
5474 // convert 3D coordinates from view reference space
5475 else if (aCoord.Length() == 3)
5480 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5481 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5485 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5486 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5490 std::cerr << "Error: wrong arguments! See usage:\n";
5491 theDI.PrintHelp (theArgVec[0]);
5499 //==============================================================================
5502 //==============================================================================
5504 static int VFps (Draw_Interpretor& theDI,
5505 Standard_Integer theArgNb,
5506 const char** theArgVec)
5508 // get the active view
5509 Handle(V3d_View) aView = ViewerTest::CurrentView();
5512 std::cerr << "No active view. Please call vinit.\n";
5516 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
5519 std::cerr << "Incorrect arguments!\n";
5523 // the time is meaningless for first call
5524 // due to async OpenGl rendering
5527 // redraw view in loop to estimate average values
5530 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
5536 const Standard_Real aTime = aTimer.ElapsedTime();
5537 aTimer.OSD_Chronometer::Show (aCpu);
5539 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
5540 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
5542 // return statistics
5543 theDI << "FPS: " << aFpsAver << "\n"
5544 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5546 // compute additional statistics in ray-tracing mode
5547 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
5549 if (aParams.Method == Graphic3d_RM_RAYTRACING)
5551 Standard_Integer aSizeX;
5552 Standard_Integer aSizeY;
5554 aView->Window()->Size (aSizeX, aSizeY);
5556 // 1 shadow ray and 1 secondary ray pew each bounce
5557 const Standard_Real aMRays = aSizeX * aSizeY * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
5559 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
5565 //==============================================================================
5566 //function : VGlDebug
5568 //==============================================================================
5570 static int VGlDebug (Draw_Interpretor& theDI,
5571 Standard_Integer theArgNb,
5572 const char** theArgVec)
5574 Handle(OpenGl_GraphicDriver) aDriver;
5575 Handle(V3d_View) aView = ViewerTest::CurrentView();
5576 if (!aView.IsNull())
5578 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5580 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
5581 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
5585 TCollection_AsciiString aDebActive, aSyncActive;
5592 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
5593 "GL_ARB_debug_output");
5594 aDebActive = isActive ? " (active)" : " (inactive)";
5597 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
5598 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
5602 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
5603 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
5604 << "glslWarn:" << (aCaps->glslWarnings ? "1" : "0") << "\n"
5605 << "extraMsg:" << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
5609 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5611 Standard_CString anArg = theArgVec[anArgIter];
5612 TCollection_AsciiString anArgCase (anArg);
5613 anArgCase.LowerCase();
5614 Standard_Boolean toEnableDebug = Standard_True;
5615 if (anArgCase == "-glsl"
5616 || anArgCase == "-glslwarn"
5617 || anArgCase == "-glslwarns"
5618 || anArgCase == "-glslwarnings")
5620 Standard_Boolean toShowWarns = Standard_True;
5621 if (++anArgIter < theArgNb
5622 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
5626 aDefCaps->glslWarnings = toShowWarns;
5629 aCaps->glslWarnings = toShowWarns;
5632 else if (anArgCase == "-extra"
5633 || anArgCase == "-extramsg"
5634 || anArgCase == "-extramessages")
5636 Standard_Boolean toShow = Standard_True;
5637 if (++anArgIter < theArgNb
5638 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
5642 aDefCaps->suppressExtraMsg = !toShow;
5645 aCaps->suppressExtraMsg = !toShow;
5648 else if (anArgCase == "-noextra"
5649 || anArgCase == "-noextramsg"
5650 || anArgCase == "-noextramessages")
5652 Standard_Boolean toSuppress = Standard_True;
5653 if (++anArgIter < theArgNb
5654 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
5658 aDefCaps->suppressExtraMsg = toSuppress;
5661 aCaps->suppressExtraMsg = toSuppress;
5664 else if (anArgCase == "-sync")
5666 Standard_Boolean toSync = Standard_True;
5667 if (++anArgIter < theArgNb
5668 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
5672 aDefCaps->contextSyncDebug = toSync;
5675 aDefCaps->contextDebug = Standard_True;
5678 else if (anArgCase == "-debug")
5680 if (++anArgIter < theArgNb
5681 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
5685 aDefCaps->contextDebug = toEnableDebug;
5687 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
5688 && (anArgIter + 1 == theArgNb))
5690 // simple alias to turn on almost everything
5691 aDefCaps->contextDebug = toEnableDebug;
5692 aDefCaps->contextSyncDebug = toEnableDebug;
5693 aDefCaps->glslWarnings = toEnableDebug;
5697 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
5705 //==============================================================================
5708 //==============================================================================
5710 static int VVbo (Draw_Interpretor& theDI,
5711 Standard_Integer theArgNb,
5712 const char** theArgVec)
5714 const Standard_Boolean toSet = (theArgNb > 1);
5715 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
5718 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
5722 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5723 if (aContextAIS.IsNull())
5727 std::cerr << "No active view!\n";
5731 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5732 if (!aDriver.IsNull())
5736 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
5740 aDriver->ChangeOptions().vboDisable = toUseVbo;
5747 //==============================================================================
5750 //==============================================================================
5752 static int VCaps (Draw_Interpretor& theDI,
5753 Standard_Integer theArgNb,
5754 const char** theArgVec)
5756 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
5757 Handle(OpenGl_GraphicDriver) aDriver;
5758 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5759 if (!aContext.IsNull())
5761 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
5762 aCaps = &aDriver->ChangeOptions();
5767 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
5768 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
5769 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
5770 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
5771 theDI << "VSync: " << aCaps->swapInterval << "\n";
5772 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
5773 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
5774 theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n";
5778 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5779 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5781 Standard_CString anArg = theArgVec[anArgIter];
5782 TCollection_AsciiString anArgCase (anArg);
5783 anArgCase.LowerCase();
5784 if (anUpdateTool.parseRedrawMode (anArg))
5788 else if (anArgCase == "-vsync"
5789 || anArgCase == "-swapinterval")
5791 Standard_Boolean toEnable = Standard_True;
5792 if (++anArgIter < theArgNb
5793 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5797 aCaps->swapInterval = toEnable;
5799 else if (anArgCase == "-ffp")
5801 Standard_Boolean toEnable = Standard_True;
5802 if (++anArgIter < theArgNb
5803 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5807 aCaps->ffpEnable = toEnable;
5809 else if (anArgCase == "-vbo")
5811 Standard_Boolean toEnable = Standard_True;
5812 if (++anArgIter < theArgNb
5813 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5817 aCaps->vboDisable = !toEnable;
5819 else if (anArgCase == "-sprite"
5820 || anArgCase == "-sprites")
5822 Standard_Boolean toEnable = Standard_True;
5823 if (++anArgIter < theArgNb
5824 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5828 aCaps->pntSpritesDisable = !toEnable;
5830 else if (anArgCase == "-softmode")
5832 Standard_Boolean toEnable = Standard_True;
5833 if (++anArgIter < theArgNb
5834 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5838 aCaps->contextNoAccel = toEnable;
5840 else if (anArgCase == "-winbuffer"
5841 || anArgCase == "-windowbuffer"
5842 || anArgCase == "-usewinbuffer"
5843 || anArgCase == "-usewindowbuffer"
5844 || anArgCase == "-usesystembuffer")
5846 Standard_Boolean toEnable = Standard_True;
5847 if (++anArgIter < theArgNb
5848 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5852 aCaps->useSystemBuffer = toEnable;
5854 else if (anArgCase == "-accel"
5855 || anArgCase == "-acceleration")
5857 Standard_Boolean toEnable = Standard_True;
5858 if (++anArgIter < theArgNb
5859 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5863 aCaps->contextNoAccel = !toEnable;
5865 else if (anArgCase == "-compat"
5866 || anArgCase == "-compatprofile"
5867 || anArgCase == "-compatible"
5868 || anArgCase == "-compatibleprofile")
5870 Standard_Boolean toEnable = Standard_True;
5871 if (++anArgIter < theArgNb
5872 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5876 aCaps->contextCompatible = toEnable;
5877 if (!aCaps->contextCompatible)
5879 aCaps->ffpEnable = Standard_False;
5882 else if (anArgCase == "-core"
5883 || anArgCase == "-coreprofile")
5885 Standard_Boolean toEnable = Standard_True;
5886 if (++anArgIter < theArgNb
5887 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5891 aCaps->contextCompatible = !toEnable;
5892 if (!aCaps->contextCompatible)
5894 aCaps->ffpEnable = Standard_False;
5897 else if (anArgCase == "-stereo"
5898 || anArgCase == "-quadbuffer")
5900 Standard_Boolean toEnable = Standard_True;
5901 if (++anArgIter < theArgNb
5902 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5906 aCaps->contextStereo = toEnable;
5910 std::cout << "Error: unknown argument '" << anArg << "'\n";
5914 if (aCaps != &ViewerTest_myDefaultCaps)
5916 ViewerTest_myDefaultCaps = *aCaps;
5921 //==============================================================================
5922 //function : VMemGpu
5924 //==============================================================================
5926 static int VMemGpu (Draw_Interpretor& theDI,
5927 Standard_Integer theArgNb,
5928 const char** theArgVec)
5931 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5932 if (aContextAIS.IsNull())
5934 std::cerr << "No active view. Please call vinit.\n";
5938 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
5939 if (aDriver.IsNull())
5941 std::cerr << "Graphic driver not available.\n";
5945 Standard_Size aFreeBytes = 0;
5946 TCollection_AsciiString anInfo;
5947 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
5949 std::cerr << "Information not available.\n";
5953 if (theArgNb > 1 && *theArgVec[1] == 'f')
5955 theDI << Standard_Real (aFreeBytes);
5965 // ==============================================================================
5966 // function : VReadPixel
5968 // ==============================================================================
5969 static int VReadPixel (Draw_Interpretor& theDI,
5970 Standard_Integer theArgNb,
5971 const char** theArgVec)
5973 // get the active view
5974 Handle(V3d_View) aView = ViewerTest::CurrentView();
5977 std::cerr << "No active view. Please call vinit.\n";
5980 else if (theArgNb < 3)
5982 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
5986 Image_Format aFormat = Image_Format_RGBA;
5987 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
5989 Standard_Integer aWidth, aHeight;
5990 aView->Window()->Size (aWidth, aHeight);
5991 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
5992 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
5993 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
5995 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
5999 Standard_Boolean toShowName = Standard_False;
6000 Standard_Boolean toShowHls = Standard_False;
6001 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
6003 TCollection_AsciiString aParam (theArgVec[anIter]);
6005 if (aParam == "rgb")
6007 aFormat = Image_Format_RGB;
6008 aBufferType = Graphic3d_BT_RGB;
6010 else if (aParam == "hls")
6012 aFormat = Image_Format_RGB;
6013 aBufferType = Graphic3d_BT_RGB;
6014 toShowHls = Standard_True;
6016 else if (aParam == "rgbf")
6018 aFormat = Image_Format_RGBF;
6019 aBufferType = Graphic3d_BT_RGB;
6021 else if (aParam == "rgba")
6023 aFormat = Image_Format_RGBA;
6024 aBufferType = Graphic3d_BT_RGBA;
6026 else if (aParam == "rgbaf")
6028 aFormat = Image_Format_RGBAF;
6029 aBufferType = Graphic3d_BT_RGBA;
6031 else if (aParam == "depth")
6033 aFormat = Image_Format_GrayF;
6034 aBufferType = Graphic3d_BT_Depth;
6036 else if (aParam == "name")
6038 toShowName = Standard_True;
6042 Image_PixMap anImage;
6043 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
6045 std::cerr << "Image allocation failed\n";
6048 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
6050 std::cerr << "Image dump failed\n";
6054 // redirect possible warning messages that could have been added by ToPixMap
6055 // into the Tcl interpretor (via DefaultMessenger) to cout, so that they do not
6056 // contaminate result of the command
6057 Standard_CString aWarnLog = theDI.Result();
6058 if (aWarnLog != NULL && aWarnLog[0] != '\0')
6060 std::cout << aWarnLog << std::endl;
6064 Quantity_ColorRGBA aColor = anImage.PixelColor (anX, anY);
6067 if (aBufferType == Graphic3d_BT_RGBA)
6069 theDI << Quantity_Color::StringName (aColor.GetRGB().Name()) << " " << aColor.Alpha();
6073 theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
6078 switch (aBufferType)
6081 case Graphic3d_BT_RGB:
6085 theDI << aColor.GetRGB().Hue() << " " << aColor.GetRGB().Light() << " " << aColor.GetRGB().Saturation();
6089 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue();
6093 case Graphic3d_BT_RGBA:
6095 theDI << aColor.GetRGB().Red() << " " << aColor.GetRGB().Green() << " " << aColor.GetRGB().Blue() << " " << aColor.Alpha();
6098 case Graphic3d_BT_Depth:
6100 theDI << aColor.GetRGB().Red();
6109 //! Auxiliary presentation for an image plane.
6110 class ViewerTest_ImagePrs : public AIS_InteractiveObject
6113 //! Main constructor.
6114 ViewerTest_ImagePrs (const Handle(Image_PixMap)& theImage,
6115 const Standard_Real theWidth,
6116 const Standard_Real theHeight,
6117 const TCollection_AsciiString& theLabel)
6118 : myLabel (theLabel), myWidth (theWidth), myHeight(theHeight)
6122 myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost);
6124 myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
6125 const Handle(Graphic3d_AspectFillArea3d)& aFillAspect = myDrawer->ShadingAspect()->Aspect();
6126 Graphic3d_MaterialAspect aMat;
6127 aMat.SetMaterialType (Graphic3d_MATERIAL_PHYSIC);
6128 aMat.SetAmbient (1.0);
6129 aMat.SetDiffuse (1.0);
6130 aMat.SetSpecular (1.0);
6131 aMat.SetEmissive (1.0);
6132 aMat.SetReflectionModeOn (Graphic3d_TOR_AMBIENT);
6133 aMat.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE);
6134 aMat.SetReflectionModeOn (Graphic3d_TOR_SPECULAR);
6135 aMat.SetReflectionModeOn (Graphic3d_TOR_EMISSION);
6136 aMat.SetAmbientColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6137 aMat.SetDiffuseColor (Quantity_Color (1.0, 1.0, 1.0, Quantity_TOC_RGB));
6138 aMat.SetSpecularColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6139 aMat.SetEmissiveColor (Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB));
6140 aFillAspect->SetFrontMaterial (aMat);
6141 aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage));
6142 aFillAspect->SetTextureMapOn();
6145 Handle(Prs3d_TextAspect) aTextAspect = new Prs3d_TextAspect();
6146 aTextAspect->SetHorizontalJustification (Graphic3d_HTA_CENTER);
6147 aTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER);
6148 myDrawer->SetTextAspect (aTextAspect);
6151 const gp_Dir aNorm (0.0, 0.0, 1.0);
6152 myTris = new Graphic3d_ArrayOfTriangles (4, 6, true, false, true);
6153 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 0.0));
6154 myTris->AddVertex (gp_Pnt( myWidth * 0.5, -myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 0.0));
6155 myTris->AddVertex (gp_Pnt(-myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (0.0, 1.0));
6156 myTris->AddVertex (gp_Pnt( myWidth * 0.5, myHeight * 0.5, 0.0), aNorm, gp_Pnt2d (1.0, 1.0));
6157 myTris->AddEdge (1);
6158 myTris->AddEdge (2);
6159 myTris->AddEdge (3);
6160 myTris->AddEdge (3);
6161 myTris->AddEdge (2);
6162 myTris->AddEdge (4);
6164 myRect = new Graphic3d_ArrayOfPolylines (4);
6165 myRect->AddVertex (myTris->Vertice (1));
6166 myRect->AddVertex (myTris->Vertice (3));
6167 myRect->AddVertex (myTris->Vertice (4));
6168 myRect->AddVertex (myTris->Vertice (2));
6172 //! Returns TRUE for accepted display modes.
6173 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; }
6175 //! Compute presentation.
6176 virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& , const Handle(Prs3d_Presentation)& thePrs, const Standard_Integer theMode) Standard_OVERRIDE
6182 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
6183 aGroup->AddPrimitiveArray (myTris);
6184 aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
6185 aGroup->AddPrimitiveArray (myRect);
6186 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
6191 Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myLabel, gp_Pnt(0.0, 0.0, 0.0));
6192 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
6193 aGroup->AddPrimitiveArray (myRect);
6194 aGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
6200 //! Compute selection.
6201 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel, const Standard_Integer theMode) Standard_OVERRIDE
6205 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 5);
6206 Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anEntityOwner);
6207 aSensitive->InitTriangulation (myTris->Attributes(), myTris->Indices(), TopLoc_Location());
6208 theSel->Add (aSensitive);
6213 Handle(Graphic3d_ArrayOfTriangles) myTris;
6214 Handle(Graphic3d_ArrayOfPolylines) myRect;
6215 TCollection_AsciiString myLabel;
6216 Standard_Real myWidth;
6217 Standard_Real myHeight;
6220 //==============================================================================
6221 //function : VDiffImage
6222 //purpose : The draw-command compares two images.
6223 //==============================================================================
6225 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
6229 std::cout << "Syntax error: not enough arguments.\n";
6233 Standard_Integer anArgIter = 1;
6234 TCollection_AsciiString anImgPathRef (theArgVec[anArgIter++]);
6235 TCollection_AsciiString anImgPathNew (theArgVec[anArgIter++]);
6236 TCollection_AsciiString aDiffImagePath;
6237 Standard_Real aTolColor = -1.0;
6238 Standard_Integer toBlackWhite = -1;
6239 Standard_Integer isBorderFilterOn = -1;
6240 Standard_Boolean isOldSyntax = Standard_False;
6241 TCollection_AsciiString aViewName, aPrsNameRef, aPrsNameNew, aPrsNameDiff;
6242 for (; anArgIter < theArgNb; ++anArgIter)
6244 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6246 if (anArgIter + 1 < theArgNb
6247 && (anArg == "-toleranceofcolor"
6248 || anArg == "-tolerancecolor"
6249 || anArg == "-tolerance"
6250 || anArg == "-toler"))
6252 aTolColor = Atof (theArgVec[++anArgIter]);
6253 if (aTolColor < 0.0 || aTolColor > 1.0)
6255 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
6259 else if (anArg == "-blackwhite")
6261 Standard_Boolean toEnable = Standard_True;
6262 if (anArgIter + 1 < theArgNb
6263 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6267 toBlackWhite = toEnable ? 1 : 0;
6269 else if (anArg == "-borderfilter")
6271 Standard_Boolean toEnable = Standard_True;
6272 if (anArgIter + 1 < theArgNb
6273 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
6277 isBorderFilterOn = toEnable ? 1 : 0;
6279 else if (anArg == "-exitonclose")
6281 Draw_ToExitOnCloseView = true;
6282 if (anArgIter + 1 < theArgNb
6283 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToExitOnCloseView))
6288 else if (anArg == "-closeonescape"
6289 || anArg == "-closeonesc")
6291 Draw_ToCloseViewOnEsc = true;
6292 if (anArgIter + 1 < theArgNb
6293 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], Draw_ToCloseViewOnEsc))
6298 else if (anArgIter + 3 < theArgNb
6299 && anArg == "-display")
6301 aViewName = theArgVec[++anArgIter];
6302 aPrsNameRef = theArgVec[++anArgIter];
6303 aPrsNameNew = theArgVec[++anArgIter];
6304 if (anArgIter + 1 < theArgNb
6305 && *theArgVec[anArgIter + 1] != '-')
6307 aPrsNameDiff = theArgVec[++anArgIter];
6310 else if (aTolColor < 0.0
6311 && anArg.IsRealValue())
6313 isOldSyntax = Standard_True;
6314 aTolColor = anArg.RealValue();
6315 if (aTolColor < 0.0 || aTolColor > 1.0)
6317 std::cout << "Syntax error at '" << anArg << " " << theArgVec[anArgIter] << "'\n";
6321 else if (isOldSyntax
6322 && toBlackWhite == -1
6323 && (anArg == "0" || anArg == "1"))
6325 toBlackWhite = anArg == "1" ? 1 : 0;
6327 else if (isOldSyntax
6328 && isBorderFilterOn == -1
6329 && (anArg == "0" || anArg == "1"))
6331 isBorderFilterOn = anArg == "1" ? 1 : 0;
6333 else if (aDiffImagePath.IsEmpty())
6335 aDiffImagePath = theArgVec[anArgIter];
6339 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
6344 Handle(Image_AlienPixMap) anImgRef = new Image_AlienPixMap();
6345 Handle(Image_AlienPixMap) anImgNew = new Image_AlienPixMap();
6346 if (!anImgRef->Load (anImgPathRef))
6348 std::cout << "Error: image file '" << anImgPathRef << "' cannot be read\n";
6351 if (!anImgNew->Load (anImgPathNew))
6353 std::cout << "Error: image file '" << anImgPathNew << "' cannot be read\n";
6357 // compare the images
6358 Image_Diff aComparer;
6359 Standard_Integer aDiffColorsNb = -1;
6360 if (aComparer.Init (anImgRef, anImgNew, toBlackWhite == 1))
6362 aComparer.SetColorTolerance (aTolColor >= 0.0 ? aTolColor : 0.0);
6363 aComparer.SetBorderFilterOn (isBorderFilterOn == 1);
6364 aDiffColorsNb = aComparer.Compare();
6365 theDI << aDiffColorsNb << "\n";
6368 // save image of difference
6369 Handle(Image_AlienPixMap) aDiff;
6370 if (aDiffColorsNb > 0
6371 && (!aDiffImagePath.IsEmpty() || !aPrsNameDiff.IsEmpty()))
6373 aDiff = new Image_AlienPixMap();
6374 if (!aDiff->InitTrash (Image_Format_Gray, anImgRef->SizeX(), anImgRef->SizeY()))
6376 std::cout << "Error: cannot allocate memory for diff image " << anImgRef->SizeX() << "x" << anImgRef->SizeY() << "\n";
6379 aComparer.SaveDiffImage (*aDiff);
6380 if (!aDiffImagePath.IsEmpty()
6381 && !aDiff->Save (aDiffImagePath))
6383 std::cout << "Error: diff image file '" << aDiffImagePath << "' cannot be written\n";
6388 if (aViewName.IsEmpty())
6393 ViewerTest_Names aViewNames (aViewName);
6394 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
6396 TCollection_AsciiString aCommand = TCollection_AsciiString ("vclose ") + aViewNames.GetViewName();
6397 theDI.Eval (aCommand.ToCString());
6400 Standard_Integer aPxLeft = 0;
6401 Standard_Integer aPxTop = 0;
6402 Standard_Integer aWinSizeX = int(anImgRef->SizeX() * 2);
6403 Standard_Integer aWinSizeY = !aDiff.IsNull() && !aPrsNameDiff.IsEmpty()
6404 ? int(anImgRef->SizeY() * 2)
6405 : int(anImgRef->SizeY());
6406 TCollection_AsciiString aDisplayName;
6407 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop,
6408 aWinSizeX, aWinSizeY,
6409 aViewName.ToCString(),
6410 aDisplayName.ToCString());
6412 Standard_Real aRatio = anImgRef->Ratio();
6413 Standard_Real aSizeX = 1.0;
6414 Standard_Real aSizeY = aSizeX / aRatio;
6416 OSD_Path aPath (anImgPathRef);
6417 TCollection_AsciiString aLabelRef;
6418 if (!aPath.Name().IsEmpty())
6420 aLabelRef = aPath.Name() + aPath.Extension();
6422 aLabelRef += TCollection_AsciiString() + "\n" + int(anImgRef->SizeX()) + "x" + int(anImgRef->SizeY());
6424 Handle(ViewerTest_ImagePrs) anImgRefPrs = new ViewerTest_ImagePrs (anImgRef, aSizeX, aSizeY, aLabelRef);
6426 aTrsfRef.SetTranslationPart (gp_Vec (-aSizeX * 0.5, 0.0, 0.0));
6427 anImgRefPrs->SetLocalTransformation (aTrsfRef);
6428 ViewerTest::Display (aPrsNameRef, anImgRefPrs, false, true);
6431 OSD_Path aPath (anImgPathNew);
6432 TCollection_AsciiString aLabelNew;
6433 if (!aPath.Name().IsEmpty())
6435 aLabelNew = aPath.Name() + aPath.Extension();
6437 aLabelNew += TCollection_AsciiString() + "\n" + int(anImgNew->SizeX()) + "x" + int(anImgNew->SizeY());
6439 Handle(ViewerTest_ImagePrs) anImgNewPrs = new ViewerTest_ImagePrs (anImgNew, aSizeX, aSizeY, aLabelNew);
6441 aTrsfRef.SetTranslationPart (gp_Vec (aSizeX * 0.5, 0.0, 0.0));
6442 anImgNewPrs->SetLocalTransformation (aTrsfRef);
6443 ViewerTest::Display (aPrsNameNew, anImgNewPrs, false, true);
6445 Handle(ViewerTest_ImagePrs) anImgDiffPrs;
6446 if (!aDiff.IsNull())
6448 anImgDiffPrs = new ViewerTest_ImagePrs (aDiff, aSizeX, aSizeY, TCollection_AsciiString() + "Difference: " + aDiffColorsNb + " pixels");
6450 aTrsfDiff.SetTranslationPart (gp_Vec (0.0, -aSizeY, 0.0));
6451 anImgDiffPrs->SetLocalTransformation (aTrsfDiff);
6453 if (!aPrsNameDiff.IsEmpty())
6455 ViewerTest::Display (aPrsNameDiff, anImgDiffPrs, false, true);
6457 ViewerTest::CurrentView()->SetProj (V3d_Zpos);
6458 ViewerTest::CurrentView()->FitAll();
6462 //=======================================================================
6463 //function : VSelect
6464 //purpose : Emulates different types of selection by mouse:
6465 // 1) single click selection
6466 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
6467 // 3) selection with polygon having corners at
6468 // pixel positions (x1,y1),...,(xn,yn)
6469 // 4) any of these selections with shift button pressed
6470 //=======================================================================
6471 static Standard_Integer VSelect (Draw_Interpretor& di,
6472 Standard_Integer argc,
6477 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]\n";
6481 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
6482 if(myAIScontext.IsNull())
6484 di << "use 'vinit' command before " << argv[0] << "\n";
6488 const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1));
6489 Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1;
6490 TCollection_AsciiString anArg;
6491 anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2];
6493 if (anArg == "-allowoverlap")
6495 Standard_Boolean isValidated = isShiftSelection ? argc == 8
6499 di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection";
6503 Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
6504 myAIScontext->MainSelector()->AllowOverlapDetection (isToAllow != 0);
6508 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
6509 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
6512 if(isShiftSelection)
6513 aCurrentEventManager->ShiftSelect();
6515 aCurrentEventManager->Select();
6517 else if(aCoordsNb == 4)
6519 if(isShiftSelection)
6520 aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
6522 aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
6526 TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2);
6528 for(Standard_Integer i=1;i<=aCoordsNb / 2;++i)
6529 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
6531 if(isShiftSelection)
6532 aCurrentEventManager->ShiftSelect(aPolyline);
6534 aCurrentEventManager->Select(aPolyline);
6539 //=======================================================================
6540 //function : VMoveTo
6541 //purpose : Emulates cursor movement to defined pixel position
6542 //=======================================================================
6543 static Standard_Integer VMoveTo (Draw_Interpretor& di,
6544 Standard_Integer argc,
6549 di << "Usage : " << argv[0] << " x y\n";
6553 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6554 if(aContext.IsNull())
6556 di << "use 'vinit' command before " << argv[0] << "\n";
6559 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
6565 //! Global map storing all animations registered in ViewerTest.
6566 static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap;
6568 //! The animation calling the Draw Harness command.
6569 class ViewerTest_AnimationProc : public AIS_Animation
6573 //! Main constructor.
6574 ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName,
6575 Draw_Interpretor* theDI,
6576 const TCollection_AsciiString& theCommand)
6577 : AIS_Animation (theAnimationName),
6579 myCommand (theCommand)
6586 //! Evaluate the command.
6587 virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE
6589 TCollection_AsciiString aCmd = myCommand;
6590 replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts));
6591 replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts));
6592 replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts));
6593 replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized));
6594 replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized));
6595 myDrawInter->Eval (aCmd.ToCString());
6598 //! Find the keyword in the command and replace it with value.
6599 //! @return the position of the keyword to pass value
6600 void replace (TCollection_AsciiString& theCmd,
6601 const TCollection_AsciiString& theKey,
6602 const TCollection_AsciiString& theVal)
6604 TCollection_AsciiString aCmd (theCmd);
6606 const Standard_Integer aPos = aCmd.Search (theKey);
6612 TCollection_AsciiString aPart1, aPart2;
6613 Standard_Integer aPart1To = aPos - 1;
6615 && aPart1To <= theCmd.Length())
6617 aPart1 = theCmd.SubString (1, aPart1To);
6620 Standard_Integer aPart2From = aPos + theKey.Length();
6622 && aPart2From <= theCmd.Length())
6624 aPart2 = theCmd.SubString (aPart2From, theCmd.Length());
6627 theCmd = aPart1 + theVal + aPart2;
6632 Draw_Interpretor* myDrawInter;
6633 TCollection_AsciiString myCommand;
6637 //! Replace the animation with the new one.
6638 static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation,
6639 Handle(AIS_Animation)& theAnimation,
6640 const Handle(AIS_Animation)& theAnimationNew)
6642 theAnimationNew->CopyFrom (theAnimation);
6643 if (!theParentAnimation.IsNull())
6645 theParentAnimation->Replace (theAnimation, theAnimationNew);
6649 ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name());
6650 ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew);
6652 theAnimation = theAnimationNew;
6655 //! Parse the point.
6656 static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
6658 const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
6659 if (!anXYZ[0].IsRealValue()
6660 || !anXYZ[1].IsRealValue()
6661 || !anXYZ[2].IsRealValue())
6663 return Standard_False;
6666 thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue());
6667 return Standard_True;
6670 //! Parse the quaternion.
6671 static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
6673 const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
6674 if (!anXYZW[0].IsRealValue()
6675 || !anXYZW[1].IsRealValue()
6676 || !anXYZW[2].IsRealValue()
6677 || !anXYZW[3].IsRealValue())
6679 return Standard_False;
6682 theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue());
6683 return Standard_True;
6686 //! Auxiliary class for flipping image upside-down.
6691 //! Empty constructor.
6692 ImageFlipper() : myTmp (NCollection_BaseAllocator::CommonBaseAllocator()) {}
6694 //! Perform flipping.
6695 Standard_Boolean FlipY (Image_PixMap& theImage)
6697 if (theImage.IsEmpty()
6698 || theImage.SizeX() == 0
6699 || theImage.SizeY() == 0)
6701 return Standard_False;
6704 const Standard_Size aRowSize = theImage.SizeRowBytes();
6705 if (myTmp.Size() < aRowSize
6706 && !myTmp.Allocate (aRowSize))
6708 return Standard_False;
6711 // for odd height middle row should be left as is
6712 Standard_Size aNbRowsHalf = theImage.SizeY() / 2;
6713 for (Standard_Size aRowT = 0, aRowB = theImage.SizeY() - 1; aRowT < aNbRowsHalf; ++aRowT, --aRowB)
6715 Standard_Byte* aTop = theImage.ChangeRow (aRowT);
6716 Standard_Byte* aBot = theImage.ChangeRow (aRowB);
6717 memcpy (myTmp.ChangeData(), aTop, aRowSize);
6718 memcpy (aTop, aBot, aRowSize);
6719 memcpy (aBot, myTmp.Data(), aRowSize);
6721 return Standard_True;
6725 NCollection_Buffer myTmp;
6730 //=================================================================================================
6731 //function : VViewParams
6732 //purpose : Gets or sets AIS View characteristics
6733 //=================================================================================================
6734 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6736 Handle(V3d_View) aView = ViewerTest::CurrentView();
6739 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
6743 Standard_Boolean toSetProj = Standard_False;
6744 Standard_Boolean toSetUp = Standard_False;
6745 Standard_Boolean toSetAt = Standard_False;
6746 Standard_Boolean toSetEye = Standard_False;
6747 Standard_Boolean toSetScale = Standard_False;
6748 Standard_Boolean toSetSize = Standard_False;
6749 Standard_Boolean toSetCenter2d = Standard_False;
6750 Standard_Real aViewScale = aView->Scale();
6751 Standard_Real aViewSize = 1.0;
6752 Graphic3d_Vec2i aCenter2d;
6753 gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
6754 aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3));
6755 aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
6756 aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
6757 aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
6760 // print all of the available view parameters
6764 "Proj: %12g %12g %12g\n"
6765 "Up: %12g %12g %12g\n"
6766 "At: %12g %12g %12g\n"
6767 "Eye: %12g %12g %12g\n",
6769 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
6770 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
6771 aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
6772 aViewEye.X(), aViewEye.Y(), aViewEye.Z());
6777 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
6778 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
6780 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6782 if (anUpdateTool.parseRedrawMode (anArg))
6786 else if (anArg == "-cmd"
6787 || anArg == "-command"
6788 || anArg == "-args")
6797 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
6798 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
6799 aViewAt.X(), aViewAt.Y(), aViewAt.Z());
6802 else if (anArg == "-scale"
6803 || anArg == "-size")
6805 if (anArgIter + 1 < theArgsNb
6806 && *theArgVec[anArgIter + 1] != '-')
6808 const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
6809 if (aValueArg.IsRealValue())
6812 if (anArg == "-scale")
6814 toSetScale = Standard_True;
6815 aViewScale = aValueArg.RealValue();
6817 else if (anArg == "-size")
6819 toSetSize = Standard_True;
6820 aViewSize = aValueArg.RealValue();
6825 if (anArg == "-scale")
6827 theDi << "Scale: " << aView->Scale() << "\n";
6829 else if (anArg == "-size")
6831 Graphic3d_Vec2d aSizeXY;
6832 aView->Size (aSizeXY.x(), aSizeXY.y());
6833 theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n";
6836 else if (anArg == "-eye"
6839 || anArg == "-proj")
6841 if (anArgIter + 3 < theArgsNb)
6844 if (parseXYZ (theArgVec + anArgIter + 1, anXYZ))
6847 if (anArg == "-eye")
6849 toSetEye = Standard_True;
6852 else if (anArg == "-at")
6854 toSetAt = Standard_True;
6857 else if (anArg == "-up")
6859 toSetUp = Standard_True;
6862 else if (anArg == "-proj")
6864 toSetProj = Standard_True;
6871 if (anArg == "-eye")
6873 theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n";
6875 else if (anArg == "-at")
6877 theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n";
6879 else if (anArg == "-up")
6881 theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n";
6883 else if (anArg == "-proj")
6885 theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n";
6888 else if (anArg == "-center")
6890 if (anArgIter + 2 < theArgsNb)
6892 const TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
6893 const TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
6894 if (anX.IsIntegerValue()
6895 && anY.IsIntegerValue())
6897 toSetCenter2d = Standard_True;
6898 aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue());
6904 std::cout << "Syntax error at '" << anArg << "'\n";
6909 // change view parameters in proper order
6912 aView->SetScale (aViewScale);
6916 aView->SetSize (aViewSize);
6920 aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z());
6924 aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z());
6928 aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z());
6932 aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z());
6936 aView->SetCenter (aCenter2d.x(), aCenter2d.y());
6942 //==============================================================================
6943 //function : VAnimation
6945 //==============================================================================
6946 static Standard_Integer VAnimation (Draw_Interpretor& theDI,
6947 Standard_Integer theArgNb,
6948 const char** theArgVec)
6950 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
6953 for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator
6954 anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next())
6956 theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n";
6962 std::cout << "Error: no active view\n";
6966 Standard_Integer anArgIter = 1;
6967 TCollection_AsciiString aNameArg (theArgVec[anArgIter++]);
6968 if (aNameArg.IsEmpty())
6970 std::cout << "Syntax error: animation name is not defined.\n";
6974 TCollection_AsciiString aNameArgLower = aNameArg;
6975 aNameArgLower.LowerCase();
6976 if (aNameArgLower == "-reset"
6977 || aNameArgLower == "-clear")
6979 ViewerTest_AnimationTimelineMap.Clear();
6982 else if (aNameArg.Value (1) == '-')
6984 std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n";
6988 const char* aNameSplitter = "/";
6989 Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter);
6990 if (aSplitPos == -1)
6992 aNameSplitter = ".";
6993 aSplitPos = aNameArg.Search (aNameSplitter);
6996 // find existing or create a new animation by specified name within syntax "parent.child".
6997 Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation;
6998 for (; !aNameArg.IsEmpty();)
7000 TCollection_AsciiString aNameParent;
7001 if (aSplitPos != -1)
7003 if (aSplitPos == aNameArg.Length())
7005 std::cout << "Syntax error: animation name is not defined.\n";
7009 aNameParent = aNameArg.SubString ( 1, aSplitPos - 1);
7010 aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length());
7012 aSplitPos = aNameArg.Search (aNameSplitter);
7016 aNameParent = aNameArg;
7020 if (anAnimation.IsNull())
7022 if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation))
7024 anAnimation = new AIS_Animation (aNameParent);
7025 ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation);
7027 aRootAnimation = anAnimation;
7031 aParentAnimation = anAnimation;
7032 anAnimation = aParentAnimation->Find (aNameParent);
7033 if (anAnimation.IsNull())
7035 anAnimation = new AIS_Animation (aNameParent);
7036 aParentAnimation->Add (anAnimation);
7041 if (anArgIter >= theArgNb)
7043 // just print the list of children
7044 for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next())
7046 theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n";
7051 // animation parameters
7052 Standard_Boolean toPlay = Standard_False;
7053 Standard_Real aPlaySpeed = 1.0;
7054 Standard_Real aPlayStartTime = anAnimation->StartPts();
7055 Standard_Real aPlayDuration = anAnimation->Duration();
7056 Standard_Boolean isFreeCamera = Standard_False;
7057 Standard_Boolean isLockLoop = Standard_False;
7059 // video recording parameters
7060 TCollection_AsciiString aRecFile;
7061 Image_VideoParams aRecParams;
7063 Handle(V3d_View) aView = ViewerTest::CurrentView();
7064 for (; anArgIter < theArgNb; ++anArgIter)
7066 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7069 if (anArg == "-reset"
7070 || anArg == "-clear")
7072 anAnimation->Clear();
7074 else if (anArg == "-remove"
7076 || anArg == "-delete")
7078 if (!aParentAnimation.IsNull())
7080 ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name());
7084 aParentAnimation->Remove (anAnimation);
7088 else if (anArg == "-play")
7090 toPlay = Standard_True;
7091 if (++anArgIter < theArgNb)
7093 if (*theArgVec[anArgIter] == '-')
7098 aPlayStartTime = Draw::Atof (theArgVec[anArgIter]);
7100 if (++anArgIter < theArgNb)
7102 if (*theArgVec[anArgIter] == '-')
7107 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
7111 else if (anArg == "-resume")
7113 toPlay = Standard_True;
7114 aPlayStartTime = anAnimation->ElapsedTime();
7115 if (++anArgIter < theArgNb)
7117 if (*theArgVec[anArgIter] == '-')
7123 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
7126 else if (anArg == "-playspeed"
7127 || anArg == "-speed")
7129 if (++anArgIter >= theArgNb)
7131 std::cout << "Syntax error at " << anArg << ".\n";
7134 aPlaySpeed = Draw::Atof (theArgVec[anArgIter]);
7136 else if (anArg == "-lock"
7137 || anArg == "-lockloop"
7138 || anArg == "-playlockloop")
7140 isLockLoop = Standard_True;
7142 else if (anArg == "-freecamera"
7143 || anArg == "-playfreecamera"
7144 || anArg == "-freelook")
7146 isFreeCamera = Standard_True;
7148 // video recodring options
7149 else if (anArg == "-rec"
7150 || anArg == "-record")
7152 if (++anArgIter >= theArgNb)
7154 std::cout << "Syntax error at " << anArg << ".\n";
7158 aRecFile = theArgVec[anArgIter];
7159 if (aRecParams.FpsNum <= 0)
7161 aRecParams.FpsNum = 24;
7164 if (anArgIter + 2 < theArgNb
7165 && *theArgVec[anArgIter + 1] != '-'
7166 && *theArgVec[anArgIter + 2] != '-')
7168 TCollection_AsciiString aWidthArg (theArgVec[anArgIter + 1]);
7169 TCollection_AsciiString aHeightArg (theArgVec[anArgIter + 2]);
7170 if (aWidthArg .IsIntegerValue()
7171 && aHeightArg.IsIntegerValue())
7173 aRecParams.Width = aWidthArg .IntegerValue();
7174 aRecParams.Height = aHeightArg.IntegerValue();
7179 else if (anArg == "-fps")
7181 if (++anArgIter >= theArgNb)
7183 std::cout << "Syntax error at " << anArg << ".\n";
7187 TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
7188 Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
7189 if (aSplitIndex == 0)
7191 aRecParams.FpsNum = aFpsArg.IntegerValue();
7195 const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
7196 aFpsArg.Split (aFpsArg.Length() - 1);
7197 const TCollection_AsciiString aNumStr = aFpsArg;
7198 aRecParams.FpsNum = aNumStr.IntegerValue();
7199 aRecParams.FpsDen = aDenStr.IntegerValue();
7200 if (aRecParams.FpsDen < 1)
7202 std::cout << "Syntax error at " << anArg << ".\n";
7207 else if (anArg == "-format")
7209 if (++anArgIter >= theArgNb)
7211 std::cout << "Syntax error at " << anArg << ".\n";
7214 aRecParams.Format = theArgVec[anArgIter];
7216 else if (anArg == "-pix_fmt"
7217 || anArg == "-pixfmt"
7218 || anArg == "-pixelformat")
7220 if (++anArgIter >= theArgNb)
7222 std::cout << "Syntax error at " << anArg << ".\n";
7225 aRecParams.PixelFormat = theArgVec[anArgIter];
7227 else if (anArg == "-codec"
7228 || anArg == "-vcodec"
7229 || anArg == "-videocodec")
7231 if (++anArgIter >= theArgNb)
7233 std::cout << "Syntax error at " << anArg << ".\n";
7236 aRecParams.VideoCodec = theArgVec[anArgIter];
7238 else if (anArg == "-crf"
7239 || anArg == "-preset"
7242 const TCollection_AsciiString aParamName = anArg.SubString (2, anArg.Length());
7243 if (++anArgIter >= theArgNb)
7245 std::cout << "Syntax error at " << anArg << ".\n";
7249 aRecParams.VideoCodecParams.Bind (aParamName, theArgVec[anArgIter]);
7251 // animation definition options
7252 else if (anArg == "-start"
7253 || anArg == "-starttime"
7254 || anArg == "-startpts")
7256 if (++anArgIter >= theArgNb)
7258 std::cout << "Syntax error at " << anArg << ".\n";
7262 anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter]));
7263 aRootAnimation->UpdateTotalDuration();
7265 else if (anArg == "-end"
7266 || anArg == "-endtime"
7267 || anArg == "-endpts")
7269 if (++anArgIter >= theArgNb)
7271 std::cout << "Syntax error at " << anArg << ".\n";
7275 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts());
7276 aRootAnimation->UpdateTotalDuration();
7278 else if (anArg == "-dur"
7279 || anArg == "-duration")
7281 if (++anArgIter >= theArgNb)
7283 std::cout << "Syntax error at " << anArg << ".\n";
7287 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]));
7288 aRootAnimation->UpdateTotalDuration();
7290 else if (anArg == "-command"
7292 || anArg == "-invoke"
7294 || anArg == "-proc")
7296 if (++anArgIter >= theArgNb)
7298 std::cout << "Syntax error at " << anArg << ".\n";
7302 Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]);
7303 replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation);
7305 else if (anArg == "-objecttrsf"
7306 || anArg == "-objectransformation"
7307 || anArg == "-objtransformation"
7308 || anArg == "-objtrsf"
7309 || anArg == "-object"
7312 if (++anArgIter >= theArgNb)
7314 std::cout << "Syntax error at " << anArg << ".\n";
7318 TCollection_AsciiString anObjName (theArgVec[anArgIter]);
7319 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS();
7320 if (!aMapOfAIS.IsBound2 (anObjName))
7322 std::cout << "Syntax error: wrong object name at " << anArg << "\n";
7326 Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (aMapOfAIS.Find2 (anObjName));
7327 gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() };
7328 gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() };
7329 gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
7330 Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
7331 Standard_Boolean isTrsfSet = Standard_False;
7332 Standard_Integer aTrsfArgIter = anArgIter + 1;
7333 for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
7335 TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]);
7336 aTrsfArg.LowerCase();
7337 const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1;
7338 if (aTrsfArg.StartsWith ("-rotation")
7339 || aTrsfArg.StartsWith ("-rot"))
7341 isTrsfSet = Standard_True;
7342 if (aTrsfArgIter + 4 >= theArgNb
7343 || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex]))
7345 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7350 else if (aTrsfArg.StartsWith ("-location")
7351 || aTrsfArg.StartsWith ("-loc"))
7353 isTrsfSet = Standard_True;
7354 if (aTrsfArgIter + 3 >= theArgNb
7355 || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex]))
7357 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7362 else if (aTrsfArg.StartsWith ("-scale"))
7364 isTrsfSet = Standard_True;
7365 if (++aTrsfArgIter >= theArgNb)
7367 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7371 const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
7372 if (!aScaleStr.IsRealValue())
7374 std::cout << "Syntax error at " << aTrsfArg << ".\n";
7377 aScales[anIndex] = aScaleStr.RealValue();
7381 anArgIter = aTrsfArgIter - 1;
7387 std::cout << "Syntax error at " << anArg << ".\n";
7390 else if (aTrsfArgIter >= theArgNb)
7392 anArgIter = theArgNb;
7395 aTrsfs[0].SetRotation (aRotQuats[0]);
7396 aTrsfs[1].SetRotation (aRotQuats[1]);
7397 aTrsfs[0].SetTranslationPart (aLocPnts[0]);
7398 aTrsfs[1].SetTranslationPart (aLocPnts[1]);
7399 aTrsfs[0].SetScaleFactor (aScales[0]);
7400 aTrsfs[1].SetScaleFactor (aScales[1]);
7402 Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
7403 replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
7405 else if (anArg == "-viewtrsf"
7406 || anArg == "-view")
7408 Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation);
7409 if (aCamAnimation.IsNull())
7411 aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView);
7412 replaceAnimation (aParentAnimation, anAnimation, aCamAnimation);
7415 Handle(Graphic3d_Camera) aCams[2] =
7417 new Graphic3d_Camera (aCamAnimation->View()->Camera()),
7418 new Graphic3d_Camera (aCamAnimation->View()->Camera())
7421 Standard_Boolean isTrsfSet = Standard_False;
7422 Standard_Integer aViewArgIter = anArgIter + 1;
7423 for (; aViewArgIter < theArgNb; ++aViewArgIter)
7425 TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]);
7426 aViewArg.LowerCase();
7427 const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1;
7428 if (aViewArg.StartsWith ("-scale"))
7430 isTrsfSet = Standard_True;
7431 if (++aViewArgIter >= theArgNb)
7433 std::cout << "Syntax error at " << anArg << ".\n";
7437 const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
7438 if (!aScaleStr.IsRealValue())
7440 std::cout << "Syntax error at " << aViewArg << ".\n";
7443 Standard_Real aScale = aScaleStr.RealValue();
7444 aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale;
7445 aCams[anIndex]->SetScale (aScale);
7447 else if (aViewArg.StartsWith ("-eye")
7448 || aViewArg.StartsWith ("-center")
7449 || aViewArg.StartsWith ("-at")
7450 || aViewArg.StartsWith ("-up"))
7452 isTrsfSet = Standard_True;
7454 if (aViewArgIter + 3 >= theArgNb
7455 || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ))
7457 std::cout << "Syntax error at " << aViewArg << ".\n";
7462 if (aViewArg.StartsWith ("-eye"))
7464 aCams[anIndex]->SetEye (anXYZ);
7466 else if (aViewArg.StartsWith ("-center")
7467 || aViewArg.StartsWith ("-at"))
7469 aCams[anIndex]->SetCenter (anXYZ);
7471 else if (aViewArg.StartsWith ("-up"))
7473 aCams[anIndex]->SetUp (anXYZ);
7478 anArgIter = aViewArgIter - 1;
7484 std::cout << "Syntax error at " << anArg << ".\n";
7487 else if (aViewArgIter >= theArgNb)
7489 anArgIter = theArgNb;
7492 aCamAnimation->SetCameraStart(aCams[0]);
7493 aCamAnimation->SetCameraEnd (aCams[1]);
7497 std::cout << "Syntax error at " << anArg << ".\n";
7502 if (!toPlay && aRecFile.IsEmpty())
7507 // Start animation timeline and process frame updating.
7508 TheIsAnimating = Standard_True;
7509 const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
7510 Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera());
7511 anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
7514 aView->Camera()->Copy (aCameraBack);
7517 const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
7518 if (aRecParams.FpsNum <= 0)
7520 while (!anAnimation->IsStopped())
7522 aCameraBack->Copy (aView->Camera());
7523 const Standard_Real aPts = anAnimation->UpdateTimer();
7526 aView->Camera()->Copy (aCameraBack);
7529 if (aPts >= anUpperPts)
7531 anAnimation->Pause();
7535 if (aView->IsInvalidated())
7541 aView->RedrawImmediate();
7546 // handle user events
7547 theDI.Eval ("after 1 set waiter 1");
7548 theDI.Eval ("vwait waiter");
7550 if (!TheIsAnimating)
7552 anAnimation->Pause();
7558 if (aView->IsInvalidated())
7564 aView->RedrawImmediate();
7569 OSD_Timer aPerfTimer;
7572 Handle(Image_VideoRecorder) aRecorder;
7573 ImageFlipper aFlipper;
7574 Handle(Draw_ProgressIndicator) aProgress;
7575 if (!aRecFile.IsEmpty())
7577 if (aRecParams.Width <= 0
7578 || aRecParams.Height <= 0)
7580 aView->Window()->Size (aRecParams.Width, aRecParams.Height);
7583 aRecorder = new Image_VideoRecorder();
7584 if (!aRecorder->Open (aRecFile.ToCString(), aRecParams))
7586 std::cout << "Error: failed to open video file for recording\n";
7590 aProgress = new Draw_ProgressIndicator (theDI, 1);
7593 // Manage frame-rated animation here
7594 Standard_Real aPts = aPlayStartTime;
7595 int64_t aNbFrames = 0;
7596 Message_ProgressSentry aPSentry (aProgress, "Video recording, sec", 0, Max (1, Standard_Integer(aPlayDuration / aPlaySpeed)), 1);
7597 Standard_Integer aSecondsProgress = 0;
7598 for (; aPts <= anUpperPts && aPSentry.More();)
7600 const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aRecParams.FpsDen) / Standard_Real(aRecParams.FpsNum)) * Standard_Real(aNbFrames));
7601 aPts = aPlayStartTime + aRecPts;
7603 if (!anAnimation->Update (aPts))
7608 if (!aRecorder.IsNull())
7610 V3d_ImageDumpOptions aDumpParams;
7611 aDumpParams.Width = aRecParams.Width;
7612 aDumpParams.Height = aRecParams.Height;
7613 aDumpParams.BufferType = Graphic3d_BT_RGBA;
7614 aDumpParams.StereoOptions = V3d_SDO_MONO;
7615 aDumpParams.ToAdjustAspect = Standard_True;
7616 if (!aView->ToPixMap (aRecorder->ChangeFrame(), aDumpParams))
7618 std::cout << "Error: view dump is failed!\n";
7621 aFlipper.FlipY (aRecorder->ChangeFrame());
7622 if (!aRecorder->PushFrame())
7632 while (aSecondsProgress < Standard_Integer(aRecPts / aPlaySpeed))
7640 anAnimation->Stop();
7641 const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
7642 theDI << "Average FPS: " << aRecFps << "\n"
7643 << "Nb. Frames: " << Standard_Real(aNbFrames);
7648 aView->SetImmediateUpdate (wasImmediateUpdate);
7649 TheIsAnimating = Standard_False;
7654 //=======================================================================
7655 //function : VChangeSelected
7656 //purpose : Adds the shape to selection or remove one from it
7657 //=======================================================================
7658 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
7659 Standard_Integer argc,
7664 di<<"Usage : " << argv[0] << " shape \n";
7668 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7669 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
7670 TCollection_AsciiString aName(argv[1]);
7671 Handle(AIS_InteractiveObject) anAISObject;
7673 if(!aMap.IsBound2(aName))
7675 di<<"Use 'vdisplay' before";
7680 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
7681 if(anAISObject.IsNull()){
7682 di<<"No interactive object \n";
7686 aContext->AddOrRemoveSelected(anAISObject, Standard_True);
7691 //=======================================================================
7692 //function : VNbSelected
7693 //purpose : Returns number of selected objects
7694 //=======================================================================
7695 static Standard_Integer VNbSelected (Draw_Interpretor& di,
7696 Standard_Integer argc,
7701 di << "Usage : " << argv[0] << "\n";
7704 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7705 if(aContext.IsNull())
7707 di << "use 'vinit' command before " << argv[0] << "\n";
7710 di << aContext->NbSelected() << "\n";
7714 //=======================================================================
7715 //function : VPurgeDisplay
7716 //purpose : Switches altialiasing on or off
7717 //=======================================================================
7718 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
7719 Standard_Integer argc,
7724 di << "Usage : " << argv[0] << "\n";
7727 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7728 if (aContext.IsNull())
7730 di << "use 'vinit' command before " << argv[0] << "\n";
7734 di << aContext->PurgeDisplay() << "\n";
7738 //=======================================================================
7739 //function : VSetViewSize
7741 //=======================================================================
7742 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
7743 Standard_Integer argc,
7746 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7747 if(aContext.IsNull())
7749 di << "use 'vinit' command before " << argv[0] << "\n";
7754 di<<"Usage : " << argv[0] << " Size\n";
7757 Standard_Real aSize = Draw::Atof (argv[1]);
7760 di<<"Bad Size value : " << aSize << "\n";
7764 Handle(V3d_View) aView = ViewerTest::CurrentView();
7765 aView->SetSize(aSize);
7769 //=======================================================================
7770 //function : VMoveView
7772 //=======================================================================
7773 static Standard_Integer VMoveView (Draw_Interpretor& di,
7774 Standard_Integer argc,
7777 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7778 if(aContext.IsNull())
7780 di << "use 'vinit' command before " << argv[0] << "\n";
7783 if(argc < 4 || argc > 5)
7785 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
7788 Standard_Real Dx = Draw::Atof (argv[1]);
7789 Standard_Real Dy = Draw::Atof (argv[2]);
7790 Standard_Real Dz = Draw::Atof (argv[3]);
7791 Standard_Boolean aStart = Standard_True;
7794 aStart = (Draw::Atoi (argv[4]) > 0);
7797 Handle(V3d_View) aView = ViewerTest::CurrentView();
7798 aView->Move(Dx,Dy,Dz,aStart);
7802 //=======================================================================
7803 //function : VTranslateView
7805 //=======================================================================
7806 static Standard_Integer VTranslateView (Draw_Interpretor& di,
7807 Standard_Integer argc,
7810 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7811 if(aContext.IsNull())
7813 di << "use 'vinit' command before " << argv[0] << "\n";
7816 if(argc < 4 || argc > 5)
7818 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
7821 Standard_Real Dx = Draw::Atof (argv[1]);
7822 Standard_Real Dy = Draw::Atof (argv[2]);
7823 Standard_Real Dz = Draw::Atof (argv[3]);
7824 Standard_Boolean aStart = Standard_True;
7827 aStart = (Draw::Atoi (argv[4]) > 0);
7830 Handle(V3d_View) aView = ViewerTest::CurrentView();
7831 aView->Translate(Dx,Dy,Dz,aStart);
7835 //=======================================================================
7836 //function : VTurnView
7838 //=======================================================================
7839 static Standard_Integer VTurnView (Draw_Interpretor& di,
7840 Standard_Integer argc,
7843 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7844 if(aContext.IsNull()) {
7845 di << "use 'vinit' command before " << argv[0] << "\n";
7848 if(argc < 4 || argc > 5){
7849 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
7852 Standard_Real Ax = Draw::Atof (argv[1]);
7853 Standard_Real Ay = Draw::Atof (argv[2]);
7854 Standard_Real Az = Draw::Atof (argv[3]);
7855 Standard_Boolean aStart = Standard_True;
7858 aStart = (Draw::Atoi (argv[4]) > 0);
7861 Handle(V3d_View) aView = ViewerTest::CurrentView();
7862 aView->Turn(Ax,Ay,Az,aStart);
7866 //==============================================================================
7867 //function : VTextureEnv
7868 //purpose : ENables or disables environment mapping
7869 //==============================================================================
7870 class OCC_TextureEnv : public Graphic3d_TextureEnv
7873 OCC_TextureEnv(const Standard_CString FileName);
7874 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
7875 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
7876 const Standard_Boolean theModulateFlag,
7877 const Graphic3d_TypeOfTextureFilter theFilter,
7878 const Standard_ShortReal theXScale,
7879 const Standard_ShortReal theYScale,
7880 const Standard_ShortReal theXShift,
7881 const Standard_ShortReal theYShift,
7882 const Standard_ShortReal theAngle);
7883 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
7885 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
7887 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
7888 : Graphic3d_TextureEnv(theFileName)
7892 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
7893 : Graphic3d_TextureEnv(theTexId)
7897 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
7898 const Standard_Boolean theModulateFlag,
7899 const Graphic3d_TypeOfTextureFilter theFilter,
7900 const Standard_ShortReal theXScale,
7901 const Standard_ShortReal theYScale,
7902 const Standard_ShortReal theXShift,
7903 const Standard_ShortReal theYShift,
7904 const Standard_ShortReal theAngle)
7906 myParams->SetRepeat (theRepeatFlag);
7907 myParams->SetModulate (theModulateFlag);
7908 myParams->SetFilter (theFilter);
7909 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
7910 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
7911 myParams->SetRotation (theAngle);
7914 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
7916 // get the active view
7917 Handle(V3d_View) aView = ViewerTest::CurrentView();
7920 std::cerr << "No active view. Please call vinit.\n";
7924 // Checking the input arguments
7925 Standard_Boolean anEnableFlag = Standard_False;
7926 Standard_Boolean isOk = theArgNb >= 2;
7929 TCollection_AsciiString anEnableOpt(theArgVec[1]);
7930 anEnableFlag = anEnableOpt.IsEqual("on");
7931 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
7935 isOk = (theArgNb == 3 || theArgNb == 11);
7938 TCollection_AsciiString aTextureOpt(theArgVec[2]);
7939 isOk = (!aTextureOpt.IsIntegerValue() ||
7940 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
7942 if (isOk && theArgNb == 11)
7944 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
7945 aModulateOpt(theArgVec[4]),
7946 aFilterOpt (theArgVec[5]),
7947 aSScaleOpt (theArgVec[6]),
7948 aTScaleOpt (theArgVec[7]),
7949 aSTransOpt (theArgVec[8]),
7950 aTTransOpt (theArgVec[9]),
7951 anAngleOpt (theArgVec[10]);
7952 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
7953 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
7954 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
7955 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
7956 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
7957 anAngleOpt.IsRealValue());
7964 std::cerr << "Usage :" << std::endl;
7965 std::cerr << theArgVec[0] << " off" << std::endl;
7966 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;
7972 TCollection_AsciiString aTextureOpt(theArgVec[2]);
7973 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
7974 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
7975 new OCC_TextureEnv(theArgVec[2]);
7979 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
7980 aTexEnv->SetTextureParameters(
7981 aRepeatOpt. IsEqual("repeat"),
7982 aModulateOpt.IsEqual("modulate"),
7983 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
7984 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
7985 Graphic3d_TOTF_TRILINEAR,
7986 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
7987 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
7988 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
7989 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
7990 (Standard_ShortReal)Draw::Atof(theArgVec[10])
7993 aView->SetTextureEnv(aTexEnv);
7995 else // Disabling environment mapping
7997 Handle(Graphic3d_TextureEnv) aTexture;
7998 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
8007 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
8009 //! Remove registered clipping plane from all views and objects.
8010 static void removePlane (MapOfPlanes& theRegPlanes,
8011 const TCollection_AsciiString& theName)
8013 Handle(Graphic3d_ClipPlane) aClipPlane;
8014 if (!theRegPlanes.Find (theName, aClipPlane))
8016 std::cout << "Warning: no such plane.\n";
8020 theRegPlanes.UnBind (theName);
8021 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
8022 anIObjIt.More(); anIObjIt.Next())
8024 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
8025 aPrs->RemoveClipPlane (aClipPlane);
8028 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
8029 aViewIt.More(); aViewIt.Next())
8031 const Handle(V3d_View)& aView = aViewIt.Key2();
8032 aView->RemoveClipPlane(aClipPlane);
8035 ViewerTest::RedrawAllViews();
8039 //===============================================================================================
8040 //function : VClipPlane
8042 //===============================================================================================
8043 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8045 // use short-cut for created clip planes map of created (or "registered by name") clip planes
8046 static MapOfPlanes aRegPlanes;
8050 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
8052 theDi << aPlaneIter.Key() << " ";
8057 TCollection_AsciiString aCommand (theArgVec[1]);
8058 aCommand.LowerCase();
8059 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
8060 if (anActiveView.IsNull())
8062 std::cout << "Error: no active view.\n";
8066 // print maximum number of planes for current viewer
8067 if (aCommand == "-maxplanes"
8068 || aCommand == "maxplanes")
8070 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
8071 << " plane slots provided by driver.\n";
8075 // create / delete plane instance
8076 if (aCommand == "-create"
8077 || aCommand == "create"
8078 || aCommand == "-delete"
8079 || aCommand == "delete"
8080 || aCommand == "-clone"
8081 || aCommand == "clone")
8085 std::cout << "Syntax error: plane name is required.\n";
8089 Standard_Boolean toCreate = aCommand == "-create"
8090 || aCommand == "create";
8091 Standard_Boolean toClone = aCommand == "-clone"
8092 || aCommand == "clone";
8093 Standard_Boolean toDelete = aCommand == "-delete"
8094 || aCommand == "delete";
8095 TCollection_AsciiString aPlane (theArgVec[2]);
8099 if (aRegPlanes.IsBound (aPlane))
8101 std::cout << "Warning: existing plane has been overridden.\n";
8106 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8110 else if (toClone) // toClone
8112 if (!aRegPlanes.IsBound (aPlane))
8114 std::cout << "Error: no such plane.\n";
8117 else if (theArgsNb < 4)
8119 std::cout << "Syntax error: enter name for new plane.\n";
8123 TCollection_AsciiString aClone (theArgVec[3]);
8124 if (aRegPlanes.IsBound (aClone))
8126 std::cout << "Error: plane name is in use.\n";
8130 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
8132 aRegPlanes.Bind (aClone, aClipPlane->Clone());
8142 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
8144 aPlane = aPlaneIter.Key();
8145 removePlane (aRegPlanes, aPlane);
8146 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
8151 removePlane (aRegPlanes, aPlane);
8157 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
8162 // set / unset plane command
8163 if (aCommand == "set"
8164 || aCommand == "unset")
8168 std::cout << "Syntax error: need more arguments.\n";
8172 // redirect to new syntax
8173 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
8174 anArgVec.SetValue (1, theArgVec[0]);
8175 anArgVec.SetValue (2, theArgVec[2]);
8176 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
8177 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
8179 anArgVec.SetValue (anIt, theArgVec[anIt]);
8182 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
8185 // change plane command
8186 TCollection_AsciiString aPlaneName;
8187 Handle(Graphic3d_ClipPlane) aClipPlane;
8188 Standard_Integer anArgIter = 0;
8189 if (aCommand == "-change"
8190 || aCommand == "change")
8192 // old syntax support
8195 std::cout << "Syntax error: need more arguments.\n";
8200 aPlaneName = theArgVec[2];
8201 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
8203 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
8207 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
8210 aPlaneName = theArgVec[1];
8215 aPlaneName = theArgVec[1];
8216 aClipPlane = new Graphic3d_ClipPlane();
8217 aRegPlanes.Bind (aPlaneName, aClipPlane);
8218 theDi << "Created new plane " << aPlaneName << ".\n";
8221 if (theArgsNb - anArgIter < 1)
8223 std::cout << "Syntax error: need more arguments.\n";
8227 for (; anArgIter < theArgsNb; ++anArgIter)
8229 const char** aChangeArgs = theArgVec + anArgIter;
8230 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
8231 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
8232 aChangeArg.LowerCase();
8234 Standard_Boolean toEnable = Standard_True;
8235 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
8237 aClipPlane->SetOn (toEnable);
8239 else if (aChangeArg == "-equation"
8240 || aChangeArg == "equation")
8242 if (aNbChangeArgs < 5)
8244 std::cout << "Syntax error: need more arguments.\n";
8248 Standard_Real aCoeffA = Draw::Atof (aChangeArgs [1]);
8249 Standard_Real aCoeffB = Draw::Atof (aChangeArgs [2]);
8250 Standard_Real aCoeffC = Draw::Atof (aChangeArgs [3]);
8251 Standard_Real aCoeffD = Draw::Atof (aChangeArgs [4]);
8252 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
8255 else if (aChangeArg == "-capping"
8256 || aChangeArg == "capping")
8258 if (aNbChangeArgs < 2)
8260 std::cout << "Syntax error: need more arguments.\n";
8264 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8266 aClipPlane->SetCapping (toEnable);
8271 // just skip otherwise (old syntax)
8274 else if (aChangeArg == "-useobjectmaterial"
8275 || aChangeArg == "-useobjectmat"
8276 || aChangeArg == "-useobjmat"
8277 || aChangeArg == "-useobjmaterial")
8279 if (aNbChangeArgs < 2)
8281 std::cout << "Syntax error: need more arguments.\n";
8285 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8287 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
8291 else if (aChangeArg == "-useobjecttexture"
8292 || aChangeArg == "-useobjecttex"
8293 || aChangeArg == "-useobjtexture"
8294 || aChangeArg == "-useobjtex")
8296 if (aNbChangeArgs < 2)
8298 std::cout << "Syntax error: need more arguments.\n";
8302 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8304 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
8308 else if (aChangeArg == "-useobjectshader"
8309 || aChangeArg == "-useobjshader")
8311 if (aNbChangeArgs < 2)
8313 std::cout << "Syntax error: need more arguments.\n";
8317 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
8319 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
8323 else if (aChangeArg == "-color"
8324 || aChangeArg == "color")
8326 Quantity_Color aColor;
8327 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
8332 std::cout << "Syntax error: need more arguments.\n";
8336 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
8337 aMat.SetAmbientColor (aColor);
8338 aMat.SetDiffuseColor (aColor);
8339 aClipPlane->SetCappingMaterial (aMat);
8340 anArgIter += aNbParsed;
8342 else if (aChangeArg == "-texname"
8343 || aChangeArg == "texname")
8345 if (aNbChangeArgs < 2)
8347 std::cout << "Syntax error: need more arguments.\n";
8351 TCollection_AsciiString aTextureName (aChangeArgs[1]);
8352 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
8353 if (!aTexture->IsDone())
8355 aClipPlane->SetCappingTexture (NULL);
8359 aTexture->EnableModulate();
8360 aTexture->EnableRepeat();
8361 aClipPlane->SetCappingTexture (aTexture);
8365 else if (aChangeArg == "-texscale"
8366 || aChangeArg == "texscale")
8368 if (aClipPlane->CappingTexture().IsNull())
8370 std::cout << "Error: no texture is set.\n";
8374 if (aNbChangeArgs < 3)
8376 std::cout << "Syntax error: need more arguments.\n";
8380 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8381 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8382 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
8385 else if (aChangeArg == "-texorigin"
8386 || aChangeArg == "texorigin") // texture origin
8388 if (aClipPlane->CappingTexture().IsNull())
8390 std::cout << "Error: no texture is set.\n";
8394 if (aNbChangeArgs < 3)
8396 std::cout << "Syntax error: need more arguments.\n";
8400 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8401 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
8403 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
8406 else if (aChangeArg == "-texrotate"
8407 || aChangeArg == "texrotate") // texture rotation
8409 if (aClipPlane->CappingTexture().IsNull())
8411 std::cout << "Error: no texture is set.\n";
8415 if (aNbChangeArgs < 2)
8417 std::cout << "Syntax error: need more arguments.\n";
8421 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
8422 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
8425 else if (aChangeArg == "-hatch"
8426 || aChangeArg == "hatch")
8428 if (aNbChangeArgs < 2)
8430 std::cout << "Syntax error: need more arguments.\n";
8434 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
8435 aHatchStr.LowerCase();
8436 if (aHatchStr == "on")
8438 aClipPlane->SetCappingHatchOn();
8440 else if (aHatchStr == "off")
8442 aClipPlane->SetCappingHatchOff();
8446 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
8450 else if (aChangeArg == "-delete"
8451 || aChangeArg == "delete")
8453 removePlane (aRegPlanes, aPlaneName);
8456 else if (aChangeArg == "-set"
8457 || aChangeArg == "-unset")
8459 // set / unset plane command
8460 Standard_Boolean toSet = aChangeArg == "-set";
8461 Standard_Integer anIt = 1;
8462 for (; anIt < aNbChangeArgs; ++anIt)
8464 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
8465 if (anEntityName.IsEmpty()
8466 || anEntityName.Value (1) == '-')
8470 else if (ViewerTest_myViews.IsBound1 (anEntityName))
8472 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
8475 aView->AddClipPlane (aClipPlane);
8479 aView->RemoveClipPlane (aClipPlane);
8483 else if (GetMapOfAIS().IsBound2 (anEntityName))
8485 Handle(AIS_InteractiveObject) aIObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
8488 aIObj->AddClipPlane (aClipPlane);
8492 aIObj->RemoveClipPlane (aClipPlane);
8497 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
8504 // apply to active view
8507 anActiveView->AddClipPlane (aClipPlane);
8511 anActiveView->RemoveClipPlane (aClipPlane);
8516 anArgIter = anArgIter + anIt - 1;
8521 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
8526 ViewerTest::RedrawAllViews();
8530 //===============================================================================================
8531 //function : VZRange
8533 //===============================================================================================
8534 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8536 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
8538 if (aCurrentView.IsNull())
8540 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
8544 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
8548 theDi << "ZNear: " << aCamera->ZNear() << "\n";
8549 theDi << "ZFar: " << aCamera->ZFar() << "\n";
8555 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
8556 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
8558 if (aNewZNear >= aNewZFar)
8560 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
8564 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
8566 std::cout << theArgVec[0] << ": invalid arguments: ";
8567 std::cout << "znear, zfar should be positive for perspective camera.\n";
8571 aCamera->SetZRange (aNewZNear, aNewZFar);
8575 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
8579 aCurrentView->Redraw();
8584 //===============================================================================================
8585 //function : VAutoZFit
8587 //===============================================================================================
8588 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
8590 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
8592 if (aCurrentView.IsNull())
8594 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
8598 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
8602 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
8608 theDi << "Auto z-fit mode: \n"
8609 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
8610 << "Scale: " << aScale << "\n";
8614 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
8618 aScale = Draw::Atoi (theArgVec[2]);
8621 aCurrentView->SetAutoZFitMode (isOn, aScale);
8622 aCurrentView->AutoZFit();
8623 aCurrentView->Redraw();
8628 //! Auxiliary function to print projection type
8629 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
8631 switch (theProjType)
8633 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
8634 case Graphic3d_Camera::Projection_Perspective: return "perspective";
8635 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
8636 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
8637 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
8642 //===============================================================================================
8643 //function : VCamera
8645 //===============================================================================================
8646 static int VCamera (Draw_Interpretor& theDI,
8647 Standard_Integer theArgsNb,
8648 const char** theArgVec)
8650 Handle(V3d_View) aView = ViewerTest::CurrentView();
8653 std::cout << "Error: no active view.\n";
8657 Handle(Graphic3d_Camera) aCamera = aView->Camera();
8660 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
8661 theDI << "FOVy: " << aCamera->FOVy() << "\n";
8662 theDI << "Distance: " << aCamera->Distance() << "\n";
8663 theDI << "IOD: " << aCamera->IOD() << "\n";
8664 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
8665 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
8666 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
8670 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
8672 Standard_CString anArg = theArgVec[anArgIter];
8673 TCollection_AsciiString anArgCase (anArg);
8674 anArgCase.LowerCase();
8675 if (anArgCase == "-proj"
8676 || anArgCase == "-projection"
8677 || anArgCase == "-projtype"
8678 || anArgCase == "-projectiontype")
8680 theDI << projTypeName (aCamera->ProjectionType()) << " ";
8682 else if (anArgCase == "-ortho"
8683 || anArgCase == "-orthographic")
8685 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
8687 else if (anArgCase == "-persp"
8688 || anArgCase == "-perspective"
8689 || anArgCase == "-perspmono"
8690 || anArgCase == "-perspectivemono"
8691 || anArgCase == "-mono")
8693 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
8695 else if (anArgCase == "-stereo"
8696 || anArgCase == "-stereoscopic"
8697 || anArgCase == "-perspstereo"
8698 || anArgCase == "-perspectivestereo")
8700 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
8702 else if (anArgCase == "-left"
8703 || anArgCase == "-lefteye"
8704 || anArgCase == "-monoleft"
8705 || anArgCase == "-monolefteye"
8706 || anArgCase == "-perpsleft"
8707 || anArgCase == "-perpslefteye")
8709 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
8711 else if (anArgCase == "-right"
8712 || anArgCase == "-righteye"
8713 || anArgCase == "-monoright"
8714 || anArgCase == "-monorighteye"
8715 || anArgCase == "-perpsright")
8717 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
8719 else if (anArgCase == "-dist"
8720 || anArgCase == "-distance")
8722 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8723 if (anArgValue != NULL
8724 && *anArgValue != '-')
8727 aCamera->SetDistance (Draw::Atof (anArgValue));
8730 theDI << aCamera->Distance() << " ";
8732 else if (anArgCase == "-iod")
8734 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8735 if (anArgValue != NULL
8736 && *anArgValue != '-')
8739 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
8742 theDI << aCamera->IOD() << " ";
8744 else if (anArgCase == "-iodtype")
8746 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
8747 TCollection_AsciiString anValueCase (anArgValue);
8748 anValueCase.LowerCase();
8749 if (anValueCase == "abs"
8750 || anValueCase == "absolute")
8753 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
8756 else if (anValueCase == "rel"
8757 || anValueCase == "relative")
8760 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
8763 else if (*anArgValue != '-')
8765 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
8768 switch (aCamera->GetIODType())
8770 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
8771 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
8774 else if (anArgCase == "-zfocus")
8776 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8777 if (anArgValue != NULL
8778 && *anArgValue != '-')
8781 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
8784 theDI << aCamera->ZFocus() << " ";
8786 else if (anArgCase == "-zfocustype")
8788 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
8789 TCollection_AsciiString anValueCase (anArgValue);
8790 anValueCase.LowerCase();
8791 if (anValueCase == "abs"
8792 || anValueCase == "absolute")
8795 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
8798 else if (anValueCase == "rel"
8799 || anValueCase == "relative")
8802 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
8805 else if (*anArgValue != '-')
8807 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
8810 switch (aCamera->ZFocusType())
8812 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
8813 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
8816 else if (anArgCase == "-fov"
8817 || anArgCase == "-fovy")
8819 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8820 if (anArgValue != NULL
8821 && *anArgValue != '-')
8824 aCamera->SetFOVy (Draw::Atof (anArgValue));
8827 theDI << aCamera->FOVy() << " ";
8831 std::cout << "Error: unknown argument '" << anArg << "'\n";
8842 //! Parse stereo output mode
8843 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
8844 Graphic3d_StereoMode& theMode)
8846 TCollection_AsciiString aFlag (theArg);
8848 if (aFlag == "quadbuffer")
8850 theMode = Graphic3d_StereoMode_QuadBuffer;
8852 else if (aFlag == "anaglyph")
8854 theMode = Graphic3d_StereoMode_Anaglyph;
8856 else if (aFlag == "row"
8857 || aFlag == "rowinterlaced")
8859 theMode = Graphic3d_StereoMode_RowInterlaced;
8861 else if (aFlag == "col"
8862 || aFlag == "colinterlaced"
8863 || aFlag == "columninterlaced")
8865 theMode = Graphic3d_StereoMode_ColumnInterlaced;
8867 else if (aFlag == "chess"
8868 || aFlag == "chessboard")
8870 theMode = Graphic3d_StereoMode_ChessBoard;
8872 else if (aFlag == "sbs"
8873 || aFlag == "sidebyside")
8875 theMode = Graphic3d_StereoMode_SideBySide;
8877 else if (aFlag == "ou"
8878 || aFlag == "overunder")
8880 theMode = Graphic3d_StereoMode_OverUnder;
8882 else if (aFlag == "pageflip"
8883 || aFlag == "softpageflip")
8885 theMode = Graphic3d_StereoMode_SoftPageFlip;
8889 return Standard_False;
8891 return Standard_True;
8894 //! Parse anaglyph filter
8895 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
8896 Graphic3d_RenderingParams::Anaglyph& theFilter)
8898 TCollection_AsciiString aFlag (theArg);
8900 if (aFlag == "redcyansimple")
8902 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
8904 else if (aFlag == "redcyan"
8905 || aFlag == "redcyanoptimized")
8907 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
8909 else if (aFlag == "yellowbluesimple")
8911 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
8913 else if (aFlag == "yellowblue"
8914 || aFlag == "yellowblueoptimized")
8916 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
8918 else if (aFlag == "greenmagenta"
8919 || aFlag == "greenmagentasimple")
8921 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
8925 return Standard_False;
8927 return Standard_True;
8930 //==============================================================================
8931 //function : VStereo
8933 //==============================================================================
8935 static int VStereo (Draw_Interpretor& theDI,
8936 Standard_Integer theArgNb,
8937 const char** theArgVec)
8939 Handle(V3d_View) aView = ViewerTest::CurrentView();
8944 std::cout << "Error: no active viewer!\n";
8948 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
8949 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
8952 TCollection_AsciiString aMode;
8953 switch (aView->RenderingParams().StereoMode)
8955 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
8956 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
8957 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
8958 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
8959 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
8960 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
8961 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
8962 case Graphic3d_StereoMode_Anaglyph :
8964 switch (aView->RenderingParams().AnaglyphFilter)
8966 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
8967 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
8968 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
8969 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
8970 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
8975 theDI << "Mode " << aMode << "\n";
8980 Handle(Graphic3d_Camera) aCamera;
8981 Graphic3d_RenderingParams* aParams = NULL;
8982 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
8983 if (!aView.IsNull())
8985 aParams = &aView->ChangeRenderingParams();
8986 aMode = aParams->StereoMode;
8987 aCamera = aView->Camera();
8990 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
8991 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
8993 Standard_CString anArg = theArgVec[anArgIter];
8994 TCollection_AsciiString aFlag (anArg);
8996 if (anUpdateTool.parseRedrawMode (aFlag))
9000 else if (aFlag == "0"
9003 if (++anArgIter < theArgNb)
9005 std::cout << "Error: wrong number of arguments!\n";
9009 if (!aCamera.IsNull()
9010 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
9012 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
9014 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
9017 else if (aFlag == "1"
9020 if (++anArgIter < theArgNb)
9022 std::cout << "Error: wrong number of arguments!\n";
9026 if (!aCamera.IsNull())
9028 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9030 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9033 else if (aFlag == "-reverse"
9034 || aFlag == "-reversed"
9035 || aFlag == "-swap")
9037 Standard_Boolean toEnable = Standard_True;
9038 if (++anArgIter < theArgNb
9039 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9043 aParams->ToReverseStereo = toEnable;
9045 else if (aFlag == "-noreverse"
9046 || aFlag == "-noswap")
9048 Standard_Boolean toDisable = Standard_True;
9049 if (++anArgIter < theArgNb
9050 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
9054 aParams->ToReverseStereo = !toDisable;
9056 else if (aFlag == "-mode"
9057 || aFlag == "-stereomode")
9059 if (++anArgIter >= theArgNb
9060 || !parseStereoMode (theArgVec[anArgIter], aMode))
9062 std::cout << "Error: syntax error at '" << anArg << "'\n";
9066 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9068 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9071 else if (aFlag == "-anaglyph"
9072 || aFlag == "-anaglyphfilter")
9074 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
9075 if (++anArgIter >= theArgNb
9076 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
9078 std::cout << "Error: syntax error at '" << anArg << "'\n";
9082 aMode = Graphic3d_StereoMode_Anaglyph;
9083 aParams->AnaglyphFilter = aFilter;
9085 else if (parseStereoMode (anArg, aMode)) // short syntax
9087 if (aMode == Graphic3d_StereoMode_QuadBuffer)
9089 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
9094 std::cout << "Error: syntax error at '" << anArg << "'\n";
9099 if (!aView.IsNull())
9101 aParams->StereoMode = aMode;
9102 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
9107 //===============================================================================================
9108 //function : VDefaults
9110 //===============================================================================================
9111 static int VDefaults (Draw_Interpretor& theDi,
9112 Standard_Integer theArgsNb,
9113 const char** theArgVec)
9115 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
9118 std::cerr << "No active viewer!\n";
9122 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
9125 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
9127 theDi << "DeflType: relative\n"
9128 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
9132 theDi << "DeflType: absolute\n"
9133 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
9135 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
9136 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
9140 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
9142 TCollection_AsciiString anArg (theArgVec[anArgIter]);
9144 if (anArg == "-ABSDEFL"
9145 || anArg == "-ABSOLUTEDEFLECTION"
9147 || anArg == "-DEFLECTION")
9149 if (++anArgIter >= theArgsNb)
9151 std::cout << "Error: wrong syntax at " << anArg << "\n";
9154 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
9155 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
9157 else if (anArg == "-RELDEFL"
9158 || anArg == "-RELATIVEDEFLECTION"
9159 || anArg == "-DEVCOEFF"
9160 || anArg == "-DEVIATIONCOEFF"
9161 || anArg == "-DEVIATIONCOEFFICIENT")
9163 if (++anArgIter >= theArgsNb)
9165 std::cout << "Error: wrong syntax at " << anArg << "\n";
9168 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
9169 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
9171 else if (anArg == "-ANGDEFL"
9172 || anArg == "-ANGULARDEFL"
9173 || anArg == "-ANGULARDEFLECTION")
9175 if (++anArgIter >= theArgsNb)
9177 std::cout << "Error: wrong syntax at " << anArg << "\n";
9180 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
9181 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
9183 else if (anArg == "-AUTOTR"
9184 || anArg == "-AUTOTRIANG"
9185 || anArg == "-AUTOTRIANGULATION")
9187 if (++anArgIter >= theArgsNb)
9189 std::cout << "Error: wrong syntax at " << anArg << "\n";
9192 TCollection_AsciiString aValue (theArgVec[anArgIter]);
9197 aDefParams->SetAutoTriangulation (Standard_True);
9199 else if (aValue == "off"
9202 aDefParams->SetAutoTriangulation (Standard_False);
9207 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
9214 //! Auxiliary method
9215 inline void addLight (const Handle(V3d_Light)& theLightNew,
9216 const Standard_Boolean theIsGlobal)
9218 if (theLightNew.IsNull())
9225 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
9229 ViewerTest::CurrentView()->SetLightOn (theLightNew);
9233 //! Auxiliary method
9234 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
9236 TCollection_AsciiString anArgNextCase (theArgNext);
9237 anArgNextCase.UpperCase();
9238 if (anArgNextCase.Length() > 5
9239 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
9241 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
9245 return theArgNext.IntegerValue();
9249 //===============================================================================================
9252 //===============================================================================================
9253 static int VLight (Draw_Interpretor& theDi,
9254 Standard_Integer theArgsNb,
9255 const char** theArgVec)
9257 Handle(V3d_View) aView = ViewerTest::CurrentView();
9258 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9260 || aViewer.IsNull())
9262 std::cerr << "No active viewer!\n";
9266 Standard_Real anXYZ[3] = {};
9267 Standard_Real anAtten[2] = {};
9270 // print lights info
9271 Standard_Integer aLightId = 0;
9272 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
9274 Handle(V3d_Light) aLight = aLightIter.Value();
9275 const Quantity_Color aColor = aLight->Color();
9276 theDi << "Light" << aLightId << "\n";
9277 switch (aLight->Type())
9281 theDi << " Type: Ambient\n";
9282 theDi << " Intensity: " << aLight->Intensity() << "\n";
9285 case V3d_DIRECTIONAL:
9287 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
9288 theDi << " Type: Directional\n";
9289 theDi << " Intensity: " << aLight->Intensity() << "\n";
9290 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9291 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
9292 if (!aLightDir.IsNull())
9294 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9295 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9296 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
9297 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9301 case V3d_POSITIONAL:
9303 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
9304 theDi << " Type: Positional\n";
9305 theDi << " Intensity: " << aLight->Intensity() << "\n";
9306 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9307 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
9308 if (!aLightPos.IsNull())
9310 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9311 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9312 aLightPos->Attenuation (anAtten[0], anAtten[1]);
9313 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
9319 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
9320 theDi << " Type: Spot\n";
9321 theDi << " Intensity: " << aLight->Intensity() << "\n";
9322 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
9323 if (!aLightSpot.IsNull())
9325 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
9326 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9327 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
9328 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
9329 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
9330 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
9331 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
9332 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
9338 theDi << " Type: UNKNOWN\n";
9342 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
9346 Handle(V3d_Light) aLightNew;
9347 Handle(V3d_Light) aLightOld;
9348 Standard_Boolean isGlobal = Standard_True;
9349 Standard_Boolean toCreate = Standard_False;
9350 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
9351 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
9353 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
9354 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
9355 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
9356 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
9357 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
9359 TCollection_AsciiString aName, aValue;
9360 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
9361 TCollection_AsciiString anArgCase (anArg);
9362 anArgCase.UpperCase();
9363 if (anUpdateTool.parseRedrawMode (anArg))
9368 if (anArgCase.IsEqual ("NEW")
9369 || anArgCase.IsEqual ("ADD")
9370 || anArgCase.IsEqual ("CREATE"))
9372 toCreate = Standard_True;
9374 else if (anArgCase.IsEqual ("GLOB")
9375 || anArgCase.IsEqual ("GLOBAL"))
9377 isGlobal = Standard_True;
9379 else if (anArgCase.IsEqual ("LOC")
9380 || anArgCase.IsEqual ("LOCAL"))
9382 isGlobal = Standard_False;
9384 else if (anArgCase.IsEqual ("DEF")
9385 || anArgCase.IsEqual ("DEFAULTS"))
9387 toCreate = Standard_False;
9388 aViewer->SetDefaultLights();
9390 else if (anArgCase.IsEqual ("CLR")
9391 || anArgCase.IsEqual ("CLEAR"))
9393 toCreate = Standard_False;
9394 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
9396 Handle(V3d_Light) aLight = aLightIter.Value();
9397 aViewer->DelLight (aLight);
9398 aLightIter = aView->ActiveLightIterator();
9401 else if (anArgCase.IsEqual ("AMB")
9402 || anArgCase.IsEqual ("AMBIENT")
9403 || anArgCase.IsEqual ("AMBLIGHT"))
9405 addLight (aLightNew, isGlobal);
9408 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9411 toCreate = Standard_False;
9412 aLightNew = new V3d_AmbientLight (aViewer);
9414 else if (anArgCase.IsEqual ("DIRECTIONAL")
9415 || anArgCase.IsEqual ("DIRLIGHT"))
9417 addLight (aLightNew, isGlobal);
9420 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9423 toCreate = Standard_False;
9424 aLightNew = new V3d_DirectionalLight (aViewer);
9426 else if (anArgCase.IsEqual ("SPOT")
9427 || anArgCase.IsEqual ("SPOTLIGHT"))
9429 addLight (aLightNew, isGlobal);
9432 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9435 toCreate = Standard_False;
9436 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
9438 else if (anArgCase.IsEqual ("POSLIGHT")
9439 || anArgCase.IsEqual ("POSITIONAL"))
9441 addLight (aLightNew, isGlobal);
9444 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9447 toCreate = Standard_False;
9448 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
9450 else if (anArgCase.IsEqual ("CHANGE"))
9452 addLight (aLightNew, isGlobal);
9453 aLightNew.Nullify();
9454 if (++anArgIt >= theArgsNb)
9456 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9460 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
9461 Standard_Integer aLightIt = 0;
9462 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
9464 if (aLightIt == aLightId)
9466 aLightOld = aLightIter.Value();
9471 if (aLightOld.IsNull())
9473 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
9477 else if (anArgCase.IsEqual ("DEL")
9478 || anArgCase.IsEqual ("DELETE"))
9480 Handle(V3d_Light) aLightDel;
9481 if (++anArgIt >= theArgsNb)
9483 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9487 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
9488 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
9489 Standard_Integer aLightIt = 0;
9490 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
9492 aLightDel = aLightIter.Value();
9493 if (aLightIt == aLightDelId)
9498 if (!aLightDel.IsNull())
9500 aViewer->DelLight (aLightDel);
9503 else if (anArgCase.IsEqual ("COLOR")
9504 || anArgCase.IsEqual ("COLOUR"))
9506 if (++anArgIt >= theArgsNb)
9508 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9512 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
9513 anArgNext.UpperCase();
9514 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
9515 if (!aLightCurr.IsNull())
9517 aLightCurr->SetColor (aColor);
9520 else if (anArgCase.IsEqual ("POS")
9521 || anArgCase.IsEqual ("POSITION"))
9523 if ((anArgIt + 3) >= theArgsNb)
9525 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9529 anXYZ[0] = Atof (theArgVec[++anArgIt]);
9530 anXYZ[1] = Atof (theArgVec[++anArgIt]);
9531 anXYZ[2] = Atof (theArgVec[++anArgIt]);
9532 if (!aLightDir.IsNull())
9534 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
9536 else if (!aLightPos.IsNull())
9538 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
9540 else if (!aLightSpot.IsNull())
9542 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
9546 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9550 else if (anArgCase.IsEqual ("DIR")
9551 || anArgCase.IsEqual ("DIRECTION"))
9553 if ((anArgIt + 3) >= theArgsNb)
9555 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9559 anXYZ[0] = Atof (theArgVec[++anArgIt]);
9560 anXYZ[1] = Atof (theArgVec[++anArgIt]);
9561 anXYZ[2] = Atof (theArgVec[++anArgIt]);
9562 if (!aLightDir.IsNull())
9564 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
9566 else if (!aLightSpot.IsNull())
9568 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
9572 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9576 else if (anArgCase.IsEqual ("SM")
9577 || anArgCase.IsEqual ("SMOOTHNESS"))
9579 if (++anArgIt >= theArgsNb)
9581 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9585 Standard_Real aSmoothness = Atof (theArgVec[anArgIt]);
9587 if (fabs (aSmoothness) < Precision::Confusion())
9589 aLightCurr->SetIntensity (1.f);
9591 else if (fabs (aLightCurr->Smoothness()) < Precision::Confusion())
9593 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
9597 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
9598 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
9601 if (!aLightPos.IsNull())
9603 aLightPos->SetSmoothRadius (aSmoothness);
9605 else if (!aLightDir.IsNull())
9607 aLightDir->SetSmoothAngle (aSmoothness);
9610 else if (anArgCase.IsEqual ("INT")
9611 || anArgCase.IsEqual ("INTENSITY"))
9613 if (++anArgIt >= theArgsNb)
9615 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9619 Standard_Real aIntensity = Atof (theArgVec[anArgIt]);
9621 if (!aLightCurr.IsNull())
9623 aLightCurr->SetIntensity (aIntensity);
9626 else if (anArgCase.IsEqual ("ANG")
9627 || anArgCase.IsEqual ("ANGLE"))
9629 if (++anArgIt >= theArgsNb)
9631 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9635 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
9637 if (!aLightSpot.IsNull())
9639 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
9642 else if (anArgCase.IsEqual ("CONSTATTEN")
9643 || anArgCase.IsEqual ("CONSTATTENUATION"))
9645 if (++anArgIt >= theArgsNb)
9647 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9651 if (!aLightPos.IsNull())
9653 aLightPos->Attenuation (anAtten[0], anAtten[1]);
9654 anAtten[0] = Atof (theArgVec[anArgIt]);
9655 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
9657 else if (!aLightSpot.IsNull())
9659 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
9660 anAtten[0] = Atof (theArgVec[anArgIt]);
9661 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
9665 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9669 else if (anArgCase.IsEqual ("LINATTEN")
9670 || anArgCase.IsEqual ("LINEARATTEN")
9671 || anArgCase.IsEqual ("LINEARATTENUATION"))
9673 if (++anArgIt >= theArgsNb)
9675 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9679 if (!aLightPos.IsNull())
9681 aLightPos->Attenuation (anAtten[0], anAtten[1]);
9682 anAtten[1] = Atof (theArgVec[anArgIt]);
9683 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
9685 else if (!aLightSpot.IsNull())
9687 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
9688 anAtten[1] = Atof (theArgVec[anArgIt]);
9689 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
9693 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9697 else if (anArgCase.IsEqual ("EXP")
9698 || anArgCase.IsEqual ("EXPONENT")
9699 || anArgCase.IsEqual ("SPOTEXP")
9700 || anArgCase.IsEqual ("SPOTEXPONENT"))
9702 if (++anArgIt >= theArgsNb)
9704 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9708 if (!aLightSpot.IsNull())
9710 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
9714 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9718 else if (anArgCase.IsEqual ("HEAD")
9719 || anArgCase.IsEqual ("HEADLIGHT"))
9721 if (++anArgIt >= theArgsNb)
9723 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9727 if (aLightAmb.IsNull()
9728 && !aLightCurr.IsNull())
9730 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
9734 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
9740 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
9744 addLight (aLightNew, isGlobal);
9745 aViewer->UpdateLights();
9750 //=======================================================================
9751 //function : VRenderParams
9752 //purpose : Enables/disables rendering features
9753 //=======================================================================
9755 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
9756 Standard_Integer theArgNb,
9757 const char** theArgVec)
9759 Handle(V3d_View) aView = ViewerTest::CurrentView();
9762 std::cerr << "Error: no active viewer!\n";
9766 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
9767 TCollection_AsciiString aCmdName (theArgVec[0]);
9768 aCmdName.LowerCase();
9769 if (aCmdName == "vraytrace")
9773 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
9776 else if (theArgNb == 2)
9778 TCollection_AsciiString aValue (theArgVec[1]);
9783 aParams.Method = Graphic3d_RM_RAYTRACING;
9787 else if (aValue == "off"
9790 aParams.Method = Graphic3d_RM_RASTERIZATION;
9796 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
9802 std::cout << "Error: wrong number of arguments\n";
9809 theDI << "renderMode: ";
9810 switch (aParams.Method)
9812 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
9813 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
9816 theDI << "transparency: ";
9817 switch (aParams.TransparencyMethod)
9819 case Graphic3d_RTM_BLEND_UNORDERED: theDI << "Basic blended transparency with non-commuting operator "; break;
9820 case Graphic3d_RTM_BLEND_OIT: theDI << "Weighted Blended Order-Independent Transparency, depth weight factor: "
9821 << TCollection_AsciiString (aParams.OitDepthFactor); break;
9824 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
9825 theDI << "rendScale: " << aParams.RenderResolutionScale << "\n";
9826 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
9827 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
9828 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
9829 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
9830 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
9831 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
9832 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
9833 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
9834 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
9835 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
9836 theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
9837 theDI << "nb tiles (iss): " << aParams.NbRayTracingTiles << "\n";
9838 theDI << "shadingModel: ";
9839 switch (aView->ShadingModel())
9841 case V3d_COLOR: theDI << "color"; break;
9842 case V3d_FLAT: theDI << "flat"; break;
9843 case V3d_GOURAUD: theDI << "gouraud"; break;
9844 case V3d_PHONG: theDI << "phong"; break;
9850 Standard_Boolean toPrint = Standard_False;
9851 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
9852 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
9854 Standard_CString anArg (theArgVec[anArgIter]);
9855 TCollection_AsciiString aFlag (anArg);
9857 if (anUpdateTool.parseRedrawMode (aFlag))
9861 else if (aFlag == "-echo"
9862 || aFlag == "-print")
9864 toPrint = Standard_True;
9865 anUpdateTool.Invalidate();
9867 else if (aFlag == "-mode"
9868 || aFlag == "-rendermode"
9869 || aFlag == "-render_mode")
9873 switch (aParams.Method)
9875 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
9876 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
9882 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9886 else if (aFlag == "-ray"
9887 || aFlag == "-raytrace")
9891 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
9895 aParams.Method = Graphic3d_RM_RAYTRACING;
9897 else if (aFlag == "-rast"
9898 || aFlag == "-raster"
9899 || aFlag == "-rasterization")
9903 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
9907 aParams.Method = Graphic3d_RM_RASTERIZATION;
9909 else if (aFlag == "-msaa")
9913 theDI << aParams.NbMsaaSamples << " ";
9916 else if (++anArgIter >= theArgNb)
9918 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9922 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
9925 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
9930 aParams.NbMsaaSamples = aNbSamples;
9933 else if (aFlag == "-oit")
9937 if (aParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT)
9939 theDI << "on, depth weight factor: " << TCollection_AsciiString (aParams.OitDepthFactor) << " ";
9943 theDI << "off" << " ";
9947 else if (++anArgIter >= theArgNb)
9949 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9953 TCollection_AsciiString aParam = theArgVec[anArgIter];
9955 if (aParam.IsRealValue())
9957 const Standard_ShortReal aWeight = (Standard_ShortReal) Draw::Atof (theArgVec[anArgIter]);
9958 if (aWeight < 0.f || aWeight > 1.f)
9960 std::cerr << "Error: invalid value of Weighted Order-Independent Transparency depth weight factor " << aWeight << ". Should be within range [0.0; 1.0]\n";
9964 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_OIT;
9965 aParams.OitDepthFactor = aWeight;
9967 else if (aParam == "off")
9969 aParams.TransparencyMethod = Graphic3d_RTM_BLEND_UNORDERED;
9973 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9977 else if (aFlag == "-rendscale"
9978 || aFlag == "-renderscale"
9979 || aFlag == "-renderresolutionscale")
9983 theDI << aParams.RenderResolutionScale << " ";
9986 else if (++anArgIter >= theArgNb)
9988 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9992 const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
9995 std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n";
10000 aParams.RenderResolutionScale = Standard_ShortReal(aScale);
10003 else if (aFlag == "-raydepth"
10004 || aFlag == "-ray_depth")
10008 theDI << aParams.RaytracingDepth << " ";
10011 else if (++anArgIter >= theArgNb)
10013 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10017 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
10019 // We allow RaytracingDepth be more than 10 in case of GI enabled
10020 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
10022 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
10027 aParams.RaytracingDepth = aDepth;
10030 else if (aFlag == "-shad"
10031 || aFlag == "-shadows")
10035 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
10039 Standard_Boolean toEnable = Standard_True;
10040 if (++anArgIter < theArgNb
10041 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10045 aParams.IsShadowEnabled = toEnable;
10047 else if (aFlag == "-refl"
10048 || aFlag == "-reflections")
10052 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
10056 Standard_Boolean toEnable = Standard_True;
10057 if (++anArgIter < theArgNb
10058 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10062 aParams.IsReflectionEnabled = toEnable;
10064 else if (aFlag == "-fsaa")
10068 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
10072 Standard_Boolean toEnable = Standard_True;
10073 if (++anArgIter < theArgNb
10074 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10078 aParams.IsAntialiasingEnabled = toEnable;
10080 else if (aFlag == "-gleam")
10084 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
10088 Standard_Boolean toEnable = Standard_True;
10089 if (++anArgIter < theArgNb
10090 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10094 aParams.IsTransparentShadowEnabled = toEnable;
10096 else if (aFlag == "-gi")
10100 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
10104 Standard_Boolean toEnable = Standard_True;
10105 if (++anArgIter < theArgNb
10106 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10110 aParams.IsGlobalIlluminationEnabled = toEnable;
10113 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
10116 else if (aFlag == "-blockedrng"
10117 || aFlag == "-brng")
10121 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
10125 Standard_Boolean toEnable = Standard_True;
10126 if (++anArgIter < theArgNb
10127 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10131 aParams.CoherentPathTracingMode = toEnable;
10133 else if (aFlag == "-maxrad")
10137 theDI << aParams.RadianceClampingValue << " ";
10140 else if (++anArgIter >= theArgNb)
10142 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10146 const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
10147 if (!aMaxRadStr.IsRealValue())
10149 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10153 const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
10154 if (aMaxRadiance <= 0.0)
10156 std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n";
10161 aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
10164 else if (aFlag == "-iss")
10168 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
10172 Standard_Boolean toEnable = Standard_True;
10173 if (++anArgIter < theArgNb
10174 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10178 aParams.AdaptiveScreenSampling = toEnable;
10180 else if (aFlag == "-issd")
10184 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
10188 Standard_Boolean toEnable = Standard_True;
10189 if (++anArgIter < theArgNb
10190 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10194 aParams.ShowSamplingTiles = toEnable;
10196 else if (aFlag == "-nbtiles")
10200 theDI << aParams.NbRayTracingTiles << " ";
10203 else if (++anArgIter >= theArgNb)
10205 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10209 const Standard_Integer aNbTiles = Draw::Atoi (theArgVec[anArgIter]);
10213 std::cerr << "Error: invalid number of ISS tiles " << aNbTiles << ".\n";
10214 std::cerr << "Specify value in range [64, 1024].\n";
10219 aParams.NbRayTracingTiles = aNbTiles;
10222 else if (aFlag == "-env")
10226 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
10230 Standard_Boolean toEnable = Standard_True;
10231 if (++anArgIter < theArgNb
10232 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10236 aParams.UseEnvironmentMapBackground = toEnable;
10238 else if (aFlag == "-twoside")
10242 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
10246 Standard_Boolean toEnable = Standard_True;
10247 if (++anArgIter < theArgNb
10248 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10252 aParams.TwoSidedBsdfModels = toEnable;
10254 else if (aFlag == "-shademodel"
10255 || aFlag == "-shadingmodel"
10256 || aFlag == "-shading")
10260 switch (aView->ShadingModel())
10262 case V3d_COLOR: theDI << "color "; break;
10263 case V3d_FLAT: theDI << "flat "; break;
10264 case V3d_GOURAUD: theDI << "gouraud "; break;
10265 case V3d_PHONG: theDI << "phong "; break;
10270 if (++anArgIter >= theArgNb)
10272 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10275 TCollection_AsciiString aMode (theArgVec[anArgIter]);
10277 if (aMode == "color"
10278 || aMode == "none")
10280 aView->SetShadingModel (V3d_COLOR);
10282 else if (aMode == "flat"
10283 || aMode == "facet")
10285 aView->SetShadingModel (V3d_FLAT);
10287 else if (aMode == "gouraud"
10288 || aMode == "vertex"
10289 || aMode == "vert")
10291 aView->SetShadingModel (V3d_GOURAUD);
10293 else if (aMode == "phong"
10294 || aMode == "fragment"
10296 || aMode == "pixel")
10298 aView->SetShadingModel (V3d_PHONG);
10302 std::cout << "Error: unknown shading model '" << aMode << "'\n";
10306 else if (aFlag == "-resolution")
10308 if (++anArgIter >= theArgNb)
10310 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
10314 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
10315 if (aResolution.IsIntegerValue())
10317 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
10321 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10325 else if (aFlag == "-rebuildglsl"
10326 || aFlag == "-rebuild")
10330 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
10334 Standard_Boolean toEnable = Standard_True;
10335 if (++anArgIter < theArgNb
10336 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
10340 aParams.RebuildRayTracingShaders = toEnable;
10342 else if (aFlag == "-focal")
10344 if (++anArgIter >= theArgNb)
10346 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10350 TCollection_AsciiString aParam (theArgVec[anArgIter]);
10351 if (aParam.IsRealValue())
10353 float aFocalDist = static_cast<float> (aParam.RealValue());
10354 if (aFocalDist < 0)
10356 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
10359 aView->ChangeRenderingParams().CameraFocalPlaneDist = aFocalDist;
10363 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10367 else if (aFlag == "-aperture")
10369 if (++anArgIter >= theArgNb)
10371 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10375 TCollection_AsciiString aParam(theArgVec[anArgIter]);
10376 if (aParam.IsRealValue())
10378 float aApertureSize = static_cast<float> (aParam.RealValue());
10379 if (aApertureSize < 0)
10381 std::cout << "Error: parameter can't be negative at argument '" << anArg << "'.\n";
10384 aView->ChangeRenderingParams().CameraApertureRadius = aApertureSize;
10388 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10392 else if (aFlag == "-exposure")
10394 if (++anArgIter >= theArgNb)
10396 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10400 TCollection_AsciiString anExposure (theArgVec[anArgIter]);
10401 if (anExposure.IsRealValue())
10403 aView->ChangeRenderingParams().Exposure = static_cast<float> (anExposure.RealValue());
10407 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10411 else if (aFlag == "-whitepoint")
10413 if (++anArgIter >= theArgNb)
10415 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10419 TCollection_AsciiString aWhitePoint (theArgVec[anArgIter]);
10420 if (aWhitePoint.IsRealValue())
10422 aView->ChangeRenderingParams().WhitePoint = static_cast<float> (aWhitePoint.RealValue());
10426 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10430 else if (aFlag == "-tonemapping")
10432 if (++anArgIter >= theArgNb)
10434 std::cout << "Error: wrong syntax at argument '" << anArg << "'\n";
10438 TCollection_AsciiString aMode (theArgVec[anArgIter]);
10441 if (aMode == "disabled")
10443 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Disabled;
10445 else if (aMode == "filmic")
10447 aView->ChangeRenderingParams().ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;
10451 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
10457 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
10465 //=======================================================================
10466 //function : VProgressiveMode
10468 //=======================================================================
10469 #if defined(_WIN32)
10470 static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
10471 Standard_Integer /*theNbArgs*/,
10472 const char** /*theArgs*/)
10474 Handle(V3d_View) aView = ViewerTest::CurrentView();
10475 if (aView.IsNull())
10477 std::cerr << "Error: no active viewer!\n";
10481 std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
10487 Standard_Boolean toExit = Standard_False;
10490 while (PeekMessageW (&aMsg, NULL, 0, 0, PM_REMOVE))
10492 if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
10494 toExit = Standard_True;
10497 TranslateMessage (&aMsg);
10498 DispatchMessageW (&aMsg);
10511 //=======================================================================
10512 //function : VFrustumCulling
10513 //purpose : enables/disables view volume's culling.
10514 //=======================================================================
10515 static int VFrustumCulling (Draw_Interpretor& theDI,
10516 Standard_Integer theArgNb,
10517 const char** theArgVec)
10519 Handle(V3d_View) aView = ViewerTest::CurrentView();
10520 if (aView.IsNull())
10522 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
10528 theDI << (aView->IsCullingEnabled() ? "on" : "off");
10531 else if (theArgNb != 2)
10533 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
10537 TCollection_AsciiString aModeStr (theArgVec[1]);
10538 aModeStr.LowerCase();
10539 Standard_Boolean toEnable = 0;
10540 if (aModeStr == "on")
10544 else if (aModeStr == "off")
10550 toEnable = Draw::Atoi (theArgVec[1]) != 0;
10553 aView->SetFrustumCulling (toEnable);
10558 //=======================================================================
10559 //function : VHighlightSelected
10561 //=======================================================================
10562 static int VHighlightSelected (Draw_Interpretor& theDI,
10563 Standard_Integer theArgNb,
10564 const char** theArgVec)
10566 if (ViewerTest::GetAISContext().IsNull())
10568 std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n";
10572 const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
10576 theDI << (aContext->ToHilightSelected() ? "on" : "off");
10582 std::cout << theArgVec[0] << " error : wrong number of parameters."
10583 << "Type 'help" << theArgVec[0] << "' for more information.";
10588 TCollection_AsciiString aMode (theArgVec[1]);
10590 Standard_Boolean toEnable = Standard_False;
10591 if (aMode.IsEqual ("on"))
10593 toEnable = Standard_True;
10595 else if (aMode.IsEqual ("off"))
10597 toEnable = Standard_False;
10601 toEnable = Draw::Atoi (theArgVec[1]) != 0;
10604 if (toEnable != aContext->ToHilightSelected())
10606 aContext->SetToHilightSelected (toEnable);
10608 // Move cursor to null position and back to process updating of detection
10609 // and highlighting of selected object immediatly.
10610 Standard_Integer aPixX = 0;
10611 Standard_Integer aPixY = 0;
10612 const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager();
10614 anEventManager->GetCurrentPosition (aPixX, aPixY);
10615 anEventManager->MoveTo (0, 0);
10616 anEventManager->MoveTo (aPixX, aPixY);
10622 //=======================================================================
10623 //function : VXRotate
10625 //=======================================================================
10626 static Standard_Integer VXRotate (Draw_Interpretor& di,
10627 Standard_Integer argc,
10628 const char ** argv)
10630 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
10631 if (aContext.IsNull())
10633 di << argv[0] << "ERROR : use 'vinit' command before \n";
10639 di << "ERROR : Usage : " << argv[0] << " name angle\n";
10643 TCollection_AsciiString aName (argv[1]);
10644 Standard_Real anAngle = Draw::Atof (argv[2]);
10647 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
10648 Handle(AIS_InteractiveObject) anIObj;
10649 if (!aMap.IsBound2 (aName) )
10651 di << "Use 'vdisplay' before\n";
10656 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
10658 gp_Trsf aTransform;
10659 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
10660 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
10662 aContext->SetLocation (anIObj, aTransform);
10663 aContext->UpdateCurrentViewer();
10669 //===============================================================================================
10670 //class : ViewerTest_AISManipulator
10671 //purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances
10672 //===============================================================================================
10673 DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
10675 class ViewerTest_AISManipulator : public AIS_Manipulator
10679 ViewerTest_AISManipulator() : AIS_Manipulator()
10681 GetMapOfAISManipulators().Add (this);
10684 virtual ~ViewerTest_AISManipulator()
10686 GetMapOfAISManipulators().Remove (this);
10689 DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
10692 IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
10693 IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
10695 //===============================================================================================
10696 //function : VManipulator
10698 //===============================================================================================
10699 static int VManipulator (Draw_Interpretor& theDi,
10700 Standard_Integer theArgsNb,
10701 const char** theArgVec)
10703 Handle(V3d_View) aView = ViewerTest::CurrentView();
10704 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
10705 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
10707 || aViewer.IsNull())
10709 std::cerr << "No active viewer!\n";
10713 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
10714 Standard_Integer anArgIter = 1;
10715 for (; anArgIter < theArgsNb; ++anArgIter)
10717 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
10720 ViewerTest_CmdParser aCmd;
10721 aCmd.AddDescription ("Manages manipulator for interactive objects:");
10722 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
10723 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
10724 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
10725 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
10726 aCmd.AddOption ("detach", "... - detach manipulator");
10728 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
10729 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
10730 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
10732 aCmd.AddOption ("move", "... x y z - move object");
10733 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
10734 aCmd.AddOption ("scale", "... factor - scale object");
10736 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
10737 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
10738 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
10739 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
10740 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
10741 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
10742 aCmd.AddOption ("size", "... size - set size of manipulator");
10743 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
10745 aCmd.Parse (theArgsNb, theArgVec);
10747 if (aCmd.HasOption ("help"))
10749 theDi.PrintHelp (theArgVec[0]);
10753 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
10755 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
10757 if (aName.IsEmpty())
10759 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
10763 // ----------------------------------
10764 // detach existing manipulator object
10765 // ----------------------------------
10767 if (aCmd.HasOption ("detach"))
10769 if (!aMapAIS.IsBound2 (aName))
10771 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
10775 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
10776 if (aManipulator.IsNull())
10778 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
10782 aManipulator->Detach();
10783 aMapAIS.UnBind2 (aName);
10784 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_True);
10789 // -----------------------------------------------
10790 // find or create manipulator if it does not exist
10791 // -----------------------------------------------
10793 Handle(AIS_Manipulator) aManipulator;
10794 if (!aMapAIS.IsBound2 (aName))
10796 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
10798 aManipulator = new ViewerTest_AISManipulator();
10799 aMapAIS.Bind (aManipulator, aName);
10803 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
10804 if (aManipulator.IsNull())
10806 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
10811 // -----------------------------------------
10812 // change properties of manipulator instance
10813 // -----------------------------------------
10815 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
10817 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
10819 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
10821 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
10823 if (aCmd.HasOption ("followRotation", 1, Standard_True))
10825 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
10827 if (aCmd.HasOption ("gap", 1, Standard_True))
10829 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
10831 if (aCmd.HasOption ("part", 3, Standard_True))
10833 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
10834 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
10835 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
10836 if (aMode < 1 || aMode > 3)
10838 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 3].\n";
10842 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
10844 if (aCmd.HasOption ("pos", 3, Standard_True))
10846 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
10847 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
10848 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
10850 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
10852 if (aCmd.HasOption ("size", 1, Standard_True))
10854 aManipulator->SetSize (aCmd.ArgFloat ("size"));
10856 if (aCmd.HasOption ("zoomable", 1, Standard_True))
10858 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
10860 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
10862 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
10863 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
10867 // ---------------------------------------------------
10868 // attach, detach or access manipulator from an object
10869 // ---------------------------------------------------
10871 if (aCmd.HasOption ("attach"))
10873 // Find an object and attach manipulator to it
10874 if (!aCmd.HasOption ("attach", 1, Standard_True))
10879 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
10880 if (!aMapAIS.IsBound2 (anObjName))
10882 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
10886 Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (aMapAIS.Find2 (anObjName));
10887 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
10888 for (; anIt.More(); anIt.Next())
10890 if (anIt.Value()->IsAttached()
10891 && anIt.Value()->Object() == anObject)
10893 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
10898 AIS_Manipulator::OptionsForAttach anOptions;
10899 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
10901 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
10903 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
10905 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
10907 if (aCmd.HasOption ("enableModes", 1, Standard_True))
10909 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
10912 aManipulator->Attach (anObject, anOptions);
10915 // --------------------------------------
10916 // apply transformation using manipulator
10917 // --------------------------------------
10919 if (aCmd.HasOption ("startTransform", 2, Standard_True))
10921 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
10923 if (aCmd.HasOption ("transform", 2, Standard_True))
10925 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
10927 if (aCmd.HasOption ("stopTransform"))
10929 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
10931 aManipulator->StopTransform (toApply);
10935 if (aCmd.HasOption ("move", 3, Standard_True))
10937 aT.SetTranslationPart (aCmd.ArgVec ("move"));
10939 if (aCmd.HasOption ("rotate", 7, Standard_True))
10941 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
10943 if (aCmd.HasOption ("scale", 1))
10945 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
10948 if (aT.Form() != gp_Identity)
10950 aManipulator->Transform (aT);
10953 ViewerTest::GetAISContext()->Redisplay (aManipulator, Standard_True);
10958 //===============================================================================================
10959 //function : VSelectionProperties
10961 //===============================================================================================
10962 static int VSelectionProperties (Draw_Interpretor& theDi,
10963 Standard_Integer theArgsNb,
10964 const char** theArgVec)
10966 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
10969 std::cerr << "No active viewer!\n";
10973 Standard_Boolean toPrint = theArgsNb == 1;
10974 Standard_Boolean toRedraw = Standard_False;
10975 Standard_Integer anArgIter = 1;
10976 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
10977 if (anArgIter < theArgsNb)
10979 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
10980 anArgFirst.LowerCase();
10982 if (anArgFirst == "dynhighlight"
10983 || anArgFirst == "dynhilight"
10984 || anArgFirst == "dynamichighlight"
10985 || anArgFirst == "dynamichilight")
10987 aType = Prs3d_TypeOfHighlight_Dynamic;
10989 else if (anArgFirst == "localdynhighlight"
10990 || anArgFirst == "localdynhilight"
10991 || anArgFirst == "localdynamichighlight"
10992 || anArgFirst == "localdynamichilight")
10994 aType = Prs3d_TypeOfHighlight_LocalDynamic;
10996 else if (anArgFirst == "selhighlight"
10997 || anArgFirst == "selhilight"
10998 || anArgFirst == "selectedhighlight"
10999 || anArgFirst == "selectedhilight")
11001 aType = Prs3d_TypeOfHighlight_Selected;
11003 else if (anArgFirst == "localselhighlight"
11004 || anArgFirst == "localselhilight"
11005 || anArgFirst == "localselectedhighlight"
11006 || anArgFirst == "localselectedhilight")
11008 aType = Prs3d_TypeOfHighlight_LocalSelected;
11015 for (; anArgIter < theArgsNb; ++anArgIter)
11017 TCollection_AsciiString anArg (theArgVec[anArgIter]);
11019 if (anArg == "-help")
11021 theDi.PrintHelp (theArgVec[0]);
11024 else if (anArg == "-print")
11026 toPrint = Standard_True;
11028 else if (anArg == "-autoactivate")
11030 Standard_Boolean toEnable = Standard_True;
11031 if (anArgIter + 1 < theArgsNb
11032 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
11036 aCtx->SetAutoActivateSelection (toEnable);
11038 else if (anArg == "-pickstrategy"
11039 || anArg == "-pickingstrategy")
11041 if (++anArgIter >= theArgsNb)
11043 std::cout << "Syntax error: type of highlighting is undefined\n";
11047 SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
11048 TCollection_AsciiString aVal (theArgVec[anArgIter]);
11050 if (aVal == "first"
11051 || aVal == "firstaccepted"
11052 || aVal == "firstacceptable")
11054 aStrategy = SelectMgr_PickingStrategy_FirstAcceptable;
11056 else if (aVal == "topmost"
11057 || aVal == "onlyTopmost")
11059 aStrategy = SelectMgr_PickingStrategy_OnlyTopmost;
11063 std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n";
11067 aCtx->SetPickingStrategy (aStrategy);
11069 else if (anArg == "-pixtol"
11070 && anArgIter + 1 < theArgsNb)
11072 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
11074 else if ((anArg == "-mode"
11075 || anArg == "-dispmode")
11076 && anArgIter + 1 < theArgsNb)
11078 if (aType == Prs3d_TypeOfHighlight_None)
11080 std::cout << "Syntax error: type of highlighting is undefined\n";
11084 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
11085 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11086 aStyle->SetDisplayMode (aDispMode);
11087 toRedraw = Standard_True;
11089 else if (anArg == "-layer"
11090 && anArgIter + 1 < theArgsNb)
11092 if (aType == Prs3d_TypeOfHighlight_None)
11094 std::cout << "Syntax error: type of highlighting is undefined\n";
11098 const Standard_Integer aNewLayer = Draw::Atoi (theArgVec[++anArgIter]);
11099 if (aNewLayer != Graphic3d_ZLayerId_UNKNOWN)
11101 TColStd_SequenceOfInteger aLayers;
11102 aCtx->CurrentViewer()->GetAllZLayers (aLayers);
11103 if (std::find (aLayers.begin(), aLayers.end(), aNewLayer) == aLayers.end())
11105 std::cout << "Syntax error: Layer " << aNewLayer << " is undefined\n";
11110 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11111 aStyle->SetZLayer (aNewLayer);
11112 toRedraw = Standard_True;
11114 else if (anArg == "-hicolor"
11115 || anArg == "-selcolor"
11116 || anArg == "-color")
11118 if (anArg.StartsWith ("-hi"))
11120 aType = Prs3d_TypeOfHighlight_Dynamic;
11122 else if (anArg.StartsWith ("-sel"))
11124 aType = Prs3d_TypeOfHighlight_Selected;
11126 else if (aType == Prs3d_TypeOfHighlight_None)
11128 std::cout << "Syntax error: type of highlighting is undefined\n";
11132 Quantity_Color aColor;
11133 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1,
11134 theArgVec + anArgIter + 1,
11136 if (aNbParsed == 0)
11138 std::cout << "Syntax error: need more arguments.\n";
11141 anArgIter += aNbParsed;
11143 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11144 aStyle->SetColor (aColor);
11145 toRedraw = Standard_True;
11147 else if ((anArg == "-transp"
11148 || anArg == "-transparency"
11149 || anArg == "-hitransp"
11150 || anArg == "-seltransp"
11151 || anArg == "-hitransplocal"
11152 || anArg == "-seltransplocal")
11153 && anArgIter + 1 < theArgsNb)
11155 if (anArg.StartsWith ("-hi"))
11157 aType = Prs3d_TypeOfHighlight_Dynamic;
11159 else if (anArg.StartsWith ("-sel"))
11161 aType = Prs3d_TypeOfHighlight_Selected;
11163 else if (aType == Prs3d_TypeOfHighlight_None)
11165 std::cout << "Syntax error: type of highlighting is undefined\n";
11169 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
11170 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11171 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
11172 toRedraw = Standard_True;
11174 else if ((anArg == "-mat"
11175 || anArg == "-material")
11176 && anArgIter + 1 < theArgsNb)
11178 if (aType == Prs3d_TypeOfHighlight_None)
11180 std::cout << "Syntax error: type of highlighting is undefined\n";
11184 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
11185 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
11186 if (aMatName != Graphic3d_NOM_DEFAULT)
11189 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
11190 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
11191 Graphic3d_MaterialAspect aMat (aMatName);
11192 aMat.SetColor (aStyle->Color());
11193 aMat.SetTransparency (aStyle->Transparency());
11194 anAspect->SetFrontMaterial (aMat);
11195 anAspect->SetInteriorColor (aStyle->Color());
11196 aStyle->SetBasicFillAreaAspect (anAspect);
11200 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
11202 toRedraw = Standard_True;
11206 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
11212 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
11213 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
11214 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
11215 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
11216 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
11217 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
11218 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
11219 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
11220 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
11221 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
11222 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
11223 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
11226 if (aCtx->NbSelected() != 0 && toRedraw)
11228 aCtx->HilightSelected (Standard_True);
11234 //===============================================================================================
11235 //function : VDumpSelectionImage
11237 //===============================================================================================
11238 static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
11239 Standard_Integer theArgsNb,
11240 const char** theArgVec)
11244 std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
11248 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
11249 if (aContext.IsNull())
11251 std::cout << "Error: no active view.\n";
11255 TCollection_AsciiString aFile;
11256 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
11257 Image_Format anImgFormat = Image_Format_BGR;
11258 Standard_Integer aPickedIndex = 1;
11259 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
11261 TCollection_AsciiString aParam (theArgVec[anArgIter]);
11262 aParam.LowerCase();
11263 if (aParam == "-type")
11265 if (++anArgIter >= theArgsNb)
11267 std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n";
11271 TCollection_AsciiString aValue (theArgVec[anArgIter]);
11272 aValue.LowerCase();
11273 if (aValue == "depth"
11274 || aValue == "normdepth"
11275 || aValue == "normalizeddepth")
11277 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
11278 anImgFormat = Image_Format_GrayF;
11280 if (aValue == "depthinverted"
11281 || aValue == "normdepthinverted"
11282 || aValue == "normalizeddepthinverted"
11283 || aValue == "inverted")
11285 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
11286 anImgFormat = Image_Format_GrayF;
11288 else if (aValue == "unnormdepth"
11289 || aValue == "unnormalizeddepth")
11291 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
11292 anImgFormat = Image_Format_GrayF;
11294 else if (aValue == "objectcolor"
11295 || aValue == "object"
11296 || aValue == "color")
11298 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
11300 else if (aValue == "entitycolor"
11301 || aValue == "entity")
11303 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
11305 else if (aValue == "ownercolor"
11306 || aValue == "owner")
11308 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
11310 else if (aValue == "selectionmodecolor"
11311 || aValue == "selectionmode"
11312 || aValue == "selmodecolor"
11313 || aValue == "selmode")
11315 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
11318 else if (aParam == "-picked"
11319 || aParam == "-pickeddepth"
11320 || aParam == "-pickedindex")
11322 if (++anArgIter >= theArgsNb)
11324 std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n";
11328 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
11330 else if (aFile.IsEmpty())
11332 aFile = theArgVec[anArgIter];
11336 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n";
11340 if (aFile.IsEmpty())
11342 std::cout << "Syntax error: image file name is missing.\n";
11346 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
11347 Standard_Integer aWidth = 0, aHeight = 0;
11348 aView->Window()->Size (aWidth, aHeight);
11350 Image_AlienPixMap aPixMap;
11351 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
11353 std::cout << "Error: can't allocate image.\n";
11356 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
11358 std::cout << "Error: can't generate selection image.\n";
11361 if (!aPixMap.Save (aFile))
11363 std::cout << "Error: can't save selection image.\n";
11369 //=======================================================================
11370 //function : ViewerCommands
11372 //=======================================================================
11374 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
11377 const char *group = "ZeViewer";
11378 theCommands.Add("vinit",
11379 "vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]"
11380 "\n\t\t: [-exitOnClose] [-closeOnEscape]"
11381 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
11382 "\n\t\t: [-display displayName]"
11384 "\n\t\t: Creates new View window with specified name viewName."
11385 "\n\t\t: By default the new view is created in the viewer and in"
11386 "\n\t\t: graphic driver shared with active view."
11387 "\n\t\t: -name {driverName/viewerName/viewName | viewerName/viewName | viewName}"
11388 "\n\t\t: If driverName isn't specified the driver will be shared with active view."
11389 "\n\t\t: If viewerName isn't specified the viewer will be shared with active view."
11390 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
11391 "\n\t\t: -display HostName.DisplayNumber[:ScreenNumber]"
11392 "\n\t\t: Display name will be used within creation of graphic driver, when specified."
11394 "\n\t\t: -left, -top pixel position of left top corner of the window."
11395 "\n\t\t: -width, -height width and heigth of window respectively."
11396 "\n\t\t: -exitOnClose when specified, closing the view will exit application."
11397 "\n\t\t: -closeOnEscape when specified, view will be closed on pressing Escape."
11398 "\n\t\t: Additional commands for operations with views: vclose, vactivate, vviewlist.",
11399 __FILE__,VInit,group);
11400 theCommands.Add("vclose" ,
11401 "[view_id [keep_context=0|1]]\n"
11402 "or vclose ALL - to remove all created views\n"
11403 " - removes view(viewer window) defined by its view_id.\n"
11404 " - keep_context: by default 0; if 1 and the last view is deleted"
11405 " the current context is not removed.",
11406 __FILE__,VClose,group);
11407 theCommands.Add("vactivate" ,
11409 " - activates view(viewer window) defined by its view_id",
11410 __FILE__,VActivate,group);
11411 theCommands.Add("vviewlist",
11412 "vviewlist [format={tree, long}]"
11413 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
11414 " - format: format of result output, if tree the output is a tree view;"
11415 "otherwise it's a list of full view names. By default format = tree",
11416 __FILE__,VViewList,group);
11417 theCommands.Add("vhelp" ,
11418 "vhelp : display help on the viewer commands",
11419 __FILE__,VHelp,group);
11420 theCommands.Add("vtop" ,
11421 "vtop or <T> : Top view. Orientation +X+Y" ,
11422 __FILE__,VTop,group);
11423 theCommands.Add("vbottom" ,
11424 "vbottom : Bottom view. Orientation +X-Y" ,
11425 __FILE__,VBottom,group);
11426 theCommands.Add("vleft" ,
11427 "vleft : Left view. Orientation -Y+Z" ,
11428 __FILE__,VLeft,group);
11429 theCommands.Add("vright" ,
11430 "vright : Right view. Orientation +Y+Z" ,
11431 __FILE__,VRight,group);
11432 theCommands.Add("vaxo" ,
11433 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
11434 __FILE__,VAxo,group);
11435 theCommands.Add("vfront" ,
11436 "vfront : Front view. Orientation +X+Z" ,
11437 __FILE__,VFront,group);
11438 theCommands.Add("vback" ,
11439 "vback : Back view. Orientation -X+Z" ,
11440 __FILE__,VBack,group);
11441 theCommands.Add("vpick" ,
11442 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
11444 theCommands.Add("vfit",
11445 "vfit or <F> [-selected] [-noupdate]"
11446 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
11447 __FILE__,VFit,group);
11448 theCommands.Add ("vfitarea",
11449 "vfitarea x1 y1 x2 y2"
11450 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
11451 "\n\t\t: Fit view to show area located between two points"
11452 "\n\t\t: given in world 2D or 3D corrdinates.",
11453 __FILE__, VFitArea, group);
11454 theCommands.Add ("vzfit", "vzfit [scale]\n"
11455 " Matches Z near, Z far view volume planes to the displayed objects.\n"
11456 " \"scale\" - specifies factor to scale computed z range.\n",
11457 __FILE__, VZFit, group);
11458 theCommands.Add("vrepaint",
11459 "vrepaint [-immediate]"
11460 "\n\t\t: force redraw",
11461 __FILE__,VRepaint,group);
11462 theCommands.Add("vclear",
11464 "\n\t\t: remove all the object from the viewer",
11465 __FILE__,VClear,group);
11466 theCommands.Add("vsetbg",
11467 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
11468 __FILE__,VSetBg,group);
11469 theCommands.Add("vsetbgmode",
11470 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
11471 __FILE__,VSetBgMode,group);
11472 theCommands.Add("vsetgradientbg",
11473 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
11474 __FILE__,VSetGradientBg,group);
11475 theCommands.Add("vsetgrbgmode",
11476 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
11477 __FILE__,VSetGradientBgMode,group);
11478 theCommands.Add("vsetcolorbg",
11479 "vsetcolorbg : vsetcolorbg r g b : Set background color",
11480 __FILE__,VSetColorBg,group);
11481 theCommands.Add("vsetdefaultbg",
11482 "vsetdefaultbg r g b\n"
11483 "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode"
11484 "\n\t\t: Set default viewer background fill color (flat/gradient).",
11485 __FILE__,VSetDefaultBg,group);
11486 theCommands.Add("vscale",
11487 "vscale : vscale X Y Z",
11488 __FILE__,VScale,group);
11489 theCommands.Add("vzbufftrihedron",
11490 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
11491 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
11492 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
11493 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
11494 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
11495 "\n\t\t: Displays a trihedron",
11496 __FILE__,VZBuffTrihedron,group);
11497 theCommands.Add("vrotate",
11498 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
11499 "\n : Option -mouseStart starts rotation according to the mouse position"
11500 "\n : Option -mouseMove continues rotation with angle computed"
11501 "\n : from last and new mouse position."
11502 "\n : vrotate AX AY AZ [X Y Z]",
11503 __FILE__,VRotate,group);
11504 theCommands.Add("vzoom",
11505 "vzoom : vzoom coef",
11506 __FILE__,VZoom,group);
11507 theCommands.Add("vpan",
11508 "vpan : vpan dx dy",
11509 __FILE__,VPan,group);
11510 theCommands.Add("vexport",
11511 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
11512 " : exports the view to a vector file of a given format"
11513 " : notice that EMF format requires patched gl2ps",
11514 __FILE__,VExport,group);
11515 theCommands.Add("vcolorscale",
11516 "vcolorscale name [-noupdate|-update] [-demo]"
11517 "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
11518 "\n\t\t: [-font HeightFont=20]"
11519 "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
11520 "\n\t\t: [-smoothTransition {on|off}=off]"
11521 "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
11522 "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
11523 "\n\t\t: [-textpos {left|right|center|none}=right]"
11524 "\n\t\t: [-labelAtBorder {on|off}=on]"
11525 "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
11526 "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
11527 "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
11528 "\n\t\t: [-xy Left=0 Bottom=0]"
11529 "\n\t\t: -demo - displays a color scale with demonstratio values"
11530 "\n\t\t: -colors - set colors for all intervals"
11531 "\n\t\t: -color - set color for specific interval"
11532 "\n\t\t: -textpos - horizontal label position relative to color scale bar"
11533 "\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
11534 "\n\t\t: at border means the value inbetween neighbor intervals,"
11535 "\n\t\t: at center means the center value within current interval"
11536 "\n\t\t: -labels - set labels for all intervals"
11537 "\n\t\t: -freeLabels - same as -labels but does not require"
11538 "\n\t\t: matching the number of intervals"
11539 "\n\t\t: -label - set label for specific interval"
11540 "\n\t\t: -title - set title"
11541 "\n\t\t: -reversed - setup smooth color transition between intervals"
11542 "\n\t\t: -smoothTransition - swap colorscale direction"
11543 "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values"
11544 __FILE__, VColorScale, group);
11545 theCommands.Add("vgraduatedtrihedron",
11546 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
11547 "\t[-namefont Name] [-valuesfont Name]\n"
11548 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
11549 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
11550 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
11551 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
11552 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
11553 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
11554 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
11555 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
11556 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
11557 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
11558 " - Displays or erases graduated trihedron"
11559 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
11560 " - namefont - font of axes names. Default: Arial\n"
11561 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
11562 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
11563 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
11564 " - valuesfont - font of axes values. Default: Arial\n"
11565 " - xcolor, ycolor, zcolor - color of axis and values\n"
11566 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
11567 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
11568 __FILE__,VGraduatedTrihedron,group);
11569 theCommands.Add("vtile" ,
11570 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
11571 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
11572 "\n\t\t: -totalSize the size of virtual bigger viewport"
11573 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
11574 "\n\t\t: -lowerLeft tile offset as lower left corner"
11575 "\n\t\t: -upperLeft tile offset as upper left corner",
11576 __FILE__, VTile, group);
11577 theCommands.Add("vzlayer",
11578 "vzlayer [layerId]"
11579 "\n\t\t: [-add|-delete|-get|-settings]"
11580 "\n\t\t: [-origin X Y Z] [-cullDist Distance] [-cullSize Size]"
11581 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
11582 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv}]"
11583 "\n\t\t: ZLayer list management:"
11584 "\n\t\t: -add add new z layer to viewer and print its id"
11585 "\n\t\t: -delete delete z layer"
11586 "\n\t\t: -get print sequence of z layers"
11587 "\n\t\t: -settings print status of z layer settings"
11588 "\n\t\t: -disable disables given setting"
11589 "\n\t\t: -enable enables given setting",
11590 __FILE__,VZLayer,group);
11591 theCommands.Add("vlayerline",
11592 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
11593 __FILE__,VLayerLine,group);
11594 theCommands.Add ("vgrid",
11595 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
11596 " : Mode - rectangular or circular"
11597 " : Type - lines or points",
11598 __FILE__, VGrid, group);
11599 theCommands.Add ("vpriviledgedplane",
11600 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
11601 "\n\t\t: Ox, Oy, Oz - plane origin"
11602 "\n\t\t: Nx, Ny, Nz - plane normal direction"
11603 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
11604 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
11605 __FILE__, VPriviledgedPlane, group);
11606 theCommands.Add ("vconvert",
11607 "vconvert v [Mode={window|view}]"
11608 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
11609 "\n\t\t: vconvert x y z [Mode={window|grid}]"
11610 "\n\t\t: window - convert to window coordinates, pixels"
11611 "\n\t\t: view - convert to view projection plane"
11612 "\n\t\t: grid - convert to model coordinates, given on grid"
11613 "\n\t\t: ray - convert projection ray to model coordiantes"
11614 "\n\t\t: - vconvert v window : convert view to window;"
11615 "\n\t\t: - vconvert v view : convert window to view;"
11616 "\n\t\t: - vconvert x y window : convert view to window;"
11617 "\n\t\t: - vconvert x y view : convert window to view;"
11618 "\n\t\t: - vconvert x y : convert window to model;"
11619 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
11620 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
11621 "\n\t\t: - vconvert x y z window : convert model to window;"
11622 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
11623 "\n\t\t: Converts the given coordinates to window/view/model space.",
11624 __FILE__, VConvert, group);
11625 theCommands.Add ("vfps",
11626 "vfps [framesNb=100] : estimate average frame rate for active view",
11627 __FILE__, VFps, group);
11628 theCommands.Add ("vgldebug",
11629 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
11630 "\n\t\t: [-extraMsg {0|1}] [{0|1}]"
11631 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
11632 "\n\t\t: Debug context can be requested only on Windows"
11633 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
11634 "\n\t\t: -sync - request synchronized debug GL context"
11635 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
11636 "\n\t\t: which are suppressed by default,"
11637 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
11638 "\n\t\t: which are suppressed by default",
11639 __FILE__, VGlDebug, group);
11640 theCommands.Add ("vvbo",
11641 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
11642 __FILE__, VVbo, group);
11643 theCommands.Add ("vstereo",
11644 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
11645 "\n\t\t: [-anaglyph Filter]"
11646 "\n\t\t: Control stereo output mode. Available modes for -mode:"
11647 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
11648 "\n\t\t: requires driver support."
11649 "\n\t\t: Should be called BEFORE vinit!"
11650 "\n\t\t: anaglyph - Anaglyph glasses"
11651 "\n\t\t: rowInterlaced - row-interlaced display"
11652 "\n\t\t: columnInterlaced - column-interlaced display"
11653 "\n\t\t: chessBoard - chess-board output"
11654 "\n\t\t: sideBySide - horizontal pair"
11655 "\n\t\t: overUnder - vertical pair"
11656 "\n\t\t: Available Anaglyph filters for -anaglyph:"
11657 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
11658 "\n\t\t: greenMagentaSimple",
11659 __FILE__, VStereo, group);
11660 theCommands.Add ("vcaps",
11661 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
11662 "\n\t\t: [-compatibleProfile {0|1}]"
11663 "\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]"
11664 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
11665 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
11666 "\n\t\t: Modify particular graphic driver options:"
11667 "\n\t\t: FFP - use fixed-function pipeline instead of"
11668 "\n\t\t: built-in GLSL programs"
11669 "\n\t\t: (requires compatible profile)"
11670 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
11671 "\n\t\t: arrays to GPU memory)"
11672 "\n\t\t: sprite - use textured sprites instead of bitmaps"
11673 "\n\t\t: vsync - switch VSync on or off"
11674 "\n\t\t: winBuffer - allow using window buffer for rendering"
11675 "\n\t\t: Context creation options:"
11676 "\n\t\t: softMode - software OpenGL implementation"
11677 "\n\t\t: compatibleProfile - backward-compatible profile"
11678 "\n\t\t: quadbuffer - QuadBuffer"
11679 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
11680 "\n\t\t: rendering paths producing the same visual result when"
11681 "\n\t\t: possible."
11682 "\n\t\t: Command is intended for testing old hardware compatibility.",
11683 __FILE__, VCaps, group);
11684 theCommands.Add ("vmemgpu",
11685 "vmemgpu [f]: print system-dependent GPU memory information if available;"
11686 " with f option returns free memory in bytes",
11687 __FILE__, VMemGpu, group);
11688 theCommands.Add ("vreadpixel",
11689 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
11690 " : Read pixel value for active view",
11691 __FILE__, VReadPixel, group);
11692 theCommands.Add("diffimage",
11693 "diffimage imageFile1 imageFile2 [diffImageFile]"
11694 "\n\t\t: [-toleranceOfColor {0..1}=0] [-blackWhite {on|off}=off] [-borderFilter {on|off}=off]"
11695 "\n\t\t: [-display viewName prsName1 prsName2 prsNameDiff] [-exitOnClose] [-closeOnEscape]"
11696 "\n\t\t: Compare two images by content and generate difference image."
11697 "\n\t\t: When -exitOnClose is specified, closing the view will exit application."
11698 "\n\t\t: When -closeOnEscape is specified, view will be closed on pressing Escape.",
11699 __FILE__, VDiffImage, group);
11700 theCommands.Add ("vselect",
11701 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
11702 "- emulates different types of selection:\n"
11703 "- 1) single click selection\n"
11704 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
11705 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
11706 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
11707 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
11708 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
11709 " (partial inclusion - overlap - is not allowed by default)\n"
11710 "- 5) any of these selections with shift button pressed",
11711 __FILE__, VSelect, group);
11712 theCommands.Add ("vmoveto",
11714 "- emulates cursor movement to pixel postion (x,y)",
11715 __FILE__, VMoveTo, group);
11716 theCommands.Add ("vviewparams",
11717 "vviewparams [-args] [-scale [s]]"
11718 "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]"
11719 "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]"
11720 "\n\t\t: Manage current view parameters or prints all"
11721 "\n\t\t: current values when called without argument."
11722 "\n\t\t: -scale [s] prints or sets viewport relative scale"
11723 "\n\t\t: -eye [x y z] prints or sets eye location"
11724 "\n\t\t: -at [x y z] prints or sets center of look"
11725 "\n\t\t: -up [x y z] prints or sets direction of up vector"
11726 "\n\t\t: -proj [x y z] prints or sets direction of look"
11727 "\n\t\t: -center x y sets location of center of the screen in pixels"
11728 "\n\t\t: -size [sx] prints viewport projection width and height sizes"
11729 "\n\t\t: or changes the size of its maximum dimension"
11730 "\n\t\t: -args prints vviewparams arguments for restoring current view",
11731 __FILE__, VViewParams, group);
11733 theCommands.Add("vanimation", "Alias for vanim",
11734 __FILE__, VAnimation, group);
11736 theCommands.Add("vanim",
11737 "List existing animations:"
11739 "\n\t\t: Animation playback:"
11740 "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]"
11741 "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]"
11742 "\n\t\t: -speed playback speed (1.0 is normal speed)"
11743 "\n\t\t: -freeLook skip camera animations"
11744 "\n\t\t: -lockLoop disable any interactions"
11746 "\n\t\t: Animation definition:"
11747 "\n\t\t: vanim Name/sub/name [-clear] [-delete]"
11748 "\n\t\t: [start TimeSec] [duration TimeSec]"
11750 "\n\t\t: Animation name defined in path-style (anim/name or anim.name)"
11751 "\n\t\t: specifies nested animations."
11752 "\n\t\t: There is no syntax to explicitly add new animation,"
11753 "\n\t\t: and all non-existing animations within the name will be"
11754 "\n\t\t: implicitly created on first use (including parents)."
11756 "\n\t\t: Each animation might define the SINGLE action (see below),"
11757 "\n\t\t: like camera transition, object transformation or custom callback."
11758 "\n\t\t: Child animations can be used for defining concurrent actions."
11760 "\n\t\t: Camera animation:"
11761 "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]"
11762 "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]"
11763 "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]"
11764 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
11765 "\n\t\t: -eyeX camera Eye positions pair (start and end)"
11766 "\n\t\t: -atX camera Center positions pair"
11767 "\n\t\t: -upX camera Up directions pair"
11768 "\n\t\t: -scaleX camera Scale factors pair"
11769 "\n\t\t: Object animation:"
11770 "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]"
11771 "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]"
11772 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
11773 "\n\t\t: -locX object Location points pair (translation)"
11774 "\n\t\t: -rotX object Orientations pair (quaternions)"
11775 "\n\t\t: -scaleX object Scale factors pair (quaternions)"
11776 "\n\t\t: Custom callback:"
11777 "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\""
11778 "\n\t\t: %Pts overall animation presentation timestamp"
11779 "\n\t\t: %LocalPts local animation timestamp"
11780 "\n\t\t: %Normalized local animation normalized value in range 0..1"
11782 "\n\t\t: Video recording:"
11783 "\n\t\t: vanim name -record FileName [Width Height] [-fps FrameRate=24]"
11784 "\n\t\t: [-format Format] [-vcodec Codec] [-pix_fmt PixelFormat]"
11785 "\n\t\t: [-crf Value] [-preset Preset]"
11786 "\n\t\t: -fps video framerate"
11787 "\n\t\t: -format file format, container (matroska, etc.)"
11788 "\n\t\t: -vcodec video codec identifier (ffv1, mjpeg, etc.)"
11789 "\n\t\t: -pix_fmt image pixel format (yuv420p, rgb24, etc.)"
11790 "\n\t\t: -crf constant rate factor (specific to codec)"
11791 "\n\t\t: -preset codec parameters preset (specific to codec)"
11792 __FILE__, VAnimation, group);
11794 theCommands.Add("vchangeselected",
11795 "vchangeselected shape"
11796 "- adds to shape to selection or remove one from it",
11797 __FILE__, VChangeSelected, group);
11798 theCommands.Add ("vnbselected",
11800 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
11801 theCommands.Add ("vcamera",
11802 "vcamera [-ortho] [-projtype]"
11804 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
11805 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
11806 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
11807 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
11808 "\n\t\t: Manage camera parameters."
11809 "\n\t\t: Prints current value when option called without argument."
11810 "\n\t\t: Orthographic camera:"
11811 "\n\t\t: -ortho activate orthographic projection"
11812 "\n\t\t: Perspective camera:"
11813 "\n\t\t: -persp activate perspective projection (mono)"
11814 "\n\t\t: -fovy field of view in y axis, in degrees"
11815 "\n\t\t: -distance distance of eye from camera center"
11816 "\n\t\t: Stereoscopic camera:"
11817 "\n\t\t: -stereo perspective projection (stereo)"
11818 "\n\t\t: -leftEye perspective projection (left eye)"
11819 "\n\t\t: -rightEye perspective projection (right eye)"
11820 "\n\t\t: -iod intraocular distance value"
11821 "\n\t\t: -iodType distance type, absolute or relative"
11822 "\n\t\t: -zfocus stereographic focus value"
11823 "\n\t\t: -zfocusType focus type, absolute or relative",
11824 __FILE__, VCamera, group);
11825 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
11826 "- vautozfit [on={1|0}] [scale]\n"
11827 " Prints or changes parameters of automatic z-fit mode:\n"
11828 " \"on\" - turns automatic z-fit on or off\n"
11829 " \"scale\" - specifies factor to scale computed z range.\n",
11830 __FILE__, VAutoZFit, group);
11831 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
11832 " vzrange - without parameters shows current values\n"
11833 " vzrange [znear] [zfar] - applies provided values to view",
11834 __FILE__,VZRange, group);
11835 theCommands.Add ("vpurgedisplay",
11837 "- removes structures which don't belong to objects displayed in neutral point",
11838 __FILE__, VPurgeDisplay, group);
11839 theCommands.Add("vsetviewsize",
11840 "vsetviewsize size",
11841 __FILE__,VSetViewSize,group);
11842 theCommands.Add("vmoveview",
11843 "vmoveview Dx Dy Dz [Start = 1|0]",
11844 __FILE__,VMoveView,group);
11845 theCommands.Add("vtranslateview",
11846 "vtranslateview Dx Dy Dz [Start = 1|0)]",
11847 __FILE__,VTranslateView,group);
11848 theCommands.Add("vturnview",
11849 "vturnview Ax Ay Az [Start = 1|0]",
11850 __FILE__,VTurnView,group);
11851 theCommands.Add("vtextureenv",
11852 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
11853 "or user-defined file and optionally applying texture mapping parameters\n"
11855 " vtextureenv off - disables environment mapping\n"
11856 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
11857 " std_texture = (0..7)\n"
11858 " rep = {clamp|repeat}\n"
11859 " mod = {decal|modulate}\n"
11860 " flt = {nearest|bilinear|trilinear}\n"
11861 " ss, st - scale factors for s and t texture coordinates\n"
11862 " ts, tt - translation for s and t texture coordinates\n"
11863 " rot - texture rotation angle in degrees",
11864 __FILE__, VTextureEnv, group);
11865 theCommands.Add("vhlr",
11866 "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
11867 "\n\t\t: Hidden Line Removal algorithm."
11868 "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones"
11869 "\n\t\t: -algoType type of HLR algorithm.\n",
11870 __FILE__,VHLR,group);
11871 theCommands.Add("vhlrtype",
11872 "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
11873 "\n\t\t: Changes the type of HLR algorithm using for shapes:"
11874 "\n\t\t: 'algo' - exact HLR algorithm is applied"
11875 "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied"
11876 "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
11877 __FILE__,VHLRType,group);
11878 theCommands.Add("vclipplane",
11879 "vclipplane planeName [{0|1}]"
11880 "\n\t\t: [-equation A B C D]"
11881 "\n\t\t: [-set|-unset [objects|views]]"
11882 "\n\t\t: [-maxPlanes]"
11883 "\n\t\t: [-capping {0|1}]"
11884 "\n\t\t: [-color R G B] [-hatch {on|off|ID}]"
11885 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
11886 "\n\t\t: [-texRotate Angle]"
11887 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
11888 "\n\t\t: [-useObjShader {0|1}]"
11889 "\n\t\t: Clipping planes management:"
11890 "\n\t\t: -maxPlanes print plane limit for view"
11891 "\n\t\t: -delete delete plane with given name"
11892 "\n\t\t: {off|on|0|1} turn clipping on/off"
11893 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
11894 "\n\t\t: applied to active View when list is omitted"
11895 "\n\t\t: -equation A B C D change plane equation"
11896 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
11897 "\n\t\t: Capping options:"
11898 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
11899 "\n\t\t: -color R G B set capping color"
11900 "\n\t\t: -texName Texture set capping texture"
11901 "\n\t\t: -texScale SX SY set capping tex scale"
11902 "\n\t\t: -texOrigin TX TY set capping tex origin"
11903 "\n\t\t: -texRotate Angle set capping tex rotation"
11904 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
11905 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
11906 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
11907 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
11908 __FILE__, VClipPlane, group);
11909 theCommands.Add("vdefaults",
11910 "vdefaults [-absDefl value]"
11911 "\n\t\t: [-devCoeff value]"
11912 "\n\t\t: [-angDefl value]"
11913 "\n\t\t: [-autoTriang {off/on | 0/1}]"
11914 , __FILE__, VDefaults, group);
11915 theCommands.Add("vlight",
11916 "tool to manage light sources, without arguments shows list of lights."
11917 "\n Main commands: "
11918 "\n 'clear' to clear lights"
11919 "\n '{def}aults' to load deafault lights"
11920 "\n 'add' (or 'new') <type> to add any light source"
11921 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
11922 "\n 'change' <lightId> to edit light source with specified lightId"
11923 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
11924 "\n {pos}ition X Y Z"
11925 "\n {dir}ection X Y Z (for directional light or for spotlight)"
11926 "\n color colorName"
11927 "\n {head}light 0|1"
11928 "\n {sm}oothness value"
11929 "\n {int}ensity value"
11930 "\n {constAtten}uation value"
11931 "\n {linearAtten}uation value"
11932 "\n angle angleDeg"
11933 "\n {spotexp}onent value"
11935 "\n\n example: vlight add positional head 1 pos 0 1 1 color red"
11936 "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
11937 __FILE__, VLight, group);
11938 theCommands.Add("vraytrace",
11940 "\n\t\t: Turns on/off ray-tracing renderer."
11941 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
11942 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
11943 __FILE__, VRenderParams, group);
11944 theCommands.Add("vrenderparams",
11945 "\n Manages rendering parameters: "
11946 "\n '-raster' Disables GPU ray-tracing"
11947 "\n '-msaa 0..4' Specifies number of samples for MSAA"
11948 "\n '-oit off|0.0-1.0' Enables/disables OIT and sets depth weight factor"
11949 "\n '-rendScale value Rendering resolution scale factor"
11950 "\n '-rayTrace' Enables GPU ray-tracing"
11951 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
11952 "\n '-shadows on|off' Enables/disables shadows rendering"
11953 "\n '-reflections on|off' Enables/disables specular reflections"
11954 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
11955 "\n '-gleam on|off' Enables/disables transparency shadow effects"
11956 "\n '-gi on|off' Enables/disables global illumination effects"
11957 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
11958 "\n '-env on|off' Enables/disables environment map background"
11959 "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
11960 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
11961 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
11962 "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)"
11963 "\n '-nbtiles 64..1024' Specifies number of screen tiles in ISS mode"
11964 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
11965 "\n '-shadingModel model' Controls shading model from enumeration"
11966 "\n color, flat, gouraud, phong"
11967 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
11968 "\n '-aperture >= 0.0' Aperture size of perspective camera for depth-of-field effect (0 disables DOF)"
11969 "\n '-focal >= 0.0' Focal distance of perspective camera for depth-of-field effect"
11970 "\n '-exposure value' Exposure value for tone mapping (0.0 value disables the effect)"
11971 "\n '-whitepoint value' White point value for filmic tone mapping"
11972 "\n '-tonemapping mode' Tone mapping mode (disabled, filmic)"
11973 "\n Unlike vcaps, these parameters dramatically change visual properties."
11974 "\n Command is intended to control presentation quality depending on"
11975 "\n hardware capabilities and performance.",
11976 __FILE__, VRenderParams, group);
11977 theCommands.Add("vfrustumculling",
11978 "vfrustumculling [toEnable]: enables/disables objects clipping",
11979 __FILE__,VFrustumCulling,group);
11980 theCommands.Add("vhighlightselected",
11981 "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n"
11982 "Without arguments it shows if highlighting of selected objects is enabled now.",
11983 __FILE__,VHighlightSelected,group);
11984 theCommands.Add ("vplace",
11986 "\n\t\t: Places the point (in pixels) at the center of the window",
11987 __FILE__, VPlace, group);
11988 theCommands.Add("vxrotate",
11990 __FILE__,VXRotate,group);
11992 theCommands.Add("vmanipulator",
11993 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
11994 "\n tool to create and manage AIS manipulators."
11996 "\n '-attach AISObject' attach manipulator to AISObject"
11997 "\n '-adjustPosition {0|1}' adjust position when attaching"
11998 "\n '-adjustSize {0|1}' adjust size when attaching"
11999 "\n '-enableModes {0|1}' enable modes when attaching"
12000 "\n '-detach' detach manipulator"
12001 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
12002 "\n '-transform mouse_x mouse_y' - invoke transformation"
12003 "\n '-stopTransform [abort]' - invoke stop of transformation"
12004 "\n '-move x y z' - move attached object"
12005 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
12006 "\n '-scale factor' - scale attached object"
12007 "\n '-autoActivate {0|1}' - set activation on detection"
12008 "\n '-followTranslation {0|1}' - set following translation transform"
12009 "\n '-followRotation {0|1}' - set following rotation transform"
12010 "\n '-gap value' - set gap between sub-parts"
12011 "\n '-part axis mode {0|1}' - set visual part"
12012 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
12013 "\n '-size value' - set size of manipulator"
12014 "\n '-zoomable {0|1}' - set zoom persistence",
12015 __FILE__, VManipulator, group);
12017 theCommands.Add("vselprops",
12018 "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]"
12019 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
12020 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
12021 "\n -pickStrategy {first|topmost} : defines picking strategy"
12022 "\n 'first' to pick first acceptable (default)"
12023 "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)"
12024 "\n -pixTol value : sets up pixel tolerance"
12025 "\n -dispMode dispMode : sets display mode for highlighting"
12026 "\n -layer ZLayer : sets ZLayer for highlighting"
12027 "\n -color {name|r g b} : sets highlight color"
12028 "\n -transp value : sets transparency coefficient for highlight"
12029 "\n -material material : sets highlight material"
12030 "\n -print : prints current state of all mentioned parameters",
12031 __FILE__, VSelectionProperties, group);
12033 theCommands.Add ("vseldump",
12034 "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1"
12035 "\n\t\t: Generate an image based on detection results:"
12036 "\n\t\t: depth normalized depth values"
12037 "\n\t\t: unnormDepth unnormalized depth values"
12038 "\n\t\t: object color of detected object"
12039 "\n\t\t: owner color of detected owner"
12040 "\n\t\t: selMode color of selection mode"
12041 "\n\t\t: entity color of etected entity",
12042 __FILE__, VDumpSelectionImage, group);
12044 #if defined(_WIN32)
12045 theCommands.Add("vprogressive",
12047 __FILE__, VProgressiveMode, group);