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 <Graphic3d_ArrayOfPolylines.hxx>
31 #include <Graphic3d_AspectMarker3d.hxx>
32 #include <Graphic3d_ExportFormat.hxx>
33 #include <Graphic3d_NameOfTextureEnv.hxx>
34 #include <Graphic3d_GraduatedTrihedron.hxx>
35 #include <Graphic3d_TextureEnv.hxx>
36 #include <Graphic3d_TextureParams.hxx>
37 #include <Graphic3d_TypeOfTextureFilter.hxx>
38 #include <Graphic3d_AspectFillArea3d.hxx>
39 #include <ViewerTest.hxx>
40 #include <ViewerTest_AutoUpdater.hxx>
41 #include <ViewerTest_EventManager.hxx>
42 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
43 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
44 #include <ViewerTest_CmdParser.hxx>
45 #include <V3d_AmbientLight.hxx>
46 #include <V3d_DirectionalLight.hxx>
47 #include <V3d_PositionalLight.hxx>
48 #include <V3d_SpotLight.hxx>
49 #include <NCollection_DoubleMap.hxx>
50 #include <NCollection_List.hxx>
51 #include <NCollection_Vector.hxx>
52 #include <AIS_InteractiveContext.hxx>
53 #include <Draw_Interpretor.hxx>
55 #include <Draw_Appli.hxx>
56 #include <Image_AlienPixMap.hxx>
57 #include <OpenGl_GraphicDriver.hxx>
58 #include <OSD_Timer.hxx>
59 #include <TColStd_HSequenceOfAsciiString.hxx>
60 #include <TColStd_SequenceOfInteger.hxx>
61 #include <TColStd_HSequenceOfReal.hxx>
62 #include <TColgp_Array1OfPnt2d.hxx>
63 #include <TColStd_MapOfAsciiString.hxx>
64 #include <Aspect_TypeOfLine.hxx>
65 #include <Image_Diff.hxx>
66 #include <Aspect_DisplayConnection.hxx>
70 #include <PrsMgr_PresentableObject.hxx>
71 #include <Graphic3d_ClipPlane.hxx>
72 #include <NCollection_DataMap.hxx>
73 #include <Graphic3d_Texture2Dmanual.hxx>
74 #include <Prs3d_ShadingAspect.hxx>
75 #include <Prs3d_Drawer.hxx>
76 #include <Prs3d_LineAspect.hxx>
77 #include <Prs3d_Root.hxx>
86 #include <WNT_WClass.hxx>
87 #include <WNT_Window.hxx>
88 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
89 #include <Cocoa_Window.hxx>
91 #include <Xw_Window.hxx>
92 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
93 #include <X11/Xutil.h>
97 // Auxiliary definitions
98 static const char THE_KEY_DELETE = 127;
100 //==============================================================================
101 // VIEWER GLOBAL VARIABLES
102 //==============================================================================
104 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
105 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
107 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
108 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
110 extern int VErase (Draw_Interpretor& theDI,
111 Standard_Integer theArgNb,
112 const char** theArgVec);
115 static Handle(WNT_Window)& VT_GetWindow() {
116 static Handle(WNT_Window) WNTWin;
119 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
120 static Handle(Cocoa_Window)& VT_GetWindow()
122 static Handle(Cocoa_Window) aWindow;
125 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
126 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
127 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
130 static Handle(Xw_Window)& VT_GetWindow(){
131 static Handle(Xw_Window) XWWin;
135 static void VProcessEvents(ClientData,int);
138 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
140 static Handle(Aspect_DisplayConnection) aDisplayConnection;
141 return aDisplayConnection;
144 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
146 GetDisplayConnection() = theDisplayConnection;
149 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
150 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
152 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
154 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
155 if (!aWindow.IsNull())
156 return aWindow->HWindow();
157 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
158 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
159 if (!aWindow.IsNull())
160 return aWindow->XWindow();
162 return aWindowHandle;
166 static Standard_Boolean MyHLRIsOn = Standard_False;
168 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
169 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
170 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
171 static OpenGl_Caps ViewerTest_myDefaultCaps;
173 static void OSWindowSetup();
177 Quantity_Color FlatColor;
178 Quantity_Color GradientColor1;
179 Quantity_Color GradientColor2;
180 Aspect_GradientFillMethod FillMethod;
181 } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
183 //==============================================================================
184 // EVENT GLOBAL VARIABLES
185 //==============================================================================
187 static int Start_Rot = 0;
188 int X_Motion = 0; // Current cursor position
190 int X_ButtonPress = 0; // Last ButtonPress position
191 int Y_ButtonPress = 0;
192 Standard_Boolean IsDragged = Standard_False;
193 Standard_Boolean DragFirst = Standard_False;
194 Standard_Boolean TheIsAnimating = Standard_False;
197 Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand()
199 static Handle(AIS_RubberBand) aBand;
202 aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0);
203 aBand->SetDisplayMode (0);
208 typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators;
210 Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators()
212 static ViewerTest_MapOfAISManipulators aMap;
216 Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator()
218 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
219 for (; anIt.More(); anIt.Next())
221 if (anIt.Value()->HasActiveMode())
229 //==============================================================================
232 static LRESULT WINAPI ViewerWindowProc(
237 static LRESULT WINAPI AdvViewerWindowProc(
245 //==============================================================================
248 //==============================================================================
250 const Handle(Standard_Transient)& ViewerTest::WClass()
252 static Handle(Standard_Transient) theWClass;
254 if (theWClass.IsNull())
256 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
257 CS_VREDRAW | CS_HREDRAW, 0, 0,
258 ::LoadCursorW (NULL, IDC_ARROW));
264 //==============================================================================
265 //function : CreateName
266 //purpose : Create numerical name for new object in theMap
267 //==============================================================================
268 template <typename ObjectType>
269 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
270 const TCollection_AsciiString& theDefaultString)
272 if (theObjectMap.IsEmpty())
273 return theDefaultString + TCollection_AsciiString(1);
275 Standard_Integer aNextKey = 1;
276 Standard_Boolean isFound = Standard_False;
279 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
280 // Look for objects with default names
281 if (theObjectMap.IsBound1(aStringKey))
286 isFound = Standard_True;
289 return theDefaultString + TCollection_AsciiString(aNextKey);
292 //==============================================================================
293 //structure : ViewerTest_Names
294 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
295 //==============================================================================
296 struct ViewerTest_Names
299 TCollection_AsciiString myDriverName;
300 TCollection_AsciiString myViewerName;
301 TCollection_AsciiString myViewName;
305 const TCollection_AsciiString& GetDriverName () const
309 void SetDriverName (const TCollection_AsciiString& theDriverName)
311 myDriverName = theDriverName;
313 const TCollection_AsciiString& GetViewerName () const
317 void SetViewerName (const TCollection_AsciiString& theViewerName)
319 myViewerName = theViewerName;
321 const TCollection_AsciiString& GetViewName () const
325 void SetViewName (const TCollection_AsciiString& theViewName)
327 myViewName = theViewName;
330 //===========================================================================
331 //function : Constructor for ViewerTest_Names
332 //purpose : Get view, viewer, driver names from custom string
333 //===========================================================================
335 ViewerTest_Names (const TCollection_AsciiString& theInputString)
337 TCollection_AsciiString aName(theInputString);
338 if (theInputString.IsEmpty())
340 // Get current configuration
341 if (ViewerTest_myDrivers.IsEmpty())
342 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
343 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
345 myDriverName = ViewerTest_myDrivers.Find2
346 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
348 if(ViewerTest_myContexts.IsEmpty())
350 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
351 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
354 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
356 myViewName = CreateName <Handle(V3d_View)>
357 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
361 // There is at least view name
362 Standard_Integer aParserNumber = 0;
363 for (Standard_Integer i = 0; i < 3; ++i)
365 Standard_Integer aParserPos = aName.SearchFromEnd("/");
369 aName.Split(aParserPos-1);
374 if (aParserNumber == 0)
377 if (!ViewerTest::GetAISContext().IsNull())
379 myDriverName = ViewerTest_myDrivers.Find2
380 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
381 myViewerName = ViewerTest_myContexts.Find2
382 (ViewerTest::GetAISContext());
386 // There is no opened contexts here, need to create names for viewer and driver
387 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
388 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
390 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
391 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
393 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
395 else if (aParserNumber == 1)
397 // Here is viewerName/viewName
398 if (!ViewerTest::GetAISContext().IsNull())
399 myDriverName = ViewerTest_myDrivers.Find2
400 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
403 // There is no opened contexts here, need to create name for driver
404 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
405 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
407 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
409 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
413 //Here is driverName/viewerName/viewName
414 myDriverName = TCollection_AsciiString(aName);
416 TCollection_AsciiString aViewerName(theInputString);
417 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
418 myViewerName = TCollection_AsciiString(aViewerName);
420 myViewName = TCollection_AsciiString(theInputString);
426 //==============================================================================
427 //function : FindContextByView
428 //purpose : Find AIS_InteractiveContext by View
429 //==============================================================================
431 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
433 Handle(AIS_InteractiveContext) anAISContext;
435 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
436 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
438 if (anIter.Value()->CurrentViewer() == theView->Viewer())
439 return anIter.Key2();
445 //==============================================================================
446 //function : SetWindowTitle
447 //purpose : Set window title
448 //==============================================================================
450 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
451 Standard_CString theTitle)
454 const TCollection_ExtendedString theTitleW (theTitle);
455 SetWindowTextW ((HWND )Handle(WNT_Window)::DownCast(theWindow)->HWindow(), theTitleW.ToWideString());
456 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
457 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
459 if(GetDisplayConnection()->GetDisplay())
462 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
463 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
468 //==============================================================================
469 //function : IsWindowOverlapped
470 //purpose : Check if theWindow overlapp another view
471 //==============================================================================
473 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
474 const Standard_Integer thePxTop,
475 const Standard_Integer thePxRight,
476 const Standard_Integer thePxBottom,
477 TCollection_AsciiString& theViewId)
479 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
480 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
482 Standard_Integer aTop = 0,
486 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
487 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
488 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
489 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
490 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
492 theViewId = anIter.Key1();
493 return Standard_True;
496 return Standard_False;
499 // Workaround: to create and delete non-orthographic views outside ViewerTest
500 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
502 ViewerTest_myViews.UnBind1 (theName);
505 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
506 const Handle(V3d_View)& theView)
508 ViewerTest_myViews.Bind (theName, theView);
511 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
513 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
515 //==============================================================================
516 //function : ViewerInit
517 //purpose : Create the window viewer and initialize all the global variable
518 //==============================================================================
520 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
521 const Standard_Integer thePxTop,
522 const Standard_Integer thePxWidth,
523 const Standard_Integer thePxHeight,
524 Standard_CString theViewName,
525 Standard_CString theDisplayName)
527 // Default position and dimension of the viewer window.
528 // Note that left top corner is set to be sufficiently small to have
529 // window fit in the small screens (actual for remote desktops, see #23003).
530 // The position corresponds to the window's client area, thus some
531 // gap is added for window frame to be visible.
532 Standard_Integer aPxLeft = 20;
533 Standard_Integer aPxTop = 40;
534 Standard_Integer aPxWidth = 409;
535 Standard_Integer aPxHeight = 409;
536 Standard_Boolean toCreateViewer = Standard_False;
538 Handle(OpenGl_GraphicDriver) aGraphicDriver;
539 ViewerTest_Names aViewNames(theViewName);
540 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
541 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
548 aPxWidth = thePxWidth;
549 if (thePxHeight != 0)
550 aPxHeight = thePxHeight;
552 // Get graphic driver (create it or get from another view)
553 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
555 // Get connection string
556 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
557 TCollection_AsciiString aDisplayName(theDisplayName);
558 if (!aDisplayName.IsEmpty())
559 SetDisplayConnection (new Aspect_DisplayConnection ());
561 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
563 (void)theDisplayName; // avoid warning on unused argument
564 SetDisplayConnection (new Aspect_DisplayConnection ());
567 if (Draw_VirtualWindows)
569 // don't waste the time waiting for VSync when window is not displayed on the screen
570 ViewerTest_myDefaultCaps.swapInterval = 0;
571 // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
572 //ViewerTest_myDefaultCaps.buffersNoSwap = true;
574 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
575 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
577 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
578 toCreateViewer = Standard_True;
582 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
585 //Dispose the window if input parameters are default
586 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
588 Standard_Integer aTop = 0,
595 // Get screen resolution
596 #if defined(_WIN32) || defined(__WIN32__)
598 GetClientRect(GetDesktopWindow(), &aWindowSize);
599 aScreenHeight = aWindowSize.bottom;
600 aScreenWidth = aWindowSize.right;
601 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
602 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
604 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
605 aScreenWidth = WidthOfScreen(aScreen);
606 aScreenHeight = HeightOfScreen(aScreen);
609 TCollection_AsciiString anOverlappedViewId("");
611 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
613 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
615 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
616 && aRight + 2*aPxWidth + 40 > aScreenWidth)
618 if (aBottom + aPxHeight + 40 > aScreenHeight)
625 aPxTop = aBottom + 40;
628 aPxLeft = aRight + 20;
633 TCollection_AsciiString aTitle("3D View - ");
634 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
636 // Change name of current active window
637 if (!ViewerTest::CurrentView().IsNull())
639 TCollection_AsciiString anActiveWindowTitle("3D View - ");
640 anActiveWindowTitle = anActiveWindowTitle
641 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
642 SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString());
646 Handle(V3d_Viewer) a3DViewer;
647 // If it's the single view, we first look for empty context
648 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
650 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
651 anIter(ViewerTest_myContexts);
653 ViewerTest::SetAISContext (anIter.Value());
654 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
656 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
658 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
659 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
661 else if (a3DViewer.IsNull())
663 toCreateViewer = Standard_True;
664 a3DViewer = new V3d_Viewer(aGraphicDriver);
665 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
666 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
667 ViewerTest_DefaultBackground.GradientColor2,
668 ViewerTest_DefaultBackground.FillMethod);
672 if (ViewerTest::GetAISContext().IsNull() ||
673 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
675 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
676 ViewerTest::SetAISContext (aContext);
677 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
681 ViewerTest::ResetEventManager();
686 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
687 Handle(WNT_WClass)::DownCast (WClass()),
688 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
692 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
693 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
695 aPxWidth, aPxHeight);
696 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
698 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
701 aPxWidth, aPxHeight);
703 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
706 Handle(V3d_View) aView = a3DViewer->CreateView();
707 aView->SetWindow (VT_GetWindow());
708 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
710 ViewerTest::CurrentView(aView);
711 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
713 // Setup for X11 or NT
716 // Set parameters for V3d_View and V3d_Viewer
717 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
718 aV3dView->SetComputedMode(Standard_False);
719 MyHLRIsOn = aV3dView->ComputedMode();
721 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
724 a3DViewer->SetDefaultLights();
725 a3DViewer->SetLightOn();
728 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
729 #if TCL_MAJOR_VERSION < 8
730 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
731 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
733 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
734 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
738 VT_GetWindow()->Map();
740 // Set the handle of created view in the event manager
741 ViewerTest::ResetEventManager();
743 ViewerTest::CurrentView()->Redraw();
748 return aViewNames.GetViewName();
751 //==============================================================================
752 //function : RedrawAllViews
753 //purpose : Redraw all created views
754 //==============================================================================
755 void ViewerTest::RedrawAllViews()
757 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
758 for (; aViewIt.More(); aViewIt.Next())
760 const Handle(V3d_View)& aView = aViewIt.Key2();
765 //==============================================================================
767 //purpose : Create the window viewer and initialize all the global variable
768 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
769 //==============================================================================
771 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
775 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
776 << "Type help for more information.\n";
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.UpperCase();
788 if (ViewerTest::SplitParameter (anArg, aName, aValue))
791 if (aName.IsEqual ("NAME"))
795 else if (aName.IsEqual ("L")
796 || aName.IsEqual ("LEFT"))
798 aPxLeft = aValue.IntegerValue();
800 else if (aName.IsEqual ("T")
801 || aName.IsEqual ("TOP"))
803 aPxTop = aValue.IntegerValue();
805 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
806 else if (aName.IsEqual ("DISP")
807 || aName.IsEqual ("DISPLAY"))
809 aDisplayName = aValue;
812 else if (aName.IsEqual ("W")
813 || aName.IsEqual ("WIDTH"))
815 aPxWidth = aValue.IntegerValue();
817 else if (aName.IsEqual ("H")
818 || aName.IsEqual ("HEIGHT"))
820 aPxHeight = aValue.IntegerValue();
824 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
827 else if (aViewName.IsEmpty())
833 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
837 ViewerTest_Names aViewNames (aViewName);
838 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
840 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
841 theDi.Eval (aCommand.ToCString());
845 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
846 aViewName.ToCString(),
847 aDisplayName.ToCString());
852 //==============================================================================
854 //purpose : hidden lines removal algorithm
855 //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}]
856 //==============================================================================
858 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
860 if (ViewerTest::CurrentView().IsNull())
862 di << argv[0] << ": Call vinit before this command, please.\n";
868 di << argv[0] << ": Wrong number of command arguments.\n"
869 << "Type help " << argv[0] << " for more information.\n";
873 // Enable or disable HLR mode.
874 Standard_Boolean isHLROn =
875 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
877 if (isHLROn != MyHLRIsOn)
880 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
883 // Show or hide hidden lines in HLR mode.
884 Standard_Boolean isCurrentShowHidden
885 = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine();
887 Standard_Boolean isShowHidden =
888 (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False)
889 : isCurrentShowHidden;
892 if (isShowHidden != isCurrentShowHidden)
896 ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine();
900 ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine();
906 AIS_ListOfInteractive aListOfShapes;
907 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
909 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
911 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value());
916 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
921 ViewerTest::CurrentView()->Update();
925 //==============================================================================
926 //function : VHLRType
927 //purpose : change type of using HLR algorithm
928 //==============================================================================
930 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
932 if (ViewerTest::CurrentView().IsNull())
934 di << argv[0] << ": Call vinit before this command, please.\n";
940 di << argv[0] << ": Wrong number of command arguments.\n"
941 << "Type help " << argv[0] << " for more information.\n";
945 Prs3d_TypeOfHLR aTypeOfHLR =
946 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
950 AIS_ListOfInteractive aListOfShapes;
951 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
952 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
953 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
954 anIter.More(); anIter.Next())
956 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
959 if (aShape->TypeOfHLR() != aTypeOfHLR)
960 aShape->SetTypeOfHLR (aTypeOfHLR);
962 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
964 ViewerTest::CurrentView()->Update();
969 for (Standard_Integer i = 2; i < argc; ++i)
971 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
972 TCollection_AsciiString aName (argv[i]);
974 if (!aMap.IsBound2 (aName))
976 di << argv[0] << ": Wrong shape name:" << aName.ToCString() << ".\n";
979 Handle(AIS_Shape) anAISObject =
980 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
981 if (anAISObject.IsNull())
983 anAISObject->SetTypeOfHLR (aTypeOfHLR);
985 ViewerTest::GetAISContext()->Redisplay (anAISObject, Standard_False);
987 ViewerTest::CurrentView()->Update();
993 //==============================================================================
994 //function : FindViewIdByWindowHandle
995 //purpose : Find theView Id in the map of views by window handle
996 //==============================================================================
997 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
998 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
1000 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
1001 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1003 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
1004 if (aWindowHandle == theWindowHandle)
1005 return anIter.Key1();
1007 return TCollection_AsciiString("");
1011 //==============================================================================
1012 //function : ActivateView
1013 //purpose : Make the view active
1014 //==============================================================================
1016 void ActivateView (const TCollection_AsciiString& theViewName)
1018 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1019 if (!aView.IsNull())
1021 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1022 if (!anAISContext.IsNull())
1024 if (!ViewerTest::CurrentView().IsNull())
1026 TCollection_AsciiString aTitle("3D View - ");
1027 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1028 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1031 ViewerTest::CurrentView (aView);
1032 // Update degenerate mode
1033 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
1034 ViewerTest::SetAISContext (anAISContext);
1035 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
1036 aTitle = aTitle + theViewName + "(*)";
1037 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1038 #if defined(_WIN32) || defined(__WIN32__)
1039 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1040 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1041 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1043 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1045 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1046 ViewerTest::CurrentView()->Redraw();
1051 //==============================================================================
1052 //function : RemoveView
1054 //==============================================================================
1055 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1056 const Standard_Boolean theToRemoveContext)
1058 if (!ViewerTest_myViews.IsBound2 (theView))
1063 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1064 RemoveView (aViewName, theToRemoveContext);
1067 //==============================================================================
1068 //function : RemoveView
1069 //purpose : Close and remove view from display, clear maps if neccessary
1070 //==============================================================================
1071 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1073 if (!ViewerTest_myViews.IsBound1(theViewName))
1075 cout << "Wrong view name\n";
1079 // Activate another view if it's active now
1080 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1082 if (ViewerTest_myViews.Extent() > 1)
1084 TCollection_AsciiString aNewViewName;
1085 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
1086 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1087 if (anIter.Key1() != theViewName)
1089 aNewViewName = anIter.Key1();
1092 ActivateView (aNewViewName);
1096 Handle(V3d_View) anEmptyView;
1097 #if defined(_WIN32) || defined(__WIN32__)
1098 Handle(WNT_Window) anEmptyWindow;
1099 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1100 Handle(Cocoa_Window) anEmptyWindow;
1102 Handle(Xw_Window) anEmptyWindow;
1104 VT_GetWindow() = anEmptyWindow;
1105 ViewerTest::CurrentView (anEmptyView);
1106 if (isContextRemoved)
1108 Handle(AIS_InteractiveContext) anEmptyContext;
1109 ViewerTest::SetAISContext(anEmptyContext);
1115 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1116 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1118 // Remove view resources
1119 ViewerTest_myViews.UnBind1(theViewName);
1122 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1123 XFlush (GetDisplayConnection()->GetDisplay());
1126 // Keep context opened only if the closed view is last to avoid
1127 // unused empty contexts
1128 if (!aCurrentContext.IsNull())
1130 // Check if there are more difined views in the viewer
1131 aCurrentContext->CurrentViewer()->InitDefinedViews();
1132 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1134 // Remove driver if there is no viewers that use it
1135 Standard_Boolean isRemoveDriver = Standard_True;
1136 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1137 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1139 if (aCurrentContext != anIter.Key2() &&
1140 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1142 isRemoveDriver = Standard_False;
1147 aCurrentContext->RemoveAll (Standard_False);
1150 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1151 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1152 #if TCL_MAJOR_VERSION < 8
1153 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1155 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1160 ViewerTest_myContexts.UnBind2(aCurrentContext);
1163 cout << "3D View - " << theViewName << " was deleted.\n";
1167 //==============================================================================
1169 //purpose : Remove the view defined by its name
1170 //==============================================================================
1172 static int VClose (Draw_Interpretor& /*theDi*/,
1173 Standard_Integer theArgsNb,
1174 const char** theArgVec)
1176 NCollection_List<TCollection_AsciiString> aViewList;
1179 TCollection_AsciiString anArg (theArgVec[1]);
1181 if (anArg.IsEqual ("ALL")
1182 || anArg.IsEqual ("*"))
1184 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1185 anIter.More(); anIter.Next())
1187 aViewList.Append (anIter.Key1());
1189 if (aViewList.IsEmpty())
1191 std::cout << "No view to close\n";
1197 ViewerTest_Names aViewName (theArgVec[1]);
1198 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1200 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1203 aViewList.Append (aViewName.GetViewName());
1208 // close active view
1209 if (ViewerTest::CurrentView().IsNull())
1211 std::cerr << "No active view!\n";
1214 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1217 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1218 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1219 anIter.More(); anIter.Next())
1221 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1227 //==============================================================================
1228 //function : VActivate
1229 //purpose : Activate the view defined by its ID
1230 //==============================================================================
1232 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1236 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1237 << "Usage: " << theArgVec[0] << " ViewID\n";
1242 theDi.Eval("vviewlist");
1246 TCollection_AsciiString aNameString(theArgVec[1]);
1247 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1249 TCollection_AsciiString aTitle("3D View - ");
1250 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1251 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1252 Handle(V3d_View) anEmptyView;
1253 #if defined(_WIN32) || defined(__WIN32__)
1254 Handle(WNT_Window) anEmptyWindow;
1255 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1256 Handle(Cocoa_Window) anEmptyWindow;
1258 Handle(Xw_Window) anEmptyWindow;
1260 VT_GetWindow() = anEmptyWindow;
1261 ViewerTest::CurrentView (anEmptyView);
1262 ViewerTest::ResetEventManager();
1263 theDi << theArgVec[0] << ": all views are inactive\n";
1267 ViewerTest_Names aViewNames(aNameString);
1269 // Check if this view exists in the viewer with the driver
1270 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1272 theDi << "Wrong view name\n";
1276 // Check if it is active already
1277 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1279 theDi << theArgVec[0] << ": the view is active already\n";
1283 ActivateView (aViewNames.GetViewName());
1287 //==============================================================================
1288 //function : VViewList
1289 //purpose : Print current list of views per viewer and graphic driver ID
1290 // shared between viewers
1291 //==============================================================================
1293 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1297 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1298 << "Usage: " << theArgVec[0] << " name";
1301 if (ViewerTest_myContexts.Size() < 1)
1304 Standard_Boolean isTreeView =
1305 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1308 theDi << theArgVec[0] <<":\n";
1310 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1311 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1314 theDi << aDriverIter.Key1() << ":\n";
1316 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1317 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1319 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1323 TCollection_AsciiString aContextName(aContextIter.Key1());
1324 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
1327 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1328 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1330 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1332 TCollection_AsciiString aViewName(aViewIter.Key1());
1335 if (aViewIter.Value() == ViewerTest::CurrentView())
1336 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
1338 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1342 theDi << aViewName << " ";
1352 //==============================================================================
1353 //function : VT_ProcessKeyPress
1354 //purpose : Handle KeyPress event from a CString
1355 //==============================================================================
1356 void VT_ProcessKeyPress (const char* buf_ret)
1358 //cout << "KeyPress" << endl;
1359 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1360 // Letter in alphabetic order
1362 if (!strcasecmp (buf_ret, "A"))
1365 aView->SetProj(V3d_XposYnegZpos);
1367 else if (!strcasecmp (buf_ret, "D"))
1372 else if (!strcasecmp (buf_ret, "F"))
1374 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1376 ViewerTest::GetAISContext()->FitSelected (aView);
1384 else if (!strcasecmp (buf_ret, "H"))
1387 cout << "HLR" << endl;
1388 aView->SetComputedMode (!aView->ComputedMode());
1389 MyHLRIsOn = aView->ComputedMode();
1391 else if (!strcasecmp (buf_ret, "P"))
1394 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1395 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1396 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1398 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1399 if (aContext->NbSelected()==0)
1401 AIS_ListOfInteractive aListOfShapes;
1402 aContext->DisplayedObjects(aListOfShapes);
1403 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1404 anIter.More(); anIter.Next())
1406 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1407 if (aShape.IsNull())
1409 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1410 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1412 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1413 aContext->Redisplay (aShape, Standard_False);
1418 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
1420 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
1421 if (aShape.IsNull())
1423 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1424 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1426 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1427 aContext->Redisplay (aShape, Standard_False);
1431 aContext->UpdateCurrentViewer();
1434 else if (!strcasecmp (buf_ret, "S"))
1436 std::cout << "setup Shaded display mode" << std::endl;
1438 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1439 if(Ctx->NbSelected()==0)
1440 Ctx->SetDisplayMode(AIS_Shaded);
1442 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1443 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
1444 Ctx->UpdateCurrentViewer();
1447 else if (!strcasecmp (buf_ret, "U"))
1449 // Unset display mode
1450 std::cout << "reset display mode to defaults" << std::endl;
1452 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1453 if(Ctx->NbSelected()==0)
1454 Ctx->SetDisplayMode(AIS_WireFrame);
1456 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1457 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
1458 Ctx->UpdateCurrentViewer();
1462 else if (!strcasecmp (buf_ret, "T"))
1465 aView->SetProj(V3d_Zpos);
1467 else if (!strcasecmp (buf_ret, "B"))
1470 aView->SetProj(V3d_Zneg);
1472 else if (!strcasecmp (buf_ret, "L"))
1475 aView->SetProj(V3d_Xneg);
1477 else if (!strcasecmp (buf_ret, "R"))
1480 aView->SetProj(V3d_Xpos);
1482 else if (!strcasecmp (buf_ret, "W"))
1484 std::cout << "setup WireFrame display mode" << std::endl;
1485 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1486 if(Ctx->NbSelected()==0)
1487 Ctx->SetDisplayMode(AIS_WireFrame);
1489 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1490 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
1491 Ctx->UpdateCurrentViewer();
1494 else if (!strcasecmp (buf_ret, ","))
1496 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1498 else if (!strcasecmp (buf_ret, "."))
1500 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1502 else if (!strcasecmp (buf_ret, "/"))
1504 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1505 if (aCamera->IsStereo())
1507 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1511 else if (!strcasecmp (buf_ret, "*"))
1513 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1514 if (aCamera->IsStereo())
1516 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1520 else if (*buf_ret == THE_KEY_DELETE)
1522 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1524 && aCtx->NbSelected() > 0)
1526 Draw_Interprete ("verase");
1532 Standard_Integer Num = Draw::Atoi(buf_ret);
1533 if(Num>=0 && Num<=7)
1534 ViewerTest::StandardModeActivation(Num);
1538 //==============================================================================
1539 //function : VT_ProcessExpose
1540 //purpose : Redraw the View on an Expose Event
1541 //==============================================================================
1542 void VT_ProcessExpose()
1544 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1545 if (!aView3d.IsNull())
1551 //==============================================================================
1552 //function : VT_ProcessConfigure
1553 //purpose : Resize the View on an Configure Event
1554 //==============================================================================
1555 void VT_ProcessConfigure()
1557 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1558 if (aView3d.IsNull())
1563 aView3d->MustBeResized();
1568 //==============================================================================
1569 //function : VT_ProcessButton1Press
1571 //==============================================================================
1572 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1573 const char** theArgVec,
1574 Standard_Boolean theToPick,
1575 Standard_Boolean theIsShift)
1579 TheIsAnimating = Standard_False;
1580 return Standard_False;
1585 Standard_Real X, Y, Z;
1586 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1588 Draw::Set (theArgVec[1], X);
1589 Draw::Set (theArgVec[2], Y);
1590 Draw::Set (theArgVec[3], Z);
1595 ViewerTest::CurrentEventManager()->ShiftSelect();
1599 ViewerTest::CurrentEventManager()->Select();
1602 return Standard_False;
1605 //==============================================================================
1606 //function : VT_ProcessButton1Release
1607 //purpose : End selecting
1608 //==============================================================================
1609 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1613 IsDragged = Standard_False;
1614 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1617 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1618 X_Motion, Y_Motion);
1622 EM->Select (X_ButtonPress, Y_ButtonPress,
1623 X_Motion, Y_Motion);
1628 //==============================================================================
1629 //function : VT_ProcessButton3Press
1630 //purpose : Start Rotation
1631 //==============================================================================
1632 void VT_ProcessButton3Press()
1637 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1639 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1642 //==============================================================================
1643 //function : VT_ProcessButton3Release
1644 //purpose : End rotation
1645 //==============================================================================
1646 void VT_ProcessButton3Release()
1653 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1658 //==============================================================================
1659 //function : ProcessControlButton1Motion
1661 //==============================================================================
1663 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1664 static void ProcessControlButton1Motion()
1666 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1668 X_ButtonPress = X_Motion;
1669 Y_ButtonPress = Y_Motion;
1673 //==============================================================================
1674 //function : VT_ProcessControlButton2Motion
1676 //==============================================================================
1677 void VT_ProcessControlButton2Motion()
1679 Standard_Integer aDx = X_Motion - X_ButtonPress;
1680 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1682 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1684 ViewerTest::CurrentView()->Pan (aDx, aDy);
1686 X_ButtonPress = X_Motion;
1687 Y_ButtonPress = Y_Motion;
1690 //==============================================================================
1691 //function : VT_ProcessControlButton3Motion
1692 //purpose : Rotation
1693 //==============================================================================
1694 void VT_ProcessControlButton3Motion()
1698 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1702 //==============================================================================
1703 //function : VT_ProcessMotion
1705 //==============================================================================
1706 void VT_ProcessMotion()
1708 //pre-hilights detected objects at mouse position
1710 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1711 EM->MoveTo(X_Motion, Y_Motion);
1715 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1717 Xpix = X_Motion;Ypix=Y_Motion;
1720 //==============================================================================
1721 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1722 //purpose : Switches to an axonometric, top, left and other views
1723 //==============================================================================
1725 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1727 if ( ViewerTest::CurrentView().IsNull() )
1729 di<<"Call vinit before this command, please\n";
1733 ViewerTest::CurrentView()->SetProj(ori);
1737 //==============================================================================
1739 //purpose : Switch to an Axonometric view
1740 //Draw arg : No args
1741 //==============================================================================
1743 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1745 return ViewProject(di, V3d_XposYnegZpos);
1748 //==============================================================================
1750 //purpose : Switch to a Top View
1751 //Draw arg : No args
1752 //==============================================================================
1754 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1756 return ViewProject(di, V3d_Zpos);
1759 //==============================================================================
1760 //function : VBottom
1761 //purpose : Switch to a Bottom View
1762 //Draw arg : No args
1763 //==============================================================================
1765 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1767 return ViewProject(di, V3d_Zneg);
1770 //==============================================================================
1772 //purpose : Switch to a Left View
1773 //Draw arg : No args
1774 //==============================================================================
1776 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1778 return ViewProject(di, V3d_Xneg);
1781 //==============================================================================
1783 //purpose : Switch to a Right View
1784 //Draw arg : No args
1785 //==============================================================================
1787 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1789 return ViewProject(di, V3d_Xpos);
1792 //==============================================================================
1794 //purpose : Switch to a Front View
1795 //Draw arg : No args
1796 //==============================================================================
1798 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1800 return ViewProject(di, V3d_Yneg);
1803 //==============================================================================
1805 //purpose : Switch to a Back View
1806 //Draw arg : No args
1807 //==============================================================================
1809 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1811 return ViewProject(di, V3d_Ypos);
1814 //==============================================================================
1816 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1817 //Draw arg : No args
1818 //==============================================================================
1820 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1823 di << "Q : Quit the application\n";
1825 di << "=========================\n";
1826 di << "F : FitAll\n";
1827 di << "T : TopView\n";
1828 di << "B : BottomView\n";
1829 di << "R : RightView\n";
1830 di << "L : LeftView\n";
1831 di << "A : AxonometricView\n";
1832 di << "D : ResetView\n";
1834 di << "=========================\n";
1835 di << "S : Shading\n";
1836 di << "W : Wireframe\n";
1837 di << "H : HidelLineRemoval\n";
1838 di << "U : Unset display mode\n";
1839 di << "Delete : Remove selection from viewer\n";
1841 di << "=========================\n";
1842 di << "Selection mode \n";
1843 di << "0 : Shape\n";
1844 di << "1 : Vertex\n";
1848 di << "5 : Shell\n";
1849 di << "6 : Solid\n";
1850 di << "7 : Compound\n";
1852 di << "=========================\n";
1853 di << "Z : Switch Z clipping On/Off\n";
1854 di << ", : Hilight next detected\n";
1855 di << ". : Hilight previous detected\n";
1862 static Standard_Boolean Ppick = 0;
1863 static Standard_Integer Pargc = 0;
1864 static const char** Pargv = NULL;
1867 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1872 if (!ViewerTest_myViews.IsEmpty()) {
1874 WPARAM fwKeys = wParam;
1879 // Delete view from map of views
1880 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1885 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1886 || ViewerTest::CurrentView().IsNull())
1888 // Activate inactive window
1889 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1891 ActivateView (FindViewIdByWindowHandle(hwnd));
1897 if (IsDragged && !DragFirst)
1899 if (!GetActiveAISManipulator().IsNull())
1901 GetActiveAISManipulator()->StopTransform();
1902 ViewerTest::GetAISContext()->ClearSelected();
1905 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
1907 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
1908 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
1911 VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0);
1913 IsDragged = Standard_False;
1914 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1917 if (IsDragged && !DragFirst)
1919 if (!GetActiveAISManipulator().IsNull())
1921 GetActiveAISManipulator()->StopTransform (Standard_False);
1922 ViewerTest::GetAISContext()->ClearSelected();
1924 IsDragged = Standard_False;
1926 return ViewerWindowProc (hwnd, Msg, wParam, lParam);
1928 case WM_LBUTTONDOWN:
1929 if (!GetActiveAISManipulator().IsNull())
1931 IsDragged = ( fwKeys == MK_LBUTTON );
1935 IsDragged = ( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) );
1940 DragFirst = Standard_True;
1941 X_ButtonPress = LOWORD(lParam);
1942 Y_ButtonPress = HIWORD(lParam);
1944 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1949 X_Motion = LOWORD (lParam);
1950 Y_Motion = HIWORD (lParam);
1951 if (!GetActiveAISManipulator().IsNull())
1955 GetActiveAISManipulator()->StartTransform (X_ButtonPress, Y_ButtonPress, ViewerTest::CurrentView());
1959 GetActiveAISManipulator()->Transform (X_Motion, Y_Motion, ViewerTest::CurrentView());
1960 ViewerTest::GetAISContext()->CurrentViewer()->Redraw();
1965 bool toRedraw = false;
1966 if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
1968 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
1973 if (GetClientRect (hwnd, &aRect))
1975 int aHeight = aRect.bottom - aRect.top;
1976 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
1977 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed);
1982 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
1986 DragFirst = Standard_False;
1989 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1993 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1997 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
2001 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
2007 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2010 return DefWindowProcW (hwnd, Msg, wParam, lParam);
2017 BeginPaint(hwnd, &ps);
2018 EndPaint(hwnd, &ps);
2023 VT_ProcessConfigure();
2028 switch (aView->RenderingParams().StereoMode)
2030 case Graphic3d_StereoMode_RowInterlaced:
2031 case Graphic3d_StereoMode_ColumnInterlaced:
2032 case Graphic3d_StereoMode_ChessBoard:
2033 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2041 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2044 c[0] = (char) wParam;
2046 if (wParam == VK_DELETE)
2048 c[0] = THE_KEY_DELETE;
2051 else if (wParam == VK_OEM_COMMA)
2056 else if (wParam == VK_OEM_PERIOD)
2060 else if (wParam == VK_DIVIDE)
2065 else if (wParam == VK_MULTIPLY)
2069 VT_ProcessKeyPress (c);
2077 VT_ProcessButton3Release();
2080 case WM_LBUTTONDOWN:
2081 case WM_MBUTTONDOWN:
2082 case WM_RBUTTONDOWN:
2084 WPARAM fwKeys = wParam;
2088 X_ButtonPress = LOWORD(lParam);
2089 Y_ButtonPress = HIWORD(lParam);
2091 if (Msg == WM_LBUTTONDOWN)
2093 if ((fwKeys & MK_CONTROL) != 0)
2095 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2099 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2102 else if (Msg == WM_RBUTTONDOWN)
2105 VT_ProcessButton3Press();
2112 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2113 if (wParam & MK_CONTROL)
2115 if (aView->Camera()->IsStereo())
2117 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2121 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2128 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2135 //cout << "\t WM_MOUSEMOVE" << endl;
2136 WPARAM fwKeys = wParam;
2137 X_Motion = LOWORD(lParam);
2138 Y_Motion = HIWORD(lParam);
2141 (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 )
2144 X_ButtonPress = LOWORD(lParam);
2145 Y_ButtonPress = HIWORD(lParam);
2147 if ((fwKeys & MK_RBUTTON) != 0) {
2149 VT_ProcessButton3Press();
2153 if ((fwKeys & MK_CONTROL) != 0)
2155 if ((fwKeys & MK_LBUTTON) != 0)
2157 ProcessControlButton1Motion();
2159 else if ((fwKeys & MK_MBUTTON) != 0
2160 || ((fwKeys & MK_LBUTTON) != 0
2161 && (fwKeys & MK_RBUTTON) != 0))
2163 VT_ProcessControlButton2Motion();
2165 else if ((fwKeys & MK_RBUTTON) != 0)
2167 VT_ProcessControlButton3Motion();
2170 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2178 return DefWindowProcW (hwnd, Msg, wParam, lParam);
2183 //==============================================================================
2184 //function : ViewerMainLoop
2185 //purpose : Get a Event on the view and dispatch it
2186 //==============================================================================
2189 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2191 Ppick = (argc > 0)? 1 : 0;
2199 cout << "Start picking" << endl;
2201 while ( Ppick == 1 ) {
2202 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2203 if (GetMessageW (&msg, NULL, 0, 0))
2205 TranslateMessage (&msg);
2206 DispatchMessageW (&msg);
2210 cout << "Picking done" << endl;
2216 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2218 int min( int a, int b )
2226 int max( int a, int b )
2234 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2237 static XEvent aReport;
2238 Standard_Boolean pick = argc > 0;
2239 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2240 XNextEvent (aDisplay, &aReport);
2242 // Handle event for the chosen display connection
2243 switch (aReport.type) {
2246 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2249 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2255 // Activate inactive view
2256 Window aWindow = GetWindowHandle(VT_GetWindow());
2257 if(aWindow != aReport.xfocus.window)
2259 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2268 case ConfigureNotify:
2270 VT_ProcessConfigure();
2279 XComposeStatus status_in_out;
2281 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2282 (char *) buf_ret , 10 ,
2283 &ks_ret , &status_in_out ) ;
2286 buf_ret[ret_len] = '\0' ;
2290 VT_ProcessKeyPress (buf_ret);
2296 X_ButtonPress = aReport.xbutton.x;
2297 Y_ButtonPress = aReport.xbutton.y;
2299 if (aReport.xbutton.button == Button1)
2301 if (aReport.xbutton.state & ControlMask)
2303 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2307 IsDragged = Standard_True;
2308 DragFirst = Standard_True;
2311 else if (aReport.xbutton.button == Button3)
2314 VT_ProcessButton3Press();
2324 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2326 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2327 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2331 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2332 if( aContext.IsNull() )
2334 cout << "The context is null. Please use vinit before createmesh" << endl;
2338 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2339 if( aReport.xbutton.button==1 )
2343 aContext->ShiftSelect();
2352 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2353 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2354 ViewerTest::CurrentView());
2358 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2359 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2360 ViewerTest::CurrentView() );
2363 VT_ProcessButton3Release();
2365 IsDragged = Standard_False;
2368 VT_ProcessButton3Release();
2373 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2381 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2383 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2387 X_Motion = aReport.xmotion.x;
2388 Y_Motion = aReport.xmotion.y;
2389 DragFirst = Standard_False;
2391 Window aWindow = GetWindowHandle(VT_GetWindow());
2394 unsigned int aWidth, aHeight, aBorderWidth, aDepth;
2395 XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth);
2396 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2397 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed);
2398 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2402 X_Motion = aReport.xmotion.x;
2403 Y_Motion = aReport.xmotion.y;
2405 // remove all the ButtonMotionMaskr
2406 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2408 if ( aReport.xmotion.state & ControlMask ) {
2409 if ( aReport.xmotion.state & Button1Mask ) {
2410 ProcessControlButton1Motion();
2412 else if ( aReport.xmotion.state & Button2Mask ) {
2413 VT_ProcessControlButton2Motion();
2415 else if ( aReport.xmotion.state & Button3Mask ) {
2416 VT_ProcessControlButton3Motion();
2430 //==============================================================================
2431 //function : VProcessEvents
2432 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2433 // event in the Viewer window
2434 //==============================================================================
2436 static void VProcessEvents(ClientData,int)
2438 NCollection_Vector<int> anEventNumbers;
2439 // Get number of messages from every display
2440 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2441 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2443 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2445 // Handle events for every display
2446 int anEventIter = 0;
2447 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2448 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2450 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2451 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2453 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2454 int anEventResult = ViewerMainLoop( 0, NULL);
2455 // If window is closed or context was not found finish current event processing loop
2461 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2466 //==============================================================================
2467 //function : OSWindowSetup
2468 //purpose : Setup for the X11 window to be able to cath the event
2469 //==============================================================================
2472 static void OSWindowSetup()
2474 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2477 Window window = VT_GetWindow()->XWindow();
2478 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2479 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2480 XSynchronize(aDisplay, 1);
2482 // X11 : For keyboard on SUN
2484 wmhints.flags = InputHint;
2487 XSetWMHints( aDisplay, window, &wmhints);
2489 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2490 ButtonPressMask | ButtonReleaseMask |
2491 StructureNotifyMask |
2493 Button1MotionMask | Button2MotionMask |
2494 Button3MotionMask | FocusChangeMask
2496 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2497 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2499 XSynchronize(aDisplay, 0);
2507 //==============================================================================
2510 //==============================================================================
2512 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgv)
2514 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2517 std::cout << "Error: no active viewer!\n";
2521 Standard_Boolean toFit = Standard_True;
2522 ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
2523 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2525 TCollection_AsciiString anArg (theArgv[anArgIter]);
2527 if (anUpdateTool.parseRedrawMode (anArg))
2531 else if (anArg == "-selected")
2533 ViewerTest::GetAISContext()->FitSelected (aView, 0.01, Standard_False);
2534 toFit = Standard_False;
2538 std::cout << "Syntax error at '" << anArg << "'\n";
2544 aView->FitAll (0.01, Standard_False);
2549 //=======================================================================
2550 //function : VFitArea
2551 //purpose : Fit view to show area located between two points
2552 // : given in world 2D or 3D coordinates.
2553 //=======================================================================
2554 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2556 Handle(V3d_View) aView = ViewerTest::CurrentView();
2559 std::cerr << theArgVec[0] << "Error: No active view.\n";
2564 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2565 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2569 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2570 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2571 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2572 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2574 else if (theArgNb == 7)
2576 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2577 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2578 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2579 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2580 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2581 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2585 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2586 theDI.PrintHelp(theArgVec[0]);
2590 // Convert model coordinates to view space
2591 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2592 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2593 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2595 // Determine fit area
2596 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2597 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2599 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2601 if (aDiagonal < Precision::Confusion())
2603 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2607 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2611 //==============================================================================
2613 //purpose : ZFitall, no DRAW arguments
2614 //Draw arg : No args
2615 //==============================================================================
2616 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2618 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2620 if (aCurrentView.IsNull())
2622 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2628 aCurrentView->ZFitAll();
2629 aCurrentView->Redraw();
2633 Standard_Real aScale = 1.0;
2637 aScale = Draw::Atoi (theArgVec[1]);
2640 aCurrentView->ZFitAll (aScale);
2641 aCurrentView->Redraw();
2646 //==============================================================================
2647 //function : VRepaint
2649 //==============================================================================
2650 static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
2652 Handle(V3d_View) V = ViewerTest::CurrentView();
2653 if ( !V.IsNull() ) V->Redraw(); return 0;
2656 //==============================================================================
2658 //purpose : Remove all the object from the viewer
2659 //Draw arg : No args
2660 //==============================================================================
2662 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2664 Handle(V3d_View) V = ViewerTest::CurrentView();
2666 ViewerTest::Clear();
2670 //==============================================================================
2673 //==============================================================================
2675 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2676 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2679 di << argv[0] << "Invalid number of arguments\n";
2683 while (ViewerMainLoop( argc, argv)) {
2689 //==============================================================================
2691 //purpose : Load image as background
2692 //==============================================================================
2694 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2696 if (argc < 2 || argc > 3)
2698 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n";
2699 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n";
2703 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2704 if(AISContext.IsNull())
2706 di << "use 'vinit' command before " << argv[0] << "\n";
2710 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2713 const char* szType = argv[2];
2714 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2715 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2716 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2717 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2720 di << "Wrong fill type : " << szType << "\n";
2721 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
2726 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2727 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2732 //==============================================================================
2733 //function : VSetBgMode
2734 //purpose : Change background image fill type
2735 //==============================================================================
2737 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2741 di << "Usage : " << argv[0] << " filltype : Change background image mode\n";
2742 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n";
2746 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2747 if(AISContext.IsNull())
2749 di << "use 'vinit' command before " << argv[0] << "\n";
2752 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2753 const char* szType = argv[1];
2754 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2755 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2756 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2757 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2760 di << "Wrong fill type : " << szType << "\n";
2761 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
2764 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2765 V3dView->SetBgImageStyle(aFillType, Standard_True);
2769 //==============================================================================
2770 //function : VSetGradientBg
2771 //purpose : Mount gradient background
2772 //==============================================================================
2773 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2777 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background\n";
2778 di << "R1,G1,B1,R2,G2,B2 = [0..255]\n";
2779 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2780 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
2784 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2785 if(AISContext.IsNull())
2787 di << "use 'vinit' command before " << argv[0] << "\n";
2793 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2794 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2795 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2796 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2798 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2799 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2800 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2802 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2803 int aType = Draw::Atoi(argv[7]);
2804 if( aType < 0 || aType > 8 )
2806 di << "Wrong fill type \n";
2807 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2808 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
2812 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2814 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2815 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2821 //==============================================================================
2822 //function : VSetGradientBgMode
2823 //purpose : Change gradient background fill style
2824 //==============================================================================
2825 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2829 di << "Usage : " << argv[0] << " Type : Change gradient background fill type\n";
2830 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2831 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
2835 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2836 if(AISContext.IsNull())
2838 di << "use 'vinit' command before " << argv[0] << "\n";
2843 int aType = Draw::Atoi(argv[1]);
2844 if( aType < 0 || aType > 8 )
2846 di << "Wrong fill type \n";
2847 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2848 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
2852 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2854 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2855 V3dView->SetBgGradientStyle( aMethod, 1 );
2861 //==============================================================================
2862 //function : VSetColorBg
2863 //purpose : Set color background
2864 //==============================================================================
2865 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2869 di << "Usage : " << argv[0] << " R G B : Set color background\n";
2870 di << "R,G,B = [0..255]\n";
2874 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2875 if(AISContext.IsNull())
2877 di << "use 'vinit' command before " << argv[0] << "\n";
2883 Standard_Real R = Draw::Atof(argv[1])/255.;
2884 Standard_Real G = Draw::Atof(argv[2])/255.;
2885 Standard_Real B = Draw::Atof(argv[3])/255.;
2886 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2888 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2889 V3dView->SetBackgroundColor( aColor );
2896 //==============================================================================
2897 //function : VSetDefaultBg
2898 //purpose : Set default viewer background fill color
2899 //==============================================================================
2900 static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2905 std::cout << "Error: wrong syntax! See usage:\n";
2906 theDI.PrintHelp (theArgVec[0]);
2910 ViewerTest_DefaultBackground.FillMethod =
2911 theArgNb == 4 ? Aspect_GFM_NONE
2912 : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]);
2916 Standard_Real R = Draw::Atof (theArgVec[1]) / 255.;
2917 Standard_Real G = Draw::Atof (theArgVec[2]) / 255.;
2918 Standard_Real B = Draw::Atof (theArgVec[3]) / 255.;
2919 ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB);
2923 Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.;
2924 Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.;
2925 Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.;
2926 ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB);
2928 Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.;
2929 Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.;
2930 Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.;
2931 ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB);
2934 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
2935 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
2937 const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer();
2938 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
2939 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
2940 ViewerTest_DefaultBackground.GradientColor2,
2941 ViewerTest_DefaultBackground.FillMethod);
2947 //==============================================================================
2949 //purpose : View Scaling
2950 //==============================================================================
2952 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2954 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2955 if ( V3dView.IsNull() ) return 1;
2958 di << argv[0] << "Invalid number of arguments\n";
2961 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2964 //==============================================================================
2965 //function : VZBuffTrihedron
2967 //==============================================================================
2969 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
2970 Standard_Integer theArgNb,
2971 const char** theArgVec)
2973 Handle(V3d_View) aView = ViewerTest::CurrentView();
2976 std::cout << "Error: no active viewer!\n";
2980 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
2982 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2983 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
2984 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
2985 Quantity_Color anArrowColorX = Quantity_NOC_RED;
2986 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
2987 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
2988 Standard_Real aScale = 0.1;
2989 Standard_Real aSizeRatio = 0.8;
2990 Standard_Real anArrowDiam = 0.05;
2991 Standard_Integer aNbFacets = 12;
2992 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2994 Standard_CString anArg = theArgVec[anArgIter];
2995 TCollection_AsciiString aFlag (anArg);
2997 if (anUpdateTool.parseRedrawMode (aFlag))
3001 else if (aFlag == "-on")
3005 else if (aFlag == "-off")
3007 aView->TriedronErase();
3010 else if (aFlag == "-pos"
3011 || aFlag == "-position"
3012 || aFlag == "-corner")
3014 if (++anArgIter >= theArgNb)
3016 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3020 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3021 aPosName.LowerCase();
3022 if (aPosName == "center")
3024 aPosition = Aspect_TOTP_CENTER;
3026 else if (aPosName == "left_lower"
3027 || aPosName == "lower_left"
3028 || aPosName == "leftlower"
3029 || aPosName == "lowerleft")
3031 aPosition = Aspect_TOTP_LEFT_LOWER;
3033 else if (aPosName == "left_upper"
3034 || aPosName == "upper_left"
3035 || aPosName == "leftupper"
3036 || aPosName == "upperleft")
3038 aPosition = Aspect_TOTP_LEFT_UPPER;
3040 else if (aPosName == "right_lower"
3041 || aPosName == "lower_right"
3042 || aPosName == "rightlower"
3043 || aPosName == "lowerright")
3045 aPosition = Aspect_TOTP_RIGHT_LOWER;
3047 else if (aPosName == "right_upper"
3048 || aPosName == "upper_right"
3049 || aPosName == "rightupper"
3050 || aPosName == "upperright")
3052 aPosition = Aspect_TOTP_RIGHT_UPPER;
3056 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3060 else if (aFlag == "-type")
3062 if (++anArgIter >= theArgNb)
3064 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3068 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3069 aTypeName.LowerCase();
3070 if (aTypeName == "wireframe"
3071 || aTypeName == "wire")
3073 aVisType = V3d_WIREFRAME;
3075 else if (aTypeName == "zbuffer"
3076 || aTypeName == "shaded")
3078 aVisType = V3d_ZBUFFER;
3082 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3085 else if (aFlag == "-scale")
3087 if (++anArgIter >= theArgNb)
3089 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3093 aScale = Draw::Atof (theArgVec[anArgIter]);
3095 else if (aFlag == "-size"
3096 || aFlag == "-sizeratio")
3098 if (++anArgIter >= theArgNb)
3100 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3104 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3106 else if (aFlag == "-arrowdiam"
3107 || aFlag == "-arrowdiameter")
3109 if (++anArgIter >= theArgNb)
3111 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3115 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3117 else if (aFlag == "-nbfacets")
3119 if (++anArgIter >= theArgNb)
3121 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3125 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3127 else if (aFlag == "-colorlabel"
3128 || aFlag == "-colorlabels")
3130 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3131 theArgVec + anArgIter + 1,
3135 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3138 anArgIter += aNbParsed;
3140 else if (aFlag == "-colorarrowx")
3142 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3143 theArgVec + anArgIter + 1,
3147 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3150 anArgIter += aNbParsed;
3152 else if (aFlag == "-colorarrowy")
3154 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3155 theArgVec + anArgIter + 1,
3159 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3162 anArgIter += aNbParsed;
3164 else if (aFlag == "-colorarrowz")
3166 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3167 theArgVec + anArgIter + 1,
3171 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3174 anArgIter += aNbParsed;
3178 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3183 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3184 aSizeRatio, anArrowDiam, aNbFacets);
3185 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
3190 //==============================================================================
3191 //function : VRotate
3192 //purpose : Camera Rotating
3193 //==============================================================================
3195 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3197 Handle(V3d_View) aView = ViewerTest::CurrentView();
3200 std::cout << "No active view!\n";
3204 Standard_Boolean hasFlags = Standard_False;
3205 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3207 Standard_CString anArg (theArgVec[anArgIter]);
3208 TCollection_AsciiString aFlag (anArg);
3210 if (aFlag == "-mousestart"
3211 || aFlag == "-mousefrom")
3213 hasFlags = Standard_True;
3214 if (anArgIter + 2 >= theArgNb)
3216 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3220 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3221 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3222 aView->StartRotation (anX, anY);
3224 else if (aFlag == "-mousemove")
3226 hasFlags = Standard_True;
3227 if (anArgIter + 2 >= theArgNb)
3229 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3233 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3234 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3235 aView->Rotation (anX, anY);
3237 else if (theArgNb != 4
3240 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3249 else if (theArgNb == 4)
3251 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3252 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3253 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3254 aView->Rotate (anAX, anAY, anAZ);
3257 else if (theArgNb == 7)
3259 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3260 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3261 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3263 Standard_Real anX = Draw::Atof (theArgVec[4]);
3264 Standard_Real anY = Draw::Atof (theArgVec[5]);
3265 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3267 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3271 std::cout << "Error: Invalid number of arguments\n";
3275 //==============================================================================
3277 //purpose : View zoom in / out (relative to current zoom)
3278 //==============================================================================
3280 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3281 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3282 if ( V3dView.IsNull() ) {
3287 Standard_Real coef = Draw::Atof(argv[1]);
3288 if ( coef <= 0.0 ) {
3289 di << argv[1] << "Invalid value\n";
3292 V3dView->SetZoom( Draw::Atof(argv[1]) );
3295 di << argv[0] << " Invalid number of arguments\n";
3300 //==============================================================================
3302 //purpose : View panning (in pixels)
3303 //==============================================================================
3305 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3306 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3307 if ( V3dView.IsNull() ) return 1;
3310 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
3313 di << argv[0] << " Invalid number of arguments\n";
3318 //==============================================================================
3320 //purpose : Place the point (in pixels) at the center of the window
3321 //==============================================================================
3322 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3324 Handle(V3d_View) aView = ViewerTest::CurrentView();
3327 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3333 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3337 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3342 //==============================================================================
3343 //function : VExport
3344 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
3345 //==============================================================================
3347 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3349 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3350 if (V3dView.IsNull())
3355 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
3359 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
3360 TCollection_AsciiString aFormatStr;
3362 TCollection_AsciiString aFileName (argv[1]);
3363 Standard_Integer aLen = aFileName.Length();
3367 aFormatStr = TCollection_AsciiString (argv[2]);
3371 if (aFileName.Value (aLen - 2) == '.')
3373 aFormatStr = aFileName.ToCString() + aLen - 2;
3375 else if (aFileName.Value (aLen - 3) == '.')
3377 aFormatStr = aFileName.ToCString() + aLen - 3;
3381 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3387 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3391 aFormatStr.UpperCase();
3392 if (aFormatStr == "PS")
3393 anExpFormat = Graphic3d_EF_PostScript;
3394 else if (aFormatStr == "EPS")
3395 anExpFormat = Graphic3d_EF_EnhPostScript;
3396 else if (aFormatStr == "TEX")
3397 anExpFormat = Graphic3d_EF_TEX;
3398 else if (aFormatStr == "PDF")
3399 anExpFormat = Graphic3d_EF_PDF;
3400 else if (aFormatStr == "SVG")
3401 anExpFormat = Graphic3d_EF_SVG;
3402 else if (aFormatStr == "PGF")
3403 anExpFormat = Graphic3d_EF_PGF;
3404 else if (aFormatStr == "EMF")
3405 anExpFormat = Graphic3d_EF_EMF;
3408 std::cout << "Invalid export format '" << aFormatStr << "'\n";
3412 Standard_DISABLE_DEPRECATION_WARNINGS
3415 if (!V3dView->Export (argv[1], anExpFormat))
3417 di << "Error: export of image to " << aFormatStr << " failed!\n";
3420 catch (Standard_Failure)
3422 di << "Error: export of image to " << aFormatStr << " failed";
3423 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
3425 Standard_ENABLE_DEPRECATION_WARNINGS
3429 static int VColorScale (Draw_Interpretor& theDI,
3430 Standard_Integer theArgNb,
3431 const char** theArgVec)
3433 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3434 Handle(V3d_View) aView = ViewerTest::CurrentView();
3435 if (aContext.IsNull())
3437 std::cout << "Error: no active view!\n";
3442 std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n";
3446 Handle(AIS_ColorScale) aColorScale;
3447 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
3449 // find existing object
3450 aColorScale = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
3451 if (aColorScale.IsNull())
3453 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
3460 if (aColorScale.IsNull())
3462 std::cout << "Syntax error: colorscale with a given name does not exist.\n";
3466 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
3467 << "Min range: " << aColorScale->GetMin() << "\n"
3468 << "Max range: " << aColorScale->GetMax() << "\n"
3469 << "Number of intervals: " << aColorScale->GetNumberOfIntervals() << "\n"
3470 << "Text height: " << aColorScale->GetTextHeight() << "\n"
3471 << "Color scale position: " << aColorScale->GetXPosition() << " " << aColorScale->GetYPosition() << "\n"
3472 << "Color scale title: " << aColorScale->GetTitle() << "\n"
3473 << "Label position: ";
3474 switch (aColorScale->GetLabelPosition())
3476 case Aspect_TOCSP_NONE:
3479 case Aspect_TOCSP_LEFT:
3482 case Aspect_TOCSP_RIGHT:
3485 case Aspect_TOCSP_CENTER:
3486 theDI << "Center\n";
3492 if (aColorScale.IsNull())
3494 aColorScale = new AIS_ColorScale();
3495 aColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
3496 aContext->SetTransformPersistence (aColorScale, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
3499 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
3500 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
3502 Standard_CString anArg = theArgVec[anArgIter];
3503 TCollection_AsciiString aFlag (anArg);
3505 if (anUpdateTool.parseRedrawMode (aFlag))
3509 else if (aFlag == "-range")
3511 if (anArgIter + 3 >= theArgNb)
3513 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3517 const TCollection_AsciiString aRangeMin (theArgVec[++anArgIter]);
3518 const TCollection_AsciiString aRangeMax (theArgVec[++anArgIter]);
3519 const TCollection_AsciiString aNbIntervals (theArgVec[++anArgIter]);
3520 if (!aRangeMin.IsRealValue()
3521 || !aRangeMax.IsRealValue())
3523 std::cout << "Error: the range values should be real!\n";
3526 else if (!aNbIntervals.IsIntegerValue())
3528 std::cout << "Error: the number of intervals should be integer!\n";
3532 aColorScale->SetRange (aRangeMin.RealValue(), aRangeMax.RealValue());
3533 aColorScale->SetNumberOfIntervals (aNbIntervals.IntegerValue());
3535 else if (aFlag == "-font")
3537 if (anArgIter + 1 >= theArgNb)
3539 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3542 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
3543 if (!aFontArg.IsIntegerValue())
3545 std::cout << "Error: HeightFont value should be integer!\n";
3549 aColorScale->SetTextHeight (aFontArg.IntegerValue());
3552 else if (aFlag == "-textpos")
3554 if (anArgIter + 1 >= theArgNb)
3556 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3560 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
3561 aTextPosArg.LowerCase();
3562 Aspect_TypeOfColorScalePosition aLabPosition = Aspect_TOCSP_NONE;
3563 if (aTextPosArg == "none")
3565 aLabPosition = Aspect_TOCSP_NONE;
3567 else if (aTextPosArg == "left")
3569 aLabPosition = Aspect_TOCSP_LEFT;
3571 else if (aTextPosArg == "right")
3573 aLabPosition = Aspect_TOCSP_RIGHT;
3575 else if (aTextPosArg == "center")
3577 aLabPosition = Aspect_TOCSP_CENTER;
3581 std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
3584 aColorScale->SetLabelPosition (aLabPosition);
3586 else if (aFlag == "-logarithmic"
3589 if (anArgIter + 1 >= theArgNb)
3591 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3595 Standard_Boolean IsLog;
3596 if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
3598 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3601 aColorScale->SetLogarithmic (IsLog);
3603 else if (aFlag == "-huerange"
3606 if (anArgIter + 2 >= theArgNb)
3608 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3612 const Standard_Real aHueMin = Draw::Atof (theArgVec[++anArgIter]);
3613 const Standard_Real aHueMax = Draw::Atof (theArgVec[++anArgIter]);
3614 aColorScale->SetHueRange (aHueMin, aHueMax);
3616 else if (aFlag == "-colorrange")
3618 Quantity_Color aColorMin, aColorMax;
3619 Standard_Integer aNbParsed1 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3620 theArgVec + (anArgIter + 1),
3622 anArgIter += aNbParsed1;
3623 Standard_Integer aNbParsed2 = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3624 theArgVec + (anArgIter + 1),
3626 anArgIter += aNbParsed2;
3630 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3634 aColorScale->SetColorRange (aColorMin, aColorMax);
3636 else if (aFlag == "-reversed"
3637 || aFlag == "-inverted"
3638 || aFlag == "-topdown"
3639 || aFlag == "-bottomup")
3641 Standard_Boolean toEnable = Standard_True;
3642 if (anArgIter + 1 < theArgNb
3643 && ViewerTest::ParseOnOff(theArgVec[anArgIter + 1], toEnable))
3647 aColorScale->SetReversed ((aFlag == "-topdown") ? !toEnable : toEnable);
3649 else if (aFlag == "-smooth"
3650 || aFlag == "-smoothtransition")
3652 Standard_Boolean toEnable = Standard_True;
3653 if (anArgIter + 1 < theArgNb
3654 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
3658 aColorScale->SetSmoothTransition (toEnable);
3660 else if (aFlag == "-xy")
3662 if (anArgIter + 2 >= theArgNb)
3664 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3668 const TCollection_AsciiString anX (theArgVec[++anArgIter]);
3669 const TCollection_AsciiString anY (theArgVec[++anArgIter]);
3670 if (!anX.IsIntegerValue()
3671 || !anY.IsIntegerValue())
3673 std::cout << "Error: coordinates should be integer values!\n";
3677 aColorScale->SetPosition (anX.IntegerValue(), anY.IntegerValue());
3679 else if (aFlag == "-width"
3681 || aFlag == "-breadth")
3683 if (anArgIter + 1 >= theArgNb)
3685 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3689 const TCollection_AsciiString aBreadth (theArgVec[++anArgIter]);
3690 if (!aBreadth.IsIntegerValue())
3692 std::cout << "Error: a width should be an integer value!\n";
3695 aColorScale->SetBreadth (aBreadth.IntegerValue());
3697 else if (aFlag == "-height"
3700 if (anArgIter + 1 >= theArgNb)
3702 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3706 const TCollection_AsciiString aHeight (theArgVec[++anArgIter]);
3707 if (!aHeight.IsIntegerValue())
3709 std::cout << "Error: a width should be an integer value!\n";
3712 aColorScale->SetHeight (aHeight.IntegerValue());
3714 else if (aFlag == "-color")
3716 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
3718 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3721 else if (anArgIter + 2 >= theArgNb)
3723 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3727 const TCollection_AsciiString anInd (theArgVec[++anArgIter]);
3728 if (!anInd.IsIntegerValue())
3730 std::cout << "Error: Index value should be integer!\n";
3733 const Standard_Integer anIndex = anInd.IntegerValue();
3734 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals())
3736 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() <<"!\n";
3740 Quantity_Color aColor;
3741 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3742 theArgVec + (anArgIter + 1),
3746 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3749 aColorScale->SetIntervalColor (aColor, anIndex);
3750 aColorScale->SetColorType (Aspect_TOCSD_USER);
3751 anArgIter += aNbParsed;
3753 else if (aFlag == "-label")
3755 if (aColorScale->GetColorType() != Aspect_TOCSD_USER)
3757 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
3760 else if (anArgIter + 2 >= theArgNb)
3762 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3766 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
3767 if (anIndex <= 0 || anIndex > aColorScale->GetNumberOfIntervals() + 1)
3769 std::cout << "Error: Index value should be within range 1.." << aColorScale->GetNumberOfIntervals() + 1 <<"!\n";
3773 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
3774 aColorScale->SetLabel (aText, anIndex);
3775 aColorScale->SetLabelType (Aspect_TOCSD_USER);
3778 else if (aFlag == "-labelat"
3779 || aFlag == "-labat"
3780 || aFlag == "-labelatborder"
3781 || aFlag == "-labatborder"
3782 || aFlag == "-labelatcenter"
3783 || aFlag == "-labatcenter")
3785 Standard_Boolean toEnable = Standard_True;
3786 if (aFlag == "-labelat"
3787 || aFlag == "-labat")
3789 Standard_Integer aLabAtBorder = -1;
3790 if (++anArgIter >= theArgNb)
3792 TCollection_AsciiString anAtBorder (theArgVec[anArgIter]);
3793 anAtBorder.LowerCase();
3794 if (anAtBorder == "border")
3798 else if (anAtBorder == "center")
3803 if (aLabAtBorder == -1)
3805 std::cout << "Syntax error at argument '" << anArg << "'!\n";
3808 toEnable = (aLabAtBorder == 1);
3810 else if (anArgIter + 1 < theArgNb
3811 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
3815 aColorScale->SetLabelAtBorder (aFlag == "-labelatcenter"
3816 || aFlag == "-labatcenter"
3820 else if (aFlag == "-colors")
3822 Aspect_SequenceOfColor aSeq;
3825 Quantity_Color aColor;
3826 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - (anArgIter + 1),
3827 theArgVec + (anArgIter + 1),
3833 anArgIter += aNbParsed;
3834 aSeq.Append (aColor);
3836 if (aSeq.Length() != aColorScale->GetNumberOfIntervals())
3838 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3839 << aColorScale->GetNumberOfIntervals() << " intervals\n";
3843 aColorScale->SetColors (aSeq);
3844 aColorScale->SetColorType (Aspect_TOCSD_USER);
3846 else if (aFlag == "-labels"
3847 || aFlag == "-freelabels")
3849 if (anArgIter + 1 >= theArgNb)
3851 std::cout << "Syntax error at argument '" << anArg << "'!\n";
3855 Standard_Integer aNbLabels = aColorScale->IsLabelAtBorder()
3856 ? aColorScale->GetNumberOfIntervals() + 1
3857 : aColorScale->GetNumberOfIntervals();
3858 if (aFlag == "-freelabels")
3861 aNbLabels = Draw::Atoi (theArgVec[anArgIter]);
3863 if (anArgIter + aNbLabels >= theArgNb)
3865 std::cout << "Error: not enough arguments! " << aNbLabels << " text labels are expected.\n";
3869 TColStd_SequenceOfExtendedString aSeq;
3870 for (Standard_Integer aLabelIter = 0; aLabelIter < aNbLabels; ++aLabelIter)
3872 aSeq.Append (TCollection_ExtendedString (theArgVec[++anArgIter]));
3874 aColorScale->SetLabels (aSeq);
3875 aColorScale->SetLabelType (Aspect_TOCSD_USER);
3877 else if (aFlag == "-title")
3879 if (anArgIter + 1 >= theArgNb)
3881 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3885 Standard_Boolean isTwoArgs = Standard_False;
3886 if (anArgIter + 2 < theArgNb)
3888 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
3889 aSecondArg.LowerCase();
3890 Standard_DISABLE_DEPRECATION_WARNINGS
3891 if (aSecondArg == "none")
3893 aColorScale->SetTitlePosition (Aspect_TOCSP_NONE);
3894 isTwoArgs = Standard_True;
3896 else if (aSecondArg == "left")
3898 aColorScale->SetTitlePosition (Aspect_TOCSP_LEFT);
3899 isTwoArgs = Standard_True;
3901 else if (aSecondArg == "right")
3903 aColorScale->SetTitlePosition (Aspect_TOCSP_RIGHT);
3904 isTwoArgs = Standard_True;
3906 else if (aSecondArg == "center")
3908 aColorScale->SetTitlePosition (Aspect_TOCSP_CENTER);
3909 isTwoArgs = Standard_True;
3911 Standard_ENABLE_DEPRECATION_WARNINGS
3914 aColorScale->SetTitle (theArgVec[anArgIter + 1]);
3921 else if (aFlag == "-demoversion"
3922 || aFlag == "-demo")
3924 aColorScale->SetPosition (0, 0);
3925 aColorScale->SetTextHeight (16);
3926 aColorScale->SetRange (0.0, 100.0);
3927 aColorScale->SetNumberOfIntervals (10);
3928 aColorScale->SetBreadth (0);
3929 aColorScale->SetHeight (0);
3930 aColorScale->SetLabelPosition (Aspect_TOCSP_RIGHT);
3931 aColorScale->SetColorType (Aspect_TOCSD_AUTO);
3932 aColorScale->SetLabelType (Aspect_TOCSD_AUTO);
3934 else if (aFlag == "-findcolor")
3936 if (anArgIter + 1 >= theArgNb)
3938 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3942 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
3944 if (!anArg1.IsRealValue())
3946 std::cout << "Error: the value should be real!\n";
3950 Quantity_Color aColor;
3951 aColorScale->FindColor (anArg1.RealValue(), aColor);
3952 theDI << Quantity_Color::StringName (aColor.Name());
3957 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
3962 Standard_Integer aWinWidth = 0, aWinHeight = 0;
3963 aView->Window()->Size (aWinWidth, aWinHeight);
3964 if (aColorScale->GetBreadth() == 0)
3966 aColorScale->SetBreadth (aWinWidth);
3968 if (aColorScale->GetHeight() == 0)
3970 aColorScale->SetHeight (aWinHeight);
3972 aColorScale->SetToUpdate();
3973 ViewerTest::Display (theArgVec[1], aColorScale, Standard_False, Standard_True);
3977 //==============================================================================
3978 //function : VGraduatedTrihedron
3979 //purpose : Displays or hides a graduated trihedron
3980 //==============================================================================
3981 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
3982 Quantity_Color& theColor)
3984 Quantity_NameOfColor aColorName;
3985 TCollection_AsciiString aVal = theValue;
3987 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
3989 return Standard_False;
3991 theColor = Quantity_Color (aColorName);
3992 return Standard_True;
3995 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
3999 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
4000 << theArgs[0] <<"' for more information.\n";
4001 return 1; //TCL_ERROR
4004 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
4005 TCollection_AsciiString aParseKey;
4006 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
4008 TCollection_AsciiString anArg (theArgs [anArgIt]);
4010 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
4013 aParseKey.Remove (1);
4014 aParseKey.LowerCase();
4015 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
4019 if (aParseKey.IsEmpty())
4024 aMapOfArgs(aParseKey)->Append (anArg);
4028 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
4029 aMapIt.More(); aMapIt.Next())
4031 const TCollection_AsciiString& aKey = aMapIt.Key();
4032 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
4034 // Bool key, without arguments
4035 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
4036 && anArgs->IsEmpty())
4042 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
4043 && anArgs->Length() == 1)
4049 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
4050 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
4051 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
4052 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
4053 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
4058 // One string argument
4059 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
4060 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
4061 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4066 // One integer argument
4067 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
4068 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
4069 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
4070 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
4071 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
4076 // One real argument
4077 if ( aKey.IsEqual ("arrowlength")
4078 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
4083 // Two string arguments
4084 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
4085 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4090 TCollection_AsciiString aLowerKey;
4093 aLowerKey.LowerCase();
4094 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
4095 std::cout << "Type help for more information.\n";
4099 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4100 if (anAISContext.IsNull())
4102 std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n";
4106 Standard_Boolean toDisplay = Standard_True;
4107 Quantity_Color aColor;
4108 Graphic3d_GraduatedTrihedron aTrihedronData;
4109 // Process parameters
4110 Handle(TColStd_HSequenceOfAsciiString) aValues;
4111 if (aMapOfArgs.Find ("off", aValues))
4113 toDisplay = Standard_False;
4117 if (aMapOfArgs.Find ("xname", aValues))
4119 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
4121 if (aMapOfArgs.Find ("yname", aValues))
4123 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
4125 if (aMapOfArgs.Find ("zname", aValues))
4127 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
4129 if (aMapOfArgs.Find ("xdrawname", aValues))
4131 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4133 if (aMapOfArgs.Find ("ydrawname", aValues))
4135 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4137 if (aMapOfArgs.Find ("zdrawname", aValues))
4139 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4141 if (aMapOfArgs.Find ("xnameoffset", aValues))
4143 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4145 if (aMapOfArgs.Find ("ynameoffset", aValues))
4147 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4149 if (aMapOfArgs.Find ("znameoffset", aValues))
4151 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4155 if (aMapOfArgs.Find ("xnamecolor", aValues))
4157 if (!GetColor (aValues->Value(1), aColor))
4159 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
4162 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
4164 if (aMapOfArgs.Find ("ynamecolor", aValues))
4166 if (!GetColor (aValues->Value(1), aColor))
4168 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
4171 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
4173 if (aMapOfArgs.Find ("znamecolor", aValues))
4175 if (!GetColor (aValues->Value(1), aColor))
4177 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
4180 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
4182 if (aMapOfArgs.Find ("xcolor", aValues))
4184 if (!GetColor (aValues->Value(1), aColor))
4186 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
4189 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
4191 if (aMapOfArgs.Find ("ycolor", aValues))
4193 if (!GetColor (aValues->Value(1), aColor))
4195 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
4198 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
4200 if (aMapOfArgs.Find ("zcolor", aValues))
4202 if (!GetColor (aValues->Value(1), aColor))
4204 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
4207 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
4211 if (aMapOfArgs.Find ("xticks", aValues))
4213 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4215 if (aMapOfArgs.Find ("yticks", aValues))
4217 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4219 if (aMapOfArgs.Find ("zticks", aValues))
4221 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4223 if (aMapOfArgs.Find ("xticklength", aValues))
4225 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4227 if (aMapOfArgs.Find ("yticklength", aValues))
4229 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4231 if (aMapOfArgs.Find ("zticklength", aValues))
4233 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4235 if (aMapOfArgs.Find ("xdrawticks", aValues))
4237 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4239 if (aMapOfArgs.Find ("ydrawticks", aValues))
4241 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4243 if (aMapOfArgs.Find ("zdrawticks", aValues))
4245 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4249 if (aMapOfArgs.Find ("xdrawvalues", aValues))
4251 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4253 if (aMapOfArgs.Find ("ydrawvalues", aValues))
4255 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4257 if (aMapOfArgs.Find ("zdrawvalues", aValues))
4259 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4261 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
4263 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4265 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
4267 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4269 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
4271 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4275 if (aMapOfArgs.Find ("arrowlength", aValues))
4277 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
4281 if (aMapOfArgs.Find ("namefont", aValues))
4283 aTrihedronData.SetNamesFont (aValues->Value(1));
4285 if (aMapOfArgs.Find ("valuesfont", aValues))
4287 aTrihedronData.SetValuesFont (aValues->Value(1));
4290 if (aMapOfArgs.Find ("drawgrid", aValues))
4292 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
4294 if (aMapOfArgs.Find ("drawaxes", aValues))
4296 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
4299 // The final step: display of erase trihedron
4302 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
4306 ViewerTest::CurrentView()->GraduatedTrihedronErase();
4309 ViewerTest::GetAISContext()->UpdateCurrentViewer();
4310 ViewerTest::CurrentView()->Redraw();
4315 //==============================================================================
4318 //==============================================================================
4319 static int VTile (Draw_Interpretor& theDI,
4320 Standard_Integer theArgNb,
4321 const char** theArgVec)
4323 Handle(V3d_View) aView = ViewerTest::CurrentView();
4326 std::cerr << "Error: no active viewer.\n";
4330 Graphic3d_CameraTile aTile = aView->Camera()->Tile();
4333 theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
4334 << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n"
4335 << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n";
4339 aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
4340 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4342 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4344 if (anArg == "-lowerleft"
4345 || anArg == "-upperleft")
4347 if (anArgIter + 3 < theArgNb)
4349 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4352 aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
4353 aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4354 aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4356 else if (anArg == "-total"
4357 || anArg == "-totalsize"
4358 || anArg == "-viewsize")
4360 if (anArgIter + 3 < theArgNb)
4362 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4365 aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4366 aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4367 if (aTile.TotalSize.x() < 1
4368 || aTile.TotalSize.y() < 1)
4370 std::cerr << "Error: total size is incorrect.\n";
4374 else if (anArg == "-tilesize")
4376 if (anArgIter + 3 < theArgNb)
4378 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4382 aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4383 aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4384 if (aTile.TileSize.x() < 1
4385 || aTile.TileSize.y() < 1)
4387 std::cerr << "Error: tile size is incorrect.\n";
4391 else if (anArg == "-unset")
4393 aView->Camera()->SetTile (Graphic3d_CameraTile());
4399 if (aTile.TileSize.x() < 1
4400 || aTile.TileSize.y() < 1)
4402 std::cerr << "Error: tile size is undefined.\n";
4405 else if (aTile.TotalSize.x() < 1
4406 || aTile.TotalSize.y() < 1)
4408 std::cerr << "Error: total size is undefined.\n";
4412 aView->Camera()->SetTile (aTile);
4417 //! Format ZLayer ID.
4418 inline const char* formZLayerId (const Standard_Integer theLayerId)
4422 case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]";
4423 case Graphic3d_ZLayerId_Default: return "[DEFAULT]";
4424 case Graphic3d_ZLayerId_Top: return "[TOP]";
4425 case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]";
4426 case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]";
4427 case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]";
4432 //! Print the ZLayer information.
4433 inline void printZLayerInfo (Draw_Interpretor& theDI,
4434 const Graphic3d_ZLayerSettings& theLayer)
4436 if (!theLayer.Name().IsEmpty())
4438 theDI << " Name: " << theLayer.Name() << "\n";
4440 if (theLayer.IsImmediate())
4442 theDI << " Immediate: TRUE\n";
4444 theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n";
4445 theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n";
4446 theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n";
4447 theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n";
4448 if (theLayer.PolygonOffset().Mode != Aspect_POM_None)
4450 theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n";
4454 //==============================================================================
4455 //function : VZLayer
4456 //purpose : Test z layer operations for v3d viewer
4457 //==============================================================================
4458 static int VZLayer (Draw_Interpretor& theDI,
4459 Standard_Integer theArgNb,
4460 const char** theArgVec)
4462 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4463 if (aContextAIS.IsNull())
4465 std::cout << "No active viewer!\n";
4469 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
4472 TColStd_SequenceOfInteger aLayers;
4473 aViewer->GetAllZLayers (aLayers);
4474 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4476 theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n";
4477 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4478 printZLayerInfo (theDI, aSettings);
4483 Standard_Integer anArgIter = 1;
4484 Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4485 ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView());
4486 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
4491 TCollection_AsciiString aFirstArg (theArgVec[anArgIter]);
4492 if (aFirstArg.IsIntegerValue())
4495 aLayerId = aFirstArg.IntegerValue();
4499 aFirstArg.LowerCase();
4500 if (aFirstArg == "default"
4501 || aFirstArg == "def")
4503 aLayerId = Graphic3d_ZLayerId_Default;
4506 else if (aFirstArg == "top")
4508 aLayerId = Graphic3d_ZLayerId_Top;
4511 else if (aFirstArg == "topmost")
4513 aLayerId = Graphic3d_ZLayerId_Topmost;
4516 else if (aFirstArg == "overlay"
4517 || aFirstArg == "toposd")
4519 aLayerId = Graphic3d_ZLayerId_TopOSD;
4522 else if (aFirstArg == "underlay"
4523 || aFirstArg == "botosd")
4525 aLayerId = Graphic3d_ZLayerId_BotOSD;
4530 TColStd_SequenceOfInteger aLayers;
4531 aViewer->GetAllZLayers (aLayers);
4532 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4534 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4535 if (TCollection_AsciiString::IsSameString (aSettings.Name(), aFirstArg, Standard_False))
4537 aLayerId = aLayeriter.Value();
4545 for (; anArgIter < theArgNb; ++anArgIter)
4547 // perform operation
4548 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4550 if (anUpdateTool.parseRedrawMode (anArg))
4554 else if (anArg == "-add"
4557 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4558 if (!aViewer->AddZLayer (aLayerId))
4560 std::cout << "Error: can not add a new z layer!\n";
4566 else if (anArg == "-del"
4567 || anArg == "-delete"
4570 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4572 if (++anArgIter >= theArgNb)
4574 std::cout << "Syntax error: id of z layer to remove is missing\n";
4578 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4581 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN
4582 || aLayerId == Graphic3d_ZLayerId_Default
4583 || aLayerId == Graphic3d_ZLayerId_Top
4584 || aLayerId == Graphic3d_ZLayerId_Topmost
4585 || aLayerId == Graphic3d_ZLayerId_TopOSD
4586 || aLayerId == Graphic3d_ZLayerId_BotOSD)
4588 std::cout << "Syntax error: standard Z layer can not be removed\n";
4592 // move all object displayed in removing layer to default layer
4593 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4594 anObjIter.More(); anObjIter.Next())
4596 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1());
4598 || aPrs->ZLayer() != aLayerId)
4602 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4605 if (!aViewer->RemoveZLayer (aLayerId))
4607 std::cout << "Z layer can not be removed!\n";
4611 theDI << aLayerId << " ";
4614 else if (anArg == "-get"
4617 TColStd_SequenceOfInteger aLayers;
4618 aViewer->GetAllZLayers (aLayers);
4619 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4621 theDI << aLayeriter.Value() << " ";
4626 else if (anArg == "-name")
4628 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4630 std::cout << "Syntax error: id of Z layer is missing\n";
4634 if (++anArgIter >= theArgNb)
4636 std::cout << "Syntax error: name is missing\n";
4640 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4641 aSettings.SetName (theArgVec[anArgIter]);
4642 aViewer->SetZLayerSettings (aLayerId, aSettings);
4644 else if (anArg == "-origin")
4646 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4648 std::cout << "Syntax error: id of Z layer is missing\n";
4652 if (anArgIter + 2 >= theArgNb)
4654 std::cout << "Syntax error: origin coordinates are missing\n";
4658 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4660 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1]));
4661 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2]));
4662 anOrigin.SetZ (0.0);
4663 if (anArgIter + 3 < theArgNb)
4665 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3]));
4672 aSettings.SetOrigin (anOrigin);
4673 aViewer->SetZLayerSettings (aLayerId, aSettings);
4675 else if (anArg == "-settings"
4676 || anArg == "settings")
4678 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4680 if (++anArgIter >= theArgNb)
4682 std::cout << "Syntax error: id of Z layer is missing\n";
4686 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4689 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4690 printZLayerInfo (theDI, aSettings);
4692 else if (anArg == "-enable"
4693 || anArg == "enable"
4694 || anArg == "-disable"
4695 || anArg == "disable")
4697 const Standard_Boolean toEnable = anArg == "-enable"
4698 || anArg == "enable";
4699 if (++anArgIter >= theArgNb)
4701 std::cout << "Syntax error: option name is missing\n";
4705 TCollection_AsciiString aSubOp (theArgVec[anArgIter]);
4707 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4709 if (++anArgIter >= theArgNb)
4711 std::cout << "Syntax error: id of Z layer is missing\n";
4715 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4718 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4719 if (aSubOp == "depthtest"
4720 || aSubOp == "test")
4722 aSettings.SetEnableDepthTest (toEnable);
4724 else if (aSubOp == "depthwrite"
4725 || aSubOp == "write")
4727 aSettings.SetEnableDepthWrite (toEnable);
4729 else if (aSubOp == "depthclear"
4730 || aSubOp == "clear")
4732 aSettings.SetClearDepth (toEnable);
4734 else if (aSubOp == "depthoffset"
4735 || aSubOp == "offset")
4737 Graphic3d_PolygonOffset aParams;
4738 aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None;
4741 if (anArgIter + 2 >= theArgNb)
4743 std::cout << "Syntax error: factor and units values for depth offset are missing\n";
4747 aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
4748 aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
4750 aSettings.SetPolygonOffset (aParams);
4752 else if (aSubOp == "positiveoffset"
4753 || aSubOp == "poffset")
4757 aSettings.SetDepthOffsetPositive();
4761 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
4764 else if (aSubOp == "negativeoffset"
4765 || aSubOp == "noffset")
4769 aSettings.SetDepthOffsetNegative();
4773 aSettings.SetPolygonOffset(Graphic3d_PolygonOffset());
4776 else if (aSubOp == "textureenv")
4778 aSettings.SetEnvironmentTexture (toEnable);
4781 aViewer->SetZLayerSettings (aLayerId, aSettings);
4785 std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n";
4793 // The interactive presentation of 2d layer item
4794 // for "vlayerline" command it provides a presentation of
4795 // line with user-defined linewidth, linetype and transparency.
4796 class V3d_LineItem : public AIS_InteractiveObject
4800 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
4803 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4804 Standard_Real X2, Standard_Real Y2,
4805 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
4806 Standard_Real theWidth = 0.5,
4807 Standard_Real theTransp = 1.0);
4811 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4812 const Handle(Prs3d_Presentation)& thePresentation,
4813 const Standard_Integer theMode) Standard_OVERRIDE;
4815 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
4816 const Standard_Integer /*aMode*/) Standard_OVERRIDE
4821 Standard_Real myX1, myY1, myX2, myY2;
4822 Aspect_TypeOfLine myType;
4823 Standard_Real myWidth;
4826 // default constructor for line item
4827 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4828 Standard_Real X2, Standard_Real Y2,
4829 Aspect_TypeOfLine theType,
4830 Standard_Real theWidth,
4831 Standard_Real theTransp) :
4832 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
4833 myType(theType), myWidth(theWidth)
4835 SetTransparency (1-theTransp);
4839 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
4840 const Handle(Prs3d_Presentation)& thePresentation,
4841 const Standard_Integer /*theMode*/)
4843 thePresentation->Clear();
4844 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
4845 Standard_Integer aWidth, aHeight;
4846 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
4847 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
4848 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
4849 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
4850 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
4851 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
4852 aGroup->SetPrimitivesAspect (anAspect->Aspect());
4853 aGroup->AddPrimitiveArray (aPrim);
4856 //=============================================================================
4857 //function : VLayerLine
4858 //purpose : Draws line in the v3d view layer with given attributes: linetype,
4859 // : linewidth, transparency coefficient
4860 //============================================================================
4861 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4863 // get the active view
4864 Handle(V3d_View) aView = ViewerTest::CurrentView();
4867 di << "Call vinit before!\n";
4872 di << "Use: " << argv[0];
4873 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
4874 di << " linetype : { 0 | 1 | 2 | 3 } \n";
4875 di << " 0 - solid \n";
4876 di << " 1 - dashed \n";
4877 di << " 2 - dot \n";
4878 di << " 3 - dashdot\n";
4879 di << " transparency : { 0.0 - 1.0 } \n";
4880 di << " 0.0 - transparent\n";
4881 di << " 1.0 - visible \n";
4885 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4886 // get the input params
4887 Standard_Real X1 = Draw::Atof(argv[1]);
4888 Standard_Real Y1 = Draw::Atof(argv[2]);
4889 Standard_Real X2 = Draw::Atof(argv[3]);
4890 Standard_Real Y2 = Draw::Atof(argv[4]);
4892 Standard_Real aWidth = 0.5;
4893 Standard_Real aTransparency = 1.0;
4897 aWidth = Draw::Atof(argv[5]);
4899 // select appropriate line type
4900 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
4902 && !ViewerTest::ParseLineType (argv[6], aLineType))
4904 std::cout << "Syntax error: unknown line type '" << argv[6] << "'\n";
4911 aTransparency = Draw::Atof(argv[7]);
4912 if (aTransparency < 0 || aTransparency > 1.0)
4913 aTransparency = 1.0;
4916 static Handle (V3d_LineItem) aLine;
4917 if (!aLine.IsNull())
4919 aContext->Erase (aLine);
4921 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
4925 aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
4926 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
4927 aLine->SetToUpdate();
4928 aContext->Display (aLine, Standard_True);
4934 //==============================================================================
4937 //==============================================================================
4939 static int VGrid (Draw_Interpretor& /*theDI*/,
4940 Standard_Integer theArgNb,
4941 const char** theArgVec)
4943 // get the active view
4944 Handle(V3d_View) aView = ViewerTest::CurrentView();
4945 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4946 if (aView.IsNull() || aViewer.IsNull())
4948 std::cerr << "No active view. Please call vinit.\n";
4952 Aspect_GridType aType = aViewer->GridType();
4953 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
4955 Standard_Integer anIter = 1;
4956 for (; anIter < theArgNb; ++anIter)
4958 const char* aValue = theArgVec[anIter];
4961 aType = Aspect_GT_Rectangular;
4963 else if (*aValue == 'c')
4965 aType = Aspect_GT_Circular;
4967 else if (*aValue == 'l')
4969 aMode = Aspect_GDM_Lines;
4971 else if (*aValue == 'p')
4973 aMode = Aspect_GDM_Points;
4975 else if (strcmp (aValue, "off" ) == 0)
4977 aViewer->DeactivateGrid();
4986 Standard_Integer aTail = (theArgNb - anIter);
4989 aViewer->ActivateGrid (aType, aMode);
4992 else if (aTail != 2 && aTail != 5)
4994 std::cerr << "Incorrect arguments number! Usage:\n"
4995 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
4999 Quantity_Length anOriginX, anOriginY;
5000 Quantity_PlaneAngle aRotAngle;
5001 if (aType == Aspect_GT_Rectangular)
5003 Quantity_Length aRStepX, aRStepY;
5004 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
5006 anOriginX = Draw::Atof (theArgVec[anIter++]);
5007 anOriginY = Draw::Atof (theArgVec[anIter++]);
5010 aRStepX = Draw::Atof (theArgVec[anIter++]);
5011 aRStepY = Draw::Atof (theArgVec[anIter++]);
5012 aRotAngle = Draw::Atof (theArgVec[anIter++]);
5014 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
5015 aViewer->ActivateGrid (aType, aMode);
5017 else if (aType == Aspect_GT_Circular)
5019 Quantity_Length aRadiusStep;
5020 Standard_Integer aDivisionNumber;
5021 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
5023 anOriginX = Draw::Atof (theArgVec[anIter++]);
5024 anOriginY = Draw::Atof (theArgVec[anIter++]);
5027 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
5028 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
5029 aRotAngle = Draw::Atof (theArgVec[anIter++]);
5032 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
5033 aViewer->ActivateGrid (aType, aMode);
5039 //==============================================================================
5040 //function : VPriviledgedPlane
5042 //==============================================================================
5044 static int VPriviledgedPlane (Draw_Interpretor& theDI,
5045 Standard_Integer theArgNb,
5046 const char** theArgVec)
5048 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
5050 std::cerr << "Error: wrong number of arguments! See usage:\n";
5051 theDI.PrintHelp (theArgVec[0]);
5055 // get the active viewer
5056 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5057 if (aViewer.IsNull())
5059 std::cerr << "Error: no active viewer. Please call vinit.\n";
5065 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
5066 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
5067 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
5068 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
5069 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
5070 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
5071 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
5075 Standard_Integer anArgIdx = 1;
5076 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
5077 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
5078 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
5079 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
5080 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
5081 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
5083 gp_Ax3 aPriviledgedPlane;
5084 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
5085 gp_Dir aNorm (aNormX, aNormY, aNormZ);
5088 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
5089 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
5090 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
5091 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
5092 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
5096 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
5099 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
5104 //==============================================================================
5105 //function : VConvert
5107 //==============================================================================
5109 static int VConvert (Draw_Interpretor& theDI,
5110 Standard_Integer theArgNb,
5111 const char** theArgVec)
5113 // get the active view
5114 Handle(V3d_View) aView = ViewerTest::CurrentView();
5117 std::cerr << "Error: no active view. Please call vinit.\n";
5121 enum { Model, Ray, View, Window, Grid } aMode = Model;
5123 // access coordinate arguments
5124 TColStd_SequenceOfReal aCoord;
5125 Standard_Integer anArgIdx = 1;
5126 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
5128 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5129 if (!anArg.IsRealValue())
5133 aCoord.Append (anArg.RealValue());
5136 // non-numeric argument too early
5137 if (aCoord.IsEmpty())
5139 std::cerr << "Error: wrong number of arguments! See usage:\n";
5140 theDI.PrintHelp (theArgVec[0]);
5144 // collect all other arguments and options
5145 for (; anArgIdx < theArgNb; ++anArgIdx)
5147 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5149 if (anArg == "window") aMode = Window;
5150 else if (anArg == "view") aMode = View;
5151 else if (anArg == "grid") aMode = Grid;
5152 else if (anArg == "ray") aMode = Ray;
5155 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
5156 theDI.PrintHelp (theArgVec[0]);
5161 // complete input checks
5162 if ((aCoord.Length() == 1 && theArgNb > 3) ||
5163 (aCoord.Length() == 2 && theArgNb > 4) ||
5164 (aCoord.Length() == 3 && theArgNb > 5))
5166 std::cerr << "Error: wrong number of arguments! See usage:\n";
5167 theDI.PrintHelp (theArgVec[0]);
5171 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
5172 Standard_Integer aXYp[2] = {0, 0};
5174 // convert one-dimensional coordinate
5175 if (aCoord.Length() == 1)
5179 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer) aCoord (1)); return 0;
5180 case Window : theDI << "Window Vp: " << aView->Convert ((Quantity_Length) aCoord (1)); return 0;
5182 std::cerr << "Error: wrong arguments! See usage:\n";
5183 theDI.PrintHelp (theArgVec[0]);
5188 // convert 2D coordinates from projection or view reference space
5189 if (aCoord.Length() == 2)
5194 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5195 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5199 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5200 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5204 aView->Convert ((V3d_Coordinate) aCoord (1), (V3d_Coordinate) aCoord (2), aXYp[0], aXYp[1]);
5205 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5209 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5210 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5211 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5215 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5216 (Standard_Integer) aCoord (2),
5217 aXYZ[0], aXYZ[1], aXYZ[2],
5218 aXYZ[3], aXYZ[4], aXYZ[5]);
5219 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5223 std::cerr << "Error: wrong arguments! See usage:\n";
5224 theDI.PrintHelp (theArgVec[0]);
5229 // convert 3D coordinates from view reference space
5230 else if (aCoord.Length() == 3)
5235 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5236 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5240 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5241 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5245 std::cerr << "Error: wrong arguments! See usage:\n";
5246 theDI.PrintHelp (theArgVec[0]);
5254 //==============================================================================
5257 //==============================================================================
5259 static int VFps (Draw_Interpretor& theDI,
5260 Standard_Integer theArgNb,
5261 const char** theArgVec)
5263 // get the active view
5264 Handle(V3d_View) aView = ViewerTest::CurrentView();
5267 std::cerr << "No active view. Please call vinit.\n";
5271 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
5274 std::cerr << "Incorrect arguments!\n";
5278 // the time is meaningless for first call
5279 // due to async OpenGl rendering
5282 // redraw view in loop to estimate average values
5285 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
5291 const Standard_Real aTime = aTimer.ElapsedTime();
5292 aTimer.OSD_Chronometer::Show (aCpu);
5294 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
5295 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
5297 // return statistics
5298 theDI << "FPS: " << aFpsAver << "\n"
5299 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5301 // compute additional statistics in ray-tracing mode
5302 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
5304 if (aParams.Method == Graphic3d_RM_RAYTRACING)
5306 Standard_Integer aSizeX;
5307 Standard_Integer aSizeY;
5309 aView->Window()->Size (aSizeX, aSizeY);
5311 // 1 shadow ray and 1 secondary ray pew each bounce
5312 const Standard_Real aMRays = aSizeX * aSizeY * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
5314 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
5320 //==============================================================================
5321 //function : VGlDebug
5323 //==============================================================================
5325 static int VGlDebug (Draw_Interpretor& theDI,
5326 Standard_Integer theArgNb,
5327 const char** theArgVec)
5329 Handle(OpenGl_GraphicDriver) aDriver;
5330 Handle(V3d_View) aView = ViewerTest::CurrentView();
5331 if (!aView.IsNull())
5333 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5335 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
5336 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
5340 TCollection_AsciiString aDebActive, aSyncActive;
5347 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
5348 "GL_ARB_debug_output");
5349 aDebActive = isActive ? " (active)" : " (inactive)";
5352 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
5353 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
5357 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
5358 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
5359 << "glslWarn:" << (aCaps->glslWarnings ? "1" : "0") << "\n"
5360 << "extraMsg:" << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
5364 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5366 Standard_CString anArg = theArgVec[anArgIter];
5367 TCollection_AsciiString anArgCase (anArg);
5368 anArgCase.LowerCase();
5369 Standard_Boolean toEnableDebug = Standard_True;
5370 if (anArgCase == "-glsl"
5371 || anArgCase == "-glslwarn"
5372 || anArgCase == "-glslwarns"
5373 || anArgCase == "-glslwarnings")
5375 Standard_Boolean toShowWarns = Standard_True;
5376 if (++anArgIter < theArgNb
5377 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
5381 aDefCaps->glslWarnings = toShowWarns;
5384 aCaps->glslWarnings = toShowWarns;
5387 else if (anArgCase == "-extra"
5388 || anArgCase == "-extramsg"
5389 || anArgCase == "-extramessages")
5391 Standard_Boolean toShow = Standard_True;
5392 if (++anArgIter < theArgNb
5393 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
5397 aDefCaps->suppressExtraMsg = !toShow;
5400 aCaps->suppressExtraMsg = !toShow;
5403 else if (anArgCase == "-noextra"
5404 || anArgCase == "-noextramsg"
5405 || anArgCase == "-noextramessages")
5407 Standard_Boolean toSuppress = Standard_True;
5408 if (++anArgIter < theArgNb
5409 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
5413 aDefCaps->suppressExtraMsg = toSuppress;
5416 aCaps->suppressExtraMsg = toSuppress;
5419 else if (anArgCase == "-sync")
5421 Standard_Boolean toSync = Standard_True;
5422 if (++anArgIter < theArgNb
5423 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
5427 aDefCaps->contextSyncDebug = toSync;
5430 aDefCaps->contextDebug = Standard_True;
5433 else if (anArgCase == "-debug")
5435 if (++anArgIter < theArgNb
5436 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
5440 aDefCaps->contextDebug = toEnableDebug;
5442 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
5443 && (anArgIter + 1 == theArgNb))
5445 // simple alias to turn on almost everything
5446 aDefCaps->contextDebug = toEnableDebug;
5447 aDefCaps->contextSyncDebug = toEnableDebug;
5448 aDefCaps->glslWarnings = toEnableDebug;
5452 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
5460 //==============================================================================
5463 //==============================================================================
5465 static int VVbo (Draw_Interpretor& theDI,
5466 Standard_Integer theArgNb,
5467 const char** theArgVec)
5469 const Standard_Boolean toSet = (theArgNb > 1);
5470 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
5473 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
5477 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5478 if (aContextAIS.IsNull())
5482 std::cerr << "No active view!\n";
5486 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5487 if (!aDriver.IsNull())
5491 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
5495 aDriver->ChangeOptions().vboDisable = toUseVbo;
5502 //==============================================================================
5505 //==============================================================================
5507 static int VCaps (Draw_Interpretor& theDI,
5508 Standard_Integer theArgNb,
5509 const char** theArgVec)
5511 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
5512 Handle(OpenGl_GraphicDriver) aDriver;
5513 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5514 if (!aContext.IsNull())
5516 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
5517 aCaps = &aDriver->ChangeOptions();
5522 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
5523 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
5524 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
5525 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
5526 theDI << "VSync: " << aCaps->swapInterval << "\n";
5527 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
5528 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
5532 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5533 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5535 Standard_CString anArg = theArgVec[anArgIter];
5536 TCollection_AsciiString anArgCase (anArg);
5537 anArgCase.LowerCase();
5538 if (anUpdateTool.parseRedrawMode (anArg))
5542 else if (anArgCase == "-vsync"
5543 || anArgCase == "-swapinterval")
5545 Standard_Boolean toEnable = Standard_True;
5546 if (++anArgIter < theArgNb
5547 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5551 aCaps->swapInterval = toEnable;
5553 else if (anArgCase == "-ffp")
5555 Standard_Boolean toEnable = Standard_True;
5556 if (++anArgIter < theArgNb
5557 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5561 aCaps->ffpEnable = toEnable;
5563 else if (anArgCase == "-vbo")
5565 Standard_Boolean toEnable = Standard_True;
5566 if (++anArgIter < theArgNb
5567 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5571 aCaps->vboDisable = !toEnable;
5573 else if (anArgCase == "-sprite"
5574 || anArgCase == "-sprites")
5576 Standard_Boolean toEnable = Standard_True;
5577 if (++anArgIter < theArgNb
5578 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5582 aCaps->pntSpritesDisable = !toEnable;
5584 else if (anArgCase == "-softmode")
5586 Standard_Boolean toEnable = Standard_True;
5587 if (++anArgIter < theArgNb
5588 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5592 aCaps->contextNoAccel = toEnable;
5594 else if (anArgCase == "-accel"
5595 || anArgCase == "-acceleration")
5597 Standard_Boolean toEnable = Standard_True;
5598 if (++anArgIter < theArgNb
5599 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5603 aCaps->contextNoAccel = !toEnable;
5605 else if (anArgCase == "-compat"
5606 || anArgCase == "-compatprofile"
5607 || anArgCase == "-compatible"
5608 || anArgCase == "-compatibleprofile")
5610 Standard_Boolean toEnable = Standard_True;
5611 if (++anArgIter < theArgNb
5612 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5616 aCaps->contextCompatible = toEnable;
5617 if (!aCaps->contextCompatible)
5619 aCaps->ffpEnable = Standard_False;
5622 else if (anArgCase == "-core"
5623 || anArgCase == "-coreprofile")
5625 Standard_Boolean toEnable = Standard_True;
5626 if (++anArgIter < theArgNb
5627 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5631 aCaps->contextCompatible = !toEnable;
5632 if (!aCaps->contextCompatible)
5634 aCaps->ffpEnable = Standard_False;
5637 else if (anArgCase == "-stereo"
5638 || anArgCase == "-quadbuffer")
5640 Standard_Boolean toEnable = Standard_True;
5641 if (++anArgIter < theArgNb
5642 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5646 aCaps->contextStereo = toEnable;
5650 std::cout << "Error: unknown argument '" << anArg << "'\n";
5654 if (aCaps != &ViewerTest_myDefaultCaps)
5656 ViewerTest_myDefaultCaps = *aCaps;
5661 //==============================================================================
5662 //function : VMemGpu
5664 //==============================================================================
5666 static int VMemGpu (Draw_Interpretor& theDI,
5667 Standard_Integer theArgNb,
5668 const char** theArgVec)
5671 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5672 if (aContextAIS.IsNull())
5674 std::cerr << "No active view. Please call vinit.\n";
5678 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
5679 if (aDriver.IsNull())
5681 std::cerr << "Graphic driver not available.\n";
5685 Standard_Size aFreeBytes = 0;
5686 TCollection_AsciiString anInfo;
5687 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
5689 std::cerr << "Information not available.\n";
5693 if (theArgNb > 1 && *theArgVec[1] == 'f')
5695 theDI << Standard_Real (aFreeBytes);
5705 // ==============================================================================
5706 // function : VReadPixel
5708 // ==============================================================================
5709 static int VReadPixel (Draw_Interpretor& theDI,
5710 Standard_Integer theArgNb,
5711 const char** theArgVec)
5713 // get the active view
5714 Handle(V3d_View) aView = ViewerTest::CurrentView();
5717 std::cerr << "No active view. Please call vinit.\n";
5720 else if (theArgNb < 3)
5722 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
5726 Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgRGBA;
5727 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
5729 Standard_Integer aWidth, aHeight;
5730 aView->Window()->Size (aWidth, aHeight);
5731 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
5732 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
5733 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
5735 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
5739 Standard_Boolean toShowName = Standard_False;
5740 Standard_Boolean toShowHls = Standard_False;
5741 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
5743 const char* aParam = theArgVec[anIter];
5744 if ( strcasecmp( aParam, "rgb" ) == 0 )
5746 aFormat = Image_PixMap::ImgRGB;
5747 aBufferType = Graphic3d_BT_RGB;
5749 else if ( strcasecmp( aParam, "hls" ) == 0 )
5751 aFormat = Image_PixMap::ImgRGB;
5752 aBufferType = Graphic3d_BT_RGB;
5753 toShowHls = Standard_True;
5755 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
5757 aFormat = Image_PixMap::ImgRGBF;
5758 aBufferType = Graphic3d_BT_RGB;
5760 else if ( strcasecmp( aParam, "rgba" ) == 0 )
5762 aFormat = Image_PixMap::ImgRGBA;
5763 aBufferType = Graphic3d_BT_RGBA;
5765 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
5767 aFormat = Image_PixMap::ImgRGBAF;
5768 aBufferType = Graphic3d_BT_RGBA;
5770 else if ( strcasecmp( aParam, "depth" ) == 0 )
5772 aFormat = Image_PixMap::ImgGrayF;
5773 aBufferType = Graphic3d_BT_Depth;
5775 else if ( strcasecmp( aParam, "name" ) == 0 )
5777 toShowName = Standard_True;
5781 Image_PixMap anImage;
5782 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
5784 std::cerr << "Image allocation failed\n";
5787 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
5789 std::cerr << "Image dump failed\n";
5793 Quantity_Parameter anAlpha;
5794 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
5797 if (aBufferType == Graphic3d_BT_RGBA)
5799 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha;
5803 theDI << Quantity_Color::StringName (aColor.Name());
5808 switch (aBufferType)
5811 case Graphic3d_BT_RGB:
5815 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation();
5819 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue();
5823 case Graphic3d_BT_RGBA:
5825 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha;
5828 case Graphic3d_BT_Depth:
5830 theDI << aColor.Red();
5839 //==============================================================================
5840 //function : VDiffImage
5841 //purpose : The draw-command compares two images.
5842 //==============================================================================
5844 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
5848 theDI << "Not enough arguments.\n";
5853 const char* anImgPathRef = theArgVec[1];
5854 const char* anImgPathNew = theArgVec[2];
5856 // get string tolerance and check its validity
5857 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
5858 if (aTolColor < 0.0)
5860 if (aTolColor > 1.0)
5863 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
5864 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
5866 // image file of difference
5867 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
5869 // compare the images
5870 Image_Diff aComparer;
5871 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
5876 aComparer.SetColorTolerance (aTolColor);
5877 aComparer.SetBorderFilterOn (isBorderFilterOn);
5878 Standard_Integer aDiffColorsNb = aComparer.Compare();
5879 theDI << aDiffColorsNb << "\n";
5881 // save image of difference
5882 if (aDiffColorsNb >0 && aDiffImagePath != NULL)
5884 aComparer.SaveDiffImage (aDiffImagePath);
5890 //=======================================================================
5891 //function : VSelect
5892 //purpose : Emulates different types of selection by mouse:
5893 // 1) single click selection
5894 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
5895 // 3) selection with polygon having corners at
5896 // pixel positions (x1,y1),...,(xn,yn)
5897 // 4) any of these selections with shift button pressed
5898 //=======================================================================
5899 static Standard_Integer VSelect (Draw_Interpretor& di,
5900 Standard_Integer argc,
5905 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]\n";
5909 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
5910 if(myAIScontext.IsNull())
5912 di << "use 'vinit' command before " << argv[0] << "\n";
5916 const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1));
5917 Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1;
5918 TCollection_AsciiString anArg;
5919 anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2];
5921 if (anArg == "-allowoverlap")
5923 Standard_Boolean isValidated = isShiftSelection ? argc == 8
5927 di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection";
5931 Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
5932 myAIScontext->MainSelector()->AllowOverlapDetection (isToAllow != 0);
5936 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
5937 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
5940 if(isShiftSelection)
5941 aCurrentEventManager->ShiftSelect();
5943 aCurrentEventManager->Select();
5945 else if(aCoordsNb == 4)
5947 if(isShiftSelection)
5948 aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
5950 aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
5954 TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2);
5956 for(Standard_Integer i=1;i<=aCoordsNb / 2;++i)
5957 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
5959 if(isShiftSelection)
5960 aCurrentEventManager->ShiftSelect(aPolyline);
5962 aCurrentEventManager->Select(aPolyline);
5967 //=======================================================================
5968 //function : VMoveTo
5969 //purpose : Emulates cursor movement to defined pixel position
5970 //=======================================================================
5971 static Standard_Integer VMoveTo (Draw_Interpretor& di,
5972 Standard_Integer argc,
5977 di << "Usage : " << argv[0] << " x y\n";
5981 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5982 if(aContext.IsNull())
5984 di << "use 'vinit' command before " << argv[0] << "\n";
5987 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
5993 //! Global map storing all animations registered in ViewerTest.
5994 static NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)> ViewerTest_AnimationTimelineMap;
5996 //! The animation calling the Draw Harness command.
5997 class ViewerTest_AnimationProc : public AIS_Animation
6001 //! Main constructor.
6002 ViewerTest_AnimationProc (const TCollection_AsciiString& theAnimationName,
6003 Draw_Interpretor* theDI,
6004 const TCollection_AsciiString& theCommand)
6005 : AIS_Animation (theAnimationName),
6007 myCommand (theCommand)
6014 //! Evaluate the command.
6015 virtual void update (const AIS_AnimationProgress& theProgress) Standard_OVERRIDE
6017 TCollection_AsciiString aCmd = myCommand;
6018 replace (aCmd, "%pts", TCollection_AsciiString(theProgress.Pts));
6019 replace (aCmd, "%localpts", TCollection_AsciiString(theProgress.LocalPts));
6020 replace (aCmd, "%ptslocal", TCollection_AsciiString(theProgress.LocalPts));
6021 replace (aCmd, "%normalized", TCollection_AsciiString(theProgress.LocalNormalized));
6022 replace (aCmd, "%localnormalized", TCollection_AsciiString(theProgress.LocalNormalized));
6023 myDrawInter->Eval (aCmd.ToCString());
6026 //! Find the keyword in the command and replace it with value.
6027 //! @return the position of the keyword to pass value
6028 void replace (TCollection_AsciiString& theCmd,
6029 const TCollection_AsciiString& theKey,
6030 const TCollection_AsciiString& theVal)
6032 TCollection_AsciiString aCmd (theCmd);
6034 const Standard_Integer aPos = aCmd.Search (theKey);
6040 TCollection_AsciiString aPart1, aPart2;
6041 Standard_Integer aPart1To = aPos - 1;
6043 && aPart1To <= theCmd.Length())
6045 aPart1 = theCmd.SubString (1, aPart1To);
6048 Standard_Integer aPart2From = aPos + theKey.Length();
6050 && aPart2From <= theCmd.Length())
6052 aPart2 = theCmd.SubString (aPart2From, theCmd.Length());
6055 theCmd = aPart1 + theVal + aPart2;
6060 Draw_Interpretor* myDrawInter;
6061 TCollection_AsciiString myCommand;
6065 //! Replace the animation with the new one.
6066 static void replaceAnimation (const Handle(AIS_Animation)& theParentAnimation,
6067 Handle(AIS_Animation)& theAnimation,
6068 const Handle(AIS_Animation)& theAnimationNew)
6070 theAnimationNew->CopyFrom (theAnimation);
6071 if (!theParentAnimation.IsNull())
6073 theParentAnimation->Replace (theAnimation, theAnimationNew);
6077 ViewerTest_AnimationTimelineMap.UnBind (theAnimationNew->Name());
6078 ViewerTest_AnimationTimelineMap.Bind (theAnimationNew->Name(), theAnimationNew);
6080 theAnimation = theAnimationNew;
6083 //! Parse the point.
6084 static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
6086 const TCollection_AsciiString anXYZ[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
6087 if (!anXYZ[0].IsRealValue()
6088 || !anXYZ[1].IsRealValue()
6089 || !anXYZ[2].IsRealValue())
6091 return Standard_False;
6094 thePnt.SetCoord (anXYZ[0].RealValue(), anXYZ[1].RealValue(), anXYZ[2].RealValue());
6095 return Standard_True;
6098 //! Parse the quaternion.
6099 static Standard_Boolean parseQuaternion (const char** theArgVec, gp_Quaternion& theQRot)
6101 const TCollection_AsciiString anXYZW[4] = {theArgVec[0], theArgVec[1], theArgVec[2], theArgVec[3]};
6102 if (!anXYZW[0].IsRealValue()
6103 || !anXYZW[1].IsRealValue()
6104 || !anXYZW[2].IsRealValue()
6105 || !anXYZW[3].IsRealValue())
6107 return Standard_False;
6110 theQRot.Set (anXYZW[0].RealValue(), anXYZW[1].RealValue(), anXYZW[2].RealValue(), anXYZW[3].RealValue());
6111 return Standard_True;
6116 //=================================================================================================
6117 //function : VViewParams
6118 //purpose : Gets or sets AIS View characteristics
6119 //=================================================================================================
6120 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6122 Handle(V3d_View) aView = ViewerTest::CurrentView();
6125 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
6129 Standard_Boolean toSetProj = Standard_False;
6130 Standard_Boolean toSetUp = Standard_False;
6131 Standard_Boolean toSetAt = Standard_False;
6132 Standard_Boolean toSetEye = Standard_False;
6133 Standard_Boolean toSetScale = Standard_False;
6134 Standard_Boolean toSetSize = Standard_False;
6135 Standard_Boolean toSetCenter2d = Standard_False;
6136 Quantity_Factor aViewScale = aView->Scale();
6137 Quantity_Length aViewSize = 1.0;
6138 Graphic3d_Vec2i aCenter2d;
6139 gp_XYZ aViewProj, aViewUp, aViewAt, aViewEye;
6140 aView->Proj (aViewProj.ChangeCoord (1), aViewProj.ChangeCoord (2), aViewProj.ChangeCoord (3));
6141 aView->Up (aViewUp .ChangeCoord (1), aViewUp .ChangeCoord (2), aViewUp .ChangeCoord (3));
6142 aView->At (aViewAt .ChangeCoord (1), aViewAt .ChangeCoord (2), aViewAt .ChangeCoord (3));
6143 aView->Eye (aViewEye .ChangeCoord (1), aViewEye .ChangeCoord (2), aViewEye .ChangeCoord (3));
6146 // print all of the available view parameters
6150 "Proj: %12g %12g %12g\n"
6151 "Up: %12g %12g %12g\n"
6152 "At: %12g %12g %12g\n"
6153 "Eye: %12g %12g %12g\n",
6155 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
6156 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
6157 aViewAt.X(), aViewAt.Y(), aViewAt.Z(),
6158 aViewEye.X(), aViewEye.Y(), aViewEye.Z());
6163 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
6164 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
6166 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6168 if (anUpdateTool.parseRedrawMode (anArg))
6172 else if (anArg == "-cmd"
6173 || anArg == "-command"
6174 || anArg == "-args")
6183 aViewProj.X(), aViewProj.Y(), aViewProj.Z(),
6184 aViewUp.X(), aViewUp.Y(), aViewUp.Z(),
6185 aViewAt.X(), aViewAt.Y(), aViewAt.Z());
6188 else if (anArg == "-scale"
6189 || anArg == "-size")
6191 if (anArgIter + 1 < theArgsNb
6192 && *theArgVec[anArgIter + 1] != '-')
6194 const TCollection_AsciiString aValueArg (theArgVec[anArgIter + 1]);
6195 if (aValueArg.IsRealValue())
6198 if (anArg == "-scale")
6200 toSetScale = Standard_True;
6201 aViewScale = aValueArg.RealValue();
6203 else if (anArg == "-size")
6205 toSetSize = Standard_True;
6206 aViewSize = aValueArg.RealValue();
6211 if (anArg == "-scale")
6213 theDi << "Scale: " << aView->Scale() << "\n";
6215 else if (anArg == "-size")
6217 Graphic3d_Vec2d aSizeXY;
6218 aView->Size (aSizeXY.x(), aSizeXY.y());
6219 theDi << "Size: " << aSizeXY.x() << " " << aSizeXY.y() << "\n";
6222 else if (anArg == "-eye"
6225 || anArg == "-proj")
6227 if (anArgIter + 3 < theArgsNb)
6230 if (parseXYZ (theArgVec + anArgIter + 1, anXYZ))
6233 if (anArg == "-eye")
6235 toSetEye = Standard_True;
6238 else if (anArg == "-at")
6240 toSetAt = Standard_True;
6243 else if (anArg == "-up")
6245 toSetUp = Standard_True;
6248 else if (anArg == "-proj")
6250 toSetProj = Standard_True;
6257 if (anArg == "-eye")
6259 theDi << "Eye: " << aViewEye.X() << " " << aViewEye.Y() << " " << aViewEye.Z() << "\n";
6261 else if (anArg == "-at")
6263 theDi << "At: " << aViewAt.X() << " " << aViewAt.Y() << " " << aViewAt.Z() << "\n";
6265 else if (anArg == "-up")
6267 theDi << "Up: " << aViewUp.X() << " " << aViewUp.Y() << " " << aViewUp.Z() << "\n";
6269 else if (anArg == "-proj")
6271 theDi << "Proj: " << aViewProj.X() << " " << aViewProj.Y() << " " << aViewProj.Z() << "\n";
6274 else if (anArg == "-center")
6276 if (anArgIter + 2 < theArgsNb)
6278 const TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
6279 const TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
6280 if (anX.IsIntegerValue()
6281 && anY.IsIntegerValue())
6283 toSetCenter2d = Standard_True;
6284 aCenter2d = Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue());
6290 std::cout << "Syntax error at '" << anArg << "'\n";
6295 // change view parameters in proper order
6298 aView->SetScale (aViewScale);
6302 aView->SetSize (aViewSize);
6306 aView->SetEye (aViewEye.X(), aViewEye.Y(), aViewEye.Z());
6310 aView->SetAt (aViewAt.X(), aViewAt.Y(), aViewAt.Z());
6314 aView->SetProj (aViewProj.X(), aViewProj.Y(), aViewProj.Z());
6318 aView->SetUp (aViewUp.X(), aViewUp.Y(), aViewUp.Z());
6322 aView->SetCenter (aCenter2d.x(), aCenter2d.y());
6328 //==============================================================================
6329 //function : VAnimation
6331 //==============================================================================
6332 static Standard_Integer VAnimation (Draw_Interpretor& theDI,
6333 Standard_Integer theArgNb,
6334 const char** theArgVec)
6336 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
6339 for (NCollection_DataMap<TCollection_AsciiString, Handle(AIS_Animation)>::Iterator
6340 anAnimIter (ViewerTest_AnimationTimelineMap); anAnimIter.More(); anAnimIter.Next())
6342 theDI << anAnimIter.Key() << " " << anAnimIter.Value()->Duration() << " sec\n";
6348 std::cout << "Error: no active view\n";
6352 Standard_Integer anArgIter = 1;
6353 TCollection_AsciiString aNameArg (theArgVec[anArgIter++]);
6354 if (aNameArg.IsEmpty())
6356 std::cout << "Syntax error: animation name is not defined.\n";
6360 TCollection_AsciiString aNameArgLower = aNameArg;
6361 aNameArgLower.LowerCase();
6362 if (aNameArgLower == "-reset"
6363 || aNameArgLower == "-clear")
6365 ViewerTest_AnimationTimelineMap.Clear();
6368 else if (aNameArg.Value (1) == '-')
6370 std::cout << "Syntax error: invalid animation name '" << aNameArg << "'.\n";
6374 const char* aNameSplitter = "/";
6375 Standard_Integer aSplitPos = aNameArg.Search (aNameSplitter);
6376 if (aSplitPos == -1)
6378 aNameSplitter = ".";
6379 aSplitPos = aNameArg.Search (aNameSplitter);
6382 // find existing or create a new animation by specified name within syntax "parent.child".
6383 Handle(AIS_Animation) aRootAnimation, aParentAnimation, anAnimation;
6384 for (; !aNameArg.IsEmpty();)
6386 TCollection_AsciiString aNameParent;
6387 if (aSplitPos != -1)
6389 if (aSplitPos == aNameArg.Length())
6391 std::cout << "Syntax error: animation name is not defined.\n";
6395 aNameParent = aNameArg.SubString ( 1, aSplitPos - 1);
6396 aNameArg = aNameArg.SubString (aSplitPos + 1, aNameArg.Length());
6398 aSplitPos = aNameArg.Search (aNameSplitter);
6402 aNameParent = aNameArg;
6406 if (anAnimation.IsNull())
6408 if (!ViewerTest_AnimationTimelineMap.Find (aNameParent, anAnimation))
6410 anAnimation = new AIS_Animation (aNameParent);
6411 ViewerTest_AnimationTimelineMap.Bind (aNameParent, anAnimation);
6413 aRootAnimation = anAnimation;
6417 aParentAnimation = anAnimation;
6418 anAnimation = aParentAnimation->Find (aNameParent);
6419 if (anAnimation.IsNull())
6421 anAnimation = new AIS_Animation (aNameParent);
6422 aParentAnimation->Add (anAnimation);
6427 if (anArgIter >= theArgNb)
6429 // just print the list of children
6430 for (NCollection_Sequence<Handle(AIS_Animation)>::Iterator anAnimIter (anAnimation->Children()); anAnimIter.More(); anAnimIter.Next())
6432 theDI << anAnimIter.Value()->Name() << " " << anAnimIter.Value()->Duration() << " sec\n";
6437 // animation parameters
6438 Standard_Boolean toPlay = Standard_False;
6439 Standard_Real aPlaySpeed = 1.0;
6440 Standard_Real aPlayStartTime = anAnimation->StartPts();
6441 Standard_Real aPlayDuration = anAnimation->Duration();
6442 Standard_Integer aFpsNum = 0;
6443 Standard_Integer aFpsDen = 1;
6444 Standard_Boolean isFreeCamera = Standard_False;
6445 Standard_Boolean isLockLoop = Standard_False;
6446 Handle(V3d_View) aView = ViewerTest::CurrentView();
6447 for (; anArgIter < theArgNb; ++anArgIter)
6449 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6452 if (anArg == "-reset"
6453 || anArg == "-clear")
6455 anAnimation->Clear();
6457 else if (anArg == "-remove"
6459 || anArg == "-delete")
6461 if (!aParentAnimation.IsNull())
6463 ViewerTest_AnimationTimelineMap.UnBind (anAnimation->Name());
6467 aParentAnimation->Remove (anAnimation);
6471 else if (anArg == "-play")
6473 toPlay = Standard_True;
6474 if (++anArgIter < theArgNb)
6476 if (*theArgVec[anArgIter] == '-')
6481 aPlayStartTime = Draw::Atof (theArgVec[anArgIter]);
6483 if (++anArgIter < theArgNb)
6485 if (*theArgVec[anArgIter] == '-')
6490 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
6494 else if (anArg == "-resume")
6496 toPlay = Standard_True;
6497 aPlayStartTime = anAnimation->ElapsedTime();
6498 if (++anArgIter < theArgNb)
6500 if (*theArgVec[anArgIter] == '-')
6506 aPlayDuration = Draw::Atof (theArgVec[anArgIter]);
6509 else if (anArg == "-playspeed"
6510 || anArg == "-speed")
6512 if (++anArgIter >= theArgNb)
6514 std::cout << "Syntax error at " << anArg << ".\n";
6517 aPlaySpeed = Draw::Atof (theArgVec[anArgIter]);
6519 else if (anArg == "-lock"
6520 || anArg == "-lockloop"
6521 || anArg == "-playlockloop")
6523 isLockLoop = Standard_True;
6525 else if (anArg == "-freecamera"
6526 || anArg == "-playfreecamera"
6527 || anArg == "-freelook")
6529 isFreeCamera = Standard_True;
6531 else if (anArg == "-fps")
6533 if (++anArgIter >= theArgNb)
6535 std::cout << "Syntax error at " << anArg << ".\n";
6539 TCollection_AsciiString aFpsArg (theArgVec[anArgIter]);
6540 Standard_Integer aSplitIndex = aFpsArg.FirstLocationInSet ("/", 1, aFpsArg.Length());
6541 if (aSplitIndex == 0)
6543 aFpsNum = aFpsArg.IntegerValue();
6547 const TCollection_AsciiString aDenStr = aFpsArg.Split (aSplitIndex);
6548 aFpsArg.Split (aFpsArg.Length() - 1);
6549 const TCollection_AsciiString aNumStr = aFpsArg;
6550 aFpsNum = aNumStr.IntegerValue();
6551 aFpsDen = aDenStr.IntegerValue();
6554 std::cout << "Syntax error at " << anArg << ".\n";
6559 // animation definition options
6560 else if (anArg == "-start"
6561 || anArg == "-starttime"
6562 || anArg == "-startpts")
6564 if (++anArgIter >= theArgNb)
6566 std::cout << "Syntax error at " << anArg << ".\n";
6570 anAnimation->SetStartPts (Draw::Atof (theArgVec[anArgIter]));
6571 aRootAnimation->UpdateTotalDuration();
6573 else if (anArg == "-end"
6574 || anArg == "-endtime"
6575 || anArg == "-endpts")
6577 if (++anArgIter >= theArgNb)
6579 std::cout << "Syntax error at " << anArg << ".\n";
6583 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]) - anAnimation->StartPts());
6584 aRootAnimation->UpdateTotalDuration();
6586 else if (anArg == "-dur"
6587 || anArg == "-duration")
6589 if (++anArgIter >= theArgNb)
6591 std::cout << "Syntax error at " << anArg << ".\n";
6595 anAnimation->SetOwnDuration (Draw::Atof (theArgVec[anArgIter]));
6596 aRootAnimation->UpdateTotalDuration();
6598 else if (anArg == "-command"
6600 || anArg == "-invoke"
6602 || anArg == "-proc")
6604 if (++anArgIter >= theArgNb)
6606 std::cout << "Syntax error at " << anArg << ".\n";
6610 Handle(ViewerTest_AnimationProc) aCmdAnimation = new ViewerTest_AnimationProc (anAnimation->Name(), &theDI, theArgVec[anArgIter]);
6611 replaceAnimation (aParentAnimation, anAnimation, aCmdAnimation);
6613 else if (anArg == "-objecttrsf"
6614 || anArg == "-objectransformation"
6615 || anArg == "-objtransformation"
6616 || anArg == "-objtrsf"
6617 || anArg == "-object"
6620 if (++anArgIter >= theArgNb)
6622 std::cout << "Syntax error at " << anArg << ".\n";
6626 TCollection_AsciiString anObjName (theArgVec[anArgIter]);
6627 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfAIS = GetMapOfAIS();
6628 if (!aMapOfAIS.IsBound2 (anObjName))
6630 std::cout << "Syntax error: wrong object name at " << anArg << "\n";
6634 Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (aMapOfAIS.Find2 (anObjName));
6635 gp_Trsf aTrsfs [2] = { anObject->LocalTransformation(), anObject->LocalTransformation() };
6636 gp_Quaternion aRotQuats[2] = { aTrsfs[0].GetRotation(), aTrsfs[1].GetRotation() };
6637 gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
6638 Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
6639 Standard_Boolean isTrsfSet = Standard_False;
6640 Standard_Integer aTrsfArgIter = anArgIter + 1;
6641 for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
6643 TCollection_AsciiString aTrsfArg (theArgVec[aTrsfArgIter]);
6644 aTrsfArg.LowerCase();
6645 const Standard_Integer anIndex = aTrsfArg.EndsWith ("1") ? 0 : 1;
6646 if (aTrsfArg.StartsWith ("-rotation")
6647 || aTrsfArg.StartsWith ("-rot"))
6649 isTrsfSet = Standard_True;
6650 if (aTrsfArgIter + 4 >= theArgNb
6651 || !parseQuaternion (theArgVec + aTrsfArgIter + 1, aRotQuats[anIndex]))
6653 std::cout << "Syntax error at " << aTrsfArg << ".\n";
6658 else if (aTrsfArg.StartsWith ("-location")
6659 || aTrsfArg.StartsWith ("-loc"))
6661 isTrsfSet = Standard_True;
6662 if (aTrsfArgIter + 3 >= theArgNb
6663 || !parseXYZ (theArgVec + aTrsfArgIter + 1, aLocPnts[anIndex]))
6665 std::cout << "Syntax error at " << aTrsfArg << ".\n";
6670 else if (aTrsfArg.StartsWith ("-scale"))
6672 isTrsfSet = Standard_True;
6673 if (++aTrsfArgIter >= theArgNb)
6675 std::cout << "Syntax error at " << aTrsfArg << ".\n";
6679 const TCollection_AsciiString aScaleStr (theArgVec[aTrsfArgIter]);
6680 if (!aScaleStr.IsRealValue())
6682 std::cout << "Syntax error at " << aTrsfArg << ".\n";
6685 aScales[anIndex] = aScaleStr.RealValue();
6689 anArgIter = aTrsfArgIter - 1;
6695 std::cout << "Syntax error at " << anArg << ".\n";
6698 else if (aTrsfArgIter >= theArgNb)
6700 anArgIter = theArgNb;
6703 aTrsfs[0].SetRotation (aRotQuats[0]);
6704 aTrsfs[1].SetRotation (aRotQuats[1]);
6705 aTrsfs[0].SetTranslationPart (aLocPnts[0]);
6706 aTrsfs[1].SetTranslationPart (aLocPnts[1]);
6707 aTrsfs[0].SetScaleFactor (aScales[0]);
6708 aTrsfs[1].SetScaleFactor (aScales[1]);
6710 Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
6711 replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
6713 else if (anArg == "-viewtrsf"
6714 || anArg == "-view")
6716 Handle(AIS_AnimationCamera) aCamAnimation = Handle(AIS_AnimationCamera)::DownCast (anAnimation);
6717 if (aCamAnimation.IsNull())
6719 aCamAnimation = new AIS_AnimationCamera (anAnimation->Name(), aView);
6720 replaceAnimation (aParentAnimation, anAnimation, aCamAnimation);
6723 Handle(Graphic3d_Camera) aCams[2] =
6725 new Graphic3d_Camera (aCamAnimation->View()->Camera()),
6726 new Graphic3d_Camera (aCamAnimation->View()->Camera())
6729 Standard_Boolean isTrsfSet = Standard_False;
6730 Standard_Integer aViewArgIter = anArgIter + 1;
6731 for (; aViewArgIter < theArgNb; ++aViewArgIter)
6733 TCollection_AsciiString aViewArg (theArgVec[aViewArgIter]);
6734 aViewArg.LowerCase();
6735 const Standard_Integer anIndex = aViewArg.EndsWith("1") ? 0 : 1;
6736 if (aViewArg.StartsWith ("-scale"))
6738 isTrsfSet = Standard_True;
6739 if (++aViewArgIter >= theArgNb)
6741 std::cout << "Syntax error at " << anArg << ".\n";
6745 const TCollection_AsciiString aScaleStr (theArgVec[aViewArgIter]);
6746 if (!aScaleStr.IsRealValue())
6748 std::cout << "Syntax error at " << aViewArg << ".\n";
6751 Standard_Real aScale = aScaleStr.RealValue();
6752 aScale = aCamAnimation->View()->DefaultCamera()->Scale() / aScale;
6753 aCams[anIndex]->SetScale (aScale);
6755 else if (aViewArg.StartsWith ("-eye")
6756 || aViewArg.StartsWith ("-center")
6757 || aViewArg.StartsWith ("-at")
6758 || aViewArg.StartsWith ("-up"))
6760 isTrsfSet = Standard_True;
6762 if (aViewArgIter + 3 >= theArgNb
6763 || !parseXYZ (theArgVec + aViewArgIter + 1, anXYZ))
6765 std::cout << "Syntax error at " << aViewArg << ".\n";
6770 if (aViewArg.StartsWith ("-eye"))
6772 aCams[anIndex]->SetEye (anXYZ);
6774 else if (aViewArg.StartsWith ("-center")
6775 || aViewArg.StartsWith ("-at"))
6777 aCams[anIndex]->SetCenter (anXYZ);
6779 else if (aViewArg.StartsWith ("-up"))
6781 aCams[anIndex]->SetUp (anXYZ);
6786 anArgIter = aViewArgIter - 1;
6792 std::cout << "Syntax error at " << anArg << ".\n";
6795 else if (aViewArgIter >= theArgNb)
6797 anArgIter = theArgNb;
6800 aCamAnimation->SetCameraStart(aCams[0]);
6801 aCamAnimation->SetCameraEnd (aCams[1]);
6805 std::cout << "Syntax error at " << anArg << ".\n";
6815 // Start animation timeline and process frame updating.
6816 TheIsAnimating = Standard_True;
6817 const Standard_Boolean wasImmediateUpdate = aView->SetImmediateUpdate (Standard_False);
6818 Handle(Graphic3d_Camera) aCameraBack = new Graphic3d_Camera (aView->Camera());
6819 anAnimation->StartTimer (aPlayStartTime, aPlaySpeed, Standard_True, aPlayDuration <= 0.0);
6822 aView->Camera()->Copy (aCameraBack);
6825 const Standard_Real anUpperPts = aPlayStartTime + aPlayDuration;
6828 while (!anAnimation->IsStopped())
6830 aCameraBack->Copy (aView->Camera());
6831 const Standard_Real aPts = anAnimation->UpdateTimer();
6834 aView->Camera()->Copy (aCameraBack);
6837 if (aPts >= anUpperPts)
6839 anAnimation->Pause();
6843 if (aView->IsInvalidated())
6849 aView->RedrawImmediate();
6854 // handle user events
6855 theDI.Eval ("after 1 set waiter 1");
6856 theDI.Eval ("vwait waiter");
6858 if (!TheIsAnimating)
6860 anAnimation->Pause();
6866 if (aView->IsInvalidated())
6872 aView->RedrawImmediate();
6877 OSD_Timer aPerfTimer;
6880 // Manage frame-rated animation here
6881 Standard_Real aPts = aPlayStartTime;
6882 int64_t aNbFrames = 0;
6883 for (; aPts <= anUpperPts;)
6885 const Standard_Real aRecPts = aPlaySpeed * ((Standard_Real(aFpsDen) / Standard_Real(aFpsNum)) * Standard_Real(aNbFrames));
6886 aPts = aPlayStartTime + aRecPts;
6888 if (!anAnimation->Update (aPts))
6897 anAnimation->Stop();
6898 const Standard_Real aRecFps = Standard_Real(aNbFrames) / aPerfTimer.ElapsedTime();
6899 theDI << "Average FPS: " << aRecFps << "\n"
6900 << "Nb. Frames: " << Standard_Real(aNbFrames);
6905 aView->SetImmediateUpdate (wasImmediateUpdate);
6906 TheIsAnimating = Standard_False;
6911 //=======================================================================
6912 //function : VChangeSelected
6913 //purpose : Adds the shape to selection or remove one from it
6914 //=======================================================================
6915 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
6916 Standard_Integer argc,
6921 di<<"Usage : " << argv[0] << " shape \n";
6925 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6926 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
6927 TCollection_AsciiString aName(argv[1]);
6928 Handle(AIS_InteractiveObject) anAISObject;
6930 if(!aMap.IsBound2(aName))
6932 di<<"Use 'vdisplay' before";
6937 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
6938 if(anAISObject.IsNull()){
6939 di<<"No interactive object \n";
6943 aContext->AddOrRemoveSelected(anAISObject);
6948 //=======================================================================
6949 //function : VNbSelected
6950 //purpose : Returns number of selected objects
6951 //=======================================================================
6952 static Standard_Integer VNbSelected (Draw_Interpretor& di,
6953 Standard_Integer argc,
6958 di << "Usage : " << argv[0] << "\n";
6961 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6962 if(aContext.IsNull())
6964 di << "use 'vinit' command before " << argv[0] << "\n";
6967 di << aContext->NbSelected() << "\n";
6971 //=======================================================================
6972 //function : VPurgeDisplay
6973 //purpose : Switches altialiasing on or off
6974 //=======================================================================
6975 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
6976 Standard_Integer argc,
6981 di << "Usage : " << argv[0] << "\n";
6984 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6985 if (aContext.IsNull())
6987 di << "use 'vinit' command before " << argv[0] << "\n";
6991 di << aContext->PurgeDisplay() << "\n";
6995 //=======================================================================
6996 //function : VSetViewSize
6998 //=======================================================================
6999 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
7000 Standard_Integer argc,
7003 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7004 if(aContext.IsNull())
7006 di << "use 'vinit' command before " << argv[0] << "\n";
7011 di<<"Usage : " << argv[0] << " Size\n";
7014 Standard_Real aSize = Draw::Atof (argv[1]);
7017 di<<"Bad Size value : " << aSize << "\n";
7021 Handle(V3d_View) aView = ViewerTest::CurrentView();
7022 aView->SetSize(aSize);
7026 //=======================================================================
7027 //function : VMoveView
7029 //=======================================================================
7030 static Standard_Integer VMoveView (Draw_Interpretor& di,
7031 Standard_Integer argc,
7034 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7035 if(aContext.IsNull())
7037 di << "use 'vinit' command before " << argv[0] << "\n";
7040 if(argc < 4 || argc > 5)
7042 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
7045 Standard_Real Dx = Draw::Atof (argv[1]);
7046 Standard_Real Dy = Draw::Atof (argv[2]);
7047 Standard_Real Dz = Draw::Atof (argv[3]);
7048 Standard_Boolean aStart = Standard_True;
7051 aStart = (Draw::Atoi (argv[4]) > 0);
7054 Handle(V3d_View) aView = ViewerTest::CurrentView();
7055 aView->Move(Dx,Dy,Dz,aStart);
7059 //=======================================================================
7060 //function : VTranslateView
7062 //=======================================================================
7063 static Standard_Integer VTranslateView (Draw_Interpretor& di,
7064 Standard_Integer argc,
7067 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7068 if(aContext.IsNull())
7070 di << "use 'vinit' command before " << argv[0] << "\n";
7073 if(argc < 4 || argc > 5)
7075 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
7078 Standard_Real Dx = Draw::Atof (argv[1]);
7079 Standard_Real Dy = Draw::Atof (argv[2]);
7080 Standard_Real Dz = Draw::Atof (argv[3]);
7081 Standard_Boolean aStart = Standard_True;
7084 aStart = (Draw::Atoi (argv[4]) > 0);
7087 Handle(V3d_View) aView = ViewerTest::CurrentView();
7088 aView->Translate(Dx,Dy,Dz,aStart);
7092 //=======================================================================
7093 //function : VTurnView
7095 //=======================================================================
7096 static Standard_Integer VTurnView (Draw_Interpretor& di,
7097 Standard_Integer argc,
7100 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7101 if(aContext.IsNull()) {
7102 di << "use 'vinit' command before " << argv[0] << "\n";
7105 if(argc < 4 || argc > 5){
7106 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
7109 Standard_Real Ax = Draw::Atof (argv[1]);
7110 Standard_Real Ay = Draw::Atof (argv[2]);
7111 Standard_Real Az = Draw::Atof (argv[3]);
7112 Standard_Boolean aStart = Standard_True;
7115 aStart = (Draw::Atoi (argv[4]) > 0);
7118 Handle(V3d_View) aView = ViewerTest::CurrentView();
7119 aView->Turn(Ax,Ay,Az,aStart);
7123 //==============================================================================
7124 //function : VTextureEnv
7125 //purpose : ENables or disables environment mapping
7126 //==============================================================================
7127 class OCC_TextureEnv : public Graphic3d_TextureEnv
7130 OCC_TextureEnv(const Standard_CString FileName);
7131 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
7132 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
7133 const Standard_Boolean theModulateFlag,
7134 const Graphic3d_TypeOfTextureFilter theFilter,
7135 const Standard_ShortReal theXScale,
7136 const Standard_ShortReal theYScale,
7137 const Standard_ShortReal theXShift,
7138 const Standard_ShortReal theYShift,
7139 const Standard_ShortReal theAngle);
7140 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
7142 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
7144 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
7145 : Graphic3d_TextureEnv(theFileName)
7149 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
7150 : Graphic3d_TextureEnv(theTexId)
7154 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
7155 const Standard_Boolean theModulateFlag,
7156 const Graphic3d_TypeOfTextureFilter theFilter,
7157 const Standard_ShortReal theXScale,
7158 const Standard_ShortReal theYScale,
7159 const Standard_ShortReal theXShift,
7160 const Standard_ShortReal theYShift,
7161 const Standard_ShortReal theAngle)
7163 myParams->SetRepeat (theRepeatFlag);
7164 myParams->SetModulate (theModulateFlag);
7165 myParams->SetFilter (theFilter);
7166 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
7167 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
7168 myParams->SetRotation (theAngle);
7171 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
7173 // get the active view
7174 Handle(V3d_View) aView = ViewerTest::CurrentView();
7177 std::cerr << "No active view. Please call vinit.\n";
7181 // Checking the input arguments
7182 Standard_Boolean anEnableFlag = Standard_False;
7183 Standard_Boolean isOk = theArgNb >= 2;
7186 TCollection_AsciiString anEnableOpt(theArgVec[1]);
7187 anEnableFlag = anEnableOpt.IsEqual("on");
7188 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
7192 isOk = (theArgNb == 3 || theArgNb == 11);
7195 TCollection_AsciiString aTextureOpt(theArgVec[2]);
7196 isOk = (!aTextureOpt.IsIntegerValue() ||
7197 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
7199 if (isOk && theArgNb == 11)
7201 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
7202 aModulateOpt(theArgVec[4]),
7203 aFilterOpt (theArgVec[5]),
7204 aSScaleOpt (theArgVec[6]),
7205 aTScaleOpt (theArgVec[7]),
7206 aSTransOpt (theArgVec[8]),
7207 aTTransOpt (theArgVec[9]),
7208 anAngleOpt (theArgVec[10]);
7209 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
7210 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
7211 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
7212 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
7213 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
7214 anAngleOpt.IsRealValue());
7221 std::cerr << "Usage :" << std::endl;
7222 std::cerr << theArgVec[0] << " off" << std::endl;
7223 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;
7229 TCollection_AsciiString aTextureOpt(theArgVec[2]);
7230 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
7231 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
7232 new OCC_TextureEnv(theArgVec[2]);
7236 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
7237 aTexEnv->SetTextureParameters(
7238 aRepeatOpt. IsEqual("repeat"),
7239 aModulateOpt.IsEqual("modulate"),
7240 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
7241 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
7242 Graphic3d_TOTF_TRILINEAR,
7243 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
7244 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
7245 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
7246 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
7247 (Standard_ShortReal)Draw::Atof(theArgVec[10])
7250 aView->SetTextureEnv(aTexEnv);
7252 else // Disabling environment mapping
7254 Handle(Graphic3d_TextureEnv) aTexture;
7255 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
7264 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
7266 //! Remove registered clipping plane from all views and objects.
7267 static void removePlane (MapOfPlanes& theRegPlanes,
7268 const TCollection_AsciiString& theName)
7270 Handle(Graphic3d_ClipPlane) aClipPlane;
7271 if (!theRegPlanes.Find (theName, aClipPlane))
7273 std::cout << "Warning: no such plane.\n";
7277 theRegPlanes.UnBind (theName);
7278 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
7279 anIObjIt.More(); anIObjIt.Next())
7281 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
7282 aPrs->RemoveClipPlane (aClipPlane);
7285 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
7286 aViewIt.More(); aViewIt.Next())
7288 const Handle(V3d_View)& aView = aViewIt.Key2();
7289 aView->RemoveClipPlane(aClipPlane);
7292 ViewerTest::RedrawAllViews();
7296 //===============================================================================================
7297 //function : VClipPlane
7299 //===============================================================================================
7300 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7302 // use short-cut for created clip planes map of created (or "registered by name") clip planes
7303 static MapOfPlanes aRegPlanes;
7307 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
7309 theDi << aPlaneIter.Key() << " ";
7314 TCollection_AsciiString aCommand (theArgVec[1]);
7315 aCommand.LowerCase();
7316 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
7317 if (anActiveView.IsNull())
7319 std::cout << "Error: no active view.\n";
7323 // print maximum number of planes for current viewer
7324 if (aCommand == "-maxplanes"
7325 || aCommand == "maxplanes")
7327 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
7328 << " plane slots provided by driver.\n";
7332 // create / delete plane instance
7333 if (aCommand == "-create"
7334 || aCommand == "create"
7335 || aCommand == "-delete"
7336 || aCommand == "delete"
7337 || aCommand == "-clone"
7338 || aCommand == "clone")
7342 std::cout << "Syntax error: plane name is required.\n";
7346 Standard_Boolean toCreate = aCommand == "-create"
7347 || aCommand == "create";
7348 Standard_Boolean toClone = aCommand == "-clone"
7349 || aCommand == "clone";
7350 Standard_Boolean toDelete = aCommand == "-delete"
7351 || aCommand == "delete";
7352 TCollection_AsciiString aPlane (theArgVec[2]);
7356 if (aRegPlanes.IsBound (aPlane))
7358 std::cout << "Warning: existing plane has been overridden.\n";
7363 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
7367 else if (toClone) // toClone
7369 if (!aRegPlanes.IsBound (aPlane))
7371 std::cout << "Error: no such plane.\n";
7374 else if (theArgsNb < 4)
7376 std::cout << "Syntax error: enter name for new plane.\n";
7380 TCollection_AsciiString aClone (theArgVec[3]);
7381 if (aRegPlanes.IsBound (aClone))
7383 std::cout << "Error: plane name is in use.\n";
7387 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
7389 aRegPlanes.Bind (aClone, aClipPlane->Clone());
7399 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
7401 aPlane = aPlaneIter.Key();
7402 removePlane (aRegPlanes, aPlane);
7403 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
7408 removePlane (aRegPlanes, aPlane);
7414 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
7419 // set / unset plane command
7420 if (aCommand == "set"
7421 || aCommand == "unset")
7425 std::cout << "Syntax error: need more arguments.\n";
7429 // redirect to new syntax
7430 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
7431 anArgVec.SetValue (1, theArgVec[0]);
7432 anArgVec.SetValue (2, theArgVec[2]);
7433 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
7434 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
7436 anArgVec.SetValue (anIt, theArgVec[anIt]);
7439 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
7442 // change plane command
7443 TCollection_AsciiString aPlaneName;
7444 Handle(Graphic3d_ClipPlane) aClipPlane;
7445 Standard_Integer anArgIter = 0;
7446 if (aCommand == "-change"
7447 || aCommand == "change")
7449 // old syntax support
7452 std::cout << "Syntax error: need more arguments.\n";
7457 aPlaneName = theArgVec[2];
7458 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
7460 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
7464 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
7467 aPlaneName = theArgVec[1];
7472 aPlaneName = theArgVec[1];
7473 aClipPlane = new Graphic3d_ClipPlane();
7474 aRegPlanes.Bind (aPlaneName, aClipPlane);
7475 theDi << "Created new plane " << aPlaneName << ".\n";
7478 if (theArgsNb - anArgIter < 1)
7480 std::cout << "Syntax error: need more arguments.\n";
7484 for (; anArgIter < theArgsNb; ++anArgIter)
7486 const char** aChangeArgs = theArgVec + anArgIter;
7487 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
7488 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
7489 aChangeArg.LowerCase();
7491 Standard_Boolean toEnable = Standard_True;
7492 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
7494 aClipPlane->SetOn (toEnable);
7496 else if (aChangeArg == "-equation"
7497 || aChangeArg == "equation")
7499 if (aNbChangeArgs < 5)
7501 std::cout << "Syntax error: need more arguments.\n";
7505 Standard_Real aCoeffA = Draw::Atof (aChangeArgs [1]);
7506 Standard_Real aCoeffB = Draw::Atof (aChangeArgs [2]);
7507 Standard_Real aCoeffC = Draw::Atof (aChangeArgs [3]);
7508 Standard_Real aCoeffD = Draw::Atof (aChangeArgs [4]);
7509 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
7512 else if (aChangeArg == "-capping"
7513 || aChangeArg == "capping")
7515 if (aNbChangeArgs < 2)
7517 std::cout << "Syntax error: need more arguments.\n";
7521 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
7523 aClipPlane->SetCapping (toEnable);
7528 // just skip otherwise (old syntax)
7531 else if (aChangeArg == "-useobjectmaterial"
7532 || aChangeArg == "-useobjectmat"
7533 || aChangeArg == "-useobjmat"
7534 || aChangeArg == "-useobjmaterial")
7536 if (aNbChangeArgs < 2)
7538 std::cout << "Syntax error: need more arguments.\n";
7542 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
7544 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
7548 else if (aChangeArg == "-useobjecttexture"
7549 || aChangeArg == "-useobjecttex"
7550 || aChangeArg == "-useobjtexture"
7551 || aChangeArg == "-useobjtex")
7553 if (aNbChangeArgs < 2)
7555 std::cout << "Syntax error: need more arguments.\n";
7559 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
7561 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
7565 else if (aChangeArg == "-useobjectshader"
7566 || aChangeArg == "-useobjshader")
7568 if (aNbChangeArgs < 2)
7570 std::cout << "Syntax error: need more arguments.\n";
7574 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
7576 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
7580 else if (aChangeArg == "-color"
7581 || aChangeArg == "color")
7583 Quantity_Color aColor;
7584 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
7589 std::cout << "Syntax error: need more arguments.\n";
7593 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
7594 aMat.SetAmbientColor (aColor);
7595 aMat.SetDiffuseColor (aColor);
7596 aClipPlane->SetCappingMaterial (aMat);
7597 anArgIter += aNbParsed;
7599 else if (aChangeArg == "-texname"
7600 || aChangeArg == "texname")
7602 if (aNbChangeArgs < 2)
7604 std::cout << "Syntax error: need more arguments.\n";
7608 TCollection_AsciiString aTextureName (aChangeArgs[1]);
7609 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
7610 if (!aTexture->IsDone())
7612 aClipPlane->SetCappingTexture (NULL);
7616 aTexture->EnableModulate();
7617 aTexture->EnableRepeat();
7618 aClipPlane->SetCappingTexture (aTexture);
7622 else if (aChangeArg == "-texscale"
7623 || aChangeArg == "texscale")
7625 if (aClipPlane->CappingTexture().IsNull())
7627 std::cout << "Error: no texture is set.\n";
7631 if (aNbChangeArgs < 3)
7633 std::cout << "Syntax error: need more arguments.\n";
7637 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
7638 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
7639 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
7642 else if (aChangeArg == "-texorigin"
7643 || aChangeArg == "texorigin") // texture origin
7645 if (aClipPlane->CappingTexture().IsNull())
7647 std::cout << "Error: no texture is set.\n";
7651 if (aNbChangeArgs < 3)
7653 std::cout << "Syntax error: need more arguments.\n";
7657 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
7658 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
7660 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
7663 else if (aChangeArg == "-texrotate"
7664 || aChangeArg == "texrotate") // texture rotation
7666 if (aClipPlane->CappingTexture().IsNull())
7668 std::cout << "Error: no texture is set.\n";
7672 if (aNbChangeArgs < 2)
7674 std::cout << "Syntax error: need more arguments.\n";
7678 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
7679 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
7682 else if (aChangeArg == "-hatch"
7683 || aChangeArg == "hatch")
7685 if (aNbChangeArgs < 2)
7687 std::cout << "Syntax error: need more arguments.\n";
7691 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
7692 aHatchStr.LowerCase();
7693 if (aHatchStr == "on")
7695 aClipPlane->SetCappingHatchOn();
7697 else if (aHatchStr == "off")
7699 aClipPlane->SetCappingHatchOff();
7703 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
7707 else if (aChangeArg == "-delete"
7708 || aChangeArg == "delete")
7710 removePlane (aRegPlanes, aPlaneName);
7713 else if (aChangeArg == "-set"
7714 || aChangeArg == "-unset")
7716 // set / unset plane command
7717 Standard_Boolean toSet = aChangeArg == "-set";
7718 Standard_Integer anIt = 1;
7719 for (; anIt < aNbChangeArgs; ++anIt)
7721 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
7722 if (anEntityName.IsEmpty()
7723 || anEntityName.Value (1) == '-')
7727 else if (ViewerTest_myViews.IsBound1 (anEntityName))
7729 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
7732 aView->AddClipPlane (aClipPlane);
7736 aView->RemoveClipPlane (aClipPlane);
7740 else if (GetMapOfAIS().IsBound2 (anEntityName))
7742 Handle(AIS_InteractiveObject) aIObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
7745 aIObj->AddClipPlane (aClipPlane);
7749 aIObj->RemoveClipPlane (aClipPlane);
7754 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
7761 // apply to active view
7764 anActiveView->AddClipPlane (aClipPlane);
7768 anActiveView->RemoveClipPlane (aClipPlane);
7773 anArgIter = anArgIter + anIt - 1;
7778 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
7783 ViewerTest::RedrawAllViews();
7787 //===============================================================================================
7788 //function : VZRange
7790 //===============================================================================================
7791 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7793 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
7795 if (aCurrentView.IsNull())
7797 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
7801 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
7805 theDi << "ZNear: " << aCamera->ZNear() << "\n";
7806 theDi << "ZFar: " << aCamera->ZFar() << "\n";
7812 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
7813 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
7815 if (aNewZNear >= aNewZFar)
7817 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
7821 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
7823 std::cout << theArgVec[0] << ": invalid arguments: ";
7824 std::cout << "znear, zfar should be positive for perspective camera.\n";
7828 aCamera->SetZRange (aNewZNear, aNewZFar);
7832 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
7836 aCurrentView->Redraw();
7841 //===============================================================================================
7842 //function : VAutoZFit
7844 //===============================================================================================
7845 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7847 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
7849 if (aCurrentView.IsNull())
7851 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
7855 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
7859 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
7865 theDi << "Auto z-fit mode: \n"
7866 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
7867 << "Scale: " << aScale << "\n";
7871 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
7875 aScale = Draw::Atoi (theArgVec[2]);
7878 aCurrentView->SetAutoZFitMode (isOn, aScale);
7879 aCurrentView->AutoZFit();
7880 aCurrentView->Redraw();
7885 //! Auxiliary function to print projection type
7886 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
7888 switch (theProjType)
7890 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
7891 case Graphic3d_Camera::Projection_Perspective: return "perspective";
7892 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
7893 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
7894 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
7899 //===============================================================================================
7900 //function : VCamera
7902 //===============================================================================================
7903 static int VCamera (Draw_Interpretor& theDI,
7904 Standard_Integer theArgsNb,
7905 const char** theArgVec)
7907 Handle(V3d_View) aView = ViewerTest::CurrentView();
7910 std::cout << "Error: no active view.\n";
7914 Handle(Graphic3d_Camera) aCamera = aView->Camera();
7917 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
7918 theDI << "FOVy: " << aCamera->FOVy() << "\n";
7919 theDI << "Distance: " << aCamera->Distance() << "\n";
7920 theDI << "IOD: " << aCamera->IOD() << "\n";
7921 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
7922 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
7923 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
7927 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7929 Standard_CString anArg = theArgVec[anArgIter];
7930 TCollection_AsciiString anArgCase (anArg);
7931 anArgCase.LowerCase();
7932 if (anArgCase == "-proj"
7933 || anArgCase == "-projection"
7934 || anArgCase == "-projtype"
7935 || anArgCase == "-projectiontype")
7937 theDI << projTypeName (aCamera->ProjectionType()) << " ";
7939 else if (anArgCase == "-ortho"
7940 || anArgCase == "-orthographic")
7942 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
7944 else if (anArgCase == "-persp"
7945 || anArgCase == "-perspective"
7946 || anArgCase == "-perspmono"
7947 || anArgCase == "-perspectivemono"
7948 || anArgCase == "-mono")
7950 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
7952 else if (anArgCase == "-stereo"
7953 || anArgCase == "-stereoscopic"
7954 || anArgCase == "-perspstereo"
7955 || anArgCase == "-perspectivestereo")
7957 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7959 else if (anArgCase == "-left"
7960 || anArgCase == "-lefteye"
7961 || anArgCase == "-monoleft"
7962 || anArgCase == "-monolefteye"
7963 || anArgCase == "-perpsleft"
7964 || anArgCase == "-perpslefteye")
7966 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
7968 else if (anArgCase == "-right"
7969 || anArgCase == "-righteye"
7970 || anArgCase == "-monoright"
7971 || anArgCase == "-monorighteye"
7972 || anArgCase == "-perpsright")
7974 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
7976 else if (anArgCase == "-dist"
7977 || anArgCase == "-distance")
7979 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7980 if (anArgValue != NULL
7981 && *anArgValue != '-')
7984 aCamera->SetDistance (Draw::Atof (anArgValue));
7987 theDI << aCamera->Distance() << " ";
7989 else if (anArgCase == "-iod")
7991 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7992 if (anArgValue != NULL
7993 && *anArgValue != '-')
7996 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
7999 theDI << aCamera->IOD() << " ";
8001 else if (anArgCase == "-iodtype")
8003 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
8004 TCollection_AsciiString anValueCase (anArgValue);
8005 anValueCase.LowerCase();
8006 if (anValueCase == "abs"
8007 || anValueCase == "absolute")
8010 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
8013 else if (anValueCase == "rel"
8014 || anValueCase == "relative")
8017 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
8020 else if (*anArgValue != '-')
8022 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
8025 switch (aCamera->GetIODType())
8027 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
8028 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
8031 else if (anArgCase == "-zfocus")
8033 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8034 if (anArgValue != NULL
8035 && *anArgValue != '-')
8038 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
8041 theDI << aCamera->ZFocus() << " ";
8043 else if (anArgCase == "-zfocustype")
8045 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
8046 TCollection_AsciiString anValueCase (anArgValue);
8047 anValueCase.LowerCase();
8048 if (anValueCase == "abs"
8049 || anValueCase == "absolute")
8052 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
8055 else if (anValueCase == "rel"
8056 || anValueCase == "relative")
8059 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
8062 else if (*anArgValue != '-')
8064 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
8067 switch (aCamera->ZFocusType())
8069 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
8070 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
8073 else if (anArgCase == "-fov"
8074 || anArgCase == "-fovy")
8076 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
8077 if (anArgValue != NULL
8078 && *anArgValue != '-')
8081 aCamera->SetFOVy (Draw::Atof (anArgValue));
8084 theDI << aCamera->FOVy() << " ";
8088 std::cout << "Error: unknown argument '" << anArg << "'\n";
8099 //! Parse stereo output mode
8100 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
8101 Graphic3d_StereoMode& theMode)
8103 TCollection_AsciiString aFlag (theArg);
8105 if (aFlag == "quadbuffer")
8107 theMode = Graphic3d_StereoMode_QuadBuffer;
8109 else if (aFlag == "anaglyph")
8111 theMode = Graphic3d_StereoMode_Anaglyph;
8113 else if (aFlag == "row"
8114 || aFlag == "rowinterlaced")
8116 theMode = Graphic3d_StereoMode_RowInterlaced;
8118 else if (aFlag == "col"
8119 || aFlag == "colinterlaced"
8120 || aFlag == "columninterlaced")
8122 theMode = Graphic3d_StereoMode_ColumnInterlaced;
8124 else if (aFlag == "chess"
8125 || aFlag == "chessboard")
8127 theMode = Graphic3d_StereoMode_ChessBoard;
8129 else if (aFlag == "sbs"
8130 || aFlag == "sidebyside")
8132 theMode = Graphic3d_StereoMode_SideBySide;
8134 else if (aFlag == "ou"
8135 || aFlag == "overunder")
8137 theMode = Graphic3d_StereoMode_OverUnder;
8139 else if (aFlag == "pageflip"
8140 || aFlag == "softpageflip")
8142 theMode = Graphic3d_StereoMode_SoftPageFlip;
8146 return Standard_False;
8148 return Standard_True;
8151 //! Parse anaglyph filter
8152 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
8153 Graphic3d_RenderingParams::Anaglyph& theFilter)
8155 TCollection_AsciiString aFlag (theArg);
8157 if (aFlag == "redcyansimple")
8159 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
8161 else if (aFlag == "redcyan"
8162 || aFlag == "redcyanoptimized")
8164 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
8166 else if (aFlag == "yellowbluesimple")
8168 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
8170 else if (aFlag == "yellowblue"
8171 || aFlag == "yellowblueoptimized")
8173 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
8175 else if (aFlag == "greenmagenta"
8176 || aFlag == "greenmagentasimple")
8178 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
8182 return Standard_False;
8184 return Standard_True;
8187 //==============================================================================
8188 //function : VStereo
8190 //==============================================================================
8192 static int VStereo (Draw_Interpretor& theDI,
8193 Standard_Integer theArgNb,
8194 const char** theArgVec)
8196 Handle(V3d_View) aView = ViewerTest::CurrentView();
8201 std::cout << "Error: no active viewer!\n";
8205 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
8206 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
8209 TCollection_AsciiString aMode;
8210 switch (aView->RenderingParams().StereoMode)
8212 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
8213 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
8214 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
8215 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
8216 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
8217 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
8218 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
8219 case Graphic3d_StereoMode_Anaglyph :
8221 switch (aView->RenderingParams().AnaglyphFilter)
8223 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
8224 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
8225 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
8226 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
8227 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
8232 theDI << "Mode " << aMode << "\n";
8237 Handle(Graphic3d_Camera) aCamera;
8238 Graphic3d_RenderingParams* aParams = NULL;
8239 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
8240 if (!aView.IsNull())
8242 aParams = &aView->ChangeRenderingParams();
8243 aMode = aParams->StereoMode;
8244 aCamera = aView->Camera();
8247 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
8248 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
8250 Standard_CString anArg = theArgVec[anArgIter];
8251 TCollection_AsciiString aFlag (anArg);
8253 if (anUpdateTool.parseRedrawMode (aFlag))
8257 else if (aFlag == "0"
8260 if (++anArgIter < theArgNb)
8262 std::cout << "Error: wrong number of arguments!\n";
8266 if (!aCamera.IsNull()
8267 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
8269 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
8271 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
8274 else if (aFlag == "1"
8277 if (++anArgIter < theArgNb)
8279 std::cout << "Error: wrong number of arguments!\n";
8283 if (!aCamera.IsNull())
8285 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
8287 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
8290 else if (aFlag == "-reverse"
8291 || aFlag == "-reversed"
8292 || aFlag == "-swap")
8294 Standard_Boolean toEnable = Standard_True;
8295 if (++anArgIter < theArgNb
8296 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8300 aParams->ToReverseStereo = toEnable;
8302 else if (aFlag == "-noreverse"
8303 || aFlag == "-noswap")
8305 Standard_Boolean toDisable = Standard_True;
8306 if (++anArgIter < theArgNb
8307 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
8311 aParams->ToReverseStereo = !toDisable;
8313 else if (aFlag == "-mode"
8314 || aFlag == "-stereomode")
8316 if (++anArgIter >= theArgNb
8317 || !parseStereoMode (theArgVec[anArgIter], aMode))
8319 std::cout << "Error: syntax error at '" << anArg << "'\n";
8323 if (aMode == Graphic3d_StereoMode_QuadBuffer)
8325 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
8328 else if (aFlag == "-anaglyph"
8329 || aFlag == "-anaglyphfilter")
8331 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
8332 if (++anArgIter >= theArgNb
8333 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
8335 std::cout << "Error: syntax error at '" << anArg << "'\n";
8339 aMode = Graphic3d_StereoMode_Anaglyph;
8340 aParams->AnaglyphFilter = aFilter;
8342 else if (parseStereoMode (anArg, aMode)) // short syntax
8344 if (aMode == Graphic3d_StereoMode_QuadBuffer)
8346 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
8351 std::cout << "Error: syntax error at '" << anArg << "'\n";
8356 if (!aView.IsNull())
8358 aParams->StereoMode = aMode;
8359 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
8364 //===============================================================================================
8365 //function : VDefaults
8367 //===============================================================================================
8368 static int VDefaults (Draw_Interpretor& theDi,
8369 Standard_Integer theArgsNb,
8370 const char** theArgVec)
8372 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
8375 std::cerr << "No active viewer!\n";
8379 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
8382 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
8384 theDi << "DeflType: relative\n"
8385 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
8389 theDi << "DeflType: absolute\n"
8390 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
8392 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
8393 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
8397 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
8399 TCollection_AsciiString anArg (theArgVec[anArgIter]);
8401 if (anArg == "-ABSDEFL"
8402 || anArg == "-ABSOLUTEDEFLECTION"
8404 || anArg == "-DEFLECTION")
8406 if (++anArgIter >= theArgsNb)
8408 std::cout << "Error: wrong syntax at " << anArg << "\n";
8411 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
8412 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
8414 else if (anArg == "-RELDEFL"
8415 || anArg == "-RELATIVEDEFLECTION"
8416 || anArg == "-DEVCOEFF"
8417 || anArg == "-DEVIATIONCOEFF"
8418 || anArg == "-DEVIATIONCOEFFICIENT")
8420 if (++anArgIter >= theArgsNb)
8422 std::cout << "Error: wrong syntax at " << anArg << "\n";
8425 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
8426 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
8428 else if (anArg == "-ANGDEFL"
8429 || anArg == "-ANGULARDEFL"
8430 || anArg == "-ANGULARDEFLECTION")
8432 if (++anArgIter >= theArgsNb)
8434 std::cout << "Error: wrong syntax at " << anArg << "\n";
8437 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
8438 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
8440 else if (anArg == "-AUTOTR"
8441 || anArg == "-AUTOTRIANG"
8442 || anArg == "-AUTOTRIANGULATION")
8444 if (++anArgIter >= theArgsNb)
8446 std::cout << "Error: wrong syntax at " << anArg << "\n";
8449 TCollection_AsciiString aValue (theArgVec[anArgIter]);
8454 aDefParams->SetAutoTriangulation (Standard_True);
8456 else if (aValue == "off"
8459 aDefParams->SetAutoTriangulation (Standard_False);
8464 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
8471 //! Auxiliary method
8472 inline void addLight (const Handle(V3d_Light)& theLightNew,
8473 const Standard_Boolean theIsGlobal)
8475 if (theLightNew.IsNull())
8482 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
8486 ViewerTest::CurrentView()->SetLightOn (theLightNew);
8490 //! Auxiliary method
8491 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
8493 TCollection_AsciiString anArgNextCase (theArgNext);
8494 anArgNextCase.UpperCase();
8495 if (anArgNextCase.Length() > 5
8496 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
8498 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
8502 return theArgNext.IntegerValue();
8506 //===============================================================================================
8509 //===============================================================================================
8510 static int VLight (Draw_Interpretor& theDi,
8511 Standard_Integer theArgsNb,
8512 const char** theArgVec)
8514 Handle(V3d_View) aView = ViewerTest::CurrentView();
8515 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
8517 || aViewer.IsNull())
8519 std::cerr << "No active viewer!\n";
8523 Standard_Real anXYZ[3];
8524 Quantity_Coefficient anAtten[2];
8527 // print lights info
8528 Standard_Integer aLightId = 0;
8529 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
8531 Handle(V3d_Light) aLight = aLightIter.Value();
8532 const Quantity_Color aColor = aLight->Color();
8533 theDi << "Light" << aLightId << "\n";
8534 switch (aLight->Type())
8538 theDi << " Type: Ambient\n";
8539 theDi << " Intensity: " << aLight->Intensity() << "\n";
8542 case V3d_DIRECTIONAL:
8544 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
8545 theDi << " Type: Directional\n";
8546 theDi << " Intensity: " << aLight->Intensity() << "\n";
8547 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
8548 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
8549 if (!aLightDir.IsNull())
8551 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
8552 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
8553 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
8554 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
8558 case V3d_POSITIONAL:
8560 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
8561 theDi << " Type: Positional\n";
8562 theDi << " Intensity: " << aLight->Intensity() << "\n";
8563 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
8564 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
8565 if (!aLightPos.IsNull())
8567 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
8568 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
8569 aLightPos->Attenuation (anAtten[0], anAtten[1]);
8570 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
8576 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
8577 theDi << " Type: Spot\n";
8578 theDi << " Intensity: " << aLight->Intensity() << "\n";
8579 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
8580 if (!aLightSpot.IsNull())
8582 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
8583 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
8584 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
8585 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
8586 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
8587 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
8588 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
8589 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
8595 theDi << " Type: UNKNOWN\n";
8599 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
8603 Handle(V3d_Light) aLightNew;
8604 Handle(V3d_Light) aLightOld;
8605 Standard_Boolean isGlobal = Standard_True;
8606 Standard_Boolean toCreate = Standard_False;
8607 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
8609 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
8610 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
8611 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
8612 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
8613 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
8615 TCollection_AsciiString aName, aValue;
8616 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
8617 TCollection_AsciiString anArgCase (anArg);
8618 anArgCase.UpperCase();
8619 if (anArgCase.IsEqual ("NEW")
8620 || anArgCase.IsEqual ("ADD")
8621 || anArgCase.IsEqual ("CREATE"))
8623 toCreate = Standard_True;
8625 else if (anArgCase.IsEqual ("GLOB")
8626 || anArgCase.IsEqual ("GLOBAL"))
8628 isGlobal = Standard_True;
8630 else if (anArgCase.IsEqual ("LOC")
8631 || anArgCase.IsEqual ("LOCAL"))
8633 isGlobal = Standard_False;
8635 else if (anArgCase.IsEqual ("DEF")
8636 || anArgCase.IsEqual ("DEFAULTS"))
8638 toCreate = Standard_False;
8639 aViewer->SetDefaultLights();
8641 else if (anArgCase.IsEqual ("CLR")
8642 || anArgCase.IsEqual ("CLEAR"))
8644 toCreate = Standard_False;
8645 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
8647 Handle(V3d_Light) aLight = aLightIter.Value();
8648 aViewer->DelLight (aLight);
8649 aLightIter = aView->ActiveLightIterator();
8652 else if (anArgCase.IsEqual ("AMB")
8653 || anArgCase.IsEqual ("AMBIENT")
8654 || anArgCase.IsEqual ("AMBLIGHT"))
8656 addLight (aLightNew, isGlobal);
8659 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8662 toCreate = Standard_False;
8663 aLightNew = new V3d_AmbientLight (aViewer);
8665 else if (anArgCase.IsEqual ("DIRECTIONAL")
8666 || anArgCase.IsEqual ("DIRLIGHT"))
8668 addLight (aLightNew, isGlobal);
8671 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8674 toCreate = Standard_False;
8675 aLightNew = new V3d_DirectionalLight (aViewer);
8677 else if (anArgCase.IsEqual ("SPOT")
8678 || anArgCase.IsEqual ("SPOTLIGHT"))
8680 addLight (aLightNew, isGlobal);
8683 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8686 toCreate = Standard_False;
8687 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
8689 else if (anArgCase.IsEqual ("POSLIGHT")
8690 || anArgCase.IsEqual ("POSITIONAL"))
8692 addLight (aLightNew, isGlobal);
8695 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8698 toCreate = Standard_False;
8699 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
8701 else if (anArgCase.IsEqual ("CHANGE"))
8703 addLight (aLightNew, isGlobal);
8704 aLightNew.Nullify();
8705 if (++anArgIt >= theArgsNb)
8707 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8711 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
8712 Standard_Integer aLightIt = 0;
8713 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
8715 if (aLightIt == aLightId)
8717 aLightOld = aLightIter.Value();
8722 if (aLightOld.IsNull())
8724 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
8728 else if (anArgCase.IsEqual ("DEL")
8729 || anArgCase.IsEqual ("DELETE"))
8731 Handle(V3d_Light) aLightDel;
8732 if (++anArgIt >= theArgsNb)
8734 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8738 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
8739 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
8740 Standard_Integer aLightIt = 0;
8741 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
8743 aLightDel = aLightIter.Value();
8744 if (aLightIt == aLightDelId)
8749 if (!aLightDel.IsNull())
8751 aViewer->DelLight (aLightDel);
8754 else if (anArgCase.IsEqual ("COLOR")
8755 || anArgCase.IsEqual ("COLOUR"))
8757 if (++anArgIt >= theArgsNb)
8759 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8763 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
8764 anArgNext.UpperCase();
8765 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
8766 if (!aLightCurr.IsNull())
8768 aLightCurr->SetColor (aColor);
8771 else if (anArgCase.IsEqual ("POS")
8772 || anArgCase.IsEqual ("POSITION"))
8774 if ((anArgIt + 3) >= theArgsNb)
8776 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8780 anXYZ[0] = Atof (theArgVec[++anArgIt]);
8781 anXYZ[1] = Atof (theArgVec[++anArgIt]);
8782 anXYZ[2] = Atof (theArgVec[++anArgIt]);
8783 if (!aLightDir.IsNull())
8785 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
8787 else if (!aLightPos.IsNull())
8789 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
8791 else if (!aLightSpot.IsNull())
8793 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
8797 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8801 else if (anArgCase.IsEqual ("DIR")
8802 || anArgCase.IsEqual ("DIRECTION"))
8804 if ((anArgIt + 3) >= theArgsNb)
8806 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8810 anXYZ[0] = Atof (theArgVec[++anArgIt]);
8811 anXYZ[1] = Atof (theArgVec[++anArgIt]);
8812 anXYZ[2] = Atof (theArgVec[++anArgIt]);
8813 if (!aLightDir.IsNull())
8815 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
8817 else if (!aLightSpot.IsNull())
8819 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
8823 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8827 else if (anArgCase.IsEqual ("SM")
8828 || anArgCase.IsEqual ("SMOOTHNESS"))
8830 if (++anArgIt >= theArgsNb)
8832 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8836 Standard_Real aSmoothness = Atof (theArgVec[anArgIt]);
8838 if (fabs (aSmoothness) < Precision::Confusion())
8840 aLightCurr->SetIntensity (1.f);
8842 else if (fabs (aLightCurr->Smoothness()) < Precision::Confusion())
8844 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
8848 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
8849 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
8852 if (!aLightPos.IsNull())
8854 aLightPos->SetSmoothRadius (aSmoothness);
8856 else if (!aLightDir.IsNull())
8858 aLightDir->SetSmoothAngle (aSmoothness);
8861 else if (anArgCase.IsEqual ("INT")
8862 || anArgCase.IsEqual ("INTENSITY"))
8864 if (++anArgIt >= theArgsNb)
8866 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8870 Standard_Real aIntensity = Atof (theArgVec[anArgIt]);
8872 if (!aLightCurr.IsNull())
8874 aLightCurr->SetIntensity (aIntensity);
8877 else if (anArgCase.IsEqual ("ANG")
8878 || anArgCase.IsEqual ("ANGLE"))
8880 if (++anArgIt >= theArgsNb)
8882 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8886 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
8888 if (!aLightSpot.IsNull())
8890 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
8893 else if (anArgCase.IsEqual ("CONSTATTEN")
8894 || anArgCase.IsEqual ("CONSTATTENUATION"))
8896 if (++anArgIt >= theArgsNb)
8898 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8902 if (!aLightPos.IsNull())
8904 aLightPos->Attenuation (anAtten[0], anAtten[1]);
8905 anAtten[0] = Atof (theArgVec[anArgIt]);
8906 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
8908 else if (!aLightSpot.IsNull())
8910 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
8911 anAtten[0] = Atof (theArgVec[anArgIt]);
8912 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
8916 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8920 else if (anArgCase.IsEqual ("LINATTEN")
8921 || anArgCase.IsEqual ("LINEARATTEN")
8922 || anArgCase.IsEqual ("LINEARATTENUATION"))
8924 if (++anArgIt >= theArgsNb)
8926 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8930 if (!aLightPos.IsNull())
8932 aLightPos->Attenuation (anAtten[0], anAtten[1]);
8933 anAtten[1] = Atof (theArgVec[anArgIt]);
8934 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
8936 else if (!aLightSpot.IsNull())
8938 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
8939 anAtten[1] = Atof (theArgVec[anArgIt]);
8940 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
8944 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8948 else if (anArgCase.IsEqual ("EXP")
8949 || anArgCase.IsEqual ("EXPONENT")
8950 || anArgCase.IsEqual ("SPOTEXP")
8951 || anArgCase.IsEqual ("SPOTEXPONENT"))
8953 if (++anArgIt >= theArgsNb)
8955 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8959 if (!aLightSpot.IsNull())
8961 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
8965 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8969 else if (anArgCase.IsEqual ("HEAD")
8970 || anArgCase.IsEqual ("HEADLIGHT"))
8972 if (++anArgIt >= theArgsNb)
8974 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8978 if (aLightAmb.IsNull()
8979 && !aLightCurr.IsNull())
8981 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
8985 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8991 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
8995 addLight (aLightNew, isGlobal);
8996 aViewer->UpdateLights();
9001 //=======================================================================
9002 //function : VRenderParams
9003 //purpose : Enables/disables rendering features
9004 //=======================================================================
9006 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
9007 Standard_Integer theArgNb,
9008 const char** theArgVec)
9010 Handle(V3d_View) aView = ViewerTest::CurrentView();
9013 std::cerr << "Error: no active viewer!\n";
9017 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
9018 TCollection_AsciiString aCmdName (theArgVec[0]);
9019 aCmdName.LowerCase();
9020 if (aCmdName == "vraytrace")
9024 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
9027 else if (theArgNb == 2)
9029 TCollection_AsciiString aValue (theArgVec[1]);
9034 aParams.Method = Graphic3d_RM_RAYTRACING;
9038 else if (aValue == "off"
9041 aParams.Method = Graphic3d_RM_RASTERIZATION;
9047 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
9053 std::cout << "Error: wrong number of arguments\n";
9060 theDI << "renderMode: ";
9061 switch (aParams.Method)
9063 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
9064 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
9067 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
9068 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
9069 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
9070 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
9071 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
9072 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
9073 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
9074 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
9075 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
9076 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
9077 theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
9078 theDI << "shadingModel: ";
9079 switch (aView->ShadingModel())
9081 case V3d_COLOR: theDI << "color"; break;
9082 case V3d_FLAT: theDI << "flat"; break;
9083 case V3d_GOURAUD: theDI << "gouraud"; break;
9084 case V3d_PHONG: theDI << "phong"; break;
9090 Standard_Boolean toPrint = Standard_False;
9091 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
9092 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
9094 Standard_CString anArg (theArgVec[anArgIter]);
9095 TCollection_AsciiString aFlag (anArg);
9097 if (anUpdateTool.parseRedrawMode (aFlag))
9101 else if (aFlag == "-echo"
9102 || aFlag == "-print")
9104 toPrint = Standard_True;
9105 anUpdateTool.Invalidate();
9107 else if (aFlag == "-mode"
9108 || aFlag == "-rendermode"
9109 || aFlag == "-render_mode")
9113 switch (aParams.Method)
9115 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
9116 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
9122 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9126 else if (aFlag == "-ray"
9127 || aFlag == "-raytrace")
9131 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
9135 aParams.Method = Graphic3d_RM_RAYTRACING;
9137 else if (aFlag == "-rast"
9138 || aFlag == "-raster"
9139 || aFlag == "-rasterization")
9143 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
9147 aParams.Method = Graphic3d_RM_RASTERIZATION;
9149 else if (aFlag == "-msaa")
9153 theDI << aParams.NbMsaaSamples << " ";
9156 else if (++anArgIter >= theArgNb)
9158 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9162 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
9165 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
9170 aParams.NbMsaaSamples = aNbSamples;
9173 else if (aFlag == "-raydepth"
9174 || aFlag == "-ray_depth")
9178 theDI << aParams.RaytracingDepth << " ";
9181 else if (++anArgIter >= theArgNb)
9183 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9187 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
9189 // We allow RaytracingDepth be more than 10 in case of GI enabled
9190 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
9192 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
9197 aParams.RaytracingDepth = aDepth;
9200 else if (aFlag == "-shad"
9201 || aFlag == "-shadows")
9205 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
9209 Standard_Boolean toEnable = Standard_True;
9210 if (++anArgIter < theArgNb
9211 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9215 aParams.IsShadowEnabled = toEnable;
9217 else if (aFlag == "-refl"
9218 || aFlag == "-reflections")
9222 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
9226 Standard_Boolean toEnable = Standard_True;
9227 if (++anArgIter < theArgNb
9228 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9232 aParams.IsReflectionEnabled = toEnable;
9234 else if (aFlag == "-fsaa")
9238 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
9242 Standard_Boolean toEnable = Standard_True;
9243 if (++anArgIter < theArgNb
9244 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9248 aParams.IsAntialiasingEnabled = toEnable;
9250 else if (aFlag == "-gleam")
9254 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
9258 Standard_Boolean toEnable = Standard_True;
9259 if (++anArgIter < theArgNb
9260 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9264 aParams.IsTransparentShadowEnabled = toEnable;
9266 else if (aFlag == "-gi")
9270 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
9274 Standard_Boolean toEnable = Standard_True;
9275 if (++anArgIter < theArgNb
9276 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9280 aParams.IsGlobalIlluminationEnabled = toEnable;
9283 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
9286 else if (aFlag == "-blockedrng"
9287 || aFlag == "-brng")
9291 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
9295 Standard_Boolean toEnable = Standard_True;
9296 if (++anArgIter < theArgNb
9297 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9301 aParams.CoherentPathTracingMode = toEnable;
9303 else if (aFlag == "-iss")
9307 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
9311 Standard_Boolean toEnable = Standard_True;
9312 if (++anArgIter < theArgNb
9313 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9317 aParams.AdaptiveScreenSampling = toEnable;
9319 else if (aFlag == "-issd")
9323 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
9327 Standard_Boolean toEnable = Standard_True;
9328 if (++anArgIter < theArgNb
9329 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9333 aParams.ShowSamplingTiles = toEnable;
9335 else if (aFlag == "-env")
9339 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
9343 Standard_Boolean toEnable = Standard_True;
9344 if (++anArgIter < theArgNb
9345 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9349 aParams.UseEnvironmentMapBackground = toEnable;
9351 else if (aFlag == "-twoside")
9355 theDI << (aParams.TwoSidedBsdfModels ? "on" : "off") << " ";
9359 Standard_Boolean toEnable = Standard_True;
9360 if (++anArgIter < theArgNb
9361 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9365 aParams.TwoSidedBsdfModels = toEnable;
9367 else if (aFlag == "-shademodel"
9368 || aFlag == "-shadingmodel"
9369 || aFlag == "-shading")
9373 switch (aView->ShadingModel())
9375 case V3d_COLOR: theDI << "color "; break;
9376 case V3d_FLAT: theDI << "flat "; break;
9377 case V3d_GOURAUD: theDI << "gouraud "; break;
9378 case V3d_PHONG: theDI << "phong "; break;
9383 if (++anArgIter >= theArgNb)
9385 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9388 TCollection_AsciiString aMode (theArgVec[anArgIter]);
9390 if (aMode == "color"
9393 aView->SetShadingModel (V3d_COLOR);
9395 else if (aMode == "flat"
9396 || aMode == "facet")
9398 aView->SetShadingModel (V3d_FLAT);
9400 else if (aMode == "gouraud"
9401 || aMode == "vertex"
9404 aView->SetShadingModel (V3d_GOURAUD);
9406 else if (aMode == "phong"
9407 || aMode == "fragment"
9409 || aMode == "pixel")
9411 aView->SetShadingModel (V3d_PHONG);
9415 std::cout << "Error: unknown shading model '" << aMode << "'\n";
9419 else if (aFlag == "-resolution")
9421 if (++anArgIter >= theArgNb)
9423 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
9427 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
9428 if (aResolution.IsIntegerValue())
9430 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
9434 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
9438 else if (aFlag == "-rebuildglsl"
9439 || aFlag == "-rebuild")
9443 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
9447 Standard_Boolean toEnable = Standard_True;
9448 if (++anArgIter < theArgNb
9449 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
9453 aParams.RebuildRayTracingShaders = toEnable;
9457 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
9465 //=======================================================================
9466 //function : VProgressiveMode
9468 //=======================================================================
9470 static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
9471 Standard_Integer /*theNbArgs*/,
9472 const char** /*theArgs*/)
9474 Handle(V3d_View) aView = ViewerTest::CurrentView();
9477 std::cerr << "Error: no active viewer!\n";
9481 std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
9487 Standard_Boolean toExit = Standard_False;
9490 while (PeekMessageW (&aMsg, NULL, 0, 0, PM_REMOVE))
9492 if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
9494 toExit = Standard_True;
9497 TranslateMessage (&aMsg);
9498 DispatchMessageW (&aMsg);
9511 //=======================================================================
9512 //function : VFrustumCulling
9513 //purpose : enables/disables view volume's culling.
9514 //=======================================================================
9515 static int VFrustumCulling (Draw_Interpretor& theDI,
9516 Standard_Integer theArgNb,
9517 const char** theArgVec)
9519 Handle(V3d_View) aView = ViewerTest::CurrentView();
9522 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
9528 theDI << (aView->IsCullingEnabled() ? "on" : "off");
9531 else if (theArgNb != 2)
9533 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
9537 TCollection_AsciiString aModeStr (theArgVec[1]);
9538 aModeStr.LowerCase();
9539 Standard_Boolean toEnable = 0;
9540 if (aModeStr == "on")
9544 else if (aModeStr == "off")
9550 toEnable = Draw::Atoi (theArgVec[1]) != 0;
9553 aView->SetFrustumCulling (toEnable);
9558 //=======================================================================
9559 //function : VHighlightSelected
9561 //=======================================================================
9562 static int VHighlightSelected (Draw_Interpretor& theDI,
9563 Standard_Integer theArgNb,
9564 const char** theArgVec)
9566 if (ViewerTest::GetAISContext().IsNull())
9568 std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n";
9572 const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9576 theDI << (aContext->ToHilightSelected() ? "on" : "off");
9582 std::cout << theArgVec[0] << " error : wrong number of parameters."
9583 << "Type 'help" << theArgVec[0] << "' for more information.";
9588 TCollection_AsciiString aMode (theArgVec[1]);
9590 Standard_Boolean toEnable = Standard_False;
9591 if (aMode.IsEqual ("on"))
9593 toEnable = Standard_True;
9595 else if (aMode.IsEqual ("off"))
9597 toEnable = Standard_False;
9601 toEnable = Draw::Atoi (theArgVec[1]) != 0;
9604 if (toEnable != aContext->ToHilightSelected())
9606 aContext->SetToHilightSelected (toEnable);
9608 // Move cursor to null position and back to process updating of detection
9609 // and highlighting of selected object immediatly.
9610 Standard_Integer aPixX = 0;
9611 Standard_Integer aPixY = 0;
9612 const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager();
9614 anEventManager->GetCurrentPosition (aPixX, aPixY);
9615 anEventManager->MoveTo (0, 0);
9616 anEventManager->MoveTo (aPixX, aPixY);
9622 //=======================================================================
9623 //function : VXRotate
9625 //=======================================================================
9626 static Standard_Integer VXRotate (Draw_Interpretor& di,
9627 Standard_Integer argc,
9630 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
9631 if (aContext.IsNull())
9633 di << argv[0] << "ERROR : use 'vinit' command before \n";
9639 di << "ERROR : Usage : " << argv[0] << " name angle\n";
9643 TCollection_AsciiString aName (argv[1]);
9644 Standard_Real anAngle = Draw::Atof (argv[2]);
9647 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
9648 Handle(AIS_InteractiveObject) anIObj;
9649 if (!aMap.IsBound2 (aName) )
9651 di << "Use 'vdisplay' before\n";
9656 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
9659 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
9660 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
9662 aContext->SetLocation (anIObj, aTransform);
9663 aContext->UpdateCurrentViewer();
9669 //===============================================================================================
9670 //class : ViewerTest_AISManipulator
9671 //purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances
9672 //===============================================================================================
9673 DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
9675 class ViewerTest_AISManipulator : public AIS_Manipulator
9679 ViewerTest_AISManipulator() : AIS_Manipulator()
9681 GetMapOfAISManipulators().Add (this);
9684 virtual ~ViewerTest_AISManipulator()
9686 GetMapOfAISManipulators().Remove (this);
9689 DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
9692 IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
9693 IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
9695 //===============================================================================================
9696 //function : VManipulator
9698 //===============================================================================================
9699 static int VManipulator (Draw_Interpretor& theDi,
9700 Standard_Integer theArgsNb,
9701 const char** theArgVec)
9703 Handle(V3d_View) aView = ViewerTest::CurrentView();
9704 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
9705 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
9707 || aViewer.IsNull())
9709 std::cerr << "No active viewer!\n";
9713 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
9714 Standard_Integer anArgIter = 1;
9715 for (; anArgIter < theArgsNb; ++anArgIter)
9717 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
9720 ViewerTest_CmdParser aCmd;
9721 aCmd.AddDescription ("Manages manipulator for interactive objects:");
9722 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
9723 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
9724 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
9725 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
9726 aCmd.AddOption ("detach", "... - detach manipulator");
9728 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
9729 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
9730 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
9732 aCmd.AddOption ("move", "... x y z - move object");
9733 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
9734 aCmd.AddOption ("scale", "... factor - scale object");
9736 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
9737 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
9738 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
9739 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
9740 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
9741 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
9742 aCmd.AddOption ("size", "... size - set size of manipulator");
9743 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
9745 aCmd.Parse (theArgsNb, theArgVec);
9747 if (aCmd.HasOption ("help"))
9749 theDi.PrintHelp (theArgVec[0]);
9753 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
9755 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
9757 if (aName.IsEmpty())
9759 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
9763 // ----------------------------------
9764 // detach existing manipulator object
9765 // ----------------------------------
9767 if (aCmd.HasOption ("detach"))
9769 if (!aMapAIS.IsBound2 (aName))
9771 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
9775 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
9776 if (aManipulator.IsNull())
9778 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
9782 aManipulator->Detach();
9783 aMapAIS.UnBind2 (aName);
9784 ViewerTest::GetAISContext()->Remove (aManipulator);
9789 // -----------------------------------------------
9790 // find or create manipulator if it does not exist
9791 // -----------------------------------------------
9793 Handle(AIS_Manipulator) aManipulator;
9794 if (!aMapAIS.IsBound2 (aName))
9796 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
9798 aManipulator = new ViewerTest_AISManipulator();
9799 aMapAIS.Bind (aManipulator, aName);
9803 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
9804 if (aManipulator.IsNull())
9806 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
9811 // -----------------------------------------
9812 // change properties of manipulator instance
9813 // -----------------------------------------
9815 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
9817 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
9819 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
9821 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
9823 if (aCmd.HasOption ("followRotation", 1, Standard_True))
9825 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
9827 if (aCmd.HasOption ("gap", 1, Standard_True))
9829 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
9831 if (aCmd.HasOption ("part", 3, Standard_True))
9833 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
9834 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
9835 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
9836 if (aMode < 1 || aMode > 3)
9838 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 3].\n";
9842 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
9844 if (aCmd.HasOption ("pos", 3, Standard_True))
9846 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
9847 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
9848 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
9850 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
9852 if (aCmd.HasOption ("size", 1, Standard_True))
9854 aManipulator->SetSize (aCmd.ArgFloat ("size"));
9856 if (aCmd.HasOption ("zoomable", 1, Standard_True))
9858 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
9860 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
9862 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
9863 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
9867 // ---------------------------------------------------
9868 // attach, detach or access manipulator from an object
9869 // ---------------------------------------------------
9871 if (aCmd.HasOption ("attach"))
9873 // Find an object and attach manipulator to it
9874 if (!aCmd.HasOption ("attach", 1, Standard_True))
9879 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
9880 if (!aMapAIS.IsBound2 (anObjName))
9882 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
9886 Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (aMapAIS.Find2 (anObjName));
9887 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
9888 for (; anIt.More(); anIt.Next())
9890 if (anIt.Value()->IsAttached()
9891 && anIt.Value()->Object() == anObject)
9893 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
9898 AIS_Manipulator::OptionsForAttach anOptions;
9899 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
9901 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
9903 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
9905 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
9907 if (aCmd.HasOption ("enableModes", 1, Standard_True))
9909 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
9912 aManipulator->Attach (anObject, anOptions);
9915 // --------------------------------------
9916 // apply transformation using manipulator
9917 // --------------------------------------
9919 if (aCmd.HasOption ("startTransform", 2, Standard_True))
9921 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
9923 if (aCmd.HasOption ("transform", 2, Standard_True))
9925 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
9927 if (aCmd.HasOption ("stopTransform"))
9929 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
9931 aManipulator->StopTransform (toApply);
9935 if (aCmd.HasOption ("move", 3, Standard_True))
9937 aT.SetTranslationPart (aCmd.ArgVec ("move"));
9939 if (aCmd.HasOption ("rotate", 7, Standard_True))
9941 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
9943 if (aCmd.HasOption ("scale", 1))
9945 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
9948 if (aT.Form() != gp_Identity)
9950 aManipulator->Transform (aT);
9953 ViewerTest::GetAISContext()->Redisplay (aManipulator);
9958 //===============================================================================================
9959 //function : VSelectionProperties
9961 //===============================================================================================
9962 static int VSelectionProperties (Draw_Interpretor& theDi,
9963 Standard_Integer theArgsNb,
9964 const char** theArgVec)
9966 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
9969 std::cerr << "No active viewer!\n";
9973 Standard_Boolean toPrint = theArgsNb == 1;
9974 Standard_Boolean toRedraw = Standard_False;
9975 Standard_Integer anArgIter = 1;
9976 Prs3d_TypeOfHighlight aType = Prs3d_TypeOfHighlight_None;
9977 if (anArgIter < theArgsNb)
9979 TCollection_AsciiString anArgFirst (theArgVec[anArgIter]);
9980 anArgFirst.LowerCase();
9982 if (anArgFirst == "dynhighlight"
9983 || anArgFirst == "dynhilight"
9984 || anArgFirst == "dynamichighlight"
9985 || anArgFirst == "dynamichilight")
9987 aType = Prs3d_TypeOfHighlight_Dynamic;
9989 else if (anArgFirst == "localdynhighlight"
9990 || anArgFirst == "localdynhilight"
9991 || anArgFirst == "localdynamichighlight"
9992 || anArgFirst == "localdynamichilight")
9994 aType = Prs3d_TypeOfHighlight_LocalDynamic;
9996 else if (anArgFirst == "selhighlight"
9997 || anArgFirst == "selhilight"
9998 || anArgFirst == "selectedhighlight"
9999 || anArgFirst == "selectedhilight")
10001 aType = Prs3d_TypeOfHighlight_Selected;
10003 else if (anArgFirst == "localselhighlight"
10004 || anArgFirst == "localselhilight"
10005 || anArgFirst == "localselectedhighlight"
10006 || anArgFirst == "localselectedhilight")
10008 aType = Prs3d_TypeOfHighlight_LocalSelected;
10015 for (; anArgIter < theArgsNb; ++anArgIter)
10017 TCollection_AsciiString anArg (theArgVec[anArgIter]);
10019 if (anArg == "-help")
10021 theDi.PrintHelp (theArgVec[0]);
10024 else if (anArg == "-print")
10026 toPrint = Standard_True;
10028 else if (anArg == "-autoactivate")
10030 Standard_Boolean toEnable = Standard_True;
10031 if (anArgIter + 1 < theArgsNb
10032 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable))
10036 aCtx->SetAutoActivateSelection (toEnable);
10038 else if (anArg == "-pixtol"
10039 && anArgIter + 1 < theArgsNb)
10041 aCtx->SetPixelTolerance (Draw::Atoi (theArgVec[++anArgIter]));
10043 else if ((anArg == "-mode"
10044 || anArg == "-dispmode")
10045 && anArgIter + 1 < theArgsNb)
10047 if (aType == Prs3d_TypeOfHighlight_None)
10049 std::cout << "Syntax error: type of highlighting is undefined\n";
10053 const Standard_Integer aDispMode = Draw::Atoi (theArgVec[++anArgIter]);
10054 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
10055 aStyle->SetDisplayMode (aDispMode);
10056 toRedraw = Standard_True;
10058 else if (anArg == "-layer"
10059 && anArgIter + 1 < theArgsNb)
10061 if (aType == Prs3d_TypeOfHighlight_None)
10063 std::cout << "Syntax error: type of highlighting is undefined\n";
10067 const Standard_Integer aNewLayer = Draw::Atoi (theArgVec[++anArgIter]);
10068 if (aNewLayer != Graphic3d_ZLayerId_UNKNOWN)
10070 TColStd_SequenceOfInteger aLayers;
10071 aCtx->CurrentViewer()->GetAllZLayers (aLayers);
10072 if (std::find (aLayers.begin(), aLayers.end(), aNewLayer) == aLayers.end())
10074 std::cout << "Syntax error: Layer " << aNewLayer << " is undefined\n";
10079 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
10080 aStyle->SetZLayer (aNewLayer);
10081 toRedraw = Standard_True;
10083 else if (anArg == "-hicolor"
10084 || anArg == "-selcolor"
10085 || anArg == "-color")
10087 if (anArg.StartsWith ("-hi"))
10089 aType = Prs3d_TypeOfHighlight_Dynamic;
10091 else if (anArg.StartsWith ("-sel"))
10093 aType = Prs3d_TypeOfHighlight_Selected;
10095 else if (aType == Prs3d_TypeOfHighlight_None)
10097 std::cout << "Syntax error: type of highlighting is undefined\n";
10101 Quantity_Color aColor;
10102 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIter - 1,
10103 theArgVec + anArgIter + 1,
10105 if (aNbParsed == 0)
10107 std::cout << "Syntax error: need more arguments.\n";
10110 anArgIter += aNbParsed;
10112 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
10113 aStyle->SetColor (aColor);
10114 toRedraw = Standard_True;
10116 else if ((anArg == "-transp"
10117 || anArg == "-transparency"
10118 || anArg == "-hitransp"
10119 || anArg == "-seltransp"
10120 || anArg == "-hitransplocal"
10121 || anArg == "-seltransplocal")
10122 && anArgIter + 1 < theArgsNb)
10124 if (anArg.StartsWith ("-hi"))
10126 aType = Prs3d_TypeOfHighlight_Dynamic;
10128 else if (anArg.StartsWith ("-sel"))
10130 aType = Prs3d_TypeOfHighlight_Selected;
10132 else if (aType == Prs3d_TypeOfHighlight_None)
10134 std::cout << "Syntax error: type of highlighting is undefined\n";
10138 const Standard_Real aTransp = Draw::Atof (theArgVec[++anArgIter]);
10139 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
10140 aStyle->SetTransparency ((Standard_ShortReal )aTransp);
10141 toRedraw = Standard_True;
10143 else if ((anArg == "-mat"
10144 || anArg == "-material")
10145 && anArgIter + 1 < theArgsNb)
10147 if (aType == Prs3d_TypeOfHighlight_None)
10149 std::cout << "Syntax error: type of highlighting is undefined\n";
10153 const Handle(Prs3d_Drawer)& aStyle = aCtx->HighlightStyle (aType);
10154 Graphic3d_NameOfMaterial aMatName = Graphic3d_MaterialAspect::MaterialFromName (theArgVec[anArgIter + 1]);
10155 if (aMatName != Graphic3d_NOM_DEFAULT)
10158 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
10159 *anAspect = *aCtx->DefaultDrawer()->ShadingAspect()->Aspect();
10160 Graphic3d_MaterialAspect aMat (aMatName);
10161 aMat.SetColor (aStyle->Color());
10162 aMat.SetTransparency (aStyle->Transparency());
10163 anAspect->SetFrontMaterial (aMat);
10164 anAspect->SetInteriorColor (aStyle->Color());
10165 aStyle->SetBasicFillAreaAspect (anAspect);
10169 aStyle->SetBasicFillAreaAspect (Handle(Graphic3d_AspectFillArea3d)());
10171 toRedraw = Standard_True;
10175 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
10181 const Handle(Prs3d_Drawer)& aHiStyle = aCtx->HighlightStyle();
10182 const Handle(Prs3d_Drawer)& aSelStyle = aCtx->SelectionStyle();
10183 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
10184 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
10185 theDi << "Selection color : " << Quantity_Color::StringName (aSelStyle->Color().Name()) << "\n";
10186 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aHiStyle->Color().Name()) << "\n";
10187 theDi << "Selection transparency : " << aSelStyle->Transparency() << "\n";
10188 theDi << "Dynamic highlight transparency : " << aHiStyle->Transparency() << "\n";
10189 theDi << "Selection mode : " << aSelStyle->DisplayMode() << "\n";
10190 theDi << "Dynamic highlight mode : " << aHiStyle->DisplayMode() << "\n";
10191 theDi << "Selection layer : " << aSelStyle->ZLayer() << "\n";
10192 theDi << "Dynamic layer : " << aHiStyle->ZLayer() << "\n";
10195 if (aCtx->NbSelected() != 0 && toRedraw)
10197 aCtx->HilightSelected (Standard_True);
10203 //===============================================================================================
10204 //function : VDumpSelectionImage
10206 //===============================================================================================
10207 static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
10208 Standard_Integer theArgsNb,
10209 const char** theArgVec)
10213 std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
10217 const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
10218 if (aContext.IsNull())
10220 std::cout << "Error: no active view.\n";
10224 TCollection_AsciiString aFile;
10225 StdSelect_TypeOfSelectionImage aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
10226 Image_PixMap::ImgFormat anImgFormat = Image_PixMap::ImgBGR;
10227 Standard_Integer aPickedIndex = 1;
10228 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
10230 TCollection_AsciiString aParam (theArgVec[anArgIter]);
10231 aParam.LowerCase();
10232 if (aParam == "-type")
10234 if (++anArgIter >= theArgsNb)
10236 std::cout << "Syntax error: wrong number parameters of flag '-depth'.\n";
10240 TCollection_AsciiString aValue (theArgVec[anArgIter]);
10241 aValue.LowerCase();
10242 if (aValue == "depth"
10243 || aValue == "normdepth"
10244 || aValue == "normalizeddepth")
10246 aType = StdSelect_TypeOfSelectionImage_NormalizedDepth;
10247 anImgFormat = Image_PixMap::ImgGrayF;
10249 if (aValue == "depthinverted"
10250 || aValue == "normdepthinverted"
10251 || aValue == "normalizeddepthinverted"
10252 || aValue == "inverted")
10254 aType = StdSelect_TypeOfSelectionImage_NormalizedDepthInverted;
10255 anImgFormat = Image_PixMap::ImgGrayF;
10257 else if (aValue == "unnormdepth"
10258 || aValue == "unnormalizeddepth")
10260 aType = StdSelect_TypeOfSelectionImage_UnnormalizedDepth;
10261 anImgFormat = Image_PixMap::ImgGrayF;
10263 else if (aValue == "objectcolor"
10264 || aValue == "object"
10265 || aValue == "color")
10267 aType = StdSelect_TypeOfSelectionImage_ColoredDetectedObject;
10269 else if (aValue == "entitycolor"
10270 || aValue == "entity")
10272 aType = StdSelect_TypeOfSelectionImage_ColoredEntity;
10274 else if (aValue == "ownercolor"
10275 || aValue == "owner")
10277 aType = StdSelect_TypeOfSelectionImage_ColoredOwner;
10279 else if (aValue == "selectionmodecolor"
10280 || aValue == "selectionmode"
10281 || aValue == "selmodecolor"
10282 || aValue == "selmode")
10284 aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
10287 else if (aParam == "-picked"
10288 || aParam == "-pickeddepth"
10289 || aParam == "-pickedindex")
10291 if (++anArgIter >= theArgsNb)
10293 std::cout << "Syntax error: wrong number parameters at '" << aParam << "'.\n";
10297 aPickedIndex = Draw::Atoi (theArgVec[anArgIter]);
10299 else if (aFile.IsEmpty())
10301 aFile = theArgVec[anArgIter];
10305 std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'.\n";
10309 if (aFile.IsEmpty())
10311 std::cout << "Syntax error: image file name is missing.\n";
10315 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
10316 Standard_Integer aWidth = 0, aHeight = 0;
10317 aView->Window()->Size (aWidth, aHeight);
10319 Image_AlienPixMap aPixMap;
10320 if (!aPixMap.InitZero (anImgFormat, aWidth, aHeight))
10322 std::cout << "Error: can't allocate image.\n";
10325 if (!aContext->MainSelector()->ToPixMap (aPixMap, aView, aType, aPickedIndex))
10327 std::cout << "Error: can't generate selection image.\n";
10330 if (!aPixMap.Save (aFile))
10332 std::cout << "Error: can't save selection image.\n";
10338 //=======================================================================
10339 //function : ViewerCommands
10341 //=======================================================================
10343 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
10346 const char *group = "ZeViewer";
10347 theCommands.Add("vinit",
10348 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
10349 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
10351 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
10353 " - Creates new View window with specified name view_name.\n"
10354 "By default the new view is created in the viewer and in"
10355 " graphic driver shared with active view.\n"
10356 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
10357 "If driverName isn't specified the driver will be shared with active view.\n"
10358 "If viewerName isn't specified the viewer will be shared with active view.\n"
10359 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
10360 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
10361 "is used in creation of graphic driver\n"
10363 " - l, t: pixel position of left top corner of the window\n"
10364 " - w,h: width and heigth of window respectively.\n"
10365 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
10366 __FILE__,VInit,group);
10367 theCommands.Add("vclose" ,
10368 "[view_id [keep_context=0|1]]\n"
10369 "or vclose ALL - to remove all created views\n"
10370 " - removes view(viewer window) defined by its view_id.\n"
10371 " - keep_context: by default 0; if 1 and the last view is deleted"
10372 " the current context is not removed.",
10373 __FILE__,VClose,group);
10374 theCommands.Add("vactivate" ,
10376 " - activates view(viewer window) defined by its view_id",
10377 __FILE__,VActivate,group);
10378 theCommands.Add("vviewlist",
10379 "vviewlist [format={tree, long}]"
10380 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
10381 " - format: format of result output, if tree the output is a tree view;"
10382 "otherwise it's a list of full view names. By default format = tree",
10383 __FILE__,VViewList,group);
10384 theCommands.Add("vhelp" ,
10385 "vhelp : display help on the viewer commands",
10386 __FILE__,VHelp,group);
10387 theCommands.Add("vtop" ,
10388 "vtop or <T> : Top view. Orientation +X+Y" ,
10389 __FILE__,VTop,group);
10390 theCommands.Add("vbottom" ,
10391 "vbottom : Bottom view. Orientation +X-Y" ,
10392 __FILE__,VBottom,group);
10393 theCommands.Add("vleft" ,
10394 "vleft : Left view. Orientation -Y+Z" ,
10395 __FILE__,VLeft,group);
10396 theCommands.Add("vright" ,
10397 "vright : Right view. Orientation +Y+Z" ,
10398 __FILE__,VRight,group);
10399 theCommands.Add("vaxo" ,
10400 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
10401 __FILE__,VAxo,group);
10402 theCommands.Add("vfront" ,
10403 "vfront : Front view. Orientation +X+Z" ,
10404 __FILE__,VFront,group);
10405 theCommands.Add("vback" ,
10406 "vback : Back view. Orientation -X+Z" ,
10407 __FILE__,VBack,group);
10408 theCommands.Add("vpick" ,
10409 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
10411 theCommands.Add("vfit",
10412 "vfit or <F> [-selected] [-noupdate]"
10413 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
10414 __FILE__,VFit,group);
10415 theCommands.Add ("vfitarea",
10416 "vfitarea x1 y1 x2 y2"
10417 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
10418 "\n\t\t: Fit view to show area located between two points"
10419 "\n\t\t: given in world 2D or 3D corrdinates.",
10420 __FILE__, VFitArea, group);
10421 theCommands.Add ("vzfit", "vzfit [scale]\n"
10422 " Matches Z near, Z far view volume planes to the displayed objects.\n"
10423 " \"scale\" - specifies factor to scale computed z range.\n",
10424 __FILE__, VZFit, group);
10425 theCommands.Add("vrepaint",
10426 "vrepaint : vrepaint, force redraw",
10427 __FILE__,VRepaint,group);
10428 theCommands.Add("vclear",
10430 "\n\t\t: remove all the object from the viewer",
10431 __FILE__,VClear,group);
10432 theCommands.Add("vsetbg",
10433 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
10434 __FILE__,VSetBg,group);
10435 theCommands.Add("vsetbgmode",
10436 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
10437 __FILE__,VSetBgMode,group);
10438 theCommands.Add("vsetgradientbg",
10439 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
10440 __FILE__,VSetGradientBg,group);
10441 theCommands.Add("vsetgrbgmode",
10442 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
10443 __FILE__,VSetGradientBgMode,group);
10444 theCommands.Add("vsetcolorbg",
10445 "vsetcolorbg : vsetcolorbg r g b : Set background color",
10446 __FILE__,VSetColorBg,group);
10447 theCommands.Add("vsetdefaultbg",
10448 "vsetdefaultbg r g b\n"
10449 "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode"
10450 "\n\t\t: Set default viewer background fill color (flat/gradient).",
10451 __FILE__,VSetDefaultBg,group);
10452 theCommands.Add("vscale",
10453 "vscale : vscale X Y Z",
10454 __FILE__,VScale,group);
10455 theCommands.Add("vzbufftrihedron",
10456 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
10457 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
10458 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
10459 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
10460 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
10461 "\n\t\t: Displays a trihedron",
10462 __FILE__,VZBuffTrihedron,group);
10463 theCommands.Add("vrotate",
10464 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
10465 "\n : Option -mouseStart starts rotation according to the mouse position"
10466 "\n : Option -mouseMove continues rotation with angle computed"
10467 "\n : from last and new mouse position."
10468 "\n : vrotate AX AY AZ [X Y Z]",
10469 __FILE__,VRotate,group);
10470 theCommands.Add("vzoom",
10471 "vzoom : vzoom coef",
10472 __FILE__,VZoom,group);
10473 theCommands.Add("vpan",
10474 "vpan : vpan dx dy",
10475 __FILE__,VPan,group);
10476 theCommands.Add("vexport",
10477 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
10478 " : exports the view to a vector file of a given format"
10479 " : notice that EMF format requires patched gl2ps",
10480 __FILE__,VExport,group);
10481 theCommands.Add("vcolorscale",
10482 "vcolorscale name [-noupdate|-update] [-demo]"
10483 "\n\t\t: [-range RangeMin=0 RangeMax=1 NbIntervals=10]"
10484 "\n\t\t: [-font HeightFont=20]"
10485 "\n\t\t: [-logarithmic {on|off}=off] [-reversed {on|off}=off]"
10486 "\n\t\t: [-smoothTransition {on|off}=off]"
10487 "\n\t\t: [-hueRange MinAngle=230 MaxAngle=0]"
10488 "\n\t\t: [-colorRange MinColor=BLUE1 MaxColor=RED]"
10489 "\n\t\t: [-textpos {left|right|center|none}=right]"
10490 "\n\t\t: [-labelAtBorder {on|off}=on]"
10491 "\n\t\t: [-colors Color1 Color2 ...] [-color Index Color]"
10492 "\n\t\t: [-labels Label1 Label2 ...] [-label Index Label]"
10493 "\n\t\t: [-freeLabels NbOfLabels Label1 Label2 ...]"
10494 "\n\t\t: [-xy Left=0 Bottom=0]"
10495 "\n\t\t: -demo - displays a color scale with demonstratio values"
10496 "\n\t\t: -colors - set colors for all intervals"
10497 "\n\t\t: -color - set color for specific interval"
10498 "\n\t\t: -textpos - horizontal label position relative to color scale bar"
10499 "\n\t\t: -labelAtBorder - vertical label position relative to color interval;"
10500 "\n\t\t: at border means the value inbetween neighbor intervals,"
10501 "\n\t\t: at center means the center value within current interval"
10502 "\n\t\t: -labels - set labels for all intervals"
10503 "\n\t\t: -freeLabels - same as -labels but does not require"
10504 "\n\t\t: matching the number of intervals"
10505 "\n\t\t: -label - set label for specific interval"
10506 "\n\t\t: -title - set title"
10507 "\n\t\t: -reversed - setup smooth color transition between intervals"
10508 "\n\t\t: -smoothTransition - swap colorscale direction"
10509 "\n\t\t: -hueRange - set hue angles corresponding to minimum and maximum values"
10510 __FILE__, VColorScale, group);
10511 theCommands.Add("vgraduatedtrihedron",
10512 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
10513 "\t[-namefont Name] [-valuesfont Name]\n"
10514 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
10515 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
10516 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
10517 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
10518 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
10519 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
10520 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
10521 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
10522 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
10523 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
10524 " - Displays or erases graduated trihedron"
10525 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
10526 " - namefont - font of axes names. Default: Arial\n"
10527 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
10528 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
10529 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
10530 " - valuesfont - font of axes values. Default: Arial\n"
10531 " - xcolor, ycolor, zcolor - color of axis and values\n"
10532 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
10533 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
10534 __FILE__,VGraduatedTrihedron,group);
10535 theCommands.Add("vtile" ,
10536 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
10537 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
10538 "\n\t\t: -totalSize the size of virtual bigger viewport"
10539 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
10540 "\n\t\t: -lowerLeft tile offset as lower left corner"
10541 "\n\t\t: -upperLeft tile offset as upper left corner",
10542 __FILE__, VTile, group);
10543 theCommands.Add("vzlayer",
10544 "vzlayer [layerId]"
10545 "\n\t\t: [-add|-delete|-get|-settings]"
10546 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
10547 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv}]"
10548 "\n\t\t: ZLayer list management:"
10549 "\n\t\t: -add add new z layer to viewer and print its id"
10550 "\n\t\t: -delete delete z layer"
10551 "\n\t\t: -get print sequence of z layers"
10552 "\n\t\t: -settings print status of z layer settings"
10553 "\n\t\t: -disable disables given setting"
10554 "\n\t\t: -enable enables given setting",
10555 __FILE__,VZLayer,group);
10556 theCommands.Add("vlayerline",
10557 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
10558 __FILE__,VLayerLine,group);
10559 theCommands.Add ("vgrid",
10560 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
10561 " : Mode - rectangular or circular"
10562 " : Type - lines or points",
10563 __FILE__, VGrid, group);
10564 theCommands.Add ("vpriviledgedplane",
10565 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
10566 "\n\t\t: Ox, Oy, Oz - plane origin"
10567 "\n\t\t: Nx, Ny, Nz - plane normal direction"
10568 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
10569 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
10570 __FILE__, VPriviledgedPlane, group);
10571 theCommands.Add ("vconvert",
10572 "vconvert v [Mode={window|view}]"
10573 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
10574 "\n\t\t: vconvert x y z [Mode={window|grid}]"
10575 "\n\t\t: window - convert to window coordinates, pixels"
10576 "\n\t\t: view - convert to view projection plane"
10577 "\n\t\t: grid - convert to model coordinates, given on grid"
10578 "\n\t\t: ray - convert projection ray to model coordiantes"
10579 "\n\t\t: - vconvert v window : convert view to window;"
10580 "\n\t\t: - vconvert v view : convert window to view;"
10581 "\n\t\t: - vconvert x y window : convert view to window;"
10582 "\n\t\t: - vconvert x y view : convert window to view;"
10583 "\n\t\t: - vconvert x y : convert window to model;"
10584 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
10585 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
10586 "\n\t\t: - vconvert x y z window : convert model to window;"
10587 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
10588 "\n\t\t: Converts the given coordinates to window/view/model space.",
10589 __FILE__, VConvert, group);
10590 theCommands.Add ("vfps",
10591 "vfps [framesNb=100] : estimate average frame rate for active view",
10592 __FILE__, VFps, group);
10593 theCommands.Add ("vgldebug",
10594 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
10595 "\n\t\t: [-extraMsg {0|1}] [{0|1}]"
10596 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
10597 "\n\t\t: Debug context can be requested only on Windows"
10598 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
10599 "\n\t\t: -sync - request synchronized debug GL context"
10600 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
10601 "\n\t\t: which are suppressed by default,"
10602 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
10603 "\n\t\t: which are suppressed by default",
10604 __FILE__, VGlDebug, group);
10605 theCommands.Add ("vvbo",
10606 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
10607 __FILE__, VVbo, group);
10608 theCommands.Add ("vstereo",
10609 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
10610 "\n\t\t: [-anaglyph Filter]"
10611 "\n\t\t: Control stereo output mode. Available modes for -mode:"
10612 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
10613 "\n\t\t: requires driver support."
10614 "\n\t\t: Should be called BEFORE vinit!"
10615 "\n\t\t: anaglyph - Anaglyph glasses"
10616 "\n\t\t: rowInterlaced - row-interlaced display"
10617 "\n\t\t: columnInterlaced - column-interlaced display"
10618 "\n\t\t: chessBoard - chess-board output"
10619 "\n\t\t: sideBySide - horizontal pair"
10620 "\n\t\t: overUnder - vertical pair"
10621 "\n\t\t: Available Anaglyph filters for -anaglyph:"
10622 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
10623 "\n\t\t: greenMagentaSimple",
10624 __FILE__, VStereo, group);
10625 theCommands.Add ("vcaps",
10626 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
10627 "\n\t\t: [-compatibleProfile {0|1}]"
10628 "\n\t\t: [-vsync {0|1}]"
10629 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
10630 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
10631 "\n\t\t: Modify particular graphic driver options:"
10632 "\n\t\t: FFP - use fixed-function pipeline instead of"
10633 "\n\t\t: built-in GLSL programs"
10634 "\n\t\t: (requires compatible profile)"
10635 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
10636 "\n\t\t: arrays to GPU memory)"
10637 "\n\t\t: sprite - use textured sprites instead of bitmaps"
10638 "\n\t\t: vsync - switch VSync on or off"
10639 "\n\t\t: Context creation options:"
10640 "\n\t\t: softMode - software OpenGL implementation"
10641 "\n\t\t: compatibleProfile - backward-compatible profile"
10642 "\n\t\t: quadbuffer - QuadBuffer"
10643 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
10644 "\n\t\t: rendering paths producing the same visual result when"
10645 "\n\t\t: possible."
10646 "\n\t\t: Command is intended for testing old hardware compatibility.",
10647 __FILE__, VCaps, group);
10648 theCommands.Add ("vmemgpu",
10649 "vmemgpu [f]: print system-dependent GPU memory information if available;"
10650 " with f option returns free memory in bytes",
10651 __FILE__, VMemGpu, group);
10652 theCommands.Add ("vreadpixel",
10653 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
10654 " : Read pixel value for active view",
10655 __FILE__, VReadPixel, group);
10656 theCommands.Add("diffimage",
10657 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
10658 __FILE__, VDiffImage, group);
10659 theCommands.Add ("vselect",
10660 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
10661 "- emulates different types of selection:\n"
10662 "- 1) single click selection\n"
10663 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
10664 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
10665 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
10666 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
10667 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
10668 " (partial inclusion - overlap - is not allowed by default)\n"
10669 "- 5) any of these selections with shift button pressed",
10670 __FILE__, VSelect, group);
10671 theCommands.Add ("vmoveto",
10673 "- emulates cursor movement to pixel postion (x,y)",
10674 __FILE__, VMoveTo, group);
10675 theCommands.Add ("vviewparams",
10676 "vviewparams [-args] [-scale [s]]"
10677 "\n\t\t: [-eye [x y z]] [-at [x y z]] [-up [x y z]]"
10678 "\n\t\t: [-proj [x y z]] [-center x y] [-size sx]"
10679 "\n\t\t: Manage current view parameters or prints all"
10680 "\n\t\t: current values when called without argument."
10681 "\n\t\t: -scale [s] prints or sets viewport relative scale"
10682 "\n\t\t: -eye [x y z] prints or sets eye location"
10683 "\n\t\t: -at [x y z] prints or sets center of look"
10684 "\n\t\t: -up [x y z] prints or sets direction of up vector"
10685 "\n\t\t: -proj [x y z] prints or sets direction of look"
10686 "\n\t\t: -center x y sets location of center of the screen in pixels"
10687 "\n\t\t: -size [sx] prints viewport projection width and height sizes"
10688 "\n\t\t: or changes the size of its maximum dimension"
10689 "\n\t\t: -args prints vviewparams arguments for restoring current view",
10690 __FILE__, VViewParams, group);
10692 theCommands.Add("vanimation", "Alias for vanim",
10693 __FILE__, VAnimation, group);
10695 theCommands.Add("vanim",
10696 "List existing animations:"
10698 "\n\t\t: Animation playback:"
10699 "\n\t\t: vanim name -play|-resume [playFrom [playDuration]]"
10700 "\n\t\t: [-speed Coeff] [-freeLook] [-lockLoop]"
10701 "\n\t\t: -speed playback speed (1.0 is normal speed)"
10702 "\n\t\t: -freeLook skip camera animations"
10703 "\n\t\t: -lockLoop disable any interactions"
10705 "\n\t\t: Animation definition:"
10706 "\n\t\t: vanim Name/sub/name [-clear] [-delete]"
10707 "\n\t\t: [start TimeSec] [duration TimeSec]"
10709 "\n\t\t: Animation name defined in path-style (anim/name or anim.name)"
10710 "\n\t\t: specifies nested animations."
10711 "\n\t\t: There is no syntax to explicitly add new animation,"
10712 "\n\t\t: and all non-existing animations within the name will be"
10713 "\n\t\t: implicitly created on first use (including parents)."
10715 "\n\t\t: Each animation might define the SINGLE action (see below),"
10716 "\n\t\t: like camera transition, object transformation or custom callback."
10717 "\n\t\t: Child animations can be used for defining concurrent actions."
10719 "\n\t\t: Camera animation:"
10720 "\n\t\t: vanim name -view [-eye1 X Y Z] [-eye2 X Y Z]"
10721 "\n\t\t: [-at1 X Y Z] [-at2 X Y Z]"
10722 "\n\t\t: [-up1 X Y Z] [-up2 X Y Z]"
10723 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
10724 "\n\t\t: -eyeX camera Eye positions pair (start and end)"
10725 "\n\t\t: -atX camera Center positions pair"
10726 "\n\t\t: -upX camera Up directions pair"
10727 "\n\t\t: -scaleX camera Scale factors pair"
10728 "\n\t\t: Object animation:"
10729 "\n\t\t: vanim name -object [-loc1 X Y Z] [-loc2 X Y Z]"
10730 "\n\t\t: [-rot1 QX QY QZ QW] [-rot2 QX QY QZ QW]"
10731 "\n\t\t: [-scale1 Scale] [-scale2 Scale]"
10732 "\n\t\t: -locX object Location points pair (translation)"
10733 "\n\t\t: -rotX object Orientations pair (quaternions)"
10734 "\n\t\t: -scaleX object Scale factors pair (quaternions)"
10735 "\n\t\t: Custom callback:"
10736 "\n\t\t: vanim name -invoke \"Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN\""
10737 "\n\t\t: %Pts overall animation presentation timestamp"
10738 "\n\t\t: %LocalPts local animation timestamp"
10739 "\n\t\t: %Normalized local animation normalized value in range 0..1"
10740 __FILE__, VAnimation, group);
10742 theCommands.Add("vchangeselected",
10743 "vchangeselected shape"
10744 "- adds to shape to selection or remove one from it",
10745 __FILE__, VChangeSelected, group);
10746 theCommands.Add ("vnbselected",
10748 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
10749 theCommands.Add ("vcamera",
10750 "vcamera [-ortho] [-projtype]"
10752 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
10753 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
10754 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
10755 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
10756 "\n\t\t: Manage camera parameters."
10757 "\n\t\t: Prints current value when option called without argument."
10758 "\n\t\t: Orthographic camera:"
10759 "\n\t\t: -ortho activate orthographic projection"
10760 "\n\t\t: Perspective camera:"
10761 "\n\t\t: -persp activate perspective projection (mono)"
10762 "\n\t\t: -fovy field of view in y axis, in degrees"
10763 "\n\t\t: -distance distance of eye from camera center"
10764 "\n\t\t: Stereoscopic camera:"
10765 "\n\t\t: -stereo perspective projection (stereo)"
10766 "\n\t\t: -leftEye perspective projection (left eye)"
10767 "\n\t\t: -rightEye perspective projection (right eye)"
10768 "\n\t\t: -iod intraocular distance value"
10769 "\n\t\t: -iodType distance type, absolute or relative"
10770 "\n\t\t: -zfocus stereographic focus value"
10771 "\n\t\t: -zfocusType focus type, absolute or relative",
10772 __FILE__, VCamera, group);
10773 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
10774 "- vautozfit [on={1|0}] [scale]\n"
10775 " Prints or changes parameters of automatic z-fit mode:\n"
10776 " \"on\" - turns automatic z-fit on or off\n"
10777 " \"scale\" - specifies factor to scale computed z range.\n",
10778 __FILE__, VAutoZFit, group);
10779 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
10780 " vzrange - without parameters shows current values\n"
10781 " vzrange [znear] [zfar] - applies provided values to view",
10782 __FILE__,VZRange, group);
10783 theCommands.Add ("vpurgedisplay",
10785 "- removes structures which don't belong to objects displayed in neutral point",
10786 __FILE__, VPurgeDisplay, group);
10787 theCommands.Add("vsetviewsize",
10788 "vsetviewsize size",
10789 __FILE__,VSetViewSize,group);
10790 theCommands.Add("vmoveview",
10791 "vmoveview Dx Dy Dz [Start = 1|0]",
10792 __FILE__,VMoveView,group);
10793 theCommands.Add("vtranslateview",
10794 "vtranslateview Dx Dy Dz [Start = 1|0)]",
10795 __FILE__,VTranslateView,group);
10796 theCommands.Add("vturnview",
10797 "vturnview Ax Ay Az [Start = 1|0]",
10798 __FILE__,VTurnView,group);
10799 theCommands.Add("vtextureenv",
10800 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
10801 "or user-defined file and optionally applying texture mapping parameters\n"
10803 " vtextureenv off - disables environment mapping\n"
10804 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
10805 " std_texture = (0..7)\n"
10806 " rep = {clamp|repeat}\n"
10807 " mod = {decal|modulate}\n"
10808 " flt = {nearest|bilinear|trilinear}\n"
10809 " ss, st - scale factors for s and t texture coordinates\n"
10810 " ts, tt - translation for s and t texture coordinates\n"
10811 " rot - texture rotation angle in degrees",
10812 __FILE__, VTextureEnv, group);
10813 theCommands.Add("vhlr" ,
10814 "is_enabled={on|off} [show_hidden={1|0}]"
10815 " - Hidden line removal algorithm:"
10816 " - is_enabled: if is on HLR algorithm is applied\n"
10817 " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n",
10818 __FILE__,VHLR,group);
10819 theCommands.Add("vhlrtype" ,
10820 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
10821 " - Changes the type of HLR algorithm using for shapes."
10822 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
10823 " if equals to polyalgo, polygonal HLR algorithm is applied."
10824 "If shapes are not given HLR algoithm of given type is applied"
10825 " to all shapes in the view\n",
10826 __FILE__,VHLRType,group);
10827 theCommands.Add("vclipplane",
10828 "vclipplane planeName [{0|1}]"
10829 "\n\t\t: [-equation A B C D]"
10830 "\n\t\t: [-set|-unset [objects|views]]"
10831 "\n\t\t: [-maxPlanes]"
10832 "\n\t\t: [-capping {0|1}]"
10833 "\n\t\t: [-color R G B] [-hatch {on|off|ID}]"
10834 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
10835 "\n\t\t: [-texRotate Angle]"
10836 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
10837 "\n\t\t: [-useObjShader {0|1}]"
10838 "\n\t\t: Clipping planes management:"
10839 "\n\t\t: -maxPlanes print plane limit for view"
10840 "\n\t\t: -delete delete plane with given name"
10841 "\n\t\t: {off|on|0|1} turn clipping on/off"
10842 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
10843 "\n\t\t: applied to active View when list is omitted"
10844 "\n\t\t: -equation A B C D change plane equation"
10845 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
10846 "\n\t\t: Capping options:"
10847 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
10848 "\n\t\t: -color R G B set capping color"
10849 "\n\t\t: -texName Texture set capping texture"
10850 "\n\t\t: -texScale SX SY set capping tex scale"
10851 "\n\t\t: -texOrigin TX TY set capping tex origin"
10852 "\n\t\t: -texRotate Angle set capping tex rotation"
10853 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
10854 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
10855 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
10856 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
10857 __FILE__, VClipPlane, group);
10858 theCommands.Add("vdefaults",
10859 "vdefaults [-absDefl value]"
10860 "\n\t\t: [-devCoeff value]"
10861 "\n\t\t: [-angDefl value]"
10862 "\n\t\t: [-autoTriang {off/on | 0/1}]"
10863 , __FILE__, VDefaults, group);
10864 theCommands.Add("vlight",
10865 "tool to manage light sources, without arguments shows list of lights."
10866 "\n Main commands: "
10867 "\n 'clear' to clear lights"
10868 "\n '{def}aults' to load deafault lights"
10869 "\n 'add' (or 'new') <type> to add any light source"
10870 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
10871 "\n 'change' <lightId> to edit light source with specified lightId"
10872 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
10873 "\n {pos}ition X Y Z"
10874 "\n {dir}ection X Y Z (for directional light or for spotlight)"
10875 "\n color colorName"
10876 "\n {head}light 0|1"
10877 "\n {sm}oothness value"
10878 "\n {int}ensity value"
10879 "\n {constAtten}uation value"
10880 "\n {linearAtten}uation value"
10881 "\n angle angleDeg"
10882 "\n {spotexp}onent value"
10884 "\n\n example: vlight add positional head 1 pos 0 1 1 color red"
10885 "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
10886 __FILE__, VLight, group);
10887 theCommands.Add("vraytrace",
10889 "\n\t\t: Turns on/off ray-tracing renderer."
10890 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
10891 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
10892 __FILE__, VRenderParams, group);
10893 theCommands.Add("vrenderparams",
10894 "\n Manages rendering parameters: "
10895 "\n '-raster' Disables GPU ray-tracing"
10896 "\n '-msaa 0..4' Specifies number of samples for MSAA"
10897 "\n '-rayTrace' Enables GPU ray-tracing"
10898 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
10899 "\n '-shadows on|off' Enables/disables shadows rendering"
10900 "\n '-reflections on|off' Enables/disables specular reflections"
10901 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
10902 "\n '-gleam on|off' Enables/disables transparency shadow effects"
10903 "\n '-gi on|off' Enables/disables global illumination effects"
10904 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
10905 "\n '-env on|off' Enables/disables environment map background"
10906 "\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
10907 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
10908 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
10909 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
10910 "\n '-shadingModel model' Controls shading model from enumeration"
10911 "\n color, flat, gouraud, phong"
10912 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
10913 "\n Unlike vcaps, these parameters dramatically change visual properties."
10914 "\n Command is intended to control presentation quality depending on"
10915 "\n hardware capabilities and performance.",
10916 __FILE__, VRenderParams, group);
10917 theCommands.Add("vfrustumculling",
10918 "vfrustumculling [toEnable]: enables/disables objects clipping",
10919 __FILE__,VFrustumCulling,group);
10920 theCommands.Add("vhighlightselected",
10921 "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n"
10922 "Without arguments it shows if highlighting of selected objects is enabled now.",
10923 __FILE__,VHighlightSelected,group);
10924 theCommands.Add ("vplace",
10926 "\n\t\t: Places the point (in pixels) at the center of the window",
10927 __FILE__, VPlace, group);
10928 theCommands.Add("vxrotate",
10930 __FILE__,VXRotate,group);
10932 theCommands.Add("vmanipulator",
10933 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
10934 "\n tool to create and manage AIS manipulators."
10936 "\n '-attach AISObject' attach manipulator to AISObject"
10937 "\n '-adjustPosition {0|1}' adjust position when attaching"
10938 "\n '-adjustSize {0|1}' adjust size when attaching"
10939 "\n '-enableModes {0|1}' enable modes when attaching"
10940 "\n '-detach' detach manipulator"
10941 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
10942 "\n '-transform mouse_x mouse_y' - invoke transformation"
10943 "\n '-stopTransform [abort]' - invoke stop of transformation"
10944 "\n '-move x y z' - move attached object"
10945 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
10946 "\n '-scale factor' - scale attached object"
10947 "\n '-autoActivate {0|1}' - set activation on detection"
10948 "\n '-followTranslation {0|1}' - set following translation transform"
10949 "\n '-followRotation {0|1}' - set following rotation transform"
10950 "\n '-gap value' - set gap between sub-parts"
10951 "\n '-part axis mode {0|1}' - set visual part"
10952 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
10953 "\n '-size value' - set size of manipulator"
10954 "\n '-zoomable {0|1}' - set zoom persistence",
10955 __FILE__, VManipulator, group);
10957 theCommands.Add("vselprops",
10958 "\n vselprops [dynHighlight|localDynHighlight|selHighlight|localSelHighlight] [options]"
10959 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
10960 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
10961 "\n -pixTol value : sets up pixel tolerance"
10962 "\n -dispMode dispMode : sets display mode for highlighting"
10963 "\n -layer ZLayer : sets ZLayer for highlighting"
10964 "\n -color {name|r g b} : sets highlight color"
10965 "\n -transp value : sets transparency coefficient for highlight"
10966 "\n -material material : sets highlight material"
10967 "\n -print : prints current state of all mentioned parameters",
10968 __FILE__, VSelectionProperties, group);
10970 theCommands.Add ("vseldump",
10971 "vseldump file -type {depth|unnormDepth|object|owner|selMode|entity}=depth -pickedIndex Index=1"
10972 "\n\t\t: Generate an image based on detection results:"
10973 "\n\t\t: depth normalized depth values"
10974 "\n\t\t: unnormDepth unnormalized depth values"
10975 "\n\t\t: object color of detected object"
10976 "\n\t\t: owner color of detected owner"
10977 "\n\t\t: selMode color of selection mode"
10978 "\n\t\t: entity color of etected entity",
10979 __FILE__, VDumpSelectionImage, group);
10981 #if defined(_WIN32)
10982 theCommands.Add("vprogressive",
10984 __FILE__, VProgressiveMode, group);