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,
4278 di << "Printing implemented only for WNT!\n";
4282 Handle(AIS_InteractiveContext) aContextAIS = NULL;
4283 Handle(V3d_View) aView = NULL;
4284 aContextAIS = ViewerTest::GetAISContext();
4285 if (!aContextAIS.IsNull())
4287 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
4288 Vwr->InitActiveViews();
4289 if(Vwr->MoreActiveViews())
4290 aView = Vwr->ActiveView();
4296 di << "Call vinit before!\n";
4301 di << "Use: " << argv[0];
4302 di << " width height filename [print algo=0] [tile_width tile_height]\n";
4303 di << "width, height of the intermediate buffer for operation\n";
4304 di << "algo : {0|1}\n";
4305 di << " 0 - stretch algorithm\n";
4306 di << " 1 - tile algorithm\n";
4307 di << "test printing algorithms into an intermediate buffer\n";
4308 di << "using specific tile size if provided\n";
4309 di << "with saving output to an image file\n";
4313 // get the input params
4314 Standard_Integer aWidth = Draw::Atoi (argv[1]);
4315 Standard_Integer aHeight = Draw::Atoi (argv[2]);
4316 Standard_Integer aMode = 0;
4317 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
4319 aMode = Draw::Atoi (argv[4]);
4321 Standard_Integer aTileWidth = 0;
4322 Standard_Integer aTileHeight = 0;
4323 Standard_Boolean isTileSizeProvided = Standard_False;
4326 isTileSizeProvided = Standard_True;
4327 aTileWidth = Draw::Atoi (argv[5]);
4328 aTileHeight = Draw::Atoi (argv[6]);
4331 // check the input parameters
4332 if (aWidth <= 0 || aHeight <= 0)
4334 di << "Width and height must be positive values!\n";
4337 if (aMode != 0 && aMode != 1)
4340 // define compatible bitmap
4341 HDC anDC = CreateCompatibleDC(0);
4342 BITMAPINFO aBitmapData;
4343 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
4344 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
4345 aBitmapData.bmiHeader.biWidth = aWidth ;
4346 aBitmapData.bmiHeader.biHeight = aHeight;
4347 aBitmapData.bmiHeader.biPlanes = 1;
4348 aBitmapData.bmiHeader.biBitCount = 24;
4349 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
4350 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
4351 aBitmapData.bmiHeader.biClrUsed = 0;
4352 aBitmapData.bmiHeader.biClrImportant = 0;
4353 aBitmapData.bmiHeader.biCompression = BI_RGB;
4354 aBitmapData.bmiHeader.biSizeImage = 0;
4356 // Create Device Independent Bitmap
4357 void* aBitsOut = NULL;
4358 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
4359 &aBitsOut, NULL, 0);
4360 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
4362 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
4363 if (aBitsOut != NULL)
4366 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
4369 if (isTileSizeProvided)
4371 Handle(Graphic3d_CView) aGraphicView = ViewerTest::CurrentView()->View();
4372 Graphic3d_PtrFrameBuffer anOldBuffer = aGraphicView->FBO();
4373 Graphic3d_PtrFrameBuffer aNewBuffer = aGraphicView->FBOCreate (aTileWidth, aTileHeight);
4374 aGraphicView->SetFBO (aNewBuffer);
4376 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
4378 aGraphicView->FBORelease (aNewBuffer);
4379 aGraphicView->SetFBO (anOldBuffer);
4383 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
4387 // successfully printed into an intermediate buffer
4390 Image_PixMap aWrapper;
4391 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
4392 aWrapper.SetTopDown (false);
4394 Image_AlienPixMap anImageBitmap;
4395 anImageBitmap.InitCopy (aWrapper);
4396 isSaved = anImageBitmap.Save (aFileName);
4400 di << "Print operation failed due to printing errors or\n";
4401 di << "insufficient memory available\n";
4402 di << "Please, try to use smaller dimensions for this test\n";
4403 di << "command, as it allocates intermediate buffer for storing\n";
4404 di << "the result\n";
4409 di << "Can't allocate memory for intermediate buffer\n";
4410 di << "Please use smaller dimensions\n";
4415 SelectObject (anDC, anOldBitmap);
4416 DeleteObject (aMemoryBitmap);
4422 di << "Save to file operation failed. This operation may fail\n";
4423 di << "if you don't have enough available memory, then you can\n";
4424 di << "use smaller dimensions for the output file\n";
4433 //==============================================================================
4434 //function : VZLayer
4435 //purpose : Test z layer operations for v3d viewer
4436 //==============================================================================
4437 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4439 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
4440 if (aContextAIS.IsNull())
4442 di << "Call vinit before!\n";
4447 di << "Use: vzlayer ";
4448 di << " add/del/get/settings/enable/disable [id]\n";
4449 di << " add - add new z layer to viewer and print its id\n";
4450 di << " del - del z layer by its id\n";
4451 di << " get - print sequence of z layers in increasing order of their overlay level\n";
4452 di << " settings - print status of z layer settings\n";
4453 di << " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n";
4454 di << " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n";
4455 di << " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n";
4456 di << "\nWhere id is the layer identificator\n";
4457 di << "\nExamples:\n";
4458 di << " vzlayer add\n";
4459 di << " vzlayer enable poffset 1\n";
4460 di << " vzlayer disable depthtest 1\n";
4461 di << " vzlayer del 1\n";
4465 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
4466 if (aViewer.IsNull())
4468 di << "No active viewer!\n";
4472 // perform operation
4473 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
4476 Standard_Integer aNewId;
4477 if (!aViewer->AddZLayer (aNewId))
4479 di << "Impossible to add new z layer!\n";
4483 di << "New z layer added with index: " << aNewId << "\n";
4485 else if (anOp == "del")
4489 di << "Please also provide as argument id of z layer to remove\n";
4493 Standard_Integer aDelId = Draw::Atoi (argv[2]);
4494 if (!aViewer->RemoveZLayer (aDelId))
4496 di << "Impossible to remove the z layer or invalid id!\n";
4500 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4501 anObjIter.More(); anObjIter.Next())
4503 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1());
4505 || aPrs->ZLayer() != aDelId)
4509 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4512 di << "Z layer " << aDelId << " has been removed\n";
4514 else if (anOp == "get")
4516 TColStd_SequenceOfInteger anIds;
4517 aViewer->GetAllZLayers (anIds);
4518 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
4520 di << anIds.Value (aSeqIdx) << " ";
4525 else if (anOp == "settings")
4529 di << "Please also provide an id\n";
4533 Standard_Integer anId = Draw::Atoi (argv[2]);
4534 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4536 di << "Depth test - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthTest) ? "enabled" : "disabled") << "\n";
4537 di << "Depth write - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthWrite) ? "enabled" : "disabled") << "\n";
4538 di << "Depth buffer clearing - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthClear) ? "enabled" : "disabled") << "\n";
4539 di << "Depth offset - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthOffset) ? "enabled" : "disabled") << "\n";
4542 else if (anOp == "enable")
4546 di << "Please also provide an option to enable\n";
4552 di << "Please also provide a layer id\n";
4556 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
4557 Standard_Integer anId = Draw::Atoi (argv[3]);
4558 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4560 if (aSubOp == "depthtest" || aSubOp == "test")
4562 aSettings.EnableSetting (Graphic3d_ZLayerDepthTest);
4564 else if (aSubOp == "depthwrite" || aSubOp == "write")
4566 aSettings.EnableSetting (Graphic3d_ZLayerDepthWrite);
4568 else if (aSubOp == "depthclear" || aSubOp == "clear")
4570 aSettings.EnableSetting (Graphic3d_ZLayerDepthClear);
4572 else if (aSubOp == "depthoffset" || aSubOp == "offset")
4576 di << "Please also provide a factor and units values for depth offset\n";
4577 di << "Format is: vzlayer enable offset [factor] [units] [layerId]\n";
4581 Standard_ShortReal aFactor = static_cast<Standard_ShortReal> (Draw::Atof (argv[3]));
4582 Standard_ShortReal aUnits = static_cast<Standard_ShortReal> (Draw::Atof (argv[4]));
4583 anId = Draw::Atoi (argv[5]);
4584 aSettings = aViewer->ZLayerSettings (anId);
4586 aSettings.DepthOffsetFactor = aFactor;
4587 aSettings.DepthOffsetUnits = aUnits;
4589 aSettings.EnableSetting (Graphic3d_ZLayerDepthOffset);
4591 else if (aSubOp == "positiveoffset" || aSubOp == "poffset")
4593 aSettings.SetDepthOffsetPositive();
4595 else if (aSubOp == "negativeoffset" || aSubOp == "noffset")
4597 aSettings.SetDepthOffsetNegative();
4600 aViewer->SetZLayerSettings (anId, aSettings);
4602 else if (anOp == "disable")
4606 di << "Please also provide an option to disable\n";
4612 di << "Please also provide a layer id\n";
4616 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
4617 Standard_Integer anId = Draw::Atoi (argv[3]);
4618 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4620 if (aSubOp == "depthtest" || aSubOp == "test")
4622 aSettings.DisableSetting (Graphic3d_ZLayerDepthTest);
4624 else if (aSubOp == "depthwrite" || aSubOp == "write")
4626 aSettings.DisableSetting (Graphic3d_ZLayerDepthWrite);
4628 else if (aSubOp == "depthclear" || aSubOp == "clear")
4630 aSettings.DisableSetting (Graphic3d_ZLayerDepthClear);
4632 else if (aSubOp == "depthoffset" || aSubOp == "offset")
4634 aSettings.DisableSetting (Graphic3d_ZLayerDepthOffset);
4637 aViewer->SetZLayerSettings (anId, aSettings);
4641 di << "Invalid operation, please use { add / del / get / settings / enable / disable}\n";
4648 // The interactive presentation of 2d layer item
4649 // for "vlayerline" command it provides a presentation of
4650 // line with user-defined linewidth, linetype and transparency.
4651 class V3d_LineItem : public AIS_InteractiveObject
4655 DEFINE_STANDARD_RTTI(V3d_LineItem, AIS_InteractiveObject)
4658 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4659 Standard_Real X2, Standard_Real Y2,
4660 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
4661 Standard_Real theWidth = 0.5,
4662 Standard_Real theTransp = 1.0);
4666 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4667 const Handle(Prs3d_Presentation)& thePresentation,
4668 const Standard_Integer theMode);
4670 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
4671 const Standard_Integer /*aMode*/){};
4675 Standard_Real myX1, myY1, myX2, myY2;
4676 Aspect_TypeOfLine myType;
4677 Standard_Real myWidth;
4680 // default constructor for line item
4681 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4682 Standard_Real X2, Standard_Real Y2,
4683 Aspect_TypeOfLine theType,
4684 Standard_Real theWidth,
4685 Standard_Real theTransp) :
4686 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
4687 myType(theType), myWidth(theWidth)
4689 SetTransparency (1-theTransp);
4693 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
4694 const Handle(Prs3d_Presentation)& thePresentation,
4695 const Standard_Integer /*theMode*/)
4697 thePresentation->Clear();
4698 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
4699 Standard_Integer aWidth, aHeight;
4700 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
4701 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
4702 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
4703 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
4704 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
4705 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
4706 aGroup->SetPrimitivesAspect (anAspect->Aspect());
4707 aGroup->AddPrimitiveArray (aPrim);
4710 //=============================================================================
4711 //function : VLayerLine
4712 //purpose : Draws line in the v3d view layer with given attributes: linetype,
4713 // : linewidth, transparency coefficient
4714 //============================================================================
4715 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4717 // get the active view
4718 Handle(V3d_View) aView = ViewerTest::CurrentView();
4721 di << "Call vinit before!\n";
4726 di << "Use: " << argv[0];
4727 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
4728 di << " linetype : { 0 | 1 | 2 | 3 } \n";
4729 di << " 0 - solid \n";
4730 di << " 1 - dashed \n";
4731 di << " 2 - dot \n";
4732 di << " 3 - dashdot\n";
4733 di << " transparency : { 0.0 - 1.0 } \n";
4734 di << " 0.0 - transparent\n";
4735 di << " 1.0 - visible \n";
4739 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4740 // get the input params
4741 Standard_Real X1 = Draw::Atof(argv[1]);
4742 Standard_Real Y1 = Draw::Atof(argv[2]);
4743 Standard_Real X2 = Draw::Atof(argv[3]);
4744 Standard_Real Y2 = Draw::Atof(argv[4]);
4746 Standard_Real aWidth = 0.5;
4747 Standard_Integer aType = 0;
4748 Standard_Real aTransparency = 1.0;
4752 aWidth = Draw::Atof(argv[5]);
4756 aType = (Standard_Integer) Draw::Atoi(argv[6]);
4761 aTransparency = Draw::Atof(argv[7]);
4762 if (aTransparency < 0 || aTransparency > 1.0)
4763 aTransparency = 1.0;
4766 // select appropriate line type
4767 Aspect_TypeOfLine aLineType;
4771 aLineType = Aspect_TOL_DASH;
4775 aLineType = Aspect_TOL_DOT;
4779 aLineType = Aspect_TOL_DOTDASH;
4783 aLineType = Aspect_TOL_SOLID;
4786 static Handle (V3d_LineItem) aLine;
4787 if (!aLine.IsNull())
4789 aContext->Erase (aLine);
4791 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
4795 aLine->SetTransformPersistence (Graphic3d_TMF_2d,gp_Pnt(-1,-1,0));
4796 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
4797 aLine->SetToUpdate();
4798 aContext->Display (aLine, Standard_True);
4804 //==============================================================================
4807 //==============================================================================
4809 static int VGrid (Draw_Interpretor& /*theDI*/,
4810 Standard_Integer theArgNb,
4811 const char** theArgVec)
4813 // get the active view
4814 Handle(V3d_View) aView = ViewerTest::CurrentView();
4815 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4816 if (aView.IsNull() || aViewer.IsNull())
4818 std::cerr << "No active view. Please call vinit.\n";
4822 Aspect_GridType aType = aViewer->GridType();
4823 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
4825 Standard_Integer anIter = 1;
4826 for (; anIter < theArgNb; ++anIter)
4828 const char* aValue = theArgVec[anIter];
4831 aType = Aspect_GT_Rectangular;
4833 else if (*aValue == 'c')
4835 aType = Aspect_GT_Circular;
4837 else if (*aValue == 'l')
4839 aMode = Aspect_GDM_Lines;
4841 else if (*aValue == 'p')
4843 aMode = Aspect_GDM_Points;
4845 else if (strcmp (aValue, "off" ) == 0)
4847 aViewer->DeactivateGrid();
4856 Standard_Integer aTail = (theArgNb - anIter);
4859 aViewer->ActivateGrid (aType, aMode);
4862 else if (aTail != 2 && aTail != 5)
4864 std::cerr << "Incorrect arguments number! Usage:\n"
4865 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
4869 Quantity_Length anOriginX, anOriginY;
4870 Quantity_PlaneAngle aRotAngle;
4871 if (aType == Aspect_GT_Rectangular)
4873 Quantity_Length aRStepX, aRStepY;
4874 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4876 anOriginX = Draw::Atof (theArgVec[anIter++]);
4877 anOriginY = Draw::Atof (theArgVec[anIter++]);
4880 aRStepX = Draw::Atof (theArgVec[anIter++]);
4881 aRStepY = Draw::Atof (theArgVec[anIter++]);
4882 aRotAngle = Draw::Atof (theArgVec[anIter++]);
4884 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4885 aViewer->ActivateGrid (aType, aMode);
4887 else if (aType == Aspect_GT_Circular)
4889 Quantity_Length aRadiusStep;
4890 Standard_Integer aDivisionNumber;
4891 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
4893 anOriginX = Draw::Atof (theArgVec[anIter++]);
4894 anOriginY = Draw::Atof (theArgVec[anIter++]);
4897 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
4898 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
4899 aRotAngle = Draw::Atof (theArgVec[anIter++]);
4902 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
4903 aViewer->ActivateGrid (aType, aMode);
4909 //==============================================================================
4910 //function : VPriviledgedPlane
4912 //==============================================================================
4914 static int VPriviledgedPlane (Draw_Interpretor& theDI,
4915 Standard_Integer theArgNb,
4916 const char** theArgVec)
4918 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
4920 std::cerr << "Error: wrong number of arguments! See usage:\n";
4921 theDI.PrintHelp (theArgVec[0]);
4925 // get the active viewer
4926 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4927 if (aViewer.IsNull())
4929 std::cerr << "Error: no active viewer. Please call vinit.\n";
4935 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
4936 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
4937 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
4938 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
4939 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
4940 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
4941 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
4945 Standard_Integer anArgIdx = 1;
4946 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
4947 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
4948 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
4949 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
4950 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
4951 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
4953 gp_Ax3 aPriviledgedPlane;
4954 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
4955 gp_Dir aNorm (aNormX, aNormY, aNormZ);
4958 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
4959 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
4960 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
4961 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
4962 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
4966 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
4969 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
4974 //==============================================================================
4975 //function : VConvert
4977 //==============================================================================
4979 static int VConvert (Draw_Interpretor& theDI,
4980 Standard_Integer theArgNb,
4981 const char** theArgVec)
4983 // get the active view
4984 Handle(V3d_View) aView = ViewerTest::CurrentView();
4987 std::cerr << "Error: no active view. Please call vinit.\n";
4991 enum { Model, Ray, View, Window, Grid } aMode = Model;
4993 // access coordinate arguments
4994 TColStd_SequenceOfReal aCoord;
4995 Standard_Integer anArgIdx = 1;
4996 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
4998 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
4999 if (!anArg.IsRealValue())
5003 aCoord.Append (anArg.RealValue());
5006 // non-numeric argument too early
5007 if (aCoord.IsEmpty())
5009 std::cerr << "Error: wrong number of arguments! See usage:\n";
5010 theDI.PrintHelp (theArgVec[0]);
5014 // collect all other arguments and options
5015 for (; anArgIdx < theArgNb; ++anArgIdx)
5017 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5019 if (anArg == "window") aMode = Window;
5020 else if (anArg == "view") aMode = View;
5021 else if (anArg == "grid") aMode = Grid;
5022 else if (anArg == "ray") aMode = Ray;
5025 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
5026 theDI.PrintHelp (theArgVec[0]);
5031 // complete input checks
5032 if ((aCoord.Length() == 1 && theArgNb > 3) ||
5033 (aCoord.Length() == 2 && theArgNb > 4) ||
5034 (aCoord.Length() == 3 && theArgNb > 5))
5036 std::cerr << "Error: wrong number of arguments! See usage:\n";
5037 theDI.PrintHelp (theArgVec[0]);
5041 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
5042 Standard_Integer aXYp[2] = {0, 0};
5044 // convert one-dimensional coordinate
5045 if (aCoord.Length() == 1)
5049 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer) aCoord (1)); return 0;
5050 case Window : theDI << "Window Vp: " << aView->Convert ((Quantity_Length) aCoord (1)); return 0;
5052 std::cerr << "Error: wrong arguments! See usage:\n";
5053 theDI.PrintHelp (theArgVec[0]);
5058 // convert 2D coordinates from projection or view reference space
5059 if (aCoord.Length() == 2)
5064 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5065 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5069 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5070 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5074 aView->Convert ((V3d_Coordinate) aCoord (1), (V3d_Coordinate) aCoord (2), aXYp[0], aXYp[1]);
5075 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5079 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5080 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5081 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5085 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5086 (Standard_Integer) aCoord (2),
5087 aXYZ[0], aXYZ[1], aXYZ[2],
5088 aXYZ[3], aXYZ[4], aXYZ[5]);
5089 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5093 std::cerr << "Error: wrong arguments! See usage:\n";
5094 theDI.PrintHelp (theArgVec[0]);
5099 // convert 3D coordinates from view reference space
5100 else if (aCoord.Length() == 3)
5105 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5106 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5110 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5111 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5115 std::cerr << "Error: wrong arguments! See usage:\n";
5116 theDI.PrintHelp (theArgVec[0]);
5124 //==============================================================================
5127 //==============================================================================
5129 static int VFps (Draw_Interpretor& theDI,
5130 Standard_Integer theArgNb,
5131 const char** theArgVec)
5133 // get the active view
5134 Handle(V3d_View) aView = ViewerTest::CurrentView();
5137 std::cerr << "No active view. Please call vinit.\n";
5141 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
5144 std::cerr << "Incorrect arguments!\n";
5148 // the time is meaningless for first call
5149 // due to async OpenGl rendering
5152 // redraw view in loop to estimate average values
5155 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
5161 const Standard_Real aTime = aTimer.ElapsedTime();
5162 aTimer.OSD_Chronometer::Show (aCpu);
5164 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
5165 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
5167 // return statistics
5168 theDI << "FPS: " << aFpsAver << "\n"
5169 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5171 // compute additional statistics in ray-tracing mode
5172 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
5174 if (aParams.Method == Graphic3d_RM_RAYTRACING)
5176 Standard_Integer aSizeX;
5177 Standard_Integer aSizeY;
5179 aView->Window()->Size (aSizeX, aSizeY);
5181 // 1 shadow ray and 1 secondary ray pew each bounce
5182 const Standard_Real aMRays = aSizeX * aSizeY * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
5184 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
5190 //==============================================================================
5191 //function : VGlDebug
5193 //==============================================================================
5195 static int VGlDebug (Draw_Interpretor& theDI,
5196 Standard_Integer theArgNb,
5197 const char** theArgVec)
5199 Handle(OpenGl_GraphicDriver) aDriver;
5200 Handle(V3d_View) aView = ViewerTest::CurrentView();
5201 if (!aView.IsNull())
5203 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5205 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
5206 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
5210 TCollection_AsciiString aDebActive, aSyncActive;
5217 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
5218 "GL_ARB_debug_output");
5219 aDebActive = isActive ? " (active)" : " (inactive)";
5222 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
5223 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
5227 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
5228 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
5229 << "glslWarn:" << (aCaps->glslWarnings ? "1" : "0") << "\n"
5230 << "extraMsg:" << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
5234 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5236 Standard_CString anArg = theArgVec[anArgIter];
5237 TCollection_AsciiString anArgCase (anArg);
5238 anArgCase.LowerCase();
5239 Standard_Boolean toEnableDebug = Standard_True;
5240 if (anArgCase == "-glsl"
5241 || anArgCase == "-glslwarn"
5242 || anArgCase == "-glslwarns"
5243 || anArgCase == "-glslwarnings")
5245 Standard_Boolean toShowWarns = Standard_True;
5246 if (++anArgIter < theArgNb
5247 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
5251 aDefCaps->glslWarnings = toShowWarns;
5254 aCaps->glslWarnings = toShowWarns;
5257 else if (anArgCase == "-extra"
5258 || anArgCase == "-extramsg"
5259 || anArgCase == "-extramessages")
5261 Standard_Boolean toShow = Standard_True;
5262 if (++anArgIter < theArgNb
5263 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
5267 aDefCaps->suppressExtraMsg = !toShow;
5270 aCaps->suppressExtraMsg = !toShow;
5273 else if (anArgCase == "-noextra"
5274 || anArgCase == "-noextramsg"
5275 || anArgCase == "-noextramessages")
5277 Standard_Boolean toSuppress = Standard_True;
5278 if (++anArgIter < theArgNb
5279 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
5283 aDefCaps->suppressExtraMsg = toSuppress;
5286 aCaps->suppressExtraMsg = toSuppress;
5289 else if (anArgCase == "-sync")
5291 Standard_Boolean toSync = Standard_True;
5292 if (++anArgIter < theArgNb
5293 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
5297 aDefCaps->contextSyncDebug = toSync;
5300 aDefCaps->contextDebug = Standard_True;
5303 else if (anArgCase == "-debug")
5305 if (++anArgIter < theArgNb
5306 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
5310 aDefCaps->contextDebug = toEnableDebug;
5312 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
5313 && (anArgIter + 1 == theArgNb))
5315 // simple alias to turn on almost everything
5316 aDefCaps->contextDebug = toEnableDebug;
5317 aDefCaps->contextSyncDebug = toEnableDebug;
5318 aDefCaps->glslWarnings = toEnableDebug;
5322 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
5330 //==============================================================================
5333 //==============================================================================
5335 static int VVbo (Draw_Interpretor& theDI,
5336 Standard_Integer theArgNb,
5337 const char** theArgVec)
5339 const Standard_Boolean toSet = (theArgNb > 1);
5340 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
5343 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
5347 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5348 if (aContextAIS.IsNull())
5352 std::cerr << "No active view!\n";
5356 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5357 if (!aDriver.IsNull())
5361 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
5365 aDriver->ChangeOptions().vboDisable = toUseVbo;
5372 //==============================================================================
5375 //==============================================================================
5377 static int VCaps (Draw_Interpretor& theDI,
5378 Standard_Integer theArgNb,
5379 const char** theArgVec)
5381 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
5382 Handle(OpenGl_GraphicDriver) aDriver;
5383 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5384 if (!aContext.IsNull())
5386 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
5387 aCaps = &aDriver->ChangeOptions();
5392 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
5393 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
5394 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
5395 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
5396 theDI << "VSync: " << aCaps->swapInterval << "\n";
5397 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
5398 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
5402 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5403 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5405 Standard_CString anArg = theArgVec[anArgIter];
5406 TCollection_AsciiString anArgCase (anArg);
5407 anArgCase.LowerCase();
5408 if (anUpdateTool.parseRedrawMode (anArg))
5412 else if (anArgCase == "-vsync"
5413 || anArgCase == "-swapinterval")
5415 Standard_Boolean toEnable = Standard_True;
5416 if (++anArgIter < theArgNb
5417 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5421 aCaps->swapInterval = toEnable;
5423 else if (anArgCase == "-ffp")
5425 Standard_Boolean toEnable = Standard_True;
5426 if (++anArgIter < theArgNb
5427 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5431 aCaps->ffpEnable = toEnable;
5433 else if (anArgCase == "-vbo")
5435 Standard_Boolean toEnable = Standard_True;
5436 if (++anArgIter < theArgNb
5437 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5441 aCaps->vboDisable = !toEnable;
5443 else if (anArgCase == "-sprite"
5444 || anArgCase == "-sprites")
5446 Standard_Boolean toEnable = Standard_True;
5447 if (++anArgIter < theArgNb
5448 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5452 aCaps->pntSpritesDisable = !toEnable;
5454 else if (anArgCase == "-softmode")
5456 Standard_Boolean toEnable = Standard_True;
5457 if (++anArgIter < theArgNb
5458 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5462 aCaps->contextNoAccel = toEnable;
5464 else if (anArgCase == "-accel"
5465 || anArgCase == "-acceleration")
5467 Standard_Boolean toEnable = Standard_True;
5468 if (++anArgIter < theArgNb
5469 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5473 aCaps->contextNoAccel = !toEnable;
5475 else if (anArgCase == "-compat"
5476 || anArgCase == "-compatprofile"
5477 || anArgCase == "-compatible"
5478 || anArgCase == "-compatibleprofile")
5480 Standard_Boolean toEnable = Standard_True;
5481 if (++anArgIter < theArgNb
5482 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5486 aCaps->contextCompatible = toEnable;
5487 if (!aCaps->contextCompatible)
5489 aCaps->ffpEnable = Standard_False;
5492 else if (anArgCase == "-core"
5493 || anArgCase == "-coreprofile")
5495 Standard_Boolean toEnable = Standard_True;
5496 if (++anArgIter < theArgNb
5497 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5501 aCaps->contextCompatible = !toEnable;
5502 if (!aCaps->contextCompatible)
5504 aCaps->ffpEnable = Standard_False;
5507 else if (anArgCase == "-stereo"
5508 || anArgCase == "-quadbuffer")
5510 Standard_Boolean toEnable = Standard_True;
5511 if (++anArgIter < theArgNb
5512 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5516 aCaps->contextStereo = toEnable;
5520 std::cout << "Error: unknown argument '" << anArg << "'\n";
5524 if (aCaps != &ViewerTest_myDefaultCaps)
5526 ViewerTest_myDefaultCaps = *aCaps;
5531 //==============================================================================
5532 //function : VMemGpu
5534 //==============================================================================
5536 static int VMemGpu (Draw_Interpretor& theDI,
5537 Standard_Integer theArgNb,
5538 const char** theArgVec)
5541 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5542 if (aContextAIS.IsNull())
5544 std::cerr << "No active view. Please call vinit.\n";
5548 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
5549 if (aDriver.IsNull())
5551 std::cerr << "Graphic driver not available.\n";
5555 Standard_Size aFreeBytes = 0;
5556 TCollection_AsciiString anInfo;
5557 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
5559 std::cerr << "Information not available.\n";
5563 if (theArgNb > 1 && *theArgVec[1] == 'f')
5565 theDI << Standard_Real (aFreeBytes);
5575 // ==============================================================================
5576 // function : VReadPixel
5578 // ==============================================================================
5579 static int VReadPixel (Draw_Interpretor& theDI,
5580 Standard_Integer theArgNb,
5581 const char** theArgVec)
5583 // get the active view
5584 Handle(V3d_View) aView = ViewerTest::CurrentView();
5587 std::cerr << "No active view. Please call vinit.\n";
5590 else if (theArgNb < 3)
5592 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
5596 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
5597 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
5599 Standard_Integer aWidth, aHeight;
5600 aView->Window()->Size (aWidth, aHeight);
5601 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
5602 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
5603 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
5605 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
5609 Standard_Boolean toShowName = Standard_False;
5610 Standard_Boolean toShowHls = Standard_False;
5611 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
5613 const char* aParam = theArgVec[anIter];
5614 if ( strcasecmp( aParam, "rgb" ) == 0 )
5616 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
5617 aBufferType = Graphic3d_BT_RGB;
5619 else if ( strcasecmp( aParam, "hls" ) == 0 )
5621 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
5622 aBufferType = Graphic3d_BT_RGB;
5623 toShowHls = Standard_True;
5625 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
5627 aFormat = Image_PixMap::ImgRGBF;
5628 aBufferType = Graphic3d_BT_RGB;
5630 else if ( strcasecmp( aParam, "rgba" ) == 0 )
5632 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
5633 aBufferType = Graphic3d_BT_RGBA;
5635 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
5637 aFormat = Image_PixMap::ImgRGBAF;
5638 aBufferType = Graphic3d_BT_RGBA;
5640 else if ( strcasecmp( aParam, "depth" ) == 0 )
5642 aFormat = Image_PixMap::ImgGrayF;
5643 aBufferType = Graphic3d_BT_Depth;
5645 else if ( strcasecmp( aParam, "name" ) == 0 )
5647 toShowName = Standard_True;
5651 Image_PixMap anImage;
5652 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
5654 std::cerr << "Image allocation failed\n";
5657 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
5659 std::cerr << "Image dump failed\n";
5663 Quantity_Parameter anAlpha;
5664 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
5667 if (aBufferType == Graphic3d_BT_RGBA)
5669 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha;
5673 theDI << Quantity_Color::StringName (aColor.Name());
5678 switch (aBufferType)
5681 case Graphic3d_BT_RGB:
5685 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation();
5689 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue();
5693 case Graphic3d_BT_RGBA:
5695 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha;
5698 case Graphic3d_BT_Depth:
5700 theDI << aColor.Red();
5709 //==============================================================================
5710 //function : VDiffImage
5711 //purpose : The draw-command compares two images.
5712 //==============================================================================
5714 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
5718 theDI << "Not enough arguments.\n";
5723 const char* anImgPathRef = theArgVec[1];
5724 const char* anImgPathNew = theArgVec[2];
5726 // get string tolerance and check its validity
5727 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
5728 if (aTolColor < 0.0)
5730 if (aTolColor > 1.0)
5733 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
5734 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
5736 // image file of difference
5737 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
5739 // compare the images
5740 Image_Diff aComparer;
5741 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
5746 aComparer.SetColorTolerance (aTolColor);
5747 aComparer.SetBorderFilterOn (isBorderFilterOn);
5748 Standard_Integer aDiffColorsNb = aComparer.Compare();
5749 theDI << aDiffColorsNb << "\n";
5751 // save image of difference
5752 if (aDiffColorsNb >0 && aDiffImagePath != NULL)
5754 aComparer.SaveDiffImage (aDiffImagePath);
5760 //=======================================================================
5761 //function : VSelect
5762 //purpose : Emulates different types of selection by mouse:
5763 // 1) single click selection
5764 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
5765 // 3) selection with polygon having corners at
5766 // pixel positions (x1,y1),...,(xn,yn)
5767 // 4) any of these selections with shift button pressed
5768 //=======================================================================
5769 static Standard_Integer VSelect (Draw_Interpretor& di,
5770 Standard_Integer argc,
5775 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
5779 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
5780 if(myAIScontext.IsNull())
5782 di << "use 'vinit' command before " << argv[0] << "\n";
5786 const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1));
5787 Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1;
5788 TCollection_AsciiString anArg;
5789 anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2];
5791 if (anArg == "-allowoverlap")
5793 Standard_Boolean isValidated = isShiftSelection ? argc == 8
5797 di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection";
5801 Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
5802 myAIScontext->MainSelector()->AllowOverlapDetection((Standard_Boolean)isToAllow);
5806 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
5807 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
5810 if(isShiftSelection)
5811 aCurrentEventManager->ShiftSelect();
5813 aCurrentEventManager->Select();
5815 else if(aCoordsNb == 4)
5817 if(isShiftSelection)
5818 aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
5820 aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
5824 TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2);
5826 for(Standard_Integer i=1;i<=aCoordsNb / 2;++i)
5827 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
5829 if(isShiftSelection)
5830 aCurrentEventManager->ShiftSelect(aPolyline);
5832 aCurrentEventManager->Select(aPolyline);
5837 //=======================================================================
5838 //function : VMoveTo
5839 //purpose : Emulates cursor movement to defined pixel position
5840 //=======================================================================
5841 static Standard_Integer VMoveTo (Draw_Interpretor& di,
5842 Standard_Integer argc,
5847 di << "Usage : " << argv[0] << " x y" << "\n";
5851 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5852 if(aContext.IsNull())
5854 di << "use 'vinit' command before " << argv[0] << "\n";
5857 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
5861 //=================================================================================================
5862 //function : VViewParams
5863 //purpose : Gets or sets AIS View characteristics
5864 //=================================================================================================
5865 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5867 Handle(V3d_View) anAISView = ViewerTest::CurrentView();
5868 if (anAISView.IsNull())
5870 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
5876 // print all of the available view parameters
5877 Quantity_Factor anAISViewScale = anAISView->Scale();
5879 Standard_Real anAISViewProjX = 0.0;
5880 Standard_Real anAISViewProjY = 0.0;
5881 Standard_Real anAISViewProjZ = 0.0;
5882 anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
5884 Standard_Real anAISViewUpX = 0.0;
5885 Standard_Real anAISViewUpY = 0.0;
5886 Standard_Real anAISViewUpZ = 0.0;
5887 anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
5889 Standard_Real anAISViewAtX = 0.0;
5890 Standard_Real anAISViewAtY = 0.0;
5891 Standard_Real anAISViewAtZ = 0.0;
5892 anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
5894 Standard_Real anAISViewEyeX = 0.0;
5895 Standard_Real anAISViewEyeY = 0.0;
5896 Standard_Real anAISViewEyeZ = 0.0;
5897 anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ);
5899 theDi << "Scale of current view: " << anAISViewScale << "\n";
5900 theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
5901 theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
5902 theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
5903 theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n";
5907 // -------------------------
5908 // Parse options and values
5909 // -------------------------
5911 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues;
5912 TCollection_AsciiString aParseKey;
5913 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5915 TCollection_AsciiString anArg (theArgVec [anArgIt]);
5917 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
5920 aParseKey.Remove (1);
5921 aParseKey.UpperCase();
5922 aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
5926 if (aParseKey.IsEmpty())
5928 std::cout << theArgVec[0] << ": values should be passed with key.\n";
5929 std::cout << "Type help for more information.\n";
5933 aMapOfKeysByValues(aParseKey)->Append (anArg);
5936 // ---------------------------------------------
5937 // Change or print parameters, order plays role
5938 // ---------------------------------------------
5940 // Check arguments for validity
5941 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues);
5942 for (; aMapIt.More(); aMapIt.Next())
5944 const TCollection_AsciiString& aKey = aMapIt.Key();
5945 const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value();
5947 if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5948 && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5949 && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty()))
5950 && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty()))
5951 && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty()))
5952 && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty()))
5953 && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2))
5955 TCollection_AsciiString aLowerKey;
5958 aLowerKey.LowerCase();
5959 std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n";
5960 std::cout << "Type help for more information.\n";
5965 Handle(TColStd_HSequenceOfAsciiString) aValues;
5967 // Change view parameters in proper order
5968 if (aMapOfKeysByValues.Find ("SCALE", aValues))
5970 if (aValues->IsEmpty())
5972 theDi << "Scale: " << anAISView->Scale() << "\n";
5976 anAISView->SetScale (aValues->Value(1).RealValue());
5979 if (aMapOfKeysByValues.Find ("SIZE", aValues))
5981 if (aValues->IsEmpty())
5983 Standard_Real aSizeX = 0.0;
5984 Standard_Real aSizeY = 0.0;
5985 anAISView->Size (aSizeX, aSizeY);
5986 theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n";
5990 anAISView->SetSize (aValues->Value(1).RealValue());
5993 if (aMapOfKeysByValues.Find ("EYE", aValues))
5995 if (aValues->IsEmpty())
5997 Standard_Real anEyeX = 0.0;
5998 Standard_Real anEyeY = 0.0;
5999 Standard_Real anEyeZ = 0.0;
6000 anAISView->Eye (anEyeX, anEyeY, anEyeZ);
6001 theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n";
6005 anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6008 if (aMapOfKeysByValues.Find ("AT", aValues))
6010 if (aValues->IsEmpty())
6012 Standard_Real anAtX = 0.0;
6013 Standard_Real anAtY = 0.0;
6014 Standard_Real anAtZ = 0.0;
6015 anAISView->At (anAtX, anAtY, anAtZ);
6016 theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n";
6020 anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6023 if (aMapOfKeysByValues.Find ("PROJ", aValues))
6025 if (aValues->IsEmpty())
6027 Standard_Real aProjX = 0.0;
6028 Standard_Real aProjY = 0.0;
6029 Standard_Real aProjZ = 0.0;
6030 anAISView->Proj (aProjX, aProjY, aProjZ);
6031 theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n";
6035 anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6038 if (aMapOfKeysByValues.Find ("UP", aValues))
6040 if (aValues->IsEmpty())
6042 Standard_Real anUpX = 0.0;
6043 Standard_Real anUpY = 0.0;
6044 Standard_Real anUpZ = 0.0;
6045 anAISView->Up (anUpX, anUpY, anUpZ);
6046 theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n";
6050 anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6053 if (aMapOfKeysByValues.Find ("CENTER", aValues))
6055 anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue());
6061 //=======================================================================
6062 //function : VChangeSelected
6063 //purpose : Adds the shape to selection or remove one from it
6064 //=======================================================================
6065 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
6066 Standard_Integer argc,
6071 di<<"Usage : " << argv[0] << " shape \n";
6075 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6076 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
6077 TCollection_AsciiString aName(argv[1]);
6078 Handle(AIS_InteractiveObject) anAISObject;
6080 if(!aMap.IsBound2(aName))
6082 di<<"Use 'vdisplay' before";
6087 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
6088 if(anAISObject.IsNull()){
6089 di<<"No interactive object \n";
6093 aContext->AddOrRemoveSelected(anAISObject);
6098 //=======================================================================
6099 //function : VZClipping
6100 //purpose : Gets or sets ZClipping mode, width and depth
6101 //=======================================================================
6102 static Standard_Integer VZClipping (Draw_Interpretor& di,
6103 Standard_Integer argc,
6108 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6109 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6112 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6113 if(aContext.IsNull())
6115 di << "use 'vinit' command before " << argv[0] << "\n";
6118 Handle(V3d_View) aView = ViewerTest::CurrentView();
6119 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
6122 TCollection_AsciiString aZClippingModeString;
6123 Quantity_Length aDepth, aWidth;
6124 aZClippingMode = aView->ZClipping(aDepth, aWidth);
6125 switch (aZClippingMode)
6128 aZClippingModeString.Copy("OFF");
6131 aZClippingModeString.Copy("BACK");
6134 aZClippingModeString.Copy("FRONT");
6137 aZClippingModeString.Copy("SLICE");
6140 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
6143 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
6144 << "ZClipping depth = " << aDepth << "\n"
6145 << "ZClipping width = " << aWidth << "\n";
6151 Standard_Integer aStatus = 0;
6152 if ( strcmp (argv [1], "OFF") == 0 ) {
6154 aZClippingMode = V3d_OFF;
6156 if ( strcmp (argv [1], "BACK") == 0 ) {
6158 aZClippingMode = V3d_BACK;
6160 if ( strcmp (argv [1], "FRONT") == 0 ) {
6162 aZClippingMode = V3d_FRONT;
6164 if ( strcmp (argv [1], "SLICE") == 0 ) {
6166 aZClippingMode = V3d_SLICE;
6170 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6171 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6174 aView->SetZClippingType(aZClippingMode);
6178 Quantity_Length aDepth = 0., aWidth = 1.;
6181 aDepth = Draw::Atof (argv[1]);
6182 aWidth = Draw::Atof (argv[2]);
6186 aDepth = Draw::Atof (argv[2]);
6187 aWidth = Draw::Atof (argv[3]);
6190 if(aDepth<0. || aDepth>1.)
6192 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6193 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6196 if(aWidth<0. || aWidth>1.)
6198 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6199 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6203 aView->SetZClippingDepth(aDepth);
6204 aView->SetZClippingWidth(aWidth);
6211 //=======================================================================
6212 //function : VNbSelected
6213 //purpose : Returns number of selected objects
6214 //=======================================================================
6215 static Standard_Integer VNbSelected (Draw_Interpretor& di,
6216 Standard_Integer argc,
6221 di << "Usage : " << argv[0] << "\n";
6224 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6225 if(aContext.IsNull())
6227 di << "use 'vinit' command before " << argv[0] << "\n";
6230 di << aContext->NbSelected() << "\n";
6234 //=======================================================================
6235 //function : VAntialiasing
6236 //purpose : Switches altialiasing on or off
6237 //=======================================================================
6238 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
6239 Standard_Integer argc,
6244 di << "Usage : " << argv[0] << " [1|0]" << "\n";
6248 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6249 if(aContext.IsNull())
6251 di << "use 'vinit' command before " << argv[0] << "\n";
6255 Handle(V3d_View) aView = ViewerTest::CurrentView();
6257 if((argc == 2) && (atof(argv[1]) == 0))
6258 aView->SetAntialiasingOff();
6260 aView->SetAntialiasingOn();
6265 //=======================================================================
6266 //function : VPurgeDisplay
6267 //purpose : Switches altialiasing on or off
6268 //=======================================================================
6269 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
6270 Standard_Integer argc,
6275 di << "Usage : " << argv[0] << "\n";
6278 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6279 if (aContext.IsNull())
6281 di << "use 'vinit' command before " << argv[0] << "\n";
6284 aContext->CloseAllContexts(Standard_False);
6285 di << aContext->PurgeDisplay() << "\n";
6289 //=======================================================================
6290 //function : VSetViewSize
6292 //=======================================================================
6293 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
6294 Standard_Integer argc,
6297 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6298 if(aContext.IsNull())
6300 di << "use 'vinit' command before " << argv[0] << "\n";
6305 di<<"Usage : " << argv[0] << " Size\n";
6308 Standard_Real aSize = Draw::Atof (argv[1]);
6311 di<<"Bad Size value : " << aSize << "\n";
6315 Handle(V3d_View) aView = ViewerTest::CurrentView();
6316 aView->SetSize(aSize);
6320 //=======================================================================
6321 //function : VMoveView
6323 //=======================================================================
6324 static Standard_Integer VMoveView (Draw_Interpretor& di,
6325 Standard_Integer argc,
6328 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6329 if(aContext.IsNull())
6331 di << "use 'vinit' command before " << argv[0] << "\n";
6334 if(argc < 4 || argc > 5)
6336 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
6339 Standard_Real Dx = Draw::Atof (argv[1]);
6340 Standard_Real Dy = Draw::Atof (argv[2]);
6341 Standard_Real Dz = Draw::Atof (argv[3]);
6342 Standard_Boolean aStart = Standard_True;
6345 aStart = (Draw::Atoi (argv[4]) > 0);
6348 Handle(V3d_View) aView = ViewerTest::CurrentView();
6349 aView->Move(Dx,Dy,Dz,aStart);
6353 //=======================================================================
6354 //function : VTranslateView
6356 //=======================================================================
6357 static Standard_Integer VTranslateView (Draw_Interpretor& di,
6358 Standard_Integer argc,
6361 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6362 if(aContext.IsNull())
6364 di << "use 'vinit' command before " << argv[0] << "\n";
6367 if(argc < 4 || argc > 5)
6369 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
6372 Standard_Real Dx = Draw::Atof (argv[1]);
6373 Standard_Real Dy = Draw::Atof (argv[2]);
6374 Standard_Real Dz = Draw::Atof (argv[3]);
6375 Standard_Boolean aStart = Standard_True;
6378 aStart = (Draw::Atoi (argv[4]) > 0);
6381 Handle(V3d_View) aView = ViewerTest::CurrentView();
6382 aView->Translate(Dx,Dy,Dz,aStart);
6386 //=======================================================================
6387 //function : VTurnView
6389 //=======================================================================
6390 static Standard_Integer VTurnView (Draw_Interpretor& di,
6391 Standard_Integer argc,
6394 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6395 if(aContext.IsNull()) {
6396 di << "use 'vinit' command before " << argv[0] << "\n";
6399 if(argc < 4 || argc > 5){
6400 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
6403 Standard_Real Ax = Draw::Atof (argv[1]);
6404 Standard_Real Ay = Draw::Atof (argv[2]);
6405 Standard_Real Az = Draw::Atof (argv[3]);
6406 Standard_Boolean aStart = Standard_True;
6409 aStart = (Draw::Atoi (argv[4]) > 0);
6412 Handle(V3d_View) aView = ViewerTest::CurrentView();
6413 aView->Turn(Ax,Ay,Az,aStart);
6417 //==============================================================================
6418 //function : VTextureEnv
6419 //purpose : ENables or disables environment mapping
6420 //==============================================================================
6421 class OCC_TextureEnv : public Graphic3d_TextureEnv
6424 OCC_TextureEnv(const Standard_CString FileName);
6425 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
6426 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
6427 const Standard_Boolean theModulateFlag,
6428 const Graphic3d_TypeOfTextureFilter theFilter,
6429 const Standard_ShortReal theXScale,
6430 const Standard_ShortReal theYScale,
6431 const Standard_ShortReal theXShift,
6432 const Standard_ShortReal theYShift,
6433 const Standard_ShortReal theAngle);
6434 DEFINE_STANDARD_RTTI(OCC_TextureEnv, Graphic3d_TextureEnv);
6436 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
6441 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
6442 : Graphic3d_TextureEnv(theFileName)
6446 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
6447 : Graphic3d_TextureEnv(theTexId)
6451 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
6452 const Standard_Boolean theModulateFlag,
6453 const Graphic3d_TypeOfTextureFilter theFilter,
6454 const Standard_ShortReal theXScale,
6455 const Standard_ShortReal theYScale,
6456 const Standard_ShortReal theXShift,
6457 const Standard_ShortReal theYShift,
6458 const Standard_ShortReal theAngle)
6460 myParams->SetRepeat (theRepeatFlag);
6461 myParams->SetModulate (theModulateFlag);
6462 myParams->SetFilter (theFilter);
6463 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
6464 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
6465 myParams->SetRotation (theAngle);
6468 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
6470 // get the active view
6471 Handle(V3d_View) aView = ViewerTest::CurrentView();
6474 std::cerr << "No active view. Please call vinit.\n";
6478 // Checking the input arguments
6479 Standard_Boolean anEnableFlag = Standard_False;
6480 Standard_Boolean isOk = theArgNb >= 2;
6483 TCollection_AsciiString anEnableOpt(theArgVec[1]);
6484 anEnableFlag = anEnableOpt.IsEqual("on");
6485 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
6489 isOk = (theArgNb == 3 || theArgNb == 11);
6492 TCollection_AsciiString aTextureOpt(theArgVec[2]);
6493 isOk = (!aTextureOpt.IsIntegerValue() ||
6494 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
6496 if (isOk && theArgNb == 11)
6498 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
6499 aModulateOpt(theArgVec[4]),
6500 aFilterOpt (theArgVec[5]),
6501 aSScaleOpt (theArgVec[6]),
6502 aTScaleOpt (theArgVec[7]),
6503 aSTransOpt (theArgVec[8]),
6504 aTTransOpt (theArgVec[9]),
6505 anAngleOpt (theArgVec[10]);
6506 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
6507 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
6508 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
6509 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
6510 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
6511 anAngleOpt.IsRealValue());
6518 std::cerr << "Usage :" << std::endl;
6519 std::cerr << theArgVec[0] << " off" << std::endl;
6520 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;
6526 TCollection_AsciiString aTextureOpt(theArgVec[2]);
6527 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
6528 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
6529 new OCC_TextureEnv(theArgVec[2]);
6533 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
6534 aTexEnv->SetTextureParameters(
6535 aRepeatOpt. IsEqual("repeat"),
6536 aModulateOpt.IsEqual("modulate"),
6537 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
6538 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
6539 Graphic3d_TOTF_TRILINEAR,
6540 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
6541 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
6542 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
6543 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
6544 (Standard_ShortReal)Draw::Atof(theArgVec[10])
6547 aView->SetTextureEnv(aTexEnv);
6548 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
6550 else // Disabling environment mapping
6552 aView->SetSurfaceDetail(V3d_TEX_NONE);
6553 Handle(Graphic3d_TextureEnv) aTexture;
6554 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
6561 //===============================================================================================
6562 //function : VClipPlane
6564 //===============================================================================================
6565 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6567 // use short-cut for created clip planes map of created (or "registered by name") clip planes
6568 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
6569 static MapOfPlanes aRegPlanes;
6573 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
6577 TCollection_AsciiString aCommand (theArgVec[1]);
6579 // print maximum number of planes for current viewer
6580 if (aCommand == "maxplanes")
6584 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
6588 TCollection_AsciiString aViewName (theArgVec[2]);
6590 if (!ViewerTest_myViews.IsBound1 (aViewName))
6592 theDi << theArgVec[0] << ": view is not found.\n";
6596 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
6598 theDi << theArgVec[0] << ": "
6599 << aView->Viewer()->Driver()->InquirePlaneLimit()
6600 << " plane slots provided by driver."
6601 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
6606 // create / delete plane instance
6607 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
6611 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
6615 Standard_Boolean toCreate = (aCommand == "create");
6616 Standard_Boolean toClone = (aCommand == "clone");
6617 TCollection_AsciiString aPlane (theArgVec[2]);
6621 if (aRegPlanes.IsBound (aPlane))
6623 theDi << theArgVec[0] << ": plane name is in use.\n";
6627 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
6629 else if (toClone) // toClone
6631 if (!aRegPlanes.IsBound (aPlane))
6633 theDi << theArgVec[0] << ": no such plane.\n";
6639 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
6643 TCollection_AsciiString aClone (theArgVec[3]);
6644 if (aRegPlanes.IsBound (aClone))
6646 theDi << theArgVec[0] << ": plane name is in use.\n";
6650 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6652 aRegPlanes.Bind (aClone, aClipPlane->Clone());
6656 if (!aRegPlanes.IsBound (aPlane))
6658 theDi << theArgVec[0] << ": no such plane.\n";
6662 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
6663 aRegPlanes.UnBind (aPlane);
6665 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
6666 for (; anIObjIt.More(); anIObjIt.Next())
6668 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
6669 aPrs->RemoveClipPlane(aClipPlane);
6672 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
6673 for (; aViewIt.More(); aViewIt.Next())
6675 const Handle(V3d_View)& aView = aViewIt.Key2();
6676 aView->RemoveClipPlane(aClipPlane);
6679 ViewerTest::RedrawAllViews();
6685 // set / unset plane command
6686 if (aCommand == "set" || aCommand == "unset")
6690 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6694 Standard_Boolean toSet = (aCommand == "set");
6695 TCollection_AsciiString aPlane (theArgVec [2]);
6696 if (!aRegPlanes.IsBound (aPlane))
6698 theDi << theArgVec[0] << ": no such plane.\n";
6702 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6704 TCollection_AsciiString aTarget (theArgVec [3]);
6705 if (aTarget != "object" && aTarget != "view")
6707 theDi << theArgVec[0] << ": invalid target.\n";
6711 if (aTarget == "object" || aTarget == "view")
6715 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6719 Standard_Boolean isObject = (aTarget == "object");
6721 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
6723 TCollection_AsciiString anEntityName (theArgVec[anIt]);
6724 if (isObject) // to object
6726 if (!GetMapOfAIS().IsBound2 (anEntityName))
6728 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
6732 Handle(AIS_InteractiveObject) aIObj =
6733 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
6736 aIObj->AddClipPlane (aClipPlane);
6738 aIObj->RemoveClipPlane (aClipPlane);
6742 if (!ViewerTest_myViews.IsBound1 (anEntityName))
6744 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
6748 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
6750 aView->AddClipPlane (aClipPlane);
6752 aView->RemoveClipPlane (aClipPlane);
6756 ViewerTest::RedrawAllViews();
6762 // change plane command
6763 if (aCommand == "change")
6767 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6771 TCollection_AsciiString aPlane (theArgVec [2]);
6772 if (!aRegPlanes.IsBound (aPlane))
6774 theDi << theArgVec[0] << ": no such plane.\n";
6778 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6780 TCollection_AsciiString aChangeArg (theArgVec [3]);
6781 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
6783 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
6787 if (aChangeArg == "on" || aChangeArg == "off") // on / off
6789 aClipPlane->SetOn (aChangeArg == "on");
6791 else if (aChangeArg == "equation") // change equation
6795 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6799 Standard_Real aCoeffA = Draw::Atof (theArgVec [4]);
6800 Standard_Real aCoeffB = Draw::Atof (theArgVec [5]);
6801 Standard_Real aCoeffC = Draw::Atof (theArgVec [6]);
6802 Standard_Real aCoeffD = Draw::Atof (theArgVec [7]);
6803 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
6805 else if (aChangeArg == "capping") // change capping aspects
6809 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6813 TCollection_AsciiString aCappingArg (theArgVec [4]);
6814 if (aCappingArg != "on" && aCappingArg != "off" &&
6815 aCappingArg != "color" && aCappingArg != "texname" &&
6816 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
6817 aCappingArg != "texrotate" && aCappingArg != "hatch")
6819 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
6823 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
6825 aClipPlane->SetCapping (aCappingArg == "on");
6827 else if (aCappingArg == "color") // color aspect for capping
6831 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6835 Standard_Real aRed = Draw::Atof (theArgVec [5]);
6836 Standard_Real aGrn = Draw::Atof (theArgVec [6]);
6837 Standard_Real aBlu = Draw::Atof (theArgVec [7]);
6839 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
6840 Quantity_Color aColor (aRed, aGrn, aBlu, Quantity_TOC_RGB);
6841 aMat.SetAmbientColor (aColor);
6842 aMat.SetDiffuseColor (aColor);
6843 aClipPlane->SetCappingMaterial (aMat);
6845 else if (aCappingArg == "texname") // texture name
6849 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6853 TCollection_AsciiString aTextureName (theArgVec [5]);
6855 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
6856 if (!aTexture->IsDone ())
6858 aClipPlane->SetCappingTexture (NULL);
6862 aTexture->EnableModulate();
6863 aTexture->EnableRepeat();
6864 aClipPlane->SetCappingTexture (aTexture);
6867 else if (aCappingArg == "texscale") // texture scale
6869 if (aClipPlane->CappingTexture().IsNull())
6871 theDi << theArgVec[0] << ": no texture is set.\n";
6877 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6881 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
6882 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
6884 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
6886 else if (aCappingArg == "texorigin") // texture origin
6888 if (aClipPlane->CappingTexture().IsNull())
6890 theDi << theArgVec[0] << ": no texture is set.\n";
6896 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6900 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
6901 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
6903 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
6905 else if (aCappingArg == "texrotate") // texture rotation
6907 if (aClipPlane->CappingTexture().IsNull())
6909 theDi << theArgVec[0] << ": no texture is set.\n";
6915 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6919 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
6921 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
6923 else if (aCappingArg == "hatch") // hatch style
6927 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6931 TCollection_AsciiString aHatchStr (theArgVec [5]);
6932 if (aHatchStr == "on")
6934 aClipPlane->SetCappingHatchOn();
6936 else if (aHatchStr == "off")
6938 aClipPlane->SetCappingHatchOff();
6942 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
6947 ViewerTest::RedrawAllViews();
6952 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
6956 //===============================================================================================
6957 //function : VSetTextureMode
6959 //===============================================================================================
6960 static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6964 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
6968 TCollection_AsciiString aViewName (theArgVec[1]);
6969 if (!ViewerTest_myViews.IsBound1 (aViewName))
6971 theDi << theArgVec[0] << ": view is not found.\n";
6975 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
6976 switch (atoi (theArgVec[2]))
6978 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
6979 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
6980 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
6982 theDi << theArgVec[0] << ": invalid mode.\n";
6990 //===============================================================================================
6991 //function : VZRange
6993 //===============================================================================================
6994 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6996 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
6998 if (aCurrentView.IsNull())
7000 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
7004 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
7008 theDi << "ZNear: " << aCamera->ZNear() << "\n";
7009 theDi << "ZFar: " << aCamera->ZFar() << "\n";
7015 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
7016 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
7018 if (aNewZNear >= aNewZFar)
7020 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
7024 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
7026 std::cout << theArgVec[0] << ": invalid arguments: ";
7027 std::cout << "znear, zfar should be positive for perspective camera.\n";
7031 aCamera->SetZRange (aNewZNear, aNewZFar);
7035 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
7039 aCurrentView->Redraw();
7044 //===============================================================================================
7045 //function : VAutoZFit
7047 //===============================================================================================
7048 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7050 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
7052 if (aCurrentView.IsNull())
7054 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
7058 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
7062 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
7068 theDi << "Auto z-fit mode: " << "\n"
7069 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
7070 << "Scale: " << aScale << "\n";
7074 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
7078 aScale = Draw::Atoi (theArgVec[2]);
7081 aCurrentView->SetAutoZFitMode (isOn, aScale);
7082 aCurrentView->AutoZFit();
7083 aCurrentView->Redraw();
7088 //! Auxiliary function to print projection type
7089 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
7091 switch (theProjType)
7093 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
7094 case Graphic3d_Camera::Projection_Perspective: return "perspective";
7095 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
7096 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
7097 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
7102 //===============================================================================================
7103 //function : VCamera
7105 //===============================================================================================
7106 static int VCamera (Draw_Interpretor& theDI,
7107 Standard_Integer theArgsNb,
7108 const char** theArgVec)
7110 Handle(V3d_View) aView = ViewerTest::CurrentView();
7113 std::cout << "Error: no active view.\n";
7117 Handle(Graphic3d_Camera) aCamera = aView->Camera();
7120 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
7121 theDI << "FOVy: " << aCamera->FOVy() << "\n";
7122 theDI << "Distance: " << aCamera->Distance() << "\n";
7123 theDI << "IOD: " << aCamera->IOD() << "\n";
7124 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
7125 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
7126 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
7130 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7132 Standard_CString anArg = theArgVec[anArgIter];
7133 TCollection_AsciiString anArgCase (anArg);
7134 anArgCase.LowerCase();
7135 if (anArgCase == "-proj"
7136 || anArgCase == "-projection"
7137 || anArgCase == "-projtype"
7138 || anArgCase == "-projectiontype")
7140 theDI << projTypeName (aCamera->ProjectionType()) << " ";
7142 else if (anArgCase == "-ortho"
7143 || anArgCase == "-orthographic")
7145 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
7147 else if (anArgCase == "-persp"
7148 || anArgCase == "-perspective"
7149 || anArgCase == "-perspmono"
7150 || anArgCase == "-perspectivemono"
7151 || anArgCase == "-mono")
7153 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
7155 else if (anArgCase == "-stereo"
7156 || anArgCase == "-stereoscopic"
7157 || anArgCase == "-perspstereo"
7158 || anArgCase == "-perspectivestereo")
7160 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7162 else if (anArgCase == "-left"
7163 || anArgCase == "-lefteye"
7164 || anArgCase == "-monoleft"
7165 || anArgCase == "-monolefteye"
7166 || anArgCase == "-perpsleft"
7167 || anArgCase == "-perpslefteye")
7169 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
7171 else if (anArgCase == "-right"
7172 || anArgCase == "-righteye"
7173 || anArgCase == "-monoright"
7174 || anArgCase == "-monorighteye"
7175 || anArgCase == "-perpsright")
7177 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
7179 else if (anArgCase == "-dist"
7180 || anArgCase == "-distance")
7182 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7183 if (anArgValue != NULL
7184 && *anArgValue != '-')
7187 aCamera->SetDistance (Draw::Atof (anArgValue));
7190 theDI << aCamera->Distance() << " ";
7192 else if (anArgCase == "-iod")
7194 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7195 if (anArgValue != NULL
7196 && *anArgValue != '-')
7199 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
7202 theDI << aCamera->IOD() << " ";
7204 else if (anArgCase == "-iodtype")
7206 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
7207 TCollection_AsciiString anValueCase (anArgValue);
7208 anValueCase.LowerCase();
7209 if (anValueCase == "abs"
7210 || anValueCase == "absolute")
7213 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
7216 else if (anValueCase == "rel"
7217 || anValueCase == "relative")
7220 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
7223 else if (*anArgValue != '-')
7225 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
7228 switch (aCamera->GetIODType())
7230 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
7231 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
7234 else if (anArgCase == "-zfocus")
7236 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7237 if (anArgValue != NULL
7238 && *anArgValue != '-')
7241 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
7244 theDI << aCamera->ZFocus() << " ";
7246 else if (anArgCase == "-zfocustype")
7248 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
7249 TCollection_AsciiString anValueCase (anArgValue);
7250 anValueCase.LowerCase();
7251 if (anValueCase == "abs"
7252 || anValueCase == "absolute")
7255 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
7258 else if (anValueCase == "rel"
7259 || anValueCase == "relative")
7262 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
7265 else if (*anArgValue != '-')
7267 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
7270 switch (aCamera->ZFocusType())
7272 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
7273 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
7276 else if (anArgCase == "-fov"
7277 || anArgCase == "-fovy")
7279 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7280 if (anArgValue != NULL
7281 && *anArgValue != '-')
7284 aCamera->SetFOVy (Draw::Atof (anArgValue));
7287 theDI << aCamera->FOVy() << " ";
7291 std::cout << "Error: unknown argument '" << anArg << "'\n";
7302 //! Parse stereo output mode
7303 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
7304 Graphic3d_StereoMode& theMode)
7306 TCollection_AsciiString aFlag (theArg);
7308 if (aFlag == "quadbuffer")
7310 theMode = Graphic3d_StereoMode_QuadBuffer;
7312 else if (aFlag == "anaglyph")
7314 theMode = Graphic3d_StereoMode_Anaglyph;
7316 else if (aFlag == "row"
7317 || aFlag == "rowinterlaced")
7319 theMode = Graphic3d_StereoMode_RowInterlaced;
7321 else if (aFlag == "col"
7322 || aFlag == "colinterlaced"
7323 || aFlag == "columninterlaced")
7325 theMode = Graphic3d_StereoMode_ColumnInterlaced;
7327 else if (aFlag == "chess"
7328 || aFlag == "chessboard")
7330 theMode = Graphic3d_StereoMode_ChessBoard;
7332 else if (aFlag == "sbs"
7333 || aFlag == "sidebyside")
7335 theMode = Graphic3d_StereoMode_SideBySide;
7337 else if (aFlag == "ou"
7338 || aFlag == "overunder")
7340 theMode = Graphic3d_StereoMode_OverUnder;
7342 else if (aFlag == "pageflip"
7343 || aFlag == "softpageflip")
7345 theMode = Graphic3d_StereoMode_SoftPageFlip;
7349 return Standard_False;
7351 return Standard_True;
7354 //! Parse anaglyph filter
7355 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
7356 Graphic3d_RenderingParams::Anaglyph& theFilter)
7358 TCollection_AsciiString aFlag (theArg);
7360 if (aFlag == "redcyansimple")
7362 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
7364 else if (aFlag == "redcyan"
7365 || aFlag == "redcyanoptimized")
7367 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
7369 else if (aFlag == "yellowbluesimple")
7371 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
7373 else if (aFlag == "yellowblue"
7374 || aFlag == "yellowblueoptimized")
7376 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
7378 else if (aFlag == "greenmagenta"
7379 || aFlag == "greenmagentasimple")
7381 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
7385 return Standard_False;
7387 return Standard_True;
7390 //==============================================================================
7391 //function : VStereo
7393 //==============================================================================
7395 static int VStereo (Draw_Interpretor& theDI,
7396 Standard_Integer theArgNb,
7397 const char** theArgVec)
7399 Handle(V3d_View) aView = ViewerTest::CurrentView();
7404 std::cout << "Error: no active viewer!\n";
7408 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
7409 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
7412 TCollection_AsciiString aMode;
7413 switch (aView->RenderingParams().StereoMode)
7415 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
7416 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
7417 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
7418 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
7419 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
7420 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
7421 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
7422 case Graphic3d_StereoMode_Anaglyph :
7424 switch (aView->RenderingParams().AnaglyphFilter)
7426 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
7427 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
7428 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
7429 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
7430 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
7435 theDI << "Mode " << aMode << "\n";
7440 Handle(Graphic3d_Camera) aCamera;
7441 Graphic3d_RenderingParams* aParams = NULL;
7442 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
7443 if (!aView.IsNull())
7445 aParams = &aView->ChangeRenderingParams();
7446 aMode = aParams->StereoMode;
7447 aCamera = aView->Camera();
7450 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7451 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7453 Standard_CString anArg = theArgVec[anArgIter];
7454 TCollection_AsciiString aFlag (anArg);
7456 if (anUpdateTool.parseRedrawMode (aFlag))
7460 else if (aFlag == "0"
7463 if (++anArgIter < theArgNb)
7465 std::cout << "Error: wrong number of arguments!\n";
7469 if (!aCamera.IsNull()
7470 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
7472 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
7474 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
7477 else if (aFlag == "1"
7480 if (++anArgIter < theArgNb)
7482 std::cout << "Error: wrong number of arguments!\n";
7486 if (!aCamera.IsNull())
7488 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7490 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
7493 else if (aFlag == "-reverse"
7494 || aFlag == "-reversed"
7495 || aFlag == "-swap")
7497 Standard_Boolean toEnable = Standard_True;
7498 if (++anArgIter < theArgNb
7499 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
7503 aParams->ToReverseStereo = toEnable;
7505 else if (aFlag == "-noreverse"
7506 || aFlag == "-noswap")
7508 Standard_Boolean toDisable = Standard_True;
7509 if (++anArgIter < theArgNb
7510 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
7514 aParams->ToReverseStereo = !toDisable;
7516 else if (aFlag == "-mode"
7517 || aFlag == "-stereomode")
7519 if (++anArgIter >= theArgNb
7520 || !parseStereoMode (theArgVec[anArgIter], aMode))
7522 std::cout << "Error: syntax error at '" << anArg << "'\n";
7526 if (aMode == Graphic3d_StereoMode_QuadBuffer)
7528 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
7531 else if (aFlag == "-anaglyph"
7532 || aFlag == "-anaglyphfilter")
7534 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
7535 if (++anArgIter >= theArgNb
7536 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
7538 std::cout << "Error: syntax error at '" << anArg << "'\n";
7542 aMode = Graphic3d_StereoMode_Anaglyph;
7543 aParams->AnaglyphFilter = aFilter;
7545 else if (parseStereoMode (anArg, aMode)) // short syntax
7547 if (aMode == Graphic3d_StereoMode_QuadBuffer)
7549 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
7554 std::cout << "Error: syntax error at '" << anArg << "'\n";
7559 if (!aView.IsNull())
7561 aParams->StereoMode = aMode;
7562 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7567 //===============================================================================================
7568 //function : VDefaults
7570 //===============================================================================================
7571 static int VDefaults (Draw_Interpretor& theDi,
7572 Standard_Integer theArgsNb,
7573 const char** theArgVec)
7575 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
7578 std::cerr << "No active viewer!\n";
7582 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
7585 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
7587 theDi << "DeflType: relative\n"
7588 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
7592 theDi << "DeflType: absolute\n"
7593 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
7595 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
7596 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
7600 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7602 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7604 if (anArg == "-ABSDEFL"
7605 || anArg == "-ABSOLUTEDEFLECTION"
7607 || anArg == "-DEFLECTION")
7609 if (++anArgIter >= theArgsNb)
7611 std::cout << "Error: wrong syntax at " << anArg << "\n";
7614 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
7615 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
7617 else if (anArg == "-RELDEFL"
7618 || anArg == "-RELATIVEDEFLECTION"
7619 || anArg == "-DEVCOEFF"
7620 || anArg == "-DEVIATIONCOEFF"
7621 || anArg == "-DEVIATIONCOEFFICIENT")
7623 if (++anArgIter >= theArgsNb)
7625 std::cout << "Error: wrong syntax at " << anArg << "\n";
7628 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
7629 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
7631 else if (anArg == "-ANGDEFL"
7632 || anArg == "-ANGULARDEFL"
7633 || anArg == "-ANGULARDEFLECTION")
7635 if (++anArgIter >= theArgsNb)
7637 std::cout << "Error: wrong syntax at " << anArg << "\n";
7640 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
7641 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
7643 else if (anArg == "-AUTOTR"
7644 || anArg == "-AUTOTRIANG"
7645 || anArg == "-AUTOTRIANGULATION")
7647 if (++anArgIter >= theArgsNb)
7649 std::cout << "Error: wrong syntax at " << anArg << "\n";
7652 TCollection_AsciiString aValue (theArgVec[anArgIter]);
7657 aDefParams->SetAutoTriangulation (Standard_True);
7659 else if (aValue == "off"
7662 aDefParams->SetAutoTriangulation (Standard_False);
7667 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
7674 //! Auxiliary method
7675 inline void addLight (const Handle(V3d_Light)& theLightNew,
7676 const Standard_Boolean theIsGlobal)
7678 if (theLightNew.IsNull())
7685 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
7689 ViewerTest::CurrentView()->SetLightOn (theLightNew);
7693 //! Auxiliary method
7694 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
7696 TCollection_AsciiString anArgNextCase (theArgNext);
7697 anArgNextCase.UpperCase();
7698 if (anArgNextCase.Length() > 5
7699 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
7701 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
7705 return theArgNext.IntegerValue();
7709 //===============================================================================================
7712 //===============================================================================================
7713 static int VLight (Draw_Interpretor& theDi,
7714 Standard_Integer theArgsNb,
7715 const char** theArgVec)
7717 Handle(V3d_View) aView = ViewerTest::CurrentView();
7718 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
7720 || aViewer.IsNull())
7722 std::cerr << "No active viewer!\n";
7726 Standard_Real anXYZ[3];
7727 Quantity_Coefficient anAtten[2];
7730 // print lights info
7731 Standard_Integer aLightId = 0;
7732 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId)
7734 Handle(V3d_Light) aLight = aView->ActiveLight();
7735 const Quantity_Color aColor = aLight->Color();
7736 theDi << "Light" << aLightId << "\n";
7737 switch (aLight->Type())
7741 theDi << " Type: Ambient\n";
7742 theDi << " Intensity: " << aLight->Intensity() << "\n";
7745 case V3d_DIRECTIONAL:
7747 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
7748 theDi << " Type: Directional\n";
7749 theDi << " Intensity: " << aLight->Intensity() << "\n";
7750 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7751 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
7752 if (!aLightDir.IsNull())
7754 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7755 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7756 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
7757 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7761 case V3d_POSITIONAL:
7763 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
7764 theDi << " Type: Positional\n";
7765 theDi << " Intensity: " << aLight->Intensity() << "\n";
7766 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7767 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
7768 if (!aLightPos.IsNull())
7770 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7771 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7772 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7773 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
7779 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
7780 theDi << " Type: Spot\n";
7781 theDi << " Intensity: " << aLight->Intensity() << "\n";
7782 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7783 if (!aLightSpot.IsNull())
7785 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7786 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7787 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
7788 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7789 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7790 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
7791 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
7792 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
7798 theDi << " Type: UNKNOWN\n";
7802 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
7806 Handle(V3d_Light) aLightNew;
7807 Handle(V3d_Light) aLightOld;
7808 Standard_Boolean isGlobal = Standard_True;
7809 Standard_Boolean toCreate = Standard_False;
7810 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
7812 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
7813 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
7814 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
7815 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
7816 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
7818 TCollection_AsciiString aName, aValue;
7819 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
7820 TCollection_AsciiString anArgCase (anArg);
7821 anArgCase.UpperCase();
7822 if (anArgCase.IsEqual ("NEW")
7823 || anArgCase.IsEqual ("ADD")
7824 || anArgCase.IsEqual ("CREATE"))
7826 toCreate = Standard_True;
7828 else if (anArgCase.IsEqual ("GLOB")
7829 || anArgCase.IsEqual ("GLOBAL"))
7831 isGlobal = Standard_True;
7833 else if (anArgCase.IsEqual ("LOC")
7834 || anArgCase.IsEqual ("LOCAL"))
7836 isGlobal = Standard_False;
7838 else if (anArgCase.IsEqual ("DEF")
7839 || anArgCase.IsEqual ("DEFAULTS"))
7841 toCreate = Standard_False;
7842 aViewer->SetDefaultLights();
7844 else if (anArgCase.IsEqual ("CLR")
7845 || anArgCase.IsEqual ("CLEAR"))
7847 toCreate = Standard_False;
7848 aView->InitActiveLights();
7849 while (aView->MoreActiveLights())
7851 aViewer->DelLight (aView->ActiveLight());
7852 aView->InitActiveLights();
7855 else if (anArgCase.IsEqual ("AMB")
7856 || anArgCase.IsEqual ("AMBIENT")
7857 || anArgCase.IsEqual ("AMBLIGHT"))
7859 addLight (aLightNew, isGlobal);
7862 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7865 toCreate = Standard_False;
7866 aLightNew = new V3d_AmbientLight (aViewer);
7868 else if (anArgCase.IsEqual ("DIRECTIONAL")
7869 || anArgCase.IsEqual ("DIRLIGHT"))
7871 addLight (aLightNew, isGlobal);
7874 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7877 toCreate = Standard_False;
7878 aLightNew = new V3d_DirectionalLight (aViewer);
7880 else if (anArgCase.IsEqual ("SPOT")
7881 || anArgCase.IsEqual ("SPOTLIGHT"))
7883 addLight (aLightNew, isGlobal);
7886 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7889 toCreate = Standard_False;
7890 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
7892 else if (anArgCase.IsEqual ("POSLIGHT")
7893 || anArgCase.IsEqual ("POSITIONAL"))
7895 addLight (aLightNew, isGlobal);
7898 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7901 toCreate = Standard_False;
7902 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
7904 else if (anArgCase.IsEqual ("CHANGE"))
7906 addLight (aLightNew, isGlobal);
7907 aLightNew.Nullify();
7908 if (++anArgIt >= theArgsNb)
7910 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7914 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
7915 Standard_Integer aLightIt = 0;
7916 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
7918 if (aLightIt == aLightId)
7920 aLightOld = aView->ActiveLight();
7925 if (aLightOld.IsNull())
7927 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
7931 else if (anArgCase.IsEqual ("DEL")
7932 || anArgCase.IsEqual ("DELETE"))
7934 Handle(V3d_Light) aLightDel;
7935 if (++anArgIt >= theArgsNb)
7937 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7941 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
7942 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
7943 Standard_Integer aLightIt = 0;
7944 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
7946 aLightDel = aView->ActiveLight();
7947 if (aLightIt == aLightDelId)
7952 if (!aLightDel.IsNull())
7954 aViewer->DelLight (aLightDel);
7957 else if (anArgCase.IsEqual ("COLOR")
7958 || anArgCase.IsEqual ("COLOUR"))
7960 if (++anArgIt >= theArgsNb)
7962 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7966 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
7967 anArgNext.UpperCase();
7968 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
7969 if (!aLightCurr.IsNull())
7971 aLightCurr->SetColor (aColor);
7974 else if (anArgCase.IsEqual ("POS")
7975 || anArgCase.IsEqual ("POSITION"))
7977 if ((anArgIt + 3) >= theArgsNb)
7979 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7983 anXYZ[0] = Atof (theArgVec[++anArgIt]);
7984 anXYZ[1] = Atof (theArgVec[++anArgIt]);
7985 anXYZ[2] = Atof (theArgVec[++anArgIt]);
7986 if (!aLightDir.IsNull())
7988 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7990 else if (!aLightPos.IsNull())
7992 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7994 else if (!aLightSpot.IsNull())
7996 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
8000 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8004 else if (anArgCase.IsEqual ("DIR")
8005 || anArgCase.IsEqual ("DIRECTION"))
8007 if ((anArgIt + 3) >= theArgsNb)
8009 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8013 anXYZ[0] = Atof (theArgVec[++anArgIt]);
8014 anXYZ[1] = Atof (theArgVec[++anArgIt]);
8015 anXYZ[2] = Atof (theArgVec[++anArgIt]);
8016 if (!aLightDir.IsNull())
8018 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
8020 else if (!aLightSpot.IsNull())
8022 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
8026 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8030 else if (anArgCase.IsEqual ("SM")
8031 || anArgCase.IsEqual ("SMOOTHNESS"))
8033 if (++anArgIt >= theArgsNb)
8035 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8039 Standard_Real aSmoothness = Atof (theArgVec[anArgIt]);
8041 if (fabs (aSmoothness) < Precision::Confusion())
8043 aLightCurr->SetIntensity (1.f);
8045 else if (fabs (aLightCurr->Smoothness()) < Precision::Confusion())
8047 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
8051 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
8052 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
8055 if (!aLightPos.IsNull())
8057 aLightPos->SetSmoothRadius (aSmoothness);
8059 else if (!aLightDir.IsNull())
8061 aLightDir->SetSmoothAngle (aSmoothness);
8064 else if (anArgCase.IsEqual ("INT")
8065 || anArgCase.IsEqual ("INTENSITY"))
8067 if (++anArgIt >= theArgsNb)
8069 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8073 Standard_Real aIntensity = Atof (theArgVec[anArgIt]);
8075 if (!aLightCurr.IsNull())
8077 aLightCurr->SetIntensity (aIntensity);
8080 else if (anArgCase.IsEqual ("ANG")
8081 || anArgCase.IsEqual ("ANGLE"))
8083 if (++anArgIt >= theArgsNb)
8085 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8089 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
8091 if (!aLightSpot.IsNull())
8093 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
8096 else if (anArgCase.IsEqual ("CONSTATTEN")
8097 || anArgCase.IsEqual ("CONSTATTENUATION"))
8099 if (++anArgIt >= theArgsNb)
8101 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8105 if (!aLightPos.IsNull())
8107 aLightPos->Attenuation (anAtten[0], anAtten[1]);
8108 anAtten[0] = Atof (theArgVec[anArgIt]);
8109 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
8111 else if (!aLightSpot.IsNull())
8113 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
8114 anAtten[0] = Atof (theArgVec[anArgIt]);
8115 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
8119 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8123 else if (anArgCase.IsEqual ("LINATTEN")
8124 || anArgCase.IsEqual ("LINEARATTEN")
8125 || anArgCase.IsEqual ("LINEARATTENUATION"))
8127 if (++anArgIt >= theArgsNb)
8129 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8133 if (!aLightPos.IsNull())
8135 aLightPos->Attenuation (anAtten[0], anAtten[1]);
8136 anAtten[1] = Atof (theArgVec[anArgIt]);
8137 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
8139 else if (!aLightSpot.IsNull())
8141 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
8142 anAtten[1] = Atof (theArgVec[anArgIt]);
8143 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
8147 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8151 else if (anArgCase.IsEqual ("EXP")
8152 || anArgCase.IsEqual ("EXPONENT")
8153 || anArgCase.IsEqual ("SPOTEXP")
8154 || anArgCase.IsEqual ("SPOTEXPONENT"))
8156 if (++anArgIt >= theArgsNb)
8158 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8162 if (!aLightSpot.IsNull())
8164 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
8168 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8172 else if (anArgCase.IsEqual ("HEAD")
8173 || anArgCase.IsEqual ("HEADLIGHT"))
8175 if (++anArgIt >= theArgsNb)
8177 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8181 if (aLightAmb.IsNull()
8182 && !aLightCurr.IsNull())
8184 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
8188 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8194 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
8198 addLight (aLightNew, isGlobal);
8199 aViewer->UpdateLights();
8204 //=======================================================================
8205 //function : VRenderParams
8206 //purpose : Enables/disables rendering features
8207 //=======================================================================
8209 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
8210 Standard_Integer theArgNb,
8211 const char** theArgVec)
8213 Handle(V3d_View) aView = ViewerTest::CurrentView();
8216 std::cerr << "Error: no active viewer!\n";
8220 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
8221 TCollection_AsciiString aCmdName (theArgVec[0]);
8222 aCmdName.LowerCase();
8223 if (aCmdName == "vraytrace")
8227 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
8230 else if (theArgNb == 2)
8232 TCollection_AsciiString aValue (theArgVec[1]);
8237 aParams.Method = Graphic3d_RM_RAYTRACING;
8241 else if (aValue == "off"
8244 aParams.Method = Graphic3d_RM_RASTERIZATION;
8250 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
8256 std::cout << "Error: wrong number of arguments\n";
8263 theDI << "renderMode: ";
8264 switch (aParams.Method)
8266 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
8267 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
8270 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
8271 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
8272 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
8273 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
8274 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
8275 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
8276 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
8277 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
8278 theDI << "shadingModel: ";
8279 switch (aView->ShadingModel())
8281 case V3d_COLOR: theDI << "color"; break;
8282 case V3d_FLAT: theDI << "flat"; break;
8283 case V3d_GOURAUD: theDI << "gouraud"; break;
8284 case V3d_PHONG: theDI << "phong"; break;
8290 Standard_Boolean toPrint = Standard_False;
8291 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
8292 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
8294 Standard_CString anArg (theArgVec[anArgIter]);
8295 TCollection_AsciiString aFlag (anArg);
8297 if (anUpdateTool.parseRedrawMode (aFlag))
8301 else if (aFlag == "-echo"
8302 || aFlag == "-print")
8304 toPrint = Standard_True;
8305 anUpdateTool.Invalidate();
8307 else if (aFlag == "-mode"
8308 || aFlag == "-rendermode"
8309 || aFlag == "-render_mode")
8313 switch (aParams.Method)
8315 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
8316 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
8322 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8326 else if (aFlag == "-ray"
8327 || aFlag == "-raytrace")
8331 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
8335 aParams.Method = Graphic3d_RM_RAYTRACING;
8337 else if (aFlag == "-rast"
8338 || aFlag == "-raster"
8339 || aFlag == "-rasterization")
8343 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
8347 aParams.Method = Graphic3d_RM_RASTERIZATION;
8349 else if (aFlag == "-msaa")
8353 theDI << aParams.NbMsaaSamples << " ";
8356 else if (++anArgIter >= theArgNb)
8358 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8362 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
8365 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
8370 aParams.NbMsaaSamples = aNbSamples;
8373 else if (aFlag == "-raydepth"
8374 || aFlag == "-ray_depth")
8378 theDI << aParams.RaytracingDepth << " ";
8381 else if (++anArgIter >= theArgNb)
8383 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8387 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
8389 // We allow RaytracingDepth be more than 10 in case of GI enabled
8390 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
8392 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
8397 aParams.RaytracingDepth = aDepth;
8400 else if (aFlag == "-shad"
8401 || aFlag == "-shadows")
8405 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
8409 Standard_Boolean toEnable = Standard_True;
8410 if (++anArgIter < theArgNb
8411 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8415 aParams.IsShadowEnabled = toEnable;
8417 else if (aFlag == "-refl"
8418 || aFlag == "-reflections")
8422 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
8426 Standard_Boolean toEnable = Standard_True;
8427 if (++anArgIter < theArgNb
8428 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8432 aParams.IsReflectionEnabled = toEnable;
8434 else if (aFlag == "-fsaa")
8438 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
8442 Standard_Boolean toEnable = Standard_True;
8443 if (++anArgIter < theArgNb
8444 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8448 aParams.IsAntialiasingEnabled = toEnable;
8450 else if (aFlag == "-gleam")
8454 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
8458 Standard_Boolean toEnable = Standard_True;
8459 if (++anArgIter < theArgNb
8460 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8464 aParams.IsTransparentShadowEnabled = toEnable;
8466 else if (aFlag == "-gi")
8470 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
8474 Standard_Boolean toEnable = Standard_True;
8475 if (++anArgIter < theArgNb
8476 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8480 aParams.IsGlobalIlluminationEnabled = toEnable;
8483 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
8486 else if (aFlag == "-blockedrng"
8487 || aFlag == "-brng")
8491 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
8495 Standard_Boolean toEnable = Standard_True;
8496 if (++anArgIter < theArgNb
8497 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8501 aParams.CoherentPathTracingMode = toEnable;
8503 else if (aFlag == "-env")
8507 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
8511 Standard_Boolean toEnable = Standard_True;
8512 if (++anArgIter < theArgNb
8513 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8517 aParams.UseEnvironmentMapBackground = toEnable;
8519 else if (aFlag == "-shademodel"
8520 || aFlag == "-shadingmodel"
8521 || aFlag == "-shading")
8525 switch (aView->ShadingModel())
8527 case V3d_COLOR: theDI << "color "; break;
8528 case V3d_FLAT: theDI << "flat "; break;
8529 case V3d_GOURAUD: theDI << "gouraud "; break;
8530 case V3d_PHONG: theDI << "phong "; break;
8535 if (++anArgIter >= theArgNb)
8537 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8540 TCollection_AsciiString aMode (theArgVec[anArgIter]);
8542 if (aMode == "color"
8545 aView->SetShadingModel (V3d_COLOR);
8547 else if (aMode == "flat"
8548 || aMode == "facet")
8550 aView->SetShadingModel (V3d_FLAT);
8552 else if (aMode == "gouraud"
8553 || aMode == "vertex"
8556 aView->SetShadingModel (V3d_GOURAUD);
8558 else if (aMode == "phong"
8559 || aMode == "fragment"
8561 || aMode == "pixel")
8563 aView->SetShadingModel (V3d_PHONG);
8567 std::cout << "Error: unknown shading model '" << aMode << "'\n";
8571 else if (aFlag == "-resolution")
8573 if (++anArgIter >= theArgNb)
8575 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8579 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
8580 if (aResolution.IsIntegerValue())
8582 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
8586 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
8592 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
8600 //=======================================================================
8601 //function : VProgressiveMode
8603 //=======================================================================
8605 static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
8606 Standard_Integer /*theNbArgs*/,
8607 const char** /*theArgs*/)
8609 Handle(V3d_View) aView = ViewerTest::CurrentView();
8612 std::cerr << "Error: no active viewer!\n";
8616 std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
8622 Standard_Boolean toExit = Standard_False;
8625 while (PeekMessage (&aMsg, NULL, NULL, NULL, PM_REMOVE))
8627 if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
8629 toExit = Standard_True;
8632 TranslateMessage (&aMsg);
8633 DispatchMessage (&aMsg);
8646 //=======================================================================
8647 //function : VFrustumCulling
8648 //purpose : enables/disables view volume's culling.
8649 //=======================================================================
8650 static int VFrustumCulling (Draw_Interpretor& theDI,
8651 Standard_Integer theArgNb,
8652 const char** theArgVec)
8654 Handle(V3d_View) aView = ViewerTest::CurrentView();
8657 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
8663 theDI << (aView->IsCullingEnabled() ? "on" : "off");
8666 else if (theArgNb != 2)
8668 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
8672 TCollection_AsciiString aModeStr (theArgVec[1]);
8673 aModeStr.LowerCase();
8674 Standard_Boolean toEnable = 0;
8675 if (aModeStr == "on")
8679 else if (aModeStr == "off")
8685 toEnable = Draw::Atoi (theArgVec[1]) != 0;
8688 aView->SetFrustumCulling (toEnable);
8693 //=======================================================================
8694 //function : VHighlightSelected
8696 //=======================================================================
8697 static int VHighlightSelected (Draw_Interpretor& theDI,
8698 Standard_Integer theArgNb,
8699 const char** theArgVec)
8701 if (ViewerTest::GetAISContext().IsNull())
8703 std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n";
8707 const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8711 theDI << (aContext->ToHilightSelected() ? "on" : "off");
8717 std::cout << theArgVec[0] << " error : wrong number of parameters."
8718 << "Type 'help" << theArgVec[0] << "' for more information.";
8723 TCollection_AsciiString aMode (theArgVec[1]);
8725 Standard_Boolean toEnable = Standard_False;
8726 if (aMode.IsEqual ("on"))
8728 toEnable = Standard_True;
8730 else if (aMode.IsEqual ("off"))
8732 toEnable = Standard_False;
8736 toEnable = Draw::Atoi (theArgVec[1]) != 0;
8739 if (toEnable != aContext->ToHilightSelected())
8741 aContext->SetToHilightSelected (toEnable);
8743 // Move cursor to null position and back to process updating of detection
8744 // and highlighting of selected object immediatly.
8745 Standard_Integer aPixX = 0;
8746 Standard_Integer aPixY = 0;
8747 const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager();
8749 anEventManager->GetCurrentPosition (aPixX, aPixY);
8750 anEventManager->MoveTo (0, 0);
8751 anEventManager->MoveTo (aPixX, aPixY);
8757 //=======================================================================
8758 //function : VXRotate
8760 //=======================================================================
8761 static Standard_Integer VXRotate (Draw_Interpretor& di,
8762 Standard_Integer argc,
8765 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8766 if (aContext.IsNull())
8768 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
8774 di << "ERROR : Usage : " << argv[0] << " name angle" << "\n";
8778 TCollection_AsciiString aName (argv[1]);
8779 Standard_Real anAngle = Draw::Atof (argv[2]);
8782 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
8783 Handle(AIS_InteractiveObject) anIObj;
8784 if (!aMap.IsBound2 (aName) )
8786 di << "Use 'vdisplay' before" << "\n";
8791 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
8794 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
8795 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
8797 aContext->SetLocation (anIObj, aTransform);
8798 aContext->UpdateCurrentViewer();
8804 //=======================================================================
8805 //function : ViewerCommands
8807 //=======================================================================
8809 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
8812 const char *group = "ZeViewer";
8813 theCommands.Add("vinit",
8814 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
8815 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
8817 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
8819 " - Creates new View window with specified name view_name.\n"
8820 "By default the new view is created in the viewer and in"
8821 " graphic driver shared with active view.\n"
8822 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
8823 "If driverName isn't specified the driver will be shared with active view.\n"
8824 "If viewerName isn't specified the viewer will be shared with active view.\n"
8825 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
8826 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
8827 "is used in creation of graphic driver\n"
8829 " - l, t: pixel position of left top corner of the window\n"
8830 " - w,h: width and heigth of window respectively.\n"
8831 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
8832 __FILE__,VInit,group);
8833 theCommands.Add("vclose" ,
8834 "[view_id [keep_context=0|1]]\n"
8835 "or vclose ALL - to remove all created views\n"
8836 " - removes view(viewer window) defined by its view_id.\n"
8837 " - keep_context: by default 0; if 1 and the last view is deleted"
8838 " the current context is not removed.",
8839 __FILE__,VClose,group);
8840 theCommands.Add("vactivate" ,
8842 " - activates view(viewer window) defined by its view_id",
8843 __FILE__,VActivate,group);
8844 theCommands.Add("vviewlist",
8845 "vviewlist [format={tree, long}]"
8846 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
8847 " - format: format of result output, if tree the output is a tree view;"
8848 "otherwise it's a list of full view names. By default format = tree",
8849 __FILE__,VViewList,group);
8850 theCommands.Add("vhelp" ,
8851 "vhelp : display help on the viewer commands",
8852 __FILE__,VHelp,group);
8853 theCommands.Add("vtop" ,
8854 "vtop or <T> : Top view. Orientation +X+Y" ,
8855 __FILE__,VTop,group);
8856 theCommands.Add("vbottom" ,
8857 "vbottom : Bottom view. Orientation +X-Y" ,
8858 __FILE__,VBottom,group);
8859 theCommands.Add("vleft" ,
8860 "vleft : Left view. Orientation -Y+Z" ,
8861 __FILE__,VLeft,group);
8862 theCommands.Add("vright" ,
8863 "vright : Right view. Orientation +Y+Z" ,
8864 __FILE__,VRight,group);
8865 theCommands.Add("vaxo" ,
8866 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
8867 __FILE__,VAxo,group);
8868 theCommands.Add("vfront" ,
8869 "vfront : Front view. Orientation +X+Z" ,
8870 __FILE__,VFront,group);
8871 theCommands.Add("vback" ,
8872 "vback : Back view. Orientation -X+Z" ,
8873 __FILE__,VBack,group);
8874 theCommands.Add("vpick" ,
8875 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
8877 theCommands.Add("vfit" ,
8878 "vfit or <F> [-selected]"
8879 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
8880 __FILE__,VFit,group);
8881 theCommands.Add ("vfitarea",
8882 "vfitarea x1 y1 x2 y2"
8883 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
8884 "\n\t\t: Fit view to show area located between two points"
8885 "\n\t\t: given in world 2D or 3D corrdinates.",
8886 __FILE__, VFitArea, group);
8887 theCommands.Add ("vzfit", "vzfit [scale]\n"
8888 " Matches Z near, Z far view volume planes to the displayed objects.\n"
8889 " \"scale\" - specifies factor to scale computed z range.\n",
8890 __FILE__, VZFit, group);
8891 theCommands.Add("vrepaint",
8892 "vrepaint : vrepaint, force redraw",
8893 __FILE__,VRepaint,group);
8894 theCommands.Add("vclear",
8896 "\n\t\t: remove all the object from the viewer",
8897 __FILE__,VClear,group);
8898 theCommands.Add("vsetbg",
8899 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
8900 __FILE__,VSetBg,group);
8901 theCommands.Add("vsetbgmode",
8902 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
8903 __FILE__,VSetBgMode,group);
8904 theCommands.Add("vsetgradientbg",
8905 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
8906 __FILE__,VSetGradientBg,group);
8907 theCommands.Add("vsetgrbgmode",
8908 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
8909 __FILE__,VSetGradientBgMode,group);
8910 theCommands.Add("vsetcolorbg",
8911 "vsetcolorbg : vsetcolorbg r g b : Set background color",
8912 __FILE__,VSetColorBg,group);
8913 theCommands.Add("vsetdefaultbg",
8914 "vsetdefaultbg r g b\n"
8915 "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode"
8916 "\n\t\t: Set default viewer background fill color (flat/gradient).",
8917 __FILE__,VSetDefaultBg,group);
8918 theCommands.Add("vscale",
8919 "vscale : vscale X Y Z",
8920 __FILE__,VScale,group);
8921 theCommands.Add("vzbufftrihedron",
8922 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
8923 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
8924 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
8925 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
8926 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
8927 "\n\t\t: Displays a trihedron",
8928 __FILE__,VZBuffTrihedron,group);
8929 theCommands.Add("vrotate",
8930 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
8931 "\n : Option -mouseStart starts rotation according to the mouse position"
8932 "\n : Option -mouseMove continues rotation with angle computed"
8933 "\n : from last and new mouse position."
8934 "\n : vrotate AX AY AZ [X Y Z]",
8935 __FILE__,VRotate,group);
8936 theCommands.Add("vzoom",
8937 "vzoom : vzoom coef",
8938 __FILE__,VZoom,group);
8939 theCommands.Add("vpan",
8940 "vpan : vpan dx dy",
8941 __FILE__,VPan,group);
8942 theCommands.Add("vexport",
8943 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
8944 " : exports the view to a vector file of a given format"
8945 " : notice that EMF format requires patched gl2ps",
8946 __FILE__,VExport,group);
8947 theCommands.Add("vcolorscale",
8948 "vcolorscale : vcolorscale name [-range RangeMin = 0 RangeMax = 100 Intervals = 10 -font HeightFont = 16 -textpos "
8949 "Position = left -xy X = 0 Y = 0] [-noupdate|-update]: draw color scale\n"
8950 "-demo/-demoversion draw a demoversion of color scale.\n"
8951 "-show/display display color scale.\n"
8952 "-hide/erase erase color scale.\n"
8953 "Please note that -show/-hide option must be the first argument!\n"
8954 "-color Index R G B: set color for indexed interval\n"
8955 "-color Index ColorName: set color for indexed interval\n"
8956 "-colors R G B R G B ...: set colors for all intervals\n"
8957 "-colors ColorName1 ColorName2 ...: set colors for all intervals\n"
8958 "-colors supports both color names and rgb values in one call\n"
8959 "-label Index Text: set label for indexed interval\n"
8960 "-labels Text Text Text ...: set labels for all intervals\n"
8961 "-title Title [Position]: set the title for color scale with certain position. Default position = center;\n"
8962 "Available text positions: left, right, center, none;\n",
8963 __FILE__,VColorScale,group);
8964 theCommands.Add("vgraduatedtrihedron",
8965 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
8966 "\t[-namefont Name] [-valuesfont Name]\n"
8967 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
8968 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
8969 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
8970 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
8971 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
8972 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
8973 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
8974 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
8975 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
8976 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
8977 " - Displays or erases graduated trihedron"
8978 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
8979 " - namefont - font of axes names. Default: Arial\n"
8980 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
8981 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
8982 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
8983 " - valuesfont - font of axes values. Default: Arial\n"
8984 " - xcolor, ycolor, zcolor - color of axis and values\n"
8985 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
8986 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
8987 __FILE__,VGraduatedTrihedron,group);
8988 theCommands.Add("vprintview" ,
8989 "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
8990 __FILE__,VPrintView,group);
8991 theCommands.Add("vzlayer",
8992 "vzlayer add/del/get/settings/enable/disable [id]\n"
8993 " add - add new z layer to viewer and print its id\n"
8994 " del - del z layer by its id\n"
8995 " get - print sequence of z layers in increasing order of their overlay level\n"
8996 " settings - print status of z layer settings\n"
8997 " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n"
8998 " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n"
8999 " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n"
9000 "\nWhere id is the layer identificator\n"
9003 " vzlayer enable poffset 1\n"
9004 " vzlayer disable depthtest 1\n"
9006 __FILE__,VZLayer,group);
9007 theCommands.Add("vlayerline",
9008 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
9009 __FILE__,VLayerLine,group);
9010 theCommands.Add ("vgrid",
9011 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
9012 " : Mode - rectangular or circular"
9013 " : Type - lines or points",
9014 __FILE__, VGrid, group);
9015 theCommands.Add ("vpriviledgedplane",
9016 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
9017 "\n\t\t: Ox, Oy, Oz - plane origin"
9018 "\n\t\t: Nx, Ny, Nz - plane normal direction"
9019 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
9020 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
9021 __FILE__, VPriviledgedPlane, group);
9022 theCommands.Add ("vconvert",
9023 "vconvert v [Mode={window|view}]"
9024 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
9025 "\n\t\t: vconvert x y z [Mode={window|grid}]"
9026 "\n\t\t: window - convert to window coordinates, pixels"
9027 "\n\t\t: view - convert to view projection plane"
9028 "\n\t\t: grid - convert to model coordinates, given on grid"
9029 "\n\t\t: ray - convert projection ray to model coordiantes"
9030 "\n\t\t: - vconvert v window : convert view to window;"
9031 "\n\t\t: - vconvert v view : convert window to view;"
9032 "\n\t\t: - vconvert x y window : convert view to window;"
9033 "\n\t\t: - vconvert x y view : convert window to view;"
9034 "\n\t\t: - vconvert x y : convert window to model;"
9035 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
9036 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
9037 "\n\t\t: - vconvert x y z window : convert model to window;"
9038 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
9039 "\n\t\t: Converts the given coordinates to window/view/model space.",
9040 __FILE__, VConvert, group);
9041 theCommands.Add ("vfps",
9042 "vfps [framesNb=100] : estimate average frame rate for active view",
9043 __FILE__, VFps, group);
9044 theCommands.Add ("vgldebug",
9045 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
9046 "\n\t\t: [-extraMsg {0|1}] [{0|1}]"
9047 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
9048 "\n\t\t: Debug context can be requested only on Windows"
9049 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
9050 "\n\t\t: -sync - request synchronized debug GL context"
9051 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
9052 "\n\t\t: which are suppressed by default,"
9053 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
9054 "\n\t\t: which are suppressed by default",
9055 __FILE__, VGlDebug, group);
9056 theCommands.Add ("vvbo",
9057 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
9058 __FILE__, VVbo, group);
9059 theCommands.Add ("vstereo",
9060 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
9061 "\n\t\t: [-anaglyph Filter]"
9062 "\n\t\t: Control stereo output mode. Available modes for -mode:"
9063 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
9064 "\n\t\t: requires driver support."
9065 "\n\t\t: Should be called BEFORE vinit!"
9066 "\n\t\t: anaglyph - Anaglyph glasses"
9067 "\n\t\t: rowInterlaced - row-interlaced display"
9068 "\n\t\t: columnInterlaced - column-interlaced display"
9069 "\n\t\t: chessBoard - chess-board output"
9070 "\n\t\t: sideBySide - horizontal pair"
9071 "\n\t\t: overUnder - vertical pair"
9072 "\n\t\t: Available Anaglyph filters for -anaglyph:"
9073 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
9074 "\n\t\t: greenMagentaSimple",
9075 __FILE__, VStereo, group);
9076 theCommands.Add ("vcaps",
9077 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
9078 "\n\t\t: [-compatibleProfile {0|1}]"
9079 "\n\t\t: [-vsync {0|1}]"
9080 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
9081 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
9082 "\n\t\t: Modify particular graphic driver options:"
9083 "\n\t\t: FFP - use fixed-function pipeline instead of"
9084 "\n\t\t: built-in GLSL programs"
9085 "\n\t\t: (requires compatible profile)"
9086 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
9087 "\n\t\t: arrays to GPU memory)"
9088 "\n\t\t: sprite - use textured sprites instead of bitmaps"
9089 "\n\t\t: vsync - switch VSync on or off"
9090 "\n\t\t: Context creation options:"
9091 "\n\t\t: softMode - software OpenGL implementation"
9092 "\n\t\t: compatibleProfile - backward-compatible profile"
9093 "\n\t\t: quadbuffer - QuadBuffer"
9094 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
9095 "\n\t\t: rendering paths producing the same visual result when"
9097 "\n\t\t: Command is intended for testing old hardware compatibility.",
9098 __FILE__, VCaps, group);
9099 theCommands.Add ("vmemgpu",
9100 "vmemgpu [f]: print system-dependent GPU memory information if available;"
9101 " with f option returns free memory in bytes",
9102 __FILE__, VMemGpu, group);
9103 theCommands.Add ("vreadpixel",
9104 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
9105 " : Read pixel value for active view",
9106 __FILE__, VReadPixel, group);
9107 theCommands.Add("diffimage",
9108 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
9109 __FILE__, VDiffImage, group);
9110 theCommands.Add ("vselect",
9111 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
9112 "- emulates different types of selection:\n"
9113 "- 1) single click selection\n"
9114 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
9115 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
9116 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
9117 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
9118 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
9119 " (partial inclusion - overlap - is not allowed by default)\n"
9120 "- 5) any of these selections with shift button pressed",
9121 __FILE__, VSelect, group);
9122 theCommands.Add ("vmoveto",
9124 "- emulates cursor movement to pixel postion (x,y)",
9125 __FILE__, VMoveTo, group);
9126 theCommands.Add ("vviewparams", "vviewparams usage:\n"
9128 "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n"
9129 " [-proj [x y z]] [-center x y] [-size sx]\n"
9130 "- Gets or sets current view parameters.\n"
9131 "- If called without arguments, all view parameters are printed.\n"
9132 "- The options are:\n"
9133 " -scale [s] : prints or sets viewport relative scale.\n"
9134 " -eye [x y z] : prints or sets eye location.\n"
9135 " -at [x y z] : prints or sets center of look.\n"
9136 " -up [x y z] : prints or sets direction of up vector.\n"
9137 " -proj [x y z] : prints or sets direction of look.\n"
9138 " -center x y : sets location of center of the screen in pixels.\n"
9139 " -size [sx] : prints viewport projection width and height sizes\n"
9140 " : or changes the size of its maximum dimension.\n",
9141 __FILE__, VViewParams, group);
9142 theCommands.Add("vchangeselected",
9143 "vchangeselected shape"
9144 "- adds to shape to selection or remove one from it",
9145 __FILE__, VChangeSelected, group);
9146 theCommands.Add("vzclipping",
9147 "vzclipping [mode] [depth width]\n"
9148 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
9149 "- gets or sets ZClipping mode, width and depth",
9150 __FILE__,VZClipping,group);
9151 theCommands.Add ("vnbselected",
9153 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
9154 theCommands.Add ("vcamera",
9155 "vcamera [-ortho] [-projtype]"
9157 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
9158 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
9159 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
9160 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
9161 "\n\t\t: Manage camera parameters."
9162 "\n\t\t: Prints current value when option called without argument."
9163 "\n\t\t: Orthographic camera:"
9164 "\n\t\t: -ortho activate orthographic projection"
9165 "\n\t\t: Perspective camera:"
9166 "\n\t\t: -persp activate perspective projection (mono)"
9167 "\n\t\t: -fovy field of view in y axis, in degrees"
9168 "\n\t\t: -distance distance of eye from camera center"
9169 "\n\t\t: Stereoscopic camera:"
9170 "\n\t\t: -stereo perspective projection (stereo)"
9171 "\n\t\t: -leftEye perspective projection (left eye)"
9172 "\n\t\t: -rightEye perspective projection (right eye)"
9173 "\n\t\t: -iod intraocular distance value"
9174 "\n\t\t: -iodType distance type, absolute or relative"
9175 "\n\t\t: -zfocus stereographic focus value"
9176 "\n\t\t: -zfocusType focus type, absolute or relative",
9177 __FILE__, VCamera, group);
9178 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
9179 "- vautozfit [on={1|0}] [scale]\n"
9180 " Prints or changes parameters of automatic z-fit mode:\n"
9181 " \"on\" - turns automatic z-fit on or off\n"
9182 " \"scale\" - specifies factor to scale computed z range.\n",
9183 __FILE__, VAutoZFit, group);
9184 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
9185 " vzrange - without parameters shows current values\n"
9186 " vzrange [znear] [zfar] - applies provided values to view",
9187 __FILE__,VZRange, group);
9188 theCommands.Add("vantialiasing",
9190 "\n\t\t: Switches altialiasing on or off",
9191 __FILE__,VAntialiasing,group);
9192 theCommands.Add ("vpurgedisplay",
9194 "- removes structures which don't belong to objects displayed in neutral point",
9195 __FILE__, VPurgeDisplay, group);
9196 theCommands.Add("vsetviewsize",
9197 "vsetviewsize size",
9198 __FILE__,VSetViewSize,group);
9199 theCommands.Add("vmoveview",
9200 "vmoveview Dx Dy Dz [Start = 1|0]",
9201 __FILE__,VMoveView,group);
9202 theCommands.Add("vtranslateview",
9203 "vtranslateview Dx Dy Dz [Start = 1|0)]",
9204 __FILE__,VTranslateView,group);
9205 theCommands.Add("vturnview",
9206 "vturnview Ax Ay Az [Start = 1|0]",
9207 __FILE__,VTurnView,group);
9208 theCommands.Add("vtextureenv",
9209 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
9210 "or user-defined file and optionally applying texture mapping parameters\n"
9212 " vtextureenv off - disables environment mapping\n"
9213 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
9214 " std_texture = (0..7)\n"
9215 " rep = {clamp|repeat}\n"
9216 " mod = {decal|modulate}\n"
9217 " flt = {nearest|bilinear|trilinear}\n"
9218 " ss, st - scale factors for s and t texture coordinates\n"
9219 " ts, tt - translation for s and t texture coordinates\n"
9220 " rot - texture rotation angle in degrees",
9221 __FILE__, VTextureEnv, group);
9222 theCommands.Add("vhlr" ,
9223 "is_enabled={on|off} [show_hidden={1|0}]"
9224 " - Hidden line removal algorithm:"
9225 " - is_enabled: if is on HLR algorithm is applied\n"
9226 " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n",
9227 __FILE__,VHLR,group);
9228 theCommands.Add("vhlrtype" ,
9229 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
9230 " - Changes the type of HLR algorithm using for shapes."
9231 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
9232 " if equals to polyalgo, polygonal HLR algorithm is applied."
9233 "If shapes are not given HLR algoithm of given type is applied"
9234 " to all shapes in the view\n",
9235 __FILE__,VHLRType,group);
9236 theCommands.Add("vclipplane", "vclipplane usage: \n"
9237 " maxplanes <view_name> - get plane limit for view.\n"
9238 " create <plane_name> - create new plane.\n"
9239 " delete <plane_name> - delete plane.\n"
9240 " clone <source_plane> <plane_name> - clone the plane definition.\n"
9241 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
9242 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
9243 " change <plane_name> on/off - turn clipping on/off.\n"
9244 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
9245 " change <plane_name> capping on/off - turn capping on/off.\n"
9246 " change <plane_name> capping color <r> <g> <b> - set color.\n"
9247 " change <plane name> capping texname <texture> - set texture.\n"
9248 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
9249 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
9250 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
9251 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
9252 " please use VSetTextureMode command to enable texture rendering in view.\n"
9253 , __FILE__, VClipPlane, group);
9254 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
9256 " 0 - no textures enabled in view.\n"
9257 " 1 - only environment textures enabled.\n"
9258 " 2 - all textures enabled.\n"
9259 " this command sets texture details mode for the specified view.\n"
9260 , __FILE__, VSetTextureMode, group);
9261 theCommands.Add("vdefaults",
9262 "vdefaults [-absDefl value]"
9263 "\n\t\t: [-devCoeff value]"
9264 "\n\t\t: [-angDefl value]"
9265 "\n\t\t: [-autoTriang {off/on | 0/1}]"
9266 , __FILE__, VDefaults, group);
9267 theCommands.Add("vlight",
9268 "tool to manage light sources, without arguments shows list of lights."
9269 "\n Main commands: "
9270 "\n 'clear' to clear lights"
9271 "\n '{def}aults' to load deafault lights"
9272 "\n 'add' (or 'new') <type> to add any light source"
9273 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
9274 "\n 'change' <lightId> to edit light source with specified lightId"
9275 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
9276 "\n {pos}ition X Y Z"
9277 "\n {dir}ection X Y Z (for directional light or for spotlight)"
9278 "\n color colorName"
9279 "\n {head}light 0|1"
9280 "\n {sm}oothness value"
9281 "\n {int}ensity value"
9282 "\n {constAtten}uation value"
9283 "\n {linearAtten}uation value"
9285 "\n {spotexp}onent value"
9287 "\n\n example: vlight add positional head 1 pos 0 1 1 color red"
9288 "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
9289 __FILE__, VLight, group);
9290 theCommands.Add("vraytrace",
9292 "\n\t\t: Turns on/off ray-tracing renderer."
9293 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
9294 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
9295 __FILE__, VRenderParams, group);
9296 theCommands.Add("vrenderparams",
9297 "\n Manages rendering parameters: "
9298 "\n '-raster' Disables GPU ray-tracing"
9299 "\n '-msaa 0..4' Specifies number of samples for MSAA"
9300 "\n '-rayTrace' Enables GPU ray-tracing"
9301 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
9302 "\n '-shadows on|off' Enables/disables shadows rendering"
9303 "\n '-reflections on|off' Enables/disables specular reflections"
9304 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
9305 "\n '-gleam on|off' Enables/disables transparency shadow effects"
9306 "\n '-gi on|off' Enables/disables global illumination effects"
9307 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
9308 "\n '-env on|off' Enables/disables environment map background"
9309 "\n '-shadingModel model' Controls shading model from enumeration"
9310 "\n color, flat, gouraud, phong"
9311 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
9312 "\n Unlike vcaps, these parameters dramatically change visual properties."
9313 "\n Command is intended to control presentation quality depending on"
9314 "\n hardware capabilities and performance.",
9315 __FILE__, VRenderParams, group);
9316 theCommands.Add("vfrustumculling",
9317 "vfrustumculling [toEnable]: enables/disables objects clipping",
9318 __FILE__,VFrustumCulling,group);
9319 theCommands.Add("vhighlightselected",
9320 "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n"
9321 "Without arguments it shows if highlighting of selected objects is enabled now.",
9322 __FILE__,VHighlightSelected,group);
9323 theCommands.Add ("vplace",
9325 "\n\t\t: Places the point (in pixels) at the center of the window",
9326 __FILE__, VPlace, group);
9327 theCommands.Add("vxrotate",
9329 __FILE__,VXRotate,group);
9332 theCommands.Add("vprogressive",
9334 __FILE__, VProgressiveMode, group);