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>
18 #include <AIS_ColorScale.hxx>
19 #include <AIS_Manipulator.hxx>
20 #include <AIS_RubberBand.hxx>
21 #include <AIS_Shape.hxx>
22 #include <AIS_InteractiveObject.hxx>
23 #include <AIS_ListOfInteractive.hxx>
24 #include <AIS_ListIteratorOfListOfInteractive.hxx>
26 #include <Graphic3d_ArrayOfPolylines.hxx>
27 #include <Graphic3d_AspectMarker3d.hxx>
28 #include <Graphic3d_ExportFormat.hxx>
29 #include <Graphic3d_NameOfTextureEnv.hxx>
30 #include <Graphic3d_GraduatedTrihedron.hxx>
31 #include <Graphic3d_TextureEnv.hxx>
32 #include <Graphic3d_TextureParams.hxx>
33 #include <Graphic3d_TypeOfTextureFilter.hxx>
34 #include <Graphic3d_AspectFillArea3d.hxx>
35 #include <ViewerTest.hxx>
36 #include <ViewerTest_AutoUpdater.hxx>
37 #include <ViewerTest_EventManager.hxx>
38 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
39 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
40 #include <ViewerTest_CmdParser.hxx>
41 #include <V3d_AmbientLight.hxx>
42 #include <V3d_DirectionalLight.hxx>
43 #include <V3d_PositionalLight.hxx>
44 #include <V3d_SpotLight.hxx>
45 #include <NCollection_DoubleMap.hxx>
46 #include <NCollection_List.hxx>
47 #include <NCollection_Vector.hxx>
48 #include <AIS_InteractiveContext.hxx>
49 #include <Draw_Interpretor.hxx>
51 #include <Draw_Appli.hxx>
52 #include <Image_AlienPixMap.hxx>
53 #include <OpenGl_GraphicDriver.hxx>
54 #include <OSD_Timer.hxx>
55 #include <TColStd_HSequenceOfAsciiString.hxx>
56 #include <TColStd_SequenceOfInteger.hxx>
57 #include <TColStd_HSequenceOfReal.hxx>
58 #include <TColgp_Array1OfPnt2d.hxx>
59 #include <TColStd_MapOfAsciiString.hxx>
60 #include <Aspect_TypeOfLine.hxx>
61 #include <Image_Diff.hxx>
62 #include <Aspect_DisplayConnection.hxx>
66 #include <PrsMgr_PresentableObject.hxx>
67 #include <Graphic3d_ClipPlane.hxx>
68 #include <NCollection_DataMap.hxx>
69 #include <Graphic3d_Texture2Dmanual.hxx>
70 #include <Prs3d_ShadingAspect.hxx>
71 #include <Prs3d_Drawer.hxx>
72 #include <Prs3d_LineAspect.hxx>
73 #include <Prs3d_Root.hxx>
82 #include <WNT_WClass.hxx>
83 #include <WNT_Window.hxx>
84 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
85 #include <Cocoa_Window.hxx>
87 #include <Xw_Window.hxx>
88 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
89 #include <X11/Xutil.h>
93 // Auxiliary definitions
94 static const char THE_KEY_DELETE = 127;
96 //==============================================================================
97 // VIEWER GLOBAL VARIABLES
98 //==============================================================================
100 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
101 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
103 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
104 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
106 extern int VErase (Draw_Interpretor& theDI,
107 Standard_Integer theArgNb,
108 const char** theArgVec);
111 static Handle(WNT_Window)& VT_GetWindow() {
112 static Handle(WNT_Window) WNTWin;
115 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
116 static Handle(Cocoa_Window)& VT_GetWindow()
118 static Handle(Cocoa_Window) aWindow;
121 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
122 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
123 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
126 static Handle(Xw_Window)& VT_GetWindow(){
127 static Handle(Xw_Window) XWWin;
131 static void VProcessEvents(ClientData,int);
134 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
136 static Handle(Aspect_DisplayConnection) aDisplayConnection;
137 return aDisplayConnection;
140 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
142 GetDisplayConnection() = theDisplayConnection;
145 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
146 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
148 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
150 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
151 if (!aWindow.IsNull())
152 return aWindow->HWindow();
153 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
154 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
155 if (!aWindow.IsNull())
156 return aWindow->XWindow();
158 return aWindowHandle;
162 static Standard_Boolean MyHLRIsOn = Standard_False;
164 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
165 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
166 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
167 static OpenGl_Caps ViewerTest_myDefaultCaps;
169 static void OSWindowSetup();
173 Quantity_Color FlatColor;
174 Quantity_Color GradientColor1;
175 Quantity_Color GradientColor2;
176 Aspect_GradientFillMethod FillMethod;
177 } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
179 //==============================================================================
180 // EVENT GLOBAL VARIABLES
181 //==============================================================================
183 static int Start_Rot = 0;
184 int X_Motion = 0; // Current cursor position
186 int X_ButtonPress = 0; // Last ButtonPress position
187 int Y_ButtonPress = 0;
188 Standard_Boolean IsDragged = Standard_False;
189 Standard_Boolean DragFirst = Standard_False;
192 Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand()
194 static Handle(AIS_RubberBand) aBand;
197 aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0);
198 aBand->SetDisplayMode (0);
203 typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators;
205 Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators()
207 static ViewerTest_MapOfAISManipulators aMap;
211 Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator()
213 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
214 for (; anIt.More(); anIt.Next())
216 if (anIt.Value()->HasActiveMode())
224 //==============================================================================
227 static LRESULT WINAPI ViewerWindowProc(
232 static LRESULT WINAPI AdvViewerWindowProc(
240 //==============================================================================
243 //==============================================================================
245 const Handle(MMgt_TShared)& ViewerTest::WClass()
247 static Handle(MMgt_TShared) theWClass;
249 if (theWClass.IsNull())
251 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
252 CS_VREDRAW | CS_HREDRAW, 0, 0,
253 ::LoadCursor (NULL, IDC_ARROW));
259 //==============================================================================
260 //function : CreateName
261 //purpose : Create numerical name for new object in theMap
262 //==============================================================================
263 template <typename ObjectType>
264 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
265 const TCollection_AsciiString& theDefaultString)
267 if (theObjectMap.IsEmpty())
268 return theDefaultString + TCollection_AsciiString(1);
270 Standard_Integer aNextKey = 1;
271 Standard_Boolean isFound = Standard_False;
274 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
275 // Look for objects with default names
276 if (theObjectMap.IsBound1(aStringKey))
281 isFound = Standard_True;
284 return theDefaultString + TCollection_AsciiString(aNextKey);
287 //==============================================================================
288 //structure : ViewerTest_Names
289 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
290 //==============================================================================
291 struct ViewerTest_Names
294 TCollection_AsciiString myDriverName;
295 TCollection_AsciiString myViewerName;
296 TCollection_AsciiString myViewName;
300 const TCollection_AsciiString& GetDriverName () const
304 void SetDriverName (const TCollection_AsciiString& theDriverName)
306 myDriverName = theDriverName;
308 const TCollection_AsciiString& GetViewerName () const
312 void SetViewerName (const TCollection_AsciiString& theViewerName)
314 myViewerName = theViewerName;
316 const TCollection_AsciiString& GetViewName () const
320 void SetViewName (const TCollection_AsciiString& theViewName)
322 myViewName = theViewName;
325 //===========================================================================
326 //function : Constructor for ViewerTest_Names
327 //purpose : Get view, viewer, driver names from custom string
328 //===========================================================================
330 ViewerTest_Names (const TCollection_AsciiString& theInputString)
332 TCollection_AsciiString aName(theInputString);
333 if (theInputString.IsEmpty())
335 // Get current configuration
336 if (ViewerTest_myDrivers.IsEmpty())
337 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
338 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
340 myDriverName = ViewerTest_myDrivers.Find2
341 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
343 if(ViewerTest_myContexts.IsEmpty())
345 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
346 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
349 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
351 myViewName = CreateName <Handle(V3d_View)>
352 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
356 // There is at least view name
357 Standard_Integer aParserNumber = 0;
358 for (Standard_Integer i = 0; i < 3; ++i)
360 Standard_Integer aParserPos = aName.SearchFromEnd("/");
364 aName.Split(aParserPos-1);
369 if (aParserNumber == 0)
372 if (!ViewerTest::GetAISContext().IsNull())
374 myDriverName = ViewerTest_myDrivers.Find2
375 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
376 myViewerName = ViewerTest_myContexts.Find2
377 (ViewerTest::GetAISContext());
381 // There is no opened contexts here, need to create names for viewer and driver
382 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
383 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
385 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
386 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
388 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
390 else if (aParserNumber == 1)
392 // Here is viewerName/viewName
393 if (!ViewerTest::GetAISContext().IsNull())
394 myDriverName = ViewerTest_myDrivers.Find2
395 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
398 // There is no opened contexts here, need to create name for driver
399 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
400 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
402 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
404 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
408 //Here is driverName/viewerName/viewName
409 myDriverName = TCollection_AsciiString(aName);
411 TCollection_AsciiString aViewerName(theInputString);
412 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
413 myViewerName = TCollection_AsciiString(aViewerName);
415 myViewName = TCollection_AsciiString(theInputString);
421 //==============================================================================
422 //function : FindContextByView
423 //purpose : Find AIS_InteractiveContext by View
424 //==============================================================================
426 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
428 Handle(AIS_InteractiveContext) anAISContext;
430 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
431 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
433 if (anIter.Value()->CurrentViewer() == theView->Viewer())
434 return anIter.Key2();
440 //==============================================================================
441 //function : SetWindowTitle
442 //purpose : Set window title
443 //==============================================================================
445 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
446 Standard_CString theTitle)
449 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
451 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
452 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
454 if(GetDisplayConnection()->GetDisplay())
457 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
458 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
463 //==============================================================================
464 //function : IsWindowOverlapped
465 //purpose : Check if theWindow overlapp another view
466 //==============================================================================
468 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
469 const Standard_Integer thePxTop,
470 const Standard_Integer thePxRight,
471 const Standard_Integer thePxBottom,
472 TCollection_AsciiString& theViewId)
474 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
475 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
477 Standard_Integer aTop = 0,
481 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
482 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
483 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
484 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
485 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
487 theViewId = anIter.Key1();
488 return Standard_True;
491 return Standard_False;
494 // Workaround: to create and delete non-orthographic views outside ViewerTest
495 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
497 ViewerTest_myViews.UnBind1 (theName);
500 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
501 const Handle(V3d_View)& theView)
503 ViewerTest_myViews.Bind (theName, theView);
506 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
508 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
510 //==============================================================================
511 //function : ViewerInit
512 //purpose : Create the window viewer and initialize all the global variable
513 //==============================================================================
515 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
516 const Standard_Integer thePxTop,
517 const Standard_Integer thePxWidth,
518 const Standard_Integer thePxHeight,
519 Standard_CString theViewName,
520 Standard_CString theDisplayName)
522 // Default position and dimension of the viewer window.
523 // Note that left top corner is set to be sufficiently small to have
524 // window fit in the small screens (actual for remote desktops, see #23003).
525 // The position corresponds to the window's client area, thus some
526 // gap is added for window frame to be visible.
527 Standard_Integer aPxLeft = 20;
528 Standard_Integer aPxTop = 40;
529 Standard_Integer aPxWidth = 409;
530 Standard_Integer aPxHeight = 409;
531 Standard_Boolean toCreateViewer = Standard_False;
533 Handle(OpenGl_GraphicDriver) aGraphicDriver;
534 ViewerTest_Names aViewNames(theViewName);
535 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
536 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
543 aPxWidth = thePxWidth;
544 if (thePxHeight != 0)
545 aPxHeight = thePxHeight;
547 // Get graphic driver (create it or get from another view)
548 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
550 // Get connection string
551 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
552 TCollection_AsciiString aDisplayName(theDisplayName);
553 if (!aDisplayName.IsEmpty())
554 SetDisplayConnection (new Aspect_DisplayConnection ());
556 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
558 (void)theDisplayName; // avoid warning on unused argument
559 SetDisplayConnection (new Aspect_DisplayConnection ());
562 if (Draw_VirtualWindows)
564 // don't waste the time waiting for VSync when window is not displayed on the screen
565 ViewerTest_myDefaultCaps.swapInterval = 0;
566 // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
567 //ViewerTest_myDefaultCaps.buffersNoSwap = true;
569 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
570 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
572 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
573 toCreateViewer = Standard_True;
577 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
580 //Dispose the window if input parameters are default
581 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
583 Standard_Integer aTop = 0,
590 // Get screen resolution
591 #if defined(_WIN32) || defined(__WIN32__)
593 GetClientRect(GetDesktopWindow(), &aWindowSize);
594 aScreenHeight = aWindowSize.bottom;
595 aScreenWidth = aWindowSize.right;
596 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
597 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
599 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
600 aScreenWidth = WidthOfScreen(aScreen);
601 aScreenHeight = HeightOfScreen(aScreen);
604 TCollection_AsciiString anOverlappedViewId("");
606 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
608 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
610 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
611 && aRight + 2*aPxWidth + 40 > aScreenWidth)
613 if (aBottom + aPxHeight + 40 > aScreenHeight)
620 aPxTop = aBottom + 40;
623 aPxLeft = aRight + 20;
628 TCollection_AsciiString aTitle("3D View - ");
629 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
631 // Change name of current active window
632 if (!ViewerTest::CurrentView().IsNull())
634 TCollection_AsciiString anActiveWindowTitle("3D View - ");
635 anActiveWindowTitle = anActiveWindowTitle
636 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
637 SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString());
641 Handle(V3d_Viewer) a3DViewer;
642 // If it's the single view, we first look for empty context
643 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
645 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
646 anIter(ViewerTest_myContexts);
648 ViewerTest::SetAISContext (anIter.Value());
649 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
651 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
653 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
654 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
656 else if (a3DViewer.IsNull())
658 toCreateViewer = Standard_True;
659 a3DViewer = new V3d_Viewer(aGraphicDriver);
660 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
661 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
662 ViewerTest_DefaultBackground.GradientColor2,
663 ViewerTest_DefaultBackground.FillMethod);
667 if (ViewerTest::GetAISContext().IsNull() ||
668 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
670 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
671 ViewerTest::SetAISContext (aContext);
672 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
676 ViewerTest::ResetEventManager();
681 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
682 Handle(WNT_WClass)::DownCast (WClass()),
683 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
687 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
688 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
690 aPxWidth, aPxHeight);
691 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
693 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
696 aPxWidth, aPxHeight);
698 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
701 Handle(V3d_View) aView = a3DViewer->CreateView();
702 aView->SetWindow (VT_GetWindow());
703 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
705 ViewerTest::CurrentView(aView);
706 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
708 // Setup for X11 or NT
711 // Set parameters for V3d_View and V3d_Viewer
712 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
713 aV3dView->SetComputedMode(Standard_False);
714 MyHLRIsOn = aV3dView->ComputedMode();
716 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
719 a3DViewer->SetDefaultLights();
720 a3DViewer->SetLightOn();
723 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
724 #if TCL_MAJOR_VERSION < 8
725 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
726 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
728 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
729 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
733 VT_GetWindow()->Map();
735 // Set the handle of created view in the event manager
736 ViewerTest::ResetEventManager();
738 ViewerTest::CurrentView()->Redraw();
743 return aViewNames.GetViewName();
746 //==============================================================================
747 //function : RedrawAllViews
748 //purpose : Redraw all created views
749 //==============================================================================
750 void ViewerTest::RedrawAllViews()
752 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
753 for (; aViewIt.More(); aViewIt.Next())
755 const Handle(V3d_View)& aView = aViewIt.Key2();
760 //==============================================================================
762 //purpose : Create the window viewer and initialize all the global variable
763 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
764 //==============================================================================
766 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
770 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
771 << "Type help for more information.\n";
775 TCollection_AsciiString aViewName, aDisplayName;
776 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
777 TCollection_AsciiString aName, aValue;
778 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
780 const TCollection_AsciiString anArg = theArgVec[anArgIt];
781 TCollection_AsciiString anArgCase = anArg;
782 anArgCase.UpperCase();
783 if (ViewerTest::SplitParameter (anArg, aName, aValue))
786 if (aName.IsEqual ("NAME"))
790 else if (aName.IsEqual ("L")
791 || aName.IsEqual ("LEFT"))
793 aPxLeft = aValue.IntegerValue();
795 else if (aName.IsEqual ("T")
796 || aName.IsEqual ("TOP"))
798 aPxTop = aValue.IntegerValue();
800 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
801 else if (aName.IsEqual ("DISP")
802 || aName.IsEqual ("DISPLAY"))
804 aDisplayName = aValue;
807 else if (aName.IsEqual ("W")
808 || aName.IsEqual ("WIDTH"))
810 aPxWidth = aValue.IntegerValue();
812 else if (aName.IsEqual ("H")
813 || aName.IsEqual ("HEIGHT"))
815 aPxHeight = aValue.IntegerValue();
819 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
822 else if (aViewName.IsEmpty())
828 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
832 ViewerTest_Names aViewNames (aViewName);
833 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
835 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
836 theDi.Eval (aCommand.ToCString());
840 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
841 aViewName.ToCString(),
842 aDisplayName.ToCString());
847 //==============================================================================
849 //purpose : hidden lines removal algorithm
850 //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}]
851 //==============================================================================
853 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
855 if (ViewerTest::CurrentView().IsNull())
857 di << argv[0] << ": Call vinit before this command, please.\n";
863 di << argv[0] << ": Wrong number of command arguments.\n"
864 << "Type help " << argv[0] << " for more information.\n";
868 // Enable or disable HLR mode.
869 Standard_Boolean isHLROn =
870 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
872 if (isHLROn != MyHLRIsOn)
875 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
878 // Show or hide hidden lines in HLR mode.
879 Standard_Boolean isCurrentShowHidden
880 = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine();
882 Standard_Boolean isShowHidden =
883 (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False)
884 : isCurrentShowHidden;
887 if (isShowHidden != isCurrentShowHidden)
891 ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine();
895 ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine();
901 AIS_ListOfInteractive aListOfShapes;
902 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
904 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
906 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value());
911 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
916 ViewerTest::CurrentView()->Update();
920 //==============================================================================
921 //function : VHLRType
922 //purpose : change type of using HLR algorithm
923 //==============================================================================
925 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
927 if (ViewerTest::CurrentView().IsNull())
929 di << argv[0] << ": Call vinit before this command, please.\n";
935 di << argv[0] << ": Wrong number of command arguments.\n"
936 << "Type help " << argv[0] << " for more information.\n";
940 Prs3d_TypeOfHLR aTypeOfHLR =
941 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
945 AIS_ListOfInteractive aListOfShapes;
946 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
947 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
948 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
949 anIter.More(); anIter.Next())
951 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
954 if (aShape->TypeOfHLR() != aTypeOfHLR)
955 aShape->SetTypeOfHLR (aTypeOfHLR);
957 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
959 ViewerTest::CurrentView()->Update();
964 for (Standard_Integer i = 2; i < argc; ++i)
966 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
967 TCollection_AsciiString aName (argv[i]);
969 if (!aMap.IsBound2 (aName))
971 di << argv[0] << ": Wrong shape name:" << aName.ToCString() << ".\n";
974 Handle(AIS_Shape) anAISObject =
975 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
976 if (anAISObject.IsNull())
978 anAISObject->SetTypeOfHLR (aTypeOfHLR);
980 ViewerTest::GetAISContext()->Redisplay (anAISObject, Standard_False);
982 ViewerTest::CurrentView()->Update();
988 //==============================================================================
989 //function : FindViewIdByWindowHandle
990 //purpose : Find theView Id in the map of views by window handle
991 //==============================================================================
992 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
993 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
995 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
996 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
998 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
999 if (aWindowHandle == theWindowHandle)
1000 return anIter.Key1();
1002 return TCollection_AsciiString("");
1006 //==============================================================================
1007 //function : ActivateView
1008 //purpose : Make the view active
1009 //==============================================================================
1011 void ActivateView (const TCollection_AsciiString& theViewName)
1013 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1014 if (!aView.IsNull())
1016 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1017 if (!anAISContext.IsNull())
1019 if (!ViewerTest::CurrentView().IsNull())
1021 TCollection_AsciiString aTitle("3D View - ");
1022 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1023 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1026 ViewerTest::CurrentView (aView);
1027 // Update degenerate mode
1028 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
1029 ViewerTest::SetAISContext (anAISContext);
1030 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
1031 aTitle = aTitle + theViewName + "(*)";
1032 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1033 #if defined(_WIN32) || defined(__WIN32__)
1034 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1035 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1036 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1038 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1040 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1041 ViewerTest::CurrentView()->Redraw();
1046 //==============================================================================
1047 //function : RemoveView
1049 //==============================================================================
1050 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1051 const Standard_Boolean theToRemoveContext)
1053 if (!ViewerTest_myViews.IsBound2 (theView))
1058 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1059 RemoveView (aViewName, theToRemoveContext);
1062 //==============================================================================
1063 //function : RemoveView
1064 //purpose : Close and remove view from display, clear maps if neccessary
1065 //==============================================================================
1066 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1068 if (!ViewerTest_myViews.IsBound1(theViewName))
1070 cout << "Wrong view name\n";
1074 // Activate another view if it's active now
1075 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1077 if (ViewerTest_myViews.Extent() > 1)
1079 TCollection_AsciiString aNewViewName;
1080 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
1081 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1082 if (anIter.Key1() != theViewName)
1084 aNewViewName = anIter.Key1();
1087 ActivateView (aNewViewName);
1091 Handle(V3d_View) anEmptyView;
1092 #if defined(_WIN32) || defined(__WIN32__)
1093 Handle(WNT_Window) anEmptyWindow;
1094 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1095 Handle(Cocoa_Window) anEmptyWindow;
1097 Handle(Xw_Window) anEmptyWindow;
1099 VT_GetWindow() = anEmptyWindow;
1100 ViewerTest::CurrentView (anEmptyView);
1101 if (isContextRemoved)
1103 Handle(AIS_InteractiveContext) anEmptyContext;
1104 ViewerTest::SetAISContext(anEmptyContext);
1110 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1111 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1113 // Remove view resources
1114 ViewerTest_myViews.UnBind1(theViewName);
1117 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1118 XFlush (GetDisplayConnection()->GetDisplay());
1121 // Keep context opened only if the closed view is last to avoid
1122 // unused empty contexts
1123 if (!aCurrentContext.IsNull())
1125 // Check if there are more difined views in the viewer
1126 aCurrentContext->CurrentViewer()->InitDefinedViews();
1127 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1129 // Remove driver if there is no viewers that use it
1130 Standard_Boolean isRemoveDriver = Standard_True;
1131 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1132 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1134 if (aCurrentContext != anIter.Key2() &&
1135 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1137 isRemoveDriver = Standard_False;
1142 aCurrentContext->RemoveAll (Standard_False);
1145 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1146 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1147 #if TCL_MAJOR_VERSION < 8
1148 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1150 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1155 ViewerTest_myContexts.UnBind2(aCurrentContext);
1158 cout << "3D View - " << theViewName << " was deleted.\n";
1162 //==============================================================================
1164 //purpose : Remove the view defined by its name
1165 //==============================================================================
1167 static int VClose (Draw_Interpretor& /*theDi*/,
1168 Standard_Integer theArgsNb,
1169 const char** theArgVec)
1171 NCollection_List<TCollection_AsciiString> aViewList;
1174 TCollection_AsciiString anArg (theArgVec[1]);
1176 if (anArg.IsEqual ("ALL")
1177 || anArg.IsEqual ("*"))
1179 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1180 anIter.More(); anIter.Next())
1182 aViewList.Append (anIter.Key1());
1184 if (aViewList.IsEmpty())
1186 std::cout << "No view to close\n";
1192 ViewerTest_Names aViewName (theArgVec[1]);
1193 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1195 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1198 aViewList.Append (aViewName.GetViewName());
1203 // close active view
1204 if (ViewerTest::CurrentView().IsNull())
1206 std::cerr << "No active view!\n";
1209 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1212 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1213 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1214 anIter.More(); anIter.Next())
1216 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1222 //==============================================================================
1223 //function : VActivate
1224 //purpose : Activate the view defined by its ID
1225 //==============================================================================
1227 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1231 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1232 << "Usage: " << theArgVec[0] << " ViewID\n";
1237 theDi.Eval("vviewlist");
1241 TCollection_AsciiString aNameString(theArgVec[1]);
1242 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1244 TCollection_AsciiString aTitle("3D View - ");
1245 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1246 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1247 Handle(V3d_View) anEmptyView;
1248 #if defined(_WIN32) || defined(__WIN32__)
1249 Handle(WNT_Window) anEmptyWindow;
1250 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1251 Handle(Cocoa_Window) anEmptyWindow;
1253 Handle(Xw_Window) anEmptyWindow;
1255 VT_GetWindow() = anEmptyWindow;
1256 ViewerTest::CurrentView (anEmptyView);
1257 ViewerTest::ResetEventManager();
1258 theDi << theArgVec[0] << ": all views are inactive\n";
1262 ViewerTest_Names aViewNames(aNameString);
1264 // Check if this view exists in the viewer with the driver
1265 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1267 theDi << "Wrong view name\n";
1271 // Check if it is active already
1272 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1274 theDi << theArgVec[0] << ": the view is active already\n";
1278 ActivateView (aViewNames.GetViewName());
1282 //==============================================================================
1283 //function : VViewList
1284 //purpose : Print current list of views per viewer and graphic driver ID
1285 // shared between viewers
1286 //==============================================================================
1288 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1292 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1293 << "Usage: " << theArgVec[0] << " name";
1296 if (ViewerTest_myContexts.Size() < 1)
1299 Standard_Boolean isTreeView =
1300 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1303 theDi << theArgVec[0] <<":\n";
1305 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1306 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1309 theDi << aDriverIter.Key1() << ":\n";
1311 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1312 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1314 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1318 TCollection_AsciiString aContextName(aContextIter.Key1());
1319 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
1322 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1323 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1325 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1327 TCollection_AsciiString aViewName(aViewIter.Key1());
1330 if (aViewIter.Value() == ViewerTest::CurrentView())
1331 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
1333 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1337 theDi << aViewName << " ";
1347 //==============================================================================
1348 //function : VT_ProcessKeyPress
1349 //purpose : Handle KeyPress event from a CString
1350 //==============================================================================
1351 void VT_ProcessKeyPress (const char* buf_ret)
1353 //cout << "KeyPress" << endl;
1354 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1355 // Letter in alphabetic order
1357 if (!strcasecmp (buf_ret, "A"))
1360 aView->SetProj(V3d_XposYnegZpos);
1362 else if (!strcasecmp (buf_ret, "D"))
1367 else if (!strcasecmp (buf_ret, "F"))
1369 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1371 ViewerTest::GetAISContext()->FitSelected (aView);
1379 else if (!strcasecmp (buf_ret, "H"))
1382 cout << "HLR" << endl;
1383 aView->SetComputedMode (!aView->ComputedMode());
1384 MyHLRIsOn = aView->ComputedMode();
1386 else if (!strcasecmp (buf_ret, "P"))
1389 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1390 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1391 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1393 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1394 if (aContext->NbSelected()==0)
1396 AIS_ListOfInteractive aListOfShapes;
1397 aContext->DisplayedObjects(aListOfShapes);
1398 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1399 anIter.More(); anIter.Next())
1401 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1402 if (aShape.IsNull())
1404 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1405 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1407 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1408 aContext->Redisplay (aShape, Standard_False);
1413 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
1415 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
1416 if (aShape.IsNull())
1418 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1419 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1421 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1422 aContext->Redisplay (aShape, Standard_False);
1426 aContext->UpdateCurrentViewer();
1429 else if (!strcasecmp (buf_ret, "S"))
1431 std::cout << "setup Shaded display mode" << std::endl;
1433 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1434 if(Ctx->NbSelected()==0)
1435 Ctx->SetDisplayMode(AIS_Shaded);
1437 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1438 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
1439 Ctx->UpdateCurrentViewer();
1442 else if (!strcasecmp (buf_ret, "U"))
1444 // Unset display mode
1445 std::cout << "reset display mode to defaults" << std::endl;
1447 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1448 if(Ctx->NbSelected()==0)
1449 Ctx->SetDisplayMode(AIS_WireFrame);
1451 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1452 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
1453 Ctx->UpdateCurrentViewer();
1457 else if (!strcasecmp (buf_ret, "T"))
1460 aView->SetProj(V3d_Zpos);
1462 else if (!strcasecmp (buf_ret, "B"))
1465 aView->SetProj(V3d_Zneg);
1467 else if (!strcasecmp (buf_ret, "L"))
1470 aView->SetProj(V3d_Xneg);
1472 else if (!strcasecmp (buf_ret, "R"))
1475 aView->SetProj(V3d_Xpos);
1477 else if (!strcasecmp (buf_ret, "W"))
1479 std::cout << "setup WireFrame display mode" << std::endl;
1480 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1481 if(Ctx->NbSelected()==0)
1482 Ctx->SetDisplayMode(AIS_WireFrame);
1484 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1485 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
1486 Ctx->UpdateCurrentViewer();
1489 else if (!strcasecmp (buf_ret, ","))
1491 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1493 else if (!strcasecmp (buf_ret, "."))
1495 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1497 else if (!strcasecmp (buf_ret, "/"))
1499 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1500 if (aCamera->IsStereo())
1502 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1506 else if (!strcasecmp (buf_ret, "*"))
1508 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1509 if (aCamera->IsStereo())
1511 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1515 else if (*buf_ret == THE_KEY_DELETE)
1517 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1519 && aCtx->NbSelected() > 0)
1521 Draw_Interprete ("verase");
1527 Standard_Integer Num = Draw::Atoi(buf_ret);
1528 if(Num>=0 && Num<=7)
1529 ViewerTest::StandardModeActivation(Num);
1533 //==============================================================================
1534 //function : VT_ProcessExpose
1535 //purpose : Redraw the View on an Expose Event
1536 //==============================================================================
1537 void VT_ProcessExpose()
1539 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1540 if (!aView3d.IsNull())
1546 //==============================================================================
1547 //function : VT_ProcessConfigure
1548 //purpose : Resize the View on an Configure Event
1549 //==============================================================================
1550 void VT_ProcessConfigure()
1552 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1553 if (aView3d.IsNull())
1558 aView3d->MustBeResized();
1563 //==============================================================================
1564 //function : VT_ProcessButton1Press
1566 //==============================================================================
1567 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1568 const char** theArgVec,
1569 Standard_Boolean theToPick,
1570 Standard_Boolean theIsShift)
1574 Standard_Real X, Y, Z;
1575 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1577 Draw::Set (theArgVec[1], X);
1578 Draw::Set (theArgVec[2], Y);
1579 Draw::Set (theArgVec[3], Z);
1584 ViewerTest::CurrentEventManager()->ShiftSelect();
1588 ViewerTest::CurrentEventManager()->Select();
1591 return Standard_False;
1594 //==============================================================================
1595 //function : VT_ProcessButton1Release
1596 //purpose : End selecting
1597 //==============================================================================
1598 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1602 IsDragged = Standard_False;
1603 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1606 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1607 X_Motion, Y_Motion);
1611 EM->Select (X_ButtonPress, Y_ButtonPress,
1612 X_Motion, Y_Motion);
1617 //==============================================================================
1618 //function : VT_ProcessButton3Press
1619 //purpose : Start Rotation
1620 //==============================================================================
1621 void VT_ProcessButton3Press()
1626 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1628 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1631 //==============================================================================
1632 //function : VT_ProcessButton3Release
1633 //purpose : End rotation
1634 //==============================================================================
1635 void VT_ProcessButton3Release()
1642 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1647 //==============================================================================
1648 //function : ProcessControlButton1Motion
1650 //==============================================================================
1652 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1653 static void ProcessControlButton1Motion()
1655 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1657 X_ButtonPress = X_Motion;
1658 Y_ButtonPress = Y_Motion;
1662 //==============================================================================
1663 //function : VT_ProcessControlButton2Motion
1665 //==============================================================================
1666 void VT_ProcessControlButton2Motion()
1668 Standard_Integer aDx = X_Motion - X_ButtonPress;
1669 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1671 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1673 ViewerTest::CurrentView()->Pan (aDx, aDy);
1675 X_ButtonPress = X_Motion;
1676 Y_ButtonPress = Y_Motion;
1679 //==============================================================================
1680 //function : VT_ProcessControlButton3Motion
1681 //purpose : Rotation
1682 //==============================================================================
1683 void VT_ProcessControlButton3Motion()
1687 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1691 //==============================================================================
1692 //function : VT_ProcessMotion
1694 //==============================================================================
1695 void VT_ProcessMotion()
1697 //pre-hilights detected objects at mouse position
1699 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1700 EM->MoveTo(X_Motion, Y_Motion);
1704 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1706 Xpix = X_Motion;Ypix=Y_Motion;
1709 //==============================================================================
1710 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1711 //purpose : Switches to an axonometric, top, left and other views
1712 //==============================================================================
1714 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1716 if ( ViewerTest::CurrentView().IsNull() )
1718 di<<"Call vinit before this command, please\n";
1722 ViewerTest::CurrentView()->SetProj(ori);
1726 //==============================================================================
1728 //purpose : Switch to an Axonometric view
1729 //Draw arg : No args
1730 //==============================================================================
1732 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1734 return ViewProject(di, V3d_XposYnegZpos);
1737 //==============================================================================
1739 //purpose : Switch to a Top View
1740 //Draw arg : No args
1741 //==============================================================================
1743 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1745 return ViewProject(di, V3d_Zpos);
1748 //==============================================================================
1749 //function : VBottom
1750 //purpose : Switch to a Bottom View
1751 //Draw arg : No args
1752 //==============================================================================
1754 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1756 return ViewProject(di, V3d_Zneg);
1759 //==============================================================================
1761 //purpose : Switch to a Left View
1762 //Draw arg : No args
1763 //==============================================================================
1765 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1767 return ViewProject(di, V3d_Xneg);
1770 //==============================================================================
1772 //purpose : Switch to a Right View
1773 //Draw arg : No args
1774 //==============================================================================
1776 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1778 return ViewProject(di, V3d_Xpos);
1781 //==============================================================================
1783 //purpose : Switch to a Front View
1784 //Draw arg : No args
1785 //==============================================================================
1787 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1789 return ViewProject(di, V3d_Yneg);
1792 //==============================================================================
1794 //purpose : Switch to a Back View
1795 //Draw arg : No args
1796 //==============================================================================
1798 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1800 return ViewProject(di, V3d_Ypos);
1803 //==============================================================================
1805 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1806 //Draw arg : No args
1807 //==============================================================================
1809 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1812 di << "Q : Quit the application\n";
1814 di << "=========================\n";
1815 di << "F : FitAll\n";
1816 di << "T : TopView\n";
1817 di << "B : BottomView\n";
1818 di << "R : RightView\n";
1819 di << "L : LeftView\n";
1820 di << "A : AxonometricView\n";
1821 di << "D : ResetView\n";
1823 di << "=========================\n";
1824 di << "S : Shading\n";
1825 di << "W : Wireframe\n";
1826 di << "H : HidelLineRemoval\n";
1827 di << "U : Unset display mode\n";
1828 di << "Delete : Remove selection from viewer\n";
1830 di << "=========================\n";
1831 di << "Selection mode \n";
1832 di << "0 : Shape\n";
1833 di << "1 : Vertex\n";
1837 di << "5 : Shell\n";
1838 di << "6 : Solid\n";
1839 di << "7 : Compound\n";
1841 di << "=========================\n";
1842 di << "Z : Switch Z clipping On/Off\n";
1843 di << ", : Hilight next detected\n";
1844 di << ". : Hilight previous detected\n";
1851 static Standard_Boolean Ppick = 0;
1852 static Standard_Integer Pargc = 0;
1853 static const char** Pargv = NULL;
1856 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1861 if (!ViewerTest_myViews.IsEmpty()) {
1863 WPARAM fwKeys = wParam;
1868 // Delete view from map of views
1869 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1874 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1875 || ViewerTest::CurrentView().IsNull())
1877 // Activate inactive window
1878 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1880 ActivateView (FindViewIdByWindowHandle(hwnd));
1886 if (IsDragged && !DragFirst)
1888 if (!GetActiveAISManipulator().IsNull())
1890 GetActiveAISManipulator()->StopTransform();
1891 ViewerTest::GetAISContext()->ClearSelected();
1894 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
1896 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
1897 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
1900 VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0);
1902 IsDragged = Standard_False;
1903 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1906 if (IsDragged && !DragFirst)
1908 if (!GetActiveAISManipulator().IsNull())
1910 GetActiveAISManipulator()->StopTransform (Standard_False);
1911 ViewerTest::GetAISContext()->ClearSelected();
1913 IsDragged = Standard_False;
1915 return ViewerWindowProc (hwnd, Msg, wParam, lParam);
1917 case WM_LBUTTONDOWN:
1918 if (!GetActiveAISManipulator().IsNull())
1920 IsDragged = ( fwKeys == MK_LBUTTON );
1924 IsDragged = ( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) );
1929 DragFirst = Standard_True;
1930 X_ButtonPress = LOWORD(lParam);
1931 Y_ButtonPress = HIWORD(lParam);
1933 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1938 X_Motion = LOWORD (lParam);
1939 Y_Motion = HIWORD (lParam);
1940 if (!GetActiveAISManipulator().IsNull())
1944 GetActiveAISManipulator()->StartTransform (X_ButtonPress, Y_ButtonPress, ViewerTest::CurrentView());
1948 GetActiveAISManipulator()->Transform (X_Motion, Y_Motion, ViewerTest::CurrentView());
1949 ViewerTest::GetAISContext()->CurrentViewer()->Redraw();
1954 bool toRedraw = false;
1955 if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
1957 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
1962 if (GetClientRect (hwnd, &aRect))
1964 int aHeight = aRect.bottom - aRect.top;
1965 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
1966 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed);
1971 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
1975 DragFirst = Standard_False;
1978 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1982 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1986 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1990 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1996 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
1999 return DefWindowProc( hwnd, Msg, wParam, lParam );
2006 BeginPaint(hwnd, &ps);
2007 EndPaint(hwnd, &ps);
2012 VT_ProcessConfigure();
2017 switch (aView->RenderingParams().StereoMode)
2019 case Graphic3d_StereoMode_RowInterlaced:
2020 case Graphic3d_StereoMode_ColumnInterlaced:
2021 case Graphic3d_StereoMode_ChessBoard:
2022 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2030 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2033 c[0] = (char) wParam;
2035 if (wParam == VK_DELETE)
2037 c[0] = THE_KEY_DELETE;
2040 else if (wParam == VK_OEM_COMMA)
2045 else if (wParam == VK_OEM_PERIOD)
2049 else if (wParam == VK_DIVIDE)
2054 else if (wParam == VK_MULTIPLY)
2058 VT_ProcessKeyPress (c);
2066 VT_ProcessButton3Release();
2069 case WM_LBUTTONDOWN:
2070 case WM_MBUTTONDOWN:
2071 case WM_RBUTTONDOWN:
2073 WPARAM fwKeys = wParam;
2077 X_ButtonPress = LOWORD(lParam);
2078 Y_ButtonPress = HIWORD(lParam);
2080 if (Msg == WM_LBUTTONDOWN)
2082 if ((fwKeys & MK_CONTROL) != 0)
2084 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2088 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2091 else if (Msg == WM_RBUTTONDOWN)
2094 VT_ProcessButton3Press();
2101 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2102 if (wParam & MK_CONTROL)
2104 if (aView->Camera()->IsStereo())
2106 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2110 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2117 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2124 //cout << "\t WM_MOUSEMOVE" << endl;
2125 WPARAM fwKeys = wParam;
2126 X_Motion = LOWORD(lParam);
2127 Y_Motion = HIWORD(lParam);
2130 (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 )
2133 X_ButtonPress = LOWORD(lParam);
2134 Y_ButtonPress = HIWORD(lParam);
2136 if ((fwKeys & MK_RBUTTON) != 0) {
2138 VT_ProcessButton3Press();
2142 if ((fwKeys & MK_CONTROL) != 0)
2144 if ((fwKeys & MK_LBUTTON) != 0)
2146 ProcessControlButton1Motion();
2148 else if ((fwKeys & MK_MBUTTON) != 0
2149 || ((fwKeys & MK_LBUTTON) != 0
2150 && (fwKeys & MK_RBUTTON) != 0))
2152 VT_ProcessControlButton2Motion();
2154 else if ((fwKeys & MK_RBUTTON) != 0)
2156 VT_ProcessControlButton3Motion();
2159 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2167 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2175 //==============================================================================
2176 //function : ViewerMainLoop
2177 //purpose : Get a Event on the view and dispatch it
2178 //==============================================================================
2181 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2183 Ppick = (argc > 0)? 1 : 0;
2191 cout << "Start picking" << endl;
2193 while ( Ppick == 1 ) {
2194 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2195 if (GetMessage(&msg, NULL, 0, 0) ) {
2196 TranslateMessage(&msg);
2197 DispatchMessage(&msg);
2201 cout << "Picking done" << endl;
2207 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2209 int min( int a, int b )
2217 int max( int a, int b )
2225 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2228 static XEvent aReport;
2229 Standard_Boolean pick = argc > 0;
2230 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2231 XNextEvent (aDisplay, &aReport);
2233 // Handle event for the chosen display connection
2234 switch (aReport.type) {
2237 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2240 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2246 // Activate inactive view
2247 Window aWindow = GetWindowHandle(VT_GetWindow());
2248 if(aWindow != aReport.xfocus.window)
2250 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2259 case ConfigureNotify:
2261 VT_ProcessConfigure();
2270 XComposeStatus status_in_out;
2272 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2273 (char *) buf_ret , 10 ,
2274 &ks_ret , &status_in_out ) ;
2277 buf_ret[ret_len] = '\0' ;
2281 VT_ProcessKeyPress (buf_ret);
2287 X_ButtonPress = aReport.xbutton.x;
2288 Y_ButtonPress = aReport.xbutton.y;
2290 if (aReport.xbutton.button == Button1)
2292 if (aReport.xbutton.state & ControlMask)
2294 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2298 IsDragged = Standard_True;
2299 DragFirst = Standard_True;
2302 else if (aReport.xbutton.button == Button3)
2305 VT_ProcessButton3Press();
2315 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2317 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2318 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2322 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2323 if( aContext.IsNull() )
2325 cout << "The context is null. Please use vinit before createmesh" << endl;
2329 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2330 if( aReport.xbutton.button==1 )
2334 aContext->ShiftSelect();
2343 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2344 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2345 ViewerTest::CurrentView());
2349 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2350 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2351 ViewerTest::CurrentView() );
2354 VT_ProcessButton3Release();
2356 IsDragged = Standard_False;
2359 VT_ProcessButton3Release();
2364 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2372 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2374 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2378 X_Motion = aReport.xmotion.x;
2379 Y_Motion = aReport.xmotion.y;
2380 DragFirst = Standard_False;
2382 Window aWindow = GetWindowHandle(VT_GetWindow());
2385 unsigned int aWidth, aHeight, aBorderWidth, aDepth;
2386 XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth);
2387 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2388 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed);
2389 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2393 X_Motion = aReport.xmotion.x;
2394 Y_Motion = aReport.xmotion.y;
2396 // remove all the ButtonMotionMaskr
2397 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2399 if ( aReport.xmotion.state & ControlMask ) {
2400 if ( aReport.xmotion.state & Button1Mask ) {
2401 ProcessControlButton1Motion();
2403 else if ( aReport.xmotion.state & Button2Mask ) {
2404 VT_ProcessControlButton2Motion();
2406 else if ( aReport.xmotion.state & Button3Mask ) {
2407 VT_ProcessControlButton3Motion();
2421 //==============================================================================
2422 //function : VProcessEvents
2423 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2424 // event in the Viewer window
2425 //==============================================================================
2427 static void VProcessEvents(ClientData,int)
2429 NCollection_Vector<int> anEventNumbers;
2430 // Get number of messages from every display
2431 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2432 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2434 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2436 // Handle events for every display
2437 int anEventIter = 0;
2438 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2439 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2441 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2442 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2444 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2445 int anEventResult = ViewerMainLoop( 0, NULL);
2446 // If window is closed or context was not found finish current event processing loop
2452 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2457 //==============================================================================
2458 //function : OSWindowSetup
2459 //purpose : Setup for the X11 window to be able to cath the event
2460 //==============================================================================
2463 static void OSWindowSetup()
2465 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2468 Window window = VT_GetWindow()->XWindow();
2469 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2470 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2471 XSynchronize(aDisplay, 1);
2473 // X11 : For keyboard on SUN
2475 wmhints.flags = InputHint;
2478 XSetWMHints( aDisplay, window, &wmhints);
2480 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2481 ButtonPressMask | ButtonReleaseMask |
2482 StructureNotifyMask |
2484 Button1MotionMask | Button2MotionMask |
2485 Button3MotionMask | FocusChangeMask
2487 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2488 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2490 XSynchronize(aDisplay, 0);
2498 //==============================================================================
2501 //purpose : Fitall, no DRAW arguments
2502 //Draw arg : No args
2503 //==============================================================================
2505 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgc, const char** theArgv)
2509 std::cout << "Wrong number of arguments! Use: vfit [-selected]" << std::endl;
2512 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2516 TCollection_AsciiString anArg (theArgv[1]);
2518 if (anArg == "-selected")
2520 ViewerTest::GetAISContext()->FitSelected (aView);
2524 if (aView.IsNull() == Standard_False) {
2531 //=======================================================================
2532 //function : VFitArea
2533 //purpose : Fit view to show area located between two points
2534 // : given in world 2D or 3D coordinates.
2535 //=======================================================================
2536 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2538 Handle(V3d_View) aView = ViewerTest::CurrentView();
2541 std::cerr << theArgVec[0] << "Error: No active view.\n";
2546 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2547 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2551 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2552 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2553 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2554 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2556 else if (theArgNb == 7)
2558 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2559 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2560 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2561 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2562 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2563 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2567 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2568 theDI.PrintHelp(theArgVec[0]);
2572 // Convert model coordinates to view space
2573 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2574 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2575 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2577 // Determine fit area
2578 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2579 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2581 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2583 if (aDiagonal < Precision::Confusion())
2585 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2589 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2593 //==============================================================================
2595 //purpose : ZFitall, no DRAW arguments
2596 //Draw arg : No args
2597 //==============================================================================
2598 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2600 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2602 if (aCurrentView.IsNull())
2604 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2610 aCurrentView->ZFitAll();
2611 aCurrentView->Redraw();
2615 Standard_Real aScale = 1.0;
2619 aScale = Draw::Atoi (theArgVec[1]);
2622 aCurrentView->ZFitAll (aScale);
2623 aCurrentView->Redraw();
2628 //==============================================================================
2629 //function : VRepaint
2631 //==============================================================================
2632 static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
2634 Handle(V3d_View) V = ViewerTest::CurrentView();
2635 if ( !V.IsNull() ) V->Redraw(); return 0;
2638 //==============================================================================
2640 //purpose : Remove all the object from the viewer
2641 //Draw arg : No args
2642 //==============================================================================
2644 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2646 Handle(V3d_View) V = ViewerTest::CurrentView();
2648 ViewerTest::Clear();
2652 //==============================================================================
2655 //==============================================================================
2657 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2658 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2661 di << argv[0] << "Invalid number of arguments\n";
2665 while (ViewerMainLoop( argc, argv)) {
2671 //==============================================================================
2673 //purpose : Load image as background
2674 //==============================================================================
2676 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2678 if (argc < 2 || argc > 3)
2680 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n";
2681 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n";
2685 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2686 if(AISContext.IsNull())
2688 di << "use 'vinit' command before " << argv[0] << "\n";
2692 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2695 const char* szType = argv[2];
2696 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2697 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2698 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2699 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2702 di << "Wrong fill type : " << szType << "\n";
2703 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
2708 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2709 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2714 //==============================================================================
2715 //function : VSetBgMode
2716 //purpose : Change background image fill type
2717 //==============================================================================
2719 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2723 di << "Usage : " << argv[0] << " filltype : Change background image mode\n";
2724 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n";
2728 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2729 if(AISContext.IsNull())
2731 di << "use 'vinit' command before " << argv[0] << "\n";
2734 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2735 const char* szType = argv[1];
2736 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2737 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2738 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2739 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2742 di << "Wrong fill type : " << szType << "\n";
2743 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
2746 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2747 V3dView->SetBgImageStyle(aFillType, Standard_True);
2751 //==============================================================================
2752 //function : VSetGradientBg
2753 //purpose : Mount gradient background
2754 //==============================================================================
2755 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2759 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background\n";
2760 di << "R1,G1,B1,R2,G2,B2 = [0..255]\n";
2761 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2762 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
2766 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2767 if(AISContext.IsNull())
2769 di << "use 'vinit' command before " << argv[0] << "\n";
2775 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2776 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2777 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2778 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2780 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2781 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2782 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2784 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2785 int aType = Draw::Atoi(argv[7]);
2786 if( aType < 0 || aType > 8 )
2788 di << "Wrong fill type \n";
2789 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2790 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
2794 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2796 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2797 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2803 //==============================================================================
2804 //function : VSetGradientBgMode
2805 //purpose : Change gradient background fill style
2806 //==============================================================================
2807 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2811 di << "Usage : " << argv[0] << " Type : Change gradient background fill type\n";
2812 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2813 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
2817 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2818 if(AISContext.IsNull())
2820 di << "use 'vinit' command before " << argv[0] << "\n";
2825 int aType = Draw::Atoi(argv[1]);
2826 if( aType < 0 || aType > 8 )
2828 di << "Wrong fill type \n";
2829 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2830 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
2834 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2836 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2837 V3dView->SetBgGradientStyle( aMethod, 1 );
2843 //==============================================================================
2844 //function : VSetColorBg
2845 //purpose : Set color background
2846 //==============================================================================
2847 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2851 di << "Usage : " << argv[0] << " R G B : Set color background\n";
2852 di << "R,G,B = [0..255]\n";
2856 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2857 if(AISContext.IsNull())
2859 di << "use 'vinit' command before " << argv[0] << "\n";
2865 Standard_Real R = Draw::Atof(argv[1])/255.;
2866 Standard_Real G = Draw::Atof(argv[2])/255.;
2867 Standard_Real B = Draw::Atof(argv[3])/255.;
2868 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2870 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2871 V3dView->SetBackgroundColor( aColor );
2878 //==============================================================================
2879 //function : VSetDefaultBg
2880 //purpose : Set default viewer background fill color
2881 //==============================================================================
2882 static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2887 std::cout << "Error: wrong syntax! See usage:\n";
2888 theDI.PrintHelp (theArgVec[0]);
2892 ViewerTest_DefaultBackground.FillMethod =
2893 theArgNb == 4 ? Aspect_GFM_NONE
2894 : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]);
2898 Standard_Real R = Draw::Atof (theArgVec[1]) / 255.;
2899 Standard_Real G = Draw::Atof (theArgVec[2]) / 255.;
2900 Standard_Real B = Draw::Atof (theArgVec[3]) / 255.;
2901 ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB);
2905 Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.;
2906 Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.;
2907 Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.;
2908 ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB);
2910 Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.;
2911 Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.;
2912 Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.;
2913 ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB);
2916 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
2917 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
2919 const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer();
2920 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
2921 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
2922 ViewerTest_DefaultBackground.GradientColor2,
2923 ViewerTest_DefaultBackground.FillMethod);
2929 //==============================================================================
2931 //purpose : View Scaling
2932 //==============================================================================
2934 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2936 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2937 if ( V3dView.IsNull() ) return 1;
2940 di << argv[0] << "Invalid number of arguments\n";
2943 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2946 //==============================================================================
2947 //function : VZBuffTrihedron
2949 //==============================================================================
2951 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
2952 Standard_Integer theArgNb,
2953 const char** theArgVec)
2955 Handle(V3d_View) aView = ViewerTest::CurrentView();
2958 std::cout << "Error: no active viewer!\n";
2962 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
2964 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2965 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
2966 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
2967 Quantity_Color anArrowColorX = Quantity_NOC_RED;
2968 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
2969 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
2970 Standard_Real aScale = 0.1;
2971 Standard_Real aSizeRatio = 0.8;
2972 Standard_Real anArrowDiam = 0.05;
2973 Standard_Integer aNbFacets = 12;
2974 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2976 Standard_CString anArg = theArgVec[anArgIter];
2977 TCollection_AsciiString aFlag (anArg);
2979 if (anUpdateTool.parseRedrawMode (aFlag))
2983 else if (aFlag == "-on")
2987 else if (aFlag == "-off")
2989 aView->TriedronErase();
2992 else if (aFlag == "-pos"
2993 || aFlag == "-position"
2994 || aFlag == "-corner")
2996 if (++anArgIter >= theArgNb)
2998 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3002 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3003 aPosName.LowerCase();
3004 if (aPosName == "center")
3006 aPosition = Aspect_TOTP_CENTER;
3008 else if (aPosName == "left_lower"
3009 || aPosName == "lower_left"
3010 || aPosName == "leftlower"
3011 || aPosName == "lowerleft")
3013 aPosition = Aspect_TOTP_LEFT_LOWER;
3015 else if (aPosName == "left_upper"
3016 || aPosName == "upper_left"
3017 || aPosName == "leftupper"
3018 || aPosName == "upperleft")
3020 aPosition = Aspect_TOTP_LEFT_UPPER;
3022 else if (aPosName == "right_lower"
3023 || aPosName == "lower_right"
3024 || aPosName == "rightlower"
3025 || aPosName == "lowerright")
3027 aPosition = Aspect_TOTP_RIGHT_LOWER;
3029 else if (aPosName == "right_upper"
3030 || aPosName == "upper_right"
3031 || aPosName == "rightupper"
3032 || aPosName == "upperright")
3034 aPosition = Aspect_TOTP_RIGHT_UPPER;
3038 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3042 else if (aFlag == "-type")
3044 if (++anArgIter >= theArgNb)
3046 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3050 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3051 aTypeName.LowerCase();
3052 if (aTypeName == "wireframe"
3053 || aTypeName == "wire")
3055 aVisType = V3d_WIREFRAME;
3057 else if (aTypeName == "zbuffer"
3058 || aTypeName == "shaded")
3060 aVisType = V3d_ZBUFFER;
3064 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3067 else if (aFlag == "-scale")
3069 if (++anArgIter >= theArgNb)
3071 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3075 aScale = Draw::Atof (theArgVec[anArgIter]);
3077 else if (aFlag == "-size"
3078 || aFlag == "-sizeratio")
3080 if (++anArgIter >= theArgNb)
3082 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3086 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3088 else if (aFlag == "-arrowdiam"
3089 || aFlag == "-arrowdiameter")
3091 if (++anArgIter >= theArgNb)
3093 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3097 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3099 else if (aFlag == "-nbfacets")
3101 if (++anArgIter >= theArgNb)
3103 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3107 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3109 else if (aFlag == "-colorlabel"
3110 || aFlag == "-colorlabels")
3112 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3113 theArgVec + anArgIter + 1,
3117 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3120 anArgIter += aNbParsed;
3122 else if (aFlag == "-colorarrowx")
3124 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3125 theArgVec + anArgIter + 1,
3129 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3132 anArgIter += aNbParsed;
3134 else if (aFlag == "-colorarrowy")
3136 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3137 theArgVec + anArgIter + 1,
3141 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3144 anArgIter += aNbParsed;
3146 else if (aFlag == "-colorarrowz")
3148 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3149 theArgVec + anArgIter + 1,
3153 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3156 anArgIter += aNbParsed;
3160 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3165 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3166 aSizeRatio, anArrowDiam, aNbFacets);
3167 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
3172 //==============================================================================
3173 //function : VRotate
3174 //purpose : Camera Rotating
3175 //==============================================================================
3177 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3179 Handle(V3d_View) aView = ViewerTest::CurrentView();
3182 std::cout << "No active view!\n";
3186 Standard_Boolean hasFlags = Standard_False;
3187 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3189 Standard_CString anArg (theArgVec[anArgIter]);
3190 TCollection_AsciiString aFlag (anArg);
3192 if (aFlag == "-mousestart"
3193 || aFlag == "-mousefrom")
3195 hasFlags = Standard_True;
3196 if (anArgIter + 2 >= theArgNb)
3198 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3202 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3203 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3204 aView->StartRotation (anX, anY);
3206 else if (aFlag == "-mousemove")
3208 hasFlags = Standard_True;
3209 if (anArgIter + 2 >= theArgNb)
3211 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3215 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3216 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3217 aView->Rotation (anX, anY);
3219 else if (theArgNb != 4
3222 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3231 else if (theArgNb == 4)
3233 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3234 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3235 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3236 aView->Rotate (anAX, anAY, anAZ);
3239 else if (theArgNb == 7)
3241 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3242 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3243 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3245 Standard_Real anX = Draw::Atof (theArgVec[4]);
3246 Standard_Real anY = Draw::Atof (theArgVec[5]);
3247 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3249 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3253 std::cout << "Error: Invalid number of arguments\n";
3257 //==============================================================================
3259 //purpose : View zoom in / out (relative to current zoom)
3260 //==============================================================================
3262 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3263 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3264 if ( V3dView.IsNull() ) {
3269 Standard_Real coef = Draw::Atof(argv[1]);
3270 if ( coef <= 0.0 ) {
3271 di << argv[1] << "Invalid value\n";
3274 V3dView->SetZoom( Draw::Atof(argv[1]) );
3277 di << argv[0] << " Invalid number of arguments\n";
3282 //==============================================================================
3284 //purpose : View panning (in pixels)
3285 //==============================================================================
3287 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3288 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3289 if ( V3dView.IsNull() ) return 1;
3292 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
3295 di << argv[0] << " Invalid number of arguments\n";
3300 //==============================================================================
3302 //purpose : Place the point (in pixels) at the center of the window
3303 //==============================================================================
3304 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3306 Handle(V3d_View) aView = ViewerTest::CurrentView();
3309 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3315 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3319 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3324 //==============================================================================
3325 //function : VExport
3326 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
3327 //==============================================================================
3329 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3331 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3332 if (V3dView.IsNull())
3337 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
3341 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
3342 TCollection_AsciiString aFormatStr;
3344 TCollection_AsciiString aFileName (argv[1]);
3345 Standard_Integer aLen = aFileName.Length();
3349 aFormatStr = TCollection_AsciiString (argv[2]);
3353 if (aFileName.Value (aLen - 2) == '.')
3355 aFormatStr = aFileName.ToCString() + aLen - 2;
3357 else if (aFileName.Value (aLen - 3) == '.')
3359 aFormatStr = aFileName.ToCString() + aLen - 3;
3363 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3369 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3373 aFormatStr.UpperCase();
3374 if (aFormatStr == "PS")
3375 anExpFormat = Graphic3d_EF_PostScript;
3376 else if (aFormatStr == "EPS")
3377 anExpFormat = Graphic3d_EF_EnhPostScript;
3378 else if (aFormatStr == "TEX")
3379 anExpFormat = Graphic3d_EF_TEX;
3380 else if (aFormatStr == "PDF")
3381 anExpFormat = Graphic3d_EF_PDF;
3382 else if (aFormatStr == "SVG")
3383 anExpFormat = Graphic3d_EF_SVG;
3384 else if (aFormatStr == "PGF")
3385 anExpFormat = Graphic3d_EF_PGF;
3386 else if (aFormatStr == "EMF")
3387 anExpFormat = Graphic3d_EF_EMF;
3390 std::cout << "Invalid export format '" << aFormatStr << "'\n";
3396 Standard_DISABLE_DEPRECATION_WARNINGS
3397 if (!V3dView->Export (argv[1], anExpFormat))
3398 Standard_ENABLE_DEPRECATION_WARNINGS
3400 di << "Error: export of image to " << aFormatStr << " failed!\n";
3403 catch (Standard_Failure)
3405 di << "Error: export of image to " << aFormatStr << " failed";
3406 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
3411 //==============================================================================
3412 //function : VColorScale
3413 //purpose : representation color scale
3414 //==============================================================================
3416 static Standard_Boolean checkColor (const TCollection_AsciiString& theRed,
3417 const TCollection_AsciiString& theGreen,
3418 const TCollection_AsciiString& theBlue,
3419 Standard_Real& theRedValue,
3420 Standard_Real& theGreenValue,
3421 Standard_Real& theBlueValue)
3423 if (!theRed.IsRealValue()
3424 || !theGreen.IsRealValue()
3425 || !theBlue.IsRealValue())
3427 std::cout << "Error: RGB color values should be real!\n";
3428 return Standard_True;
3430 theRedValue = theRed .RealValue();
3431 theGreenValue = theGreen.RealValue();
3432 theBlueValue = theBlue .RealValue();
3433 if (theRedValue < 0.0 || theRedValue > 1.0
3434 || theGreenValue < 0.0 || theGreenValue > 1.0
3435 || theBlueValue < 0.0 || theBlueValue > 1.0)
3437 std::cout << "Error: RGB color values should be within range 0..1!\n";
3438 return Standard_True;
3440 return Standard_False;
3443 static int VColorScale (Draw_Interpretor& theDI,
3444 Standard_Integer theArgNb,
3445 const char** theArgVec)
3447 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3448 Handle(V3d_View) aView = ViewerTest::CurrentView();
3449 if (aContext.IsNull())
3451 std::cout << "Error: no active view!\n";
3456 std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n";
3460 Handle(AIS_ColorScale) aCS;
3462 Handle(AIS_InteractiveObject) anIObj;
3463 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
3465 aCS = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
3468 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
3474 aCS = new AIS_ColorScale();
3475 GetMapOfAIS().Bind (aCS,theArgVec[1]);
3478 if (aCS->ZLayer() != Graphic3d_ZLayerId_TopOSD)
3480 aCS->SetZLayer (Graphic3d_ZLayerId_TopOSD);
3482 if (aCS->TransformPersistence().IsNull()
3483 || aCS->TransformPersistence()->Mode() != Graphic3d_TMF_2d)
3485 aContext->SetTransformPersistence (aCS, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
3488 Standard_Real aMinRange = aCS->GetMin();
3489 Standard_Real aMaxRange = aCS->GetMax();
3490 Standard_Integer aBreadth = aCS->GetBreadth();
3491 Standard_Integer aHeight = aCS->GetHeight();
3492 Standard_Integer aNbIntervals = aCS->GetNumberOfIntervals();
3493 Standard_Integer aTextHeight = aCS->GetTextHeight();
3494 Aspect_TypeOfColorScalePosition aLabPosition = aCS->GetLabelPosition();
3495 Standard_Integer aPosX = aCS->GetXPosition();
3496 Standard_Integer aPosY = aCS->GetYPosition();
3498 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
3502 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
3503 << "Min range: " << aMinRange << "\n"
3504 << "Max range: " << aMaxRange << "\n"
3505 << "Number of intervals: " << aNbIntervals << "\n"
3506 << "Text height: " << aTextHeight << "\n"
3507 << "Color scale position: " << aPosX <<" "<< aPosY<< "\n"
3508 << "Color scale title: " << aCS->GetTitle() << "\n"
3509 << "Label position: ";
3510 switch (aLabPosition)
3512 case Aspect_TOCSP_NONE:
3515 case Aspect_TOCSP_LEFT:
3518 case Aspect_TOCSP_RIGHT:
3521 case Aspect_TOCSP_CENTER:
3522 theDI << "Center\n";
3528 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
3530 Standard_CString anArg = theArgVec[anArgIter];
3531 TCollection_AsciiString aFlag (anArg);
3533 if (anUpdateTool.parseRedrawMode (aFlag))
3537 else if (aFlag == "-range")
3539 if (anArgIter + 3 >= theArgNb)
3541 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3545 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
3546 TCollection_AsciiString anArg2 (theArgVec[++anArgIter]);
3547 TCollection_AsciiString anArg3 (theArgVec[++anArgIter]);
3548 if (!anArg1.IsRealValue())
3550 std::cout << "Error: the minRange value should be real!\n";
3553 else if (!anArg2.IsRealValue())
3555 std::cout << "Error: the maxRange value should be real!\n";
3558 else if (!anArg3.IsIntegerValue())
3560 std::cout << "Error: the number of intervals should be integer!\n";
3564 aMinRange = anArg1.RealValue();
3565 aMaxRange = anArg2.RealValue();
3566 aNbIntervals = anArg3.IntegerValue();
3568 else if (aFlag == "-font")
3570 if (anArgIter + 1 >= theArgNb)
3572 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3575 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
3576 if (!aFontArg.IsIntegerValue())
3578 std::cout << "Error: HeightFont value should be integer!\n";
3582 aTextHeight = aFontArg.IntegerValue();
3585 else if (aFlag == "-textpos")
3587 if (anArgIter + 1 >= theArgNb)
3589 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3592 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
3593 aTextPosArg.LowerCase();
3594 if (aTextPosArg == "none")
3596 aLabPosition = Aspect_TOCSP_NONE;
3598 else if (aTextPosArg == "left")
3600 aLabPosition = Aspect_TOCSP_LEFT;
3602 else if (aTextPosArg == "right")
3604 aLabPosition = Aspect_TOCSP_RIGHT;
3606 else if (aTextPosArg == "center")
3608 aLabPosition = Aspect_TOCSP_CENTER;
3612 std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
3616 else if (aFlag == "-logarithmic"
3619 if (anArgIter + 1 >= theArgNb)
3621 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3624 Standard_Boolean IsLog;
3625 if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
3627 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3630 aCS->SetLogarithmic (IsLog);
3632 else if (aFlag == "-xy")
3634 if (anArgIter + 2 >= theArgNb)
3636 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3640 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3641 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3642 if (!aX.IsIntegerValue()
3643 || !aY.IsIntegerValue())
3645 std::cout << "Error: coordinates should be integer values!\n";
3649 aPosX = aX.IntegerValue();
3650 aPosY = aY.IntegerValue();
3652 else if (aFlag == "-width"
3655 if (anArgIter + 1 >= theArgNb)
3657 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3661 TCollection_AsciiString aW (theArgVec[++anArgIter]);
3662 if (!aW.IsIntegerValue())
3664 std::cout << "Error: a width should be an integer value!\n";
3668 aBreadth = aW.IntegerValue();
3670 else if (aFlag == "-height"
3673 if (anArgIter + 1 >= theArgNb)
3675 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3679 TCollection_AsciiString aH (theArgVec[++anArgIter]);
3680 if (!aH.IsIntegerValue())
3682 std::cout << "Error: a width should be an integer value!\n";
3686 aHeight = aH.IntegerValue();
3688 else if (aFlag == "-color")
3690 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3692 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3696 Quantity_NameOfColor aColorName;
3697 if (anArgIter + 4 >= theArgNb)
3699 if (anArgIter + 2 >= theArgNb)
3701 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3704 else if (!Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3706 std::cout << "Error: wrong color name: '" << theArgVec[anArgIter + 2] << "' !\n";
3711 TCollection_AsciiString anInd (theArgVec[anArgIter + 1]);
3712 if (!anInd.IsIntegerValue())
3714 std::cout << "Error: Index value should be integer!\n";
3718 Standard_Integer anIndex = anInd.IntegerValue();
3719 if (anIndex <= 0 || anIndex > aNbIntervals)
3721 std::cout << "Error: Index value should be within range 1.." << aNbIntervals <<"!\n";
3725 if (Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3727 aCS->SetIntervalColor (Quantity_Color (aColorName), anIndex);
3728 aCS->SetColorType (Aspect_TOCSD_USER);
3733 TCollection_AsciiString aRed (theArgVec[anArgIter + 2]);
3734 TCollection_AsciiString aGreen (theArgVec[anArgIter + 3]);
3735 TCollection_AsciiString aBlue (theArgVec[anArgIter + 4]);
3736 Standard_Real aRedValue,aGreenValue, aBlueValue;
3737 if(checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3741 aCS->SetIntervalColor (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB), anIndex);
3742 aCS->SetColorType (Aspect_TOCSD_USER);
3745 else if (aFlag == "-label")
3747 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3749 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
3752 else if (anArgIter + 2 >= theArgNb)
3754 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3758 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
3759 if (anIndex <= 0 || anIndex > aNbIntervals+1)
3761 std::cout << "Error: Index value should be within range 1.." << aNbIntervals+1 <<"!\n";
3765 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
3766 aCS->SetLabel (aText, anIndex);
3767 aCS->SetLabelType (Aspect_TOCSD_USER);
3770 else if (aFlag == "-colors")
3772 Aspect_SequenceOfColor aSeq;
3773 if (anArgIter + aNbIntervals + 1 > theArgNb)
3775 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3776 << aNbIntervals << " intervals\n";
3780 Standard_Integer aColorIter = anArgIter + 1;
3781 while (aColorIter < theArgNb)
3783 if (theArgVec[aColorIter][0] == '-')
3788 else if (theArgVec[aColorIter][0] >= 97
3789 && theArgVec[aColorIter][0] <= 122)
3791 Quantity_NameOfColor aColorName;
3792 if (!Quantity_Color::ColorFromName (theArgVec[aColorIter], aColorName))
3794 std::cout << "Error: wrong color name: " << theArgVec[aColorIter] << " !\n";
3797 aSeq.Append (Quantity_Color (aColorName));
3803 TCollection_AsciiString aRed (theArgVec[aColorIter]);
3804 TCollection_AsciiString aGreen (theArgVec[aColorIter + 1]);
3805 TCollection_AsciiString aBlue (theArgVec[aColorIter + 2]);
3806 Standard_Real aRedValue,aGreenValue, aBlueValue;
3807 if (checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3811 aSeq.Append (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB));
3816 if (aSeq.Length() < aNbIntervals)
3818 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3819 << aNbIntervals << " intervals\n";
3823 aCS->SetColors (aSeq);
3824 aCS->SetColorType (Aspect_TOCSD_USER);
3826 else if (aFlag == "-labels")
3828 if (anArgIter + aNbIntervals + 1 >= theArgNb)
3830 std::cout << "Error: not enough arguments! You should provide " << (aNbIntervals + 1)
3831 << " text labels for " << aNbIntervals << " intervals.\n";
3835 TColStd_SequenceOfExtendedString aSeq;
3836 for (int aLabelIter = anArgIter + 1; aLabelIter <= anArgIter + aNbIntervals + 1; aLabelIter += 1)
3838 aSeq.Append (TCollection_ExtendedString (theArgVec[aLabelIter]));
3840 aCS->SetLabels (aSeq);
3841 aCS->SetLabelType (Aspect_TOCSD_USER);
3842 anArgIter += aSeq.Length();
3844 else if (aFlag == "-title")
3846 if (anArgIter + 1 >= theArgNb)
3848 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3852 Standard_Boolean isTwoArgs = Standard_False;
3853 if (anArgIter + 2 < theArgNb)
3855 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
3856 aSecondArg.LowerCase();
3857 if (aSecondArg == "none")
3859 aCS->SetTitlePosition (Aspect_TOCSP_NONE);
3860 isTwoArgs = Standard_True;
3862 else if (aSecondArg == "left")
3864 aCS->SetTitlePosition (Aspect_TOCSP_LEFT);
3865 isTwoArgs = Standard_True;
3867 else if (aSecondArg == "right")
3869 aCS->SetTitlePosition (Aspect_TOCSP_RIGHT);
3870 isTwoArgs = Standard_True;
3872 else if (aSecondArg == "center")
3874 aCS->SetTitlePosition (Aspect_TOCSP_CENTER);
3875 isTwoArgs = Standard_True;
3879 aCS->SetTitle (theArgVec[anArgIter + 1]);
3886 else if (aFlag == "-demoversion"
3887 || aFlag == "-demo")
3897 aLabPosition = Aspect_TOCSP_RIGHT;
3898 aCS->SetColorType (Aspect_TOCSD_AUTO);
3899 aCS->SetLabelType (Aspect_TOCSD_AUTO);
3901 else if (aFlag == "-findcolor")
3903 if (anArgIter + 1 >= theArgNb)
3905 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3909 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
3911 if (!anArg1.IsRealValue())
3913 std::cout << "Error: the value should be real!\n";
3917 Quantity_Color aColor;
3918 aCS->FindColor (anArg1.RealValue(), aColor);
3919 theDI << Quantity_Color::StringName (aColor.Name());
3924 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
3928 if (!aBreadth || !aHeight)
3930 Standard_Integer aWinWidth, aWinHeight;
3931 aView->Window()->Size (aWinWidth, aWinHeight);
3934 aBreadth = aWinWidth;
3938 aHeight = aWinHeight;
3941 aCS->SetSize (aBreadth, aHeight);
3942 aCS->SetPosition (aPosX, aPosY);
3943 aCS->SetTextHeight (aTextHeight);
3944 aCS->SetRange (aMinRange, aMaxRange);
3945 aCS->SetNumberOfIntervals (aNbIntervals);
3946 aCS->SetLabelPosition (aLabPosition);
3947 // aCS->SetColor (aView->BackgroundColor().Invert());
3949 aContext->Display (aCS);
3954 //==============================================================================
3955 //function : VGraduatedTrihedron
3956 //purpose : Displays or hides a graduated trihedron
3957 //==============================================================================
3958 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
3959 Quantity_Color& theColor)
3961 Quantity_NameOfColor aColorName;
3962 TCollection_AsciiString aVal = theValue;
3964 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
3966 return Standard_False;
3968 theColor = Quantity_Color (aColorName);
3969 return Standard_True;
3972 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
3976 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
3977 << theArgs[0] <<"' for more information.\n";
3978 return 1; //TCL_ERROR
3981 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
3982 TCollection_AsciiString aParseKey;
3983 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
3985 TCollection_AsciiString anArg (theArgs [anArgIt]);
3987 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3990 aParseKey.Remove (1);
3991 aParseKey.LowerCase();
3992 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
3996 if (aParseKey.IsEmpty())
4001 aMapOfArgs(aParseKey)->Append (anArg);
4005 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
4006 aMapIt.More(); aMapIt.Next())
4008 const TCollection_AsciiString& aKey = aMapIt.Key();
4009 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
4011 // Bool key, without arguments
4012 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
4013 && anArgs->IsEmpty())
4019 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
4020 && anArgs->Length() == 1)
4026 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
4027 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
4028 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
4029 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
4030 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
4035 // One string argument
4036 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
4037 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
4038 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4043 // One integer argument
4044 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
4045 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
4046 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
4047 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
4048 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
4053 // One real argument
4054 if ( aKey.IsEqual ("arrowlength")
4055 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
4060 // Two string arguments
4061 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
4062 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4067 TCollection_AsciiString aLowerKey;
4070 aLowerKey.LowerCase();
4071 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
4072 std::cout << "Type help for more information.\n";
4076 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4077 if (anAISContext.IsNull())
4079 std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n";
4083 Standard_Boolean toDisplay = Standard_True;
4084 Quantity_Color aColor;
4085 Graphic3d_GraduatedTrihedron aTrihedronData;
4086 // Process parameters
4087 Handle(TColStd_HSequenceOfAsciiString) aValues;
4088 if (aMapOfArgs.Find ("off", aValues))
4090 toDisplay = Standard_False;
4094 if (aMapOfArgs.Find ("xname", aValues))
4096 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
4098 if (aMapOfArgs.Find ("yname", aValues))
4100 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
4102 if (aMapOfArgs.Find ("zname", aValues))
4104 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
4106 if (aMapOfArgs.Find ("xdrawname", aValues))
4108 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4110 if (aMapOfArgs.Find ("ydrawname", aValues))
4112 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4114 if (aMapOfArgs.Find ("zdrawname", aValues))
4116 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4118 if (aMapOfArgs.Find ("xnameoffset", aValues))
4120 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4122 if (aMapOfArgs.Find ("ynameoffset", aValues))
4124 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4126 if (aMapOfArgs.Find ("znameoffset", aValues))
4128 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4132 if (aMapOfArgs.Find ("xnamecolor", aValues))
4134 if (!GetColor (aValues->Value(1), aColor))
4136 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
4139 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
4141 if (aMapOfArgs.Find ("ynamecolor", aValues))
4143 if (!GetColor (aValues->Value(1), aColor))
4145 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
4148 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
4150 if (aMapOfArgs.Find ("znamecolor", aValues))
4152 if (!GetColor (aValues->Value(1), aColor))
4154 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
4157 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
4159 if (aMapOfArgs.Find ("xcolor", aValues))
4161 if (!GetColor (aValues->Value(1), aColor))
4163 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
4166 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
4168 if (aMapOfArgs.Find ("ycolor", aValues))
4170 if (!GetColor (aValues->Value(1), aColor))
4172 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
4175 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
4177 if (aMapOfArgs.Find ("zcolor", aValues))
4179 if (!GetColor (aValues->Value(1), aColor))
4181 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
4184 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
4188 if (aMapOfArgs.Find ("xticks", aValues))
4190 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4192 if (aMapOfArgs.Find ("yticks", aValues))
4194 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4196 if (aMapOfArgs.Find ("zticks", aValues))
4198 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4200 if (aMapOfArgs.Find ("xticklength", aValues))
4202 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4204 if (aMapOfArgs.Find ("yticklength", aValues))
4206 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4208 if (aMapOfArgs.Find ("zticklength", aValues))
4210 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4212 if (aMapOfArgs.Find ("xdrawticks", aValues))
4214 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4216 if (aMapOfArgs.Find ("ydrawticks", aValues))
4218 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4220 if (aMapOfArgs.Find ("zdrawticks", aValues))
4222 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4226 if (aMapOfArgs.Find ("xdrawvalues", aValues))
4228 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4230 if (aMapOfArgs.Find ("ydrawvalues", aValues))
4232 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4234 if (aMapOfArgs.Find ("zdrawvalues", aValues))
4236 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4238 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
4240 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4242 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
4244 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4246 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
4248 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4252 if (aMapOfArgs.Find ("arrowlength", aValues))
4254 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
4258 if (aMapOfArgs.Find ("namefont", aValues))
4260 aTrihedronData.SetNamesFont (aValues->Value(1));
4262 if (aMapOfArgs.Find ("valuesfont", aValues))
4264 aTrihedronData.SetValuesFont (aValues->Value(1));
4267 if (aMapOfArgs.Find ("drawgrid", aValues))
4269 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
4271 if (aMapOfArgs.Find ("drawaxes", aValues))
4273 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
4276 // The final step: display of erase trihedron
4279 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
4283 ViewerTest::CurrentView()->GraduatedTrihedronErase();
4286 ViewerTest::GetAISContext()->UpdateCurrentViewer();
4287 ViewerTest::CurrentView()->Redraw();
4292 //==============================================================================
4295 //==============================================================================
4296 static int VTile (Draw_Interpretor& theDI,
4297 Standard_Integer theArgNb,
4298 const char** theArgVec)
4300 Handle(V3d_View) aView = ViewerTest::CurrentView();
4303 std::cerr << "Error: no active viewer.\n";
4307 Graphic3d_CameraTile aTile = aView->Camera()->Tile();
4310 theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
4311 << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n"
4312 << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n";
4316 aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
4317 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4319 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4321 if (anArg == "-lowerleft"
4322 || anArg == "-upperleft")
4324 if (anArgIter + 3 < theArgNb)
4326 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4329 aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
4330 aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4331 aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4333 else if (anArg == "-total"
4334 || anArg == "-totalsize"
4335 || anArg == "-viewsize")
4337 if (anArgIter + 3 < theArgNb)
4339 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4342 aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4343 aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4344 if (aTile.TotalSize.x() < 1
4345 || aTile.TotalSize.y() < 1)
4347 std::cerr << "Error: total size is incorrect.\n";
4351 else if (anArg == "-tilesize")
4353 if (anArgIter + 3 < theArgNb)
4355 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4359 aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4360 aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4361 if (aTile.TileSize.x() < 1
4362 || aTile.TileSize.y() < 1)
4364 std::cerr << "Error: tile size is incorrect.\n";
4368 else if (anArg == "-unset")
4370 aView->Camera()->SetTile (Graphic3d_CameraTile());
4376 if (aTile.TileSize.x() < 1
4377 || aTile.TileSize.y() < 1)
4379 std::cerr << "Error: tile size is undefined.\n";
4382 else if (aTile.TotalSize.x() < 1
4383 || aTile.TotalSize.y() < 1)
4385 std::cerr << "Error: total size is undefined.\n";
4389 aView->Camera()->SetTile (aTile);
4394 //! Format ZLayer ID.
4395 inline const char* formZLayerId (const Standard_Integer theLayerId)
4399 case Graphic3d_ZLayerId_UNKNOWN: return "[INVALID]";
4400 case Graphic3d_ZLayerId_Default: return "[DEFAULT]";
4401 case Graphic3d_ZLayerId_Top: return "[TOP]";
4402 case Graphic3d_ZLayerId_Topmost: return "[TOPMOST]";
4403 case Graphic3d_ZLayerId_TopOSD: return "[OVERLAY]";
4404 case Graphic3d_ZLayerId_BotOSD: return "[UNDERLAY]";
4409 //! Print the ZLayer information.
4410 inline void printZLayerInfo (Draw_Interpretor& theDI,
4411 const Graphic3d_ZLayerSettings& theLayer)
4413 if (!theLayer.Name().IsEmpty())
4415 theDI << " Name: " << theLayer.Name() << "\n";
4417 if (theLayer.IsImmediate())
4419 theDI << " Immediate: TRUE\n";
4421 theDI << " Origin: " << theLayer.Origin().X() << " " << theLayer.Origin().Y() << " " << theLayer.Origin().Z() << "\n";
4422 theDI << " Depth test: " << (theLayer.ToEnableDepthTest() ? "enabled" : "disabled") << "\n";
4423 theDI << " Depth write: " << (theLayer.ToEnableDepthWrite() ? "enabled" : "disabled") << "\n";
4424 theDI << " Depth buffer clearing: " << (theLayer.ToClearDepth() ? "enabled" : "disabled") << "\n";
4425 if (theLayer.PolygonOffset().Mode != Aspect_POM_None)
4427 theDI << " Depth offset: " << theLayer.PolygonOffset().Factor << " " << theLayer.PolygonOffset().Units << "\n";
4431 //==============================================================================
4432 //function : VZLayer
4433 //purpose : Test z layer operations for v3d viewer
4434 //==============================================================================
4435 static int VZLayer (Draw_Interpretor& theDI,
4436 Standard_Integer theArgNb,
4437 const char** theArgVec)
4439 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4440 if (aContextAIS.IsNull())
4442 std::cout << "No active viewer!\n";
4446 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
4449 TColStd_SequenceOfInteger aLayers;
4450 aViewer->GetAllZLayers (aLayers);
4451 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4453 theDI << "ZLayer " << aLayeriter.Value() << " " << formZLayerId (aLayeriter.Value()) << "\n";
4454 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4455 printZLayerInfo (theDI, aSettings);
4460 Standard_Integer anArgIter = 1;
4461 Standard_Integer aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4462 ViewerTest_AutoUpdater anUpdateTool (aContextAIS, ViewerTest::CurrentView());
4463 if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
4468 TCollection_AsciiString aFirstArg (theArgVec[anArgIter]);
4469 if (aFirstArg.IsIntegerValue())
4472 aLayerId = aFirstArg.IntegerValue();
4476 aFirstArg.LowerCase();
4477 if (aFirstArg == "default"
4478 || aFirstArg == "def")
4480 aLayerId = Graphic3d_ZLayerId_Default;
4483 else if (aFirstArg == "top")
4485 aLayerId = Graphic3d_ZLayerId_Top;
4488 else if (aFirstArg == "topmost")
4490 aLayerId = Graphic3d_ZLayerId_Topmost;
4493 else if (aFirstArg == "overlay"
4494 || aFirstArg == "toposd")
4496 aLayerId = Graphic3d_ZLayerId_TopOSD;
4499 else if (aFirstArg == "underlay"
4500 || aFirstArg == "botosd")
4502 aLayerId = Graphic3d_ZLayerId_BotOSD;
4507 TColStd_SequenceOfInteger aLayers;
4508 aViewer->GetAllZLayers (aLayers);
4509 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4511 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
4512 if (TCollection_AsciiString::IsSameString (aSettings.Name(), aFirstArg, Standard_False))
4514 aLayerId = aLayeriter.Value();
4522 for (; anArgIter < theArgNb; ++anArgIter)
4524 // perform operation
4525 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4527 if (anUpdateTool.parseRedrawMode (anArg))
4531 else if (anArg == "-add"
4534 aLayerId = Graphic3d_ZLayerId_UNKNOWN;
4535 if (!aViewer->AddZLayer (aLayerId))
4537 std::cout << "Error: can not add a new z layer!\n";
4543 else if (anArg == "-del"
4544 || anArg == "-delete"
4547 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4549 if (++anArgIter >= theArgNb)
4551 std::cout << "Syntax error: id of z layer to remove is missing\n";
4555 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4558 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN
4559 || aLayerId == Graphic3d_ZLayerId_Default
4560 || aLayerId == Graphic3d_ZLayerId_Top
4561 || aLayerId == Graphic3d_ZLayerId_Topmost
4562 || aLayerId == Graphic3d_ZLayerId_TopOSD
4563 || aLayerId == Graphic3d_ZLayerId_BotOSD)
4565 std::cout << "Syntax error: standard Z layer can not be removed\n";
4569 // move all object displayed in removing layer to default layer
4570 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4571 anObjIter.More(); anObjIter.Next())
4573 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1());
4575 || aPrs->ZLayer() != aLayerId)
4579 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4582 if (!aViewer->RemoveZLayer (aLayerId))
4584 std::cout << "Z layer can not be removed!\n";
4588 theDI << aLayerId << " ";
4591 else if (anArg == "-get"
4594 TColStd_SequenceOfInteger aLayers;
4595 aViewer->GetAllZLayers (aLayers);
4596 for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
4598 theDI << aLayeriter.Value() << " ";
4603 else if (anArg == "-name")
4605 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4607 std::cout << "Syntax error: id of Z layer is missing\n";
4611 if (++anArgIter >= theArgNb)
4613 std::cout << "Syntax error: name is missing\n";
4617 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4618 aSettings.SetName (theArgVec[anArgIter]);
4619 aViewer->SetZLayerSettings (aLayerId, aSettings);
4621 else if (anArg == "-origin")
4623 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4625 std::cout << "Syntax error: id of Z layer is missing\n";
4629 if (anArgIter + 2 >= theArgNb)
4631 std::cout << "Syntax error: origin coordinates are missing\n";
4635 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4637 anOrigin.SetX (Draw::Atof (theArgVec[anArgIter + 1]));
4638 anOrigin.SetY (Draw::Atof (theArgVec[anArgIter + 2]));
4639 anOrigin.SetZ (0.0);
4640 if (anArgIter + 3 < theArgNb)
4642 anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter + 3]));
4649 aSettings.SetOrigin (anOrigin);
4650 aViewer->SetZLayerSettings (aLayerId, aSettings);
4652 else if (anArg == "-settings"
4653 || anArg == "settings")
4655 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4657 if (++anArgIter >= theArgNb)
4659 std::cout << "Syntax error: id of Z layer is missing\n";
4663 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4666 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4667 printZLayerInfo (theDI, aSettings);
4669 else if (anArg == "-enable"
4670 || anArg == "enable"
4671 || anArg == "-disable"
4672 || anArg == "disable")
4674 const Standard_Boolean toEnable = anArg == "-enable"
4675 || anArg == "enable";
4676 if (++anArgIter >= theArgNb)
4678 std::cout << "Syntax error: option name is missing\n";
4682 TCollection_AsciiString aSubOp (theArgVec[anArgIter]);
4684 if (aLayerId == Graphic3d_ZLayerId_UNKNOWN)
4686 if (++anArgIter >= theArgNb)
4688 std::cout << "Syntax error: id of Z layer is missing\n";
4692 aLayerId = Draw::Atoi (theArgVec[anArgIter]);
4695 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerId);
4696 if (aSubOp == "depthtest"
4697 || aSubOp == "test")
4699 aSettings.SetEnableDepthTest (toEnable);
4701 else if (aSubOp == "depthwrite"
4702 || aSubOp == "write")
4704 aSettings.SetEnableDepthWrite (toEnable);
4706 else if (aSubOp == "depthclear"
4707 || aSubOp == "clear")
4709 aSettings.SetClearDepth (toEnable);
4711 else if (aSubOp == "depthoffset"
4712 || aSubOp == "offset")
4714 Graphic3d_PolygonOffset aParams;
4715 aParams.Mode = toEnable ? Aspect_POM_Fill : Aspect_POM_None;
4718 if (anArgIter + 2 >= theArgNb)
4720 std::cout << "Syntax error: factor and units values for depth offset are missing\n";
4724 aParams.Factor = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
4725 aParams.Units = static_cast<Standard_ShortReal> (Draw::Atof (theArgVec[++anArgIter]));
4727 aSettings.SetPolygonOffset (aParams);
4729 else if (aSubOp == "positiveoffset"
4730 || aSubOp == "poffset")
4734 aSettings.SetDepthOffsetPositive();
4738 aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
4741 else if (aSubOp == "negativeoffset"
4742 || aSubOp == "noffset")
4746 aSettings.SetDepthOffsetNegative();
4750 aSettings.SetPolygonOffset(Graphic3d_PolygonOffset());
4753 else if (aSubOp == "textureenv")
4755 aSettings.SetEnvironmentTexture (toEnable);
4758 aViewer->SetZLayerSettings (aLayerId, aSettings);
4762 std::cout << "Syntax error: unknown option " << theArgVec[anArgIter] << "\n";
4770 // The interactive presentation of 2d layer item
4771 // for "vlayerline" command it provides a presentation of
4772 // line with user-defined linewidth, linetype and transparency.
4773 class V3d_LineItem : public AIS_InteractiveObject
4777 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
4780 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4781 Standard_Real X2, Standard_Real Y2,
4782 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
4783 Standard_Real theWidth = 0.5,
4784 Standard_Real theTransp = 1.0);
4788 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4789 const Handle(Prs3d_Presentation)& thePresentation,
4790 const Standard_Integer theMode) Standard_OVERRIDE;
4792 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
4793 const Standard_Integer /*aMode*/) Standard_OVERRIDE
4798 Standard_Real myX1, myY1, myX2, myY2;
4799 Aspect_TypeOfLine myType;
4800 Standard_Real myWidth;
4803 // default constructor for line item
4804 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4805 Standard_Real X2, Standard_Real Y2,
4806 Aspect_TypeOfLine theType,
4807 Standard_Real theWidth,
4808 Standard_Real theTransp) :
4809 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
4810 myType(theType), myWidth(theWidth)
4812 SetTransparency (1-theTransp);
4816 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
4817 const Handle(Prs3d_Presentation)& thePresentation,
4818 const Standard_Integer /*theMode*/)
4820 thePresentation->Clear();
4821 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
4822 Standard_Integer aWidth, aHeight;
4823 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
4824 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
4825 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
4826 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
4827 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
4828 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
4829 aGroup->SetPrimitivesAspect (anAspect->Aspect());
4830 aGroup->AddPrimitiveArray (aPrim);
4833 //=============================================================================
4834 //function : VLayerLine
4835 //purpose : Draws line in the v3d view layer with given attributes: linetype,
4836 // : linewidth, transparency coefficient
4837 //============================================================================
4838 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4840 // get the active view
4841 Handle(V3d_View) aView = ViewerTest::CurrentView();
4844 di << "Call vinit before!\n";
4849 di << "Use: " << argv[0];
4850 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
4851 di << " linetype : { 0 | 1 | 2 | 3 } \n";
4852 di << " 0 - solid \n";
4853 di << " 1 - dashed \n";
4854 di << " 2 - dot \n";
4855 di << " 3 - dashdot\n";
4856 di << " transparency : { 0.0 - 1.0 } \n";
4857 di << " 0.0 - transparent\n";
4858 di << " 1.0 - visible \n";
4862 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4863 // get the input params
4864 Standard_Real X1 = Draw::Atof(argv[1]);
4865 Standard_Real Y1 = Draw::Atof(argv[2]);
4866 Standard_Real X2 = Draw::Atof(argv[3]);
4867 Standard_Real Y2 = Draw::Atof(argv[4]);
4869 Standard_Real aWidth = 0.5;
4870 Standard_Integer aType = 0;
4871 Standard_Real aTransparency = 1.0;
4875 aWidth = Draw::Atof(argv[5]);
4879 aType = (Standard_Integer) Draw::Atoi(argv[6]);
4884 aTransparency = Draw::Atof(argv[7]);
4885 if (aTransparency < 0 || aTransparency > 1.0)
4886 aTransparency = 1.0;
4889 // select appropriate line type
4890 Aspect_TypeOfLine aLineType;
4894 aLineType = Aspect_TOL_DASH;
4898 aLineType = Aspect_TOL_DOT;
4902 aLineType = Aspect_TOL_DOTDASH;
4906 aLineType = Aspect_TOL_SOLID;
4909 static Handle (V3d_LineItem) aLine;
4910 if (!aLine.IsNull())
4912 aContext->Erase (aLine);
4914 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
4918 aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER));
4919 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
4920 aLine->SetToUpdate();
4921 aContext->Display (aLine, Standard_True);
4927 //==============================================================================
4930 //==============================================================================
4932 static int VGrid (Draw_Interpretor& /*theDI*/,
4933 Standard_Integer theArgNb,
4934 const char** theArgVec)
4936 // get the active view
4937 Handle(V3d_View) aView = ViewerTest::CurrentView();
4938 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4939 if (aView.IsNull() || aViewer.IsNull())
4941 std::cerr << "No active view. Please call vinit.\n";
4945 Aspect_GridType aType = aViewer->GridType();
4946 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
4948 Standard_Integer anIter = 1;
4949 for (; anIter < theArgNb; ++anIter)
4951 const char* aValue = theArgVec[anIter];
4954 aType = Aspect_GT_Rectangular;
4956 else if (*aValue == 'c')
4958 aType = Aspect_GT_Circular;
4960 else if (*aValue == 'l')
4962 aMode = Aspect_GDM_Lines;
4964 else if (*aValue == 'p')
4966 aMode = Aspect_GDM_Points;
4968 else if (strcmp (aValue, "off" ) == 0)
4970 aViewer->DeactivateGrid();
4979 Standard_Integer aTail = (theArgNb - anIter);
4982 aViewer->ActivateGrid (aType, aMode);
4985 else if (aTail != 2 && aTail != 5)
4987 std::cerr << "Incorrect arguments number! Usage:\n"
4988 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
4992 Quantity_Length anOriginX, anOriginY;
4993 Quantity_PlaneAngle aRotAngle;
4994 if (aType == Aspect_GT_Rectangular)
4996 Quantity_Length aRStepX, aRStepY;
4997 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4999 anOriginX = Draw::Atof (theArgVec[anIter++]);
5000 anOriginY = Draw::Atof (theArgVec[anIter++]);
5003 aRStepX = Draw::Atof (theArgVec[anIter++]);
5004 aRStepY = Draw::Atof (theArgVec[anIter++]);
5005 aRotAngle = Draw::Atof (theArgVec[anIter++]);
5007 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
5008 aViewer->ActivateGrid (aType, aMode);
5010 else if (aType == Aspect_GT_Circular)
5012 Quantity_Length aRadiusStep;
5013 Standard_Integer aDivisionNumber;
5014 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
5016 anOriginX = Draw::Atof (theArgVec[anIter++]);
5017 anOriginY = Draw::Atof (theArgVec[anIter++]);
5020 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
5021 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
5022 aRotAngle = Draw::Atof (theArgVec[anIter++]);
5025 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
5026 aViewer->ActivateGrid (aType, aMode);
5032 //==============================================================================
5033 //function : VPriviledgedPlane
5035 //==============================================================================
5037 static int VPriviledgedPlane (Draw_Interpretor& theDI,
5038 Standard_Integer theArgNb,
5039 const char** theArgVec)
5041 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
5043 std::cerr << "Error: wrong number of arguments! See usage:\n";
5044 theDI.PrintHelp (theArgVec[0]);
5048 // get the active viewer
5049 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5050 if (aViewer.IsNull())
5052 std::cerr << "Error: no active viewer. Please call vinit.\n";
5058 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
5059 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
5060 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
5061 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
5062 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
5063 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
5064 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
5068 Standard_Integer anArgIdx = 1;
5069 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
5070 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
5071 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
5072 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
5073 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
5074 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
5076 gp_Ax3 aPriviledgedPlane;
5077 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
5078 gp_Dir aNorm (aNormX, aNormY, aNormZ);
5081 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
5082 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
5083 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
5084 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
5085 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
5089 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
5092 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
5097 //==============================================================================
5098 //function : VConvert
5100 //==============================================================================
5102 static int VConvert (Draw_Interpretor& theDI,
5103 Standard_Integer theArgNb,
5104 const char** theArgVec)
5106 // get the active view
5107 Handle(V3d_View) aView = ViewerTest::CurrentView();
5110 std::cerr << "Error: no active view. Please call vinit.\n";
5114 enum { Model, Ray, View, Window, Grid } aMode = Model;
5116 // access coordinate arguments
5117 TColStd_SequenceOfReal aCoord;
5118 Standard_Integer anArgIdx = 1;
5119 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
5121 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5122 if (!anArg.IsRealValue())
5126 aCoord.Append (anArg.RealValue());
5129 // non-numeric argument too early
5130 if (aCoord.IsEmpty())
5132 std::cerr << "Error: wrong number of arguments! See usage:\n";
5133 theDI.PrintHelp (theArgVec[0]);
5137 // collect all other arguments and options
5138 for (; anArgIdx < theArgNb; ++anArgIdx)
5140 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5142 if (anArg == "window") aMode = Window;
5143 else if (anArg == "view") aMode = View;
5144 else if (anArg == "grid") aMode = Grid;
5145 else if (anArg == "ray") aMode = Ray;
5148 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
5149 theDI.PrintHelp (theArgVec[0]);
5154 // complete input checks
5155 if ((aCoord.Length() == 1 && theArgNb > 3) ||
5156 (aCoord.Length() == 2 && theArgNb > 4) ||
5157 (aCoord.Length() == 3 && theArgNb > 5))
5159 std::cerr << "Error: wrong number of arguments! See usage:\n";
5160 theDI.PrintHelp (theArgVec[0]);
5164 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
5165 Standard_Integer aXYp[2] = {0, 0};
5167 // convert one-dimensional coordinate
5168 if (aCoord.Length() == 1)
5172 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer) aCoord (1)); return 0;
5173 case Window : theDI << "Window Vp: " << aView->Convert ((Quantity_Length) aCoord (1)); return 0;
5175 std::cerr << "Error: wrong arguments! See usage:\n";
5176 theDI.PrintHelp (theArgVec[0]);
5181 // convert 2D coordinates from projection or view reference space
5182 if (aCoord.Length() == 2)
5187 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5188 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5192 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5193 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5197 aView->Convert ((V3d_Coordinate) aCoord (1), (V3d_Coordinate) aCoord (2), aXYp[0], aXYp[1]);
5198 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5202 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5203 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5204 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5208 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5209 (Standard_Integer) aCoord (2),
5210 aXYZ[0], aXYZ[1], aXYZ[2],
5211 aXYZ[3], aXYZ[4], aXYZ[5]);
5212 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5216 std::cerr << "Error: wrong arguments! See usage:\n";
5217 theDI.PrintHelp (theArgVec[0]);
5222 // convert 3D coordinates from view reference space
5223 else if (aCoord.Length() == 3)
5228 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5229 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5233 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5234 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5238 std::cerr << "Error: wrong arguments! See usage:\n";
5239 theDI.PrintHelp (theArgVec[0]);
5247 //==============================================================================
5250 //==============================================================================
5252 static int VFps (Draw_Interpretor& theDI,
5253 Standard_Integer theArgNb,
5254 const char** theArgVec)
5256 // get the active view
5257 Handle(V3d_View) aView = ViewerTest::CurrentView();
5260 std::cerr << "No active view. Please call vinit.\n";
5264 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
5267 std::cerr << "Incorrect arguments!\n";
5271 // the time is meaningless for first call
5272 // due to async OpenGl rendering
5275 // redraw view in loop to estimate average values
5278 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
5284 const Standard_Real aTime = aTimer.ElapsedTime();
5285 aTimer.OSD_Chronometer::Show (aCpu);
5287 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
5288 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
5290 // return statistics
5291 theDI << "FPS: " << aFpsAver << "\n"
5292 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5294 // compute additional statistics in ray-tracing mode
5295 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
5297 if (aParams.Method == Graphic3d_RM_RAYTRACING)
5299 Standard_Integer aSizeX;
5300 Standard_Integer aSizeY;
5302 aView->Window()->Size (aSizeX, aSizeY);
5304 // 1 shadow ray and 1 secondary ray pew each bounce
5305 const Standard_Real aMRays = aSizeX * aSizeY * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
5307 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
5313 //==============================================================================
5314 //function : VGlDebug
5316 //==============================================================================
5318 static int VGlDebug (Draw_Interpretor& theDI,
5319 Standard_Integer theArgNb,
5320 const char** theArgVec)
5322 Handle(OpenGl_GraphicDriver) aDriver;
5323 Handle(V3d_View) aView = ViewerTest::CurrentView();
5324 if (!aView.IsNull())
5326 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5328 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
5329 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
5333 TCollection_AsciiString aDebActive, aSyncActive;
5340 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
5341 "GL_ARB_debug_output");
5342 aDebActive = isActive ? " (active)" : " (inactive)";
5345 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
5346 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
5350 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
5351 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
5352 << "glslWarn:" << (aCaps->glslWarnings ? "1" : "0") << "\n"
5353 << "extraMsg:" << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
5357 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5359 Standard_CString anArg = theArgVec[anArgIter];
5360 TCollection_AsciiString anArgCase (anArg);
5361 anArgCase.LowerCase();
5362 Standard_Boolean toEnableDebug = Standard_True;
5363 if (anArgCase == "-glsl"
5364 || anArgCase == "-glslwarn"
5365 || anArgCase == "-glslwarns"
5366 || anArgCase == "-glslwarnings")
5368 Standard_Boolean toShowWarns = Standard_True;
5369 if (++anArgIter < theArgNb
5370 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
5374 aDefCaps->glslWarnings = toShowWarns;
5377 aCaps->glslWarnings = toShowWarns;
5380 else if (anArgCase == "-extra"
5381 || anArgCase == "-extramsg"
5382 || anArgCase == "-extramessages")
5384 Standard_Boolean toShow = Standard_True;
5385 if (++anArgIter < theArgNb
5386 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
5390 aDefCaps->suppressExtraMsg = !toShow;
5393 aCaps->suppressExtraMsg = !toShow;
5396 else if (anArgCase == "-noextra"
5397 || anArgCase == "-noextramsg"
5398 || anArgCase == "-noextramessages")
5400 Standard_Boolean toSuppress = Standard_True;
5401 if (++anArgIter < theArgNb
5402 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
5406 aDefCaps->suppressExtraMsg = toSuppress;
5409 aCaps->suppressExtraMsg = toSuppress;
5412 else if (anArgCase == "-sync")
5414 Standard_Boolean toSync = Standard_True;
5415 if (++anArgIter < theArgNb
5416 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
5420 aDefCaps->contextSyncDebug = toSync;
5423 aDefCaps->contextDebug = Standard_True;
5426 else if (anArgCase == "-debug")
5428 if (++anArgIter < theArgNb
5429 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
5433 aDefCaps->contextDebug = toEnableDebug;
5435 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
5436 && (anArgIter + 1 == theArgNb))
5438 // simple alias to turn on almost everything
5439 aDefCaps->contextDebug = toEnableDebug;
5440 aDefCaps->contextSyncDebug = toEnableDebug;
5441 aDefCaps->glslWarnings = toEnableDebug;
5445 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
5453 //==============================================================================
5456 //==============================================================================
5458 static int VVbo (Draw_Interpretor& theDI,
5459 Standard_Integer theArgNb,
5460 const char** theArgVec)
5462 const Standard_Boolean toSet = (theArgNb > 1);
5463 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
5466 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
5470 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5471 if (aContextAIS.IsNull())
5475 std::cerr << "No active view!\n";
5479 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5480 if (!aDriver.IsNull())
5484 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
5488 aDriver->ChangeOptions().vboDisable = toUseVbo;
5495 //==============================================================================
5498 //==============================================================================
5500 static int VCaps (Draw_Interpretor& theDI,
5501 Standard_Integer theArgNb,
5502 const char** theArgVec)
5504 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
5505 Handle(OpenGl_GraphicDriver) aDriver;
5506 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5507 if (!aContext.IsNull())
5509 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
5510 aCaps = &aDriver->ChangeOptions();
5515 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
5516 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
5517 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
5518 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
5519 theDI << "VSync: " << aCaps->swapInterval << "\n";
5520 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
5521 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
5525 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5526 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5528 Standard_CString anArg = theArgVec[anArgIter];
5529 TCollection_AsciiString anArgCase (anArg);
5530 anArgCase.LowerCase();
5531 if (anUpdateTool.parseRedrawMode (anArg))
5535 else if (anArgCase == "-vsync"
5536 || anArgCase == "-swapinterval")
5538 Standard_Boolean toEnable = Standard_True;
5539 if (++anArgIter < theArgNb
5540 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5544 aCaps->swapInterval = toEnable;
5546 else if (anArgCase == "-ffp")
5548 Standard_Boolean toEnable = Standard_True;
5549 if (++anArgIter < theArgNb
5550 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5554 aCaps->ffpEnable = toEnable;
5556 else if (anArgCase == "-vbo")
5558 Standard_Boolean toEnable = Standard_True;
5559 if (++anArgIter < theArgNb
5560 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5564 aCaps->vboDisable = !toEnable;
5566 else if (anArgCase == "-sprite"
5567 || anArgCase == "-sprites")
5569 Standard_Boolean toEnable = Standard_True;
5570 if (++anArgIter < theArgNb
5571 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5575 aCaps->pntSpritesDisable = !toEnable;
5577 else if (anArgCase == "-softmode")
5579 Standard_Boolean toEnable = Standard_True;
5580 if (++anArgIter < theArgNb
5581 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5585 aCaps->contextNoAccel = toEnable;
5587 else if (anArgCase == "-accel"
5588 || anArgCase == "-acceleration")
5590 Standard_Boolean toEnable = Standard_True;
5591 if (++anArgIter < theArgNb
5592 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5596 aCaps->contextNoAccel = !toEnable;
5598 else if (anArgCase == "-compat"
5599 || anArgCase == "-compatprofile"
5600 || anArgCase == "-compatible"
5601 || anArgCase == "-compatibleprofile")
5603 Standard_Boolean toEnable = Standard_True;
5604 if (++anArgIter < theArgNb
5605 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5609 aCaps->contextCompatible = toEnable;
5610 if (!aCaps->contextCompatible)
5612 aCaps->ffpEnable = Standard_False;
5615 else if (anArgCase == "-core"
5616 || anArgCase == "-coreprofile")
5618 Standard_Boolean toEnable = Standard_True;
5619 if (++anArgIter < theArgNb
5620 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5624 aCaps->contextCompatible = !toEnable;
5625 if (!aCaps->contextCompatible)
5627 aCaps->ffpEnable = Standard_False;
5630 else if (anArgCase == "-stereo"
5631 || anArgCase == "-quadbuffer")
5633 Standard_Boolean toEnable = Standard_True;
5634 if (++anArgIter < theArgNb
5635 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5639 aCaps->contextStereo = toEnable;
5643 std::cout << "Error: unknown argument '" << anArg << "'\n";
5647 if (aCaps != &ViewerTest_myDefaultCaps)
5649 ViewerTest_myDefaultCaps = *aCaps;
5654 //==============================================================================
5655 //function : VMemGpu
5657 //==============================================================================
5659 static int VMemGpu (Draw_Interpretor& theDI,
5660 Standard_Integer theArgNb,
5661 const char** theArgVec)
5664 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5665 if (aContextAIS.IsNull())
5667 std::cerr << "No active view. Please call vinit.\n";
5671 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
5672 if (aDriver.IsNull())
5674 std::cerr << "Graphic driver not available.\n";
5678 Standard_Size aFreeBytes = 0;
5679 TCollection_AsciiString anInfo;
5680 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
5682 std::cerr << "Information not available.\n";
5686 if (theArgNb > 1 && *theArgVec[1] == 'f')
5688 theDI << Standard_Real (aFreeBytes);
5698 // ==============================================================================
5699 // function : VReadPixel
5701 // ==============================================================================
5702 static int VReadPixel (Draw_Interpretor& theDI,
5703 Standard_Integer theArgNb,
5704 const char** theArgVec)
5706 // get the active view
5707 Handle(V3d_View) aView = ViewerTest::CurrentView();
5710 std::cerr << "No active view. Please call vinit.\n";
5713 else if (theArgNb < 3)
5715 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
5719 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
5720 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
5722 Standard_Integer aWidth, aHeight;
5723 aView->Window()->Size (aWidth, aHeight);
5724 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
5725 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
5726 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
5728 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
5732 Standard_Boolean toShowName = Standard_False;
5733 Standard_Boolean toShowHls = Standard_False;
5734 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
5736 const char* aParam = theArgVec[anIter];
5737 if ( strcasecmp( aParam, "rgb" ) == 0 )
5739 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
5740 aBufferType = Graphic3d_BT_RGB;
5742 else if ( strcasecmp( aParam, "hls" ) == 0 )
5744 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
5745 aBufferType = Graphic3d_BT_RGB;
5746 toShowHls = Standard_True;
5748 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
5750 aFormat = Image_PixMap::ImgRGBF;
5751 aBufferType = Graphic3d_BT_RGB;
5753 else if ( strcasecmp( aParam, "rgba" ) == 0 )
5755 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
5756 aBufferType = Graphic3d_BT_RGBA;
5758 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
5760 aFormat = Image_PixMap::ImgRGBAF;
5761 aBufferType = Graphic3d_BT_RGBA;
5763 else if ( strcasecmp( aParam, "depth" ) == 0 )
5765 aFormat = Image_PixMap::ImgGrayF;
5766 aBufferType = Graphic3d_BT_Depth;
5768 else if ( strcasecmp( aParam, "name" ) == 0 )
5770 toShowName = Standard_True;
5774 Image_PixMap anImage;
5775 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
5777 std::cerr << "Image allocation failed\n";
5780 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
5782 std::cerr << "Image dump failed\n";
5786 Quantity_Parameter anAlpha;
5787 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
5790 if (aBufferType == Graphic3d_BT_RGBA)
5792 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha;
5796 theDI << Quantity_Color::StringName (aColor.Name());
5801 switch (aBufferType)
5804 case Graphic3d_BT_RGB:
5808 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation();
5812 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue();
5816 case Graphic3d_BT_RGBA:
5818 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha;
5821 case Graphic3d_BT_Depth:
5823 theDI << aColor.Red();
5832 //==============================================================================
5833 //function : VDiffImage
5834 //purpose : The draw-command compares two images.
5835 //==============================================================================
5837 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
5841 theDI << "Not enough arguments.\n";
5846 const char* anImgPathRef = theArgVec[1];
5847 const char* anImgPathNew = theArgVec[2];
5849 // get string tolerance and check its validity
5850 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
5851 if (aTolColor < 0.0)
5853 if (aTolColor > 1.0)
5856 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
5857 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
5859 // image file of difference
5860 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
5862 // compare the images
5863 Image_Diff aComparer;
5864 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
5869 aComparer.SetColorTolerance (aTolColor);
5870 aComparer.SetBorderFilterOn (isBorderFilterOn);
5871 Standard_Integer aDiffColorsNb = aComparer.Compare();
5872 theDI << aDiffColorsNb << "\n";
5874 // save image of difference
5875 if (aDiffColorsNb >0 && aDiffImagePath != NULL)
5877 aComparer.SaveDiffImage (aDiffImagePath);
5883 //=======================================================================
5884 //function : VSelect
5885 //purpose : Emulates different types of selection by mouse:
5886 // 1) single click selection
5887 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
5888 // 3) selection with polygon having corners at
5889 // pixel positions (x1,y1),...,(xn,yn)
5890 // 4) any of these selections with shift button pressed
5891 //=======================================================================
5892 static Standard_Integer VSelect (Draw_Interpretor& di,
5893 Standard_Integer argc,
5898 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]\n";
5902 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
5903 if(myAIScontext.IsNull())
5905 di << "use 'vinit' command before " << argv[0] << "\n";
5909 const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1));
5910 Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1;
5911 TCollection_AsciiString anArg;
5912 anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2];
5914 if (anArg == "-allowoverlap")
5916 Standard_Boolean isValidated = isShiftSelection ? argc == 8
5920 di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection";
5924 Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
5925 myAIScontext->MainSelector()->AllowOverlapDetection (isToAllow != 0);
5929 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
5930 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
5933 if(isShiftSelection)
5934 aCurrentEventManager->ShiftSelect();
5936 aCurrentEventManager->Select();
5938 else if(aCoordsNb == 4)
5940 if(isShiftSelection)
5941 aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
5943 aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
5947 TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2);
5949 for(Standard_Integer i=1;i<=aCoordsNb / 2;++i)
5950 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
5952 if(isShiftSelection)
5953 aCurrentEventManager->ShiftSelect(aPolyline);
5955 aCurrentEventManager->Select(aPolyline);
5960 //=======================================================================
5961 //function : VMoveTo
5962 //purpose : Emulates cursor movement to defined pixel position
5963 //=======================================================================
5964 static Standard_Integer VMoveTo (Draw_Interpretor& di,
5965 Standard_Integer argc,
5970 di << "Usage : " << argv[0] << " x y\n";
5974 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5975 if(aContext.IsNull())
5977 di << "use 'vinit' command before " << argv[0] << "\n";
5980 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
5984 //=================================================================================================
5985 //function : VViewParams
5986 //purpose : Gets or sets AIS View characteristics
5987 //=================================================================================================
5988 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5990 Handle(V3d_View) anAISView = ViewerTest::CurrentView();
5991 if (anAISView.IsNull())
5993 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
5999 // print all of the available view parameters
6000 Quantity_Factor anAISViewScale = anAISView->Scale();
6002 Standard_Real anAISViewProjX = 0.0;
6003 Standard_Real anAISViewProjY = 0.0;
6004 Standard_Real anAISViewProjZ = 0.0;
6005 anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
6007 Standard_Real anAISViewUpX = 0.0;
6008 Standard_Real anAISViewUpY = 0.0;
6009 Standard_Real anAISViewUpZ = 0.0;
6010 anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
6012 Standard_Real anAISViewAtX = 0.0;
6013 Standard_Real anAISViewAtY = 0.0;
6014 Standard_Real anAISViewAtZ = 0.0;
6015 anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
6017 Standard_Real anAISViewEyeX = 0.0;
6018 Standard_Real anAISViewEyeY = 0.0;
6019 Standard_Real anAISViewEyeZ = 0.0;
6020 anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ);
6022 theDi << "Scale of current view: " << anAISViewScale << "\n";
6023 theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
6024 theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
6025 theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
6026 theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n";
6030 // -------------------------
6031 // Parse options and values
6032 // -------------------------
6034 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues;
6035 TCollection_AsciiString aParseKey;
6036 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
6038 TCollection_AsciiString anArg (theArgVec [anArgIt]);
6040 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
6043 aParseKey.Remove (1);
6044 aParseKey.UpperCase();
6045 aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
6049 if (aParseKey.IsEmpty())
6051 std::cout << theArgVec[0] << ": values should be passed with key.\n";
6052 std::cout << "Type help for more information.\n";
6056 aMapOfKeysByValues(aParseKey)->Append (anArg);
6059 // ---------------------------------------------
6060 // Change or print parameters, order plays role
6061 // ---------------------------------------------
6063 // Check arguments for validity
6064 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues);
6065 for (; aMapIt.More(); aMapIt.Next())
6067 const TCollection_AsciiString& aKey = aMapIt.Key();
6068 const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value();
6070 if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty()))
6071 && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty()))
6072 && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty()))
6073 && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty()))
6074 && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty()))
6075 && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty()))
6076 && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2))
6078 TCollection_AsciiString aLowerKey;
6081 aLowerKey.LowerCase();
6082 std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n";
6083 std::cout << "Type help for more information.\n";
6088 Handle(TColStd_HSequenceOfAsciiString) aValues;
6090 // Change view parameters in proper order
6091 if (aMapOfKeysByValues.Find ("SCALE", aValues))
6093 if (aValues->IsEmpty())
6095 theDi << "Scale: " << anAISView->Scale() << "\n";
6099 anAISView->SetScale (aValues->Value(1).RealValue());
6102 if (aMapOfKeysByValues.Find ("SIZE", aValues))
6104 if (aValues->IsEmpty())
6106 Standard_Real aSizeX = 0.0;
6107 Standard_Real aSizeY = 0.0;
6108 anAISView->Size (aSizeX, aSizeY);
6109 theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n";
6113 anAISView->SetSize (aValues->Value(1).RealValue());
6116 if (aMapOfKeysByValues.Find ("EYE", aValues))
6118 if (aValues->IsEmpty())
6120 Standard_Real anEyeX = 0.0;
6121 Standard_Real anEyeY = 0.0;
6122 Standard_Real anEyeZ = 0.0;
6123 anAISView->Eye (anEyeX, anEyeY, anEyeZ);
6124 theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n";
6128 anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6131 if (aMapOfKeysByValues.Find ("AT", aValues))
6133 if (aValues->IsEmpty())
6135 Standard_Real anAtX = 0.0;
6136 Standard_Real anAtY = 0.0;
6137 Standard_Real anAtZ = 0.0;
6138 anAISView->At (anAtX, anAtY, anAtZ);
6139 theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n";
6143 anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6146 if (aMapOfKeysByValues.Find ("PROJ", aValues))
6148 if (aValues->IsEmpty())
6150 Standard_Real aProjX = 0.0;
6151 Standard_Real aProjY = 0.0;
6152 Standard_Real aProjZ = 0.0;
6153 anAISView->Proj (aProjX, aProjY, aProjZ);
6154 theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n";
6158 anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6161 if (aMapOfKeysByValues.Find ("UP", aValues))
6163 if (aValues->IsEmpty())
6165 Standard_Real anUpX = 0.0;
6166 Standard_Real anUpY = 0.0;
6167 Standard_Real anUpZ = 0.0;
6168 anAISView->Up (anUpX, anUpY, anUpZ);
6169 theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n";
6173 anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6176 if (aMapOfKeysByValues.Find ("CENTER", aValues))
6178 anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue());
6184 //=======================================================================
6185 //function : VChangeSelected
6186 //purpose : Adds the shape to selection or remove one from it
6187 //=======================================================================
6188 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
6189 Standard_Integer argc,
6194 di<<"Usage : " << argv[0] << " shape \n";
6198 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6199 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
6200 TCollection_AsciiString aName(argv[1]);
6201 Handle(AIS_InteractiveObject) anAISObject;
6203 if(!aMap.IsBound2(aName))
6205 di<<"Use 'vdisplay' before";
6210 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
6211 if(anAISObject.IsNull()){
6212 di<<"No interactive object \n";
6216 aContext->AddOrRemoveSelected(anAISObject);
6221 //=======================================================================
6222 //function : VNbSelected
6223 //purpose : Returns number of selected objects
6224 //=======================================================================
6225 static Standard_Integer VNbSelected (Draw_Interpretor& di,
6226 Standard_Integer argc,
6231 di << "Usage : " << argv[0] << "\n";
6234 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6235 if(aContext.IsNull())
6237 di << "use 'vinit' command before " << argv[0] << "\n";
6240 di << aContext->NbSelected() << "\n";
6244 //=======================================================================
6245 //function : VPurgeDisplay
6246 //purpose : Switches altialiasing on or off
6247 //=======================================================================
6248 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
6249 Standard_Integer argc,
6254 di << "Usage : " << argv[0] << "\n";
6257 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6258 if (aContext.IsNull())
6260 di << "use 'vinit' command before " << argv[0] << "\n";
6263 aContext->CloseAllContexts(Standard_False);
6264 di << aContext->PurgeDisplay() << "\n";
6268 //=======================================================================
6269 //function : VSetViewSize
6271 //=======================================================================
6272 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
6273 Standard_Integer argc,
6276 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6277 if(aContext.IsNull())
6279 di << "use 'vinit' command before " << argv[0] << "\n";
6284 di<<"Usage : " << argv[0] << " Size\n";
6287 Standard_Real aSize = Draw::Atof (argv[1]);
6290 di<<"Bad Size value : " << aSize << "\n";
6294 Handle(V3d_View) aView = ViewerTest::CurrentView();
6295 aView->SetSize(aSize);
6299 //=======================================================================
6300 //function : VMoveView
6302 //=======================================================================
6303 static Standard_Integer VMoveView (Draw_Interpretor& di,
6304 Standard_Integer argc,
6307 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6308 if(aContext.IsNull())
6310 di << "use 'vinit' command before " << argv[0] << "\n";
6313 if(argc < 4 || argc > 5)
6315 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
6318 Standard_Real Dx = Draw::Atof (argv[1]);
6319 Standard_Real Dy = Draw::Atof (argv[2]);
6320 Standard_Real Dz = Draw::Atof (argv[3]);
6321 Standard_Boolean aStart = Standard_True;
6324 aStart = (Draw::Atoi (argv[4]) > 0);
6327 Handle(V3d_View) aView = ViewerTest::CurrentView();
6328 aView->Move(Dx,Dy,Dz,aStart);
6332 //=======================================================================
6333 //function : VTranslateView
6335 //=======================================================================
6336 static Standard_Integer VTranslateView (Draw_Interpretor& di,
6337 Standard_Integer argc,
6340 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6341 if(aContext.IsNull())
6343 di << "use 'vinit' command before " << argv[0] << "\n";
6346 if(argc < 4 || argc > 5)
6348 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
6351 Standard_Real Dx = Draw::Atof (argv[1]);
6352 Standard_Real Dy = Draw::Atof (argv[2]);
6353 Standard_Real Dz = Draw::Atof (argv[3]);
6354 Standard_Boolean aStart = Standard_True;
6357 aStart = (Draw::Atoi (argv[4]) > 0);
6360 Handle(V3d_View) aView = ViewerTest::CurrentView();
6361 aView->Translate(Dx,Dy,Dz,aStart);
6365 //=======================================================================
6366 //function : VTurnView
6368 //=======================================================================
6369 static Standard_Integer VTurnView (Draw_Interpretor& di,
6370 Standard_Integer argc,
6373 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6374 if(aContext.IsNull()) {
6375 di << "use 'vinit' command before " << argv[0] << "\n";
6378 if(argc < 4 || argc > 5){
6379 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
6382 Standard_Real Ax = Draw::Atof (argv[1]);
6383 Standard_Real Ay = Draw::Atof (argv[2]);
6384 Standard_Real Az = Draw::Atof (argv[3]);
6385 Standard_Boolean aStart = Standard_True;
6388 aStart = (Draw::Atoi (argv[4]) > 0);
6391 Handle(V3d_View) aView = ViewerTest::CurrentView();
6392 aView->Turn(Ax,Ay,Az,aStart);
6396 //==============================================================================
6397 //function : VTextureEnv
6398 //purpose : ENables or disables environment mapping
6399 //==============================================================================
6400 class OCC_TextureEnv : public Graphic3d_TextureEnv
6403 OCC_TextureEnv(const Standard_CString FileName);
6404 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
6405 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
6406 const Standard_Boolean theModulateFlag,
6407 const Graphic3d_TypeOfTextureFilter theFilter,
6408 const Standard_ShortReal theXScale,
6409 const Standard_ShortReal theYScale,
6410 const Standard_ShortReal theXShift,
6411 const Standard_ShortReal theYShift,
6412 const Standard_ShortReal theAngle);
6413 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
6415 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
6417 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
6418 : Graphic3d_TextureEnv(theFileName)
6422 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
6423 : Graphic3d_TextureEnv(theTexId)
6427 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
6428 const Standard_Boolean theModulateFlag,
6429 const Graphic3d_TypeOfTextureFilter theFilter,
6430 const Standard_ShortReal theXScale,
6431 const Standard_ShortReal theYScale,
6432 const Standard_ShortReal theXShift,
6433 const Standard_ShortReal theYShift,
6434 const Standard_ShortReal theAngle)
6436 myParams->SetRepeat (theRepeatFlag);
6437 myParams->SetModulate (theModulateFlag);
6438 myParams->SetFilter (theFilter);
6439 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
6440 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
6441 myParams->SetRotation (theAngle);
6444 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
6446 // get the active view
6447 Handle(V3d_View) aView = ViewerTest::CurrentView();
6450 std::cerr << "No active view. Please call vinit.\n";
6454 // Checking the input arguments
6455 Standard_Boolean anEnableFlag = Standard_False;
6456 Standard_Boolean isOk = theArgNb >= 2;
6459 TCollection_AsciiString anEnableOpt(theArgVec[1]);
6460 anEnableFlag = anEnableOpt.IsEqual("on");
6461 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
6465 isOk = (theArgNb == 3 || theArgNb == 11);
6468 TCollection_AsciiString aTextureOpt(theArgVec[2]);
6469 isOk = (!aTextureOpt.IsIntegerValue() ||
6470 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
6472 if (isOk && theArgNb == 11)
6474 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
6475 aModulateOpt(theArgVec[4]),
6476 aFilterOpt (theArgVec[5]),
6477 aSScaleOpt (theArgVec[6]),
6478 aTScaleOpt (theArgVec[7]),
6479 aSTransOpt (theArgVec[8]),
6480 aTTransOpt (theArgVec[9]),
6481 anAngleOpt (theArgVec[10]);
6482 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
6483 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
6484 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
6485 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
6486 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
6487 anAngleOpt.IsRealValue());
6494 std::cerr << "Usage :" << std::endl;
6495 std::cerr << theArgVec[0] << " off" << std::endl;
6496 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;
6502 TCollection_AsciiString aTextureOpt(theArgVec[2]);
6503 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
6504 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
6505 new OCC_TextureEnv(theArgVec[2]);
6509 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
6510 aTexEnv->SetTextureParameters(
6511 aRepeatOpt. IsEqual("repeat"),
6512 aModulateOpt.IsEqual("modulate"),
6513 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
6514 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
6515 Graphic3d_TOTF_TRILINEAR,
6516 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
6517 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
6518 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
6519 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
6520 (Standard_ShortReal)Draw::Atof(theArgVec[10])
6523 aView->SetTextureEnv(aTexEnv);
6525 else // Disabling environment mapping
6527 Handle(Graphic3d_TextureEnv) aTexture;
6528 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
6537 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
6539 //! Remove registered clipping plane from all views and objects.
6540 static void removePlane (MapOfPlanes& theRegPlanes,
6541 const TCollection_AsciiString& theName)
6543 Handle(Graphic3d_ClipPlane) aClipPlane;
6544 if (!theRegPlanes.Find (theName, aClipPlane))
6546 std::cout << "Warning: no such plane.\n";
6550 theRegPlanes.UnBind (theName);
6551 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
6552 anIObjIt.More(); anIObjIt.Next())
6554 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
6555 aPrs->RemoveClipPlane (aClipPlane);
6558 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
6559 aViewIt.More(); aViewIt.Next())
6561 const Handle(V3d_View)& aView = aViewIt.Key2();
6562 aView->RemoveClipPlane(aClipPlane);
6565 ViewerTest::RedrawAllViews();
6569 //===============================================================================================
6570 //function : VClipPlane
6572 //===============================================================================================
6573 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6575 // use short-cut for created clip planes map of created (or "registered by name") clip planes
6576 static MapOfPlanes aRegPlanes;
6580 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
6582 theDi << aPlaneIter.Key() << " ";
6587 TCollection_AsciiString aCommand (theArgVec[1]);
6588 aCommand.LowerCase();
6589 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
6590 if (anActiveView.IsNull())
6592 std::cout << "Error: no active view.\n";
6596 // print maximum number of planes for current viewer
6597 if (aCommand == "-maxplanes"
6598 || aCommand == "maxplanes")
6600 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
6601 << " plane slots provided by driver.\n";
6605 // create / delete plane instance
6606 if (aCommand == "-create"
6607 || aCommand == "create"
6608 || aCommand == "-delete"
6609 || aCommand == "delete"
6610 || aCommand == "-clone"
6611 || aCommand == "clone")
6615 std::cout << "Syntax error: plane name is required.\n";
6619 Standard_Boolean toCreate = aCommand == "-create"
6620 || aCommand == "create";
6621 Standard_Boolean toClone = aCommand == "-clone"
6622 || aCommand == "clone";
6623 Standard_Boolean toDelete = aCommand == "-delete"
6624 || aCommand == "delete";
6625 TCollection_AsciiString aPlane (theArgVec[2]);
6629 if (aRegPlanes.IsBound (aPlane))
6631 std::cout << "Warning: existing plane has been overridden.\n";
6636 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
6640 else if (toClone) // toClone
6642 if (!aRegPlanes.IsBound (aPlane))
6644 std::cout << "Error: no such plane.\n";
6647 else if (theArgsNb < 4)
6649 std::cout << "Syntax error: enter name for new plane.\n";
6653 TCollection_AsciiString aClone (theArgVec[3]);
6654 if (aRegPlanes.IsBound (aClone))
6656 std::cout << "Error: plane name is in use.\n";
6660 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6662 aRegPlanes.Bind (aClone, aClipPlane->Clone());
6672 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
6674 aPlane = aPlaneIter.Key();
6675 removePlane (aRegPlanes, aPlane);
6676 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
6681 removePlane (aRegPlanes, aPlane);
6687 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
6692 // set / unset plane command
6693 if (aCommand == "set"
6694 || aCommand == "unset")
6698 std::cout << "Syntax error: need more arguments.\n";
6702 // redirect to new syntax
6703 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
6704 anArgVec.SetValue (1, theArgVec[0]);
6705 anArgVec.SetValue (2, theArgVec[2]);
6706 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
6707 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
6709 anArgVec.SetValue (anIt, theArgVec[anIt]);
6712 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
6715 // change plane command
6716 TCollection_AsciiString aPlaneName;
6717 Handle(Graphic3d_ClipPlane) aClipPlane;
6718 Standard_Integer anArgIter = 0;
6719 if (aCommand == "-change"
6720 || aCommand == "change")
6722 // old syntax support
6725 std::cout << "Syntax error: need more arguments.\n";
6730 aPlaneName = theArgVec[2];
6731 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
6733 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
6737 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
6740 aPlaneName = theArgVec[1];
6745 aPlaneName = theArgVec[1];
6746 aClipPlane = new Graphic3d_ClipPlane();
6747 aRegPlanes.Bind (aPlaneName, aClipPlane);
6748 theDi << "Created new plane " << aPlaneName << ".\n";
6751 if (theArgsNb - anArgIter < 1)
6753 std::cout << "Syntax error: need more arguments.\n";
6757 for (; anArgIter < theArgsNb; ++anArgIter)
6759 const char** aChangeArgs = theArgVec + anArgIter;
6760 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
6761 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
6762 aChangeArg.LowerCase();
6764 Standard_Boolean toEnable = Standard_True;
6765 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
6767 aClipPlane->SetOn (toEnable);
6769 else if (aChangeArg == "-equation"
6770 || aChangeArg == "equation")
6772 if (aNbChangeArgs < 5)
6774 std::cout << "Syntax error: need more arguments.\n";
6778 Standard_Real aCoeffA = Draw::Atof (aChangeArgs [1]);
6779 Standard_Real aCoeffB = Draw::Atof (aChangeArgs [2]);
6780 Standard_Real aCoeffC = Draw::Atof (aChangeArgs [3]);
6781 Standard_Real aCoeffD = Draw::Atof (aChangeArgs [4]);
6782 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
6785 else if (aChangeArg == "-capping"
6786 || aChangeArg == "capping")
6788 if (aNbChangeArgs < 2)
6790 std::cout << "Syntax error: need more arguments.\n";
6794 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
6796 aClipPlane->SetCapping (toEnable);
6801 // just skip otherwise (old syntax)
6804 else if (aChangeArg == "-useobjectmaterial"
6805 || aChangeArg == "-useobjectmat"
6806 || aChangeArg == "-useobjmat"
6807 || aChangeArg == "-useobjmaterial")
6809 if (aNbChangeArgs < 2)
6811 std::cout << "Syntax error: need more arguments.\n";
6815 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
6817 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
6821 else if (aChangeArg == "-useobjecttexture"
6822 || aChangeArg == "-useobjecttex"
6823 || aChangeArg == "-useobjtexture"
6824 || aChangeArg == "-useobjtex")
6826 if (aNbChangeArgs < 2)
6828 std::cout << "Syntax error: need more arguments.\n";
6832 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
6834 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
6838 else if (aChangeArg == "-useobjectshader"
6839 || aChangeArg == "-useobjshader")
6841 if (aNbChangeArgs < 2)
6843 std::cout << "Syntax error: need more arguments.\n";
6847 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
6849 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
6853 else if (aChangeArg == "-color"
6854 || aChangeArg == "color")
6856 Quantity_Color aColor;
6857 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
6862 std::cout << "Syntax error: need more arguments.\n";
6866 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
6867 aMat.SetAmbientColor (aColor);
6868 aMat.SetDiffuseColor (aColor);
6869 aClipPlane->SetCappingMaterial (aMat);
6870 anArgIter += aNbParsed;
6872 else if (aChangeArg == "-texname"
6873 || aChangeArg == "texname")
6875 if (aNbChangeArgs < 2)
6877 std::cout << "Syntax error: need more arguments.\n";
6881 TCollection_AsciiString aTextureName (aChangeArgs[1]);
6882 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
6883 if (!aTexture->IsDone())
6885 aClipPlane->SetCappingTexture (NULL);
6889 aTexture->EnableModulate();
6890 aTexture->EnableRepeat();
6891 aClipPlane->SetCappingTexture (aTexture);
6895 else if (aChangeArg == "-texscale"
6896 || aChangeArg == "texscale")
6898 if (aClipPlane->CappingTexture().IsNull())
6900 std::cout << "Error: no texture is set.\n";
6904 if (aNbChangeArgs < 3)
6906 std::cout << "Syntax error: need more arguments.\n";
6910 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
6911 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
6912 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
6915 else if (aChangeArg == "-texorigin"
6916 || aChangeArg == "texorigin") // texture origin
6918 if (aClipPlane->CappingTexture().IsNull())
6920 std::cout << "Error: no texture is set.\n";
6924 if (aNbChangeArgs < 3)
6926 std::cout << "Syntax error: need more arguments.\n";
6930 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
6931 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
6933 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
6936 else if (aChangeArg == "-texrotate"
6937 || aChangeArg == "texrotate") // texture rotation
6939 if (aClipPlane->CappingTexture().IsNull())
6941 std::cout << "Error: no texture is set.\n";
6945 if (aNbChangeArgs < 2)
6947 std::cout << "Syntax error: need more arguments.\n";
6951 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
6952 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
6955 else if (aChangeArg == "-hatch"
6956 || aChangeArg == "hatch")
6958 if (aNbChangeArgs < 2)
6960 std::cout << "Syntax error: need more arguments.\n";
6964 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
6965 aHatchStr.LowerCase();
6966 if (aHatchStr == "on")
6968 aClipPlane->SetCappingHatchOn();
6970 else if (aHatchStr == "off")
6972 aClipPlane->SetCappingHatchOff();
6976 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
6980 else if (aChangeArg == "-delete"
6981 || aChangeArg == "delete")
6983 removePlane (aRegPlanes, aPlaneName);
6986 else if (aChangeArg == "-set"
6987 || aChangeArg == "-unset")
6989 // set / unset plane command
6990 Standard_Boolean toSet = aChangeArg == "-set";
6991 Standard_Integer anIt = 1;
6992 for (; anIt < aNbChangeArgs; ++anIt)
6994 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
6995 if (anEntityName.IsEmpty()
6996 || anEntityName.Value (1) == '-')
7000 else if (ViewerTest_myViews.IsBound1 (anEntityName))
7002 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
7005 aView->AddClipPlane (aClipPlane);
7009 aView->RemoveClipPlane (aClipPlane);
7013 else if (GetMapOfAIS().IsBound2 (anEntityName))
7015 Handle(AIS_InteractiveObject) aIObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
7018 aIObj->AddClipPlane (aClipPlane);
7022 aIObj->RemoveClipPlane (aClipPlane);
7027 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
7034 // apply to active view
7037 anActiveView->AddClipPlane (aClipPlane);
7041 anActiveView->RemoveClipPlane (aClipPlane);
7046 anArgIter = anArgIter + anIt - 1;
7051 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
7056 ViewerTest::RedrawAllViews();
7060 //===============================================================================================
7061 //function : VZRange
7063 //===============================================================================================
7064 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7066 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
7068 if (aCurrentView.IsNull())
7070 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
7074 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
7078 theDi << "ZNear: " << aCamera->ZNear() << "\n";
7079 theDi << "ZFar: " << aCamera->ZFar() << "\n";
7085 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
7086 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
7088 if (aNewZNear >= aNewZFar)
7090 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
7094 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
7096 std::cout << theArgVec[0] << ": invalid arguments: ";
7097 std::cout << "znear, zfar should be positive for perspective camera.\n";
7101 aCamera->SetZRange (aNewZNear, aNewZFar);
7105 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
7109 aCurrentView->Redraw();
7114 //===============================================================================================
7115 //function : VAutoZFit
7117 //===============================================================================================
7118 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7120 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
7122 if (aCurrentView.IsNull())
7124 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
7128 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
7132 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
7138 theDi << "Auto z-fit mode: \n"
7139 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
7140 << "Scale: " << aScale << "\n";
7144 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
7148 aScale = Draw::Atoi (theArgVec[2]);
7151 aCurrentView->SetAutoZFitMode (isOn, aScale);
7152 aCurrentView->AutoZFit();
7153 aCurrentView->Redraw();
7158 //! Auxiliary function to print projection type
7159 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
7161 switch (theProjType)
7163 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
7164 case Graphic3d_Camera::Projection_Perspective: return "perspective";
7165 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
7166 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
7167 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
7172 //===============================================================================================
7173 //function : VCamera
7175 //===============================================================================================
7176 static int VCamera (Draw_Interpretor& theDI,
7177 Standard_Integer theArgsNb,
7178 const char** theArgVec)
7180 Handle(V3d_View) aView = ViewerTest::CurrentView();
7183 std::cout << "Error: no active view.\n";
7187 Handle(Graphic3d_Camera) aCamera = aView->Camera();
7190 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
7191 theDI << "FOVy: " << aCamera->FOVy() << "\n";
7192 theDI << "Distance: " << aCamera->Distance() << "\n";
7193 theDI << "IOD: " << aCamera->IOD() << "\n";
7194 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
7195 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
7196 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
7200 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7202 Standard_CString anArg = theArgVec[anArgIter];
7203 TCollection_AsciiString anArgCase (anArg);
7204 anArgCase.LowerCase();
7205 if (anArgCase == "-proj"
7206 || anArgCase == "-projection"
7207 || anArgCase == "-projtype"
7208 || anArgCase == "-projectiontype")
7210 theDI << projTypeName (aCamera->ProjectionType()) << " ";
7212 else if (anArgCase == "-ortho"
7213 || anArgCase == "-orthographic")
7215 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
7217 else if (anArgCase == "-persp"
7218 || anArgCase == "-perspective"
7219 || anArgCase == "-perspmono"
7220 || anArgCase == "-perspectivemono"
7221 || anArgCase == "-mono")
7223 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
7225 else if (anArgCase == "-stereo"
7226 || anArgCase == "-stereoscopic"
7227 || anArgCase == "-perspstereo"
7228 || anArgCase == "-perspectivestereo")
7230 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7232 else if (anArgCase == "-left"
7233 || anArgCase == "-lefteye"
7234 || anArgCase == "-monoleft"
7235 || anArgCase == "-monolefteye"
7236 || anArgCase == "-perpsleft"
7237 || anArgCase == "-perpslefteye")
7239 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
7241 else if (anArgCase == "-right"
7242 || anArgCase == "-righteye"
7243 || anArgCase == "-monoright"
7244 || anArgCase == "-monorighteye"
7245 || anArgCase == "-perpsright")
7247 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
7249 else if (anArgCase == "-dist"
7250 || anArgCase == "-distance")
7252 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7253 if (anArgValue != NULL
7254 && *anArgValue != '-')
7257 aCamera->SetDistance (Draw::Atof (anArgValue));
7260 theDI << aCamera->Distance() << " ";
7262 else if (anArgCase == "-iod")
7264 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7265 if (anArgValue != NULL
7266 && *anArgValue != '-')
7269 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
7272 theDI << aCamera->IOD() << " ";
7274 else if (anArgCase == "-iodtype")
7276 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
7277 TCollection_AsciiString anValueCase (anArgValue);
7278 anValueCase.LowerCase();
7279 if (anValueCase == "abs"
7280 || anValueCase == "absolute")
7283 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
7286 else if (anValueCase == "rel"
7287 || anValueCase == "relative")
7290 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
7293 else if (*anArgValue != '-')
7295 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
7298 switch (aCamera->GetIODType())
7300 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
7301 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
7304 else if (anArgCase == "-zfocus")
7306 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7307 if (anArgValue != NULL
7308 && *anArgValue != '-')
7311 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
7314 theDI << aCamera->ZFocus() << " ";
7316 else if (anArgCase == "-zfocustype")
7318 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
7319 TCollection_AsciiString anValueCase (anArgValue);
7320 anValueCase.LowerCase();
7321 if (anValueCase == "abs"
7322 || anValueCase == "absolute")
7325 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
7328 else if (anValueCase == "rel"
7329 || anValueCase == "relative")
7332 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
7335 else if (*anArgValue != '-')
7337 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
7340 switch (aCamera->ZFocusType())
7342 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
7343 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
7346 else if (anArgCase == "-fov"
7347 || anArgCase == "-fovy")
7349 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7350 if (anArgValue != NULL
7351 && *anArgValue != '-')
7354 aCamera->SetFOVy (Draw::Atof (anArgValue));
7357 theDI << aCamera->FOVy() << " ";
7361 std::cout << "Error: unknown argument '" << anArg << "'\n";
7372 //! Parse stereo output mode
7373 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
7374 Graphic3d_StereoMode& theMode)
7376 TCollection_AsciiString aFlag (theArg);
7378 if (aFlag == "quadbuffer")
7380 theMode = Graphic3d_StereoMode_QuadBuffer;
7382 else if (aFlag == "anaglyph")
7384 theMode = Graphic3d_StereoMode_Anaglyph;
7386 else if (aFlag == "row"
7387 || aFlag == "rowinterlaced")
7389 theMode = Graphic3d_StereoMode_RowInterlaced;
7391 else if (aFlag == "col"
7392 || aFlag == "colinterlaced"
7393 || aFlag == "columninterlaced")
7395 theMode = Graphic3d_StereoMode_ColumnInterlaced;
7397 else if (aFlag == "chess"
7398 || aFlag == "chessboard")
7400 theMode = Graphic3d_StereoMode_ChessBoard;
7402 else if (aFlag == "sbs"
7403 || aFlag == "sidebyside")
7405 theMode = Graphic3d_StereoMode_SideBySide;
7407 else if (aFlag == "ou"
7408 || aFlag == "overunder")
7410 theMode = Graphic3d_StereoMode_OverUnder;
7412 else if (aFlag == "pageflip"
7413 || aFlag == "softpageflip")
7415 theMode = Graphic3d_StereoMode_SoftPageFlip;
7419 return Standard_False;
7421 return Standard_True;
7424 //! Parse anaglyph filter
7425 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
7426 Graphic3d_RenderingParams::Anaglyph& theFilter)
7428 TCollection_AsciiString aFlag (theArg);
7430 if (aFlag == "redcyansimple")
7432 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
7434 else if (aFlag == "redcyan"
7435 || aFlag == "redcyanoptimized")
7437 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
7439 else if (aFlag == "yellowbluesimple")
7441 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
7443 else if (aFlag == "yellowblue"
7444 || aFlag == "yellowblueoptimized")
7446 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
7448 else if (aFlag == "greenmagenta"
7449 || aFlag == "greenmagentasimple")
7451 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
7455 return Standard_False;
7457 return Standard_True;
7460 //==============================================================================
7461 //function : VStereo
7463 //==============================================================================
7465 static int VStereo (Draw_Interpretor& theDI,
7466 Standard_Integer theArgNb,
7467 const char** theArgVec)
7469 Handle(V3d_View) aView = ViewerTest::CurrentView();
7474 std::cout << "Error: no active viewer!\n";
7478 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
7479 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
7482 TCollection_AsciiString aMode;
7483 switch (aView->RenderingParams().StereoMode)
7485 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
7486 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
7487 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
7488 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
7489 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
7490 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
7491 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
7492 case Graphic3d_StereoMode_Anaglyph :
7494 switch (aView->RenderingParams().AnaglyphFilter)
7496 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
7497 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
7498 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
7499 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
7500 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
7505 theDI << "Mode " << aMode << "\n";
7510 Handle(Graphic3d_Camera) aCamera;
7511 Graphic3d_RenderingParams* aParams = NULL;
7512 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
7513 if (!aView.IsNull())
7515 aParams = &aView->ChangeRenderingParams();
7516 aMode = aParams->StereoMode;
7517 aCamera = aView->Camera();
7520 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7521 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7523 Standard_CString anArg = theArgVec[anArgIter];
7524 TCollection_AsciiString aFlag (anArg);
7526 if (anUpdateTool.parseRedrawMode (aFlag))
7530 else if (aFlag == "0"
7533 if (++anArgIter < theArgNb)
7535 std::cout << "Error: wrong number of arguments!\n";
7539 if (!aCamera.IsNull()
7540 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
7542 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
7544 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
7547 else if (aFlag == "1"
7550 if (++anArgIter < theArgNb)
7552 std::cout << "Error: wrong number of arguments!\n";
7556 if (!aCamera.IsNull())
7558 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7560 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
7563 else if (aFlag == "-reverse"
7564 || aFlag == "-reversed"
7565 || aFlag == "-swap")
7567 Standard_Boolean toEnable = Standard_True;
7568 if (++anArgIter < theArgNb
7569 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
7573 aParams->ToReverseStereo = toEnable;
7575 else if (aFlag == "-noreverse"
7576 || aFlag == "-noswap")
7578 Standard_Boolean toDisable = Standard_True;
7579 if (++anArgIter < theArgNb
7580 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
7584 aParams->ToReverseStereo = !toDisable;
7586 else if (aFlag == "-mode"
7587 || aFlag == "-stereomode")
7589 if (++anArgIter >= theArgNb
7590 || !parseStereoMode (theArgVec[anArgIter], aMode))
7592 std::cout << "Error: syntax error at '" << anArg << "'\n";
7596 if (aMode == Graphic3d_StereoMode_QuadBuffer)
7598 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
7601 else if (aFlag == "-anaglyph"
7602 || aFlag == "-anaglyphfilter")
7604 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
7605 if (++anArgIter >= theArgNb
7606 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
7608 std::cout << "Error: syntax error at '" << anArg << "'\n";
7612 aMode = Graphic3d_StereoMode_Anaglyph;
7613 aParams->AnaglyphFilter = aFilter;
7615 else if (parseStereoMode (anArg, aMode)) // short syntax
7617 if (aMode == Graphic3d_StereoMode_QuadBuffer)
7619 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
7624 std::cout << "Error: syntax error at '" << anArg << "'\n";
7629 if (!aView.IsNull())
7631 aParams->StereoMode = aMode;
7632 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7637 //===============================================================================================
7638 //function : VDefaults
7640 //===============================================================================================
7641 static int VDefaults (Draw_Interpretor& theDi,
7642 Standard_Integer theArgsNb,
7643 const char** theArgVec)
7645 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
7648 std::cerr << "No active viewer!\n";
7652 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
7655 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
7657 theDi << "DeflType: relative\n"
7658 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
7662 theDi << "DeflType: absolute\n"
7663 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
7665 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
7666 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
7670 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7672 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7674 if (anArg == "-ABSDEFL"
7675 || anArg == "-ABSOLUTEDEFLECTION"
7677 || anArg == "-DEFLECTION")
7679 if (++anArgIter >= theArgsNb)
7681 std::cout << "Error: wrong syntax at " << anArg << "\n";
7684 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
7685 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
7687 else if (anArg == "-RELDEFL"
7688 || anArg == "-RELATIVEDEFLECTION"
7689 || anArg == "-DEVCOEFF"
7690 || anArg == "-DEVIATIONCOEFF"
7691 || anArg == "-DEVIATIONCOEFFICIENT")
7693 if (++anArgIter >= theArgsNb)
7695 std::cout << "Error: wrong syntax at " << anArg << "\n";
7698 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
7699 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
7701 else if (anArg == "-ANGDEFL"
7702 || anArg == "-ANGULARDEFL"
7703 || anArg == "-ANGULARDEFLECTION")
7705 if (++anArgIter >= theArgsNb)
7707 std::cout << "Error: wrong syntax at " << anArg << "\n";
7710 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
7711 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
7713 else if (anArg == "-AUTOTR"
7714 || anArg == "-AUTOTRIANG"
7715 || anArg == "-AUTOTRIANGULATION")
7717 if (++anArgIter >= theArgsNb)
7719 std::cout << "Error: wrong syntax at " << anArg << "\n";
7722 TCollection_AsciiString aValue (theArgVec[anArgIter]);
7727 aDefParams->SetAutoTriangulation (Standard_True);
7729 else if (aValue == "off"
7732 aDefParams->SetAutoTriangulation (Standard_False);
7737 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
7744 //! Auxiliary method
7745 inline void addLight (const Handle(V3d_Light)& theLightNew,
7746 const Standard_Boolean theIsGlobal)
7748 if (theLightNew.IsNull())
7755 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
7759 ViewerTest::CurrentView()->SetLightOn (theLightNew);
7763 //! Auxiliary method
7764 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
7766 TCollection_AsciiString anArgNextCase (theArgNext);
7767 anArgNextCase.UpperCase();
7768 if (anArgNextCase.Length() > 5
7769 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
7771 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
7775 return theArgNext.IntegerValue();
7779 //===============================================================================================
7782 //===============================================================================================
7783 static int VLight (Draw_Interpretor& theDi,
7784 Standard_Integer theArgsNb,
7785 const char** theArgVec)
7787 Handle(V3d_View) aView = ViewerTest::CurrentView();
7788 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
7790 || aViewer.IsNull())
7792 std::cerr << "No active viewer!\n";
7796 Standard_Real anXYZ[3];
7797 Quantity_Coefficient anAtten[2];
7800 // print lights info
7801 Standard_Integer aLightId = 0;
7802 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightId)
7804 Handle(V3d_Light) aLight = aLightIter.Value();
7805 const Quantity_Color aColor = aLight->Color();
7806 theDi << "Light" << aLightId << "\n";
7807 switch (aLight->Type())
7811 theDi << " Type: Ambient\n";
7812 theDi << " Intensity: " << aLight->Intensity() << "\n";
7815 case V3d_DIRECTIONAL:
7817 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
7818 theDi << " Type: Directional\n";
7819 theDi << " Intensity: " << aLight->Intensity() << "\n";
7820 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7821 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
7822 if (!aLightDir.IsNull())
7824 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7825 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7826 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
7827 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7831 case V3d_POSITIONAL:
7833 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
7834 theDi << " Type: Positional\n";
7835 theDi << " Intensity: " << aLight->Intensity() << "\n";
7836 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7837 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
7838 if (!aLightPos.IsNull())
7840 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7841 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7842 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7843 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
7849 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
7850 theDi << " Type: Spot\n";
7851 theDi << " Intensity: " << aLight->Intensity() << "\n";
7852 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7853 if (!aLightSpot.IsNull())
7855 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7856 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7857 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
7858 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7859 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7860 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
7861 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
7862 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
7868 theDi << " Type: UNKNOWN\n";
7872 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
7876 Handle(V3d_Light) aLightNew;
7877 Handle(V3d_Light) aLightOld;
7878 Standard_Boolean isGlobal = Standard_True;
7879 Standard_Boolean toCreate = Standard_False;
7880 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
7882 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
7883 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
7884 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
7885 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
7886 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
7888 TCollection_AsciiString aName, aValue;
7889 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
7890 TCollection_AsciiString anArgCase (anArg);
7891 anArgCase.UpperCase();
7892 if (anArgCase.IsEqual ("NEW")
7893 || anArgCase.IsEqual ("ADD")
7894 || anArgCase.IsEqual ("CREATE"))
7896 toCreate = Standard_True;
7898 else if (anArgCase.IsEqual ("GLOB")
7899 || anArgCase.IsEqual ("GLOBAL"))
7901 isGlobal = Standard_True;
7903 else if (anArgCase.IsEqual ("LOC")
7904 || anArgCase.IsEqual ("LOCAL"))
7906 isGlobal = Standard_False;
7908 else if (anArgCase.IsEqual ("DEF")
7909 || anArgCase.IsEqual ("DEFAULTS"))
7911 toCreate = Standard_False;
7912 aViewer->SetDefaultLights();
7914 else if (anArgCase.IsEqual ("CLR")
7915 || anArgCase.IsEqual ("CLEAR"))
7917 toCreate = Standard_False;
7918 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
7920 Handle(V3d_Light) aLight = aLightIter.Value();
7921 aViewer->DelLight (aLight);
7922 aLightIter = aView->ActiveLightIterator();
7925 else if (anArgCase.IsEqual ("AMB")
7926 || anArgCase.IsEqual ("AMBIENT")
7927 || anArgCase.IsEqual ("AMBLIGHT"))
7929 addLight (aLightNew, isGlobal);
7932 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7935 toCreate = Standard_False;
7936 aLightNew = new V3d_AmbientLight (aViewer);
7938 else if (anArgCase.IsEqual ("DIRECTIONAL")
7939 || anArgCase.IsEqual ("DIRLIGHT"))
7941 addLight (aLightNew, isGlobal);
7944 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7947 toCreate = Standard_False;
7948 aLightNew = new V3d_DirectionalLight (aViewer);
7950 else if (anArgCase.IsEqual ("SPOT")
7951 || anArgCase.IsEqual ("SPOTLIGHT"))
7953 addLight (aLightNew, isGlobal);
7956 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7959 toCreate = Standard_False;
7960 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
7962 else if (anArgCase.IsEqual ("POSLIGHT")
7963 || anArgCase.IsEqual ("POSITIONAL"))
7965 addLight (aLightNew, isGlobal);
7968 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7971 toCreate = Standard_False;
7972 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
7974 else if (anArgCase.IsEqual ("CHANGE"))
7976 addLight (aLightNew, isGlobal);
7977 aLightNew.Nullify();
7978 if (++anArgIt >= theArgsNb)
7980 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7984 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
7985 Standard_Integer aLightIt = 0;
7986 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
7988 if (aLightIt == aLightId)
7990 aLightOld = aLightIter.Value();
7995 if (aLightOld.IsNull())
7997 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
8001 else if (anArgCase.IsEqual ("DEL")
8002 || anArgCase.IsEqual ("DELETE"))
8004 Handle(V3d_Light) aLightDel;
8005 if (++anArgIt >= theArgsNb)
8007 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8011 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
8012 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
8013 Standard_Integer aLightIt = 0;
8014 for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
8016 aLightDel = aLightIter.Value();
8017 if (aLightIt == aLightDelId)
8022 if (!aLightDel.IsNull())
8024 aViewer->DelLight (aLightDel);
8027 else if (anArgCase.IsEqual ("COLOR")
8028 || anArgCase.IsEqual ("COLOUR"))
8030 if (++anArgIt >= theArgsNb)
8032 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8036 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
8037 anArgNext.UpperCase();
8038 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
8039 if (!aLightCurr.IsNull())
8041 aLightCurr->SetColor (aColor);
8044 else if (anArgCase.IsEqual ("POS")
8045 || anArgCase.IsEqual ("POSITION"))
8047 if ((anArgIt + 3) >= theArgsNb)
8049 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8053 anXYZ[0] = Atof (theArgVec[++anArgIt]);
8054 anXYZ[1] = Atof (theArgVec[++anArgIt]);
8055 anXYZ[2] = Atof (theArgVec[++anArgIt]);
8056 if (!aLightDir.IsNull())
8058 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
8060 else if (!aLightPos.IsNull())
8062 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
8064 else if (!aLightSpot.IsNull())
8066 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
8070 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8074 else if (anArgCase.IsEqual ("DIR")
8075 || anArgCase.IsEqual ("DIRECTION"))
8077 if ((anArgIt + 3) >= theArgsNb)
8079 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8083 anXYZ[0] = Atof (theArgVec[++anArgIt]);
8084 anXYZ[1] = Atof (theArgVec[++anArgIt]);
8085 anXYZ[2] = Atof (theArgVec[++anArgIt]);
8086 if (!aLightDir.IsNull())
8088 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
8090 else if (!aLightSpot.IsNull())
8092 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
8096 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8100 else if (anArgCase.IsEqual ("SM")
8101 || anArgCase.IsEqual ("SMOOTHNESS"))
8103 if (++anArgIt >= theArgsNb)
8105 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8109 Standard_Real aSmoothness = Atof (theArgVec[anArgIt]);
8111 if (fabs (aSmoothness) < Precision::Confusion())
8113 aLightCurr->SetIntensity (1.f);
8115 else if (fabs (aLightCurr->Smoothness()) < Precision::Confusion())
8117 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
8121 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
8122 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
8125 if (!aLightPos.IsNull())
8127 aLightPos->SetSmoothRadius (aSmoothness);
8129 else if (!aLightDir.IsNull())
8131 aLightDir->SetSmoothAngle (aSmoothness);
8134 else if (anArgCase.IsEqual ("INT")
8135 || anArgCase.IsEqual ("INTENSITY"))
8137 if (++anArgIt >= theArgsNb)
8139 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8143 Standard_Real aIntensity = Atof (theArgVec[anArgIt]);
8145 if (!aLightCurr.IsNull())
8147 aLightCurr->SetIntensity (aIntensity);
8150 else if (anArgCase.IsEqual ("ANG")
8151 || anArgCase.IsEqual ("ANGLE"))
8153 if (++anArgIt >= theArgsNb)
8155 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8159 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
8161 if (!aLightSpot.IsNull())
8163 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
8166 else if (anArgCase.IsEqual ("CONSTATTEN")
8167 || anArgCase.IsEqual ("CONSTATTENUATION"))
8169 if (++anArgIt >= theArgsNb)
8171 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8175 if (!aLightPos.IsNull())
8177 aLightPos->Attenuation (anAtten[0], anAtten[1]);
8178 anAtten[0] = Atof (theArgVec[anArgIt]);
8179 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
8181 else if (!aLightSpot.IsNull())
8183 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
8184 anAtten[0] = Atof (theArgVec[anArgIt]);
8185 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
8189 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8193 else if (anArgCase.IsEqual ("LINATTEN")
8194 || anArgCase.IsEqual ("LINEARATTEN")
8195 || anArgCase.IsEqual ("LINEARATTENUATION"))
8197 if (++anArgIt >= theArgsNb)
8199 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8203 if (!aLightPos.IsNull())
8205 aLightPos->Attenuation (anAtten[0], anAtten[1]);
8206 anAtten[1] = Atof (theArgVec[anArgIt]);
8207 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
8209 else if (!aLightSpot.IsNull())
8211 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
8212 anAtten[1] = Atof (theArgVec[anArgIt]);
8213 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
8217 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8221 else if (anArgCase.IsEqual ("EXP")
8222 || anArgCase.IsEqual ("EXPONENT")
8223 || anArgCase.IsEqual ("SPOTEXP")
8224 || anArgCase.IsEqual ("SPOTEXPONENT"))
8226 if (++anArgIt >= theArgsNb)
8228 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8232 if (!aLightSpot.IsNull())
8234 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
8238 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8242 else if (anArgCase.IsEqual ("HEAD")
8243 || anArgCase.IsEqual ("HEADLIGHT"))
8245 if (++anArgIt >= theArgsNb)
8247 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8251 if (aLightAmb.IsNull()
8252 && !aLightCurr.IsNull())
8254 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
8258 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8264 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
8268 addLight (aLightNew, isGlobal);
8269 aViewer->UpdateLights();
8274 //=======================================================================
8275 //function : VRenderParams
8276 //purpose : Enables/disables rendering features
8277 //=======================================================================
8279 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
8280 Standard_Integer theArgNb,
8281 const char** theArgVec)
8283 Handle(V3d_View) aView = ViewerTest::CurrentView();
8286 std::cerr << "Error: no active viewer!\n";
8290 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
8291 TCollection_AsciiString aCmdName (theArgVec[0]);
8292 aCmdName.LowerCase();
8293 if (aCmdName == "vraytrace")
8297 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
8300 else if (theArgNb == 2)
8302 TCollection_AsciiString aValue (theArgVec[1]);
8307 aParams.Method = Graphic3d_RM_RAYTRACING;
8311 else if (aValue == "off"
8314 aParams.Method = Graphic3d_RM_RASTERIZATION;
8320 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
8326 std::cout << "Error: wrong number of arguments\n";
8333 theDI << "renderMode: ";
8334 switch (aParams.Method)
8336 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
8337 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
8340 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
8341 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
8342 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
8343 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
8344 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
8345 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
8346 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
8347 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
8348 theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
8349 theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
8350 theDI << "shadingModel: ";
8351 switch (aView->ShadingModel())
8353 case V3d_COLOR: theDI << "color"; break;
8354 case V3d_FLAT: theDI << "flat"; break;
8355 case V3d_GOURAUD: theDI << "gouraud"; break;
8356 case V3d_PHONG: theDI << "phong"; break;
8362 Standard_Boolean toPrint = Standard_False;
8363 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
8364 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
8366 Standard_CString anArg (theArgVec[anArgIter]);
8367 TCollection_AsciiString aFlag (anArg);
8369 if (anUpdateTool.parseRedrawMode (aFlag))
8373 else if (aFlag == "-echo"
8374 || aFlag == "-print")
8376 toPrint = Standard_True;
8377 anUpdateTool.Invalidate();
8379 else if (aFlag == "-mode"
8380 || aFlag == "-rendermode"
8381 || aFlag == "-render_mode")
8385 switch (aParams.Method)
8387 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
8388 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
8394 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8398 else if (aFlag == "-ray"
8399 || aFlag == "-raytrace")
8403 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
8407 aParams.Method = Graphic3d_RM_RAYTRACING;
8409 else if (aFlag == "-rast"
8410 || aFlag == "-raster"
8411 || aFlag == "-rasterization")
8415 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
8419 aParams.Method = Graphic3d_RM_RASTERIZATION;
8421 else if (aFlag == "-msaa")
8425 theDI << aParams.NbMsaaSamples << " ";
8428 else if (++anArgIter >= theArgNb)
8430 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8434 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
8437 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
8442 aParams.NbMsaaSamples = aNbSamples;
8445 else if (aFlag == "-raydepth"
8446 || aFlag == "-ray_depth")
8450 theDI << aParams.RaytracingDepth << " ";
8453 else if (++anArgIter >= theArgNb)
8455 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8459 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
8461 // We allow RaytracingDepth be more than 10 in case of GI enabled
8462 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
8464 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
8469 aParams.RaytracingDepth = aDepth;
8472 else if (aFlag == "-shad"
8473 || aFlag == "-shadows")
8477 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
8481 Standard_Boolean toEnable = Standard_True;
8482 if (++anArgIter < theArgNb
8483 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8487 aParams.IsShadowEnabled = toEnable;
8489 else if (aFlag == "-refl"
8490 || aFlag == "-reflections")
8494 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
8498 Standard_Boolean toEnable = Standard_True;
8499 if (++anArgIter < theArgNb
8500 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8504 aParams.IsReflectionEnabled = toEnable;
8506 else if (aFlag == "-fsaa")
8510 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
8514 Standard_Boolean toEnable = Standard_True;
8515 if (++anArgIter < theArgNb
8516 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8520 aParams.IsAntialiasingEnabled = toEnable;
8522 else if (aFlag == "-gleam")
8526 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
8530 Standard_Boolean toEnable = Standard_True;
8531 if (++anArgIter < theArgNb
8532 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8536 aParams.IsTransparentShadowEnabled = toEnable;
8538 else if (aFlag == "-gi")
8542 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
8546 Standard_Boolean toEnable = Standard_True;
8547 if (++anArgIter < theArgNb
8548 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8552 aParams.IsGlobalIlluminationEnabled = toEnable;
8555 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
8558 else if (aFlag == "-blockedrng"
8559 || aFlag == "-brng")
8563 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
8567 Standard_Boolean toEnable = Standard_True;
8568 if (++anArgIter < theArgNb
8569 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8573 aParams.CoherentPathTracingMode = toEnable;
8575 else if (aFlag == "-iss")
8579 theDI << (aParams.AdaptiveScreenSampling ? "on" : "off") << " ";
8583 Standard_Boolean toEnable = Standard_True;
8584 if (++anArgIter < theArgNb
8585 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8589 aParams.AdaptiveScreenSampling = toEnable;
8591 else if (aFlag == "-issd")
8595 theDI << (aParams.ShowSamplingTiles ? "on" : "off") << " ";
8599 Standard_Boolean toEnable = Standard_True;
8600 if (++anArgIter < theArgNb
8601 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8605 aParams.ShowSamplingTiles = toEnable;
8607 else if (aFlag == "-env")
8611 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
8615 Standard_Boolean toEnable = Standard_True;
8616 if (++anArgIter < theArgNb
8617 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8621 aParams.UseEnvironmentMapBackground = toEnable;
8623 else if (aFlag == "-shademodel"
8624 || aFlag == "-shadingmodel"
8625 || aFlag == "-shading")
8629 switch (aView->ShadingModel())
8631 case V3d_COLOR: theDI << "color "; break;
8632 case V3d_FLAT: theDI << "flat "; break;
8633 case V3d_GOURAUD: theDI << "gouraud "; break;
8634 case V3d_PHONG: theDI << "phong "; break;
8639 if (++anArgIter >= theArgNb)
8641 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8644 TCollection_AsciiString aMode (theArgVec[anArgIter]);
8646 if (aMode == "color"
8649 aView->SetShadingModel (V3d_COLOR);
8651 else if (aMode == "flat"
8652 || aMode == "facet")
8654 aView->SetShadingModel (V3d_FLAT);
8656 else if (aMode == "gouraud"
8657 || aMode == "vertex"
8660 aView->SetShadingModel (V3d_GOURAUD);
8662 else if (aMode == "phong"
8663 || aMode == "fragment"
8665 || aMode == "pixel")
8667 aView->SetShadingModel (V3d_PHONG);
8671 std::cout << "Error: unknown shading model '" << aMode << "'\n";
8675 else if (aFlag == "-resolution")
8677 if (++anArgIter >= theArgNb)
8679 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8683 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
8684 if (aResolution.IsIntegerValue())
8686 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
8690 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
8694 else if (aFlag == "-rebuildglsl"
8695 || aFlag == "-rebuild")
8699 theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " ";
8703 Standard_Boolean toEnable = Standard_True;
8704 if (++anArgIter < theArgNb
8705 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8709 aParams.RebuildRayTracingShaders = toEnable;
8713 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
8721 //=======================================================================
8722 //function : VProgressiveMode
8724 //=======================================================================
8726 static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
8727 Standard_Integer /*theNbArgs*/,
8728 const char** /*theArgs*/)
8730 Handle(V3d_View) aView = ViewerTest::CurrentView();
8733 std::cerr << "Error: no active viewer!\n";
8737 std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
8743 Standard_Boolean toExit = Standard_False;
8746 while (PeekMessage (&aMsg, NULL, 0, 0, PM_REMOVE))
8748 if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
8750 toExit = Standard_True;
8753 TranslateMessage (&aMsg);
8754 DispatchMessage (&aMsg);
8767 //=======================================================================
8768 //function : VFrustumCulling
8769 //purpose : enables/disables view volume's culling.
8770 //=======================================================================
8771 static int VFrustumCulling (Draw_Interpretor& theDI,
8772 Standard_Integer theArgNb,
8773 const char** theArgVec)
8775 Handle(V3d_View) aView = ViewerTest::CurrentView();
8778 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
8784 theDI << (aView->IsCullingEnabled() ? "on" : "off");
8787 else if (theArgNb != 2)
8789 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
8793 TCollection_AsciiString aModeStr (theArgVec[1]);
8794 aModeStr.LowerCase();
8795 Standard_Boolean toEnable = 0;
8796 if (aModeStr == "on")
8800 else if (aModeStr == "off")
8806 toEnable = Draw::Atoi (theArgVec[1]) != 0;
8809 aView->SetFrustumCulling (toEnable);
8814 //=======================================================================
8815 //function : VHighlightSelected
8817 //=======================================================================
8818 static int VHighlightSelected (Draw_Interpretor& theDI,
8819 Standard_Integer theArgNb,
8820 const char** theArgVec)
8822 if (ViewerTest::GetAISContext().IsNull())
8824 std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n";
8828 const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8832 theDI << (aContext->ToHilightSelected() ? "on" : "off");
8838 std::cout << theArgVec[0] << " error : wrong number of parameters."
8839 << "Type 'help" << theArgVec[0] << "' for more information.";
8844 TCollection_AsciiString aMode (theArgVec[1]);
8846 Standard_Boolean toEnable = Standard_False;
8847 if (aMode.IsEqual ("on"))
8849 toEnable = Standard_True;
8851 else if (aMode.IsEqual ("off"))
8853 toEnable = Standard_False;
8857 toEnable = Draw::Atoi (theArgVec[1]) != 0;
8860 if (toEnable != aContext->ToHilightSelected())
8862 aContext->SetToHilightSelected (toEnable);
8864 // Move cursor to null position and back to process updating of detection
8865 // and highlighting of selected object immediatly.
8866 Standard_Integer aPixX = 0;
8867 Standard_Integer aPixY = 0;
8868 const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager();
8870 anEventManager->GetCurrentPosition (aPixX, aPixY);
8871 anEventManager->MoveTo (0, 0);
8872 anEventManager->MoveTo (aPixX, aPixY);
8878 //=======================================================================
8879 //function : VXRotate
8881 //=======================================================================
8882 static Standard_Integer VXRotate (Draw_Interpretor& di,
8883 Standard_Integer argc,
8886 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8887 if (aContext.IsNull())
8889 di << argv[0] << "ERROR : use 'vinit' command before \n";
8895 di << "ERROR : Usage : " << argv[0] << " name angle\n";
8899 TCollection_AsciiString aName (argv[1]);
8900 Standard_Real anAngle = Draw::Atof (argv[2]);
8903 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
8904 Handle(AIS_InteractiveObject) anIObj;
8905 if (!aMap.IsBound2 (aName) )
8907 di << "Use 'vdisplay' before\n";
8912 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
8915 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
8916 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
8918 aContext->SetLocation (anIObj, aTransform);
8919 aContext->UpdateCurrentViewer();
8925 //===============================================================================================
8926 //class : ViewerTest_AISManipulator
8927 //purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances
8928 //===============================================================================================
8929 DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
8931 class ViewerTest_AISManipulator : public AIS_Manipulator
8935 ViewerTest_AISManipulator() : AIS_Manipulator()
8937 GetMapOfAISManipulators().Add (this);
8940 virtual ~ViewerTest_AISManipulator()
8942 GetMapOfAISManipulators().Remove (this);
8945 DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
8948 IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
8949 IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
8951 //===============================================================================================
8952 //function : VManipulator
8954 //===============================================================================================
8955 static int VManipulator (Draw_Interpretor& theDi,
8956 Standard_Integer theArgsNb,
8957 const char** theArgVec)
8959 Handle(V3d_View) aView = ViewerTest::CurrentView();
8960 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
8961 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
8963 || aViewer.IsNull())
8965 std::cerr << "No active viewer!\n";
8969 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
8970 Standard_Integer anArgIter = 1;
8971 for (; anArgIter < theArgsNb; ++anArgIter)
8973 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
8976 ViewerTest_CmdParser aCmd;
8977 aCmd.AddDescription ("Manages manipulator for interactive objects:");
8978 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
8979 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
8980 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
8981 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
8982 aCmd.AddOption ("detach", "... - detach manipulator");
8984 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
8985 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
8986 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
8988 aCmd.AddOption ("move", "... x y z - move object");
8989 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
8990 aCmd.AddOption ("scale", "... factor - scale object");
8992 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
8993 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
8994 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
8995 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
8996 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
8997 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
8998 aCmd.AddOption ("size", "... size - set size of manipulator");
8999 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
9001 aCmd.Parse (theArgsNb, theArgVec);
9003 if (aCmd.HasOption ("help"))
9005 theDi.PrintHelp (theArgVec[0]);
9009 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
9011 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
9013 if (aName.IsEmpty())
9015 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
9019 // ----------------------------------
9020 // detach existing manipulator object
9021 // ----------------------------------
9023 if (aCmd.HasOption ("detach"))
9025 if (!aMapAIS.IsBound2 (aName))
9027 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
9031 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
9032 if (aManipulator.IsNull())
9034 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
9038 aManipulator->Detach();
9039 aMapAIS.UnBind2 (aName);
9040 ViewerTest::GetAISContext()->Remove (aManipulator);
9045 // -----------------------------------------------
9046 // find or create manipulator if it does not exist
9047 // -----------------------------------------------
9049 Handle(AIS_Manipulator) aManipulator;
9050 if (!aMapAIS.IsBound2 (aName))
9052 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
9054 aManipulator = new ViewerTest_AISManipulator();
9055 aMapAIS.Bind (aManipulator, aName);
9059 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
9060 if (aManipulator.IsNull())
9062 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
9067 // -----------------------------------------
9068 // change properties of manipulator instance
9069 // -----------------------------------------
9071 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
9073 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
9075 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
9077 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
9079 if (aCmd.HasOption ("followRotation", 1, Standard_True))
9081 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
9083 if (aCmd.HasOption ("gap", 1, Standard_True))
9085 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
9087 if (aCmd.HasOption ("part", 3, Standard_True))
9089 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
9090 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
9091 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
9092 if (aMode < 1 || aMode > 3)
9094 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 3].\n";
9098 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
9100 if (aCmd.HasOption ("pos", 3, Standard_True))
9102 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
9103 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
9104 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
9106 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
9108 if (aCmd.HasOption ("size", 1, Standard_True))
9110 aManipulator->SetSize (aCmd.ArgFloat ("size"));
9112 if (aCmd.HasOption ("zoomable", 1, Standard_True))
9114 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
9116 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
9118 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
9119 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
9123 // ---------------------------------------------------
9124 // attach, detach or access manipulator from an object
9125 // ---------------------------------------------------
9127 if (aCmd.HasOption ("attach"))
9129 // Find an object and attach manipulator to it
9130 if (!aCmd.HasOption ("attach", 1, Standard_True))
9135 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
9136 if (!aMapAIS.IsBound2 (anObjName))
9138 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
9142 Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (aMapAIS.Find2 (anObjName));
9143 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
9144 for (; anIt.More(); anIt.Next())
9146 if (anIt.Value()->IsAttached()
9147 && anIt.Value()->Object() == anObject)
9149 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
9154 AIS_Manipulator::OptionsForAttach anOptions;
9155 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
9157 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
9159 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
9161 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
9163 if (aCmd.HasOption ("enableModes", 1, Standard_True))
9165 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
9168 aManipulator->Attach (anObject, anOptions);
9171 // --------------------------------------
9172 // apply transformation using manipulator
9173 // --------------------------------------
9175 if (aCmd.HasOption ("startTransform", 2, Standard_True))
9177 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
9179 if (aCmd.HasOption ("transform", 2, Standard_True))
9181 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
9183 if (aCmd.HasOption ("stopTransform"))
9185 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
9187 aManipulator->StopTransform (toApply);
9191 if (aCmd.HasOption ("move", 3, Standard_True))
9193 aT.SetTranslationPart (aCmd.ArgVec ("move"));
9195 if (aCmd.HasOption ("rotate", 7, Standard_True))
9197 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
9199 if (aCmd.HasOption ("scale", 1))
9201 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
9204 if (aT.Form() != gp_Identity)
9206 aManipulator->Transform (aT);
9209 ViewerTest::GetAISContext()->Redisplay (aManipulator);
9214 //===============================================================================================
9215 //function : parseColor
9217 //===============================================================================================
9218 static Standard_Boolean parseColor (ViewerTest_CmdParser& theParser,
9219 const std::string& theOptionName,
9220 Quantity_Color& theColor)
9222 std::string aColorArg = theParser.Arg (theOptionName, 0);
9223 if (std::isdigit (aColorArg[0]))
9225 Graphic3d_Vec3d aColor = theParser.ArgVec3d (theOptionName);
9226 if (aColor.x() < 0.0 || aColor.x() > 1.0
9227 || aColor.y() < 0.0 || aColor.y() > 1.0
9228 || aColor.z() < 0.0 || aColor.z() > 1.0)
9230 std::cerr << "Error: RGB color values should be within range 0..1!\n";
9231 return Standard_False;
9233 theColor.SetValues (aColor.x(), aColor.y(), aColor.z(), Quantity_TOC_RGB);
9237 Quantity_NameOfColor aName = Quantity_NOC_BLACK;
9238 if (!Quantity_Color::ColorFromName (aColorArg.c_str(), aName))
9240 std::cerr << "Name: " << theParser.Arg (theOptionName, 0)
9241 << " does not correspond to any color in Quantity_NameOfColor!"
9243 return Standard_False;
9245 theColor.SetValues (aName);
9248 return Standard_True;
9251 //===============================================================================================
9252 //function : VSelectionProperties
9254 //===============================================================================================
9255 static int VSelectionProperties (Draw_Interpretor& theDi,
9256 Standard_Integer theArgsNb,
9257 const char** theArgVec)
9259 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
9262 std::cerr << "No active viewer!\n";
9266 ViewerTest_CmdParser aCmd;
9268 aCmd.AddOption ("autoActivate");
9269 aCmd.AddOption ("pixTol");
9271 aCmd.AddOption ("selColor");
9272 aCmd.AddOption ("hiColor");
9273 aCmd.AddOption ("selTransp");
9274 aCmd.AddOption ("hiTransp");
9276 aCmd.AddOption ("print");
9278 aCmd.Parse (theArgsNb, theArgVec);
9280 if (aCmd.HasOption ("help"))
9282 theDi.PrintHelp (theArgVec[0]);
9286 if (aCmd.HasOption ("autoActivate", 1, Standard_False))
9288 aCtx->SetAutoActivateSelection (aCmd.ArgBool ("autoActivate"));
9290 if (aCmd.HasOption ("pixTol", 1, Standard_False))
9292 aCtx->SetPixelTolerance (aCmd.ArgInt ("pixTol"));
9295 Handle(Graphic3d_HighlightStyle)& aHiStyle = aCtx->ChangeHighlightStyle();
9296 Handle(Graphic3d_HighlightStyle)& aSelStyle = aCtx->ChangeSelectionStyle();
9297 Standard_Boolean toRedraw = Standard_False;
9298 if (aCmd.HasOption ("selColor"))
9300 Quantity_Color aNewColor;
9301 if (!parseColor (aCmd, "selColor", aNewColor))
9303 aSelStyle->SetColor (aNewColor);
9304 toRedraw = Standard_True;
9306 if (aCmd.HasOption ("hiColor"))
9308 Quantity_Color aNewColor;
9309 if (!parseColor (aCmd, "hiColor", aNewColor))
9311 aHiStyle->SetColor (aNewColor);
9313 if (aCmd.HasOption ("selTransp"))
9315 aSelStyle->SetTransparency (aCmd.ArgFloat ("selTransp"));
9316 toRedraw = Standard_True;
9318 if (aCmd.HasOption ("hiTransp"))
9320 aHiStyle->SetTransparency (aCmd.ArgFloat ("hiTransp"));
9323 if (aCmd.HasOption ("print") || theArgsNb == 1)
9325 theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
9326 theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
9327 theDi << "Selection color : " << Quantity_Color::StringName (aCtx->SelectionStyle()->Color().Name()) << "\n";
9328 theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aCtx->HighlightStyle()->Color().Name()) << "\n";
9329 theDi << "Selection transparency : " << aCtx->SelectionStyle()->Transparency() << "\n";
9330 theDi << "Dynamic highlight transparency : " << aCtx->HighlightStyle()->Transparency() << "\n";
9333 if (aCtx->NbSelected() != 0 && toRedraw)
9335 aCtx->HilightSelected (Standard_True);
9341 //=======================================================================
9342 //function : ViewerCommands
9344 //=======================================================================
9346 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
9349 const char *group = "ZeViewer";
9350 theCommands.Add("vinit",
9351 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
9352 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
9354 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
9356 " - Creates new View window with specified name view_name.\n"
9357 "By default the new view is created in the viewer and in"
9358 " graphic driver shared with active view.\n"
9359 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
9360 "If driverName isn't specified the driver will be shared with active view.\n"
9361 "If viewerName isn't specified the viewer will be shared with active view.\n"
9362 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
9363 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
9364 "is used in creation of graphic driver\n"
9366 " - l, t: pixel position of left top corner of the window\n"
9367 " - w,h: width and heigth of window respectively.\n"
9368 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
9369 __FILE__,VInit,group);
9370 theCommands.Add("vclose" ,
9371 "[view_id [keep_context=0|1]]\n"
9372 "or vclose ALL - to remove all created views\n"
9373 " - removes view(viewer window) defined by its view_id.\n"
9374 " - keep_context: by default 0; if 1 and the last view is deleted"
9375 " the current context is not removed.",
9376 __FILE__,VClose,group);
9377 theCommands.Add("vactivate" ,
9379 " - activates view(viewer window) defined by its view_id",
9380 __FILE__,VActivate,group);
9381 theCommands.Add("vviewlist",
9382 "vviewlist [format={tree, long}]"
9383 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
9384 " - format: format of result output, if tree the output is a tree view;"
9385 "otherwise it's a list of full view names. By default format = tree",
9386 __FILE__,VViewList,group);
9387 theCommands.Add("vhelp" ,
9388 "vhelp : display help on the viewer commands",
9389 __FILE__,VHelp,group);
9390 theCommands.Add("vtop" ,
9391 "vtop or <T> : Top view. Orientation +X+Y" ,
9392 __FILE__,VTop,group);
9393 theCommands.Add("vbottom" ,
9394 "vbottom : Bottom view. Orientation +X-Y" ,
9395 __FILE__,VBottom,group);
9396 theCommands.Add("vleft" ,
9397 "vleft : Left view. Orientation -Y+Z" ,
9398 __FILE__,VLeft,group);
9399 theCommands.Add("vright" ,
9400 "vright : Right view. Orientation +Y+Z" ,
9401 __FILE__,VRight,group);
9402 theCommands.Add("vaxo" ,
9403 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
9404 __FILE__,VAxo,group);
9405 theCommands.Add("vfront" ,
9406 "vfront : Front view. Orientation +X+Z" ,
9407 __FILE__,VFront,group);
9408 theCommands.Add("vback" ,
9409 "vback : Back view. Orientation -X+Z" ,
9410 __FILE__,VBack,group);
9411 theCommands.Add("vpick" ,
9412 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
9414 theCommands.Add("vfit" ,
9415 "vfit or <F> [-selected]"
9416 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
9417 __FILE__,VFit,group);
9418 theCommands.Add ("vfitarea",
9419 "vfitarea x1 y1 x2 y2"
9420 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
9421 "\n\t\t: Fit view to show area located between two points"
9422 "\n\t\t: given in world 2D or 3D corrdinates.",
9423 __FILE__, VFitArea, group);
9424 theCommands.Add ("vzfit", "vzfit [scale]\n"
9425 " Matches Z near, Z far view volume planes to the displayed objects.\n"
9426 " \"scale\" - specifies factor to scale computed z range.\n",
9427 __FILE__, VZFit, group);
9428 theCommands.Add("vrepaint",
9429 "vrepaint : vrepaint, force redraw",
9430 __FILE__,VRepaint,group);
9431 theCommands.Add("vclear",
9433 "\n\t\t: remove all the object from the viewer",
9434 __FILE__,VClear,group);
9435 theCommands.Add("vsetbg",
9436 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
9437 __FILE__,VSetBg,group);
9438 theCommands.Add("vsetbgmode",
9439 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
9440 __FILE__,VSetBgMode,group);
9441 theCommands.Add("vsetgradientbg",
9442 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
9443 __FILE__,VSetGradientBg,group);
9444 theCommands.Add("vsetgrbgmode",
9445 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
9446 __FILE__,VSetGradientBgMode,group);
9447 theCommands.Add("vsetcolorbg",
9448 "vsetcolorbg : vsetcolorbg r g b : Set background color",
9449 __FILE__,VSetColorBg,group);
9450 theCommands.Add("vsetdefaultbg",
9451 "vsetdefaultbg r g b\n"
9452 "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode"
9453 "\n\t\t: Set default viewer background fill color (flat/gradient).",
9454 __FILE__,VSetDefaultBg,group);
9455 theCommands.Add("vscale",
9456 "vscale : vscale X Y Z",
9457 __FILE__,VScale,group);
9458 theCommands.Add("vzbufftrihedron",
9459 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
9460 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
9461 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
9462 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
9463 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
9464 "\n\t\t: Displays a trihedron",
9465 __FILE__,VZBuffTrihedron,group);
9466 theCommands.Add("vrotate",
9467 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
9468 "\n : Option -mouseStart starts rotation according to the mouse position"
9469 "\n : Option -mouseMove continues rotation with angle computed"
9470 "\n : from last and new mouse position."
9471 "\n : vrotate AX AY AZ [X Y Z]",
9472 __FILE__,VRotate,group);
9473 theCommands.Add("vzoom",
9474 "vzoom : vzoom coef",
9475 __FILE__,VZoom,group);
9476 theCommands.Add("vpan",
9477 "vpan : vpan dx dy",
9478 __FILE__,VPan,group);
9479 theCommands.Add("vexport",
9480 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
9481 " : exports the view to a vector file of a given format"
9482 " : notice that EMF format requires patched gl2ps",
9483 __FILE__,VExport,group);
9484 theCommands.Add("vcolorscale",
9485 "vcolorscale : vcolorscale name [-range RangeMin = 0 RangeMax = 100 Intervals = 10 -font HeightFont = 16 -textpos "
9486 "Position = left -xy X = 0 Y = 0] [-noupdate|-update]: draw color scale\n"
9487 "-demo/-demoversion draw a demoversion of color scale.\n"
9488 "-show/display display color scale.\n"
9489 "-hide/erase erase color scale.\n"
9490 "Please note that -show/-hide option must be the first argument!\n"
9491 "-color Index R G B: set color for indexed interval\n"
9492 "-color Index ColorName: set color for indexed interval\n"
9493 "-colors R G B R G B ...: set colors for all intervals\n"
9494 "-colors ColorName1 ColorName2 ...: set colors for all intervals\n"
9495 "-colors supports both color names and rgb values in one call\n"
9496 "-label Index Text: set label for indexed interval\n"
9497 "-labels Text Text Text ...: set labels for all intervals\n"
9498 "-title Title [Position]: set the title for color scale with certain position. Default position = center;\n"
9499 "Available text positions: left, right, center, none;\n",
9500 __FILE__,VColorScale,group);
9501 theCommands.Add("vgraduatedtrihedron",
9502 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
9503 "\t[-namefont Name] [-valuesfont Name]\n"
9504 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
9505 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
9506 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
9507 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
9508 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
9509 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
9510 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
9511 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
9512 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
9513 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
9514 " - Displays or erases graduated trihedron"
9515 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
9516 " - namefont - font of axes names. Default: Arial\n"
9517 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
9518 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
9519 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
9520 " - valuesfont - font of axes values. Default: Arial\n"
9521 " - xcolor, ycolor, zcolor - color of axis and values\n"
9522 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
9523 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
9524 __FILE__,VGraduatedTrihedron,group);
9525 theCommands.Add("vtile" ,
9526 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
9527 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
9528 "\n\t\t: -totalSize the size of virtual bigger viewport"
9529 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
9530 "\n\t\t: -lowerLeft tile offset as lower left corner"
9531 "\n\t\t: -upperLeft tile offset as upper left corner",
9532 __FILE__, VTile, group);
9533 theCommands.Add("vzlayer",
9535 "\n\t\t: [-add|-delete|-get|-settings]"
9536 "\n\t\t: [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
9537 "\n\t\t: [-enable|-disable {positiveOffset|negativeOffset|textureenv}]"
9538 "\n\t\t: ZLayer list management:"
9539 "\n\t\t: -add add new z layer to viewer and print its id"
9540 "\n\t\t: -delete delete z layer"
9541 "\n\t\t: -get print sequence of z layers"
9542 "\n\t\t: -settings print status of z layer settings"
9543 "\n\t\t: -disable disables given setting"
9544 "\n\t\t: -enable enables given setting",
9545 __FILE__,VZLayer,group);
9546 theCommands.Add("vlayerline",
9547 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
9548 __FILE__,VLayerLine,group);
9549 theCommands.Add ("vgrid",
9550 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
9551 " : Mode - rectangular or circular"
9552 " : Type - lines or points",
9553 __FILE__, VGrid, group);
9554 theCommands.Add ("vpriviledgedplane",
9555 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
9556 "\n\t\t: Ox, Oy, Oz - plane origin"
9557 "\n\t\t: Nx, Ny, Nz - plane normal direction"
9558 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
9559 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
9560 __FILE__, VPriviledgedPlane, group);
9561 theCommands.Add ("vconvert",
9562 "vconvert v [Mode={window|view}]"
9563 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
9564 "\n\t\t: vconvert x y z [Mode={window|grid}]"
9565 "\n\t\t: window - convert to window coordinates, pixels"
9566 "\n\t\t: view - convert to view projection plane"
9567 "\n\t\t: grid - convert to model coordinates, given on grid"
9568 "\n\t\t: ray - convert projection ray to model coordiantes"
9569 "\n\t\t: - vconvert v window : convert view to window;"
9570 "\n\t\t: - vconvert v view : convert window to view;"
9571 "\n\t\t: - vconvert x y window : convert view to window;"
9572 "\n\t\t: - vconvert x y view : convert window to view;"
9573 "\n\t\t: - vconvert x y : convert window to model;"
9574 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
9575 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
9576 "\n\t\t: - vconvert x y z window : convert model to window;"
9577 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
9578 "\n\t\t: Converts the given coordinates to window/view/model space.",
9579 __FILE__, VConvert, group);
9580 theCommands.Add ("vfps",
9581 "vfps [framesNb=100] : estimate average frame rate for active view",
9582 __FILE__, VFps, group);
9583 theCommands.Add ("vgldebug",
9584 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
9585 "\n\t\t: [-extraMsg {0|1}] [{0|1}]"
9586 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
9587 "\n\t\t: Debug context can be requested only on Windows"
9588 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
9589 "\n\t\t: -sync - request synchronized debug GL context"
9590 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
9591 "\n\t\t: which are suppressed by default,"
9592 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
9593 "\n\t\t: which are suppressed by default",
9594 __FILE__, VGlDebug, group);
9595 theCommands.Add ("vvbo",
9596 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
9597 __FILE__, VVbo, group);
9598 theCommands.Add ("vstereo",
9599 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
9600 "\n\t\t: [-anaglyph Filter]"
9601 "\n\t\t: Control stereo output mode. Available modes for -mode:"
9602 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
9603 "\n\t\t: requires driver support."
9604 "\n\t\t: Should be called BEFORE vinit!"
9605 "\n\t\t: anaglyph - Anaglyph glasses"
9606 "\n\t\t: rowInterlaced - row-interlaced display"
9607 "\n\t\t: columnInterlaced - column-interlaced display"
9608 "\n\t\t: chessBoard - chess-board output"
9609 "\n\t\t: sideBySide - horizontal pair"
9610 "\n\t\t: overUnder - vertical pair"
9611 "\n\t\t: Available Anaglyph filters for -anaglyph:"
9612 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
9613 "\n\t\t: greenMagentaSimple",
9614 __FILE__, VStereo, group);
9615 theCommands.Add ("vcaps",
9616 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
9617 "\n\t\t: [-compatibleProfile {0|1}]"
9618 "\n\t\t: [-vsync {0|1}]"
9619 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
9620 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
9621 "\n\t\t: Modify particular graphic driver options:"
9622 "\n\t\t: FFP - use fixed-function pipeline instead of"
9623 "\n\t\t: built-in GLSL programs"
9624 "\n\t\t: (requires compatible profile)"
9625 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
9626 "\n\t\t: arrays to GPU memory)"
9627 "\n\t\t: sprite - use textured sprites instead of bitmaps"
9628 "\n\t\t: vsync - switch VSync on or off"
9629 "\n\t\t: Context creation options:"
9630 "\n\t\t: softMode - software OpenGL implementation"
9631 "\n\t\t: compatibleProfile - backward-compatible profile"
9632 "\n\t\t: quadbuffer - QuadBuffer"
9633 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
9634 "\n\t\t: rendering paths producing the same visual result when"
9636 "\n\t\t: Command is intended for testing old hardware compatibility.",
9637 __FILE__, VCaps, group);
9638 theCommands.Add ("vmemgpu",
9639 "vmemgpu [f]: print system-dependent GPU memory information if available;"
9640 " with f option returns free memory in bytes",
9641 __FILE__, VMemGpu, group);
9642 theCommands.Add ("vreadpixel",
9643 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
9644 " : Read pixel value for active view",
9645 __FILE__, VReadPixel, group);
9646 theCommands.Add("diffimage",
9647 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
9648 __FILE__, VDiffImage, group);
9649 theCommands.Add ("vselect",
9650 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
9651 "- emulates different types of selection:\n"
9652 "- 1) single click selection\n"
9653 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
9654 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
9655 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
9656 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
9657 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
9658 " (partial inclusion - overlap - is not allowed by default)\n"
9659 "- 5) any of these selections with shift button pressed",
9660 __FILE__, VSelect, group);
9661 theCommands.Add ("vmoveto",
9663 "- emulates cursor movement to pixel postion (x,y)",
9664 __FILE__, VMoveTo, group);
9665 theCommands.Add ("vviewparams", "vviewparams usage:\n"
9667 "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n"
9668 " [-proj [x y z]] [-center x y] [-size sx]\n"
9669 "- Gets or sets current view parameters.\n"
9670 "- If called without arguments, all view parameters are printed.\n"
9671 "- The options are:\n"
9672 " -scale [s] : prints or sets viewport relative scale.\n"
9673 " -eye [x y z] : prints or sets eye location.\n"
9674 " -at [x y z] : prints or sets center of look.\n"
9675 " -up [x y z] : prints or sets direction of up vector.\n"
9676 " -proj [x y z] : prints or sets direction of look.\n"
9677 " -center x y : sets location of center of the screen in pixels.\n"
9678 " -size [sx] : prints viewport projection width and height sizes\n"
9679 " : or changes the size of its maximum dimension.\n",
9680 __FILE__, VViewParams, group);
9681 theCommands.Add("vchangeselected",
9682 "vchangeselected shape"
9683 "- adds to shape to selection or remove one from it",
9684 __FILE__, VChangeSelected, group);
9685 theCommands.Add ("vnbselected",
9687 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
9688 theCommands.Add ("vcamera",
9689 "vcamera [-ortho] [-projtype]"
9691 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
9692 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
9693 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
9694 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
9695 "\n\t\t: Manage camera parameters."
9696 "\n\t\t: Prints current value when option called without argument."
9697 "\n\t\t: Orthographic camera:"
9698 "\n\t\t: -ortho activate orthographic projection"
9699 "\n\t\t: Perspective camera:"
9700 "\n\t\t: -persp activate perspective projection (mono)"
9701 "\n\t\t: -fovy field of view in y axis, in degrees"
9702 "\n\t\t: -distance distance of eye from camera center"
9703 "\n\t\t: Stereoscopic camera:"
9704 "\n\t\t: -stereo perspective projection (stereo)"
9705 "\n\t\t: -leftEye perspective projection (left eye)"
9706 "\n\t\t: -rightEye perspective projection (right eye)"
9707 "\n\t\t: -iod intraocular distance value"
9708 "\n\t\t: -iodType distance type, absolute or relative"
9709 "\n\t\t: -zfocus stereographic focus value"
9710 "\n\t\t: -zfocusType focus type, absolute or relative",
9711 __FILE__, VCamera, group);
9712 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
9713 "- vautozfit [on={1|0}] [scale]\n"
9714 " Prints or changes parameters of automatic z-fit mode:\n"
9715 " \"on\" - turns automatic z-fit on or off\n"
9716 " \"scale\" - specifies factor to scale computed z range.\n",
9717 __FILE__, VAutoZFit, group);
9718 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
9719 " vzrange - without parameters shows current values\n"
9720 " vzrange [znear] [zfar] - applies provided values to view",
9721 __FILE__,VZRange, group);
9722 theCommands.Add ("vpurgedisplay",
9724 "- removes structures which don't belong to objects displayed in neutral point",
9725 __FILE__, VPurgeDisplay, group);
9726 theCommands.Add("vsetviewsize",
9727 "vsetviewsize size",
9728 __FILE__,VSetViewSize,group);
9729 theCommands.Add("vmoveview",
9730 "vmoveview Dx Dy Dz [Start = 1|0]",
9731 __FILE__,VMoveView,group);
9732 theCommands.Add("vtranslateview",
9733 "vtranslateview Dx Dy Dz [Start = 1|0)]",
9734 __FILE__,VTranslateView,group);
9735 theCommands.Add("vturnview",
9736 "vturnview Ax Ay Az [Start = 1|0]",
9737 __FILE__,VTurnView,group);
9738 theCommands.Add("vtextureenv",
9739 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
9740 "or user-defined file and optionally applying texture mapping parameters\n"
9742 " vtextureenv off - disables environment mapping\n"
9743 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
9744 " std_texture = (0..7)\n"
9745 " rep = {clamp|repeat}\n"
9746 " mod = {decal|modulate}\n"
9747 " flt = {nearest|bilinear|trilinear}\n"
9748 " ss, st - scale factors for s and t texture coordinates\n"
9749 " ts, tt - translation for s and t texture coordinates\n"
9750 " rot - texture rotation angle in degrees",
9751 __FILE__, VTextureEnv, group);
9752 theCommands.Add("vhlr" ,
9753 "is_enabled={on|off} [show_hidden={1|0}]"
9754 " - Hidden line removal algorithm:"
9755 " - is_enabled: if is on HLR algorithm is applied\n"
9756 " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n",
9757 __FILE__,VHLR,group);
9758 theCommands.Add("vhlrtype" ,
9759 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
9760 " - Changes the type of HLR algorithm using for shapes."
9761 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
9762 " if equals to polyalgo, polygonal HLR algorithm is applied."
9763 "If shapes are not given HLR algoithm of given type is applied"
9764 " to all shapes in the view\n",
9765 __FILE__,VHLRType,group);
9766 theCommands.Add("vclipplane",
9767 "vclipplane planeName [{0|1}]"
9768 "\n\t\t: [-equation A B C D]"
9769 "\n\t\t: [-set|-unset [objects|views]]"
9770 "\n\t\t: [-maxPlanes]"
9771 "\n\t\t: [-capping {0|1}]"
9772 "\n\t\t: [-color R G B] [-hatch {on|off|ID}]"
9773 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
9774 "\n\t\t: [-texRotate Angle]"
9775 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
9776 "\n\t\t: [-useObjShader {0|1}]"
9777 "\n\t\t: Clipping planes management:"
9778 "\n\t\t: -maxPlanes print plane limit for view"
9779 "\n\t\t: -delete delete plane with given name"
9780 "\n\t\t: {off|on|0|1} turn clipping on/off"
9781 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
9782 "\n\t\t: applied to active View when list is omitted"
9783 "\n\t\t: -equation A B C D change plane equation"
9784 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
9785 "\n\t\t: Capping options:"
9786 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
9787 "\n\t\t: -color R G B set capping color"
9788 "\n\t\t: -texName Texture set capping texture"
9789 "\n\t\t: -texScale SX SY set capping tex scale"
9790 "\n\t\t: -texOrigin TX TY set capping tex origin"
9791 "\n\t\t: -texRotate Angle set capping tex rotation"
9792 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
9793 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
9794 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
9795 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
9796 __FILE__, VClipPlane, group);
9797 theCommands.Add("vdefaults",
9798 "vdefaults [-absDefl value]"
9799 "\n\t\t: [-devCoeff value]"
9800 "\n\t\t: [-angDefl value]"
9801 "\n\t\t: [-autoTriang {off/on | 0/1}]"
9802 , __FILE__, VDefaults, group);
9803 theCommands.Add("vlight",
9804 "tool to manage light sources, without arguments shows list of lights."
9805 "\n Main commands: "
9806 "\n 'clear' to clear lights"
9807 "\n '{def}aults' to load deafault lights"
9808 "\n 'add' (or 'new') <type> to add any light source"
9809 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
9810 "\n 'change' <lightId> to edit light source with specified lightId"
9811 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
9812 "\n {pos}ition X Y Z"
9813 "\n {dir}ection X Y Z (for directional light or for spotlight)"
9814 "\n color colorName"
9815 "\n {head}light 0|1"
9816 "\n {sm}oothness value"
9817 "\n {int}ensity value"
9818 "\n {constAtten}uation value"
9819 "\n {linearAtten}uation value"
9821 "\n {spotexp}onent value"
9823 "\n\n example: vlight add positional head 1 pos 0 1 1 color red"
9824 "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
9825 __FILE__, VLight, group);
9826 theCommands.Add("vraytrace",
9828 "\n\t\t: Turns on/off ray-tracing renderer."
9829 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
9830 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
9831 __FILE__, VRenderParams, group);
9832 theCommands.Add("vrenderparams",
9833 "\n Manages rendering parameters: "
9834 "\n '-raster' Disables GPU ray-tracing"
9835 "\n '-msaa 0..4' Specifies number of samples for MSAA"
9836 "\n '-rayTrace' Enables GPU ray-tracing"
9837 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
9838 "\n '-shadows on|off' Enables/disables shadows rendering"
9839 "\n '-reflections on|off' Enables/disables specular reflections"
9840 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
9841 "\n '-gleam on|off' Enables/disables transparency shadow effects"
9842 "\n '-gi on|off' Enables/disables global illumination effects"
9843 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
9844 "\n '-env on|off' Enables/disables environment map background"
9845 "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
9846 "\n '-issd on|off' Shows screen sampling distribution in ISS mode"
9847 "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
9848 "\n '-shadingModel model' Controls shading model from enumeration"
9849 "\n color, flat, gouraud, phong"
9850 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
9851 "\n Unlike vcaps, these parameters dramatically change visual properties."
9852 "\n Command is intended to control presentation quality depending on"
9853 "\n hardware capabilities and performance.",
9854 __FILE__, VRenderParams, group);
9855 theCommands.Add("vfrustumculling",
9856 "vfrustumculling [toEnable]: enables/disables objects clipping",
9857 __FILE__,VFrustumCulling,group);
9858 theCommands.Add("vhighlightselected",
9859 "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n"
9860 "Without arguments it shows if highlighting of selected objects is enabled now.",
9861 __FILE__,VHighlightSelected,group);
9862 theCommands.Add ("vplace",
9864 "\n\t\t: Places the point (in pixels) at the center of the window",
9865 __FILE__, VPlace, group);
9866 theCommands.Add("vxrotate",
9868 __FILE__,VXRotate,group);
9870 theCommands.Add("vmanipulator",
9871 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
9872 "\n tool to create and manage AIS manipulators."
9874 "\n '-attach AISObject' attach manipulator to AISObject"
9875 "\n '-adjustPosition {0|1}' adjust position when attaching"
9876 "\n '-adjustSize {0|1}' adjust size when attaching"
9877 "\n '-enableModes {0|1}' enable modes when attaching"
9878 "\n '-detach' detach manipulator"
9879 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
9880 "\n '-transform mouse_x mouse_y' - invoke transformation"
9881 "\n '-stopTransform [abort]' - invoke stop of transformation"
9882 "\n '-move x y z' - move attached object"
9883 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
9884 "\n '-scale factor' - scale attached object"
9885 "\n '-autoActivate {0|1}' - set activation on detection"
9886 "\n '-followTranslation {0|1}' - set following translation transform"
9887 "\n '-followRotation {0|1}' - set following rotation transform"
9888 "\n '-gap value' - set gap between sub-parts"
9889 "\n '-part axis mode {0|1}' - set visual part"
9890 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
9891 "\n '-size value' - set size of manipulator"
9892 "\n '-zoomable {0|1}' - set zoom persistence",
9893 __FILE__, VManipulator, group);
9895 theCommands.Add("vselprops",
9896 "\n vselprops [options]"
9897 "\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
9898 "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
9899 "\n -pixTol value : sets up pixel tolerance"
9900 "\n -selColor {name|r g b} : sets selection color"
9901 "\n -hiColor {name|r g b} : sets dynamic highlight color"
9902 "\n -selTransp value : sets transparency coefficient for selection"
9903 "\n -hiTransp value : sets transparency coefficient for dynamic highlight"
9904 "\n -print : prints current state of all mentioned parameters",
9905 __FILE__, VSelectionProperties, group);
9908 theCommands.Add("vprogressive",
9910 __FILE__, VProgressiveMode, group);