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_Shape.hxx>
20 #include <AIS_InteractiveObject.hxx>
21 #include <AIS_ListOfInteractive.hxx>
22 #include <AIS_ListIteratorOfListOfInteractive.hxx>
24 #include <Graphic3d_ArrayOfPolylines.hxx>
25 #include <Graphic3d_AspectMarker3d.hxx>
26 #include <Graphic3d_ExportFormat.hxx>
27 #include <Graphic3d_NameOfTextureEnv.hxx>
28 #include <Graphic3d_GraduatedTrihedron.hxx>
29 #include <Graphic3d_TextureEnv.hxx>
30 #include <Graphic3d_TextureParams.hxx>
31 #include <Graphic3d_TypeOfTextureFilter.hxx>
32 #include <Graphic3d_AspectFillArea3d.hxx>
33 #include <ViewerTest.hxx>
34 #include <ViewerTest_AutoUpdater.hxx>
35 #include <ViewerTest_EventManager.hxx>
36 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
37 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
38 #include <V3d_AmbientLight.hxx>
39 #include <V3d_DirectionalLight.hxx>
40 #include <V3d_PositionalLight.hxx>
41 #include <V3d_SpotLight.hxx>
42 #include <NCollection_DoubleMap.hxx>
43 #include <NCollection_List.hxx>
44 #include <NCollection_Vector.hxx>
45 #include <AIS_InteractiveContext.hxx>
46 #include <Draw_Interpretor.hxx>
48 #include <Draw_Appli.hxx>
49 #include <Aspect_PrintAlgo.hxx>
50 #include <Image_AlienPixMap.hxx>
51 #include <OpenGl_GraphicDriver.hxx>
52 #include <OSD_Timer.hxx>
53 #include <TColStd_HSequenceOfAsciiString.hxx>
54 #include <TColStd_SequenceOfInteger.hxx>
55 #include <TColStd_HSequenceOfReal.hxx>
56 #include <TColgp_Array1OfPnt2d.hxx>
57 #include <TColStd_MapOfAsciiString.hxx>
58 #include <Aspect_TypeOfLine.hxx>
59 #include <Image_Diff.hxx>
60 #include <Aspect_DisplayConnection.hxx>
64 #include <PrsMgr_PresentableObject.hxx>
65 #include <Graphic3d_ClipPlane.hxx>
66 #include <NCollection_DataMap.hxx>
67 #include <Graphic3d_Texture2Dmanual.hxx>
68 #include <Prs3d_ShadingAspect.hxx>
69 #include <Prs3d_Drawer.hxx>
70 #include <Prs3d_LineAspect.hxx>
71 #include <Prs3d_Root.hxx>
80 #include <WNT_WClass.hxx>
81 #include <WNT_Window.hxx>
84 #define _CRT_SECURE_NO_DEPRECATE
85 #pragma warning (disable:4996)
87 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
88 #include <Cocoa_Window.hxx>
90 #include <Xw_Window.hxx>
91 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
92 #include <X11/Xutil.h>
96 // Auxiliary definitions
97 static const char THE_KEY_DELETE = 127;
99 //==============================================================================
100 // VIEWER GLOBAL VARIABLES
101 //==============================================================================
103 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
104 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
106 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
107 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
109 extern int VErase (Draw_Interpretor& theDI,
110 Standard_Integer theArgNb,
111 const char** theArgVec);
114 static Handle(WNT_Window)& VT_GetWindow() {
115 static Handle(WNT_Window) WNTWin;
118 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
119 static Handle(Cocoa_Window)& VT_GetWindow()
121 static Handle(Cocoa_Window) aWindow;
124 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
125 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
126 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
129 static Handle(Xw_Window)& VT_GetWindow(){
130 static Handle(Xw_Window) XWWin;
134 static void VProcessEvents(ClientData,int);
137 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
139 static Handle(Aspect_DisplayConnection) aDisplayConnection;
140 return aDisplayConnection;
143 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
145 GetDisplayConnection() = theDisplayConnection;
148 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
149 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
151 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
153 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
154 if (!aWindow.IsNull())
155 return aWindow->HWindow();
156 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
157 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
158 if (!aWindow.IsNull())
159 return aWindow->XWindow();
161 return aWindowHandle;
165 static Standard_Boolean MyHLRIsOn = Standard_False;
167 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
168 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
169 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
170 static OpenGl_Caps ViewerTest_myDefaultCaps;
172 #define ZCLIPWIDTH 1.
174 static void OSWindowSetup();
178 Quantity_Color FlatColor;
179 Quantity_Color GradientColor1;
180 Quantity_Color GradientColor2;
181 Aspect_GradientFillMethod FillMethod;
182 } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
184 //==============================================================================
185 // EVENT GLOBAL VARIABLES
186 //==============================================================================
188 static int Start_Rot = 0;
189 static int ZClipIsOn = 0;
190 int X_Motion = 0; // Current cursor position
192 int X_ButtonPress = 0; // Last ButtonPress position
193 int Y_ButtonPress = 0;
194 Standard_Boolean IsDragged = Standard_False;
195 Standard_Boolean DragFirst = Standard_False;
197 //==============================================================================
200 static LRESULT WINAPI ViewerWindowProc(
205 static LRESULT WINAPI AdvViewerWindowProc(
213 //==============================================================================
216 //==============================================================================
218 const Handle(MMgt_TShared)& ViewerTest::WClass()
220 static Handle(MMgt_TShared) theWClass;
222 if (theWClass.IsNull())
224 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
225 CS_VREDRAW | CS_HREDRAW, 0, 0,
226 ::LoadCursor (NULL, IDC_ARROW));
232 //==============================================================================
233 //function : CreateName
234 //purpose : Create numerical name for new object in theMap
235 //==============================================================================
236 template <typename ObjectType>
237 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
238 const TCollection_AsciiString& theDefaultString)
240 if (theObjectMap.IsEmpty())
241 return theDefaultString + TCollection_AsciiString(1);
243 Standard_Integer aNextKey = 1;
244 Standard_Boolean isFound = Standard_False;
247 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
248 // Look for objects with default names
249 if (theObjectMap.IsBound1(aStringKey))
254 isFound = Standard_True;
257 return theDefaultString + TCollection_AsciiString(aNextKey);
260 //==============================================================================
261 //structure : ViewerTest_Names
262 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
263 //==============================================================================
264 struct ViewerTest_Names
267 TCollection_AsciiString myDriverName;
268 TCollection_AsciiString myViewerName;
269 TCollection_AsciiString myViewName;
273 const TCollection_AsciiString& GetDriverName () const
277 void SetDriverName (const TCollection_AsciiString& theDriverName)
279 myDriverName = theDriverName;
281 const TCollection_AsciiString& GetViewerName () const
285 void SetViewerName (const TCollection_AsciiString& theViewerName)
287 myViewerName = theViewerName;
289 const TCollection_AsciiString& GetViewName () const
293 void SetViewName (const TCollection_AsciiString& theViewName)
295 myViewName = theViewName;
298 //===========================================================================
299 //function : Constructor for ViewerTest_Names
300 //purpose : Get view, viewer, driver names from custom string
301 //===========================================================================
303 ViewerTest_Names (const TCollection_AsciiString& theInputString)
305 TCollection_AsciiString aName(theInputString);
306 if (theInputString.IsEmpty())
308 // Get current configuration
309 if (ViewerTest_myDrivers.IsEmpty())
310 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
311 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
313 myDriverName = ViewerTest_myDrivers.Find2
314 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
316 if(ViewerTest_myContexts.IsEmpty())
318 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
319 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
322 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
324 myViewName = CreateName <Handle(V3d_View)>
325 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
329 // There is at least view name
330 Standard_Integer aParserNumber = 0;
331 for (Standard_Integer i = 0; i < 3; ++i)
333 Standard_Integer aParserPos = aName.SearchFromEnd("/");
337 aName.Split(aParserPos-1);
342 if (aParserNumber == 0)
345 if (!ViewerTest::GetAISContext().IsNull())
347 myDriverName = ViewerTest_myDrivers.Find2
348 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
349 myViewerName = ViewerTest_myContexts.Find2
350 (ViewerTest::GetAISContext());
354 // There is no opened contexts here, need to create names for viewer and driver
355 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
356 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
358 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
359 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
361 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
363 else if (aParserNumber == 1)
365 // Here is viewerName/viewName
366 if (!ViewerTest::GetAISContext().IsNull())
367 myDriverName = ViewerTest_myDrivers.Find2
368 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
371 // There is no opened contexts here, need to create name for driver
372 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
373 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
375 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
377 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
381 //Here is driverName/viewerName/viewName
382 myDriverName = TCollection_AsciiString(aName);
384 TCollection_AsciiString aViewerName(theInputString);
385 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
386 myViewerName = TCollection_AsciiString(aViewerName);
388 myViewName = TCollection_AsciiString(theInputString);
394 //==============================================================================
395 //function : FindContextByView
396 //purpose : Find AIS_InteractiveContext by View
397 //==============================================================================
399 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
401 Handle(AIS_InteractiveContext) anAISContext;
403 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
404 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
406 if (anIter.Value()->CurrentViewer() == theView->Viewer())
407 return anIter.Key2();
413 //==============================================================================
414 //function : SetWindowTitle
415 //purpose : Set window title
416 //==============================================================================
418 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
419 Standard_CString theTitle)
422 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
424 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
425 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
427 if(GetDisplayConnection()->GetDisplay())
430 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
431 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
436 //==============================================================================
437 //function : IsWindowOverlapped
438 //purpose : Check if theWindow overlapp another view
439 //==============================================================================
441 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
442 const Standard_Integer thePxTop,
443 const Standard_Integer thePxRight,
444 const Standard_Integer thePxBottom,
445 TCollection_AsciiString& theViewId)
447 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
448 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
450 Standard_Integer aTop = 0,
454 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
455 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
456 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
457 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
458 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
460 theViewId = anIter.Key1();
461 return Standard_True;
464 return Standard_False;
467 // Workaround: to create and delete non-orthographic views outside ViewerTest
468 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
470 ViewerTest_myViews.UnBind1 (theName);
473 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
474 const Handle(V3d_View)& theView)
476 ViewerTest_myViews.Bind (theName, theView);
479 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
481 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
483 //==============================================================================
484 //function : ViewerInit
485 //purpose : Create the window viewer and initialize all the global variable
486 //==============================================================================
488 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
489 const Standard_Integer thePxTop,
490 const Standard_Integer thePxWidth,
491 const Standard_Integer thePxHeight,
492 Standard_CString theViewName,
493 Standard_CString theDisplayName)
495 // Default position and dimension of the viewer window.
496 // Note that left top corner is set to be sufficiently small to have
497 // window fit in the small screens (actual for remote desktops, see #23003).
498 // The position corresponds to the window's client area, thus some
499 // gap is added for window frame to be visible.
500 Standard_Integer aPxLeft = 20;
501 Standard_Integer aPxTop = 40;
502 Standard_Integer aPxWidth = 409;
503 Standard_Integer aPxHeight = 409;
504 Standard_Boolean toCreateViewer = Standard_False;
506 Handle(OpenGl_GraphicDriver) aGraphicDriver;
507 ViewerTest_Names aViewNames(theViewName);
508 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
509 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
516 aPxWidth = thePxWidth;
517 if (thePxHeight != 0)
518 aPxHeight = thePxHeight;
520 // Get graphic driver (create it or get from another view)
521 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
523 // Get connection string
524 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
525 TCollection_AsciiString aDisplayName(theDisplayName);
526 if (!aDisplayName.IsEmpty())
527 SetDisplayConnection (new Aspect_DisplayConnection ());
529 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
531 (void)theDisplayName; // avoid warning on unused argument
532 SetDisplayConnection (new Aspect_DisplayConnection ());
534 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
535 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
536 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
537 toCreateViewer = Standard_True;
541 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
544 //Dispose the window if input parameters are default
545 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
547 Standard_Integer aTop = 0,
554 // Get screen resolution
555 #if defined(_WIN32) || defined(__WIN32__)
557 GetClientRect(GetDesktopWindow(), &aWindowSize);
558 aScreenHeight = aWindowSize.bottom;
559 aScreenWidth = aWindowSize.right;
560 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
561 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
563 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
564 aScreenWidth = WidthOfScreen(aScreen);
565 aScreenHeight = HeightOfScreen(aScreen);
568 TCollection_AsciiString anOverlappedViewId("");
570 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
572 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
574 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
575 && aRight + 2*aPxWidth + 40 > aScreenWidth)
577 if (aBottom + aPxHeight + 40 > aScreenHeight)
584 aPxTop = aBottom + 40;
587 aPxLeft = aRight + 20;
592 TCollection_AsciiString aTitle("3D View - ");
593 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
595 // Change name of current active window
596 if (!ViewerTest::CurrentView().IsNull())
598 TCollection_AsciiString anActiveWindowTitle("3D View - ");
599 anActiveWindowTitle = anActiveWindowTitle
600 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
601 SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString());
605 Handle(V3d_Viewer) a3DViewer;
606 // If it's the single view, we first look for empty context
607 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
609 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
610 anIter(ViewerTest_myContexts);
612 ViewerTest::SetAISContext (anIter.Value());
613 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
615 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
617 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
618 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
620 else if (a3DViewer.IsNull())
622 toCreateViewer = Standard_True;
623 TCollection_ExtendedString NameOfWindow("Viewer3D");
624 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
625 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
626 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
627 ViewerTest_DefaultBackground.GradientColor2,
628 ViewerTest_DefaultBackground.FillMethod);
632 if (ViewerTest::GetAISContext().IsNull() ||
633 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
635 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
636 ViewerTest::SetAISContext (aContext);
637 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
641 ViewerTest::ResetEventManager();
646 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
647 Handle(WNT_WClass)::DownCast (WClass()),
648 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
652 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
653 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
655 aPxWidth, aPxHeight);
656 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
658 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
661 aPxWidth, aPxHeight);
663 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
666 Handle(V3d_View) aView = a3DViewer->CreateView();
667 aView->SetWindow (VT_GetWindow());
668 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
670 ViewerTest::CurrentView(aView);
671 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
673 // Setup for X11 or NT
676 // Set parameters for V3d_View and V3d_Viewer
677 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
678 aV3dView->SetComputedMode(Standard_False);
679 MyHLRIsOn = aV3dView->ComputedMode();
680 aV3dView->SetZClippingDepth(0.5);
681 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
683 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
686 a3DViewer->SetDefaultLights();
687 a3DViewer->SetLightOn();
690 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
691 #if TCL_MAJOR_VERSION < 8
692 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
693 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
695 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
696 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
700 VT_GetWindow()->Map();
702 // Set the handle of created view in the event manager
703 ViewerTest::ResetEventManager();
705 ViewerTest::CurrentView()->Redraw();
710 return aViewNames.GetViewName();
713 //==============================================================================
714 //function : RedrawAllViews
715 //purpose : Redraw all created views
716 //==============================================================================
717 void ViewerTest::RedrawAllViews()
719 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
720 for (; aViewIt.More(); aViewIt.Next())
722 const Handle(V3d_View)& aView = aViewIt.Key2();
727 //==============================================================================
729 //purpose : Create the window viewer and initialize all the global variable
730 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
731 //==============================================================================
733 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
737 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
738 << "Type help for more information.\n";
742 TCollection_AsciiString aViewName, aDisplayName;
743 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
744 TCollection_AsciiString aName, aValue;
745 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
747 const TCollection_AsciiString anArg = theArgVec[anArgIt];
748 TCollection_AsciiString anArgCase = anArg;
749 anArgCase.UpperCase();
750 if (ViewerTest::SplitParameter (anArg, aName, aValue))
753 if (aName.IsEqual ("NAME"))
757 else if (aName.IsEqual ("L")
758 || aName.IsEqual ("LEFT"))
760 aPxLeft = aValue.IntegerValue();
762 else if (aName.IsEqual ("T")
763 || aName.IsEqual ("TOP"))
765 aPxTop = aValue.IntegerValue();
767 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
768 else if (aName.IsEqual ("DISP")
769 || aName.IsEqual ("DISPLAY"))
771 aDisplayName = aValue;
774 else if (aName.IsEqual ("W")
775 || aName.IsEqual ("WIDTH"))
777 aPxWidth = aValue.IntegerValue();
779 else if (aName.IsEqual ("H")
780 || aName.IsEqual ("HEIGHT"))
782 aPxHeight = aValue.IntegerValue();
786 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
789 else if (aViewName.IsEmpty())
795 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
799 ViewerTest_Names aViewNames (aViewName);
800 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
802 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
803 theDi.Eval (aCommand.ToCString());
807 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
808 aViewName.ToCString(),
809 aDisplayName.ToCString());
814 //==============================================================================
816 //purpose : hidden lines removal algorithm
817 //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}]
818 //==============================================================================
820 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
822 if (ViewerTest::CurrentView().IsNull())
824 di << argv[0] << ": Call vinit before this command, please.\n";
830 di << argv[0] << ": Wrong number of command arguments.\n"
831 << "Type help " << argv[0] << " for more information.\n";
835 // Enable or disable HLR mode.
836 Standard_Boolean isHLROn =
837 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
839 if (isHLROn != MyHLRIsOn)
842 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
845 // Show or hide hidden lines in HLR mode.
846 Standard_Boolean isCurrentShowHidden
847 = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine();
849 Standard_Boolean isShowHidden =
850 (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False)
851 : isCurrentShowHidden;
854 if (isShowHidden != isCurrentShowHidden)
858 ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine();
862 ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine();
868 AIS_ListOfInteractive aListOfShapes;
869 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
871 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
873 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value());
878 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
883 ViewerTest::CurrentView()->Update();
887 //==============================================================================
888 //function : VHLRType
889 //purpose : change type of using HLR algorithm
890 //==============================================================================
892 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
894 if (ViewerTest::CurrentView().IsNull())
896 di << argv[0] << ": Call vinit before this command, please.\n";
902 di << argv[0] << ": Wrong number of command arguments.\n"
903 << "Type help " << argv[0] << " for more information.\n";
907 Prs3d_TypeOfHLR aTypeOfHLR =
908 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
912 AIS_ListOfInteractive aListOfShapes;
913 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
914 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
915 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
916 anIter.More(); anIter.Next())
918 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
921 if (aShape->TypeOfHLR() != aTypeOfHLR)
922 aShape->SetTypeOfHLR (aTypeOfHLR);
924 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
926 ViewerTest::CurrentView()->Update();
931 for (Standard_Integer i = 2; i < argc; ++i)
933 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
934 TCollection_AsciiString aName (argv[i]);
936 if (!aMap.IsBound2 (aName))
938 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
941 Handle(AIS_Shape) anAISObject =
942 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
943 if (anAISObject.IsNull())
945 anAISObject->SetTypeOfHLR (aTypeOfHLR);
947 ViewerTest::GetAISContext()->Redisplay (anAISObject, Standard_False);
949 ViewerTest::CurrentView()->Update();
955 //==============================================================================
956 //function : FindViewIdByWindowHandle
957 //purpose : Find theView Id in the map of views by window handle
958 //==============================================================================
959 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
960 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
962 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
963 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
965 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
966 if (aWindowHandle == theWindowHandle)
967 return anIter.Key1();
969 return TCollection_AsciiString("");
973 //==============================================================================
974 //function : ActivateView
975 //purpose : Make the view active
976 //==============================================================================
978 void ActivateView (const TCollection_AsciiString& theViewName)
980 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
983 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
984 if (!anAISContext.IsNull())
986 if (!ViewerTest::CurrentView().IsNull())
988 TCollection_AsciiString aTitle("3D View - ");
989 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
990 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
993 ViewerTest::CurrentView (aView);
994 // Update degenerate mode
995 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
996 ViewerTest::SetAISContext (anAISContext);
997 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
998 aTitle = aTitle + theViewName + "(*)";
999 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1000 #if defined(_WIN32) || defined(__WIN32__)
1001 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1002 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1003 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1005 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1007 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1008 ViewerTest::CurrentView()->Redraw();
1013 //==============================================================================
1014 //function : RemoveView
1016 //==============================================================================
1017 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1018 const Standard_Boolean theToRemoveContext)
1020 if (!ViewerTest_myViews.IsBound2 (theView))
1025 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1026 RemoveView (aViewName, theToRemoveContext);
1029 //==============================================================================
1030 //function : RemoveView
1031 //purpose : Close and remove view from display, clear maps if neccessary
1032 //==============================================================================
1033 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1035 if (!ViewerTest_myViews.IsBound1(theViewName))
1037 cout << "Wrong view name\n";
1041 // Activate another view if it's active now
1042 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1044 if (ViewerTest_myViews.Extent() > 1)
1046 TCollection_AsciiString aNewViewName;
1047 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
1048 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1049 if (anIter.Key1() != theViewName)
1051 aNewViewName = anIter.Key1();
1054 ActivateView (aNewViewName);
1058 Handle(V3d_View) anEmptyView;
1059 #if defined(_WIN32) || defined(__WIN32__)
1060 Handle(WNT_Window) anEmptyWindow;
1061 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1062 Handle(Cocoa_Window) anEmptyWindow;
1064 Handle(Xw_Window) anEmptyWindow;
1066 VT_GetWindow() = anEmptyWindow;
1067 ViewerTest::CurrentView (anEmptyView);
1068 if (isContextRemoved)
1070 Handle(AIS_InteractiveContext) anEmptyContext;
1071 ViewerTest::SetAISContext(anEmptyContext);
1077 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1078 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1080 // Remove view resources
1081 ViewerTest_myViews.UnBind1(theViewName);
1084 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1085 XFlush (GetDisplayConnection()->GetDisplay());
1088 // Keep context opened only if the closed view is last to avoid
1089 // unused empty contexts
1090 if (!aCurrentContext.IsNull())
1092 // Check if there are more difined views in the viewer
1093 aCurrentContext->CurrentViewer()->InitDefinedViews();
1094 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1096 // Remove driver if there is no viewers that use it
1097 Standard_Boolean isRemoveDriver = Standard_True;
1098 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1099 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1101 if (aCurrentContext != anIter.Key2() &&
1102 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1104 isRemoveDriver = Standard_False;
1110 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1111 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1112 #if TCL_MAJOR_VERSION < 8
1113 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1115 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1120 ViewerTest_myContexts.UnBind2(aCurrentContext);
1123 cout << "3D View - " << theViewName << " was deleted.\n";
1127 //==============================================================================
1129 //purpose : Remove the view defined by its name
1130 //==============================================================================
1132 static int VClose (Draw_Interpretor& /*theDi*/,
1133 Standard_Integer theArgsNb,
1134 const char** theArgVec)
1136 NCollection_List<TCollection_AsciiString> aViewList;
1139 TCollection_AsciiString anArg (theArgVec[1]);
1141 if (anArg.IsEqual ("ALL")
1142 || anArg.IsEqual ("*"))
1144 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1145 anIter.More(); anIter.Next())
1147 aViewList.Append (anIter.Key1());
1149 if (aViewList.IsEmpty())
1151 std::cout << "No view to close\n";
1157 ViewerTest_Names aViewName (theArgVec[1]);
1158 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1160 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1163 aViewList.Append (aViewName.GetViewName());
1168 // close active view
1169 if (ViewerTest::CurrentView().IsNull())
1171 std::cerr << "No active view!\n";
1174 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1177 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1178 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1179 anIter.More(); anIter.Next())
1181 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1187 //==============================================================================
1188 //function : VActivate
1189 //purpose : Activate the view defined by its ID
1190 //==============================================================================
1192 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1196 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1197 << "Usage: " << theArgVec[0] << " ViewID\n";
1202 theDi.Eval("vviewlist");
1206 TCollection_AsciiString aNameString(theArgVec[1]);
1207 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1209 TCollection_AsciiString aTitle("3D View - ");
1210 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1211 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1212 Handle(V3d_View) anEmptyView;
1213 #if defined(_WIN32) || defined(__WIN32__)
1214 Handle(WNT_Window) anEmptyWindow;
1215 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1216 Handle(Cocoa_Window) anEmptyWindow;
1218 Handle(Xw_Window) anEmptyWindow;
1220 VT_GetWindow() = anEmptyWindow;
1221 ViewerTest::CurrentView (anEmptyView);
1222 ViewerTest::ResetEventManager();
1223 theDi << theArgVec[0] << ": all views are inactive\n";
1227 ViewerTest_Names aViewNames(aNameString);
1229 // Check if this view exists in the viewer with the driver
1230 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1232 theDi << "Wrong view name\n";
1236 // Check if it is active already
1237 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1239 theDi << theArgVec[0] << ": the view is active already\n";
1243 ActivateView (aViewNames.GetViewName());
1247 //==============================================================================
1248 //function : VViewList
1249 //purpose : Print current list of views per viewer and graphic driver ID
1250 // shared between viewers
1251 //==============================================================================
1253 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1257 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1258 << "Usage: " << theArgVec[0] << " name";
1261 if (ViewerTest_myContexts.Size() < 1)
1264 Standard_Boolean isTreeView =
1265 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1268 theDi << theArgVec[0] <<":\n";
1270 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1271 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1274 theDi << aDriverIter.Key1() << ":\n";
1276 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1277 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1279 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1283 TCollection_AsciiString aContextName(aContextIter.Key1());
1284 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1287 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1288 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1290 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1292 TCollection_AsciiString aViewName(aViewIter.Key1());
1295 if (aViewIter.Value() == ViewerTest::CurrentView())
1296 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1298 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1302 theDi << aViewName << " ";
1312 //==============================================================================
1313 //function : VT_ProcessKeyPress
1314 //purpose : Handle KeyPress event from a CString
1315 //==============================================================================
1316 void VT_ProcessKeyPress (const char* buf_ret)
1318 //cout << "KeyPress" << endl;
1319 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1320 // Letter in alphabetic order
1322 if (!strcasecmp (buf_ret, "A"))
1325 aView->SetProj(V3d_XposYnegZpos);
1327 else if (!strcasecmp (buf_ret, "D"))
1332 else if (!strcasecmp (buf_ret, "F"))
1334 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1336 ViewerTest::GetAISContext()->FitSelected (aView);
1344 else if (!strcasecmp (buf_ret, "H"))
1347 cout << "HLR" << endl;
1348 aView->SetComputedMode (!aView->ComputedMode());
1349 MyHLRIsOn = aView->ComputedMode();
1351 else if (!strcasecmp (buf_ret, "P"))
1354 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1355 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1356 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1358 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1359 if (aContext->NbSelected()==0)
1361 AIS_ListOfInteractive aListOfShapes;
1362 aContext->DisplayedObjects(aListOfShapes);
1363 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1364 anIter.More(); anIter.Next())
1366 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1367 if (aShape.IsNull())
1369 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1370 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1372 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1373 aContext->Redisplay (aShape, Standard_False);
1378 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
1380 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
1381 if (aShape.IsNull())
1383 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1384 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1386 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1387 aContext->Redisplay (aShape, Standard_False);
1391 aContext->UpdateCurrentViewer();
1394 else if (!strcasecmp (buf_ret, "S"))
1396 std::cout << "setup Shaded display mode" << std::endl;
1398 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1399 if(Ctx->NbSelected()==0)
1400 Ctx->SetDisplayMode(AIS_Shaded);
1402 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1403 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
1404 Ctx->UpdateCurrentViewer();
1407 else if (!strcasecmp (buf_ret, "U"))
1409 // Unset display mode
1410 std::cout << "reset display mode to defaults" << std::endl;
1412 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1413 if(Ctx->NbSelected()==0)
1414 Ctx->SetDisplayMode(AIS_WireFrame);
1416 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1417 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
1418 Ctx->UpdateCurrentViewer();
1422 else if (!strcasecmp (buf_ret, "T"))
1425 aView->SetProj(V3d_Zpos);
1427 else if (!strcasecmp (buf_ret, "B"))
1430 aView->SetProj(V3d_Zneg);
1432 else if (!strcasecmp (buf_ret, "L"))
1435 aView->SetProj(V3d_Xneg);
1437 else if (!strcasecmp (buf_ret, "R"))
1440 aView->SetProj(V3d_Xpos);
1442 else if (!strcasecmp (buf_ret, "W"))
1444 std::cout << "setup WireFrame display mode" << std::endl;
1445 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1446 if(Ctx->NbSelected()==0)
1447 Ctx->SetDisplayMode(AIS_WireFrame);
1449 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1450 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
1451 Ctx->UpdateCurrentViewer();
1454 else if (!strcasecmp (buf_ret, "Z"))
1458 cout << "ZClipping OFF" << endl;
1461 aView->SetZClippingType(V3d_OFF);
1465 cout << "ZClipping ON" << endl;
1468 aView->SetZClippingType(V3d_FRONT);
1472 else if (!strcasecmp (buf_ret, ","))
1474 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1476 else if (!strcasecmp (buf_ret, "."))
1478 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1480 else if (!strcasecmp (buf_ret, "/"))
1482 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1483 if (aCamera->IsStereo())
1485 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1489 else if (!strcasecmp (buf_ret, "*"))
1491 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1492 if (aCamera->IsStereo())
1494 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1498 else if (*buf_ret == THE_KEY_DELETE)
1500 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1502 && aCtx->NbSelected() > 0)
1504 Draw_Interprete ("verase");
1510 Standard_Integer Num = Draw::Atoi(buf_ret);
1511 if(Num>=0 && Num<=7)
1512 ViewerTest::StandardModeActivation(Num);
1516 //==============================================================================
1517 //function : VT_ProcessExpose
1518 //purpose : Redraw the View on an Expose Event
1519 //==============================================================================
1520 void VT_ProcessExpose()
1522 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1523 if (!aView3d.IsNull())
1529 //==============================================================================
1530 //function : VT_ProcessConfigure
1531 //purpose : Resize the View on an Configure Event
1532 //==============================================================================
1533 void VT_ProcessConfigure()
1535 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1536 if (aView3d.IsNull())
1541 aView3d->MustBeResized();
1546 //==============================================================================
1547 //function : VT_ProcessButton1Press
1549 //==============================================================================
1550 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1551 const char** theArgVec,
1552 Standard_Boolean theToPick,
1553 Standard_Boolean theIsShift)
1557 Standard_Real X, Y, Z;
1558 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1560 Draw::Set (theArgVec[1], X);
1561 Draw::Set (theArgVec[2], Y);
1562 Draw::Set (theArgVec[3], Z);
1567 ViewerTest::CurrentEventManager()->ShiftSelect();
1571 ViewerTest::CurrentEventManager()->Select();
1574 return Standard_False;
1577 //==============================================================================
1578 //function : VT_ProcessButton1Release
1579 //purpose : End selecting
1580 //==============================================================================
1581 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1585 IsDragged = Standard_False;
1586 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1589 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1590 X_Motion, Y_Motion);
1594 EM->Select (X_ButtonPress, Y_ButtonPress,
1595 X_Motion, Y_Motion);
1600 //==============================================================================
1601 //function : VT_ProcessButton3Press
1602 //purpose : Start Rotation
1603 //==============================================================================
1604 void VT_ProcessButton3Press()
1609 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1611 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1614 //==============================================================================
1615 //function : VT_ProcessButton3Release
1616 //purpose : End rotation
1617 //==============================================================================
1618 void VT_ProcessButton3Release()
1625 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1630 //==============================================================================
1631 //function : ProcessZClipMotion
1633 //==============================================================================
1635 void ProcessZClipMotion()
1637 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1638 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1640 //Quantity_Length VDX, VDY;
1641 //a3DView->Size(VDX,VDY);
1642 //Standard_Real VDZ = a3DView->ZSize();
1643 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1645 Quantity_Length aDx = a3DView->Convert(X_Motion - X_ButtonPress);
1647 // Front = Depth + width/2.
1648 Standard_Real aDepth = 0.5;
1649 Standard_Real aWidth = 0.1;
1650 a3DView->ZClipping(aDepth,aWidth);
1654 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1656 a3DView->SetZClippingDepth(aDepth);
1660 X_ButtonPress = X_Motion;
1661 Y_ButtonPress = Y_Motion;
1665 //==============================================================================
1666 //function : ProcessControlButton1Motion
1668 //==============================================================================
1670 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1671 static void ProcessControlButton1Motion()
1673 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1675 X_ButtonPress = X_Motion;
1676 Y_ButtonPress = Y_Motion;
1680 //==============================================================================
1681 //function : VT_ProcessControlButton2Motion
1683 //==============================================================================
1684 void VT_ProcessControlButton2Motion()
1686 Standard_Integer aDx = X_Motion - X_ButtonPress;
1687 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1689 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1691 ViewerTest::CurrentView()->Pan (aDx, aDy);
1693 X_ButtonPress = X_Motion;
1694 Y_ButtonPress = Y_Motion;
1697 //==============================================================================
1698 //function : VT_ProcessControlButton3Motion
1699 //purpose : Rotation
1700 //==============================================================================
1701 void VT_ProcessControlButton3Motion()
1705 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1709 //==============================================================================
1710 //function : VT_ProcessMotion
1712 //==============================================================================
1713 void VT_ProcessMotion()
1715 //pre-hilights detected objects at mouse position
1717 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1718 EM->MoveTo(X_Motion, Y_Motion);
1722 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1724 Xpix = X_Motion;Ypix=Y_Motion;
1727 //==============================================================================
1728 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1729 //purpose : Switches to an axonometric, top, left and other views
1730 //==============================================================================
1732 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1734 if ( ViewerTest::CurrentView().IsNull() )
1736 di<<"Call vinit before this command, please"<<"\n";
1740 ViewerTest::CurrentView()->SetProj(ori);
1744 //==============================================================================
1746 //purpose : Switch to an Axonometric view
1747 //Draw arg : No args
1748 //==============================================================================
1750 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1752 return ViewProject(di, V3d_XposYnegZpos);
1755 //==============================================================================
1757 //purpose : Switch to a Top View
1758 //Draw arg : No args
1759 //==============================================================================
1761 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1763 return ViewProject(di, V3d_Zpos);
1766 //==============================================================================
1767 //function : VBottom
1768 //purpose : Switch to a Bottom View
1769 //Draw arg : No args
1770 //==============================================================================
1772 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1774 return ViewProject(di, V3d_Zneg);
1777 //==============================================================================
1779 //purpose : Switch to a Left View
1780 //Draw arg : No args
1781 //==============================================================================
1783 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1785 return ViewProject(di, V3d_Xneg);
1788 //==============================================================================
1790 //purpose : Switch to a Right View
1791 //Draw arg : No args
1792 //==============================================================================
1794 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1796 return ViewProject(di, V3d_Xpos);
1799 //==============================================================================
1801 //purpose : Switch to a Front View
1802 //Draw arg : No args
1803 //==============================================================================
1805 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1807 return ViewProject(di, V3d_Yneg);
1810 //==============================================================================
1812 //purpose : Switch to a Back View
1813 //Draw arg : No args
1814 //==============================================================================
1816 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1818 return ViewProject(di, V3d_Ypos);
1821 //==============================================================================
1823 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1824 //Draw arg : No args
1825 //==============================================================================
1827 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1830 di << "Q : Quit the application" << "\n";
1832 di << "========================="<<"\n";
1833 di << "F : FitAll" << "\n";
1834 di << "T : TopView" << "\n";
1835 di << "B : BottomView" << "\n";
1836 di << "R : RightView" << "\n";
1837 di << "L : LeftView" << "\n";
1838 di << "A : AxonometricView" << "\n";
1839 di << "D : ResetView" << "\n";
1841 di << "========================="<<"\n";
1842 di << "S : Shading" << "\n";
1843 di << "W : Wireframe" << "\n";
1844 di << "H : HidelLineRemoval" << "\n";
1845 di << "U : Unset display mode" << "\n";
1846 di << "Delete : Remove selection from viewer" << "\n";
1848 di << "========================="<<"\n";
1849 di << "Selection mode "<<"\n";
1850 di << "0 : Shape" <<"\n";
1851 di << "1 : Vertex" <<"\n";
1852 di << "2 : Edge" <<"\n";
1853 di << "3 : Wire" <<"\n";
1854 di << "4 : Face" <<"\n";
1855 di << "5 : Shell" <<"\n";
1856 di << "6 : Solid" <<"\n";
1857 di << "7 : Compound" <<"\n";
1859 di << "========================="<<"\n";
1860 di << "Z : Switch Z clipping On/Off" << "\n";
1861 di << ", : Hilight next detected" << "\n";
1862 di << ". : Hilight previous detected" << "\n";
1869 static Standard_Boolean Ppick = 0;
1870 static Standard_Integer Pargc = 0;
1871 static const char** Pargv = NULL;
1874 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1879 if (!ViewerTest_myViews.IsEmpty()) {
1881 WPARAM fwKeys = wParam;
1886 // Delete view from map of views
1887 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1892 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1893 || ViewerTest::CurrentView().IsNull())
1895 // Activate inactive window
1896 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1898 ActivateView (FindViewIdByWindowHandle(hwnd));
1905 HDC hdc = GetDC( hwnd );
1906 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1907 SetROP2( hdc, R2_NOT );
1908 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1909 ReleaseDC( hwnd, hdc );
1910 VT_ProcessButton1Release (fwKeys & MK_SHIFT);
1912 IsDragged = Standard_False;
1913 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1915 case WM_LBUTTONDOWN:
1916 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1918 IsDragged = Standard_True;
1919 DragFirst = Standard_True;
1920 X_ButtonPress = LOWORD(lParam);
1921 Y_ButtonPress = HIWORD(lParam);
1923 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1930 HDC hdc = GetDC( hwnd );
1932 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1933 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1934 SetROP2( hdc, R2_NOT );
1937 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1939 DragFirst = Standard_False;
1940 X_Motion = LOWORD(lParam);
1941 Y_Motion = HIWORD(lParam);
1943 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1945 SelectObject( hdc, anObj );
1947 ReleaseDC( hwnd, hdc );
1950 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1954 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1958 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1962 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1968 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
1971 return DefWindowProc( hwnd, Msg, wParam, lParam );
1978 BeginPaint(hwnd, &ps);
1979 EndPaint(hwnd, &ps);
1984 VT_ProcessConfigure();
1989 switch (aView->RenderingParams().StereoMode)
1991 case Graphic3d_StereoMode_RowInterlaced:
1992 case Graphic3d_StereoMode_ColumnInterlaced:
1993 case Graphic3d_StereoMode_ChessBoard:
1994 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2002 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2005 c[0] = (char) wParam;
2007 if (wParam == VK_DELETE)
2009 c[0] = THE_KEY_DELETE;
2012 else if (wParam == VK_OEM_COMMA)
2017 else if (wParam == VK_OEM_PERIOD)
2021 else if (wParam == VK_DIVIDE)
2026 else if (wParam == VK_MULTIPLY)
2030 VT_ProcessKeyPress (c);
2038 VT_ProcessButton3Release();
2041 case WM_LBUTTONDOWN:
2042 case WM_MBUTTONDOWN:
2043 case WM_RBUTTONDOWN:
2045 WPARAM fwKeys = wParam;
2049 X_ButtonPress = LOWORD(lParam);
2050 Y_ButtonPress = HIWORD(lParam);
2052 if (Msg == WM_LBUTTONDOWN)
2054 if (fwKeys & MK_CONTROL)
2056 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2060 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2063 else if (Msg == WM_RBUTTONDOWN)
2066 VT_ProcessButton3Press();
2073 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2074 if (wParam & MK_CONTROL)
2076 if (aView->Camera()->IsStereo())
2078 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2082 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2089 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2096 //cout << "\t WM_MOUSEMOVE" << endl;
2097 WPARAM fwKeys = wParam;
2098 X_Motion = LOWORD(lParam);
2099 Y_Motion = HIWORD(lParam);
2102 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2104 X_ButtonPress = LOWORD(lParam);
2105 Y_ButtonPress = HIWORD(lParam);
2107 if ( fwKeys & MK_RBUTTON ) {
2109 VT_ProcessButton3Press();
2113 if ( fwKeys & MK_CONTROL ) {
2114 if ( fwKeys & MK_LBUTTON ) {
2115 ProcessControlButton1Motion();
2117 else if ( fwKeys & MK_MBUTTON ||
2118 ((fwKeys&MK_LBUTTON) &&
2119 (fwKeys&MK_RBUTTON) ) ){
2120 VT_ProcessControlButton2Motion();
2122 else if ( fwKeys & MK_RBUTTON ) {
2123 VT_ProcessControlButton3Motion();
2127 else if ( fwKeys & MK_SHIFT ) {
2128 if ( fwKeys & MK_MBUTTON ||
2129 ((fwKeys&MK_LBUTTON) &&
2130 (fwKeys&MK_RBUTTON) ) ) {
2131 cout << "ProcessZClipMotion()" << endl;
2132 ProcessZClipMotion();
2136 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2138 if ((fwKeys & MK_MBUTTON
2139 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2141 ProcessZClipMotion();
2152 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2160 //==============================================================================
2161 //function : ViewerMainLoop
2162 //purpose : Get a Event on the view and dispatch it
2163 //==============================================================================
2166 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2168 Ppick = (argc > 0)? 1 : 0;
2176 cout << "Start picking" << endl;
2178 while ( Ppick == 1 ) {
2179 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2180 if (GetMessage(&msg, NULL, 0, 0) ) {
2181 TranslateMessage(&msg);
2182 DispatchMessage(&msg);
2186 cout << "Picking done" << endl;
2192 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2194 int min( int a, int b )
2202 int max( int a, int b )
2210 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2213 static XEvent aReport;
2214 Standard_Boolean pick = argc > 0;
2215 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2216 XNextEvent (aDisplay, &aReport);
2218 // Handle event for the chosen display connection
2219 switch (aReport.type) {
2222 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2225 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2231 // Activate inactive view
2232 Window aWindow = GetWindowHandle(VT_GetWindow());
2233 if(aWindow != aReport.xfocus.window)
2235 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2244 case ConfigureNotify:
2246 VT_ProcessConfigure();
2255 XComposeStatus status_in_out;
2257 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2258 (char *) buf_ret , 10 ,
2259 &ks_ret , &status_in_out ) ;
2262 buf_ret[ret_len] = '\0' ;
2266 VT_ProcessKeyPress (buf_ret);
2272 X_ButtonPress = aReport.xbutton.x;
2273 Y_ButtonPress = aReport.xbutton.y;
2275 if (aReport.xbutton.button == Button1)
2277 if (aReport.xbutton.state & ControlMask)
2279 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2283 IsDragged = Standard_True;
2284 DragFirst = Standard_True;
2287 else if (aReport.xbutton.button == Button3)
2290 VT_ProcessButton3Press();
2300 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2301 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2302 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2305 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2306 if( aContext.IsNull() )
2308 cout << "The context is null. Please use vinit before createmesh" << endl;
2312 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2313 if( aReport.xbutton.button==1 )
2317 aContext->ShiftSelect();
2326 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2327 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2328 ViewerTest::CurrentView());
2332 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2333 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2334 ViewerTest::CurrentView() );
2337 VT_ProcessButton3Release();
2339 IsDragged = Standard_False;
2342 VT_ProcessButton3Release();
2347 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2353 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2354 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2355 XSetFunction( aDisplay, gc, GXinvert );
2358 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2360 X_Motion = aReport.xmotion.x;
2361 Y_Motion = aReport.xmotion.y;
2362 DragFirst = Standard_False;
2364 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2368 X_Motion = aReport.xmotion.x;
2369 Y_Motion = aReport.xmotion.y;
2371 // remove all the ButtonMotionMaskr
2372 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2374 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2375 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2377 Quantity_Length VDX, VDY;
2379 ViewerTest::CurrentView()->Size(VDX,VDY);
2380 Standard_Real VDZ =0 ;
2381 VDZ = ViewerTest::CurrentView()->ZSize();
2383 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2385 Quantity_Length dx = 0 ;
2386 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2390 dx = dx / VDX * VDZ;
2394 ViewerTest::CurrentView()->Redraw();
2398 if ( aReport.xmotion.state & ControlMask ) {
2399 if ( aReport.xmotion.state & Button1Mask ) {
2400 ProcessControlButton1Motion();
2402 else if ( aReport.xmotion.state & Button2Mask ) {
2403 VT_ProcessControlButton2Motion();
2405 else if ( aReport.xmotion.state & Button3Mask ) {
2406 VT_ProcessControlButton3Motion();
2420 //==============================================================================
2421 //function : VProcessEvents
2422 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2423 // event in the Viewer window
2424 //==============================================================================
2426 static void VProcessEvents(ClientData,int)
2428 NCollection_Vector<int> anEventNumbers;
2429 // Get number of messages from every display
2430 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2431 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2433 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2435 // Handle events for every display
2436 int anEventIter = 0;
2437 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2438 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2440 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2441 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2443 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2444 int anEventResult = ViewerMainLoop( 0, NULL);
2445 // If window is closed or context was not found finish current event processing loop
2451 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2456 //==============================================================================
2457 //function : OSWindowSetup
2458 //purpose : Setup for the X11 window to be able to cath the event
2459 //==============================================================================
2462 static void OSWindowSetup()
2464 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2467 Window window = VT_GetWindow()->XWindow();
2468 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2469 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2470 XSynchronize(aDisplay, 1);
2472 // X11 : For keyboard on SUN
2474 wmhints.flags = InputHint;
2477 XSetWMHints( aDisplay, window, &wmhints);
2479 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2480 ButtonPressMask | ButtonReleaseMask |
2481 StructureNotifyMask |
2483 Button1MotionMask | Button2MotionMask |
2484 Button3MotionMask | FocusChangeMask
2486 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2487 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2489 XSynchronize(aDisplay, 0);
2497 //==============================================================================
2500 //purpose : Fitall, no DRAW arguments
2501 //Draw arg : No args
2502 //==============================================================================
2504 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgc, const char** theArgv)
2508 std::cout << "Wrong number of arguments! Use: vfit [-selected]" << std::endl;
2511 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2515 TCollection_AsciiString anArg (theArgv[1]);
2517 if (anArg == "-selected")
2519 ViewerTest::GetAISContext()->FitSelected (aView);
2523 if (aView.IsNull() == Standard_False) {
2530 //=======================================================================
2531 //function : VFitArea
2532 //purpose : Fit view to show area located between two points
2533 // : given in world 2D or 3D coordinates.
2534 //=======================================================================
2535 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2537 Handle(V3d_View) aView = ViewerTest::CurrentView();
2540 std::cerr << theArgVec[0] << "Error: No active view.\n";
2545 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2546 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2550 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2551 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2552 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2553 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2555 else if (theArgNb == 7)
2557 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2558 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2559 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2560 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2561 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2562 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2566 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2567 theDI.PrintHelp(theArgVec[0]);
2571 // Convert model coordinates to view space
2572 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2573 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2574 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2576 // Determine fit area
2577 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2578 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2580 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2582 if (aDiagonal < Precision::Confusion())
2584 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2588 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2592 //==============================================================================
2594 //purpose : ZFitall, no DRAW arguments
2595 //Draw arg : No args
2596 //==============================================================================
2597 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2599 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2601 if (aCurrentView.IsNull())
2603 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2609 aCurrentView->ZFitAll();
2610 aCurrentView->Redraw();
2614 Standard_Real aScale = 1.0;
2618 aScale = Draw::Atoi (theArgVec[1]);
2621 aCurrentView->ZFitAll (aScale);
2622 aCurrentView->Redraw();
2627 //==============================================================================
2628 //function : VRepaint
2630 //==============================================================================
2631 static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
2633 Handle(V3d_View) V = ViewerTest::CurrentView();
2634 if ( !V.IsNull() ) V->Redraw(); return 0;
2637 //==============================================================================
2639 //purpose : Remove all the object from the viewer
2640 //Draw arg : No args
2641 //==============================================================================
2643 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2645 Handle(V3d_View) V = ViewerTest::CurrentView();
2647 ViewerTest::Clear();
2651 //==============================================================================
2654 //==============================================================================
2656 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2657 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2660 di << argv[0] << "Invalid number of arguments" << "\n";
2664 while (ViewerMainLoop( argc, argv)) {
2670 //==============================================================================
2672 //purpose : Load image as background
2673 //==============================================================================
2675 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2677 if (argc < 2 || argc > 3)
2679 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2680 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2684 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2685 if(AISContext.IsNull())
2687 di << "use 'vinit' command before " << argv[0] << "\n";
2691 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2694 const char* szType = argv[2];
2695 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2696 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2697 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2698 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2701 di << "Wrong fill type : " << szType << "\n";
2702 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2707 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2708 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2713 //==============================================================================
2714 //function : VSetBgMode
2715 //purpose : Change background image fill type
2716 //==============================================================================
2718 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2722 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2723 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2727 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2728 if(AISContext.IsNull())
2730 di << "use 'vinit' command before " << argv[0] << "\n";
2733 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2734 const char* szType = argv[1];
2735 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2736 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2737 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2738 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2741 di << "Wrong fill type : " << szType << "\n";
2742 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2745 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2746 V3dView->SetBgImageStyle(aFillType, Standard_True);
2750 //==============================================================================
2751 //function : VSetGradientBg
2752 //purpose : Mount gradient background
2753 //==============================================================================
2754 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2758 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2759 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2760 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2761 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2765 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2766 if(AISContext.IsNull())
2768 di << "use 'vinit' command before " << argv[0] << "\n";
2774 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2775 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2776 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2777 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2779 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2780 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2781 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2783 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2784 int aType = Draw::Atoi(argv[7]);
2785 if( aType < 0 || aType > 8 )
2787 di << "Wrong fill type " << "\n";
2788 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2789 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2793 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2795 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2796 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2802 //==============================================================================
2803 //function : VSetGradientBgMode
2804 //purpose : Change gradient background fill style
2805 //==============================================================================
2806 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2810 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2811 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2812 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2816 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2817 if(AISContext.IsNull())
2819 di << "use 'vinit' command before " << argv[0] << "\n";
2824 int aType = Draw::Atoi(argv[1]);
2825 if( aType < 0 || aType > 8 )
2827 di << "Wrong fill type " << "\n";
2828 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2829 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2833 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2835 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2836 V3dView->SetBgGradientStyle( aMethod, 1 );
2842 //==============================================================================
2843 //function : VSetColorBg
2844 //purpose : Set color background
2845 //==============================================================================
2846 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2850 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2851 di << "R,G,B = [0..255]" << "\n";
2855 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2856 if(AISContext.IsNull())
2858 di << "use 'vinit' command before " << argv[0] << "\n";
2864 Standard_Real R = Draw::Atof(argv[1])/255.;
2865 Standard_Real G = Draw::Atof(argv[2])/255.;
2866 Standard_Real B = Draw::Atof(argv[3])/255.;
2867 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2869 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2870 V3dView->SetBackgroundColor( aColor );
2877 //==============================================================================
2878 //function : VSetDefaultBg
2879 //purpose : Set default viewer background fill color
2880 //==============================================================================
2881 static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2886 std::cout << "Error: wrong syntax! See usage:\n";
2887 theDI.PrintHelp (theArgVec[0]);
2891 ViewerTest_DefaultBackground.FillMethod =
2892 theArgNb == 4 ? Aspect_GFM_NONE
2893 : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]);
2897 Standard_Real R = Draw::Atof (theArgVec[1]) / 255.;
2898 Standard_Real G = Draw::Atof (theArgVec[2]) / 255.;
2899 Standard_Real B = Draw::Atof (theArgVec[3]) / 255.;
2900 ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB);
2904 Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.;
2905 Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.;
2906 Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.;
2907 ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB);
2909 Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.;
2910 Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.;
2911 Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.;
2912 ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB);
2915 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
2916 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
2918 const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer();
2919 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
2920 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
2921 ViewerTest_DefaultBackground.GradientColor2,
2922 ViewerTest_DefaultBackground.FillMethod);
2928 //==============================================================================
2930 //purpose : View Scaling
2931 //==============================================================================
2933 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2935 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2936 if ( V3dView.IsNull() ) return 1;
2939 di << argv[0] << "Invalid number of arguments" << "\n";
2942 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2945 //==============================================================================
2946 //function : VZBuffTrihedron
2948 //==============================================================================
2950 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
2951 Standard_Integer theArgNb,
2952 const char** theArgVec)
2954 Handle(V3d_View) aView = ViewerTest::CurrentView();
2957 std::cout << "Error: no active viewer!\n";
2961 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
2963 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2964 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
2965 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
2966 Quantity_Color anArrowColorX = Quantity_NOC_RED;
2967 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
2968 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
2969 Standard_Real aScale = 0.1;
2970 Standard_Real aSizeRatio = 0.8;
2971 Standard_Real anArrowDiam = 0.05;
2972 Standard_Integer aNbFacets = 12;
2973 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2975 Standard_CString anArg = theArgVec[anArgIter];
2976 TCollection_AsciiString aFlag (anArg);
2978 if (anUpdateTool.parseRedrawMode (aFlag))
2982 else if (aFlag == "-on")
2986 else if (aFlag == "-off")
2988 aView->TriedronErase();
2991 else if (aFlag == "-pos"
2992 || aFlag == "-position"
2993 || aFlag == "-corner")
2995 if (++anArgIter >= theArgNb)
2997 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3001 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3002 aPosName.LowerCase();
3003 if (aPosName == "center")
3005 aPosition = Aspect_TOTP_CENTER;
3007 else if (aPosName == "left_lower"
3008 || aPosName == "lower_left"
3009 || aPosName == "leftlower"
3010 || aPosName == "lowerleft")
3012 aPosition = Aspect_TOTP_LEFT_LOWER;
3014 else if (aPosName == "left_upper"
3015 || aPosName == "upper_left"
3016 || aPosName == "leftupper"
3017 || aPosName == "upperleft")
3019 aPosition = Aspect_TOTP_LEFT_UPPER;
3021 else if (aPosName == "right_lower"
3022 || aPosName == "lower_right"
3023 || aPosName == "rightlower"
3024 || aPosName == "lowerright")
3026 aPosition = Aspect_TOTP_RIGHT_LOWER;
3028 else if (aPosName == "right_upper"
3029 || aPosName == "upper_right"
3030 || aPosName == "rightupper"
3031 || aPosName == "upperright")
3033 aPosition = Aspect_TOTP_RIGHT_UPPER;
3037 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3041 else if (aFlag == "-type")
3043 if (++anArgIter >= theArgNb)
3045 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3049 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3050 aTypeName.LowerCase();
3051 if (aTypeName == "wireframe"
3052 || aTypeName == "wire")
3054 aVisType = V3d_WIREFRAME;
3056 else if (aTypeName == "zbuffer"
3057 || aTypeName == "shaded")
3059 aVisType = V3d_ZBUFFER;
3063 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3066 else if (aFlag == "-scale")
3068 if (++anArgIter >= theArgNb)
3070 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3074 aScale = Draw::Atof (theArgVec[anArgIter]);
3076 else if (aFlag == "-size"
3077 || aFlag == "-sizeratio")
3079 if (++anArgIter >= theArgNb)
3081 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3085 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3087 else if (aFlag == "-arrowdiam"
3088 || aFlag == "-arrowdiameter")
3090 if (++anArgIter >= theArgNb)
3092 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3096 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3098 else if (aFlag == "-nbfacets")
3100 if (++anArgIter >= theArgNb)
3102 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3106 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3108 else if (aFlag == "-colorlabel"
3109 || aFlag == "-colorlabels")
3111 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3112 theArgVec + anArgIter + 1,
3116 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3119 anArgIter += aNbParsed;
3121 else if (aFlag == "-colorarrowx")
3123 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3124 theArgVec + anArgIter + 1,
3128 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3131 anArgIter += aNbParsed;
3133 else if (aFlag == "-colorarrowy")
3135 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3136 theArgVec + anArgIter + 1,
3140 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3143 anArgIter += aNbParsed;
3145 else if (aFlag == "-colorarrowz")
3147 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3148 theArgVec + anArgIter + 1,
3152 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3155 anArgIter += aNbParsed;
3159 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3164 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3165 aSizeRatio, anArrowDiam, aNbFacets);
3166 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
3171 //==============================================================================
3172 //function : VRotate
3173 //purpose : Camera Rotating
3174 //==============================================================================
3176 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3178 Handle(V3d_View) aView = ViewerTest::CurrentView();
3181 std::cout << "No active view!\n";
3185 Standard_Boolean hasFlags = Standard_False;
3186 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3188 Standard_CString anArg (theArgVec[anArgIter]);
3189 TCollection_AsciiString aFlag (anArg);
3191 if (aFlag == "-mousestart"
3192 || aFlag == "-mousefrom")
3194 hasFlags = Standard_True;
3195 if (anArgIter + 2 >= theArgNb)
3197 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3201 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3202 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3203 aView->StartRotation (anX, anY);
3205 else if (aFlag == "-mousemove")
3207 hasFlags = Standard_True;
3208 if (anArgIter + 2 >= theArgNb)
3210 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3214 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3215 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3216 aView->Rotation (anX, anY);
3218 else if (theArgNb != 4
3221 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3230 else if (theArgNb == 4)
3232 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3233 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3234 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3235 aView->Rotate (anAX, anAY, anAZ);
3238 else if (theArgNb == 7)
3240 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3241 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3242 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3244 Standard_Real anX = Draw::Atof (theArgVec[4]);
3245 Standard_Real anY = Draw::Atof (theArgVec[5]);
3246 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3248 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3252 std::cout << "Error: Invalid number of arguments\n";
3256 //==============================================================================
3258 //purpose : View zoom in / out (relative to current zoom)
3259 //==============================================================================
3261 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3262 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3263 if ( V3dView.IsNull() ) {
3268 Standard_Real coef = Draw::Atof(argv[1]);
3269 if ( coef <= 0.0 ) {
3270 di << argv[1] << "Invalid value" << "\n";
3273 V3dView->SetZoom( Draw::Atof(argv[1]) );
3276 di << argv[0] << " Invalid number of arguments" << "\n";
3281 //==============================================================================
3283 //purpose : View panning (in pixels)
3284 //==============================================================================
3286 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3287 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3288 if ( V3dView.IsNull() ) return 1;
3291 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
3294 di << argv[0] << " Invalid number of arguments" << "\n";
3299 //==============================================================================
3301 //purpose : Place the point (in pixels) at the center of the window
3302 //==============================================================================
3303 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3305 Handle(V3d_View) aView = ViewerTest::CurrentView();
3308 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3314 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3318 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3323 //==============================================================================
3324 //function : VExport
3325 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
3326 //==============================================================================
3328 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3330 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3331 if (V3dView.IsNull())
3336 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
3340 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
3341 TCollection_AsciiString aFormatStr;
3343 TCollection_AsciiString aFileName (argv[1]);
3344 Standard_Integer aLen = aFileName.Length();
3348 aFormatStr = TCollection_AsciiString (argv[2]);
3352 if (aFileName.Value (aLen - 2) == '.')
3354 aFormatStr = aFileName.ToCString() + aLen - 2;
3356 else if (aFileName.Value (aLen - 3) == '.')
3358 aFormatStr = aFileName.ToCString() + aLen - 3;
3362 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3368 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3372 aFormatStr.UpperCase();
3373 if (aFormatStr == "PS")
3374 anExpFormat = Graphic3d_EF_PostScript;
3375 else if (aFormatStr == "EPS")
3376 anExpFormat = Graphic3d_EF_EnhPostScript;
3377 else if (aFormatStr == "TEX")
3378 anExpFormat = Graphic3d_EF_TEX;
3379 else if (aFormatStr == "PDF")
3380 anExpFormat = Graphic3d_EF_PDF;
3381 else if (aFormatStr == "SVG")
3382 anExpFormat = Graphic3d_EF_SVG;
3383 else if (aFormatStr == "PGF")
3384 anExpFormat = Graphic3d_EF_PGF;
3385 else if (aFormatStr == "EMF")
3386 anExpFormat = Graphic3d_EF_EMF;
3389 std::cout << "Invalid export format '" << aFormatStr << "'\n";
3395 if (!V3dView->Export (argv[1], anExpFormat))
3397 di << "Error: export of image to " << aFormatStr << " failed!\n";
3400 catch (Standard_Failure)
3402 di << "Error: export of image to " << aFormatStr << " failed";
3403 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
3408 //==============================================================================
3409 //function : VColorScale
3410 //purpose : representation color scale
3411 //==============================================================================
3413 static Standard_Boolean checkColor (const TCollection_AsciiString& theRed,
3414 const TCollection_AsciiString& theGreen,
3415 const TCollection_AsciiString& theBlue,
3416 Standard_Real& theRedValue,
3417 Standard_Real& theGreenValue,
3418 Standard_Real& theBlueValue)
3420 if (!theRed.IsRealValue()
3421 || !theGreen.IsRealValue()
3422 || !theBlue.IsRealValue())
3424 std::cout << "Error: RGB color values should be real!\n";
3425 return Standard_True;
3427 theRedValue = theRed .RealValue();
3428 theGreenValue = theGreen.RealValue();
3429 theBlueValue = theBlue .RealValue();
3430 if (theRedValue < 0.0 || theRedValue > 1.0
3431 || theGreenValue < 0.0 || theGreenValue > 1.0
3432 || theBlueValue < 0.0 || theBlueValue > 1.0)
3434 std::cout << "Error: RGB color values should be within range 0..1!\n";
3435 return Standard_True;
3437 return Standard_False;
3440 static int VColorScale (Draw_Interpretor& theDI,
3441 Standard_Integer theArgNb,
3442 const char** theArgVec)
3444 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3445 Handle(V3d_View) aView = ViewerTest::CurrentView();
3446 if (aContext.IsNull())
3448 std::cout << "Error: no active view!\n";
3453 std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n";
3457 Handle(AIS_ColorScale) aCS;
3459 Handle(AIS_InteractiveObject) anIObj;
3460 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
3462 aCS = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
3465 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
3471 aCS = new AIS_ColorScale();
3472 GetMapOfAIS().Bind (aCS,theArgVec[1]);
3475 if (aCS->ZLayer() != Graphic3d_ZLayerId_TopOSD)
3477 aCS->SetZLayer (Graphic3d_ZLayerId_TopOSD);
3479 if (aCS->GetTransformPersistenceMode() != Graphic3d_TMF_2d)
3481 aCS->SetTransformPersistence (Graphic3d_TMF_2d, gp_Pnt (-1,-1,0));
3484 Standard_Real aMinRange = aCS->GetMin();
3485 Standard_Real aMaxRange = aCS->GetMax();
3486 Standard_Integer aWidth = aCS->GetWidth();
3487 Standard_Integer aHeight = aCS->GetHeight();
3488 Standard_Integer aNbIntervals = aCS->GetNumberOfIntervals();
3489 Standard_Integer aTextHeight = aCS->GetTextHeight();
3490 Aspect_TypeOfColorScalePosition aLabPosition = aCS->GetLabelPosition();
3491 Standard_Integer aPosX = aCS->GetXPosition();
3492 Standard_Integer aPosY = aCS->GetYPosition();
3494 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
3498 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
3499 << "Min range: " << aMinRange << "\n"
3500 << "Max range: " << aMaxRange << "\n"
3501 << "Number of intervals: " << aNbIntervals << "\n"
3502 << "Text height: " << aTextHeight << "\n"
3503 << "Color scale position: " << aPosX <<" "<< aPosY<< "\n"
3504 << "Color scale title: " << aCS->GetTitle() << "\n"
3505 << "Label position: ";
3506 switch (aLabPosition)
3508 case Aspect_TOCSP_NONE:
3511 case Aspect_TOCSP_LEFT:
3514 case Aspect_TOCSP_RIGHT:
3517 case Aspect_TOCSP_CENTER:
3518 theDI << "Center\n";
3524 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
3526 Standard_CString anArg = theArgVec[anArgIter];
3527 TCollection_AsciiString aFlag (anArg);
3529 if (anUpdateTool.parseRedrawMode (aFlag))
3533 else if (aFlag == "-range")
3535 if (anArgIter + 3 >= theArgNb)
3537 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3541 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
3542 TCollection_AsciiString anArg2 (theArgVec[++anArgIter]);
3543 TCollection_AsciiString anArg3 (theArgVec[++anArgIter]);
3544 if (!anArg1.IsRealValue())
3546 std::cout << "Error: the minRange value should be real!\n";
3549 else if (!anArg2.IsRealValue())
3551 std::cout << "Error: the maxRange value should be real!\n";
3554 else if (!anArg3.IsIntegerValue())
3556 std::cout << "Error: the number of intervals should be integer!\n";
3560 aMinRange = anArg1.RealValue();
3561 aMaxRange = anArg2.RealValue();
3562 aNbIntervals = anArg3.IntegerValue();
3564 else if (aFlag == "-font")
3566 if (anArgIter + 1 >= theArgNb)
3568 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3571 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
3572 if (!aFontArg.IsIntegerValue())
3574 std::cout << "Error: HeightFont value should be integer!\n";
3578 aTextHeight = aFontArg.IntegerValue();
3581 else if (aFlag == "-textpos")
3583 if (anArgIter + 1 >= theArgNb)
3585 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3588 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
3589 aTextPosArg.LowerCase();
3590 if (aTextPosArg == "none")
3592 aLabPosition = Aspect_TOCSP_NONE;
3594 else if (aTextPosArg == "left")
3596 aLabPosition = Aspect_TOCSP_LEFT;
3598 else if (aTextPosArg == "right")
3600 aLabPosition = Aspect_TOCSP_RIGHT;
3602 else if (aTextPosArg == "center")
3604 aLabPosition = Aspect_TOCSP_CENTER;
3608 std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
3612 else if (aFlag == "-logarithmic"
3615 if (anArgIter + 1 >= theArgNb)
3617 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3620 Standard_Boolean IsLog;
3621 if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
3623 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3626 aCS->SetLogarithmic (IsLog);
3628 else if (aFlag == "-xy")
3630 if (anArgIter + 2 >= theArgNb)
3632 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3636 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3637 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3638 if (!aX.IsIntegerValue()
3639 || !aY.IsIntegerValue())
3641 std::cout << "Error: coordinates should be integer values!\n";
3645 aPosX = aX.IntegerValue();
3646 aPosY = aY.IntegerValue();
3648 else if (aFlag == "-width"
3651 if (anArgIter + 1 >= theArgNb)
3653 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3657 TCollection_AsciiString aW (theArgVec[++anArgIter]);
3658 if (!aW.IsIntegerValue())
3660 std::cout << "Error: a width should be an integer value!\n";
3664 aWidth = aW.IntegerValue();
3666 else if (aFlag == "-height"
3669 if (anArgIter + 1 >= theArgNb)
3671 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3675 TCollection_AsciiString aH (theArgVec[++anArgIter]);
3676 if (!aH.IsIntegerValue())
3678 std::cout << "Error: a width should be an integer value!\n";
3682 aHeight = aH.IntegerValue();
3684 else if (aFlag == "-color")
3686 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3688 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3692 Quantity_NameOfColor aColorName;
3693 if (anArgIter + 4 >= theArgNb)
3695 if (anArgIter + 2 >= theArgNb)
3697 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3700 else if (!Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3702 std::cout << "Error: wrong color name: '" << theArgVec[anArgIter + 2] << "' !\n";
3707 TCollection_AsciiString anInd (theArgVec[anArgIter + 1]);
3708 if (!anInd.IsIntegerValue())
3710 std::cout << "Error: Index value should be integer!\n";
3714 Standard_Integer anIndex = anInd.IntegerValue();
3716 || anIndex > aNbIntervals - 1)
3718 std::cout << "Error: Index value should be within range 0..." << (aNbIntervals - 1) <<"!\n";
3722 if (Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3724 aCS->SetColor (Quantity_Color (aColorName), anIndex);
3725 aCS->SetColorType (Aspect_TOCSD_USER);
3730 TCollection_AsciiString aRed (theArgVec[anArgIter + 2]);
3731 TCollection_AsciiString aGreen (theArgVec[anArgIter + 3]);
3732 TCollection_AsciiString aBlue (theArgVec[anArgIter + 4]);
3733 Standard_Real aRedValue,aGreenValue, aBlueValue;
3734 if(checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3738 aCS->SetColor (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB), anIndex);
3739 aCS->SetColorType (Aspect_TOCSD_USER);
3742 else if (aFlag == "-label")
3744 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3746 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
3749 else if (anArgIter + 2 >= theArgNb)
3751 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3755 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
3757 || anIndex > aNbIntervals)
3759 std::cout << "Error: Index value should be within range 0..." << aNbIntervals <<"!\n";
3763 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
3764 aCS->SetLabel (aText, anIndex);
3765 aCS->SetLabelType (Aspect_TOCSD_USER);
3768 else if (aFlag == "-colors")
3770 Aspect_SequenceOfColor aSeq;
3771 if (anArgIter + aNbIntervals + 1 > theArgNb)
3773 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3774 << aNbIntervals << " intervals\n";
3778 Standard_Integer aColorIter = anArgIter + 1;
3779 while (aColorIter < theArgNb)
3781 if (theArgVec[aColorIter][0] == '-')
3786 else if (theArgVec[aColorIter][0] >= 97
3787 && theArgVec[aColorIter][0] <= 122)
3789 Quantity_NameOfColor aColorName;
3790 if (!Quantity_Color::ColorFromName (theArgVec[aColorIter], aColorName))
3792 std::cout << "Error: wrong color name: " << theArgVec[aColorIter] << " !\n";
3795 aSeq.Append (Quantity_Color (aColorName));
3801 TCollection_AsciiString aRed (theArgVec[aColorIter]);
3802 TCollection_AsciiString aGreen (theArgVec[aColorIter + 1]);
3803 TCollection_AsciiString aBlue (theArgVec[aColorIter + 2]);
3804 Standard_Real aRedValue,aGreenValue, aBlueValue;
3805 if (checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3809 aSeq.Append (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB));
3814 if (aSeq.Length() < aNbIntervals)
3816 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3817 << aNbIntervals << " intervals\n";
3821 aCS->SetColors (aSeq);
3822 aCS->SetColorType (Aspect_TOCSD_USER);
3824 else if (aFlag == "-labels")
3826 if (anArgIter + aNbIntervals + 1 >= theArgNb)
3828 std::cout << "Error: not enough arguments! You should provide " << (aNbIntervals + 1)
3829 << " text labels for " << aNbIntervals << " intervals.\n";
3833 TColStd_SequenceOfExtendedString aSeq;
3834 for (int aLabelIter = anArgIter + 1; aLabelIter <= anArgIter + aNbIntervals + 1; aLabelIter += 1)
3836 aSeq.Append (TCollection_ExtendedString (theArgVec[aLabelIter]));
3838 aCS->SetLabels (aSeq);
3839 aCS->SetLabelType (Aspect_TOCSD_USER);
3840 anArgIter += aSeq.Length();
3842 else if (aFlag == "-title")
3844 if (anArgIter + 1 >= theArgNb)
3846 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3850 Standard_Boolean isTwoArgs = Standard_False;
3851 if (anArgIter + 2 < theArgNb)
3853 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
3854 aSecondArg.LowerCase();
3855 if (aSecondArg == "none")
3857 aCS->SetTitlePosition (Aspect_TOCSP_NONE);
3858 isTwoArgs = Standard_True;
3860 else if (aSecondArg == "left")
3862 aCS->SetTitlePosition (Aspect_TOCSP_LEFT);
3863 isTwoArgs = Standard_True;
3865 else if (aSecondArg == "right")
3867 aCS->SetTitlePosition (Aspect_TOCSP_RIGHT);
3868 isTwoArgs = Standard_True;
3870 else if (aSecondArg == "center")
3872 aCS->SetTitlePosition (Aspect_TOCSP_CENTER);
3873 isTwoArgs = Standard_True;
3877 aCS->SetTitle (theArgVec[anArgIter + 1]);
3884 else if (aFlag == "-demoversion"
3885 || aFlag == "-demo")
3895 aLabPosition = Aspect_TOCSP_RIGHT;
3896 aCS->SetColorType (Aspect_TOCSD_AUTO);
3897 aCS->SetLabelType (Aspect_TOCSD_AUTO);
3901 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
3905 if (!aWidth || !aHeight)
3907 Standard_Integer aWinWidth, aWinHeight;
3908 aView->Window()->Size (aWinWidth, aWinHeight);
3915 aHeight = aWinHeight;
3918 aCS->SetSize (aWidth, aHeight);
3919 aCS->SetPosition (aPosX, aPosY);
3920 aCS->SetTextHeight (aTextHeight);
3921 aCS->SetRange (aMinRange, aMaxRange);
3922 aCS->SetNumberOfIntervals (aNbIntervals);
3923 aCS->SetLabelPosition (aLabPosition);
3924 aCS->SetBGColor (aView->BackgroundColor());
3926 aContext->Display (aCS);
3931 //==============================================================================
3932 //function : VGraduatedTrihedron
3933 //purpose : Displays or hides a graduated trihedron
3934 //==============================================================================
3935 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
3936 Quantity_Color& theColor)
3938 Quantity_NameOfColor aColorName;
3939 TCollection_AsciiString aVal = theValue;
3941 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
3943 return Standard_False;
3945 theColor = Quantity_Color (aColorName);
3946 return Standard_True;
3949 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
3953 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
3954 << theArgs[0] <<"' for more information.\n";
3955 return 1; //TCL_ERROR
3958 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
3959 TCollection_AsciiString aParseKey;
3960 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
3962 TCollection_AsciiString anArg (theArgs [anArgIt]);
3964 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3967 aParseKey.Remove (1);
3968 aParseKey.LowerCase();
3969 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
3973 if (aParseKey.IsEmpty())
3978 aMapOfArgs(aParseKey)->Append (anArg);
3982 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
3983 aMapIt.More(); aMapIt.Next())
3985 const TCollection_AsciiString& aKey = aMapIt.Key();
3986 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
3988 // Bool key, without arguments
3989 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
3990 && anArgs->IsEmpty())
3996 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
3997 && anArgs->Length() == 1)
4003 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
4004 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
4005 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
4006 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
4007 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
4012 // One string argument
4013 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
4014 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
4015 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4020 // One integer argument
4021 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
4022 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
4023 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
4024 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
4025 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
4030 // One real argument
4031 if ( aKey.IsEqual ("arrowlength")
4032 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
4037 // Two string arguments
4038 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
4039 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4044 TCollection_AsciiString aLowerKey;
4047 aLowerKey.LowerCase();
4048 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
4049 std::cout << "Type help for more information.\n";
4053 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4054 if (anAISContext.IsNull())
4056 std::cout << theArgs[0] << ": " << " please use 'vinit' command to initialize view.\n";
4060 Standard_Boolean toDisplay = Standard_True;
4061 Quantity_Color aColor;
4062 Graphic3d_GraduatedTrihedron aTrihedronData;
4063 // Process parameters
4064 Handle(TColStd_HSequenceOfAsciiString) aValues;
4065 if (aMapOfArgs.Find ("off", aValues))
4067 toDisplay = Standard_False;
4071 if (aMapOfArgs.Find ("xname", aValues))
4073 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
4075 if (aMapOfArgs.Find ("yname", aValues))
4077 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
4079 if (aMapOfArgs.Find ("zname", aValues))
4081 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
4083 if (aMapOfArgs.Find ("xdrawname", aValues))
4085 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4087 if (aMapOfArgs.Find ("ydrawname", aValues))
4089 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4091 if (aMapOfArgs.Find ("zdrawname", aValues))
4093 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4095 if (aMapOfArgs.Find ("xnameoffset", aValues))
4097 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4099 if (aMapOfArgs.Find ("ynameoffset", aValues))
4101 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4103 if (aMapOfArgs.Find ("znameoffset", aValues))
4105 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4109 if (aMapOfArgs.Find ("xnamecolor", aValues))
4111 if (!GetColor (aValues->Value(1), aColor))
4113 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
4116 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
4118 if (aMapOfArgs.Find ("ynamecolor", aValues))
4120 if (!GetColor (aValues->Value(1), aColor))
4122 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
4125 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
4127 if (aMapOfArgs.Find ("znamecolor", aValues))
4129 if (!GetColor (aValues->Value(1), aColor))
4131 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
4134 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
4136 if (aMapOfArgs.Find ("xcolor", aValues))
4138 if (!GetColor (aValues->Value(1), aColor))
4140 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
4143 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
4145 if (aMapOfArgs.Find ("ycolor", aValues))
4147 if (!GetColor (aValues->Value(1), aColor))
4149 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
4152 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
4154 if (aMapOfArgs.Find ("zcolor", aValues))
4156 if (!GetColor (aValues->Value(1), aColor))
4158 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
4161 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
4165 if (aMapOfArgs.Find ("xticks", aValues))
4167 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4169 if (aMapOfArgs.Find ("yticks", aValues))
4171 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4173 if (aMapOfArgs.Find ("zticks", aValues))
4175 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4177 if (aMapOfArgs.Find ("xticklength", aValues))
4179 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4181 if (aMapOfArgs.Find ("yticklength", aValues))
4183 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4185 if (aMapOfArgs.Find ("zticklength", aValues))
4187 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4189 if (aMapOfArgs.Find ("xdrawticks", aValues))
4191 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4193 if (aMapOfArgs.Find ("ydrawticks", aValues))
4195 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4197 if (aMapOfArgs.Find ("zdrawticks", aValues))
4199 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4203 if (aMapOfArgs.Find ("xdrawvalues", aValues))
4205 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4207 if (aMapOfArgs.Find ("ydrawvalues", aValues))
4209 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4211 if (aMapOfArgs.Find ("zdrawvalues", aValues))
4213 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4215 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
4217 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4219 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
4221 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4223 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
4225 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4229 if (aMapOfArgs.Find ("arrowlength", aValues))
4231 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
4235 if (aMapOfArgs.Find ("namefont", aValues))
4237 aTrihedronData.SetNamesFont (aValues->Value(1));
4239 if (aMapOfArgs.Find ("valuesfont", aValues))
4241 aTrihedronData.SetValuesFont (aValues->Value(1));
4244 if (aMapOfArgs.Find ("drawgrid", aValues))
4246 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
4248 if (aMapOfArgs.Find ("drawaxes", aValues))
4250 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
4253 // The final step: display of erase trihedron
4256 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
4260 ViewerTest::CurrentView()->GraduatedTrihedronErase();
4263 ViewerTest::GetAISContext()->UpdateCurrentViewer();
4264 ViewerTest::CurrentView()->Redraw();
4269 //==============================================================================
4270 //function : VPrintView
4271 //purpose : Test printing algorithm, print the view to image file with given
4272 // width and height. Printing implemented only for WNT.
4273 //==============================================================================
4274 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
4280 di << "Printing implemented only for WNT!\n";
4284 Handle(AIS_InteractiveContext) aContextAIS = NULL;
4285 Handle(V3d_View) aView = NULL;
4286 aContextAIS = ViewerTest::GetAISContext();
4287 if (!aContextAIS.IsNull())
4289 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
4290 Vwr->InitActiveViews();
4291 if(Vwr->MoreActiveViews())
4292 aView = Vwr->ActiveView();
4298 di << "Call vinit before!\n";
4303 di << "Use: " << argv[0];
4304 di << " width height filename [print algo=0] [tile_width tile_height]\n";
4305 di << "width, height of the intermediate buffer for operation\n";
4306 di << "algo : {0|1}\n";
4307 di << " 0 - stretch algorithm\n";
4308 di << " 1 - tile algorithm\n";
4309 di << "test printing algorithms into an intermediate buffer\n";
4310 di << "using specific tile size if provided\n";
4311 di << "with saving output to an image file\n";
4315 // get the input params
4316 Standard_Integer aWidth = Draw::Atoi (argv[1]);
4317 Standard_Integer aHeight = Draw::Atoi (argv[2]);
4318 Standard_Integer aMode = 0;
4319 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
4321 aMode = Draw::Atoi (argv[4]);
4323 Standard_Integer aTileWidth = 0;
4324 Standard_Integer aTileHeight = 0;
4325 Standard_Boolean isTileSizeProvided = Standard_False;
4328 isTileSizeProvided = Standard_True;
4329 aTileWidth = Draw::Atoi (argv[5]);
4330 aTileHeight = Draw::Atoi (argv[6]);
4333 // check the input parameters
4334 if (aWidth <= 0 || aHeight <= 0)
4336 di << "Width and height must be positive values!\n";
4339 if (aMode != 0 && aMode != 1)
4342 // define compatible bitmap
4343 HDC anDC = CreateCompatibleDC(0);
4344 BITMAPINFO aBitmapData;
4345 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
4346 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
4347 aBitmapData.bmiHeader.biWidth = aWidth ;
4348 aBitmapData.bmiHeader.biHeight = aHeight;
4349 aBitmapData.bmiHeader.biPlanes = 1;
4350 aBitmapData.bmiHeader.biBitCount = 24;
4351 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
4352 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
4353 aBitmapData.bmiHeader.biClrUsed = 0;
4354 aBitmapData.bmiHeader.biClrImportant = 0;
4355 aBitmapData.bmiHeader.biCompression = BI_RGB;
4356 aBitmapData.bmiHeader.biSizeImage = 0;
4358 // Create Device Independent Bitmap
4359 void* aBitsOut = NULL;
4360 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
4361 &aBitsOut, NULL, 0);
4362 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
4364 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
4365 if (aBitsOut != NULL)
4368 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
4371 if (isTileSizeProvided)
4373 Handle(Graphic3d_CView) aGraphicView = ViewerTest::CurrentView()->View();
4374 Handle(Standard_Transient) anOldBuffer = aGraphicView->FBO();
4375 Handle(Standard_Transient) aNewBuffer = aGraphicView->FBOCreate (aTileWidth, aTileHeight);
4376 aGraphicView->SetFBO (aNewBuffer);
4378 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
4380 aGraphicView->FBORelease (aNewBuffer);
4381 aGraphicView->SetFBO (anOldBuffer);
4385 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
4389 // successfully printed into an intermediate buffer
4392 Image_PixMap aWrapper;
4393 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
4394 aWrapper.SetTopDown (false);
4396 Image_AlienPixMap anImageBitmap;
4397 anImageBitmap.InitCopy (aWrapper);
4398 isSaved = anImageBitmap.Save (aFileName);
4402 di << "Print operation failed due to printing errors or\n";
4403 di << "insufficient memory available\n";
4404 di << "Please, try to use smaller dimensions for this test\n";
4405 di << "command, as it allocates intermediate buffer for storing\n";
4406 di << "the result\n";
4411 di << "Can't allocate memory for intermediate buffer\n";
4412 di << "Please use smaller dimensions\n";
4417 SelectObject (anDC, anOldBitmap);
4418 DeleteObject (aMemoryBitmap);
4424 di << "Save to file operation failed. This operation may fail\n";
4425 di << "if you don't have enough available memory, then you can\n";
4426 di << "use smaller dimensions for the output file\n";
4435 //==============================================================================
4436 //function : VZLayer
4437 //purpose : Test z layer operations for v3d viewer
4438 //==============================================================================
4439 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4441 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
4442 if (aContextAIS.IsNull())
4444 di << "Call vinit before!\n";
4449 di << "Use: vzlayer ";
4450 di << " add/del/get/settings/enable/disable [id]\n";
4451 di << " add - add new z layer to viewer and print its id\n";
4452 di << " del - del z layer by its id\n";
4453 di << " get - print sequence of z layers in increasing order of their overlay level\n";
4454 di << " settings - print status of z layer settings\n";
4455 di << " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n";
4456 di << " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n";
4457 di << " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n";
4458 di << "\nWhere id is the layer identificator\n";
4459 di << "\nExamples:\n";
4460 di << " vzlayer add\n";
4461 di << " vzlayer enable poffset 1\n";
4462 di << " vzlayer disable depthtest 1\n";
4463 di << " vzlayer del 1\n";
4467 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
4468 if (aViewer.IsNull())
4470 di << "No active viewer!\n";
4474 // perform operation
4475 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
4478 Standard_Integer aNewId;
4479 if (!aViewer->AddZLayer (aNewId))
4481 di << "Impossible to add new z layer!\n";
4485 di << "New z layer added with index: " << aNewId << "\n";
4487 else if (anOp == "del")
4491 di << "Please also provide as argument id of z layer to remove\n";
4495 Standard_Integer aDelId = Draw::Atoi (argv[2]);
4496 if (!aViewer->RemoveZLayer (aDelId))
4498 di << "Impossible to remove the z layer or invalid id!\n";
4502 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4503 anObjIter.More(); anObjIter.Next())
4505 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1());
4507 || aPrs->ZLayer() != aDelId)
4511 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4514 di << "Z layer " << aDelId << " has been removed\n";
4516 else if (anOp == "get")
4518 TColStd_SequenceOfInteger anIds;
4519 aViewer->GetAllZLayers (anIds);
4520 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
4522 di << anIds.Value (aSeqIdx) << " ";
4527 else if (anOp == "settings")
4531 di << "Please also provide an id\n";
4535 Standard_Integer anId = Draw::Atoi (argv[2]);
4536 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4538 di << "Depth test - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthTest) ? "enabled" : "disabled") << "\n";
4539 di << "Depth write - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthWrite) ? "enabled" : "disabled") << "\n";
4540 di << "Depth buffer clearing - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthClear) ? "enabled" : "disabled") << "\n";
4541 di << "Depth offset - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthOffset) ? "enabled" : "disabled") << "\n";
4544 else if (anOp == "enable")
4548 di << "Please also provide an option to enable\n";
4554 di << "Please also provide a layer id\n";
4558 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
4559 Standard_Integer anId = Draw::Atoi (argv[3]);
4560 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4562 if (aSubOp == "depthtest" || aSubOp == "test")
4564 aSettings.EnableSetting (Graphic3d_ZLayerDepthTest);
4566 else if (aSubOp == "depthwrite" || aSubOp == "write")
4568 aSettings.EnableSetting (Graphic3d_ZLayerDepthWrite);
4570 else if (aSubOp == "depthclear" || aSubOp == "clear")
4572 aSettings.EnableSetting (Graphic3d_ZLayerDepthClear);
4574 else if (aSubOp == "depthoffset" || aSubOp == "offset")
4578 di << "Please also provide a factor and units values for depth offset\n";
4579 di << "Format is: vzlayer enable offset [factor] [units] [layerId]\n";
4583 Standard_ShortReal aFactor = static_cast<Standard_ShortReal> (Draw::Atof (argv[3]));
4584 Standard_ShortReal aUnits = static_cast<Standard_ShortReal> (Draw::Atof (argv[4]));
4585 anId = Draw::Atoi (argv[5]);
4586 aSettings = aViewer->ZLayerSettings (anId);
4588 aSettings.DepthOffsetFactor = aFactor;
4589 aSettings.DepthOffsetUnits = aUnits;
4591 aSettings.EnableSetting (Graphic3d_ZLayerDepthOffset);
4593 else if (aSubOp == "positiveoffset" || aSubOp == "poffset")
4595 aSettings.SetDepthOffsetPositive();
4597 else if (aSubOp == "negativeoffset" || aSubOp == "noffset")
4599 aSettings.SetDepthOffsetNegative();
4602 aViewer->SetZLayerSettings (anId, aSettings);
4604 else if (anOp == "disable")
4608 di << "Please also provide an option to disable\n";
4614 di << "Please also provide a layer id\n";
4618 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
4619 Standard_Integer anId = Draw::Atoi (argv[3]);
4620 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4622 if (aSubOp == "depthtest" || aSubOp == "test")
4624 aSettings.DisableSetting (Graphic3d_ZLayerDepthTest);
4626 else if (aSubOp == "depthwrite" || aSubOp == "write")
4628 aSettings.DisableSetting (Graphic3d_ZLayerDepthWrite);
4630 else if (aSubOp == "depthclear" || aSubOp == "clear")
4632 aSettings.DisableSetting (Graphic3d_ZLayerDepthClear);
4634 else if (aSubOp == "depthoffset" || aSubOp == "offset")
4636 aSettings.DisableSetting (Graphic3d_ZLayerDepthOffset);
4639 aViewer->SetZLayerSettings (anId, aSettings);
4643 di << "Invalid operation, please use { add / del / get / settings / enable / disable}\n";
4650 // The interactive presentation of 2d layer item
4651 // for "vlayerline" command it provides a presentation of
4652 // line with user-defined linewidth, linetype and transparency.
4653 class V3d_LineItem : public AIS_InteractiveObject
4657 DEFINE_STANDARD_RTTI(V3d_LineItem, AIS_InteractiveObject)
4660 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4661 Standard_Real X2, Standard_Real Y2,
4662 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
4663 Standard_Real theWidth = 0.5,
4664 Standard_Real theTransp = 1.0);
4668 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4669 const Handle(Prs3d_Presentation)& thePresentation,
4670 const Standard_Integer theMode) Standard_OVERRIDE;
4672 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
4673 const Standard_Integer /*aMode*/) Standard_OVERRIDE
4678 Standard_Real myX1, myY1, myX2, myY2;
4679 Aspect_TypeOfLine myType;
4680 Standard_Real myWidth;
4683 // default constructor for line item
4684 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4685 Standard_Real X2, Standard_Real Y2,
4686 Aspect_TypeOfLine theType,
4687 Standard_Real theWidth,
4688 Standard_Real theTransp) :
4689 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
4690 myType(theType), myWidth(theWidth)
4692 SetTransparency (1-theTransp);
4696 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
4697 const Handle(Prs3d_Presentation)& thePresentation,
4698 const Standard_Integer /*theMode*/)
4700 thePresentation->Clear();
4701 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
4702 Standard_Integer aWidth, aHeight;
4703 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
4704 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
4705 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
4706 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
4707 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
4708 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
4709 aGroup->SetPrimitivesAspect (anAspect->Aspect());
4710 aGroup->AddPrimitiveArray (aPrim);
4713 //=============================================================================
4714 //function : VLayerLine
4715 //purpose : Draws line in the v3d view layer with given attributes: linetype,
4716 // : linewidth, transparency coefficient
4717 //============================================================================
4718 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4720 // get the active view
4721 Handle(V3d_View) aView = ViewerTest::CurrentView();
4724 di << "Call vinit before!\n";
4729 di << "Use: " << argv[0];
4730 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
4731 di << " linetype : { 0 | 1 | 2 | 3 } \n";
4732 di << " 0 - solid \n";
4733 di << " 1 - dashed \n";
4734 di << " 2 - dot \n";
4735 di << " 3 - dashdot\n";
4736 di << " transparency : { 0.0 - 1.0 } \n";
4737 di << " 0.0 - transparent\n";
4738 di << " 1.0 - visible \n";
4742 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4743 // get the input params
4744 Standard_Real X1 = Draw::Atof(argv[1]);
4745 Standard_Real Y1 = Draw::Atof(argv[2]);
4746 Standard_Real X2 = Draw::Atof(argv[3]);
4747 Standard_Real Y2 = Draw::Atof(argv[4]);
4749 Standard_Real aWidth = 0.5;
4750 Standard_Integer aType = 0;
4751 Standard_Real aTransparency = 1.0;
4755 aWidth = Draw::Atof(argv[5]);
4759 aType = (Standard_Integer) Draw::Atoi(argv[6]);
4764 aTransparency = Draw::Atof(argv[7]);
4765 if (aTransparency < 0 || aTransparency > 1.0)
4766 aTransparency = 1.0;
4769 // select appropriate line type
4770 Aspect_TypeOfLine aLineType;
4774 aLineType = Aspect_TOL_DASH;
4778 aLineType = Aspect_TOL_DOT;
4782 aLineType = Aspect_TOL_DOTDASH;
4786 aLineType = Aspect_TOL_SOLID;
4789 static Handle (V3d_LineItem) aLine;
4790 if (!aLine.IsNull())
4792 aContext->Erase (aLine);
4794 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
4798 aLine->SetTransformPersistence (Graphic3d_TMF_2d,gp_Pnt(-1,-1,0));
4799 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
4800 aLine->SetToUpdate();
4801 aContext->Display (aLine, Standard_True);
4807 //==============================================================================
4810 //==============================================================================
4812 static int VGrid (Draw_Interpretor& /*theDI*/,
4813 Standard_Integer theArgNb,
4814 const char** theArgVec)
4816 // get the active view
4817 Handle(V3d_View) aView = ViewerTest::CurrentView();
4818 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4819 if (aView.IsNull() || aViewer.IsNull())
4821 std::cerr << "No active view. Please call vinit.\n";
4825 Aspect_GridType aType = aViewer->GridType();
4826 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
4828 Standard_Integer anIter = 1;
4829 for (; anIter < theArgNb; ++anIter)
4831 const char* aValue = theArgVec[anIter];
4834 aType = Aspect_GT_Rectangular;
4836 else if (*aValue == 'c')
4838 aType = Aspect_GT_Circular;
4840 else if (*aValue == 'l')
4842 aMode = Aspect_GDM_Lines;
4844 else if (*aValue == 'p')
4846 aMode = Aspect_GDM_Points;
4848 else if (strcmp (aValue, "off" ) == 0)
4850 aViewer->DeactivateGrid();
4859 Standard_Integer aTail = (theArgNb - anIter);
4862 aViewer->ActivateGrid (aType, aMode);
4865 else if (aTail != 2 && aTail != 5)
4867 std::cerr << "Incorrect arguments number! Usage:\n"
4868 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
4872 Quantity_Length anOriginX, anOriginY;
4873 Quantity_PlaneAngle aRotAngle;
4874 if (aType == Aspect_GT_Rectangular)
4876 Quantity_Length aRStepX, aRStepY;
4877 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4879 anOriginX = Draw::Atof (theArgVec[anIter++]);
4880 anOriginY = Draw::Atof (theArgVec[anIter++]);
4883 aRStepX = Draw::Atof (theArgVec[anIter++]);
4884 aRStepY = Draw::Atof (theArgVec[anIter++]);
4885 aRotAngle = Draw::Atof (theArgVec[anIter++]);
4887 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4888 aViewer->ActivateGrid (aType, aMode);
4890 else if (aType == Aspect_GT_Circular)
4892 Quantity_Length aRadiusStep;
4893 Standard_Integer aDivisionNumber;
4894 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
4896 anOriginX = Draw::Atof (theArgVec[anIter++]);
4897 anOriginY = Draw::Atof (theArgVec[anIter++]);
4900 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
4901 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
4902 aRotAngle = Draw::Atof (theArgVec[anIter++]);
4905 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
4906 aViewer->ActivateGrid (aType, aMode);
4912 //==============================================================================
4913 //function : VPriviledgedPlane
4915 //==============================================================================
4917 static int VPriviledgedPlane (Draw_Interpretor& theDI,
4918 Standard_Integer theArgNb,
4919 const char** theArgVec)
4921 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
4923 std::cerr << "Error: wrong number of arguments! See usage:\n";
4924 theDI.PrintHelp (theArgVec[0]);
4928 // get the active viewer
4929 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4930 if (aViewer.IsNull())
4932 std::cerr << "Error: no active viewer. Please call vinit.\n";
4938 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
4939 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
4940 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
4941 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
4942 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
4943 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
4944 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
4948 Standard_Integer anArgIdx = 1;
4949 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
4950 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
4951 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
4952 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
4953 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
4954 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
4956 gp_Ax3 aPriviledgedPlane;
4957 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
4958 gp_Dir aNorm (aNormX, aNormY, aNormZ);
4961 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
4962 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
4963 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
4964 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
4965 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
4969 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
4972 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
4977 //==============================================================================
4978 //function : VConvert
4980 //==============================================================================
4982 static int VConvert (Draw_Interpretor& theDI,
4983 Standard_Integer theArgNb,
4984 const char** theArgVec)
4986 // get the active view
4987 Handle(V3d_View) aView = ViewerTest::CurrentView();
4990 std::cerr << "Error: no active view. Please call vinit.\n";
4994 enum { Model, Ray, View, Window, Grid } aMode = Model;
4996 // access coordinate arguments
4997 TColStd_SequenceOfReal aCoord;
4998 Standard_Integer anArgIdx = 1;
4999 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
5001 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5002 if (!anArg.IsRealValue())
5006 aCoord.Append (anArg.RealValue());
5009 // non-numeric argument too early
5010 if (aCoord.IsEmpty())
5012 std::cerr << "Error: wrong number of arguments! See usage:\n";
5013 theDI.PrintHelp (theArgVec[0]);
5017 // collect all other arguments and options
5018 for (; anArgIdx < theArgNb; ++anArgIdx)
5020 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5022 if (anArg == "window") aMode = Window;
5023 else if (anArg == "view") aMode = View;
5024 else if (anArg == "grid") aMode = Grid;
5025 else if (anArg == "ray") aMode = Ray;
5028 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
5029 theDI.PrintHelp (theArgVec[0]);
5034 // complete input checks
5035 if ((aCoord.Length() == 1 && theArgNb > 3) ||
5036 (aCoord.Length() == 2 && theArgNb > 4) ||
5037 (aCoord.Length() == 3 && theArgNb > 5))
5039 std::cerr << "Error: wrong number of arguments! See usage:\n";
5040 theDI.PrintHelp (theArgVec[0]);
5044 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
5045 Standard_Integer aXYp[2] = {0, 0};
5047 // convert one-dimensional coordinate
5048 if (aCoord.Length() == 1)
5052 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer) aCoord (1)); return 0;
5053 case Window : theDI << "Window Vp: " << aView->Convert ((Quantity_Length) aCoord (1)); return 0;
5055 std::cerr << "Error: wrong arguments! See usage:\n";
5056 theDI.PrintHelp (theArgVec[0]);
5061 // convert 2D coordinates from projection or view reference space
5062 if (aCoord.Length() == 2)
5067 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5068 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5072 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5073 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5077 aView->Convert ((V3d_Coordinate) aCoord (1), (V3d_Coordinate) aCoord (2), aXYp[0], aXYp[1]);
5078 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5082 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5083 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5084 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5088 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5089 (Standard_Integer) aCoord (2),
5090 aXYZ[0], aXYZ[1], aXYZ[2],
5091 aXYZ[3], aXYZ[4], aXYZ[5]);
5092 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5096 std::cerr << "Error: wrong arguments! See usage:\n";
5097 theDI.PrintHelp (theArgVec[0]);
5102 // convert 3D coordinates from view reference space
5103 else if (aCoord.Length() == 3)
5108 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5109 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5113 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5114 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5118 std::cerr << "Error: wrong arguments! See usage:\n";
5119 theDI.PrintHelp (theArgVec[0]);
5127 //==============================================================================
5130 //==============================================================================
5132 static int VFps (Draw_Interpretor& theDI,
5133 Standard_Integer theArgNb,
5134 const char** theArgVec)
5136 // get the active view
5137 Handle(V3d_View) aView = ViewerTest::CurrentView();
5140 std::cerr << "No active view. Please call vinit.\n";
5144 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
5147 std::cerr << "Incorrect arguments!\n";
5151 // the time is meaningless for first call
5152 // due to async OpenGl rendering
5155 // redraw view in loop to estimate average values
5158 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
5164 const Standard_Real aTime = aTimer.ElapsedTime();
5165 aTimer.OSD_Chronometer::Show (aCpu);
5167 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
5168 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
5170 // return statistics
5171 theDI << "FPS: " << aFpsAver << "\n"
5172 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5174 // compute additional statistics in ray-tracing mode
5175 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
5177 if (aParams.Method == Graphic3d_RM_RAYTRACING)
5179 Standard_Integer aSizeX;
5180 Standard_Integer aSizeY;
5182 aView->Window()->Size (aSizeX, aSizeY);
5184 // 1 shadow ray and 1 secondary ray pew each bounce
5185 const Standard_Real aMRays = aSizeX * aSizeY * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
5187 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
5193 //==============================================================================
5194 //function : VGlDebug
5196 //==============================================================================
5198 static int VGlDebug (Draw_Interpretor& theDI,
5199 Standard_Integer theArgNb,
5200 const char** theArgVec)
5202 Handle(OpenGl_GraphicDriver) aDriver;
5203 Handle(V3d_View) aView = ViewerTest::CurrentView();
5204 if (!aView.IsNull())
5206 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5208 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
5209 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
5213 TCollection_AsciiString aDebActive, aSyncActive;
5220 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
5221 "GL_ARB_debug_output");
5222 aDebActive = isActive ? " (active)" : " (inactive)";
5225 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
5226 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
5230 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
5231 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
5232 << "glslWarn:" << (aCaps->glslWarnings ? "1" : "0") << "\n"
5233 << "extraMsg:" << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
5237 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5239 Standard_CString anArg = theArgVec[anArgIter];
5240 TCollection_AsciiString anArgCase (anArg);
5241 anArgCase.LowerCase();
5242 Standard_Boolean toEnableDebug = Standard_True;
5243 if (anArgCase == "-glsl"
5244 || anArgCase == "-glslwarn"
5245 || anArgCase == "-glslwarns"
5246 || anArgCase == "-glslwarnings")
5248 Standard_Boolean toShowWarns = Standard_True;
5249 if (++anArgIter < theArgNb
5250 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
5254 aDefCaps->glslWarnings = toShowWarns;
5257 aCaps->glslWarnings = toShowWarns;
5260 else if (anArgCase == "-extra"
5261 || anArgCase == "-extramsg"
5262 || anArgCase == "-extramessages")
5264 Standard_Boolean toShow = Standard_True;
5265 if (++anArgIter < theArgNb
5266 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
5270 aDefCaps->suppressExtraMsg = !toShow;
5273 aCaps->suppressExtraMsg = !toShow;
5276 else if (anArgCase == "-noextra"
5277 || anArgCase == "-noextramsg"
5278 || anArgCase == "-noextramessages")
5280 Standard_Boolean toSuppress = Standard_True;
5281 if (++anArgIter < theArgNb
5282 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
5286 aDefCaps->suppressExtraMsg = toSuppress;
5289 aCaps->suppressExtraMsg = toSuppress;
5292 else if (anArgCase == "-sync")
5294 Standard_Boolean toSync = Standard_True;
5295 if (++anArgIter < theArgNb
5296 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
5300 aDefCaps->contextSyncDebug = toSync;
5303 aDefCaps->contextDebug = Standard_True;
5306 else if (anArgCase == "-debug")
5308 if (++anArgIter < theArgNb
5309 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
5313 aDefCaps->contextDebug = toEnableDebug;
5315 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
5316 && (anArgIter + 1 == theArgNb))
5318 // simple alias to turn on almost everything
5319 aDefCaps->contextDebug = toEnableDebug;
5320 aDefCaps->contextSyncDebug = toEnableDebug;
5321 aDefCaps->glslWarnings = toEnableDebug;
5325 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
5333 //==============================================================================
5336 //==============================================================================
5338 static int VVbo (Draw_Interpretor& theDI,
5339 Standard_Integer theArgNb,
5340 const char** theArgVec)
5342 const Standard_Boolean toSet = (theArgNb > 1);
5343 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
5346 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
5350 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5351 if (aContextAIS.IsNull())
5355 std::cerr << "No active view!\n";
5359 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5360 if (!aDriver.IsNull())
5364 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
5368 aDriver->ChangeOptions().vboDisable = toUseVbo;
5375 //==============================================================================
5378 //==============================================================================
5380 static int VCaps (Draw_Interpretor& theDI,
5381 Standard_Integer theArgNb,
5382 const char** theArgVec)
5384 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
5385 Handle(OpenGl_GraphicDriver) aDriver;
5386 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5387 if (!aContext.IsNull())
5389 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
5390 aCaps = &aDriver->ChangeOptions();
5395 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
5396 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
5397 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
5398 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
5399 theDI << "VSync: " << aCaps->swapInterval << "\n";
5400 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
5401 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
5405 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5406 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5408 Standard_CString anArg = theArgVec[anArgIter];
5409 TCollection_AsciiString anArgCase (anArg);
5410 anArgCase.LowerCase();
5411 if (anUpdateTool.parseRedrawMode (anArg))
5415 else if (anArgCase == "-vsync"
5416 || anArgCase == "-swapinterval")
5418 Standard_Boolean toEnable = Standard_True;
5419 if (++anArgIter < theArgNb
5420 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5424 aCaps->swapInterval = toEnable;
5426 else if (anArgCase == "-ffp")
5428 Standard_Boolean toEnable = Standard_True;
5429 if (++anArgIter < theArgNb
5430 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5434 aCaps->ffpEnable = toEnable;
5436 else if (anArgCase == "-vbo")
5438 Standard_Boolean toEnable = Standard_True;
5439 if (++anArgIter < theArgNb
5440 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5444 aCaps->vboDisable = !toEnable;
5446 else if (anArgCase == "-sprite"
5447 || anArgCase == "-sprites")
5449 Standard_Boolean toEnable = Standard_True;
5450 if (++anArgIter < theArgNb
5451 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5455 aCaps->pntSpritesDisable = !toEnable;
5457 else if (anArgCase == "-softmode")
5459 Standard_Boolean toEnable = Standard_True;
5460 if (++anArgIter < theArgNb
5461 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5465 aCaps->contextNoAccel = toEnable;
5467 else if (anArgCase == "-accel"
5468 || anArgCase == "-acceleration")
5470 Standard_Boolean toEnable = Standard_True;
5471 if (++anArgIter < theArgNb
5472 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5476 aCaps->contextNoAccel = !toEnable;
5478 else if (anArgCase == "-compat"
5479 || anArgCase == "-compatprofile"
5480 || anArgCase == "-compatible"
5481 || anArgCase == "-compatibleprofile")
5483 Standard_Boolean toEnable = Standard_True;
5484 if (++anArgIter < theArgNb
5485 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5489 aCaps->contextCompatible = toEnable;
5490 if (!aCaps->contextCompatible)
5492 aCaps->ffpEnable = Standard_False;
5495 else if (anArgCase == "-core"
5496 || anArgCase == "-coreprofile")
5498 Standard_Boolean toEnable = Standard_True;
5499 if (++anArgIter < theArgNb
5500 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5504 aCaps->contextCompatible = !toEnable;
5505 if (!aCaps->contextCompatible)
5507 aCaps->ffpEnable = Standard_False;
5510 else if (anArgCase == "-stereo"
5511 || anArgCase == "-quadbuffer")
5513 Standard_Boolean toEnable = Standard_True;
5514 if (++anArgIter < theArgNb
5515 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5519 aCaps->contextStereo = toEnable;
5523 std::cout << "Error: unknown argument '" << anArg << "'\n";
5527 if (aCaps != &ViewerTest_myDefaultCaps)
5529 ViewerTest_myDefaultCaps = *aCaps;
5534 //==============================================================================
5535 //function : VMemGpu
5537 //==============================================================================
5539 static int VMemGpu (Draw_Interpretor& theDI,
5540 Standard_Integer theArgNb,
5541 const char** theArgVec)
5544 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5545 if (aContextAIS.IsNull())
5547 std::cerr << "No active view. Please call vinit.\n";
5551 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
5552 if (aDriver.IsNull())
5554 std::cerr << "Graphic driver not available.\n";
5558 Standard_Size aFreeBytes = 0;
5559 TCollection_AsciiString anInfo;
5560 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
5562 std::cerr << "Information not available.\n";
5566 if (theArgNb > 1 && *theArgVec[1] == 'f')
5568 theDI << Standard_Real (aFreeBytes);
5578 // ==============================================================================
5579 // function : VReadPixel
5581 // ==============================================================================
5582 static int VReadPixel (Draw_Interpretor& theDI,
5583 Standard_Integer theArgNb,
5584 const char** theArgVec)
5586 // get the active view
5587 Handle(V3d_View) aView = ViewerTest::CurrentView();
5590 std::cerr << "No active view. Please call vinit.\n";
5593 else if (theArgNb < 3)
5595 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
5599 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
5600 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
5602 Standard_Integer aWidth, aHeight;
5603 aView->Window()->Size (aWidth, aHeight);
5604 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
5605 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
5606 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
5608 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
5612 Standard_Boolean toShowName = Standard_False;
5613 Standard_Boolean toShowHls = Standard_False;
5614 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
5616 const char* aParam = theArgVec[anIter];
5617 if ( strcasecmp( aParam, "rgb" ) == 0 )
5619 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
5620 aBufferType = Graphic3d_BT_RGB;
5622 else if ( strcasecmp( aParam, "hls" ) == 0 )
5624 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
5625 aBufferType = Graphic3d_BT_RGB;
5626 toShowHls = Standard_True;
5628 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
5630 aFormat = Image_PixMap::ImgRGBF;
5631 aBufferType = Graphic3d_BT_RGB;
5633 else if ( strcasecmp( aParam, "rgba" ) == 0 )
5635 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
5636 aBufferType = Graphic3d_BT_RGBA;
5638 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
5640 aFormat = Image_PixMap::ImgRGBAF;
5641 aBufferType = Graphic3d_BT_RGBA;
5643 else if ( strcasecmp( aParam, "depth" ) == 0 )
5645 aFormat = Image_PixMap::ImgGrayF;
5646 aBufferType = Graphic3d_BT_Depth;
5648 else if ( strcasecmp( aParam, "name" ) == 0 )
5650 toShowName = Standard_True;
5654 Image_PixMap anImage;
5655 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
5657 std::cerr << "Image allocation failed\n";
5660 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
5662 std::cerr << "Image dump failed\n";
5666 Quantity_Parameter anAlpha;
5667 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
5670 if (aBufferType == Graphic3d_BT_RGBA)
5672 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha;
5676 theDI << Quantity_Color::StringName (aColor.Name());
5681 switch (aBufferType)
5684 case Graphic3d_BT_RGB:
5688 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation();
5692 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue();
5696 case Graphic3d_BT_RGBA:
5698 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha;
5701 case Graphic3d_BT_Depth:
5703 theDI << aColor.Red();
5712 //==============================================================================
5713 //function : VDiffImage
5714 //purpose : The draw-command compares two images.
5715 //==============================================================================
5717 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
5721 theDI << "Not enough arguments.\n";
5726 const char* anImgPathRef = theArgVec[1];
5727 const char* anImgPathNew = theArgVec[2];
5729 // get string tolerance and check its validity
5730 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
5731 if (aTolColor < 0.0)
5733 if (aTolColor > 1.0)
5736 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
5737 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
5739 // image file of difference
5740 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
5742 // compare the images
5743 Image_Diff aComparer;
5744 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
5749 aComparer.SetColorTolerance (aTolColor);
5750 aComparer.SetBorderFilterOn (isBorderFilterOn);
5751 Standard_Integer aDiffColorsNb = aComparer.Compare();
5752 theDI << aDiffColorsNb << "\n";
5754 // save image of difference
5755 if (aDiffColorsNb >0 && aDiffImagePath != NULL)
5757 aComparer.SaveDiffImage (aDiffImagePath);
5763 //=======================================================================
5764 //function : VSelect
5765 //purpose : Emulates different types of selection by mouse:
5766 // 1) single click selection
5767 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
5768 // 3) selection with polygon having corners at
5769 // pixel positions (x1,y1),...,(xn,yn)
5770 // 4) any of these selections with shift button pressed
5771 //=======================================================================
5772 static Standard_Integer VSelect (Draw_Interpretor& di,
5773 Standard_Integer argc,
5778 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
5782 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
5783 if(myAIScontext.IsNull())
5785 di << "use 'vinit' command before " << argv[0] << "\n";
5789 const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1));
5790 Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1;
5791 TCollection_AsciiString anArg;
5792 anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2];
5794 if (anArg == "-allowoverlap")
5796 Standard_Boolean isValidated = isShiftSelection ? argc == 8
5800 di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection";
5804 Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
5805 myAIScontext->MainSelector()->AllowOverlapDetection((Standard_Boolean)isToAllow);
5809 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
5810 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
5813 if(isShiftSelection)
5814 aCurrentEventManager->ShiftSelect();
5816 aCurrentEventManager->Select();
5818 else if(aCoordsNb == 4)
5820 if(isShiftSelection)
5821 aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
5823 aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
5827 TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2);
5829 for(Standard_Integer i=1;i<=aCoordsNb / 2;++i)
5830 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
5832 if(isShiftSelection)
5833 aCurrentEventManager->ShiftSelect(aPolyline);
5835 aCurrentEventManager->Select(aPolyline);
5840 //=======================================================================
5841 //function : VMoveTo
5842 //purpose : Emulates cursor movement to defined pixel position
5843 //=======================================================================
5844 static Standard_Integer VMoveTo (Draw_Interpretor& di,
5845 Standard_Integer argc,
5850 di << "Usage : " << argv[0] << " x y" << "\n";
5854 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5855 if(aContext.IsNull())
5857 di << "use 'vinit' command before " << argv[0] << "\n";
5860 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
5864 //=================================================================================================
5865 //function : VViewParams
5866 //purpose : Gets or sets AIS View characteristics
5867 //=================================================================================================
5868 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5870 Handle(V3d_View) anAISView = ViewerTest::CurrentView();
5871 if (anAISView.IsNull())
5873 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
5879 // print all of the available view parameters
5880 Quantity_Factor anAISViewScale = anAISView->Scale();
5882 Standard_Real anAISViewProjX = 0.0;
5883 Standard_Real anAISViewProjY = 0.0;
5884 Standard_Real anAISViewProjZ = 0.0;
5885 anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
5887 Standard_Real anAISViewUpX = 0.0;
5888 Standard_Real anAISViewUpY = 0.0;
5889 Standard_Real anAISViewUpZ = 0.0;
5890 anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
5892 Standard_Real anAISViewAtX = 0.0;
5893 Standard_Real anAISViewAtY = 0.0;
5894 Standard_Real anAISViewAtZ = 0.0;
5895 anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
5897 Standard_Real anAISViewEyeX = 0.0;
5898 Standard_Real anAISViewEyeY = 0.0;
5899 Standard_Real anAISViewEyeZ = 0.0;
5900 anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ);
5902 theDi << "Scale of current view: " << anAISViewScale << "\n";
5903 theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
5904 theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
5905 theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
5906 theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n";
5910 // -------------------------
5911 // Parse options and values
5912 // -------------------------
5914 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues;
5915 TCollection_AsciiString aParseKey;
5916 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5918 TCollection_AsciiString anArg (theArgVec [anArgIt]);
5920 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
5923 aParseKey.Remove (1);
5924 aParseKey.UpperCase();
5925 aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
5929 if (aParseKey.IsEmpty())
5931 std::cout << theArgVec[0] << ": values should be passed with key.\n";
5932 std::cout << "Type help for more information.\n";
5936 aMapOfKeysByValues(aParseKey)->Append (anArg);
5939 // ---------------------------------------------
5940 // Change or print parameters, order plays role
5941 // ---------------------------------------------
5943 // Check arguments for validity
5944 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues);
5945 for (; aMapIt.More(); aMapIt.Next())
5947 const TCollection_AsciiString& aKey = aMapIt.Key();
5948 const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value();
5950 if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5951 && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5952 && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty()))
5953 && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty()))
5954 && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty()))
5955 && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty()))
5956 && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2))
5958 TCollection_AsciiString aLowerKey;
5961 aLowerKey.LowerCase();
5962 std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n";
5963 std::cout << "Type help for more information.\n";
5968 Handle(TColStd_HSequenceOfAsciiString) aValues;
5970 // Change view parameters in proper order
5971 if (aMapOfKeysByValues.Find ("SCALE", aValues))
5973 if (aValues->IsEmpty())
5975 theDi << "Scale: " << anAISView->Scale() << "\n";
5979 anAISView->SetScale (aValues->Value(1).RealValue());
5982 if (aMapOfKeysByValues.Find ("SIZE", aValues))
5984 if (aValues->IsEmpty())
5986 Standard_Real aSizeX = 0.0;
5987 Standard_Real aSizeY = 0.0;
5988 anAISView->Size (aSizeX, aSizeY);
5989 theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n";
5993 anAISView->SetSize (aValues->Value(1).RealValue());
5996 if (aMapOfKeysByValues.Find ("EYE", aValues))
5998 if (aValues->IsEmpty())
6000 Standard_Real anEyeX = 0.0;
6001 Standard_Real anEyeY = 0.0;
6002 Standard_Real anEyeZ = 0.0;
6003 anAISView->Eye (anEyeX, anEyeY, anEyeZ);
6004 theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n";
6008 anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6011 if (aMapOfKeysByValues.Find ("AT", aValues))
6013 if (aValues->IsEmpty())
6015 Standard_Real anAtX = 0.0;
6016 Standard_Real anAtY = 0.0;
6017 Standard_Real anAtZ = 0.0;
6018 anAISView->At (anAtX, anAtY, anAtZ);
6019 theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n";
6023 anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6026 if (aMapOfKeysByValues.Find ("PROJ", aValues))
6028 if (aValues->IsEmpty())
6030 Standard_Real aProjX = 0.0;
6031 Standard_Real aProjY = 0.0;
6032 Standard_Real aProjZ = 0.0;
6033 anAISView->Proj (aProjX, aProjY, aProjZ);
6034 theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n";
6038 anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6041 if (aMapOfKeysByValues.Find ("UP", aValues))
6043 if (aValues->IsEmpty())
6045 Standard_Real anUpX = 0.0;
6046 Standard_Real anUpY = 0.0;
6047 Standard_Real anUpZ = 0.0;
6048 anAISView->Up (anUpX, anUpY, anUpZ);
6049 theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n";
6053 anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6056 if (aMapOfKeysByValues.Find ("CENTER", aValues))
6058 anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue());
6064 //=======================================================================
6065 //function : VChangeSelected
6066 //purpose : Adds the shape to selection or remove one from it
6067 //=======================================================================
6068 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
6069 Standard_Integer argc,
6074 di<<"Usage : " << argv[0] << " shape \n";
6078 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6079 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
6080 TCollection_AsciiString aName(argv[1]);
6081 Handle(AIS_InteractiveObject) anAISObject;
6083 if(!aMap.IsBound2(aName))
6085 di<<"Use 'vdisplay' before";
6090 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
6091 if(anAISObject.IsNull()){
6092 di<<"No interactive object \n";
6096 aContext->AddOrRemoveSelected(anAISObject);
6101 //=======================================================================
6102 //function : VZClipping
6103 //purpose : Gets or sets ZClipping mode, width and depth
6104 //=======================================================================
6105 static Standard_Integer VZClipping (Draw_Interpretor& di,
6106 Standard_Integer argc,
6111 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6112 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6115 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6116 if(aContext.IsNull())
6118 di << "use 'vinit' command before " << argv[0] << "\n";
6121 Handle(V3d_View) aView = ViewerTest::CurrentView();
6122 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
6125 TCollection_AsciiString aZClippingModeString;
6126 Quantity_Length aDepth, aWidth;
6127 aZClippingMode = aView->ZClipping(aDepth, aWidth);
6128 switch (aZClippingMode)
6131 aZClippingModeString.Copy("OFF");
6134 aZClippingModeString.Copy("BACK");
6137 aZClippingModeString.Copy("FRONT");
6140 aZClippingModeString.Copy("SLICE");
6143 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
6146 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
6147 << "ZClipping depth = " << aDepth << "\n"
6148 << "ZClipping width = " << aWidth << "\n";
6154 Standard_Integer aStatus = 0;
6155 if ( strcmp (argv [1], "OFF") == 0 ) {
6157 aZClippingMode = V3d_OFF;
6159 if ( strcmp (argv [1], "BACK") == 0 ) {
6161 aZClippingMode = V3d_BACK;
6163 if ( strcmp (argv [1], "FRONT") == 0 ) {
6165 aZClippingMode = V3d_FRONT;
6167 if ( strcmp (argv [1], "SLICE") == 0 ) {
6169 aZClippingMode = V3d_SLICE;
6173 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6174 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6177 aView->SetZClippingType(aZClippingMode);
6181 Quantity_Length aDepth = 0., aWidth = 1.;
6184 aDepth = Draw::Atof (argv[1]);
6185 aWidth = Draw::Atof (argv[2]);
6189 aDepth = Draw::Atof (argv[2]);
6190 aWidth = Draw::Atof (argv[3]);
6193 if(aDepth<0. || aDepth>1.)
6195 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6196 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6199 if(aWidth<0. || aWidth>1.)
6201 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6202 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6206 aView->SetZClippingDepth(aDepth);
6207 aView->SetZClippingWidth(aWidth);
6214 //=======================================================================
6215 //function : VNbSelected
6216 //purpose : Returns number of selected objects
6217 //=======================================================================
6218 static Standard_Integer VNbSelected (Draw_Interpretor& di,
6219 Standard_Integer argc,
6224 di << "Usage : " << argv[0] << "\n";
6227 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6228 if(aContext.IsNull())
6230 di << "use 'vinit' command before " << argv[0] << "\n";
6233 di << aContext->NbSelected() << "\n";
6237 //=======================================================================
6238 //function : VAntialiasing
6239 //purpose : Switches altialiasing on or off
6240 //=======================================================================
6241 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
6242 Standard_Integer argc,
6247 di << "Usage : " << argv[0] << " [1|0]" << "\n";
6251 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6252 if(aContext.IsNull())
6254 di << "use 'vinit' command before " << argv[0] << "\n";
6258 Handle(V3d_View) aView = ViewerTest::CurrentView();
6260 if((argc == 2) && (atof(argv[1]) == 0))
6261 aView->SetAntialiasingOff();
6263 aView->SetAntialiasingOn();
6268 //=======================================================================
6269 //function : VPurgeDisplay
6270 //purpose : Switches altialiasing on or off
6271 //=======================================================================
6272 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
6273 Standard_Integer argc,
6278 di << "Usage : " << argv[0] << "\n";
6281 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6282 if (aContext.IsNull())
6284 di << "use 'vinit' command before " << argv[0] << "\n";
6287 aContext->CloseAllContexts(Standard_False);
6288 di << aContext->PurgeDisplay() << "\n";
6292 //=======================================================================
6293 //function : VSetViewSize
6295 //=======================================================================
6296 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
6297 Standard_Integer argc,
6300 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6301 if(aContext.IsNull())
6303 di << "use 'vinit' command before " << argv[0] << "\n";
6308 di<<"Usage : " << argv[0] << " Size\n";
6311 Standard_Real aSize = Draw::Atof (argv[1]);
6314 di<<"Bad Size value : " << aSize << "\n";
6318 Handle(V3d_View) aView = ViewerTest::CurrentView();
6319 aView->SetSize(aSize);
6323 //=======================================================================
6324 //function : VMoveView
6326 //=======================================================================
6327 static Standard_Integer VMoveView (Draw_Interpretor& di,
6328 Standard_Integer argc,
6331 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6332 if(aContext.IsNull())
6334 di << "use 'vinit' command before " << argv[0] << "\n";
6337 if(argc < 4 || argc > 5)
6339 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
6342 Standard_Real Dx = Draw::Atof (argv[1]);
6343 Standard_Real Dy = Draw::Atof (argv[2]);
6344 Standard_Real Dz = Draw::Atof (argv[3]);
6345 Standard_Boolean aStart = Standard_True;
6348 aStart = (Draw::Atoi (argv[4]) > 0);
6351 Handle(V3d_View) aView = ViewerTest::CurrentView();
6352 aView->Move(Dx,Dy,Dz,aStart);
6356 //=======================================================================
6357 //function : VTranslateView
6359 //=======================================================================
6360 static Standard_Integer VTranslateView (Draw_Interpretor& di,
6361 Standard_Integer argc,
6364 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6365 if(aContext.IsNull())
6367 di << "use 'vinit' command before " << argv[0] << "\n";
6370 if(argc < 4 || argc > 5)
6372 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
6375 Standard_Real Dx = Draw::Atof (argv[1]);
6376 Standard_Real Dy = Draw::Atof (argv[2]);
6377 Standard_Real Dz = Draw::Atof (argv[3]);
6378 Standard_Boolean aStart = Standard_True;
6381 aStart = (Draw::Atoi (argv[4]) > 0);
6384 Handle(V3d_View) aView = ViewerTest::CurrentView();
6385 aView->Translate(Dx,Dy,Dz,aStart);
6389 //=======================================================================
6390 //function : VTurnView
6392 //=======================================================================
6393 static Standard_Integer VTurnView (Draw_Interpretor& di,
6394 Standard_Integer argc,
6397 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6398 if(aContext.IsNull()) {
6399 di << "use 'vinit' command before " << argv[0] << "\n";
6402 if(argc < 4 || argc > 5){
6403 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
6406 Standard_Real Ax = Draw::Atof (argv[1]);
6407 Standard_Real Ay = Draw::Atof (argv[2]);
6408 Standard_Real Az = Draw::Atof (argv[3]);
6409 Standard_Boolean aStart = Standard_True;
6412 aStart = (Draw::Atoi (argv[4]) > 0);
6415 Handle(V3d_View) aView = ViewerTest::CurrentView();
6416 aView->Turn(Ax,Ay,Az,aStart);
6420 //==============================================================================
6421 //function : VTextureEnv
6422 //purpose : ENables or disables environment mapping
6423 //==============================================================================
6424 class OCC_TextureEnv : public Graphic3d_TextureEnv
6427 OCC_TextureEnv(const Standard_CString FileName);
6428 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
6429 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
6430 const Standard_Boolean theModulateFlag,
6431 const Graphic3d_TypeOfTextureFilter theFilter,
6432 const Standard_ShortReal theXScale,
6433 const Standard_ShortReal theYScale,
6434 const Standard_ShortReal theXShift,
6435 const Standard_ShortReal theYShift,
6436 const Standard_ShortReal theAngle);
6437 DEFINE_STANDARD_RTTI(OCC_TextureEnv, Graphic3d_TextureEnv);
6439 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
6444 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
6445 : Graphic3d_TextureEnv(theFileName)
6449 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
6450 : Graphic3d_TextureEnv(theTexId)
6454 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
6455 const Standard_Boolean theModulateFlag,
6456 const Graphic3d_TypeOfTextureFilter theFilter,
6457 const Standard_ShortReal theXScale,
6458 const Standard_ShortReal theYScale,
6459 const Standard_ShortReal theXShift,
6460 const Standard_ShortReal theYShift,
6461 const Standard_ShortReal theAngle)
6463 myParams->SetRepeat (theRepeatFlag);
6464 myParams->SetModulate (theModulateFlag);
6465 myParams->SetFilter (theFilter);
6466 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
6467 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
6468 myParams->SetRotation (theAngle);
6471 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
6473 // get the active view
6474 Handle(V3d_View) aView = ViewerTest::CurrentView();
6477 std::cerr << "No active view. Please call vinit.\n";
6481 // Checking the input arguments
6482 Standard_Boolean anEnableFlag = Standard_False;
6483 Standard_Boolean isOk = theArgNb >= 2;
6486 TCollection_AsciiString anEnableOpt(theArgVec[1]);
6487 anEnableFlag = anEnableOpt.IsEqual("on");
6488 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
6492 isOk = (theArgNb == 3 || theArgNb == 11);
6495 TCollection_AsciiString aTextureOpt(theArgVec[2]);
6496 isOk = (!aTextureOpt.IsIntegerValue() ||
6497 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
6499 if (isOk && theArgNb == 11)
6501 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
6502 aModulateOpt(theArgVec[4]),
6503 aFilterOpt (theArgVec[5]),
6504 aSScaleOpt (theArgVec[6]),
6505 aTScaleOpt (theArgVec[7]),
6506 aSTransOpt (theArgVec[8]),
6507 aTTransOpt (theArgVec[9]),
6508 anAngleOpt (theArgVec[10]);
6509 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
6510 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
6511 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
6512 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
6513 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
6514 anAngleOpt.IsRealValue());
6521 std::cerr << "Usage :" << std::endl;
6522 std::cerr << theArgVec[0] << " off" << std::endl;
6523 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;
6529 TCollection_AsciiString aTextureOpt(theArgVec[2]);
6530 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
6531 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
6532 new OCC_TextureEnv(theArgVec[2]);
6536 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
6537 aTexEnv->SetTextureParameters(
6538 aRepeatOpt. IsEqual("repeat"),
6539 aModulateOpt.IsEqual("modulate"),
6540 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
6541 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
6542 Graphic3d_TOTF_TRILINEAR,
6543 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
6544 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
6545 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
6546 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
6547 (Standard_ShortReal)Draw::Atof(theArgVec[10])
6550 aView->SetTextureEnv(aTexEnv);
6551 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
6553 else // Disabling environment mapping
6555 aView->SetSurfaceDetail(V3d_TEX_NONE);
6556 Handle(Graphic3d_TextureEnv) aTexture;
6557 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
6564 //===============================================================================================
6565 //function : VClipPlane
6567 //===============================================================================================
6568 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6570 // use short-cut for created clip planes map of created (or "registered by name") clip planes
6571 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
6572 static MapOfPlanes aRegPlanes;
6576 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
6580 TCollection_AsciiString aCommand (theArgVec[1]);
6582 // print maximum number of planes for current viewer
6583 if (aCommand == "maxplanes")
6587 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
6591 TCollection_AsciiString aViewName (theArgVec[2]);
6593 if (!ViewerTest_myViews.IsBound1 (aViewName))
6595 theDi << theArgVec[0] << ": view is not found.\n";
6599 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
6601 theDi << theArgVec[0] << ": "
6602 << aView->Viewer()->Driver()->InquirePlaneLimit()
6603 << " plane slots provided by driver."
6604 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
6609 // create / delete plane instance
6610 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
6614 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
6618 Standard_Boolean toCreate = (aCommand == "create");
6619 Standard_Boolean toClone = (aCommand == "clone");
6620 TCollection_AsciiString aPlane (theArgVec[2]);
6624 if (aRegPlanes.IsBound (aPlane))
6626 theDi << theArgVec[0] << ": plane name is in use.\n";
6630 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
6632 else if (toClone) // toClone
6634 if (!aRegPlanes.IsBound (aPlane))
6636 theDi << theArgVec[0] << ": no such plane.\n";
6642 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
6646 TCollection_AsciiString aClone (theArgVec[3]);
6647 if (aRegPlanes.IsBound (aClone))
6649 theDi << theArgVec[0] << ": plane name is in use.\n";
6653 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6655 aRegPlanes.Bind (aClone, aClipPlane->Clone());
6659 if (!aRegPlanes.IsBound (aPlane))
6661 theDi << theArgVec[0] << ": no such plane.\n";
6665 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
6666 aRegPlanes.UnBind (aPlane);
6668 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
6669 for (; anIObjIt.More(); anIObjIt.Next())
6671 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
6672 aPrs->RemoveClipPlane(aClipPlane);
6675 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
6676 for (; aViewIt.More(); aViewIt.Next())
6678 const Handle(V3d_View)& aView = aViewIt.Key2();
6679 aView->RemoveClipPlane(aClipPlane);
6682 ViewerTest::RedrawAllViews();
6688 // set / unset plane command
6689 if (aCommand == "set" || aCommand == "unset")
6693 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6697 Standard_Boolean toSet = (aCommand == "set");
6698 TCollection_AsciiString aPlane (theArgVec [2]);
6699 if (!aRegPlanes.IsBound (aPlane))
6701 theDi << theArgVec[0] << ": no such plane.\n";
6705 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6707 TCollection_AsciiString aTarget (theArgVec [3]);
6708 if (aTarget != "object" && aTarget != "view")
6710 theDi << theArgVec[0] << ": invalid target.\n";
6714 if (aTarget == "object" || aTarget == "view")
6718 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6722 Standard_Boolean isObject = (aTarget == "object");
6724 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
6726 TCollection_AsciiString anEntityName (theArgVec[anIt]);
6727 if (isObject) // to object
6729 if (!GetMapOfAIS().IsBound2 (anEntityName))
6731 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
6735 Handle(AIS_InteractiveObject) aIObj =
6736 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
6739 aIObj->AddClipPlane (aClipPlane);
6741 aIObj->RemoveClipPlane (aClipPlane);
6745 if (!ViewerTest_myViews.IsBound1 (anEntityName))
6747 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
6751 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
6753 aView->AddClipPlane (aClipPlane);
6755 aView->RemoveClipPlane (aClipPlane);
6759 ViewerTest::RedrawAllViews();
6765 // change plane command
6766 if (aCommand == "change")
6770 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6774 TCollection_AsciiString aPlane (theArgVec [2]);
6775 if (!aRegPlanes.IsBound (aPlane))
6777 theDi << theArgVec[0] << ": no such plane.\n";
6781 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6783 TCollection_AsciiString aChangeArg (theArgVec [3]);
6784 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
6786 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
6790 if (aChangeArg == "on" || aChangeArg == "off") // on / off
6792 aClipPlane->SetOn (aChangeArg == "on");
6794 else if (aChangeArg == "equation") // change equation
6798 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6802 Standard_Real aCoeffA = Draw::Atof (theArgVec [4]);
6803 Standard_Real aCoeffB = Draw::Atof (theArgVec [5]);
6804 Standard_Real aCoeffC = Draw::Atof (theArgVec [6]);
6805 Standard_Real aCoeffD = Draw::Atof (theArgVec [7]);
6806 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
6808 else if (aChangeArg == "capping") // change capping aspects
6812 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6816 TCollection_AsciiString aCappingArg (theArgVec [4]);
6817 if (aCappingArg != "on" && aCappingArg != "off" &&
6818 aCappingArg != "color" && aCappingArg != "texname" &&
6819 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
6820 aCappingArg != "texrotate" && aCappingArg != "hatch")
6822 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
6826 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
6828 aClipPlane->SetCapping (aCappingArg == "on");
6830 else if (aCappingArg == "color") // color aspect for capping
6834 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6838 Standard_Real aRed = Draw::Atof (theArgVec [5]);
6839 Standard_Real aGrn = Draw::Atof (theArgVec [6]);
6840 Standard_Real aBlu = Draw::Atof (theArgVec [7]);
6842 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
6843 Quantity_Color aColor (aRed, aGrn, aBlu, Quantity_TOC_RGB);
6844 aMat.SetAmbientColor (aColor);
6845 aMat.SetDiffuseColor (aColor);
6846 aClipPlane->SetCappingMaterial (aMat);
6848 else if (aCappingArg == "texname") // texture name
6852 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6856 TCollection_AsciiString aTextureName (theArgVec [5]);
6858 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
6859 if (!aTexture->IsDone ())
6861 aClipPlane->SetCappingTexture (NULL);
6865 aTexture->EnableModulate();
6866 aTexture->EnableRepeat();
6867 aClipPlane->SetCappingTexture (aTexture);
6870 else if (aCappingArg == "texscale") // texture scale
6872 if (aClipPlane->CappingTexture().IsNull())
6874 theDi << theArgVec[0] << ": no texture is set.\n";
6880 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6884 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
6885 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
6887 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
6889 else if (aCappingArg == "texorigin") // texture origin
6891 if (aClipPlane->CappingTexture().IsNull())
6893 theDi << theArgVec[0] << ": no texture is set.\n";
6899 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6903 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
6904 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
6906 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
6908 else if (aCappingArg == "texrotate") // texture rotation
6910 if (aClipPlane->CappingTexture().IsNull())
6912 theDi << theArgVec[0] << ": no texture is set.\n";
6918 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6922 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
6924 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
6926 else if (aCappingArg == "hatch") // hatch style
6930 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6934 TCollection_AsciiString aHatchStr (theArgVec [5]);
6935 if (aHatchStr == "on")
6937 aClipPlane->SetCappingHatchOn();
6939 else if (aHatchStr == "off")
6941 aClipPlane->SetCappingHatchOff();
6945 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
6950 ViewerTest::RedrawAllViews();
6955 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
6959 //===============================================================================================
6960 //function : VSetTextureMode
6962 //===============================================================================================
6963 static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6967 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
6971 TCollection_AsciiString aViewName (theArgVec[1]);
6972 if (!ViewerTest_myViews.IsBound1 (aViewName))
6974 theDi << theArgVec[0] << ": view is not found.\n";
6978 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
6979 switch (atoi (theArgVec[2]))
6981 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
6982 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
6983 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
6985 theDi << theArgVec[0] << ": invalid mode.\n";
6993 //===============================================================================================
6994 //function : VZRange
6996 //===============================================================================================
6997 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6999 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
7001 if (aCurrentView.IsNull())
7003 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
7007 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
7011 theDi << "ZNear: " << aCamera->ZNear() << "\n";
7012 theDi << "ZFar: " << aCamera->ZFar() << "\n";
7018 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
7019 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
7021 if (aNewZNear >= aNewZFar)
7023 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
7027 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
7029 std::cout << theArgVec[0] << ": invalid arguments: ";
7030 std::cout << "znear, zfar should be positive for perspective camera.\n";
7034 aCamera->SetZRange (aNewZNear, aNewZFar);
7038 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
7042 aCurrentView->Redraw();
7047 //===============================================================================================
7048 //function : VAutoZFit
7050 //===============================================================================================
7051 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7053 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
7055 if (aCurrentView.IsNull())
7057 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
7061 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
7065 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
7071 theDi << "Auto z-fit mode: " << "\n"
7072 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
7073 << "Scale: " << aScale << "\n";
7077 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
7081 aScale = Draw::Atoi (theArgVec[2]);
7084 aCurrentView->SetAutoZFitMode (isOn, aScale);
7085 aCurrentView->AutoZFit();
7086 aCurrentView->Redraw();
7091 //! Auxiliary function to print projection type
7092 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
7094 switch (theProjType)
7096 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
7097 case Graphic3d_Camera::Projection_Perspective: return "perspective";
7098 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
7099 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
7100 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
7105 //===============================================================================================
7106 //function : VCamera
7108 //===============================================================================================
7109 static int VCamera (Draw_Interpretor& theDI,
7110 Standard_Integer theArgsNb,
7111 const char** theArgVec)
7113 Handle(V3d_View) aView = ViewerTest::CurrentView();
7116 std::cout << "Error: no active view.\n";
7120 Handle(Graphic3d_Camera) aCamera = aView->Camera();
7123 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
7124 theDI << "FOVy: " << aCamera->FOVy() << "\n";
7125 theDI << "Distance: " << aCamera->Distance() << "\n";
7126 theDI << "IOD: " << aCamera->IOD() << "\n";
7127 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
7128 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
7129 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
7133 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7135 Standard_CString anArg = theArgVec[anArgIter];
7136 TCollection_AsciiString anArgCase (anArg);
7137 anArgCase.LowerCase();
7138 if (anArgCase == "-proj"
7139 || anArgCase == "-projection"
7140 || anArgCase == "-projtype"
7141 || anArgCase == "-projectiontype")
7143 theDI << projTypeName (aCamera->ProjectionType()) << " ";
7145 else if (anArgCase == "-ortho"
7146 || anArgCase == "-orthographic")
7148 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
7150 else if (anArgCase == "-persp"
7151 || anArgCase == "-perspective"
7152 || anArgCase == "-perspmono"
7153 || anArgCase == "-perspectivemono"
7154 || anArgCase == "-mono")
7156 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
7158 else if (anArgCase == "-stereo"
7159 || anArgCase == "-stereoscopic"
7160 || anArgCase == "-perspstereo"
7161 || anArgCase == "-perspectivestereo")
7163 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7165 else if (anArgCase == "-left"
7166 || anArgCase == "-lefteye"
7167 || anArgCase == "-monoleft"
7168 || anArgCase == "-monolefteye"
7169 || anArgCase == "-perpsleft"
7170 || anArgCase == "-perpslefteye")
7172 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
7174 else if (anArgCase == "-right"
7175 || anArgCase == "-righteye"
7176 || anArgCase == "-monoright"
7177 || anArgCase == "-monorighteye"
7178 || anArgCase == "-perpsright")
7180 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
7182 else if (anArgCase == "-dist"
7183 || anArgCase == "-distance")
7185 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7186 if (anArgValue != NULL
7187 && *anArgValue != '-')
7190 aCamera->SetDistance (Draw::Atof (anArgValue));
7193 theDI << aCamera->Distance() << " ";
7195 else if (anArgCase == "-iod")
7197 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7198 if (anArgValue != NULL
7199 && *anArgValue != '-')
7202 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
7205 theDI << aCamera->IOD() << " ";
7207 else if (anArgCase == "-iodtype")
7209 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
7210 TCollection_AsciiString anValueCase (anArgValue);
7211 anValueCase.LowerCase();
7212 if (anValueCase == "abs"
7213 || anValueCase == "absolute")
7216 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
7219 else if (anValueCase == "rel"
7220 || anValueCase == "relative")
7223 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
7226 else if (*anArgValue != '-')
7228 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
7231 switch (aCamera->GetIODType())
7233 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
7234 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
7237 else if (anArgCase == "-zfocus")
7239 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7240 if (anArgValue != NULL
7241 && *anArgValue != '-')
7244 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
7247 theDI << aCamera->ZFocus() << " ";
7249 else if (anArgCase == "-zfocustype")
7251 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
7252 TCollection_AsciiString anValueCase (anArgValue);
7253 anValueCase.LowerCase();
7254 if (anValueCase == "abs"
7255 || anValueCase == "absolute")
7258 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
7261 else if (anValueCase == "rel"
7262 || anValueCase == "relative")
7265 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
7268 else if (*anArgValue != '-')
7270 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
7273 switch (aCamera->ZFocusType())
7275 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
7276 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
7279 else if (anArgCase == "-fov"
7280 || anArgCase == "-fovy")
7282 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7283 if (anArgValue != NULL
7284 && *anArgValue != '-')
7287 aCamera->SetFOVy (Draw::Atof (anArgValue));
7290 theDI << aCamera->FOVy() << " ";
7294 std::cout << "Error: unknown argument '" << anArg << "'\n";
7305 //! Parse stereo output mode
7306 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
7307 Graphic3d_StereoMode& theMode)
7309 TCollection_AsciiString aFlag (theArg);
7311 if (aFlag == "quadbuffer")
7313 theMode = Graphic3d_StereoMode_QuadBuffer;
7315 else if (aFlag == "anaglyph")
7317 theMode = Graphic3d_StereoMode_Anaglyph;
7319 else if (aFlag == "row"
7320 || aFlag == "rowinterlaced")
7322 theMode = Graphic3d_StereoMode_RowInterlaced;
7324 else if (aFlag == "col"
7325 || aFlag == "colinterlaced"
7326 || aFlag == "columninterlaced")
7328 theMode = Graphic3d_StereoMode_ColumnInterlaced;
7330 else if (aFlag == "chess"
7331 || aFlag == "chessboard")
7333 theMode = Graphic3d_StereoMode_ChessBoard;
7335 else if (aFlag == "sbs"
7336 || aFlag == "sidebyside")
7338 theMode = Graphic3d_StereoMode_SideBySide;
7340 else if (aFlag == "ou"
7341 || aFlag == "overunder")
7343 theMode = Graphic3d_StereoMode_OverUnder;
7345 else if (aFlag == "pageflip"
7346 || aFlag == "softpageflip")
7348 theMode = Graphic3d_StereoMode_SoftPageFlip;
7352 return Standard_False;
7354 return Standard_True;
7357 //! Parse anaglyph filter
7358 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
7359 Graphic3d_RenderingParams::Anaglyph& theFilter)
7361 TCollection_AsciiString aFlag (theArg);
7363 if (aFlag == "redcyansimple")
7365 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
7367 else if (aFlag == "redcyan"
7368 || aFlag == "redcyanoptimized")
7370 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
7372 else if (aFlag == "yellowbluesimple")
7374 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
7376 else if (aFlag == "yellowblue"
7377 || aFlag == "yellowblueoptimized")
7379 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
7381 else if (aFlag == "greenmagenta"
7382 || aFlag == "greenmagentasimple")
7384 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
7388 return Standard_False;
7390 return Standard_True;
7393 //==============================================================================
7394 //function : VStereo
7396 //==============================================================================
7398 static int VStereo (Draw_Interpretor& theDI,
7399 Standard_Integer theArgNb,
7400 const char** theArgVec)
7402 Handle(V3d_View) aView = ViewerTest::CurrentView();
7407 std::cout << "Error: no active viewer!\n";
7411 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
7412 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
7415 TCollection_AsciiString aMode;
7416 switch (aView->RenderingParams().StereoMode)
7418 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
7419 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
7420 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
7421 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
7422 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
7423 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
7424 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
7425 case Graphic3d_StereoMode_Anaglyph :
7427 switch (aView->RenderingParams().AnaglyphFilter)
7429 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
7430 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
7431 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
7432 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
7433 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
7438 theDI << "Mode " << aMode << "\n";
7443 Handle(Graphic3d_Camera) aCamera;
7444 Graphic3d_RenderingParams* aParams = NULL;
7445 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
7446 if (!aView.IsNull())
7448 aParams = &aView->ChangeRenderingParams();
7449 aMode = aParams->StereoMode;
7450 aCamera = aView->Camera();
7453 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7454 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7456 Standard_CString anArg = theArgVec[anArgIter];
7457 TCollection_AsciiString aFlag (anArg);
7459 if (anUpdateTool.parseRedrawMode (aFlag))
7463 else if (aFlag == "0"
7466 if (++anArgIter < theArgNb)
7468 std::cout << "Error: wrong number of arguments!\n";
7472 if (!aCamera.IsNull()
7473 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
7475 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
7477 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
7480 else if (aFlag == "1"
7483 if (++anArgIter < theArgNb)
7485 std::cout << "Error: wrong number of arguments!\n";
7489 if (!aCamera.IsNull())
7491 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7493 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
7496 else if (aFlag == "-reverse"
7497 || aFlag == "-reversed"
7498 || aFlag == "-swap")
7500 Standard_Boolean toEnable = Standard_True;
7501 if (++anArgIter < theArgNb
7502 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
7506 aParams->ToReverseStereo = toEnable;
7508 else if (aFlag == "-noreverse"
7509 || aFlag == "-noswap")
7511 Standard_Boolean toDisable = Standard_True;
7512 if (++anArgIter < theArgNb
7513 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
7517 aParams->ToReverseStereo = !toDisable;
7519 else if (aFlag == "-mode"
7520 || aFlag == "-stereomode")
7522 if (++anArgIter >= theArgNb
7523 || !parseStereoMode (theArgVec[anArgIter], aMode))
7525 std::cout << "Error: syntax error at '" << anArg << "'\n";
7529 if (aMode == Graphic3d_StereoMode_QuadBuffer)
7531 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
7534 else if (aFlag == "-anaglyph"
7535 || aFlag == "-anaglyphfilter")
7537 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
7538 if (++anArgIter >= theArgNb
7539 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
7541 std::cout << "Error: syntax error at '" << anArg << "'\n";
7545 aMode = Graphic3d_StereoMode_Anaglyph;
7546 aParams->AnaglyphFilter = aFilter;
7548 else if (parseStereoMode (anArg, aMode)) // short syntax
7550 if (aMode == Graphic3d_StereoMode_QuadBuffer)
7552 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
7557 std::cout << "Error: syntax error at '" << anArg << "'\n";
7562 if (!aView.IsNull())
7564 aParams->StereoMode = aMode;
7565 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7570 //===============================================================================================
7571 //function : VDefaults
7573 //===============================================================================================
7574 static int VDefaults (Draw_Interpretor& theDi,
7575 Standard_Integer theArgsNb,
7576 const char** theArgVec)
7578 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
7581 std::cerr << "No active viewer!\n";
7585 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
7588 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
7590 theDi << "DeflType: relative\n"
7591 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
7595 theDi << "DeflType: absolute\n"
7596 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
7598 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
7599 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
7603 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7605 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7607 if (anArg == "-ABSDEFL"
7608 || anArg == "-ABSOLUTEDEFLECTION"
7610 || anArg == "-DEFLECTION")
7612 if (++anArgIter >= theArgsNb)
7614 std::cout << "Error: wrong syntax at " << anArg << "\n";
7617 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
7618 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
7620 else if (anArg == "-RELDEFL"
7621 || anArg == "-RELATIVEDEFLECTION"
7622 || anArg == "-DEVCOEFF"
7623 || anArg == "-DEVIATIONCOEFF"
7624 || anArg == "-DEVIATIONCOEFFICIENT")
7626 if (++anArgIter >= theArgsNb)
7628 std::cout << "Error: wrong syntax at " << anArg << "\n";
7631 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
7632 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
7634 else if (anArg == "-ANGDEFL"
7635 || anArg == "-ANGULARDEFL"
7636 || anArg == "-ANGULARDEFLECTION")
7638 if (++anArgIter >= theArgsNb)
7640 std::cout << "Error: wrong syntax at " << anArg << "\n";
7643 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
7644 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
7646 else if (anArg == "-AUTOTR"
7647 || anArg == "-AUTOTRIANG"
7648 || anArg == "-AUTOTRIANGULATION")
7650 if (++anArgIter >= theArgsNb)
7652 std::cout << "Error: wrong syntax at " << anArg << "\n";
7655 TCollection_AsciiString aValue (theArgVec[anArgIter]);
7660 aDefParams->SetAutoTriangulation (Standard_True);
7662 else if (aValue == "off"
7665 aDefParams->SetAutoTriangulation (Standard_False);
7670 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
7677 //! Auxiliary method
7678 inline void addLight (const Handle(V3d_Light)& theLightNew,
7679 const Standard_Boolean theIsGlobal)
7681 if (theLightNew.IsNull())
7688 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
7692 ViewerTest::CurrentView()->SetLightOn (theLightNew);
7696 //! Auxiliary method
7697 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
7699 TCollection_AsciiString anArgNextCase (theArgNext);
7700 anArgNextCase.UpperCase();
7701 if (anArgNextCase.Length() > 5
7702 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
7704 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
7708 return theArgNext.IntegerValue();
7712 //===============================================================================================
7715 //===============================================================================================
7716 static int VLight (Draw_Interpretor& theDi,
7717 Standard_Integer theArgsNb,
7718 const char** theArgVec)
7720 Handle(V3d_View) aView = ViewerTest::CurrentView();
7721 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
7723 || aViewer.IsNull())
7725 std::cerr << "No active viewer!\n";
7729 Standard_Real anXYZ[3];
7730 Quantity_Coefficient anAtten[2];
7733 // print lights info
7734 Standard_Integer aLightId = 0;
7735 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId)
7737 Handle(V3d_Light) aLight = aView->ActiveLight();
7738 const Quantity_Color aColor = aLight->Color();
7739 theDi << "Light" << aLightId << "\n";
7740 switch (aLight->Type())
7744 theDi << " Type: Ambient\n";
7745 theDi << " Intensity: " << aLight->Intensity() << "\n";
7748 case V3d_DIRECTIONAL:
7750 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
7751 theDi << " Type: Directional\n";
7752 theDi << " Intensity: " << aLight->Intensity() << "\n";
7753 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7754 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
7755 if (!aLightDir.IsNull())
7757 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7758 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7759 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
7760 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7764 case V3d_POSITIONAL:
7766 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
7767 theDi << " Type: Positional\n";
7768 theDi << " Intensity: " << aLight->Intensity() << "\n";
7769 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7770 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
7771 if (!aLightPos.IsNull())
7773 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7774 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7775 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7776 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
7782 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
7783 theDi << " Type: Spot\n";
7784 theDi << " Intensity: " << aLight->Intensity() << "\n";
7785 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7786 if (!aLightSpot.IsNull())
7788 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7789 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7790 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
7791 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7792 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7793 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
7794 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
7795 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
7801 theDi << " Type: UNKNOWN\n";
7805 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
7809 Handle(V3d_Light) aLightNew;
7810 Handle(V3d_Light) aLightOld;
7811 Standard_Boolean isGlobal = Standard_True;
7812 Standard_Boolean toCreate = Standard_False;
7813 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
7815 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
7816 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
7817 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
7818 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
7819 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
7821 TCollection_AsciiString aName, aValue;
7822 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
7823 TCollection_AsciiString anArgCase (anArg);
7824 anArgCase.UpperCase();
7825 if (anArgCase.IsEqual ("NEW")
7826 || anArgCase.IsEqual ("ADD")
7827 || anArgCase.IsEqual ("CREATE"))
7829 toCreate = Standard_True;
7831 else if (anArgCase.IsEqual ("GLOB")
7832 || anArgCase.IsEqual ("GLOBAL"))
7834 isGlobal = Standard_True;
7836 else if (anArgCase.IsEqual ("LOC")
7837 || anArgCase.IsEqual ("LOCAL"))
7839 isGlobal = Standard_False;
7841 else if (anArgCase.IsEqual ("DEF")
7842 || anArgCase.IsEqual ("DEFAULTS"))
7844 toCreate = Standard_False;
7845 aViewer->SetDefaultLights();
7847 else if (anArgCase.IsEqual ("CLR")
7848 || anArgCase.IsEqual ("CLEAR"))
7850 toCreate = Standard_False;
7851 aView->InitActiveLights();
7852 while (aView->MoreActiveLights())
7854 aViewer->DelLight (aView->ActiveLight());
7855 aView->InitActiveLights();
7858 else if (anArgCase.IsEqual ("AMB")
7859 || anArgCase.IsEqual ("AMBIENT")
7860 || anArgCase.IsEqual ("AMBLIGHT"))
7862 addLight (aLightNew, isGlobal);
7865 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7868 toCreate = Standard_False;
7869 aLightNew = new V3d_AmbientLight (aViewer);
7871 else if (anArgCase.IsEqual ("DIRECTIONAL")
7872 || anArgCase.IsEqual ("DIRLIGHT"))
7874 addLight (aLightNew, isGlobal);
7877 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7880 toCreate = Standard_False;
7881 aLightNew = new V3d_DirectionalLight (aViewer);
7883 else if (anArgCase.IsEqual ("SPOT")
7884 || anArgCase.IsEqual ("SPOTLIGHT"))
7886 addLight (aLightNew, isGlobal);
7889 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7892 toCreate = Standard_False;
7893 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
7895 else if (anArgCase.IsEqual ("POSLIGHT")
7896 || anArgCase.IsEqual ("POSITIONAL"))
7898 addLight (aLightNew, isGlobal);
7901 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7904 toCreate = Standard_False;
7905 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
7907 else if (anArgCase.IsEqual ("CHANGE"))
7909 addLight (aLightNew, isGlobal);
7910 aLightNew.Nullify();
7911 if (++anArgIt >= theArgsNb)
7913 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7917 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
7918 Standard_Integer aLightIt = 0;
7919 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
7921 if (aLightIt == aLightId)
7923 aLightOld = aView->ActiveLight();
7928 if (aLightOld.IsNull())
7930 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
7934 else if (anArgCase.IsEqual ("DEL")
7935 || anArgCase.IsEqual ("DELETE"))
7937 Handle(V3d_Light) aLightDel;
7938 if (++anArgIt >= theArgsNb)
7940 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7944 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
7945 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
7946 Standard_Integer aLightIt = 0;
7947 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
7949 aLightDel = aView->ActiveLight();
7950 if (aLightIt == aLightDelId)
7955 if (!aLightDel.IsNull())
7957 aViewer->DelLight (aLightDel);
7960 else if (anArgCase.IsEqual ("COLOR")
7961 || anArgCase.IsEqual ("COLOUR"))
7963 if (++anArgIt >= theArgsNb)
7965 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7969 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
7970 anArgNext.UpperCase();
7971 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
7972 if (!aLightCurr.IsNull())
7974 aLightCurr->SetColor (aColor);
7977 else if (anArgCase.IsEqual ("POS")
7978 || anArgCase.IsEqual ("POSITION"))
7980 if ((anArgIt + 3) >= theArgsNb)
7982 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7986 anXYZ[0] = Atof (theArgVec[++anArgIt]);
7987 anXYZ[1] = Atof (theArgVec[++anArgIt]);
7988 anXYZ[2] = Atof (theArgVec[++anArgIt]);
7989 if (!aLightDir.IsNull())
7991 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7993 else if (!aLightPos.IsNull())
7995 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7997 else if (!aLightSpot.IsNull())
7999 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
8003 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8007 else if (anArgCase.IsEqual ("DIR")
8008 || anArgCase.IsEqual ("DIRECTION"))
8010 if ((anArgIt + 3) >= theArgsNb)
8012 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8016 anXYZ[0] = Atof (theArgVec[++anArgIt]);
8017 anXYZ[1] = Atof (theArgVec[++anArgIt]);
8018 anXYZ[2] = Atof (theArgVec[++anArgIt]);
8019 if (!aLightDir.IsNull())
8021 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
8023 else if (!aLightSpot.IsNull())
8025 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
8029 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8033 else if (anArgCase.IsEqual ("SM")
8034 || anArgCase.IsEqual ("SMOOTHNESS"))
8036 if (++anArgIt >= theArgsNb)
8038 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8042 Standard_Real aSmoothness = Atof (theArgVec[anArgIt]);
8044 if (fabs (aSmoothness) < Precision::Confusion())
8046 aLightCurr->SetIntensity (1.f);
8048 else if (fabs (aLightCurr->Smoothness()) < Precision::Confusion())
8050 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
8054 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
8055 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
8058 if (!aLightPos.IsNull())
8060 aLightPos->SetSmoothRadius (aSmoothness);
8062 else if (!aLightDir.IsNull())
8064 aLightDir->SetSmoothAngle (aSmoothness);
8067 else if (anArgCase.IsEqual ("INT")
8068 || anArgCase.IsEqual ("INTENSITY"))
8070 if (++anArgIt >= theArgsNb)
8072 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8076 Standard_Real aIntensity = Atof (theArgVec[anArgIt]);
8078 if (!aLightCurr.IsNull())
8080 aLightCurr->SetIntensity (aIntensity);
8083 else if (anArgCase.IsEqual ("ANG")
8084 || anArgCase.IsEqual ("ANGLE"))
8086 if (++anArgIt >= theArgsNb)
8088 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8092 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
8094 if (!aLightSpot.IsNull())
8096 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
8099 else if (anArgCase.IsEqual ("CONSTATTEN")
8100 || anArgCase.IsEqual ("CONSTATTENUATION"))
8102 if (++anArgIt >= theArgsNb)
8104 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8108 if (!aLightPos.IsNull())
8110 aLightPos->Attenuation (anAtten[0], anAtten[1]);
8111 anAtten[0] = Atof (theArgVec[anArgIt]);
8112 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
8114 else if (!aLightSpot.IsNull())
8116 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
8117 anAtten[0] = Atof (theArgVec[anArgIt]);
8118 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
8122 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8126 else if (anArgCase.IsEqual ("LINATTEN")
8127 || anArgCase.IsEqual ("LINEARATTEN")
8128 || anArgCase.IsEqual ("LINEARATTENUATION"))
8130 if (++anArgIt >= theArgsNb)
8132 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8136 if (!aLightPos.IsNull())
8138 aLightPos->Attenuation (anAtten[0], anAtten[1]);
8139 anAtten[1] = Atof (theArgVec[anArgIt]);
8140 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
8142 else if (!aLightSpot.IsNull())
8144 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
8145 anAtten[1] = Atof (theArgVec[anArgIt]);
8146 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
8150 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8154 else if (anArgCase.IsEqual ("EXP")
8155 || anArgCase.IsEqual ("EXPONENT")
8156 || anArgCase.IsEqual ("SPOTEXP")
8157 || anArgCase.IsEqual ("SPOTEXPONENT"))
8159 if (++anArgIt >= theArgsNb)
8161 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8165 if (!aLightSpot.IsNull())
8167 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
8171 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8175 else if (anArgCase.IsEqual ("HEAD")
8176 || anArgCase.IsEqual ("HEADLIGHT"))
8178 if (++anArgIt >= theArgsNb)
8180 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8184 if (aLightAmb.IsNull()
8185 && !aLightCurr.IsNull())
8187 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
8191 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8197 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
8201 addLight (aLightNew, isGlobal);
8202 aViewer->UpdateLights();
8207 //=======================================================================
8208 //function : VRenderParams
8209 //purpose : Enables/disables rendering features
8210 //=======================================================================
8212 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
8213 Standard_Integer theArgNb,
8214 const char** theArgVec)
8216 Handle(V3d_View) aView = ViewerTest::CurrentView();
8219 std::cerr << "Error: no active viewer!\n";
8223 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
8224 TCollection_AsciiString aCmdName (theArgVec[0]);
8225 aCmdName.LowerCase();
8226 if (aCmdName == "vraytrace")
8230 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
8233 else if (theArgNb == 2)
8235 TCollection_AsciiString aValue (theArgVec[1]);
8240 aParams.Method = Graphic3d_RM_RAYTRACING;
8244 else if (aValue == "off"
8247 aParams.Method = Graphic3d_RM_RASTERIZATION;
8253 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
8259 std::cout << "Error: wrong number of arguments\n";
8266 theDI << "renderMode: ";
8267 switch (aParams.Method)
8269 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
8270 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
8273 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
8274 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
8275 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
8276 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
8277 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
8278 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
8279 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
8280 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
8281 theDI << "shadingModel: ";
8282 switch (aView->ShadingModel())
8284 case V3d_COLOR: theDI << "color"; break;
8285 case V3d_FLAT: theDI << "flat"; break;
8286 case V3d_GOURAUD: theDI << "gouraud"; break;
8287 case V3d_PHONG: theDI << "phong"; break;
8293 Standard_Boolean toPrint = Standard_False;
8294 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
8295 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
8297 Standard_CString anArg (theArgVec[anArgIter]);
8298 TCollection_AsciiString aFlag (anArg);
8300 if (anUpdateTool.parseRedrawMode (aFlag))
8304 else if (aFlag == "-echo"
8305 || aFlag == "-print")
8307 toPrint = Standard_True;
8308 anUpdateTool.Invalidate();
8310 else if (aFlag == "-mode"
8311 || aFlag == "-rendermode"
8312 || aFlag == "-render_mode")
8316 switch (aParams.Method)
8318 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
8319 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
8325 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8329 else if (aFlag == "-ray"
8330 || aFlag == "-raytrace")
8334 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
8338 aParams.Method = Graphic3d_RM_RAYTRACING;
8340 else if (aFlag == "-rast"
8341 || aFlag == "-raster"
8342 || aFlag == "-rasterization")
8346 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
8350 aParams.Method = Graphic3d_RM_RASTERIZATION;
8352 else if (aFlag == "-msaa")
8356 theDI << aParams.NbMsaaSamples << " ";
8359 else if (++anArgIter >= theArgNb)
8361 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8365 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
8368 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
8373 aParams.NbMsaaSamples = aNbSamples;
8376 else if (aFlag == "-raydepth"
8377 || aFlag == "-ray_depth")
8381 theDI << aParams.RaytracingDepth << " ";
8384 else if (++anArgIter >= theArgNb)
8386 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8390 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
8392 // We allow RaytracingDepth be more than 10 in case of GI enabled
8393 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
8395 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
8400 aParams.RaytracingDepth = aDepth;
8403 else if (aFlag == "-shad"
8404 || aFlag == "-shadows")
8408 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
8412 Standard_Boolean toEnable = Standard_True;
8413 if (++anArgIter < theArgNb
8414 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8418 aParams.IsShadowEnabled = toEnable;
8420 else if (aFlag == "-refl"
8421 || aFlag == "-reflections")
8425 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
8429 Standard_Boolean toEnable = Standard_True;
8430 if (++anArgIter < theArgNb
8431 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8435 aParams.IsReflectionEnabled = toEnable;
8437 else if (aFlag == "-fsaa")
8441 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
8445 Standard_Boolean toEnable = Standard_True;
8446 if (++anArgIter < theArgNb
8447 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8451 aParams.IsAntialiasingEnabled = toEnable;
8453 else if (aFlag == "-gleam")
8457 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
8461 Standard_Boolean toEnable = Standard_True;
8462 if (++anArgIter < theArgNb
8463 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8467 aParams.IsTransparentShadowEnabled = toEnable;
8469 else if (aFlag == "-gi")
8473 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
8477 Standard_Boolean toEnable = Standard_True;
8478 if (++anArgIter < theArgNb
8479 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8483 aParams.IsGlobalIlluminationEnabled = toEnable;
8486 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
8489 else if (aFlag == "-blockedrng"
8490 || aFlag == "-brng")
8494 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
8498 Standard_Boolean toEnable = Standard_True;
8499 if (++anArgIter < theArgNb
8500 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8504 aParams.CoherentPathTracingMode = toEnable;
8506 else if (aFlag == "-env")
8510 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
8514 Standard_Boolean toEnable = Standard_True;
8515 if (++anArgIter < theArgNb
8516 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8520 aParams.UseEnvironmentMapBackground = toEnable;
8522 else if (aFlag == "-shademodel"
8523 || aFlag == "-shadingmodel"
8524 || aFlag == "-shading")
8528 switch (aView->ShadingModel())
8530 case V3d_COLOR: theDI << "color "; break;
8531 case V3d_FLAT: theDI << "flat "; break;
8532 case V3d_GOURAUD: theDI << "gouraud "; break;
8533 case V3d_PHONG: theDI << "phong "; break;
8538 if (++anArgIter >= theArgNb)
8540 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8543 TCollection_AsciiString aMode (theArgVec[anArgIter]);
8545 if (aMode == "color"
8548 aView->SetShadingModel (V3d_COLOR);
8550 else if (aMode == "flat"
8551 || aMode == "facet")
8553 aView->SetShadingModel (V3d_FLAT);
8555 else if (aMode == "gouraud"
8556 || aMode == "vertex"
8559 aView->SetShadingModel (V3d_GOURAUD);
8561 else if (aMode == "phong"
8562 || aMode == "fragment"
8564 || aMode == "pixel")
8566 aView->SetShadingModel (V3d_PHONG);
8570 std::cout << "Error: unknown shading model '" << aMode << "'\n";
8574 else if (aFlag == "-resolution")
8576 if (++anArgIter >= theArgNb)
8578 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8582 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
8583 if (aResolution.IsIntegerValue())
8585 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
8589 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
8595 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
8603 //=======================================================================
8604 //function : VProgressiveMode
8606 //=======================================================================
8608 static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
8609 Standard_Integer /*theNbArgs*/,
8610 const char** /*theArgs*/)
8612 Handle(V3d_View) aView = ViewerTest::CurrentView();
8615 std::cerr << "Error: no active viewer!\n";
8619 std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
8625 Standard_Boolean toExit = Standard_False;
8628 while (PeekMessage (&aMsg, NULL, NULL, NULL, PM_REMOVE))
8630 if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
8632 toExit = Standard_True;
8635 TranslateMessage (&aMsg);
8636 DispatchMessage (&aMsg);
8649 //=======================================================================
8650 //function : VFrustumCulling
8651 //purpose : enables/disables view volume's culling.
8652 //=======================================================================
8653 static int VFrustumCulling (Draw_Interpretor& theDI,
8654 Standard_Integer theArgNb,
8655 const char** theArgVec)
8657 Handle(V3d_View) aView = ViewerTest::CurrentView();
8660 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
8666 theDI << (aView->IsCullingEnabled() ? "on" : "off");
8669 else if (theArgNb != 2)
8671 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
8675 TCollection_AsciiString aModeStr (theArgVec[1]);
8676 aModeStr.LowerCase();
8677 Standard_Boolean toEnable = 0;
8678 if (aModeStr == "on")
8682 else if (aModeStr == "off")
8688 toEnable = Draw::Atoi (theArgVec[1]) != 0;
8691 aView->SetFrustumCulling (toEnable);
8696 //=======================================================================
8697 //function : VHighlightSelected
8699 //=======================================================================
8700 static int VHighlightSelected (Draw_Interpretor& theDI,
8701 Standard_Integer theArgNb,
8702 const char** theArgVec)
8704 if (ViewerTest::GetAISContext().IsNull())
8706 std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n";
8710 const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8714 theDI << (aContext->ToHilightSelected() ? "on" : "off");
8720 std::cout << theArgVec[0] << " error : wrong number of parameters."
8721 << "Type 'help" << theArgVec[0] << "' for more information.";
8726 TCollection_AsciiString aMode (theArgVec[1]);
8728 Standard_Boolean toEnable = Standard_False;
8729 if (aMode.IsEqual ("on"))
8731 toEnable = Standard_True;
8733 else if (aMode.IsEqual ("off"))
8735 toEnable = Standard_False;
8739 toEnable = Draw::Atoi (theArgVec[1]) != 0;
8742 if (toEnable != aContext->ToHilightSelected())
8744 aContext->SetToHilightSelected (toEnable);
8746 // Move cursor to null position and back to process updating of detection
8747 // and highlighting of selected object immediatly.
8748 Standard_Integer aPixX = 0;
8749 Standard_Integer aPixY = 0;
8750 const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager();
8752 anEventManager->GetCurrentPosition (aPixX, aPixY);
8753 anEventManager->MoveTo (0, 0);
8754 anEventManager->MoveTo (aPixX, aPixY);
8760 //=======================================================================
8761 //function : VXRotate
8763 //=======================================================================
8764 static Standard_Integer VXRotate (Draw_Interpretor& di,
8765 Standard_Integer argc,
8768 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8769 if (aContext.IsNull())
8771 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
8777 di << "ERROR : Usage : " << argv[0] << " name angle" << "\n";
8781 TCollection_AsciiString aName (argv[1]);
8782 Standard_Real anAngle = Draw::Atof (argv[2]);
8785 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
8786 Handle(AIS_InteractiveObject) anIObj;
8787 if (!aMap.IsBound2 (aName) )
8789 di << "Use 'vdisplay' before" << "\n";
8794 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
8797 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
8798 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
8800 aContext->SetLocation (anIObj, aTransform);
8801 aContext->UpdateCurrentViewer();
8807 //=======================================================================
8808 //function : ViewerCommands
8810 //=======================================================================
8812 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
8815 const char *group = "ZeViewer";
8816 theCommands.Add("vinit",
8817 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
8818 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
8820 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
8822 " - Creates new View window with specified name view_name.\n"
8823 "By default the new view is created in the viewer and in"
8824 " graphic driver shared with active view.\n"
8825 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
8826 "If driverName isn't specified the driver will be shared with active view.\n"
8827 "If viewerName isn't specified the viewer will be shared with active view.\n"
8828 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
8829 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
8830 "is used in creation of graphic driver\n"
8832 " - l, t: pixel position of left top corner of the window\n"
8833 " - w,h: width and heigth of window respectively.\n"
8834 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
8835 __FILE__,VInit,group);
8836 theCommands.Add("vclose" ,
8837 "[view_id [keep_context=0|1]]\n"
8838 "or vclose ALL - to remove all created views\n"
8839 " - removes view(viewer window) defined by its view_id.\n"
8840 " - keep_context: by default 0; if 1 and the last view is deleted"
8841 " the current context is not removed.",
8842 __FILE__,VClose,group);
8843 theCommands.Add("vactivate" ,
8845 " - activates view(viewer window) defined by its view_id",
8846 __FILE__,VActivate,group);
8847 theCommands.Add("vviewlist",
8848 "vviewlist [format={tree, long}]"
8849 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
8850 " - format: format of result output, if tree the output is a tree view;"
8851 "otherwise it's a list of full view names. By default format = tree",
8852 __FILE__,VViewList,group);
8853 theCommands.Add("vhelp" ,
8854 "vhelp : display help on the viewer commands",
8855 __FILE__,VHelp,group);
8856 theCommands.Add("vtop" ,
8857 "vtop or <T> : Top view. Orientation +X+Y" ,
8858 __FILE__,VTop,group);
8859 theCommands.Add("vbottom" ,
8860 "vbottom : Bottom view. Orientation +X-Y" ,
8861 __FILE__,VBottom,group);
8862 theCommands.Add("vleft" ,
8863 "vleft : Left view. Orientation -Y+Z" ,
8864 __FILE__,VLeft,group);
8865 theCommands.Add("vright" ,
8866 "vright : Right view. Orientation +Y+Z" ,
8867 __FILE__,VRight,group);
8868 theCommands.Add("vaxo" ,
8869 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
8870 __FILE__,VAxo,group);
8871 theCommands.Add("vfront" ,
8872 "vfront : Front view. Orientation +X+Z" ,
8873 __FILE__,VFront,group);
8874 theCommands.Add("vback" ,
8875 "vback : Back view. Orientation -X+Z" ,
8876 __FILE__,VBack,group);
8877 theCommands.Add("vpick" ,
8878 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
8880 theCommands.Add("vfit" ,
8881 "vfit or <F> [-selected]"
8882 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
8883 __FILE__,VFit,group);
8884 theCommands.Add ("vfitarea",
8885 "vfitarea x1 y1 x2 y2"
8886 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
8887 "\n\t\t: Fit view to show area located between two points"
8888 "\n\t\t: given in world 2D or 3D corrdinates.",
8889 __FILE__, VFitArea, group);
8890 theCommands.Add ("vzfit", "vzfit [scale]\n"
8891 " Matches Z near, Z far view volume planes to the displayed objects.\n"
8892 " \"scale\" - specifies factor to scale computed z range.\n",
8893 __FILE__, VZFit, group);
8894 theCommands.Add("vrepaint",
8895 "vrepaint : vrepaint, force redraw",
8896 __FILE__,VRepaint,group);
8897 theCommands.Add("vclear",
8899 "\n\t\t: remove all the object from the viewer",
8900 __FILE__,VClear,group);
8901 theCommands.Add("vsetbg",
8902 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
8903 __FILE__,VSetBg,group);
8904 theCommands.Add("vsetbgmode",
8905 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
8906 __FILE__,VSetBgMode,group);
8907 theCommands.Add("vsetgradientbg",
8908 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
8909 __FILE__,VSetGradientBg,group);
8910 theCommands.Add("vsetgrbgmode",
8911 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
8912 __FILE__,VSetGradientBgMode,group);
8913 theCommands.Add("vsetcolorbg",
8914 "vsetcolorbg : vsetcolorbg r g b : Set background color",
8915 __FILE__,VSetColorBg,group);
8916 theCommands.Add("vsetdefaultbg",
8917 "vsetdefaultbg r g b\n"
8918 "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode"
8919 "\n\t\t: Set default viewer background fill color (flat/gradient).",
8920 __FILE__,VSetDefaultBg,group);
8921 theCommands.Add("vscale",
8922 "vscale : vscale X Y Z",
8923 __FILE__,VScale,group);
8924 theCommands.Add("vzbufftrihedron",
8925 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
8926 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
8927 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
8928 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
8929 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
8930 "\n\t\t: Displays a trihedron",
8931 __FILE__,VZBuffTrihedron,group);
8932 theCommands.Add("vrotate",
8933 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
8934 "\n : Option -mouseStart starts rotation according to the mouse position"
8935 "\n : Option -mouseMove continues rotation with angle computed"
8936 "\n : from last and new mouse position."
8937 "\n : vrotate AX AY AZ [X Y Z]",
8938 __FILE__,VRotate,group);
8939 theCommands.Add("vzoom",
8940 "vzoom : vzoom coef",
8941 __FILE__,VZoom,group);
8942 theCommands.Add("vpan",
8943 "vpan : vpan dx dy",
8944 __FILE__,VPan,group);
8945 theCommands.Add("vexport",
8946 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
8947 " : exports the view to a vector file of a given format"
8948 " : notice that EMF format requires patched gl2ps",
8949 __FILE__,VExport,group);
8950 theCommands.Add("vcolorscale",
8951 "vcolorscale : vcolorscale name [-range RangeMin = 0 RangeMax = 100 Intervals = 10 -font HeightFont = 16 -textpos "
8952 "Position = left -xy X = 0 Y = 0] [-noupdate|-update]: draw color scale\n"
8953 "-demo/-demoversion draw a demoversion of color scale.\n"
8954 "-show/display display color scale.\n"
8955 "-hide/erase erase color scale.\n"
8956 "Please note that -show/-hide option must be the first argument!\n"
8957 "-color Index R G B: set color for indexed interval\n"
8958 "-color Index ColorName: set color for indexed interval\n"
8959 "-colors R G B R G B ...: set colors for all intervals\n"
8960 "-colors ColorName1 ColorName2 ...: set colors for all intervals\n"
8961 "-colors supports both color names and rgb values in one call\n"
8962 "-label Index Text: set label for indexed interval\n"
8963 "-labels Text Text Text ...: set labels for all intervals\n"
8964 "-title Title [Position]: set the title for color scale with certain position. Default position = center;\n"
8965 "Available text positions: left, right, center, none;\n",
8966 __FILE__,VColorScale,group);
8967 theCommands.Add("vgraduatedtrihedron",
8968 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
8969 "\t[-namefont Name] [-valuesfont Name]\n"
8970 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
8971 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
8972 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
8973 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
8974 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
8975 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
8976 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
8977 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
8978 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
8979 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
8980 " - Displays or erases graduated trihedron"
8981 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
8982 " - namefont - font of axes names. Default: Arial\n"
8983 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
8984 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
8985 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
8986 " - valuesfont - font of axes values. Default: Arial\n"
8987 " - xcolor, ycolor, zcolor - color of axis and values\n"
8988 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
8989 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
8990 __FILE__,VGraduatedTrihedron,group);
8991 theCommands.Add("vprintview" ,
8992 "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
8993 __FILE__,VPrintView,group);
8994 theCommands.Add("vzlayer",
8995 "vzlayer add/del/get/settings/enable/disable [id]\n"
8996 " add - add new z layer to viewer and print its id\n"
8997 " del - del z layer by its id\n"
8998 " get - print sequence of z layers in increasing order of their overlay level\n"
8999 " settings - print status of z layer settings\n"
9000 " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n"
9001 " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n"
9002 " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n"
9003 "\nWhere id is the layer identificator\n"
9006 " vzlayer enable poffset 1\n"
9007 " vzlayer disable depthtest 1\n"
9009 __FILE__,VZLayer,group);
9010 theCommands.Add("vlayerline",
9011 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
9012 __FILE__,VLayerLine,group);
9013 theCommands.Add ("vgrid",
9014 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
9015 " : Mode - rectangular or circular"
9016 " : Type - lines or points",
9017 __FILE__, VGrid, group);
9018 theCommands.Add ("vpriviledgedplane",
9019 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
9020 "\n\t\t: Ox, Oy, Oz - plane origin"
9021 "\n\t\t: Nx, Ny, Nz - plane normal direction"
9022 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
9023 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
9024 __FILE__, VPriviledgedPlane, group);
9025 theCommands.Add ("vconvert",
9026 "vconvert v [Mode={window|view}]"
9027 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
9028 "\n\t\t: vconvert x y z [Mode={window|grid}]"
9029 "\n\t\t: window - convert to window coordinates, pixels"
9030 "\n\t\t: view - convert to view projection plane"
9031 "\n\t\t: grid - convert to model coordinates, given on grid"
9032 "\n\t\t: ray - convert projection ray to model coordiantes"
9033 "\n\t\t: - vconvert v window : convert view to window;"
9034 "\n\t\t: - vconvert v view : convert window to view;"
9035 "\n\t\t: - vconvert x y window : convert view to window;"
9036 "\n\t\t: - vconvert x y view : convert window to view;"
9037 "\n\t\t: - vconvert x y : convert window to model;"
9038 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
9039 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
9040 "\n\t\t: - vconvert x y z window : convert model to window;"
9041 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
9042 "\n\t\t: Converts the given coordinates to window/view/model space.",
9043 __FILE__, VConvert, group);
9044 theCommands.Add ("vfps",
9045 "vfps [framesNb=100] : estimate average frame rate for active view",
9046 __FILE__, VFps, group);
9047 theCommands.Add ("vgldebug",
9048 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
9049 "\n\t\t: [-extraMsg {0|1}] [{0|1}]"
9050 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
9051 "\n\t\t: Debug context can be requested only on Windows"
9052 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
9053 "\n\t\t: -sync - request synchronized debug GL context"
9054 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
9055 "\n\t\t: which are suppressed by default,"
9056 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
9057 "\n\t\t: which are suppressed by default",
9058 __FILE__, VGlDebug, group);
9059 theCommands.Add ("vvbo",
9060 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
9061 __FILE__, VVbo, group);
9062 theCommands.Add ("vstereo",
9063 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
9064 "\n\t\t: [-anaglyph Filter]"
9065 "\n\t\t: Control stereo output mode. Available modes for -mode:"
9066 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
9067 "\n\t\t: requires driver support."
9068 "\n\t\t: Should be called BEFORE vinit!"
9069 "\n\t\t: anaglyph - Anaglyph glasses"
9070 "\n\t\t: rowInterlaced - row-interlaced display"
9071 "\n\t\t: columnInterlaced - column-interlaced display"
9072 "\n\t\t: chessBoard - chess-board output"
9073 "\n\t\t: sideBySide - horizontal pair"
9074 "\n\t\t: overUnder - vertical pair"
9075 "\n\t\t: Available Anaglyph filters for -anaglyph:"
9076 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
9077 "\n\t\t: greenMagentaSimple",
9078 __FILE__, VStereo, group);
9079 theCommands.Add ("vcaps",
9080 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
9081 "\n\t\t: [-compatibleProfile {0|1}]"
9082 "\n\t\t: [-vsync {0|1}]"
9083 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
9084 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
9085 "\n\t\t: Modify particular graphic driver options:"
9086 "\n\t\t: FFP - use fixed-function pipeline instead of"
9087 "\n\t\t: built-in GLSL programs"
9088 "\n\t\t: (requires compatible profile)"
9089 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
9090 "\n\t\t: arrays to GPU memory)"
9091 "\n\t\t: sprite - use textured sprites instead of bitmaps"
9092 "\n\t\t: vsync - switch VSync on or off"
9093 "\n\t\t: Context creation options:"
9094 "\n\t\t: softMode - software OpenGL implementation"
9095 "\n\t\t: compatibleProfile - backward-compatible profile"
9096 "\n\t\t: quadbuffer - QuadBuffer"
9097 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
9098 "\n\t\t: rendering paths producing the same visual result when"
9100 "\n\t\t: Command is intended for testing old hardware compatibility.",
9101 __FILE__, VCaps, group);
9102 theCommands.Add ("vmemgpu",
9103 "vmemgpu [f]: print system-dependent GPU memory information if available;"
9104 " with f option returns free memory in bytes",
9105 __FILE__, VMemGpu, group);
9106 theCommands.Add ("vreadpixel",
9107 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
9108 " : Read pixel value for active view",
9109 __FILE__, VReadPixel, group);
9110 theCommands.Add("diffimage",
9111 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
9112 __FILE__, VDiffImage, group);
9113 theCommands.Add ("vselect",
9114 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
9115 "- emulates different types of selection:\n"
9116 "- 1) single click selection\n"
9117 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
9118 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
9119 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
9120 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
9121 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
9122 " (partial inclusion - overlap - is not allowed by default)\n"
9123 "- 5) any of these selections with shift button pressed",
9124 __FILE__, VSelect, group);
9125 theCommands.Add ("vmoveto",
9127 "- emulates cursor movement to pixel postion (x,y)",
9128 __FILE__, VMoveTo, group);
9129 theCommands.Add ("vviewparams", "vviewparams usage:\n"
9131 "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n"
9132 " [-proj [x y z]] [-center x y] [-size sx]\n"
9133 "- Gets or sets current view parameters.\n"
9134 "- If called without arguments, all view parameters are printed.\n"
9135 "- The options are:\n"
9136 " -scale [s] : prints or sets viewport relative scale.\n"
9137 " -eye [x y z] : prints or sets eye location.\n"
9138 " -at [x y z] : prints or sets center of look.\n"
9139 " -up [x y z] : prints or sets direction of up vector.\n"
9140 " -proj [x y z] : prints or sets direction of look.\n"
9141 " -center x y : sets location of center of the screen in pixels.\n"
9142 " -size [sx] : prints viewport projection width and height sizes\n"
9143 " : or changes the size of its maximum dimension.\n",
9144 __FILE__, VViewParams, group);
9145 theCommands.Add("vchangeselected",
9146 "vchangeselected shape"
9147 "- adds to shape to selection or remove one from it",
9148 __FILE__, VChangeSelected, group);
9149 theCommands.Add("vzclipping",
9150 "vzclipping [mode] [depth width]\n"
9151 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
9152 "- gets or sets ZClipping mode, width and depth",
9153 __FILE__,VZClipping,group);
9154 theCommands.Add ("vnbselected",
9156 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
9157 theCommands.Add ("vcamera",
9158 "vcamera [-ortho] [-projtype]"
9160 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
9161 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
9162 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
9163 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
9164 "\n\t\t: Manage camera parameters."
9165 "\n\t\t: Prints current value when option called without argument."
9166 "\n\t\t: Orthographic camera:"
9167 "\n\t\t: -ortho activate orthographic projection"
9168 "\n\t\t: Perspective camera:"
9169 "\n\t\t: -persp activate perspective projection (mono)"
9170 "\n\t\t: -fovy field of view in y axis, in degrees"
9171 "\n\t\t: -distance distance of eye from camera center"
9172 "\n\t\t: Stereoscopic camera:"
9173 "\n\t\t: -stereo perspective projection (stereo)"
9174 "\n\t\t: -leftEye perspective projection (left eye)"
9175 "\n\t\t: -rightEye perspective projection (right eye)"
9176 "\n\t\t: -iod intraocular distance value"
9177 "\n\t\t: -iodType distance type, absolute or relative"
9178 "\n\t\t: -zfocus stereographic focus value"
9179 "\n\t\t: -zfocusType focus type, absolute or relative",
9180 __FILE__, VCamera, group);
9181 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
9182 "- vautozfit [on={1|0}] [scale]\n"
9183 " Prints or changes parameters of automatic z-fit mode:\n"
9184 " \"on\" - turns automatic z-fit on or off\n"
9185 " \"scale\" - specifies factor to scale computed z range.\n",
9186 __FILE__, VAutoZFit, group);
9187 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
9188 " vzrange - without parameters shows current values\n"
9189 " vzrange [znear] [zfar] - applies provided values to view",
9190 __FILE__,VZRange, group);
9191 theCommands.Add("vantialiasing",
9193 "\n\t\t: Switches altialiasing on or off",
9194 __FILE__,VAntialiasing,group);
9195 theCommands.Add ("vpurgedisplay",
9197 "- removes structures which don't belong to objects displayed in neutral point",
9198 __FILE__, VPurgeDisplay, group);
9199 theCommands.Add("vsetviewsize",
9200 "vsetviewsize size",
9201 __FILE__,VSetViewSize,group);
9202 theCommands.Add("vmoveview",
9203 "vmoveview Dx Dy Dz [Start = 1|0]",
9204 __FILE__,VMoveView,group);
9205 theCommands.Add("vtranslateview",
9206 "vtranslateview Dx Dy Dz [Start = 1|0)]",
9207 __FILE__,VTranslateView,group);
9208 theCommands.Add("vturnview",
9209 "vturnview Ax Ay Az [Start = 1|0]",
9210 __FILE__,VTurnView,group);
9211 theCommands.Add("vtextureenv",
9212 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
9213 "or user-defined file and optionally applying texture mapping parameters\n"
9215 " vtextureenv off - disables environment mapping\n"
9216 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
9217 " std_texture = (0..7)\n"
9218 " rep = {clamp|repeat}\n"
9219 " mod = {decal|modulate}\n"
9220 " flt = {nearest|bilinear|trilinear}\n"
9221 " ss, st - scale factors for s and t texture coordinates\n"
9222 " ts, tt - translation for s and t texture coordinates\n"
9223 " rot - texture rotation angle in degrees",
9224 __FILE__, VTextureEnv, group);
9225 theCommands.Add("vhlr" ,
9226 "is_enabled={on|off} [show_hidden={1|0}]"
9227 " - Hidden line removal algorithm:"
9228 " - is_enabled: if is on HLR algorithm is applied\n"
9229 " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n",
9230 __FILE__,VHLR,group);
9231 theCommands.Add("vhlrtype" ,
9232 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
9233 " - Changes the type of HLR algorithm using for shapes."
9234 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
9235 " if equals to polyalgo, polygonal HLR algorithm is applied."
9236 "If shapes are not given HLR algoithm of given type is applied"
9237 " to all shapes in the view\n",
9238 __FILE__,VHLRType,group);
9239 theCommands.Add("vclipplane", "vclipplane usage: \n"
9240 " maxplanes <view_name> - get plane limit for view.\n"
9241 " create <plane_name> - create new plane.\n"
9242 " delete <plane_name> - delete plane.\n"
9243 " clone <source_plane> <plane_name> - clone the plane definition.\n"
9244 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
9245 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
9246 " change <plane_name> on/off - turn clipping on/off.\n"
9247 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
9248 " change <plane_name> capping on/off - turn capping on/off.\n"
9249 " change <plane_name> capping color <r> <g> <b> - set color.\n"
9250 " change <plane name> capping texname <texture> - set texture.\n"
9251 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
9252 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
9253 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
9254 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
9255 " please use VSetTextureMode command to enable texture rendering in view.\n"
9256 , __FILE__, VClipPlane, group);
9257 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
9259 " 0 - no textures enabled in view.\n"
9260 " 1 - only environment textures enabled.\n"
9261 " 2 - all textures enabled.\n"
9262 " this command sets texture details mode for the specified view.\n"
9263 , __FILE__, VSetTextureMode, group);
9264 theCommands.Add("vdefaults",
9265 "vdefaults [-absDefl value]"
9266 "\n\t\t: [-devCoeff value]"
9267 "\n\t\t: [-angDefl value]"
9268 "\n\t\t: [-autoTriang {off/on | 0/1}]"
9269 , __FILE__, VDefaults, group);
9270 theCommands.Add("vlight",
9271 "tool to manage light sources, without arguments shows list of lights."
9272 "\n Main commands: "
9273 "\n 'clear' to clear lights"
9274 "\n '{def}aults' to load deafault lights"
9275 "\n 'add' (or 'new') <type> to add any light source"
9276 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
9277 "\n 'change' <lightId> to edit light source with specified lightId"
9278 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
9279 "\n {pos}ition X Y Z"
9280 "\n {dir}ection X Y Z (for directional light or for spotlight)"
9281 "\n color colorName"
9282 "\n {head}light 0|1"
9283 "\n {sm}oothness value"
9284 "\n {int}ensity value"
9285 "\n {constAtten}uation value"
9286 "\n {linearAtten}uation value"
9288 "\n {spotexp}onent value"
9290 "\n\n example: vlight add positional head 1 pos 0 1 1 color red"
9291 "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
9292 __FILE__, VLight, group);
9293 theCommands.Add("vraytrace",
9295 "\n\t\t: Turns on/off ray-tracing renderer."
9296 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
9297 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
9298 __FILE__, VRenderParams, group);
9299 theCommands.Add("vrenderparams",
9300 "\n Manages rendering parameters: "
9301 "\n '-raster' Disables GPU ray-tracing"
9302 "\n '-msaa 0..4' Specifies number of samples for MSAA"
9303 "\n '-rayTrace' Enables GPU ray-tracing"
9304 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
9305 "\n '-shadows on|off' Enables/disables shadows rendering"
9306 "\n '-reflections on|off' Enables/disables specular reflections"
9307 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
9308 "\n '-gleam on|off' Enables/disables transparency shadow effects"
9309 "\n '-gi on|off' Enables/disables global illumination effects"
9310 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
9311 "\n '-env on|off' Enables/disables environment map background"
9312 "\n '-shadingModel model' Controls shading model from enumeration"
9313 "\n color, flat, gouraud, phong"
9314 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
9315 "\n Unlike vcaps, these parameters dramatically change visual properties."
9316 "\n Command is intended to control presentation quality depending on"
9317 "\n hardware capabilities and performance.",
9318 __FILE__, VRenderParams, group);
9319 theCommands.Add("vfrustumculling",
9320 "vfrustumculling [toEnable]: enables/disables objects clipping",
9321 __FILE__,VFrustumCulling,group);
9322 theCommands.Add("vhighlightselected",
9323 "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n"
9324 "Without arguments it shows if highlighting of selected objects is enabled now.",
9325 __FILE__,VHighlightSelected,group);
9326 theCommands.Add ("vplace",
9328 "\n\t\t: Places the point (in pixels) at the center of the window",
9329 __FILE__, VPlace, group);
9330 theCommands.Add("vxrotate",
9332 __FILE__,VXRotate,group);
9335 theCommands.Add("vprogressive",
9337 __FILE__, VProgressiveMode, group);