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_RubberBand.hxx>
20 #include <AIS_Shape.hxx>
21 #include <AIS_InteractiveObject.hxx>
22 #include <AIS_ListOfInteractive.hxx>
23 #include <AIS_ListIteratorOfListOfInteractive.hxx>
25 #include <Graphic3d_ArrayOfPolylines.hxx>
26 #include <Graphic3d_AspectMarker3d.hxx>
27 #include <Graphic3d_ExportFormat.hxx>
28 #include <Graphic3d_NameOfTextureEnv.hxx>
29 #include <Graphic3d_GraduatedTrihedron.hxx>
30 #include <Graphic3d_TextureEnv.hxx>
31 #include <Graphic3d_TextureParams.hxx>
32 #include <Graphic3d_TypeOfTextureFilter.hxx>
33 #include <Graphic3d_AspectFillArea3d.hxx>
34 #include <ViewerTest.hxx>
35 #include <ViewerTest_AutoUpdater.hxx>
36 #include <ViewerTest_EventManager.hxx>
37 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
38 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
39 #include <V3d_AmbientLight.hxx>
40 #include <V3d_DirectionalLight.hxx>
41 #include <V3d_PositionalLight.hxx>
42 #include <V3d_SpotLight.hxx>
43 #include <NCollection_DoubleMap.hxx>
44 #include <NCollection_List.hxx>
45 #include <NCollection_Vector.hxx>
46 #include <AIS_InteractiveContext.hxx>
47 #include <Draw_Interpretor.hxx>
49 #include <Draw_Appli.hxx>
50 #include <Aspect_PrintAlgo.hxx>
51 #include <Image_AlienPixMap.hxx>
52 #include <OpenGl_GraphicDriver.hxx>
53 #include <OSD_Timer.hxx>
54 #include <TColStd_HSequenceOfAsciiString.hxx>
55 #include <TColStd_SequenceOfInteger.hxx>
56 #include <TColStd_HSequenceOfReal.hxx>
57 #include <TColgp_Array1OfPnt2d.hxx>
58 #include <TColStd_MapOfAsciiString.hxx>
59 #include <Aspect_TypeOfLine.hxx>
60 #include <Image_Diff.hxx>
61 #include <Aspect_DisplayConnection.hxx>
65 #include <PrsMgr_PresentableObject.hxx>
66 #include <Graphic3d_ClipPlane.hxx>
67 #include <NCollection_DataMap.hxx>
68 #include <Graphic3d_Texture2Dmanual.hxx>
69 #include <Prs3d_ShadingAspect.hxx>
70 #include <Prs3d_Drawer.hxx>
71 #include <Prs3d_LineAspect.hxx>
72 #include <Prs3d_Root.hxx>
81 #include <WNT_WClass.hxx>
82 #include <WNT_Window.hxx>
85 #define _CRT_SECURE_NO_DEPRECATE
86 #pragma warning (disable:4996)
88 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
89 #include <Cocoa_Window.hxx>
91 #include <Xw_Window.hxx>
92 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
93 #include <X11/Xutil.h>
97 // Auxiliary definitions
98 static const char THE_KEY_DELETE = 127;
100 //==============================================================================
101 // VIEWER GLOBAL VARIABLES
102 //==============================================================================
104 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
105 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
107 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
108 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
110 extern int VErase (Draw_Interpretor& theDI,
111 Standard_Integer theArgNb,
112 const char** theArgVec);
115 static Handle(WNT_Window)& VT_GetWindow() {
116 static Handle(WNT_Window) WNTWin;
119 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
120 static Handle(Cocoa_Window)& VT_GetWindow()
122 static Handle(Cocoa_Window) aWindow;
125 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
126 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
127 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
130 static Handle(Xw_Window)& VT_GetWindow(){
131 static Handle(Xw_Window) XWWin;
135 static void VProcessEvents(ClientData,int);
138 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
140 static Handle(Aspect_DisplayConnection) aDisplayConnection;
141 return aDisplayConnection;
144 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
146 GetDisplayConnection() = theDisplayConnection;
149 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
150 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
152 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
154 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
155 if (!aWindow.IsNull())
156 return aWindow->HWindow();
157 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
158 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
159 if (!aWindow.IsNull())
160 return aWindow->XWindow();
162 return aWindowHandle;
166 static Standard_Boolean MyHLRIsOn = Standard_False;
168 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
169 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
170 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
171 static OpenGl_Caps ViewerTest_myDefaultCaps;
173 #define ZCLIPWIDTH 1.
175 static void OSWindowSetup();
179 Quantity_Color FlatColor;
180 Quantity_Color GradientColor1;
181 Quantity_Color GradientColor2;
182 Aspect_GradientFillMethod FillMethod;
183 } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
185 //==============================================================================
186 // EVENT GLOBAL VARIABLES
187 //==============================================================================
189 static int Start_Rot = 0;
190 static int ZClipIsOn = 0;
191 int X_Motion = 0; // Current cursor position
193 int X_ButtonPress = 0; // Last ButtonPress position
194 int Y_ButtonPress = 0;
195 Standard_Boolean IsDragged = Standard_False;
196 Standard_Boolean DragFirst = Standard_False;
199 Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand()
201 static Handle(AIS_RubberBand) aBand;
204 aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0);
205 aBand->SetDisplayMode (0);
210 //==============================================================================
213 static LRESULT WINAPI ViewerWindowProc(
218 static LRESULT WINAPI AdvViewerWindowProc(
226 //==============================================================================
229 //==============================================================================
231 const Handle(MMgt_TShared)& ViewerTest::WClass()
233 static Handle(MMgt_TShared) theWClass;
235 if (theWClass.IsNull())
237 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
238 CS_VREDRAW | CS_HREDRAW, 0, 0,
239 ::LoadCursor (NULL, IDC_ARROW));
245 //==============================================================================
246 //function : CreateName
247 //purpose : Create numerical name for new object in theMap
248 //==============================================================================
249 template <typename ObjectType>
250 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
251 const TCollection_AsciiString& theDefaultString)
253 if (theObjectMap.IsEmpty())
254 return theDefaultString + TCollection_AsciiString(1);
256 Standard_Integer aNextKey = 1;
257 Standard_Boolean isFound = Standard_False;
260 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
261 // Look for objects with default names
262 if (theObjectMap.IsBound1(aStringKey))
267 isFound = Standard_True;
270 return theDefaultString + TCollection_AsciiString(aNextKey);
273 //==============================================================================
274 //structure : ViewerTest_Names
275 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
276 //==============================================================================
277 struct ViewerTest_Names
280 TCollection_AsciiString myDriverName;
281 TCollection_AsciiString myViewerName;
282 TCollection_AsciiString myViewName;
286 const TCollection_AsciiString& GetDriverName () const
290 void SetDriverName (const TCollection_AsciiString& theDriverName)
292 myDriverName = theDriverName;
294 const TCollection_AsciiString& GetViewerName () const
298 void SetViewerName (const TCollection_AsciiString& theViewerName)
300 myViewerName = theViewerName;
302 const TCollection_AsciiString& GetViewName () const
306 void SetViewName (const TCollection_AsciiString& theViewName)
308 myViewName = theViewName;
311 //===========================================================================
312 //function : Constructor for ViewerTest_Names
313 //purpose : Get view, viewer, driver names from custom string
314 //===========================================================================
316 ViewerTest_Names (const TCollection_AsciiString& theInputString)
318 TCollection_AsciiString aName(theInputString);
319 if (theInputString.IsEmpty())
321 // Get current configuration
322 if (ViewerTest_myDrivers.IsEmpty())
323 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
324 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
326 myDriverName = ViewerTest_myDrivers.Find2
327 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
329 if(ViewerTest_myContexts.IsEmpty())
331 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
332 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
335 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
337 myViewName = CreateName <Handle(V3d_View)>
338 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
342 // There is at least view name
343 Standard_Integer aParserNumber = 0;
344 for (Standard_Integer i = 0; i < 3; ++i)
346 Standard_Integer aParserPos = aName.SearchFromEnd("/");
350 aName.Split(aParserPos-1);
355 if (aParserNumber == 0)
358 if (!ViewerTest::GetAISContext().IsNull())
360 myDriverName = ViewerTest_myDrivers.Find2
361 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
362 myViewerName = ViewerTest_myContexts.Find2
363 (ViewerTest::GetAISContext());
367 // There is no opened contexts here, need to create names for viewer and driver
368 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
369 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
371 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
372 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
374 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
376 else if (aParserNumber == 1)
378 // Here is viewerName/viewName
379 if (!ViewerTest::GetAISContext().IsNull())
380 myDriverName = ViewerTest_myDrivers.Find2
381 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
384 // There is no opened contexts here, need to create name for driver
385 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
386 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
388 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
390 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
394 //Here is driverName/viewerName/viewName
395 myDriverName = TCollection_AsciiString(aName);
397 TCollection_AsciiString aViewerName(theInputString);
398 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
399 myViewerName = TCollection_AsciiString(aViewerName);
401 myViewName = TCollection_AsciiString(theInputString);
407 //==============================================================================
408 //function : FindContextByView
409 //purpose : Find AIS_InteractiveContext by View
410 //==============================================================================
412 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
414 Handle(AIS_InteractiveContext) anAISContext;
416 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
417 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
419 if (anIter.Value()->CurrentViewer() == theView->Viewer())
420 return anIter.Key2();
426 //==============================================================================
427 //function : SetWindowTitle
428 //purpose : Set window title
429 //==============================================================================
431 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
432 Standard_CString theTitle)
435 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
437 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
438 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
440 if(GetDisplayConnection()->GetDisplay())
443 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
444 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
449 //==============================================================================
450 //function : IsWindowOverlapped
451 //purpose : Check if theWindow overlapp another view
452 //==============================================================================
454 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
455 const Standard_Integer thePxTop,
456 const Standard_Integer thePxRight,
457 const Standard_Integer thePxBottom,
458 TCollection_AsciiString& theViewId)
460 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
461 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
463 Standard_Integer aTop = 0,
467 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
468 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
469 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
470 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
471 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
473 theViewId = anIter.Key1();
474 return Standard_True;
477 return Standard_False;
480 // Workaround: to create and delete non-orthographic views outside ViewerTest
481 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
483 ViewerTest_myViews.UnBind1 (theName);
486 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
487 const Handle(V3d_View)& theView)
489 ViewerTest_myViews.Bind (theName, theView);
492 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
494 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
496 //==============================================================================
497 //function : ViewerInit
498 //purpose : Create the window viewer and initialize all the global variable
499 //==============================================================================
501 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
502 const Standard_Integer thePxTop,
503 const Standard_Integer thePxWidth,
504 const Standard_Integer thePxHeight,
505 Standard_CString theViewName,
506 Standard_CString theDisplayName)
508 // Default position and dimension of the viewer window.
509 // Note that left top corner is set to be sufficiently small to have
510 // window fit in the small screens (actual for remote desktops, see #23003).
511 // The position corresponds to the window's client area, thus some
512 // gap is added for window frame to be visible.
513 Standard_Integer aPxLeft = 20;
514 Standard_Integer aPxTop = 40;
515 Standard_Integer aPxWidth = 409;
516 Standard_Integer aPxHeight = 409;
517 Standard_Boolean toCreateViewer = Standard_False;
519 Handle(OpenGl_GraphicDriver) aGraphicDriver;
520 ViewerTest_Names aViewNames(theViewName);
521 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
522 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
529 aPxWidth = thePxWidth;
530 if (thePxHeight != 0)
531 aPxHeight = thePxHeight;
533 // Get graphic driver (create it or get from another view)
534 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
536 // Get connection string
537 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
538 TCollection_AsciiString aDisplayName(theDisplayName);
539 if (!aDisplayName.IsEmpty())
540 SetDisplayConnection (new Aspect_DisplayConnection ());
542 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
544 (void)theDisplayName; // avoid warning on unused argument
545 SetDisplayConnection (new Aspect_DisplayConnection ());
547 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
548 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
549 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
550 toCreateViewer = Standard_True;
554 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
557 //Dispose the window if input parameters are default
558 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
560 Standard_Integer aTop = 0,
567 // Get screen resolution
568 #if defined(_WIN32) || defined(__WIN32__)
570 GetClientRect(GetDesktopWindow(), &aWindowSize);
571 aScreenHeight = aWindowSize.bottom;
572 aScreenWidth = aWindowSize.right;
573 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
574 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
576 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
577 aScreenWidth = WidthOfScreen(aScreen);
578 aScreenHeight = HeightOfScreen(aScreen);
581 TCollection_AsciiString anOverlappedViewId("");
583 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
585 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
587 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
588 && aRight + 2*aPxWidth + 40 > aScreenWidth)
590 if (aBottom + aPxHeight + 40 > aScreenHeight)
597 aPxTop = aBottom + 40;
600 aPxLeft = aRight + 20;
605 TCollection_AsciiString aTitle("3D View - ");
606 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
608 // Change name of current active window
609 if (!ViewerTest::CurrentView().IsNull())
611 TCollection_AsciiString anActiveWindowTitle("3D View - ");
612 anActiveWindowTitle = anActiveWindowTitle
613 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
614 SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString());
618 Handle(V3d_Viewer) a3DViewer;
619 // If it's the single view, we first look for empty context
620 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
622 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
623 anIter(ViewerTest_myContexts);
625 ViewerTest::SetAISContext (anIter.Value());
626 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
628 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
630 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
631 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
633 else if (a3DViewer.IsNull())
635 toCreateViewer = Standard_True;
636 TCollection_ExtendedString NameOfWindow("Viewer3D");
637 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
638 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
639 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
640 ViewerTest_DefaultBackground.GradientColor2,
641 ViewerTest_DefaultBackground.FillMethod);
645 if (ViewerTest::GetAISContext().IsNull() ||
646 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
648 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
649 ViewerTest::SetAISContext (aContext);
650 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
654 ViewerTest::ResetEventManager();
659 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
660 Handle(WNT_WClass)::DownCast (WClass()),
661 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
665 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
666 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
668 aPxWidth, aPxHeight);
669 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
671 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
674 aPxWidth, aPxHeight);
676 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
679 Handle(V3d_View) aView = a3DViewer->CreateView();
680 aView->SetWindow (VT_GetWindow());
681 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
683 ViewerTest::CurrentView(aView);
684 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
686 // Setup for X11 or NT
689 // Set parameters for V3d_View and V3d_Viewer
690 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
691 aV3dView->SetComputedMode(Standard_False);
692 MyHLRIsOn = aV3dView->ComputedMode();
693 aV3dView->SetZClippingDepth(0.5);
694 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
696 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
699 a3DViewer->SetDefaultLights();
700 a3DViewer->SetLightOn();
703 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
704 #if TCL_MAJOR_VERSION < 8
705 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
706 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
708 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
709 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
713 VT_GetWindow()->Map();
715 // Set the handle of created view in the event manager
716 ViewerTest::ResetEventManager();
718 ViewerTest::CurrentView()->Redraw();
723 return aViewNames.GetViewName();
726 //==============================================================================
727 //function : RedrawAllViews
728 //purpose : Redraw all created views
729 //==============================================================================
730 void ViewerTest::RedrawAllViews()
732 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
733 for (; aViewIt.More(); aViewIt.Next())
735 const Handle(V3d_View)& aView = aViewIt.Key2();
740 //==============================================================================
742 //purpose : Create the window viewer and initialize all the global variable
743 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
744 //==============================================================================
746 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
750 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
751 << "Type help for more information.\n";
755 TCollection_AsciiString aViewName, aDisplayName;
756 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
757 TCollection_AsciiString aName, aValue;
758 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
760 const TCollection_AsciiString anArg = theArgVec[anArgIt];
761 TCollection_AsciiString anArgCase = anArg;
762 anArgCase.UpperCase();
763 if (ViewerTest::SplitParameter (anArg, aName, aValue))
766 if (aName.IsEqual ("NAME"))
770 else if (aName.IsEqual ("L")
771 || aName.IsEqual ("LEFT"))
773 aPxLeft = aValue.IntegerValue();
775 else if (aName.IsEqual ("T")
776 || aName.IsEqual ("TOP"))
778 aPxTop = aValue.IntegerValue();
780 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
781 else if (aName.IsEqual ("DISP")
782 || aName.IsEqual ("DISPLAY"))
784 aDisplayName = aValue;
787 else if (aName.IsEqual ("W")
788 || aName.IsEqual ("WIDTH"))
790 aPxWidth = aValue.IntegerValue();
792 else if (aName.IsEqual ("H")
793 || aName.IsEqual ("HEIGHT"))
795 aPxHeight = aValue.IntegerValue();
799 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
802 else if (aViewName.IsEmpty())
808 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
812 ViewerTest_Names aViewNames (aViewName);
813 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
815 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
816 theDi.Eval (aCommand.ToCString());
820 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
821 aViewName.ToCString(),
822 aDisplayName.ToCString());
827 //==============================================================================
829 //purpose : hidden lines removal algorithm
830 //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}]
831 //==============================================================================
833 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
835 if (ViewerTest::CurrentView().IsNull())
837 di << argv[0] << ": Call vinit before this command, please.\n";
843 di << argv[0] << ": Wrong number of command arguments.\n"
844 << "Type help " << argv[0] << " for more information.\n";
848 // Enable or disable HLR mode.
849 Standard_Boolean isHLROn =
850 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
852 if (isHLROn != MyHLRIsOn)
855 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
858 // Show or hide hidden lines in HLR mode.
859 Standard_Boolean isCurrentShowHidden
860 = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine();
862 Standard_Boolean isShowHidden =
863 (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False)
864 : isCurrentShowHidden;
867 if (isShowHidden != isCurrentShowHidden)
871 ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine();
875 ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine();
881 AIS_ListOfInteractive aListOfShapes;
882 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
884 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
886 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value());
891 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
896 ViewerTest::CurrentView()->Update();
900 //==============================================================================
901 //function : VHLRType
902 //purpose : change type of using HLR algorithm
903 //==============================================================================
905 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
907 if (ViewerTest::CurrentView().IsNull())
909 di << argv[0] << ": Call vinit before this command, please.\n";
915 di << argv[0] << ": Wrong number of command arguments.\n"
916 << "Type help " << argv[0] << " for more information.\n";
920 Prs3d_TypeOfHLR aTypeOfHLR =
921 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
925 AIS_ListOfInteractive aListOfShapes;
926 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
927 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
928 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
929 anIter.More(); anIter.Next())
931 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
934 if (aShape->TypeOfHLR() != aTypeOfHLR)
935 aShape->SetTypeOfHLR (aTypeOfHLR);
937 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
939 ViewerTest::CurrentView()->Update();
944 for (Standard_Integer i = 2; i < argc; ++i)
946 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
947 TCollection_AsciiString aName (argv[i]);
949 if (!aMap.IsBound2 (aName))
951 di << argv[0] << ": Wrong shape name:" << aName.ToCString() << ".\n";
954 Handle(AIS_Shape) anAISObject =
955 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
956 if (anAISObject.IsNull())
958 anAISObject->SetTypeOfHLR (aTypeOfHLR);
960 ViewerTest::GetAISContext()->Redisplay (anAISObject, Standard_False);
962 ViewerTest::CurrentView()->Update();
968 //==============================================================================
969 //function : FindViewIdByWindowHandle
970 //purpose : Find theView Id in the map of views by window handle
971 //==============================================================================
972 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
973 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
975 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
976 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
978 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
979 if (aWindowHandle == theWindowHandle)
980 return anIter.Key1();
982 return TCollection_AsciiString("");
986 //==============================================================================
987 //function : ActivateView
988 //purpose : Make the view active
989 //==============================================================================
991 void ActivateView (const TCollection_AsciiString& theViewName)
993 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
996 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
997 if (!anAISContext.IsNull())
999 if (!ViewerTest::CurrentView().IsNull())
1001 TCollection_AsciiString aTitle("3D View - ");
1002 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1003 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1006 ViewerTest::CurrentView (aView);
1007 // Update degenerate mode
1008 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
1009 ViewerTest::SetAISContext (anAISContext);
1010 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
1011 aTitle = aTitle + theViewName + "(*)";
1012 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1013 #if defined(_WIN32) || defined(__WIN32__)
1014 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1015 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1016 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1018 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1020 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1021 ViewerTest::CurrentView()->Redraw();
1026 //==============================================================================
1027 //function : RemoveView
1029 //==============================================================================
1030 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1031 const Standard_Boolean theToRemoveContext)
1033 if (!ViewerTest_myViews.IsBound2 (theView))
1038 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1039 RemoveView (aViewName, theToRemoveContext);
1042 //==============================================================================
1043 //function : RemoveView
1044 //purpose : Close and remove view from display, clear maps if neccessary
1045 //==============================================================================
1046 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1048 if (!ViewerTest_myViews.IsBound1(theViewName))
1050 cout << "Wrong view name\n";
1054 // Activate another view if it's active now
1055 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1057 if (ViewerTest_myViews.Extent() > 1)
1059 TCollection_AsciiString aNewViewName;
1060 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
1061 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1062 if (anIter.Key1() != theViewName)
1064 aNewViewName = anIter.Key1();
1067 ActivateView (aNewViewName);
1071 Handle(V3d_View) anEmptyView;
1072 #if defined(_WIN32) || defined(__WIN32__)
1073 Handle(WNT_Window) anEmptyWindow;
1074 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1075 Handle(Cocoa_Window) anEmptyWindow;
1077 Handle(Xw_Window) anEmptyWindow;
1079 VT_GetWindow() = anEmptyWindow;
1080 ViewerTest::CurrentView (anEmptyView);
1081 if (isContextRemoved)
1083 Handle(AIS_InteractiveContext) anEmptyContext;
1084 ViewerTest::SetAISContext(anEmptyContext);
1090 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1091 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1093 // Remove view resources
1094 ViewerTest_myViews.UnBind1(theViewName);
1097 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1098 XFlush (GetDisplayConnection()->GetDisplay());
1101 // Keep context opened only if the closed view is last to avoid
1102 // unused empty contexts
1103 if (!aCurrentContext.IsNull())
1105 // Check if there are more difined views in the viewer
1106 aCurrentContext->CurrentViewer()->InitDefinedViews();
1107 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1109 // Remove driver if there is no viewers that use it
1110 Standard_Boolean isRemoveDriver = Standard_True;
1111 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1112 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1114 if (aCurrentContext != anIter.Key2() &&
1115 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1117 isRemoveDriver = Standard_False;
1123 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1124 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1125 #if TCL_MAJOR_VERSION < 8
1126 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1128 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1133 ViewerTest_myContexts.UnBind2(aCurrentContext);
1136 cout << "3D View - " << theViewName << " was deleted.\n";
1140 //==============================================================================
1142 //purpose : Remove the view defined by its name
1143 //==============================================================================
1145 static int VClose (Draw_Interpretor& /*theDi*/,
1146 Standard_Integer theArgsNb,
1147 const char** theArgVec)
1149 NCollection_List<TCollection_AsciiString> aViewList;
1152 TCollection_AsciiString anArg (theArgVec[1]);
1154 if (anArg.IsEqual ("ALL")
1155 || anArg.IsEqual ("*"))
1157 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1158 anIter.More(); anIter.Next())
1160 aViewList.Append (anIter.Key1());
1162 if (aViewList.IsEmpty())
1164 std::cout << "No view to close\n";
1170 ViewerTest_Names aViewName (theArgVec[1]);
1171 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1173 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1176 aViewList.Append (aViewName.GetViewName());
1181 // close active view
1182 if (ViewerTest::CurrentView().IsNull())
1184 std::cerr << "No active view!\n";
1187 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1190 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1191 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1192 anIter.More(); anIter.Next())
1194 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1200 //==============================================================================
1201 //function : VActivate
1202 //purpose : Activate the view defined by its ID
1203 //==============================================================================
1205 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1209 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1210 << "Usage: " << theArgVec[0] << " ViewID\n";
1215 theDi.Eval("vviewlist");
1219 TCollection_AsciiString aNameString(theArgVec[1]);
1220 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1222 TCollection_AsciiString aTitle("3D View - ");
1223 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1224 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1225 Handle(V3d_View) anEmptyView;
1226 #if defined(_WIN32) || defined(__WIN32__)
1227 Handle(WNT_Window) anEmptyWindow;
1228 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1229 Handle(Cocoa_Window) anEmptyWindow;
1231 Handle(Xw_Window) anEmptyWindow;
1233 VT_GetWindow() = anEmptyWindow;
1234 ViewerTest::CurrentView (anEmptyView);
1235 ViewerTest::ResetEventManager();
1236 theDi << theArgVec[0] << ": all views are inactive\n";
1240 ViewerTest_Names aViewNames(aNameString);
1242 // Check if this view exists in the viewer with the driver
1243 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1245 theDi << "Wrong view name\n";
1249 // Check if it is active already
1250 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1252 theDi << theArgVec[0] << ": the view is active already\n";
1256 ActivateView (aViewNames.GetViewName());
1260 //==============================================================================
1261 //function : VViewList
1262 //purpose : Print current list of views per viewer and graphic driver ID
1263 // shared between viewers
1264 //==============================================================================
1266 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1270 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1271 << "Usage: " << theArgVec[0] << " name";
1274 if (ViewerTest_myContexts.Size() < 1)
1277 Standard_Boolean isTreeView =
1278 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1281 theDi << theArgVec[0] <<":\n";
1283 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1284 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1287 theDi << aDriverIter.Key1() << ":\n";
1289 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1290 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1292 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1296 TCollection_AsciiString aContextName(aContextIter.Key1());
1297 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
1300 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1301 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1303 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1305 TCollection_AsciiString aViewName(aViewIter.Key1());
1308 if (aViewIter.Value() == ViewerTest::CurrentView())
1309 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
1311 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1315 theDi << aViewName << " ";
1325 //==============================================================================
1326 //function : VT_ProcessKeyPress
1327 //purpose : Handle KeyPress event from a CString
1328 //==============================================================================
1329 void VT_ProcessKeyPress (const char* buf_ret)
1331 //cout << "KeyPress" << endl;
1332 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1333 // Letter in alphabetic order
1335 if (!strcasecmp (buf_ret, "A"))
1338 aView->SetProj(V3d_XposYnegZpos);
1340 else if (!strcasecmp (buf_ret, "D"))
1345 else if (!strcasecmp (buf_ret, "F"))
1347 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1349 ViewerTest::GetAISContext()->FitSelected (aView);
1357 else if (!strcasecmp (buf_ret, "H"))
1360 cout << "HLR" << endl;
1361 aView->SetComputedMode (!aView->ComputedMode());
1362 MyHLRIsOn = aView->ComputedMode();
1364 else if (!strcasecmp (buf_ret, "P"))
1367 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1368 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1369 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1371 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1372 if (aContext->NbSelected()==0)
1374 AIS_ListOfInteractive aListOfShapes;
1375 aContext->DisplayedObjects(aListOfShapes);
1376 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1377 anIter.More(); anIter.Next())
1379 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1380 if (aShape.IsNull())
1382 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1383 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1385 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1386 aContext->Redisplay (aShape, Standard_False);
1391 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
1393 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
1394 if (aShape.IsNull())
1396 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1397 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1399 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1400 aContext->Redisplay (aShape, Standard_False);
1404 aContext->UpdateCurrentViewer();
1407 else if (!strcasecmp (buf_ret, "S"))
1409 std::cout << "setup Shaded display mode" << std::endl;
1411 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1412 if(Ctx->NbSelected()==0)
1413 Ctx->SetDisplayMode(AIS_Shaded);
1415 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1416 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
1417 Ctx->UpdateCurrentViewer();
1420 else if (!strcasecmp (buf_ret, "U"))
1422 // Unset display mode
1423 std::cout << "reset display mode to defaults" << std::endl;
1425 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1426 if(Ctx->NbSelected()==0)
1427 Ctx->SetDisplayMode(AIS_WireFrame);
1429 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1430 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
1431 Ctx->UpdateCurrentViewer();
1435 else if (!strcasecmp (buf_ret, "T"))
1438 aView->SetProj(V3d_Zpos);
1440 else if (!strcasecmp (buf_ret, "B"))
1443 aView->SetProj(V3d_Zneg);
1445 else if (!strcasecmp (buf_ret, "L"))
1448 aView->SetProj(V3d_Xneg);
1450 else if (!strcasecmp (buf_ret, "R"))
1453 aView->SetProj(V3d_Xpos);
1455 else if (!strcasecmp (buf_ret, "W"))
1457 std::cout << "setup WireFrame display mode" << std::endl;
1458 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1459 if(Ctx->NbSelected()==0)
1460 Ctx->SetDisplayMode(AIS_WireFrame);
1462 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1463 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
1464 Ctx->UpdateCurrentViewer();
1467 else if (!strcasecmp (buf_ret, "Z"))
1471 cout << "ZClipping OFF" << endl;
1474 aView->SetZClippingType(V3d_OFF);
1478 cout << "ZClipping ON" << endl;
1481 aView->SetZClippingType(V3d_FRONT);
1485 else if (!strcasecmp (buf_ret, ","))
1487 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1489 else if (!strcasecmp (buf_ret, "."))
1491 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1493 else if (!strcasecmp (buf_ret, "/"))
1495 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1496 if (aCamera->IsStereo())
1498 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1502 else if (!strcasecmp (buf_ret, "*"))
1504 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1505 if (aCamera->IsStereo())
1507 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1511 else if (*buf_ret == THE_KEY_DELETE)
1513 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1515 && aCtx->NbSelected() > 0)
1517 Draw_Interprete ("verase");
1523 Standard_Integer Num = Draw::Atoi(buf_ret);
1524 if(Num>=0 && Num<=7)
1525 ViewerTest::StandardModeActivation(Num);
1529 //==============================================================================
1530 //function : VT_ProcessExpose
1531 //purpose : Redraw the View on an Expose Event
1532 //==============================================================================
1533 void VT_ProcessExpose()
1535 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1536 if (!aView3d.IsNull())
1542 //==============================================================================
1543 //function : VT_ProcessConfigure
1544 //purpose : Resize the View on an Configure Event
1545 //==============================================================================
1546 void VT_ProcessConfigure()
1548 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1549 if (aView3d.IsNull())
1554 aView3d->MustBeResized();
1559 //==============================================================================
1560 //function : VT_ProcessButton1Press
1562 //==============================================================================
1563 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1564 const char** theArgVec,
1565 Standard_Boolean theToPick,
1566 Standard_Boolean theIsShift)
1570 Standard_Real X, Y, Z;
1571 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1573 Draw::Set (theArgVec[1], X);
1574 Draw::Set (theArgVec[2], Y);
1575 Draw::Set (theArgVec[3], Z);
1580 ViewerTest::CurrentEventManager()->ShiftSelect();
1584 ViewerTest::CurrentEventManager()->Select();
1587 return Standard_False;
1590 //==============================================================================
1591 //function : VT_ProcessButton1Release
1592 //purpose : End selecting
1593 //==============================================================================
1594 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1598 IsDragged = Standard_False;
1599 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1602 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1603 X_Motion, Y_Motion);
1607 EM->Select (X_ButtonPress, Y_ButtonPress,
1608 X_Motion, Y_Motion);
1613 //==============================================================================
1614 //function : VT_ProcessButton3Press
1615 //purpose : Start Rotation
1616 //==============================================================================
1617 void VT_ProcessButton3Press()
1622 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1624 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1627 //==============================================================================
1628 //function : VT_ProcessButton3Release
1629 //purpose : End rotation
1630 //==============================================================================
1631 void VT_ProcessButton3Release()
1638 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1643 //==============================================================================
1644 //function : ProcessZClipMotion
1646 //==============================================================================
1648 void ProcessZClipMotion()
1650 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1651 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1653 //Quantity_Length VDX, VDY;
1654 //a3DView->Size(VDX,VDY);
1655 //Standard_Real VDZ = a3DView->ZSize();
1656 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1658 Quantity_Length aDx = a3DView->Convert(X_Motion - X_ButtonPress);
1660 // Front = Depth + width/2.
1661 Standard_Real aDepth = 0.5;
1662 Standard_Real aWidth = 0.1;
1663 a3DView->ZClipping(aDepth,aWidth);
1667 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1669 a3DView->SetZClippingDepth(aDepth);
1673 X_ButtonPress = X_Motion;
1674 Y_ButtonPress = Y_Motion;
1678 //==============================================================================
1679 //function : ProcessControlButton1Motion
1681 //==============================================================================
1683 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1684 static void ProcessControlButton1Motion()
1686 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1688 X_ButtonPress = X_Motion;
1689 Y_ButtonPress = Y_Motion;
1693 //==============================================================================
1694 //function : VT_ProcessControlButton2Motion
1696 //==============================================================================
1697 void VT_ProcessControlButton2Motion()
1699 Standard_Integer aDx = X_Motion - X_ButtonPress;
1700 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1702 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1704 ViewerTest::CurrentView()->Pan (aDx, aDy);
1706 X_ButtonPress = X_Motion;
1707 Y_ButtonPress = Y_Motion;
1710 //==============================================================================
1711 //function : VT_ProcessControlButton3Motion
1712 //purpose : Rotation
1713 //==============================================================================
1714 void VT_ProcessControlButton3Motion()
1718 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1722 //==============================================================================
1723 //function : VT_ProcessMotion
1725 //==============================================================================
1726 void VT_ProcessMotion()
1728 //pre-hilights detected objects at mouse position
1730 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1731 EM->MoveTo(X_Motion, Y_Motion);
1735 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1737 Xpix = X_Motion;Ypix=Y_Motion;
1740 //==============================================================================
1741 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1742 //purpose : Switches to an axonometric, top, left and other views
1743 //==============================================================================
1745 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1747 if ( ViewerTest::CurrentView().IsNull() )
1749 di<<"Call vinit before this command, please\n";
1753 ViewerTest::CurrentView()->SetProj(ori);
1757 //==============================================================================
1759 //purpose : Switch to an Axonometric view
1760 //Draw arg : No args
1761 //==============================================================================
1763 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1765 return ViewProject(di, V3d_XposYnegZpos);
1768 //==============================================================================
1770 //purpose : Switch to a Top View
1771 //Draw arg : No args
1772 //==============================================================================
1774 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1776 return ViewProject(di, V3d_Zpos);
1779 //==============================================================================
1780 //function : VBottom
1781 //purpose : Switch to a Bottom View
1782 //Draw arg : No args
1783 //==============================================================================
1785 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1787 return ViewProject(di, V3d_Zneg);
1790 //==============================================================================
1792 //purpose : Switch to a Left View
1793 //Draw arg : No args
1794 //==============================================================================
1796 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1798 return ViewProject(di, V3d_Xneg);
1801 //==============================================================================
1803 //purpose : Switch to a Right View
1804 //Draw arg : No args
1805 //==============================================================================
1807 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1809 return ViewProject(di, V3d_Xpos);
1812 //==============================================================================
1814 //purpose : Switch to a Front View
1815 //Draw arg : No args
1816 //==============================================================================
1818 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1820 return ViewProject(di, V3d_Yneg);
1823 //==============================================================================
1825 //purpose : Switch to a Back View
1826 //Draw arg : No args
1827 //==============================================================================
1829 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1831 return ViewProject(di, V3d_Ypos);
1834 //==============================================================================
1836 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1837 //Draw arg : No args
1838 //==============================================================================
1840 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1843 di << "Q : Quit the application\n";
1845 di << "=========================\n";
1846 di << "F : FitAll\n";
1847 di << "T : TopView\n";
1848 di << "B : BottomView\n";
1849 di << "R : RightView\n";
1850 di << "L : LeftView\n";
1851 di << "A : AxonometricView\n";
1852 di << "D : ResetView\n";
1854 di << "=========================\n";
1855 di << "S : Shading\n";
1856 di << "W : Wireframe\n";
1857 di << "H : HidelLineRemoval\n";
1858 di << "U : Unset display mode\n";
1859 di << "Delete : Remove selection from viewer\n";
1861 di << "=========================\n";
1862 di << "Selection mode \n";
1863 di << "0 : Shape\n";
1864 di << "1 : Vertex\n";
1868 di << "5 : Shell\n";
1869 di << "6 : Solid\n";
1870 di << "7 : Compound\n";
1872 di << "=========================\n";
1873 di << "Z : Switch Z clipping On/Off\n";
1874 di << ", : Hilight next detected\n";
1875 di << ". : Hilight previous detected\n";
1882 static Standard_Boolean Ppick = 0;
1883 static Standard_Integer Pargc = 0;
1884 static const char** Pargv = NULL;
1887 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1892 if (!ViewerTest_myViews.IsEmpty()) {
1894 WPARAM fwKeys = wParam;
1899 // Delete view from map of views
1900 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1905 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1906 || ViewerTest::CurrentView().IsNull())
1908 // Activate inactive window
1909 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1911 ActivateView (FindViewIdByWindowHandle(hwnd));
1918 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
1920 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
1921 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
1924 VT_ProcessButton1Release (fwKeys & MK_SHIFT);
1926 IsDragged = Standard_False;
1927 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1929 case WM_LBUTTONDOWN:
1930 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1932 IsDragged = Standard_True;
1933 DragFirst = Standard_True;
1934 X_ButtonPress = LOWORD(lParam);
1935 Y_ButtonPress = HIWORD(lParam);
1937 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1944 bool toRedraw = false;
1945 if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
1947 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
1951 DragFirst = Standard_False;
1952 X_Motion = LOWORD (lParam);
1953 Y_Motion = HIWORD (lParam);
1956 if (GetClientRect (hwnd, &aRect))
1958 int aHeight = aRect.bottom - aRect.top;
1959 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
1960 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed);
1965 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
1969 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1973 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1977 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1981 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1987 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
1990 return DefWindowProc( hwnd, Msg, wParam, lParam );
1997 BeginPaint(hwnd, &ps);
1998 EndPaint(hwnd, &ps);
2003 VT_ProcessConfigure();
2008 switch (aView->RenderingParams().StereoMode)
2010 case Graphic3d_StereoMode_RowInterlaced:
2011 case Graphic3d_StereoMode_ColumnInterlaced:
2012 case Graphic3d_StereoMode_ChessBoard:
2013 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2021 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2024 c[0] = (char) wParam;
2026 if (wParam == VK_DELETE)
2028 c[0] = THE_KEY_DELETE;
2031 else if (wParam == VK_OEM_COMMA)
2036 else if (wParam == VK_OEM_PERIOD)
2040 else if (wParam == VK_DIVIDE)
2045 else if (wParam == VK_MULTIPLY)
2049 VT_ProcessKeyPress (c);
2057 VT_ProcessButton3Release();
2060 case WM_LBUTTONDOWN:
2061 case WM_MBUTTONDOWN:
2062 case WM_RBUTTONDOWN:
2064 WPARAM fwKeys = wParam;
2068 X_ButtonPress = LOWORD(lParam);
2069 Y_ButtonPress = HIWORD(lParam);
2071 if (Msg == WM_LBUTTONDOWN)
2073 if (fwKeys & MK_CONTROL)
2075 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2079 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2082 else if (Msg == WM_RBUTTONDOWN)
2085 VT_ProcessButton3Press();
2092 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2093 if (wParam & MK_CONTROL)
2095 if (aView->Camera()->IsStereo())
2097 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2101 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2108 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2115 //cout << "\t WM_MOUSEMOVE" << endl;
2116 WPARAM fwKeys = wParam;
2117 X_Motion = LOWORD(lParam);
2118 Y_Motion = HIWORD(lParam);
2121 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2123 X_ButtonPress = LOWORD(lParam);
2124 Y_ButtonPress = HIWORD(lParam);
2126 if ( fwKeys & MK_RBUTTON ) {
2128 VT_ProcessButton3Press();
2132 if ( fwKeys & MK_CONTROL ) {
2133 if ( fwKeys & MK_LBUTTON ) {
2134 ProcessControlButton1Motion();
2136 else if ( fwKeys & MK_MBUTTON ||
2137 ((fwKeys&MK_LBUTTON) &&
2138 (fwKeys&MK_RBUTTON) ) ){
2139 VT_ProcessControlButton2Motion();
2141 else if ( fwKeys & MK_RBUTTON ) {
2142 VT_ProcessControlButton3Motion();
2146 else if ( fwKeys & MK_SHIFT ) {
2147 if ( fwKeys & MK_MBUTTON ||
2148 ((fwKeys&MK_LBUTTON) &&
2149 (fwKeys&MK_RBUTTON) ) ) {
2150 cout << "ProcessZClipMotion()" << endl;
2151 ProcessZClipMotion();
2155 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2157 if ((fwKeys & MK_MBUTTON
2158 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2160 ProcessZClipMotion();
2171 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2179 //==============================================================================
2180 //function : ViewerMainLoop
2181 //purpose : Get a Event on the view and dispatch it
2182 //==============================================================================
2185 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2187 Ppick = (argc > 0)? 1 : 0;
2195 cout << "Start picking" << endl;
2197 while ( Ppick == 1 ) {
2198 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2199 if (GetMessage(&msg, NULL, 0, 0) ) {
2200 TranslateMessage(&msg);
2201 DispatchMessage(&msg);
2205 cout << "Picking done" << endl;
2211 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2213 int min( int a, int b )
2221 int max( int a, int b )
2229 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2232 static XEvent aReport;
2233 Standard_Boolean pick = argc > 0;
2234 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2235 XNextEvent (aDisplay, &aReport);
2237 // Handle event for the chosen display connection
2238 switch (aReport.type) {
2241 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2244 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2250 // Activate inactive view
2251 Window aWindow = GetWindowHandle(VT_GetWindow());
2252 if(aWindow != aReport.xfocus.window)
2254 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2263 case ConfigureNotify:
2265 VT_ProcessConfigure();
2274 XComposeStatus status_in_out;
2276 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2277 (char *) buf_ret , 10 ,
2278 &ks_ret , &status_in_out ) ;
2281 buf_ret[ret_len] = '\0' ;
2285 VT_ProcessKeyPress (buf_ret);
2291 X_ButtonPress = aReport.xbutton.x;
2292 Y_ButtonPress = aReport.xbutton.y;
2294 if (aReport.xbutton.button == Button1)
2296 if (aReport.xbutton.state & ControlMask)
2298 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2302 IsDragged = Standard_True;
2303 DragFirst = Standard_True;
2306 else if (aReport.xbutton.button == Button3)
2309 VT_ProcessButton3Press();
2319 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2321 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2322 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2326 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2327 if( aContext.IsNull() )
2329 cout << "The context is null. Please use vinit before createmesh" << endl;
2333 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2334 if( aReport.xbutton.button==1 )
2338 aContext->ShiftSelect();
2347 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2348 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2349 ViewerTest::CurrentView());
2353 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2354 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2355 ViewerTest::CurrentView() );
2358 VT_ProcessButton3Release();
2360 IsDragged = Standard_False;
2363 VT_ProcessButton3Release();
2368 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2376 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2378 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2382 X_Motion = aReport.xmotion.x;
2383 Y_Motion = aReport.xmotion.y;
2384 DragFirst = Standard_False;
2386 Window aWindow = GetWindowHandle(VT_GetWindow());
2389 unsigned int aWidth, aHeight, aBorderWidth, aDepth;
2390 XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth);
2391 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2392 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed);
2393 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2397 X_Motion = aReport.xmotion.x;
2398 Y_Motion = aReport.xmotion.y;
2400 // remove all the ButtonMotionMaskr
2401 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2403 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2404 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2406 Quantity_Length VDX, VDY;
2408 ViewerTest::CurrentView()->Size(VDX,VDY);
2409 Standard_Real VDZ =0 ;
2410 VDZ = ViewerTest::CurrentView()->ZSize();
2412 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2414 Quantity_Length dx = 0 ;
2415 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2419 dx = dx / VDX * VDZ;
2423 ViewerTest::CurrentView()->Redraw();
2427 if ( aReport.xmotion.state & ControlMask ) {
2428 if ( aReport.xmotion.state & Button1Mask ) {
2429 ProcessControlButton1Motion();
2431 else if ( aReport.xmotion.state & Button2Mask ) {
2432 VT_ProcessControlButton2Motion();
2434 else if ( aReport.xmotion.state & Button3Mask ) {
2435 VT_ProcessControlButton3Motion();
2449 //==============================================================================
2450 //function : VProcessEvents
2451 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2452 // event in the Viewer window
2453 //==============================================================================
2455 static void VProcessEvents(ClientData,int)
2457 NCollection_Vector<int> anEventNumbers;
2458 // Get number of messages from every display
2459 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2460 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2462 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2464 // Handle events for every display
2465 int anEventIter = 0;
2466 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2467 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2469 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2470 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2472 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2473 int anEventResult = ViewerMainLoop( 0, NULL);
2474 // If window is closed or context was not found finish current event processing loop
2480 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2485 //==============================================================================
2486 //function : OSWindowSetup
2487 //purpose : Setup for the X11 window to be able to cath the event
2488 //==============================================================================
2491 static void OSWindowSetup()
2493 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2496 Window window = VT_GetWindow()->XWindow();
2497 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2498 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2499 XSynchronize(aDisplay, 1);
2501 // X11 : For keyboard on SUN
2503 wmhints.flags = InputHint;
2506 XSetWMHints( aDisplay, window, &wmhints);
2508 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2509 ButtonPressMask | ButtonReleaseMask |
2510 StructureNotifyMask |
2512 Button1MotionMask | Button2MotionMask |
2513 Button3MotionMask | FocusChangeMask
2515 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2516 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2518 XSynchronize(aDisplay, 0);
2526 //==============================================================================
2529 //purpose : Fitall, no DRAW arguments
2530 //Draw arg : No args
2531 //==============================================================================
2533 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgc, const char** theArgv)
2537 std::cout << "Wrong number of arguments! Use: vfit [-selected]" << std::endl;
2540 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2544 TCollection_AsciiString anArg (theArgv[1]);
2546 if (anArg == "-selected")
2548 ViewerTest::GetAISContext()->FitSelected (aView);
2552 if (aView.IsNull() == Standard_False) {
2559 //=======================================================================
2560 //function : VFitArea
2561 //purpose : Fit view to show area located between two points
2562 // : given in world 2D or 3D coordinates.
2563 //=======================================================================
2564 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2566 Handle(V3d_View) aView = ViewerTest::CurrentView();
2569 std::cerr << theArgVec[0] << "Error: No active view.\n";
2574 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2575 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2579 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2580 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2581 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2582 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2584 else if (theArgNb == 7)
2586 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2587 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2588 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2589 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2590 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2591 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2595 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2596 theDI.PrintHelp(theArgVec[0]);
2600 // Convert model coordinates to view space
2601 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2602 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2603 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2605 // Determine fit area
2606 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2607 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2609 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2611 if (aDiagonal < Precision::Confusion())
2613 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2617 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2621 //==============================================================================
2623 //purpose : ZFitall, no DRAW arguments
2624 //Draw arg : No args
2625 //==============================================================================
2626 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2628 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2630 if (aCurrentView.IsNull())
2632 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2638 aCurrentView->ZFitAll();
2639 aCurrentView->Redraw();
2643 Standard_Real aScale = 1.0;
2647 aScale = Draw::Atoi (theArgVec[1]);
2650 aCurrentView->ZFitAll (aScale);
2651 aCurrentView->Redraw();
2656 //==============================================================================
2657 //function : VRepaint
2659 //==============================================================================
2660 static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
2662 Handle(V3d_View) V = ViewerTest::CurrentView();
2663 if ( !V.IsNull() ) V->Redraw(); return 0;
2666 //==============================================================================
2668 //purpose : Remove all the object from the viewer
2669 //Draw arg : No args
2670 //==============================================================================
2672 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2674 Handle(V3d_View) V = ViewerTest::CurrentView();
2676 ViewerTest::Clear();
2680 //==============================================================================
2683 //==============================================================================
2685 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2686 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2689 di << argv[0] << "Invalid number of arguments\n";
2693 while (ViewerMainLoop( argc, argv)) {
2699 //==============================================================================
2701 //purpose : Load image as background
2702 //==============================================================================
2704 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2706 if (argc < 2 || argc > 3)
2708 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n";
2709 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n";
2713 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2714 if(AISContext.IsNull())
2716 di << "use 'vinit' command before " << argv[0] << "\n";
2720 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2723 const char* szType = argv[2];
2724 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2725 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2726 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2727 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2730 di << "Wrong fill type : " << szType << "\n";
2731 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
2736 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2737 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2742 //==============================================================================
2743 //function : VSetBgMode
2744 //purpose : Change background image fill type
2745 //==============================================================================
2747 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2751 di << "Usage : " << argv[0] << " filltype : Change background image mode\n";
2752 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n";
2756 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2757 if(AISContext.IsNull())
2759 di << "use 'vinit' command before " << argv[0] << "\n";
2762 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2763 const char* szType = argv[1];
2764 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2765 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2766 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2767 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2770 di << "Wrong fill type : " << szType << "\n";
2771 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
2774 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2775 V3dView->SetBgImageStyle(aFillType, Standard_True);
2779 //==============================================================================
2780 //function : VSetGradientBg
2781 //purpose : Mount gradient background
2782 //==============================================================================
2783 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2787 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background\n";
2788 di << "R1,G1,B1,R2,G2,B2 = [0..255]\n";
2789 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2790 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
2794 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2795 if(AISContext.IsNull())
2797 di << "use 'vinit' command before " << argv[0] << "\n";
2803 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2804 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2805 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2806 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2808 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2809 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2810 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2812 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2813 int aType = Draw::Atoi(argv[7]);
2814 if( aType < 0 || aType > 8 )
2816 di << "Wrong fill type \n";
2817 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2818 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
2822 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2824 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2825 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2831 //==============================================================================
2832 //function : VSetGradientBgMode
2833 //purpose : Change gradient background fill style
2834 //==============================================================================
2835 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2839 di << "Usage : " << argv[0] << " Type : Change gradient background fill type\n";
2840 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2841 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
2845 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2846 if(AISContext.IsNull())
2848 di << "use 'vinit' command before " << argv[0] << "\n";
2853 int aType = Draw::Atoi(argv[1]);
2854 if( aType < 0 || aType > 8 )
2856 di << "Wrong fill type \n";
2857 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2858 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
2862 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2864 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2865 V3dView->SetBgGradientStyle( aMethod, 1 );
2871 //==============================================================================
2872 //function : VSetColorBg
2873 //purpose : Set color background
2874 //==============================================================================
2875 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2879 di << "Usage : " << argv[0] << " R G B : Set color background\n";
2880 di << "R,G,B = [0..255]\n";
2884 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2885 if(AISContext.IsNull())
2887 di << "use 'vinit' command before " << argv[0] << "\n";
2893 Standard_Real R = Draw::Atof(argv[1])/255.;
2894 Standard_Real G = Draw::Atof(argv[2])/255.;
2895 Standard_Real B = Draw::Atof(argv[3])/255.;
2896 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2898 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2899 V3dView->SetBackgroundColor( aColor );
2906 //==============================================================================
2907 //function : VSetDefaultBg
2908 //purpose : Set default viewer background fill color
2909 //==============================================================================
2910 static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2915 std::cout << "Error: wrong syntax! See usage:\n";
2916 theDI.PrintHelp (theArgVec[0]);
2920 ViewerTest_DefaultBackground.FillMethod =
2921 theArgNb == 4 ? Aspect_GFM_NONE
2922 : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]);
2926 Standard_Real R = Draw::Atof (theArgVec[1]) / 255.;
2927 Standard_Real G = Draw::Atof (theArgVec[2]) / 255.;
2928 Standard_Real B = Draw::Atof (theArgVec[3]) / 255.;
2929 ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB);
2933 Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.;
2934 Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.;
2935 Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.;
2936 ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB);
2938 Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.;
2939 Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.;
2940 Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.;
2941 ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB);
2944 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
2945 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
2947 const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer();
2948 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
2949 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
2950 ViewerTest_DefaultBackground.GradientColor2,
2951 ViewerTest_DefaultBackground.FillMethod);
2957 //==============================================================================
2959 //purpose : View Scaling
2960 //==============================================================================
2962 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2964 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2965 if ( V3dView.IsNull() ) return 1;
2968 di << argv[0] << "Invalid number of arguments\n";
2971 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2974 //==============================================================================
2975 //function : VZBuffTrihedron
2977 //==============================================================================
2979 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
2980 Standard_Integer theArgNb,
2981 const char** theArgVec)
2983 Handle(V3d_View) aView = ViewerTest::CurrentView();
2986 std::cout << "Error: no active viewer!\n";
2990 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
2992 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2993 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
2994 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
2995 Quantity_Color anArrowColorX = Quantity_NOC_RED;
2996 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
2997 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
2998 Standard_Real aScale = 0.1;
2999 Standard_Real aSizeRatio = 0.8;
3000 Standard_Real anArrowDiam = 0.05;
3001 Standard_Integer aNbFacets = 12;
3002 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3004 Standard_CString anArg = theArgVec[anArgIter];
3005 TCollection_AsciiString aFlag (anArg);
3007 if (anUpdateTool.parseRedrawMode (aFlag))
3011 else if (aFlag == "-on")
3015 else if (aFlag == "-off")
3017 aView->TriedronErase();
3020 else if (aFlag == "-pos"
3021 || aFlag == "-position"
3022 || aFlag == "-corner")
3024 if (++anArgIter >= theArgNb)
3026 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3030 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3031 aPosName.LowerCase();
3032 if (aPosName == "center")
3034 aPosition = Aspect_TOTP_CENTER;
3036 else if (aPosName == "left_lower"
3037 || aPosName == "lower_left"
3038 || aPosName == "leftlower"
3039 || aPosName == "lowerleft")
3041 aPosition = Aspect_TOTP_LEFT_LOWER;
3043 else if (aPosName == "left_upper"
3044 || aPosName == "upper_left"
3045 || aPosName == "leftupper"
3046 || aPosName == "upperleft")
3048 aPosition = Aspect_TOTP_LEFT_UPPER;
3050 else if (aPosName == "right_lower"
3051 || aPosName == "lower_right"
3052 || aPosName == "rightlower"
3053 || aPosName == "lowerright")
3055 aPosition = Aspect_TOTP_RIGHT_LOWER;
3057 else if (aPosName == "right_upper"
3058 || aPosName == "upper_right"
3059 || aPosName == "rightupper"
3060 || aPosName == "upperright")
3062 aPosition = Aspect_TOTP_RIGHT_UPPER;
3066 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3070 else if (aFlag == "-type")
3072 if (++anArgIter >= theArgNb)
3074 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3078 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3079 aTypeName.LowerCase();
3080 if (aTypeName == "wireframe"
3081 || aTypeName == "wire")
3083 aVisType = V3d_WIREFRAME;
3085 else if (aTypeName == "zbuffer"
3086 || aTypeName == "shaded")
3088 aVisType = V3d_ZBUFFER;
3092 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3095 else if (aFlag == "-scale")
3097 if (++anArgIter >= theArgNb)
3099 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3103 aScale = Draw::Atof (theArgVec[anArgIter]);
3105 else if (aFlag == "-size"
3106 || aFlag == "-sizeratio")
3108 if (++anArgIter >= theArgNb)
3110 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3114 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3116 else if (aFlag == "-arrowdiam"
3117 || aFlag == "-arrowdiameter")
3119 if (++anArgIter >= theArgNb)
3121 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3125 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3127 else if (aFlag == "-nbfacets")
3129 if (++anArgIter >= theArgNb)
3131 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3135 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3137 else if (aFlag == "-colorlabel"
3138 || aFlag == "-colorlabels")
3140 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3141 theArgVec + anArgIter + 1,
3145 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3148 anArgIter += aNbParsed;
3150 else if (aFlag == "-colorarrowx")
3152 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3153 theArgVec + anArgIter + 1,
3157 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3160 anArgIter += aNbParsed;
3162 else if (aFlag == "-colorarrowy")
3164 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3165 theArgVec + anArgIter + 1,
3169 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3172 anArgIter += aNbParsed;
3174 else if (aFlag == "-colorarrowz")
3176 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3177 theArgVec + anArgIter + 1,
3181 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3184 anArgIter += aNbParsed;
3188 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3193 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3194 aSizeRatio, anArrowDiam, aNbFacets);
3195 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
3200 //==============================================================================
3201 //function : VRotate
3202 //purpose : Camera Rotating
3203 //==============================================================================
3205 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3207 Handle(V3d_View) aView = ViewerTest::CurrentView();
3210 std::cout << "No active view!\n";
3214 Standard_Boolean hasFlags = Standard_False;
3215 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3217 Standard_CString anArg (theArgVec[anArgIter]);
3218 TCollection_AsciiString aFlag (anArg);
3220 if (aFlag == "-mousestart"
3221 || aFlag == "-mousefrom")
3223 hasFlags = Standard_True;
3224 if (anArgIter + 2 >= theArgNb)
3226 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3230 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3231 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3232 aView->StartRotation (anX, anY);
3234 else if (aFlag == "-mousemove")
3236 hasFlags = Standard_True;
3237 if (anArgIter + 2 >= theArgNb)
3239 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3243 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3244 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3245 aView->Rotation (anX, anY);
3247 else if (theArgNb != 4
3250 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3259 else if (theArgNb == 4)
3261 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3262 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3263 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3264 aView->Rotate (anAX, anAY, anAZ);
3267 else if (theArgNb == 7)
3269 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3270 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3271 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3273 Standard_Real anX = Draw::Atof (theArgVec[4]);
3274 Standard_Real anY = Draw::Atof (theArgVec[5]);
3275 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3277 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3281 std::cout << "Error: Invalid number of arguments\n";
3285 //==============================================================================
3287 //purpose : View zoom in / out (relative to current zoom)
3288 //==============================================================================
3290 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3291 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3292 if ( V3dView.IsNull() ) {
3297 Standard_Real coef = Draw::Atof(argv[1]);
3298 if ( coef <= 0.0 ) {
3299 di << argv[1] << "Invalid value\n";
3302 V3dView->SetZoom( Draw::Atof(argv[1]) );
3305 di << argv[0] << " Invalid number of arguments\n";
3310 //==============================================================================
3312 //purpose : View panning (in pixels)
3313 //==============================================================================
3315 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3316 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3317 if ( V3dView.IsNull() ) return 1;
3320 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
3323 di << argv[0] << " Invalid number of arguments\n";
3328 //==============================================================================
3330 //purpose : Place the point (in pixels) at the center of the window
3331 //==============================================================================
3332 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3334 Handle(V3d_View) aView = ViewerTest::CurrentView();
3337 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3343 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3347 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3352 //==============================================================================
3353 //function : VExport
3354 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
3355 //==============================================================================
3357 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3359 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3360 if (V3dView.IsNull())
3365 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
3369 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
3370 TCollection_AsciiString aFormatStr;
3372 TCollection_AsciiString aFileName (argv[1]);
3373 Standard_Integer aLen = aFileName.Length();
3377 aFormatStr = TCollection_AsciiString (argv[2]);
3381 if (aFileName.Value (aLen - 2) == '.')
3383 aFormatStr = aFileName.ToCString() + aLen - 2;
3385 else if (aFileName.Value (aLen - 3) == '.')
3387 aFormatStr = aFileName.ToCString() + aLen - 3;
3391 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3397 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3401 aFormatStr.UpperCase();
3402 if (aFormatStr == "PS")
3403 anExpFormat = Graphic3d_EF_PostScript;
3404 else if (aFormatStr == "EPS")
3405 anExpFormat = Graphic3d_EF_EnhPostScript;
3406 else if (aFormatStr == "TEX")
3407 anExpFormat = Graphic3d_EF_TEX;
3408 else if (aFormatStr == "PDF")
3409 anExpFormat = Graphic3d_EF_PDF;
3410 else if (aFormatStr == "SVG")
3411 anExpFormat = Graphic3d_EF_SVG;
3412 else if (aFormatStr == "PGF")
3413 anExpFormat = Graphic3d_EF_PGF;
3414 else if (aFormatStr == "EMF")
3415 anExpFormat = Graphic3d_EF_EMF;
3418 std::cout << "Invalid export format '" << aFormatStr << "'\n";
3424 if (!V3dView->Export (argv[1], anExpFormat))
3426 di << "Error: export of image to " << aFormatStr << " failed!\n";
3429 catch (Standard_Failure)
3431 di << "Error: export of image to " << aFormatStr << " failed";
3432 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
3437 //==============================================================================
3438 //function : VColorScale
3439 //purpose : representation color scale
3440 //==============================================================================
3442 static Standard_Boolean checkColor (const TCollection_AsciiString& theRed,
3443 const TCollection_AsciiString& theGreen,
3444 const TCollection_AsciiString& theBlue,
3445 Standard_Real& theRedValue,
3446 Standard_Real& theGreenValue,
3447 Standard_Real& theBlueValue)
3449 if (!theRed.IsRealValue()
3450 || !theGreen.IsRealValue()
3451 || !theBlue.IsRealValue())
3453 std::cout << "Error: RGB color values should be real!\n";
3454 return Standard_True;
3456 theRedValue = theRed .RealValue();
3457 theGreenValue = theGreen.RealValue();
3458 theBlueValue = theBlue .RealValue();
3459 if (theRedValue < 0.0 || theRedValue > 1.0
3460 || theGreenValue < 0.0 || theGreenValue > 1.0
3461 || theBlueValue < 0.0 || theBlueValue > 1.0)
3463 std::cout << "Error: RGB color values should be within range 0..1!\n";
3464 return Standard_True;
3466 return Standard_False;
3469 static int VColorScale (Draw_Interpretor& theDI,
3470 Standard_Integer theArgNb,
3471 const char** theArgVec)
3473 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3474 Handle(V3d_View) aView = ViewerTest::CurrentView();
3475 if (aContext.IsNull())
3477 std::cout << "Error: no active view!\n";
3482 std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n";
3486 Handle(AIS_ColorScale) aCS;
3488 Handle(AIS_InteractiveObject) anIObj;
3489 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
3491 aCS = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
3494 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
3500 aCS = new AIS_ColorScale();
3501 GetMapOfAIS().Bind (aCS,theArgVec[1]);
3504 if (aCS->ZLayer() != Graphic3d_ZLayerId_TopOSD)
3506 aCS->SetZLayer (Graphic3d_ZLayerId_TopOSD);
3508 if (aCS->GetTransformPersistenceMode() != Graphic3d_TMF_2d)
3510 aCS->SetTransformPersistence (Graphic3d_TMF_2d, gp_Pnt (-1,-1,0));
3513 Standard_Real aMinRange = aCS->GetMin();
3514 Standard_Real aMaxRange = aCS->GetMax();
3515 Standard_Integer aBreadth = aCS->GetBreadth();
3516 Standard_Integer aHeight = aCS->GetHeight();
3517 Standard_Integer aNbIntervals = aCS->GetNumberOfIntervals();
3518 Standard_Integer aTextHeight = aCS->GetTextHeight();
3519 Aspect_TypeOfColorScalePosition aLabPosition = aCS->GetLabelPosition();
3520 Standard_Integer aPosX = aCS->GetXPosition();
3521 Standard_Integer aPosY = aCS->GetYPosition();
3523 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
3527 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
3528 << "Min range: " << aMinRange << "\n"
3529 << "Max range: " << aMaxRange << "\n"
3530 << "Number of intervals: " << aNbIntervals << "\n"
3531 << "Text height: " << aTextHeight << "\n"
3532 << "Color scale position: " << aPosX <<" "<< aPosY<< "\n"
3533 << "Color scale title: " << aCS->GetTitle() << "\n"
3534 << "Label position: ";
3535 switch (aLabPosition)
3537 case Aspect_TOCSP_NONE:
3540 case Aspect_TOCSP_LEFT:
3543 case Aspect_TOCSP_RIGHT:
3546 case Aspect_TOCSP_CENTER:
3547 theDI << "Center\n";
3553 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
3555 Standard_CString anArg = theArgVec[anArgIter];
3556 TCollection_AsciiString aFlag (anArg);
3558 if (anUpdateTool.parseRedrawMode (aFlag))
3562 else if (aFlag == "-range")
3564 if (anArgIter + 3 >= theArgNb)
3566 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3570 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
3571 TCollection_AsciiString anArg2 (theArgVec[++anArgIter]);
3572 TCollection_AsciiString anArg3 (theArgVec[++anArgIter]);
3573 if (!anArg1.IsRealValue())
3575 std::cout << "Error: the minRange value should be real!\n";
3578 else if (!anArg2.IsRealValue())
3580 std::cout << "Error: the maxRange value should be real!\n";
3583 else if (!anArg3.IsIntegerValue())
3585 std::cout << "Error: the number of intervals should be integer!\n";
3589 aMinRange = anArg1.RealValue();
3590 aMaxRange = anArg2.RealValue();
3591 aNbIntervals = anArg3.IntegerValue();
3593 else if (aFlag == "-font")
3595 if (anArgIter + 1 >= theArgNb)
3597 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3600 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
3601 if (!aFontArg.IsIntegerValue())
3603 std::cout << "Error: HeightFont value should be integer!\n";
3607 aTextHeight = aFontArg.IntegerValue();
3610 else if (aFlag == "-textpos")
3612 if (anArgIter + 1 >= theArgNb)
3614 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3617 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
3618 aTextPosArg.LowerCase();
3619 if (aTextPosArg == "none")
3621 aLabPosition = Aspect_TOCSP_NONE;
3623 else if (aTextPosArg == "left")
3625 aLabPosition = Aspect_TOCSP_LEFT;
3627 else if (aTextPosArg == "right")
3629 aLabPosition = Aspect_TOCSP_RIGHT;
3631 else if (aTextPosArg == "center")
3633 aLabPosition = Aspect_TOCSP_CENTER;
3637 std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
3641 else if (aFlag == "-logarithmic"
3644 if (anArgIter + 1 >= theArgNb)
3646 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3649 Standard_Boolean IsLog;
3650 if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
3652 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3655 aCS->SetLogarithmic (IsLog);
3657 else if (aFlag == "-xy")
3659 if (anArgIter + 2 >= theArgNb)
3661 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3665 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3666 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3667 if (!aX.IsIntegerValue()
3668 || !aY.IsIntegerValue())
3670 std::cout << "Error: coordinates should be integer values!\n";
3674 aPosX = aX.IntegerValue();
3675 aPosY = aY.IntegerValue();
3677 else if (aFlag == "-width"
3680 if (anArgIter + 1 >= theArgNb)
3682 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3686 TCollection_AsciiString aW (theArgVec[++anArgIter]);
3687 if (!aW.IsIntegerValue())
3689 std::cout << "Error: a width should be an integer value!\n";
3693 aBreadth = aW.IntegerValue();
3695 else if (aFlag == "-height"
3698 if (anArgIter + 1 >= theArgNb)
3700 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3704 TCollection_AsciiString aH (theArgVec[++anArgIter]);
3705 if (!aH.IsIntegerValue())
3707 std::cout << "Error: a width should be an integer value!\n";
3711 aHeight = aH.IntegerValue();
3713 else if (aFlag == "-color")
3715 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3717 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3721 Quantity_NameOfColor aColorName;
3722 if (anArgIter + 4 >= theArgNb)
3724 if (anArgIter + 2 >= theArgNb)
3726 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3729 else if (!Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3731 std::cout << "Error: wrong color name: '" << theArgVec[anArgIter + 2] << "' !\n";
3736 TCollection_AsciiString anInd (theArgVec[anArgIter + 1]);
3737 if (!anInd.IsIntegerValue())
3739 std::cout << "Error: Index value should be integer!\n";
3743 Standard_Integer anIndex = anInd.IntegerValue();
3744 if (anIndex <= 0 || anIndex > aNbIntervals)
3746 std::cout << "Error: Index value should be within range 1.." << aNbIntervals <<"!\n";
3750 if (Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3752 aCS->SetIntervalColor (Quantity_Color (aColorName), anIndex);
3753 aCS->SetColorType (Aspect_TOCSD_USER);
3758 TCollection_AsciiString aRed (theArgVec[anArgIter + 2]);
3759 TCollection_AsciiString aGreen (theArgVec[anArgIter + 3]);
3760 TCollection_AsciiString aBlue (theArgVec[anArgIter + 4]);
3761 Standard_Real aRedValue,aGreenValue, aBlueValue;
3762 if(checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3766 aCS->SetIntervalColor (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB), anIndex);
3767 aCS->SetColorType (Aspect_TOCSD_USER);
3770 else if (aFlag == "-label")
3772 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3774 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
3777 else if (anArgIter + 2 >= theArgNb)
3779 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3783 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
3784 if (anIndex <= 0 || anIndex > aNbIntervals+1)
3786 std::cout << "Error: Index value should be within range 1.." << aNbIntervals+1 <<"!\n";
3790 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
3791 aCS->SetLabel (aText, anIndex);
3792 aCS->SetLabelType (Aspect_TOCSD_USER);
3795 else if (aFlag == "-colors")
3797 Aspect_SequenceOfColor aSeq;
3798 if (anArgIter + aNbIntervals + 1 > theArgNb)
3800 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3801 << aNbIntervals << " intervals\n";
3805 Standard_Integer aColorIter = anArgIter + 1;
3806 while (aColorIter < theArgNb)
3808 if (theArgVec[aColorIter][0] == '-')
3813 else if (theArgVec[aColorIter][0] >= 97
3814 && theArgVec[aColorIter][0] <= 122)
3816 Quantity_NameOfColor aColorName;
3817 if (!Quantity_Color::ColorFromName (theArgVec[aColorIter], aColorName))
3819 std::cout << "Error: wrong color name: " << theArgVec[aColorIter] << " !\n";
3822 aSeq.Append (Quantity_Color (aColorName));
3828 TCollection_AsciiString aRed (theArgVec[aColorIter]);
3829 TCollection_AsciiString aGreen (theArgVec[aColorIter + 1]);
3830 TCollection_AsciiString aBlue (theArgVec[aColorIter + 2]);
3831 Standard_Real aRedValue,aGreenValue, aBlueValue;
3832 if (checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3836 aSeq.Append (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB));
3841 if (aSeq.Length() < aNbIntervals)
3843 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3844 << aNbIntervals << " intervals\n";
3848 aCS->SetColors (aSeq);
3849 aCS->SetColorType (Aspect_TOCSD_USER);
3851 else if (aFlag == "-labels")
3853 if (anArgIter + aNbIntervals + 1 >= theArgNb)
3855 std::cout << "Error: not enough arguments! You should provide " << (aNbIntervals + 1)
3856 << " text labels for " << aNbIntervals << " intervals.\n";
3860 TColStd_SequenceOfExtendedString aSeq;
3861 for (int aLabelIter = anArgIter + 1; aLabelIter <= anArgIter + aNbIntervals + 1; aLabelIter += 1)
3863 aSeq.Append (TCollection_ExtendedString (theArgVec[aLabelIter]));
3865 aCS->SetLabels (aSeq);
3866 aCS->SetLabelType (Aspect_TOCSD_USER);
3867 anArgIter += aSeq.Length();
3869 else if (aFlag == "-title")
3871 if (anArgIter + 1 >= theArgNb)
3873 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3877 Standard_Boolean isTwoArgs = Standard_False;
3878 if (anArgIter + 2 < theArgNb)
3880 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
3881 aSecondArg.LowerCase();
3882 if (aSecondArg == "none")
3884 aCS->SetTitlePosition (Aspect_TOCSP_NONE);
3885 isTwoArgs = Standard_True;
3887 else if (aSecondArg == "left")
3889 aCS->SetTitlePosition (Aspect_TOCSP_LEFT);
3890 isTwoArgs = Standard_True;
3892 else if (aSecondArg == "right")
3894 aCS->SetTitlePosition (Aspect_TOCSP_RIGHT);
3895 isTwoArgs = Standard_True;
3897 else if (aSecondArg == "center")
3899 aCS->SetTitlePosition (Aspect_TOCSP_CENTER);
3900 isTwoArgs = Standard_True;
3904 aCS->SetTitle (theArgVec[anArgIter + 1]);
3911 else if (aFlag == "-demoversion"
3912 || aFlag == "-demo")
3922 aLabPosition = Aspect_TOCSP_RIGHT;
3923 aCS->SetColorType (Aspect_TOCSD_AUTO);
3924 aCS->SetLabelType (Aspect_TOCSD_AUTO);
3928 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
3932 if (!aBreadth || !aHeight)
3934 Standard_Integer aWinWidth, aWinHeight;
3935 aView->Window()->Size (aWinWidth, aWinHeight);
3938 aBreadth = aWinWidth;
3942 aHeight = aWinHeight;
3945 aCS->SetSize (aBreadth, aHeight);
3946 aCS->SetPosition (aPosX, aPosY);
3947 aCS->SetTextHeight (aTextHeight);
3948 aCS->SetRange (aMinRange, aMaxRange);
3949 aCS->SetNumberOfIntervals (aNbIntervals);
3950 aCS->SetLabelPosition (aLabPosition);
3951 // aCS->SetColor (aView->BackgroundColor().Invert());
3953 aContext->Display (aCS);
3958 //==============================================================================
3959 //function : VGraduatedTrihedron
3960 //purpose : Displays or hides a graduated trihedron
3961 //==============================================================================
3962 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
3963 Quantity_Color& theColor)
3965 Quantity_NameOfColor aColorName;
3966 TCollection_AsciiString aVal = theValue;
3968 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
3970 return Standard_False;
3972 theColor = Quantity_Color (aColorName);
3973 return Standard_True;
3976 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
3980 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
3981 << theArgs[0] <<"' for more information.\n";
3982 return 1; //TCL_ERROR
3985 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
3986 TCollection_AsciiString aParseKey;
3987 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
3989 TCollection_AsciiString anArg (theArgs [anArgIt]);
3991 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3994 aParseKey.Remove (1);
3995 aParseKey.LowerCase();
3996 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
4000 if (aParseKey.IsEmpty())
4005 aMapOfArgs(aParseKey)->Append (anArg);
4009 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
4010 aMapIt.More(); aMapIt.Next())
4012 const TCollection_AsciiString& aKey = aMapIt.Key();
4013 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
4015 // Bool key, without arguments
4016 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
4017 && anArgs->IsEmpty())
4023 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
4024 && anArgs->Length() == 1)
4030 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
4031 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
4032 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
4033 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
4034 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
4039 // One string argument
4040 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
4041 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
4042 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4047 // One integer argument
4048 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
4049 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
4050 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
4051 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
4052 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
4057 // One real argument
4058 if ( aKey.IsEqual ("arrowlength")
4059 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
4064 // Two string arguments
4065 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
4066 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4071 TCollection_AsciiString aLowerKey;
4074 aLowerKey.LowerCase();
4075 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
4076 std::cout << "Type help for more information.\n";
4080 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4081 if (anAISContext.IsNull())
4083 std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n";
4087 Standard_Boolean toDisplay = Standard_True;
4088 Quantity_Color aColor;
4089 Graphic3d_GraduatedTrihedron aTrihedronData;
4090 // Process parameters
4091 Handle(TColStd_HSequenceOfAsciiString) aValues;
4092 if (aMapOfArgs.Find ("off", aValues))
4094 toDisplay = Standard_False;
4098 if (aMapOfArgs.Find ("xname", aValues))
4100 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
4102 if (aMapOfArgs.Find ("yname", aValues))
4104 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
4106 if (aMapOfArgs.Find ("zname", aValues))
4108 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
4110 if (aMapOfArgs.Find ("xdrawname", aValues))
4112 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4114 if (aMapOfArgs.Find ("ydrawname", aValues))
4116 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4118 if (aMapOfArgs.Find ("zdrawname", aValues))
4120 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4122 if (aMapOfArgs.Find ("xnameoffset", aValues))
4124 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4126 if (aMapOfArgs.Find ("ynameoffset", aValues))
4128 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4130 if (aMapOfArgs.Find ("znameoffset", aValues))
4132 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4136 if (aMapOfArgs.Find ("xnamecolor", aValues))
4138 if (!GetColor (aValues->Value(1), aColor))
4140 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
4143 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
4145 if (aMapOfArgs.Find ("ynamecolor", aValues))
4147 if (!GetColor (aValues->Value(1), aColor))
4149 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
4152 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
4154 if (aMapOfArgs.Find ("znamecolor", aValues))
4156 if (!GetColor (aValues->Value(1), aColor))
4158 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
4161 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
4163 if (aMapOfArgs.Find ("xcolor", aValues))
4165 if (!GetColor (aValues->Value(1), aColor))
4167 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
4170 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
4172 if (aMapOfArgs.Find ("ycolor", aValues))
4174 if (!GetColor (aValues->Value(1), aColor))
4176 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
4179 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
4181 if (aMapOfArgs.Find ("zcolor", aValues))
4183 if (!GetColor (aValues->Value(1), aColor))
4185 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
4188 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
4192 if (aMapOfArgs.Find ("xticks", aValues))
4194 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4196 if (aMapOfArgs.Find ("yticks", aValues))
4198 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4200 if (aMapOfArgs.Find ("zticks", aValues))
4202 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4204 if (aMapOfArgs.Find ("xticklength", aValues))
4206 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4208 if (aMapOfArgs.Find ("yticklength", aValues))
4210 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4212 if (aMapOfArgs.Find ("zticklength", aValues))
4214 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4216 if (aMapOfArgs.Find ("xdrawticks", aValues))
4218 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4220 if (aMapOfArgs.Find ("ydrawticks", aValues))
4222 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4224 if (aMapOfArgs.Find ("zdrawticks", aValues))
4226 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4230 if (aMapOfArgs.Find ("xdrawvalues", aValues))
4232 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4234 if (aMapOfArgs.Find ("ydrawvalues", aValues))
4236 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4238 if (aMapOfArgs.Find ("zdrawvalues", aValues))
4240 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4242 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
4244 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4246 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
4248 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4250 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
4252 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4256 if (aMapOfArgs.Find ("arrowlength", aValues))
4258 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
4262 if (aMapOfArgs.Find ("namefont", aValues))
4264 aTrihedronData.SetNamesFont (aValues->Value(1));
4266 if (aMapOfArgs.Find ("valuesfont", aValues))
4268 aTrihedronData.SetValuesFont (aValues->Value(1));
4271 if (aMapOfArgs.Find ("drawgrid", aValues))
4273 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
4275 if (aMapOfArgs.Find ("drawaxes", aValues))
4277 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
4280 // The final step: display of erase trihedron
4283 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
4287 ViewerTest::CurrentView()->GraduatedTrihedronErase();
4290 ViewerTest::GetAISContext()->UpdateCurrentViewer();
4291 ViewerTest::CurrentView()->Redraw();
4296 //==============================================================================
4297 //function : VPrintView
4298 //purpose : Test printing algorithm, print the view to image file with given
4299 // width and height. Printing implemented only for WNT.
4300 //==============================================================================
4301 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
4307 di << "Printing implemented only for WNT!\n";
4311 Handle(AIS_InteractiveContext) aContextAIS = NULL;
4312 Handle(V3d_View) aView = NULL;
4313 aContextAIS = ViewerTest::GetAISContext();
4314 if (!aContextAIS.IsNull())
4316 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
4317 Vwr->InitActiveViews();
4318 if(Vwr->MoreActiveViews())
4319 aView = Vwr->ActiveView();
4325 di << "Call vinit before!\n";
4330 di << "Use: " << argv[0];
4331 di << " width height filename [print algo=0] [tile_width tile_height]\n";
4332 di << "width, height of the intermediate buffer for operation\n";
4333 di << "algo : {0|1}\n";
4334 di << " 0 - stretch algorithm\n";
4335 di << " 1 - tile algorithm\n";
4336 di << "test printing algorithms into an intermediate buffer\n";
4337 di << "using specific tile size if provided\n";
4338 di << "with saving output to an image file\n";
4342 // get the input params
4343 Standard_Integer aWidth = Draw::Atoi (argv[1]);
4344 Standard_Integer aHeight = Draw::Atoi (argv[2]);
4345 Standard_Integer aMode = 0;
4346 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
4348 aMode = Draw::Atoi (argv[4]);
4350 Standard_Integer aTileWidth = 0;
4351 Standard_Integer aTileHeight = 0;
4352 Standard_Boolean isTileSizeProvided = Standard_False;
4355 isTileSizeProvided = Standard_True;
4356 aTileWidth = Draw::Atoi (argv[5]);
4357 aTileHeight = Draw::Atoi (argv[6]);
4360 // check the input parameters
4361 if (aWidth <= 0 || aHeight <= 0)
4363 di << "Width and height must be positive values!\n";
4366 if (aMode != 0 && aMode != 1)
4369 // define compatible bitmap
4370 HDC anDC = CreateCompatibleDC(0);
4371 BITMAPINFO aBitmapData;
4372 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
4373 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
4374 aBitmapData.bmiHeader.biWidth = aWidth ;
4375 aBitmapData.bmiHeader.biHeight = aHeight;
4376 aBitmapData.bmiHeader.biPlanes = 1;
4377 aBitmapData.bmiHeader.biBitCount = 24;
4378 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
4379 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
4380 aBitmapData.bmiHeader.biClrUsed = 0;
4381 aBitmapData.bmiHeader.biClrImportant = 0;
4382 aBitmapData.bmiHeader.biCompression = BI_RGB;
4383 aBitmapData.bmiHeader.biSizeImage = 0;
4385 // Create Device Independent Bitmap
4386 void* aBitsOut = NULL;
4387 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
4388 &aBitsOut, NULL, 0);
4389 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
4391 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
4392 if (aBitsOut != NULL)
4395 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
4398 if (isTileSizeProvided)
4400 Handle(Graphic3d_CView) aGraphicView = ViewerTest::CurrentView()->View();
4401 Handle(Standard_Transient) anOldBuffer = aGraphicView->FBO();
4402 Handle(Standard_Transient) aNewBuffer = aGraphicView->FBOCreate (aTileWidth, aTileHeight);
4403 aGraphicView->SetFBO (aNewBuffer);
4405 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
4407 aGraphicView->FBORelease (aNewBuffer);
4408 aGraphicView->SetFBO (anOldBuffer);
4412 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
4416 // successfully printed into an intermediate buffer
4419 Image_PixMap aWrapper;
4420 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
4421 aWrapper.SetTopDown (false);
4423 Image_AlienPixMap anImageBitmap;
4424 anImageBitmap.InitCopy (aWrapper);
4425 isSaved = anImageBitmap.Save (aFileName);
4429 di << "Print operation failed due to printing errors or\n";
4430 di << "insufficient memory available\n";
4431 di << "Please, try to use smaller dimensions for this test\n";
4432 di << "command, as it allocates intermediate buffer for storing\n";
4433 di << "the result\n";
4438 di << "Can't allocate memory for intermediate buffer\n";
4439 di << "Please use smaller dimensions\n";
4444 SelectObject (anDC, anOldBitmap);
4445 DeleteObject (aMemoryBitmap);
4451 di << "Save to file operation failed. This operation may fail\n";
4452 di << "if you don't have enough available memory, then you can\n";
4453 di << "use smaller dimensions for the output file\n";
4462 //==============================================================================
4463 //function : VZLayer
4464 //purpose : Test z layer operations for v3d viewer
4465 //==============================================================================
4466 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4468 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
4469 if (aContextAIS.IsNull())
4471 di << "Call vinit before!\n";
4476 di << "Use: vzlayer ";
4477 di << " add/del/get/settings/enable/disable [id]\n";
4478 di << " add - add new z layer to viewer and print its id\n";
4479 di << " del - del z layer by its id\n";
4480 di << " get - print sequence of z layers in increasing order of their overlay level\n";
4481 di << " settings - print status of z layer settings\n";
4482 di << " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n";
4483 di << " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n";
4484 di << " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n";
4485 di << "\nWhere id is the layer identificator\n";
4486 di << "\nExamples:\n";
4487 di << " vzlayer add\n";
4488 di << " vzlayer enable poffset 1\n";
4489 di << " vzlayer disable depthtest 1\n";
4490 di << " vzlayer del 1\n";
4494 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
4495 if (aViewer.IsNull())
4497 di << "No active viewer!\n";
4501 // perform operation
4502 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
4505 Standard_Integer aNewId;
4506 if (!aViewer->AddZLayer (aNewId))
4508 di << "Impossible to add new z layer!\n";
4512 di << "New z layer added with index: " << aNewId << "\n";
4514 else if (anOp == "del")
4518 di << "Please also provide as argument id of z layer to remove\n";
4522 Standard_Integer aDelId = Draw::Atoi (argv[2]);
4523 if (!aViewer->RemoveZLayer (aDelId))
4525 di << "Impossible to remove the z layer or invalid id!\n";
4529 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4530 anObjIter.More(); anObjIter.Next())
4532 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1());
4534 || aPrs->ZLayer() != aDelId)
4538 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4541 di << "Z layer " << aDelId << " has been removed\n";
4543 else if (anOp == "get")
4545 TColStd_SequenceOfInteger anIds;
4546 aViewer->GetAllZLayers (anIds);
4547 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
4549 di << anIds.Value (aSeqIdx) << " ";
4554 else if (anOp == "settings")
4558 di << "Please also provide an id\n";
4562 Standard_Integer anId = Draw::Atoi (argv[2]);
4563 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4565 di << "Depth test - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthTest) ? "enabled" : "disabled") << "\n";
4566 di << "Depth write - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthWrite) ? "enabled" : "disabled") << "\n";
4567 di << "Depth buffer clearing - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthClear) ? "enabled" : "disabled") << "\n";
4568 di << "Depth offset - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthOffset) ? "enabled" : "disabled") << "\n";
4571 else if (anOp == "enable")
4575 di << "Please also provide an option to enable\n";
4581 di << "Please also provide a layer id\n";
4585 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
4586 Standard_Integer anId = Draw::Atoi (argv[3]);
4587 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4589 if (aSubOp == "depthtest" || aSubOp == "test")
4591 aSettings.EnableSetting (Graphic3d_ZLayerDepthTest);
4593 else if (aSubOp == "depthwrite" || aSubOp == "write")
4595 aSettings.EnableSetting (Graphic3d_ZLayerDepthWrite);
4597 else if (aSubOp == "depthclear" || aSubOp == "clear")
4599 aSettings.EnableSetting (Graphic3d_ZLayerDepthClear);
4601 else if (aSubOp == "depthoffset" || aSubOp == "offset")
4605 di << "Please also provide a factor and units values for depth offset\n";
4606 di << "Format is: vzlayer enable offset [factor] [units] [layerId]\n";
4610 Standard_ShortReal aFactor = static_cast<Standard_ShortReal> (Draw::Atof (argv[3]));
4611 Standard_ShortReal aUnits = static_cast<Standard_ShortReal> (Draw::Atof (argv[4]));
4612 anId = Draw::Atoi (argv[5]);
4613 aSettings = aViewer->ZLayerSettings (anId);
4615 aSettings.DepthOffsetFactor = aFactor;
4616 aSettings.DepthOffsetUnits = aUnits;
4618 aSettings.EnableSetting (Graphic3d_ZLayerDepthOffset);
4620 else if (aSubOp == "positiveoffset" || aSubOp == "poffset")
4622 aSettings.SetDepthOffsetPositive();
4624 else if (aSubOp == "negativeoffset" || aSubOp == "noffset")
4626 aSettings.SetDepthOffsetNegative();
4629 aViewer->SetZLayerSettings (anId, aSettings);
4631 else if (anOp == "disable")
4635 di << "Please also provide an option to disable\n";
4641 di << "Please also provide a layer id\n";
4645 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
4646 Standard_Integer anId = Draw::Atoi (argv[3]);
4647 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4649 if (aSubOp == "depthtest" || aSubOp == "test")
4651 aSettings.DisableSetting (Graphic3d_ZLayerDepthTest);
4653 else if (aSubOp == "depthwrite" || aSubOp == "write")
4655 aSettings.DisableSetting (Graphic3d_ZLayerDepthWrite);
4657 else if (aSubOp == "depthclear" || aSubOp == "clear")
4659 aSettings.DisableSetting (Graphic3d_ZLayerDepthClear);
4661 else if (aSubOp == "depthoffset" || aSubOp == "offset")
4663 aSettings.DisableSetting (Graphic3d_ZLayerDepthOffset);
4666 aViewer->SetZLayerSettings (anId, aSettings);
4670 di << "Invalid operation, please use { add / del / get / settings / enable / disable}\n";
4677 // The interactive presentation of 2d layer item
4678 // for "vlayerline" command it provides a presentation of
4679 // line with user-defined linewidth, linetype and transparency.
4680 class V3d_LineItem : public AIS_InteractiveObject
4684 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
4687 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4688 Standard_Real X2, Standard_Real Y2,
4689 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
4690 Standard_Real theWidth = 0.5,
4691 Standard_Real theTransp = 1.0);
4695 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4696 const Handle(Prs3d_Presentation)& thePresentation,
4697 const Standard_Integer theMode) Standard_OVERRIDE;
4699 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
4700 const Standard_Integer /*aMode*/) Standard_OVERRIDE
4705 Standard_Real myX1, myY1, myX2, myY2;
4706 Aspect_TypeOfLine myType;
4707 Standard_Real myWidth;
4710 // default constructor for line item
4711 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4712 Standard_Real X2, Standard_Real Y2,
4713 Aspect_TypeOfLine theType,
4714 Standard_Real theWidth,
4715 Standard_Real theTransp) :
4716 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
4717 myType(theType), myWidth(theWidth)
4719 SetTransparency (1-theTransp);
4723 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
4724 const Handle(Prs3d_Presentation)& thePresentation,
4725 const Standard_Integer /*theMode*/)
4727 thePresentation->Clear();
4728 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
4729 Standard_Integer aWidth, aHeight;
4730 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
4731 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
4732 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
4733 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
4734 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
4735 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
4736 aGroup->SetPrimitivesAspect (anAspect->Aspect());
4737 aGroup->AddPrimitiveArray (aPrim);
4740 //=============================================================================
4741 //function : VLayerLine
4742 //purpose : Draws line in the v3d view layer with given attributes: linetype,
4743 // : linewidth, transparency coefficient
4744 //============================================================================
4745 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4747 // get the active view
4748 Handle(V3d_View) aView = ViewerTest::CurrentView();
4751 di << "Call vinit before!\n";
4756 di << "Use: " << argv[0];
4757 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
4758 di << " linetype : { 0 | 1 | 2 | 3 } \n";
4759 di << " 0 - solid \n";
4760 di << " 1 - dashed \n";
4761 di << " 2 - dot \n";
4762 di << " 3 - dashdot\n";
4763 di << " transparency : { 0.0 - 1.0 } \n";
4764 di << " 0.0 - transparent\n";
4765 di << " 1.0 - visible \n";
4769 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4770 // get the input params
4771 Standard_Real X1 = Draw::Atof(argv[1]);
4772 Standard_Real Y1 = Draw::Atof(argv[2]);
4773 Standard_Real X2 = Draw::Atof(argv[3]);
4774 Standard_Real Y2 = Draw::Atof(argv[4]);
4776 Standard_Real aWidth = 0.5;
4777 Standard_Integer aType = 0;
4778 Standard_Real aTransparency = 1.0;
4782 aWidth = Draw::Atof(argv[5]);
4786 aType = (Standard_Integer) Draw::Atoi(argv[6]);
4791 aTransparency = Draw::Atof(argv[7]);
4792 if (aTransparency < 0 || aTransparency > 1.0)
4793 aTransparency = 1.0;
4796 // select appropriate line type
4797 Aspect_TypeOfLine aLineType;
4801 aLineType = Aspect_TOL_DASH;
4805 aLineType = Aspect_TOL_DOT;
4809 aLineType = Aspect_TOL_DOTDASH;
4813 aLineType = Aspect_TOL_SOLID;
4816 static Handle (V3d_LineItem) aLine;
4817 if (!aLine.IsNull())
4819 aContext->Erase (aLine);
4821 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
4825 aLine->SetTransformPersistence (Graphic3d_TMF_2d,gp_Pnt(-1,-1,0));
4826 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
4827 aLine->SetToUpdate();
4828 aContext->Display (aLine, Standard_True);
4834 //==============================================================================
4837 //==============================================================================
4839 static int VGrid (Draw_Interpretor& /*theDI*/,
4840 Standard_Integer theArgNb,
4841 const char** theArgVec)
4843 // get the active view
4844 Handle(V3d_View) aView = ViewerTest::CurrentView();
4845 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4846 if (aView.IsNull() || aViewer.IsNull())
4848 std::cerr << "No active view. Please call vinit.\n";
4852 Aspect_GridType aType = aViewer->GridType();
4853 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
4855 Standard_Integer anIter = 1;
4856 for (; anIter < theArgNb; ++anIter)
4858 const char* aValue = theArgVec[anIter];
4861 aType = Aspect_GT_Rectangular;
4863 else if (*aValue == 'c')
4865 aType = Aspect_GT_Circular;
4867 else if (*aValue == 'l')
4869 aMode = Aspect_GDM_Lines;
4871 else if (*aValue == 'p')
4873 aMode = Aspect_GDM_Points;
4875 else if (strcmp (aValue, "off" ) == 0)
4877 aViewer->DeactivateGrid();
4886 Standard_Integer aTail = (theArgNb - anIter);
4889 aViewer->ActivateGrid (aType, aMode);
4892 else if (aTail != 2 && aTail != 5)
4894 std::cerr << "Incorrect arguments number! Usage:\n"
4895 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
4899 Quantity_Length anOriginX, anOriginY;
4900 Quantity_PlaneAngle aRotAngle;
4901 if (aType == Aspect_GT_Rectangular)
4903 Quantity_Length aRStepX, aRStepY;
4904 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4906 anOriginX = Draw::Atof (theArgVec[anIter++]);
4907 anOriginY = Draw::Atof (theArgVec[anIter++]);
4910 aRStepX = Draw::Atof (theArgVec[anIter++]);
4911 aRStepY = Draw::Atof (theArgVec[anIter++]);
4912 aRotAngle = Draw::Atof (theArgVec[anIter++]);
4914 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4915 aViewer->ActivateGrid (aType, aMode);
4917 else if (aType == Aspect_GT_Circular)
4919 Quantity_Length aRadiusStep;
4920 Standard_Integer aDivisionNumber;
4921 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
4923 anOriginX = Draw::Atof (theArgVec[anIter++]);
4924 anOriginY = Draw::Atof (theArgVec[anIter++]);
4927 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
4928 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
4929 aRotAngle = Draw::Atof (theArgVec[anIter++]);
4932 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
4933 aViewer->ActivateGrid (aType, aMode);
4939 //==============================================================================
4940 //function : VPriviledgedPlane
4942 //==============================================================================
4944 static int VPriviledgedPlane (Draw_Interpretor& theDI,
4945 Standard_Integer theArgNb,
4946 const char** theArgVec)
4948 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
4950 std::cerr << "Error: wrong number of arguments! See usage:\n";
4951 theDI.PrintHelp (theArgVec[0]);
4955 // get the active viewer
4956 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4957 if (aViewer.IsNull())
4959 std::cerr << "Error: no active viewer. Please call vinit.\n";
4965 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
4966 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
4967 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
4968 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
4969 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
4970 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
4971 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
4975 Standard_Integer anArgIdx = 1;
4976 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
4977 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
4978 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
4979 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
4980 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
4981 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
4983 gp_Ax3 aPriviledgedPlane;
4984 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
4985 gp_Dir aNorm (aNormX, aNormY, aNormZ);
4988 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
4989 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
4990 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
4991 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
4992 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
4996 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
4999 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
5004 //==============================================================================
5005 //function : VConvert
5007 //==============================================================================
5009 static int VConvert (Draw_Interpretor& theDI,
5010 Standard_Integer theArgNb,
5011 const char** theArgVec)
5013 // get the active view
5014 Handle(V3d_View) aView = ViewerTest::CurrentView();
5017 std::cerr << "Error: no active view. Please call vinit.\n";
5021 enum { Model, Ray, View, Window, Grid } aMode = Model;
5023 // access coordinate arguments
5024 TColStd_SequenceOfReal aCoord;
5025 Standard_Integer anArgIdx = 1;
5026 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
5028 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5029 if (!anArg.IsRealValue())
5033 aCoord.Append (anArg.RealValue());
5036 // non-numeric argument too early
5037 if (aCoord.IsEmpty())
5039 std::cerr << "Error: wrong number of arguments! See usage:\n";
5040 theDI.PrintHelp (theArgVec[0]);
5044 // collect all other arguments and options
5045 for (; anArgIdx < theArgNb; ++anArgIdx)
5047 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5049 if (anArg == "window") aMode = Window;
5050 else if (anArg == "view") aMode = View;
5051 else if (anArg == "grid") aMode = Grid;
5052 else if (anArg == "ray") aMode = Ray;
5055 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
5056 theDI.PrintHelp (theArgVec[0]);
5061 // complete input checks
5062 if ((aCoord.Length() == 1 && theArgNb > 3) ||
5063 (aCoord.Length() == 2 && theArgNb > 4) ||
5064 (aCoord.Length() == 3 && theArgNb > 5))
5066 std::cerr << "Error: wrong number of arguments! See usage:\n";
5067 theDI.PrintHelp (theArgVec[0]);
5071 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
5072 Standard_Integer aXYp[2] = {0, 0};
5074 // convert one-dimensional coordinate
5075 if (aCoord.Length() == 1)
5079 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer) aCoord (1)); return 0;
5080 case Window : theDI << "Window Vp: " << aView->Convert ((Quantity_Length) aCoord (1)); return 0;
5082 std::cerr << "Error: wrong arguments! See usage:\n";
5083 theDI.PrintHelp (theArgVec[0]);
5088 // convert 2D coordinates from projection or view reference space
5089 if (aCoord.Length() == 2)
5094 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5095 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5099 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5100 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5104 aView->Convert ((V3d_Coordinate) aCoord (1), (V3d_Coordinate) aCoord (2), aXYp[0], aXYp[1]);
5105 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5109 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5110 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5111 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5115 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5116 (Standard_Integer) aCoord (2),
5117 aXYZ[0], aXYZ[1], aXYZ[2],
5118 aXYZ[3], aXYZ[4], aXYZ[5]);
5119 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5123 std::cerr << "Error: wrong arguments! See usage:\n";
5124 theDI.PrintHelp (theArgVec[0]);
5129 // convert 3D coordinates from view reference space
5130 else if (aCoord.Length() == 3)
5135 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5136 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5140 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5141 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5145 std::cerr << "Error: wrong arguments! See usage:\n";
5146 theDI.PrintHelp (theArgVec[0]);
5154 //==============================================================================
5157 //==============================================================================
5159 static int VFps (Draw_Interpretor& theDI,
5160 Standard_Integer theArgNb,
5161 const char** theArgVec)
5163 // get the active view
5164 Handle(V3d_View) aView = ViewerTest::CurrentView();
5167 std::cerr << "No active view. Please call vinit.\n";
5171 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
5174 std::cerr << "Incorrect arguments!\n";
5178 // the time is meaningless for first call
5179 // due to async OpenGl rendering
5182 // redraw view in loop to estimate average values
5185 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
5191 const Standard_Real aTime = aTimer.ElapsedTime();
5192 aTimer.OSD_Chronometer::Show (aCpu);
5194 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
5195 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
5197 // return statistics
5198 theDI << "FPS: " << aFpsAver << "\n"
5199 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5201 // compute additional statistics in ray-tracing mode
5202 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
5204 if (aParams.Method == Graphic3d_RM_RAYTRACING)
5206 Standard_Integer aSizeX;
5207 Standard_Integer aSizeY;
5209 aView->Window()->Size (aSizeX, aSizeY);
5211 // 1 shadow ray and 1 secondary ray pew each bounce
5212 const Standard_Real aMRays = aSizeX * aSizeY * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
5214 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
5220 //==============================================================================
5221 //function : VGlDebug
5223 //==============================================================================
5225 static int VGlDebug (Draw_Interpretor& theDI,
5226 Standard_Integer theArgNb,
5227 const char** theArgVec)
5229 Handle(OpenGl_GraphicDriver) aDriver;
5230 Handle(V3d_View) aView = ViewerTest::CurrentView();
5231 if (!aView.IsNull())
5233 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5235 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
5236 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
5240 TCollection_AsciiString aDebActive, aSyncActive;
5247 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
5248 "GL_ARB_debug_output");
5249 aDebActive = isActive ? " (active)" : " (inactive)";
5252 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
5253 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
5257 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
5258 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
5259 << "glslWarn:" << (aCaps->glslWarnings ? "1" : "0") << "\n"
5260 << "extraMsg:" << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
5264 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5266 Standard_CString anArg = theArgVec[anArgIter];
5267 TCollection_AsciiString anArgCase (anArg);
5268 anArgCase.LowerCase();
5269 Standard_Boolean toEnableDebug = Standard_True;
5270 if (anArgCase == "-glsl"
5271 || anArgCase == "-glslwarn"
5272 || anArgCase == "-glslwarns"
5273 || anArgCase == "-glslwarnings")
5275 Standard_Boolean toShowWarns = Standard_True;
5276 if (++anArgIter < theArgNb
5277 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
5281 aDefCaps->glslWarnings = toShowWarns;
5284 aCaps->glslWarnings = toShowWarns;
5287 else if (anArgCase == "-extra"
5288 || anArgCase == "-extramsg"
5289 || anArgCase == "-extramessages")
5291 Standard_Boolean toShow = Standard_True;
5292 if (++anArgIter < theArgNb
5293 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
5297 aDefCaps->suppressExtraMsg = !toShow;
5300 aCaps->suppressExtraMsg = !toShow;
5303 else if (anArgCase == "-noextra"
5304 || anArgCase == "-noextramsg"
5305 || anArgCase == "-noextramessages")
5307 Standard_Boolean toSuppress = Standard_True;
5308 if (++anArgIter < theArgNb
5309 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
5313 aDefCaps->suppressExtraMsg = toSuppress;
5316 aCaps->suppressExtraMsg = toSuppress;
5319 else if (anArgCase == "-sync")
5321 Standard_Boolean toSync = Standard_True;
5322 if (++anArgIter < theArgNb
5323 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
5327 aDefCaps->contextSyncDebug = toSync;
5330 aDefCaps->contextDebug = Standard_True;
5333 else if (anArgCase == "-debug")
5335 if (++anArgIter < theArgNb
5336 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
5340 aDefCaps->contextDebug = toEnableDebug;
5342 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
5343 && (anArgIter + 1 == theArgNb))
5345 // simple alias to turn on almost everything
5346 aDefCaps->contextDebug = toEnableDebug;
5347 aDefCaps->contextSyncDebug = toEnableDebug;
5348 aDefCaps->glslWarnings = toEnableDebug;
5352 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
5360 //==============================================================================
5363 //==============================================================================
5365 static int VVbo (Draw_Interpretor& theDI,
5366 Standard_Integer theArgNb,
5367 const char** theArgVec)
5369 const Standard_Boolean toSet = (theArgNb > 1);
5370 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
5373 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
5377 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5378 if (aContextAIS.IsNull())
5382 std::cerr << "No active view!\n";
5386 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5387 if (!aDriver.IsNull())
5391 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
5395 aDriver->ChangeOptions().vboDisable = toUseVbo;
5402 //==============================================================================
5405 //==============================================================================
5407 static int VCaps (Draw_Interpretor& theDI,
5408 Standard_Integer theArgNb,
5409 const char** theArgVec)
5411 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
5412 Handle(OpenGl_GraphicDriver) aDriver;
5413 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5414 if (!aContext.IsNull())
5416 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
5417 aCaps = &aDriver->ChangeOptions();
5422 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
5423 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
5424 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
5425 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
5426 theDI << "VSync: " << aCaps->swapInterval << "\n";
5427 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
5428 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
5432 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5433 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5435 Standard_CString anArg = theArgVec[anArgIter];
5436 TCollection_AsciiString anArgCase (anArg);
5437 anArgCase.LowerCase();
5438 if (anUpdateTool.parseRedrawMode (anArg))
5442 else if (anArgCase == "-vsync"
5443 || anArgCase == "-swapinterval")
5445 Standard_Boolean toEnable = Standard_True;
5446 if (++anArgIter < theArgNb
5447 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5451 aCaps->swapInterval = toEnable;
5453 else if (anArgCase == "-ffp")
5455 Standard_Boolean toEnable = Standard_True;
5456 if (++anArgIter < theArgNb
5457 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5461 aCaps->ffpEnable = toEnable;
5463 else if (anArgCase == "-vbo")
5465 Standard_Boolean toEnable = Standard_True;
5466 if (++anArgIter < theArgNb
5467 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5471 aCaps->vboDisable = !toEnable;
5473 else if (anArgCase == "-sprite"
5474 || anArgCase == "-sprites")
5476 Standard_Boolean toEnable = Standard_True;
5477 if (++anArgIter < theArgNb
5478 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5482 aCaps->pntSpritesDisable = !toEnable;
5484 else if (anArgCase == "-softmode")
5486 Standard_Boolean toEnable = Standard_True;
5487 if (++anArgIter < theArgNb
5488 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5492 aCaps->contextNoAccel = toEnable;
5494 else if (anArgCase == "-accel"
5495 || anArgCase == "-acceleration")
5497 Standard_Boolean toEnable = Standard_True;
5498 if (++anArgIter < theArgNb
5499 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5503 aCaps->contextNoAccel = !toEnable;
5505 else if (anArgCase == "-compat"
5506 || anArgCase == "-compatprofile"
5507 || anArgCase == "-compatible"
5508 || anArgCase == "-compatibleprofile")
5510 Standard_Boolean toEnable = Standard_True;
5511 if (++anArgIter < theArgNb
5512 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5516 aCaps->contextCompatible = toEnable;
5517 if (!aCaps->contextCompatible)
5519 aCaps->ffpEnable = Standard_False;
5522 else if (anArgCase == "-core"
5523 || anArgCase == "-coreprofile")
5525 Standard_Boolean toEnable = Standard_True;
5526 if (++anArgIter < theArgNb
5527 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5531 aCaps->contextCompatible = !toEnable;
5532 if (!aCaps->contextCompatible)
5534 aCaps->ffpEnable = Standard_False;
5537 else if (anArgCase == "-stereo"
5538 || anArgCase == "-quadbuffer")
5540 Standard_Boolean toEnable = Standard_True;
5541 if (++anArgIter < theArgNb
5542 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5546 aCaps->contextStereo = toEnable;
5550 std::cout << "Error: unknown argument '" << anArg << "'\n";
5554 if (aCaps != &ViewerTest_myDefaultCaps)
5556 ViewerTest_myDefaultCaps = *aCaps;
5561 //==============================================================================
5562 //function : VMemGpu
5564 //==============================================================================
5566 static int VMemGpu (Draw_Interpretor& theDI,
5567 Standard_Integer theArgNb,
5568 const char** theArgVec)
5571 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5572 if (aContextAIS.IsNull())
5574 std::cerr << "No active view. Please call vinit.\n";
5578 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
5579 if (aDriver.IsNull())
5581 std::cerr << "Graphic driver not available.\n";
5585 Standard_Size aFreeBytes = 0;
5586 TCollection_AsciiString anInfo;
5587 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
5589 std::cerr << "Information not available.\n";
5593 if (theArgNb > 1 && *theArgVec[1] == 'f')
5595 theDI << Standard_Real (aFreeBytes);
5605 // ==============================================================================
5606 // function : VReadPixel
5608 // ==============================================================================
5609 static int VReadPixel (Draw_Interpretor& theDI,
5610 Standard_Integer theArgNb,
5611 const char** theArgVec)
5613 // get the active view
5614 Handle(V3d_View) aView = ViewerTest::CurrentView();
5617 std::cerr << "No active view. Please call vinit.\n";
5620 else if (theArgNb < 3)
5622 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
5626 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
5627 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
5629 Standard_Integer aWidth, aHeight;
5630 aView->Window()->Size (aWidth, aHeight);
5631 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
5632 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
5633 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
5635 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
5639 Standard_Boolean toShowName = Standard_False;
5640 Standard_Boolean toShowHls = Standard_False;
5641 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
5643 const char* aParam = theArgVec[anIter];
5644 if ( strcasecmp( aParam, "rgb" ) == 0 )
5646 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
5647 aBufferType = Graphic3d_BT_RGB;
5649 else if ( strcasecmp( aParam, "hls" ) == 0 )
5651 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
5652 aBufferType = Graphic3d_BT_RGB;
5653 toShowHls = Standard_True;
5655 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
5657 aFormat = Image_PixMap::ImgRGBF;
5658 aBufferType = Graphic3d_BT_RGB;
5660 else if ( strcasecmp( aParam, "rgba" ) == 0 )
5662 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
5663 aBufferType = Graphic3d_BT_RGBA;
5665 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
5667 aFormat = Image_PixMap::ImgRGBAF;
5668 aBufferType = Graphic3d_BT_RGBA;
5670 else if ( strcasecmp( aParam, "depth" ) == 0 )
5672 aFormat = Image_PixMap::ImgGrayF;
5673 aBufferType = Graphic3d_BT_Depth;
5675 else if ( strcasecmp( aParam, "name" ) == 0 )
5677 toShowName = Standard_True;
5681 Image_PixMap anImage;
5682 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
5684 std::cerr << "Image allocation failed\n";
5687 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
5689 std::cerr << "Image dump failed\n";
5693 Quantity_Parameter anAlpha;
5694 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
5697 if (aBufferType == Graphic3d_BT_RGBA)
5699 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha;
5703 theDI << Quantity_Color::StringName (aColor.Name());
5708 switch (aBufferType)
5711 case Graphic3d_BT_RGB:
5715 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation();
5719 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue();
5723 case Graphic3d_BT_RGBA:
5725 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha;
5728 case Graphic3d_BT_Depth:
5730 theDI << aColor.Red();
5739 //==============================================================================
5740 //function : VDiffImage
5741 //purpose : The draw-command compares two images.
5742 //==============================================================================
5744 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
5748 theDI << "Not enough arguments.\n";
5753 const char* anImgPathRef = theArgVec[1];
5754 const char* anImgPathNew = theArgVec[2];
5756 // get string tolerance and check its validity
5757 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
5758 if (aTolColor < 0.0)
5760 if (aTolColor > 1.0)
5763 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
5764 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
5766 // image file of difference
5767 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
5769 // compare the images
5770 Image_Diff aComparer;
5771 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
5776 aComparer.SetColorTolerance (aTolColor);
5777 aComparer.SetBorderFilterOn (isBorderFilterOn);
5778 Standard_Integer aDiffColorsNb = aComparer.Compare();
5779 theDI << aDiffColorsNb << "\n";
5781 // save image of difference
5782 if (aDiffColorsNb >0 && aDiffImagePath != NULL)
5784 aComparer.SaveDiffImage (aDiffImagePath);
5790 //=======================================================================
5791 //function : VSelect
5792 //purpose : Emulates different types of selection by mouse:
5793 // 1) single click selection
5794 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
5795 // 3) selection with polygon having corners at
5796 // pixel positions (x1,y1),...,(xn,yn)
5797 // 4) any of these selections with shift button pressed
5798 //=======================================================================
5799 static Standard_Integer VSelect (Draw_Interpretor& di,
5800 Standard_Integer argc,
5805 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]\n";
5809 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
5810 if(myAIScontext.IsNull())
5812 di << "use 'vinit' command before " << argv[0] << "\n";
5816 const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1));
5817 Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1;
5818 TCollection_AsciiString anArg;
5819 anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2];
5821 if (anArg == "-allowoverlap")
5823 Standard_Boolean isValidated = isShiftSelection ? argc == 8
5827 di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection";
5831 Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
5832 myAIScontext->MainSelector()->AllowOverlapDetection((Standard_Boolean)isToAllow);
5836 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
5837 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
5840 if(isShiftSelection)
5841 aCurrentEventManager->ShiftSelect();
5843 aCurrentEventManager->Select();
5845 else if(aCoordsNb == 4)
5847 if(isShiftSelection)
5848 aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
5850 aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
5854 TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2);
5856 for(Standard_Integer i=1;i<=aCoordsNb / 2;++i)
5857 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
5859 if(isShiftSelection)
5860 aCurrentEventManager->ShiftSelect(aPolyline);
5862 aCurrentEventManager->Select(aPolyline);
5867 //=======================================================================
5868 //function : VMoveTo
5869 //purpose : Emulates cursor movement to defined pixel position
5870 //=======================================================================
5871 static Standard_Integer VMoveTo (Draw_Interpretor& di,
5872 Standard_Integer argc,
5877 di << "Usage : " << argv[0] << " x y\n";
5881 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5882 if(aContext.IsNull())
5884 di << "use 'vinit' command before " << argv[0] << "\n";
5887 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
5891 //=================================================================================================
5892 //function : VViewParams
5893 //purpose : Gets or sets AIS View characteristics
5894 //=================================================================================================
5895 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5897 Handle(V3d_View) anAISView = ViewerTest::CurrentView();
5898 if (anAISView.IsNull())
5900 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
5906 // print all of the available view parameters
5907 Quantity_Factor anAISViewScale = anAISView->Scale();
5909 Standard_Real anAISViewProjX = 0.0;
5910 Standard_Real anAISViewProjY = 0.0;
5911 Standard_Real anAISViewProjZ = 0.0;
5912 anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
5914 Standard_Real anAISViewUpX = 0.0;
5915 Standard_Real anAISViewUpY = 0.0;
5916 Standard_Real anAISViewUpZ = 0.0;
5917 anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
5919 Standard_Real anAISViewAtX = 0.0;
5920 Standard_Real anAISViewAtY = 0.0;
5921 Standard_Real anAISViewAtZ = 0.0;
5922 anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
5924 Standard_Real anAISViewEyeX = 0.0;
5925 Standard_Real anAISViewEyeY = 0.0;
5926 Standard_Real anAISViewEyeZ = 0.0;
5927 anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ);
5929 theDi << "Scale of current view: " << anAISViewScale << "\n";
5930 theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
5931 theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
5932 theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
5933 theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n";
5937 // -------------------------
5938 // Parse options and values
5939 // -------------------------
5941 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues;
5942 TCollection_AsciiString aParseKey;
5943 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5945 TCollection_AsciiString anArg (theArgVec [anArgIt]);
5947 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
5950 aParseKey.Remove (1);
5951 aParseKey.UpperCase();
5952 aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
5956 if (aParseKey.IsEmpty())
5958 std::cout << theArgVec[0] << ": values should be passed with key.\n";
5959 std::cout << "Type help for more information.\n";
5963 aMapOfKeysByValues(aParseKey)->Append (anArg);
5966 // ---------------------------------------------
5967 // Change or print parameters, order plays role
5968 // ---------------------------------------------
5970 // Check arguments for validity
5971 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues);
5972 for (; aMapIt.More(); aMapIt.Next())
5974 const TCollection_AsciiString& aKey = aMapIt.Key();
5975 const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value();
5977 if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5978 && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5979 && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty()))
5980 && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty()))
5981 && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty()))
5982 && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty()))
5983 && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2))
5985 TCollection_AsciiString aLowerKey;
5988 aLowerKey.LowerCase();
5989 std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n";
5990 std::cout << "Type help for more information.\n";
5995 Handle(TColStd_HSequenceOfAsciiString) aValues;
5997 // Change view parameters in proper order
5998 if (aMapOfKeysByValues.Find ("SCALE", aValues))
6000 if (aValues->IsEmpty())
6002 theDi << "Scale: " << anAISView->Scale() << "\n";
6006 anAISView->SetScale (aValues->Value(1).RealValue());
6009 if (aMapOfKeysByValues.Find ("SIZE", aValues))
6011 if (aValues->IsEmpty())
6013 Standard_Real aSizeX = 0.0;
6014 Standard_Real aSizeY = 0.0;
6015 anAISView->Size (aSizeX, aSizeY);
6016 theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n";
6020 anAISView->SetSize (aValues->Value(1).RealValue());
6023 if (aMapOfKeysByValues.Find ("EYE", aValues))
6025 if (aValues->IsEmpty())
6027 Standard_Real anEyeX = 0.0;
6028 Standard_Real anEyeY = 0.0;
6029 Standard_Real anEyeZ = 0.0;
6030 anAISView->Eye (anEyeX, anEyeY, anEyeZ);
6031 theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n";
6035 anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6038 if (aMapOfKeysByValues.Find ("AT", aValues))
6040 if (aValues->IsEmpty())
6042 Standard_Real anAtX = 0.0;
6043 Standard_Real anAtY = 0.0;
6044 Standard_Real anAtZ = 0.0;
6045 anAISView->At (anAtX, anAtY, anAtZ);
6046 theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n";
6050 anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6053 if (aMapOfKeysByValues.Find ("PROJ", aValues))
6055 if (aValues->IsEmpty())
6057 Standard_Real aProjX = 0.0;
6058 Standard_Real aProjY = 0.0;
6059 Standard_Real aProjZ = 0.0;
6060 anAISView->Proj (aProjX, aProjY, aProjZ);
6061 theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n";
6065 anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6068 if (aMapOfKeysByValues.Find ("UP", aValues))
6070 if (aValues->IsEmpty())
6072 Standard_Real anUpX = 0.0;
6073 Standard_Real anUpY = 0.0;
6074 Standard_Real anUpZ = 0.0;
6075 anAISView->Up (anUpX, anUpY, anUpZ);
6076 theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n";
6080 anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6083 if (aMapOfKeysByValues.Find ("CENTER", aValues))
6085 anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue());
6091 //=======================================================================
6092 //function : VChangeSelected
6093 //purpose : Adds the shape to selection or remove one from it
6094 //=======================================================================
6095 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
6096 Standard_Integer argc,
6101 di<<"Usage : " << argv[0] << " shape \n";
6105 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6106 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
6107 TCollection_AsciiString aName(argv[1]);
6108 Handle(AIS_InteractiveObject) anAISObject;
6110 if(!aMap.IsBound2(aName))
6112 di<<"Use 'vdisplay' before";
6117 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
6118 if(anAISObject.IsNull()){
6119 di<<"No interactive object \n";
6123 aContext->AddOrRemoveSelected(anAISObject);
6128 //=======================================================================
6129 //function : VZClipping
6130 //purpose : Gets or sets ZClipping mode, width and depth
6131 //=======================================================================
6132 static Standard_Integer VZClipping (Draw_Interpretor& di,
6133 Standard_Integer argc,
6138 di << "Usage : " << argv[0] << " [mode] [depth width]\n"
6139 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n";
6142 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6143 if(aContext.IsNull())
6145 di << "use 'vinit' command before " << argv[0] << "\n";
6148 Handle(V3d_View) aView = ViewerTest::CurrentView();
6149 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
6152 TCollection_AsciiString aZClippingModeString;
6153 Quantity_Length aDepth, aWidth;
6154 aZClippingMode = aView->ZClipping(aDepth, aWidth);
6155 switch (aZClippingMode)
6158 aZClippingModeString.Copy("OFF");
6161 aZClippingModeString.Copy("BACK");
6164 aZClippingModeString.Copy("FRONT");
6167 aZClippingModeString.Copy("SLICE");
6170 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
6173 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
6174 << "ZClipping depth = " << aDepth << "\n"
6175 << "ZClipping width = " << aWidth << "\n";
6181 Standard_Integer aStatus = 0;
6182 if ( strcmp (argv [1], "OFF") == 0 ) {
6184 aZClippingMode = V3d_OFF;
6186 if ( strcmp (argv [1], "BACK") == 0 ) {
6188 aZClippingMode = V3d_BACK;
6190 if ( strcmp (argv [1], "FRONT") == 0 ) {
6192 aZClippingMode = V3d_FRONT;
6194 if ( strcmp (argv [1], "SLICE") == 0 ) {
6196 aZClippingMode = V3d_SLICE;
6200 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]\n"
6201 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n";
6204 aView->SetZClippingType(aZClippingMode);
6208 Quantity_Length aDepth = 0., aWidth = 1.;
6211 aDepth = Draw::Atof (argv[1]);
6212 aWidth = Draw::Atof (argv[2]);
6216 aDepth = Draw::Atof (argv[2]);
6217 aWidth = Draw::Atof (argv[3]);
6220 if(aDepth<0. || aDepth>1.)
6222 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]\n"
6223 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n";
6226 if(aWidth<0. || aWidth>1.)
6228 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]\n"
6229 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n";
6233 aView->SetZClippingDepth(aDepth);
6234 aView->SetZClippingWidth(aWidth);
6241 //=======================================================================
6242 //function : VNbSelected
6243 //purpose : Returns number of selected objects
6244 //=======================================================================
6245 static Standard_Integer VNbSelected (Draw_Interpretor& di,
6246 Standard_Integer argc,
6251 di << "Usage : " << argv[0] << "\n";
6254 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6255 if(aContext.IsNull())
6257 di << "use 'vinit' command before " << argv[0] << "\n";
6260 di << aContext->NbSelected() << "\n";
6264 //=======================================================================
6265 //function : VAntialiasing
6266 //purpose : Switches altialiasing on or off
6267 //=======================================================================
6268 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
6269 Standard_Integer argc,
6274 di << "Usage : " << argv[0] << " [1|0]\n";
6278 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6279 if(aContext.IsNull())
6281 di << "use 'vinit' command before " << argv[0] << "\n";
6285 Handle(V3d_View) aView = ViewerTest::CurrentView();
6287 if((argc == 2) && (atof(argv[1]) == 0))
6288 aView->SetAntialiasingOff();
6290 aView->SetAntialiasingOn();
6295 //=======================================================================
6296 //function : VPurgeDisplay
6297 //purpose : Switches altialiasing on or off
6298 //=======================================================================
6299 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
6300 Standard_Integer argc,
6305 di << "Usage : " << argv[0] << "\n";
6308 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6309 if (aContext.IsNull())
6311 di << "use 'vinit' command before " << argv[0] << "\n";
6314 aContext->CloseAllContexts(Standard_False);
6315 di << aContext->PurgeDisplay() << "\n";
6319 //=======================================================================
6320 //function : VSetViewSize
6322 //=======================================================================
6323 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
6324 Standard_Integer argc,
6327 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6328 if(aContext.IsNull())
6330 di << "use 'vinit' command before " << argv[0] << "\n";
6335 di<<"Usage : " << argv[0] << " Size\n";
6338 Standard_Real aSize = Draw::Atof (argv[1]);
6341 di<<"Bad Size value : " << aSize << "\n";
6345 Handle(V3d_View) aView = ViewerTest::CurrentView();
6346 aView->SetSize(aSize);
6350 //=======================================================================
6351 //function : VMoveView
6353 //=======================================================================
6354 static Standard_Integer VMoveView (Draw_Interpretor& di,
6355 Standard_Integer argc,
6358 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6359 if(aContext.IsNull())
6361 di << "use 'vinit' command before " << argv[0] << "\n";
6364 if(argc < 4 || argc > 5)
6366 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
6369 Standard_Real Dx = Draw::Atof (argv[1]);
6370 Standard_Real Dy = Draw::Atof (argv[2]);
6371 Standard_Real Dz = Draw::Atof (argv[3]);
6372 Standard_Boolean aStart = Standard_True;
6375 aStart = (Draw::Atoi (argv[4]) > 0);
6378 Handle(V3d_View) aView = ViewerTest::CurrentView();
6379 aView->Move(Dx,Dy,Dz,aStart);
6383 //=======================================================================
6384 //function : VTranslateView
6386 //=======================================================================
6387 static Standard_Integer VTranslateView (Draw_Interpretor& di,
6388 Standard_Integer argc,
6391 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6392 if(aContext.IsNull())
6394 di << "use 'vinit' command before " << argv[0] << "\n";
6397 if(argc < 4 || argc > 5)
6399 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
6402 Standard_Real Dx = Draw::Atof (argv[1]);
6403 Standard_Real Dy = Draw::Atof (argv[2]);
6404 Standard_Real Dz = Draw::Atof (argv[3]);
6405 Standard_Boolean aStart = Standard_True;
6408 aStart = (Draw::Atoi (argv[4]) > 0);
6411 Handle(V3d_View) aView = ViewerTest::CurrentView();
6412 aView->Translate(Dx,Dy,Dz,aStart);
6416 //=======================================================================
6417 //function : VTurnView
6419 //=======================================================================
6420 static Standard_Integer VTurnView (Draw_Interpretor& di,
6421 Standard_Integer argc,
6424 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6425 if(aContext.IsNull()) {
6426 di << "use 'vinit' command before " << argv[0] << "\n";
6429 if(argc < 4 || argc > 5){
6430 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
6433 Standard_Real Ax = Draw::Atof (argv[1]);
6434 Standard_Real Ay = Draw::Atof (argv[2]);
6435 Standard_Real Az = Draw::Atof (argv[3]);
6436 Standard_Boolean aStart = Standard_True;
6439 aStart = (Draw::Atoi (argv[4]) > 0);
6442 Handle(V3d_View) aView = ViewerTest::CurrentView();
6443 aView->Turn(Ax,Ay,Az,aStart);
6447 //==============================================================================
6448 //function : VTextureEnv
6449 //purpose : ENables or disables environment mapping
6450 //==============================================================================
6451 class OCC_TextureEnv : public Graphic3d_TextureEnv
6454 OCC_TextureEnv(const Standard_CString FileName);
6455 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
6456 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
6457 const Standard_Boolean theModulateFlag,
6458 const Graphic3d_TypeOfTextureFilter theFilter,
6459 const Standard_ShortReal theXScale,
6460 const Standard_ShortReal theYScale,
6461 const Standard_ShortReal theXShift,
6462 const Standard_ShortReal theYShift,
6463 const Standard_ShortReal theAngle);
6464 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
6466 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
6468 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
6469 : Graphic3d_TextureEnv(theFileName)
6473 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
6474 : Graphic3d_TextureEnv(theTexId)
6478 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
6479 const Standard_Boolean theModulateFlag,
6480 const Graphic3d_TypeOfTextureFilter theFilter,
6481 const Standard_ShortReal theXScale,
6482 const Standard_ShortReal theYScale,
6483 const Standard_ShortReal theXShift,
6484 const Standard_ShortReal theYShift,
6485 const Standard_ShortReal theAngle)
6487 myParams->SetRepeat (theRepeatFlag);
6488 myParams->SetModulate (theModulateFlag);
6489 myParams->SetFilter (theFilter);
6490 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
6491 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
6492 myParams->SetRotation (theAngle);
6495 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
6497 // get the active view
6498 Handle(V3d_View) aView = ViewerTest::CurrentView();
6501 std::cerr << "No active view. Please call vinit.\n";
6505 // Checking the input arguments
6506 Standard_Boolean anEnableFlag = Standard_False;
6507 Standard_Boolean isOk = theArgNb >= 2;
6510 TCollection_AsciiString anEnableOpt(theArgVec[1]);
6511 anEnableFlag = anEnableOpt.IsEqual("on");
6512 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
6516 isOk = (theArgNb == 3 || theArgNb == 11);
6519 TCollection_AsciiString aTextureOpt(theArgVec[2]);
6520 isOk = (!aTextureOpt.IsIntegerValue() ||
6521 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
6523 if (isOk && theArgNb == 11)
6525 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
6526 aModulateOpt(theArgVec[4]),
6527 aFilterOpt (theArgVec[5]),
6528 aSScaleOpt (theArgVec[6]),
6529 aTScaleOpt (theArgVec[7]),
6530 aSTransOpt (theArgVec[8]),
6531 aTTransOpt (theArgVec[9]),
6532 anAngleOpt (theArgVec[10]);
6533 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
6534 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
6535 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
6536 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
6537 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
6538 anAngleOpt.IsRealValue());
6545 std::cerr << "Usage :" << std::endl;
6546 std::cerr << theArgVec[0] << " off" << std::endl;
6547 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;
6553 TCollection_AsciiString aTextureOpt(theArgVec[2]);
6554 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
6555 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
6556 new OCC_TextureEnv(theArgVec[2]);
6560 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
6561 aTexEnv->SetTextureParameters(
6562 aRepeatOpt. IsEqual("repeat"),
6563 aModulateOpt.IsEqual("modulate"),
6564 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
6565 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
6566 Graphic3d_TOTF_TRILINEAR,
6567 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
6568 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
6569 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
6570 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
6571 (Standard_ShortReal)Draw::Atof(theArgVec[10])
6574 aView->SetTextureEnv(aTexEnv);
6575 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
6577 else // Disabling environment mapping
6579 aView->SetSurfaceDetail(V3d_TEX_NONE);
6580 Handle(Graphic3d_TextureEnv) aTexture;
6581 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
6588 //===============================================================================================
6589 //function : VClipPlane
6591 //===============================================================================================
6592 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6594 // use short-cut for created clip planes map of created (or "registered by name") clip planes
6595 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
6596 static MapOfPlanes aRegPlanes;
6600 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
6604 TCollection_AsciiString aCommand (theArgVec[1]);
6606 // print maximum number of planes for current viewer
6607 if (aCommand == "maxplanes")
6611 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
6615 TCollection_AsciiString aViewName (theArgVec[2]);
6617 if (!ViewerTest_myViews.IsBound1 (aViewName))
6619 theDi << theArgVec[0] << ": view is not found.\n";
6623 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
6625 theDi << theArgVec[0] << ": "
6626 << aView->Viewer()->Driver()->InquirePlaneLimit()
6627 << " plane slots provided by driver."
6628 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
6633 // create / delete plane instance
6634 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
6638 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
6642 Standard_Boolean toCreate = (aCommand == "create");
6643 Standard_Boolean toClone = (aCommand == "clone");
6644 TCollection_AsciiString aPlane (theArgVec[2]);
6648 if (aRegPlanes.IsBound (aPlane))
6650 theDi << theArgVec[0] << ": plane name is in use.\n";
6654 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
6656 else if (toClone) // toClone
6658 if (!aRegPlanes.IsBound (aPlane))
6660 theDi << theArgVec[0] << ": no such plane.\n";
6666 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
6670 TCollection_AsciiString aClone (theArgVec[3]);
6671 if (aRegPlanes.IsBound (aClone))
6673 theDi << theArgVec[0] << ": plane name is in use.\n";
6677 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6679 aRegPlanes.Bind (aClone, aClipPlane->Clone());
6683 if (!aRegPlanes.IsBound (aPlane))
6685 theDi << theArgVec[0] << ": no such plane.\n";
6689 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
6690 aRegPlanes.UnBind (aPlane);
6692 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
6693 for (; anIObjIt.More(); anIObjIt.Next())
6695 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
6696 aPrs->RemoveClipPlane(aClipPlane);
6699 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
6700 for (; aViewIt.More(); aViewIt.Next())
6702 const Handle(V3d_View)& aView = aViewIt.Key2();
6703 aView->RemoveClipPlane(aClipPlane);
6706 ViewerTest::RedrawAllViews();
6712 // set / unset plane command
6713 if (aCommand == "set" || aCommand == "unset")
6717 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6721 Standard_Boolean toSet = (aCommand == "set");
6722 TCollection_AsciiString aPlane (theArgVec [2]);
6723 if (!aRegPlanes.IsBound (aPlane))
6725 theDi << theArgVec[0] << ": no such plane.\n";
6729 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6731 TCollection_AsciiString aTarget (theArgVec [3]);
6732 if (aTarget != "object" && aTarget != "view")
6734 theDi << theArgVec[0] << ": invalid target.\n";
6738 if (aTarget == "object" || aTarget == "view")
6742 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6746 Standard_Boolean isObject = (aTarget == "object");
6748 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
6750 TCollection_AsciiString anEntityName (theArgVec[anIt]);
6751 if (isObject) // to object
6753 if (!GetMapOfAIS().IsBound2 (anEntityName))
6755 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
6759 Handle(AIS_InteractiveObject) aIObj =
6760 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
6763 aIObj->AddClipPlane (aClipPlane);
6765 aIObj->RemoveClipPlane (aClipPlane);
6769 if (!ViewerTest_myViews.IsBound1 (anEntityName))
6771 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
6775 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
6777 aView->AddClipPlane (aClipPlane);
6779 aView->RemoveClipPlane (aClipPlane);
6783 ViewerTest::RedrawAllViews();
6789 // change plane command
6790 if (aCommand == "change")
6794 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6798 TCollection_AsciiString aPlane (theArgVec [2]);
6799 if (!aRegPlanes.IsBound (aPlane))
6801 theDi << theArgVec[0] << ": no such plane.\n";
6805 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6807 TCollection_AsciiString aChangeArg (theArgVec [3]);
6808 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
6810 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
6814 if (aChangeArg == "on" || aChangeArg == "off") // on / off
6816 aClipPlane->SetOn (aChangeArg == "on");
6818 else if (aChangeArg == "equation") // change equation
6822 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6826 Standard_Real aCoeffA = Draw::Atof (theArgVec [4]);
6827 Standard_Real aCoeffB = Draw::Atof (theArgVec [5]);
6828 Standard_Real aCoeffC = Draw::Atof (theArgVec [6]);
6829 Standard_Real aCoeffD = Draw::Atof (theArgVec [7]);
6830 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
6832 else if (aChangeArg == "capping") // change capping aspects
6836 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6840 TCollection_AsciiString aCappingArg (theArgVec [4]);
6841 if (aCappingArg != "on" && aCappingArg != "off" &&
6842 aCappingArg != "color" && aCappingArg != "texname" &&
6843 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
6844 aCappingArg != "texrotate" && aCappingArg != "hatch")
6846 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
6850 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
6852 aClipPlane->SetCapping (aCappingArg == "on");
6854 else if (aCappingArg == "color") // color aspect for capping
6858 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6862 Standard_Real aRed = Draw::Atof (theArgVec [5]);
6863 Standard_Real aGrn = Draw::Atof (theArgVec [6]);
6864 Standard_Real aBlu = Draw::Atof (theArgVec [7]);
6866 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
6867 Quantity_Color aColor (aRed, aGrn, aBlu, Quantity_TOC_RGB);
6868 aMat.SetAmbientColor (aColor);
6869 aMat.SetDiffuseColor (aColor);
6870 aClipPlane->SetCappingMaterial (aMat);
6872 else if (aCappingArg == "texname") // texture name
6876 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6880 TCollection_AsciiString aTextureName (theArgVec [5]);
6882 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
6883 if (!aTexture->IsDone ())
6885 aClipPlane->SetCappingTexture (NULL);
6889 aTexture->EnableModulate();
6890 aTexture->EnableRepeat();
6891 aClipPlane->SetCappingTexture (aTexture);
6894 else if (aCappingArg == "texscale") // texture scale
6896 if (aClipPlane->CappingTexture().IsNull())
6898 theDi << theArgVec[0] << ": no texture is set.\n";
6904 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6908 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
6909 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
6911 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
6913 else if (aCappingArg == "texorigin") // texture origin
6915 if (aClipPlane->CappingTexture().IsNull())
6917 theDi << theArgVec[0] << ": no texture is set.\n";
6923 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6927 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
6928 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
6930 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
6932 else if (aCappingArg == "texrotate") // texture rotation
6934 if (aClipPlane->CappingTexture().IsNull())
6936 theDi << theArgVec[0] << ": no texture is set.\n";
6942 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6946 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
6948 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
6950 else if (aCappingArg == "hatch") // hatch style
6954 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6958 TCollection_AsciiString aHatchStr (theArgVec [5]);
6959 if (aHatchStr == "on")
6961 aClipPlane->SetCappingHatchOn();
6963 else if (aHatchStr == "off")
6965 aClipPlane->SetCappingHatchOff();
6969 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
6974 ViewerTest::RedrawAllViews();
6979 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
6983 //===============================================================================================
6984 //function : VSetTextureMode
6986 //===============================================================================================
6987 static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6991 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
6995 TCollection_AsciiString aViewName (theArgVec[1]);
6996 if (!ViewerTest_myViews.IsBound1 (aViewName))
6998 theDi << theArgVec[0] << ": view is not found.\n";
7002 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
7003 switch (atoi (theArgVec[2]))
7005 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
7006 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
7007 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
7009 theDi << theArgVec[0] << ": invalid mode.\n";
7017 //===============================================================================================
7018 //function : VZRange
7020 //===============================================================================================
7021 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7023 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
7025 if (aCurrentView.IsNull())
7027 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
7031 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
7035 theDi << "ZNear: " << aCamera->ZNear() << "\n";
7036 theDi << "ZFar: " << aCamera->ZFar() << "\n";
7042 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
7043 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
7045 if (aNewZNear >= aNewZFar)
7047 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
7051 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
7053 std::cout << theArgVec[0] << ": invalid arguments: ";
7054 std::cout << "znear, zfar should be positive for perspective camera.\n";
7058 aCamera->SetZRange (aNewZNear, aNewZFar);
7062 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
7066 aCurrentView->Redraw();
7071 //===============================================================================================
7072 //function : VAutoZFit
7074 //===============================================================================================
7075 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7077 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
7079 if (aCurrentView.IsNull())
7081 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
7085 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
7089 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
7095 theDi << "Auto z-fit mode: \n"
7096 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
7097 << "Scale: " << aScale << "\n";
7101 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
7105 aScale = Draw::Atoi (theArgVec[2]);
7108 aCurrentView->SetAutoZFitMode (isOn, aScale);
7109 aCurrentView->AutoZFit();
7110 aCurrentView->Redraw();
7115 //! Auxiliary function to print projection type
7116 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
7118 switch (theProjType)
7120 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
7121 case Graphic3d_Camera::Projection_Perspective: return "perspective";
7122 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
7123 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
7124 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
7129 //===============================================================================================
7130 //function : VCamera
7132 //===============================================================================================
7133 static int VCamera (Draw_Interpretor& theDI,
7134 Standard_Integer theArgsNb,
7135 const char** theArgVec)
7137 Handle(V3d_View) aView = ViewerTest::CurrentView();
7140 std::cout << "Error: no active view.\n";
7144 Handle(Graphic3d_Camera) aCamera = aView->Camera();
7147 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
7148 theDI << "FOVy: " << aCamera->FOVy() << "\n";
7149 theDI << "Distance: " << aCamera->Distance() << "\n";
7150 theDI << "IOD: " << aCamera->IOD() << "\n";
7151 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
7152 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
7153 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
7157 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7159 Standard_CString anArg = theArgVec[anArgIter];
7160 TCollection_AsciiString anArgCase (anArg);
7161 anArgCase.LowerCase();
7162 if (anArgCase == "-proj"
7163 || anArgCase == "-projection"
7164 || anArgCase == "-projtype"
7165 || anArgCase == "-projectiontype")
7167 theDI << projTypeName (aCamera->ProjectionType()) << " ";
7169 else if (anArgCase == "-ortho"
7170 || anArgCase == "-orthographic")
7172 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
7174 else if (anArgCase == "-persp"
7175 || anArgCase == "-perspective"
7176 || anArgCase == "-perspmono"
7177 || anArgCase == "-perspectivemono"
7178 || anArgCase == "-mono")
7180 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
7182 else if (anArgCase == "-stereo"
7183 || anArgCase == "-stereoscopic"
7184 || anArgCase == "-perspstereo"
7185 || anArgCase == "-perspectivestereo")
7187 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7189 else if (anArgCase == "-left"
7190 || anArgCase == "-lefteye"
7191 || anArgCase == "-monoleft"
7192 || anArgCase == "-monolefteye"
7193 || anArgCase == "-perpsleft"
7194 || anArgCase == "-perpslefteye")
7196 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
7198 else if (anArgCase == "-right"
7199 || anArgCase == "-righteye"
7200 || anArgCase == "-monoright"
7201 || anArgCase == "-monorighteye"
7202 || anArgCase == "-perpsright")
7204 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
7206 else if (anArgCase == "-dist"
7207 || anArgCase == "-distance")
7209 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7210 if (anArgValue != NULL
7211 && *anArgValue != '-')
7214 aCamera->SetDistance (Draw::Atof (anArgValue));
7217 theDI << aCamera->Distance() << " ";
7219 else if (anArgCase == "-iod")
7221 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7222 if (anArgValue != NULL
7223 && *anArgValue != '-')
7226 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
7229 theDI << aCamera->IOD() << " ";
7231 else if (anArgCase == "-iodtype")
7233 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
7234 TCollection_AsciiString anValueCase (anArgValue);
7235 anValueCase.LowerCase();
7236 if (anValueCase == "abs"
7237 || anValueCase == "absolute")
7240 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
7243 else if (anValueCase == "rel"
7244 || anValueCase == "relative")
7247 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
7250 else if (*anArgValue != '-')
7252 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
7255 switch (aCamera->GetIODType())
7257 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
7258 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
7261 else if (anArgCase == "-zfocus")
7263 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7264 if (anArgValue != NULL
7265 && *anArgValue != '-')
7268 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
7271 theDI << aCamera->ZFocus() << " ";
7273 else if (anArgCase == "-zfocustype")
7275 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
7276 TCollection_AsciiString anValueCase (anArgValue);
7277 anValueCase.LowerCase();
7278 if (anValueCase == "abs"
7279 || anValueCase == "absolute")
7282 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
7285 else if (anValueCase == "rel"
7286 || anValueCase == "relative")
7289 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
7292 else if (*anArgValue != '-')
7294 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
7297 switch (aCamera->ZFocusType())
7299 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
7300 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
7303 else if (anArgCase == "-fov"
7304 || anArgCase == "-fovy")
7306 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7307 if (anArgValue != NULL
7308 && *anArgValue != '-')
7311 aCamera->SetFOVy (Draw::Atof (anArgValue));
7314 theDI << aCamera->FOVy() << " ";
7318 std::cout << "Error: unknown argument '" << anArg << "'\n";
7329 //! Parse stereo output mode
7330 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
7331 Graphic3d_StereoMode& theMode)
7333 TCollection_AsciiString aFlag (theArg);
7335 if (aFlag == "quadbuffer")
7337 theMode = Graphic3d_StereoMode_QuadBuffer;
7339 else if (aFlag == "anaglyph")
7341 theMode = Graphic3d_StereoMode_Anaglyph;
7343 else if (aFlag == "row"
7344 || aFlag == "rowinterlaced")
7346 theMode = Graphic3d_StereoMode_RowInterlaced;
7348 else if (aFlag == "col"
7349 || aFlag == "colinterlaced"
7350 || aFlag == "columninterlaced")
7352 theMode = Graphic3d_StereoMode_ColumnInterlaced;
7354 else if (aFlag == "chess"
7355 || aFlag == "chessboard")
7357 theMode = Graphic3d_StereoMode_ChessBoard;
7359 else if (aFlag == "sbs"
7360 || aFlag == "sidebyside")
7362 theMode = Graphic3d_StereoMode_SideBySide;
7364 else if (aFlag == "ou"
7365 || aFlag == "overunder")
7367 theMode = Graphic3d_StereoMode_OverUnder;
7369 else if (aFlag == "pageflip"
7370 || aFlag == "softpageflip")
7372 theMode = Graphic3d_StereoMode_SoftPageFlip;
7376 return Standard_False;
7378 return Standard_True;
7381 //! Parse anaglyph filter
7382 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
7383 Graphic3d_RenderingParams::Anaglyph& theFilter)
7385 TCollection_AsciiString aFlag (theArg);
7387 if (aFlag == "redcyansimple")
7389 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
7391 else if (aFlag == "redcyan"
7392 || aFlag == "redcyanoptimized")
7394 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
7396 else if (aFlag == "yellowbluesimple")
7398 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
7400 else if (aFlag == "yellowblue"
7401 || aFlag == "yellowblueoptimized")
7403 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
7405 else if (aFlag == "greenmagenta"
7406 || aFlag == "greenmagentasimple")
7408 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
7412 return Standard_False;
7414 return Standard_True;
7417 //==============================================================================
7418 //function : VStereo
7420 //==============================================================================
7422 static int VStereo (Draw_Interpretor& theDI,
7423 Standard_Integer theArgNb,
7424 const char** theArgVec)
7426 Handle(V3d_View) aView = ViewerTest::CurrentView();
7431 std::cout << "Error: no active viewer!\n";
7435 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
7436 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
7439 TCollection_AsciiString aMode;
7440 switch (aView->RenderingParams().StereoMode)
7442 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
7443 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
7444 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
7445 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
7446 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
7447 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
7448 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
7449 case Graphic3d_StereoMode_Anaglyph :
7451 switch (aView->RenderingParams().AnaglyphFilter)
7453 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
7454 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
7455 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
7456 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
7457 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
7462 theDI << "Mode " << aMode << "\n";
7467 Handle(Graphic3d_Camera) aCamera;
7468 Graphic3d_RenderingParams* aParams = NULL;
7469 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
7470 if (!aView.IsNull())
7472 aParams = &aView->ChangeRenderingParams();
7473 aMode = aParams->StereoMode;
7474 aCamera = aView->Camera();
7477 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7478 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7480 Standard_CString anArg = theArgVec[anArgIter];
7481 TCollection_AsciiString aFlag (anArg);
7483 if (anUpdateTool.parseRedrawMode (aFlag))
7487 else if (aFlag == "0"
7490 if (++anArgIter < theArgNb)
7492 std::cout << "Error: wrong number of arguments!\n";
7496 if (!aCamera.IsNull()
7497 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
7499 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
7501 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
7504 else if (aFlag == "1"
7507 if (++anArgIter < theArgNb)
7509 std::cout << "Error: wrong number of arguments!\n";
7513 if (!aCamera.IsNull())
7515 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7517 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
7520 else if (aFlag == "-reverse"
7521 || aFlag == "-reversed"
7522 || aFlag == "-swap")
7524 Standard_Boolean toEnable = Standard_True;
7525 if (++anArgIter < theArgNb
7526 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
7530 aParams->ToReverseStereo = toEnable;
7532 else if (aFlag == "-noreverse"
7533 || aFlag == "-noswap")
7535 Standard_Boolean toDisable = Standard_True;
7536 if (++anArgIter < theArgNb
7537 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
7541 aParams->ToReverseStereo = !toDisable;
7543 else if (aFlag == "-mode"
7544 || aFlag == "-stereomode")
7546 if (++anArgIter >= theArgNb
7547 || !parseStereoMode (theArgVec[anArgIter], aMode))
7549 std::cout << "Error: syntax error at '" << anArg << "'\n";
7553 if (aMode == Graphic3d_StereoMode_QuadBuffer)
7555 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
7558 else if (aFlag == "-anaglyph"
7559 || aFlag == "-anaglyphfilter")
7561 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
7562 if (++anArgIter >= theArgNb
7563 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
7565 std::cout << "Error: syntax error at '" << anArg << "'\n";
7569 aMode = Graphic3d_StereoMode_Anaglyph;
7570 aParams->AnaglyphFilter = aFilter;
7572 else if (parseStereoMode (anArg, aMode)) // short syntax
7574 if (aMode == Graphic3d_StereoMode_QuadBuffer)
7576 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
7581 std::cout << "Error: syntax error at '" << anArg << "'\n";
7586 if (!aView.IsNull())
7588 aParams->StereoMode = aMode;
7589 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7594 //===============================================================================================
7595 //function : VDefaults
7597 //===============================================================================================
7598 static int VDefaults (Draw_Interpretor& theDi,
7599 Standard_Integer theArgsNb,
7600 const char** theArgVec)
7602 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
7605 std::cerr << "No active viewer!\n";
7609 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
7612 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
7614 theDi << "DeflType: relative\n"
7615 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
7619 theDi << "DeflType: absolute\n"
7620 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
7622 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
7623 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
7627 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7629 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7631 if (anArg == "-ABSDEFL"
7632 || anArg == "-ABSOLUTEDEFLECTION"
7634 || anArg == "-DEFLECTION")
7636 if (++anArgIter >= theArgsNb)
7638 std::cout << "Error: wrong syntax at " << anArg << "\n";
7641 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
7642 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
7644 else if (anArg == "-RELDEFL"
7645 || anArg == "-RELATIVEDEFLECTION"
7646 || anArg == "-DEVCOEFF"
7647 || anArg == "-DEVIATIONCOEFF"
7648 || anArg == "-DEVIATIONCOEFFICIENT")
7650 if (++anArgIter >= theArgsNb)
7652 std::cout << "Error: wrong syntax at " << anArg << "\n";
7655 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
7656 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
7658 else if (anArg == "-ANGDEFL"
7659 || anArg == "-ANGULARDEFL"
7660 || anArg == "-ANGULARDEFLECTION")
7662 if (++anArgIter >= theArgsNb)
7664 std::cout << "Error: wrong syntax at " << anArg << "\n";
7667 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
7668 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
7670 else if (anArg == "-AUTOTR"
7671 || anArg == "-AUTOTRIANG"
7672 || anArg == "-AUTOTRIANGULATION")
7674 if (++anArgIter >= theArgsNb)
7676 std::cout << "Error: wrong syntax at " << anArg << "\n";
7679 TCollection_AsciiString aValue (theArgVec[anArgIter]);
7684 aDefParams->SetAutoTriangulation (Standard_True);
7686 else if (aValue == "off"
7689 aDefParams->SetAutoTriangulation (Standard_False);
7694 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
7701 //! Auxiliary method
7702 inline void addLight (const Handle(V3d_Light)& theLightNew,
7703 const Standard_Boolean theIsGlobal)
7705 if (theLightNew.IsNull())
7712 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
7716 ViewerTest::CurrentView()->SetLightOn (theLightNew);
7720 //! Auxiliary method
7721 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
7723 TCollection_AsciiString anArgNextCase (theArgNext);
7724 anArgNextCase.UpperCase();
7725 if (anArgNextCase.Length() > 5
7726 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
7728 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
7732 return theArgNext.IntegerValue();
7736 //===============================================================================================
7739 //===============================================================================================
7740 static int VLight (Draw_Interpretor& theDi,
7741 Standard_Integer theArgsNb,
7742 const char** theArgVec)
7744 Handle(V3d_View) aView = ViewerTest::CurrentView();
7745 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
7747 || aViewer.IsNull())
7749 std::cerr << "No active viewer!\n";
7753 Standard_Real anXYZ[3];
7754 Quantity_Coefficient anAtten[2];
7757 // print lights info
7758 Standard_Integer aLightId = 0;
7759 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId)
7761 Handle(V3d_Light) aLight = aView->ActiveLight();
7762 const Quantity_Color aColor = aLight->Color();
7763 theDi << "Light" << aLightId << "\n";
7764 switch (aLight->Type())
7768 theDi << " Type: Ambient\n";
7769 theDi << " Intensity: " << aLight->Intensity() << "\n";
7772 case V3d_DIRECTIONAL:
7774 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
7775 theDi << " Type: Directional\n";
7776 theDi << " Intensity: " << aLight->Intensity() << "\n";
7777 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7778 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
7779 if (!aLightDir.IsNull())
7781 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7782 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7783 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
7784 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7788 case V3d_POSITIONAL:
7790 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
7791 theDi << " Type: Positional\n";
7792 theDi << " Intensity: " << aLight->Intensity() << "\n";
7793 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7794 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
7795 if (!aLightPos.IsNull())
7797 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7798 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7799 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7800 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
7806 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
7807 theDi << " Type: Spot\n";
7808 theDi << " Intensity: " << aLight->Intensity() << "\n";
7809 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7810 if (!aLightSpot.IsNull())
7812 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7813 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7814 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
7815 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7816 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7817 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
7818 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
7819 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
7825 theDi << " Type: UNKNOWN\n";
7829 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
7833 Handle(V3d_Light) aLightNew;
7834 Handle(V3d_Light) aLightOld;
7835 Standard_Boolean isGlobal = Standard_True;
7836 Standard_Boolean toCreate = Standard_False;
7837 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
7839 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
7840 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
7841 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
7842 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
7843 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
7845 TCollection_AsciiString aName, aValue;
7846 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
7847 TCollection_AsciiString anArgCase (anArg);
7848 anArgCase.UpperCase();
7849 if (anArgCase.IsEqual ("NEW")
7850 || anArgCase.IsEqual ("ADD")
7851 || anArgCase.IsEqual ("CREATE"))
7853 toCreate = Standard_True;
7855 else if (anArgCase.IsEqual ("GLOB")
7856 || anArgCase.IsEqual ("GLOBAL"))
7858 isGlobal = Standard_True;
7860 else if (anArgCase.IsEqual ("LOC")
7861 || anArgCase.IsEqual ("LOCAL"))
7863 isGlobal = Standard_False;
7865 else if (anArgCase.IsEqual ("DEF")
7866 || anArgCase.IsEqual ("DEFAULTS"))
7868 toCreate = Standard_False;
7869 aViewer->SetDefaultLights();
7871 else if (anArgCase.IsEqual ("CLR")
7872 || anArgCase.IsEqual ("CLEAR"))
7874 toCreate = Standard_False;
7875 aView->InitActiveLights();
7876 while (aView->MoreActiveLights())
7878 aViewer->DelLight (aView->ActiveLight());
7879 aView->InitActiveLights();
7882 else if (anArgCase.IsEqual ("AMB")
7883 || anArgCase.IsEqual ("AMBIENT")
7884 || anArgCase.IsEqual ("AMBLIGHT"))
7886 addLight (aLightNew, isGlobal);
7889 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7892 toCreate = Standard_False;
7893 aLightNew = new V3d_AmbientLight (aViewer);
7895 else if (anArgCase.IsEqual ("DIRECTIONAL")
7896 || anArgCase.IsEqual ("DIRLIGHT"))
7898 addLight (aLightNew, isGlobal);
7901 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7904 toCreate = Standard_False;
7905 aLightNew = new V3d_DirectionalLight (aViewer);
7907 else if (anArgCase.IsEqual ("SPOT")
7908 || anArgCase.IsEqual ("SPOTLIGHT"))
7910 addLight (aLightNew, isGlobal);
7913 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7916 toCreate = Standard_False;
7917 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
7919 else if (anArgCase.IsEqual ("POSLIGHT")
7920 || anArgCase.IsEqual ("POSITIONAL"))
7922 addLight (aLightNew, isGlobal);
7925 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7928 toCreate = Standard_False;
7929 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
7931 else if (anArgCase.IsEqual ("CHANGE"))
7933 addLight (aLightNew, isGlobal);
7934 aLightNew.Nullify();
7935 if (++anArgIt >= theArgsNb)
7937 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7941 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
7942 Standard_Integer aLightIt = 0;
7943 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
7945 if (aLightIt == aLightId)
7947 aLightOld = aView->ActiveLight();
7952 if (aLightOld.IsNull())
7954 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
7958 else if (anArgCase.IsEqual ("DEL")
7959 || anArgCase.IsEqual ("DELETE"))
7961 Handle(V3d_Light) aLightDel;
7962 if (++anArgIt >= theArgsNb)
7964 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7968 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
7969 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
7970 Standard_Integer aLightIt = 0;
7971 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
7973 aLightDel = aView->ActiveLight();
7974 if (aLightIt == aLightDelId)
7979 if (!aLightDel.IsNull())
7981 aViewer->DelLight (aLightDel);
7984 else if (anArgCase.IsEqual ("COLOR")
7985 || anArgCase.IsEqual ("COLOUR"))
7987 if (++anArgIt >= theArgsNb)
7989 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7993 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
7994 anArgNext.UpperCase();
7995 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
7996 if (!aLightCurr.IsNull())
7998 aLightCurr->SetColor (aColor);
8001 else if (anArgCase.IsEqual ("POS")
8002 || anArgCase.IsEqual ("POSITION"))
8004 if ((anArgIt + 3) >= theArgsNb)
8006 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8010 anXYZ[0] = Atof (theArgVec[++anArgIt]);
8011 anXYZ[1] = Atof (theArgVec[++anArgIt]);
8012 anXYZ[2] = Atof (theArgVec[++anArgIt]);
8013 if (!aLightDir.IsNull())
8015 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
8017 else if (!aLightPos.IsNull())
8019 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
8021 else if (!aLightSpot.IsNull())
8023 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
8027 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8031 else if (anArgCase.IsEqual ("DIR")
8032 || anArgCase.IsEqual ("DIRECTION"))
8034 if ((anArgIt + 3) >= theArgsNb)
8036 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8040 anXYZ[0] = Atof (theArgVec[++anArgIt]);
8041 anXYZ[1] = Atof (theArgVec[++anArgIt]);
8042 anXYZ[2] = Atof (theArgVec[++anArgIt]);
8043 if (!aLightDir.IsNull())
8045 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
8047 else if (!aLightSpot.IsNull())
8049 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
8053 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8057 else if (anArgCase.IsEqual ("SM")
8058 || anArgCase.IsEqual ("SMOOTHNESS"))
8060 if (++anArgIt >= theArgsNb)
8062 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8066 Standard_Real aSmoothness = Atof (theArgVec[anArgIt]);
8068 if (fabs (aSmoothness) < Precision::Confusion())
8070 aLightCurr->SetIntensity (1.f);
8072 else if (fabs (aLightCurr->Smoothness()) < Precision::Confusion())
8074 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
8078 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
8079 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
8082 if (!aLightPos.IsNull())
8084 aLightPos->SetSmoothRadius (aSmoothness);
8086 else if (!aLightDir.IsNull())
8088 aLightDir->SetSmoothAngle (aSmoothness);
8091 else if (anArgCase.IsEqual ("INT")
8092 || anArgCase.IsEqual ("INTENSITY"))
8094 if (++anArgIt >= theArgsNb)
8096 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8100 Standard_Real aIntensity = Atof (theArgVec[anArgIt]);
8102 if (!aLightCurr.IsNull())
8104 aLightCurr->SetIntensity (aIntensity);
8107 else if (anArgCase.IsEqual ("ANG")
8108 || anArgCase.IsEqual ("ANGLE"))
8110 if (++anArgIt >= theArgsNb)
8112 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8116 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
8118 if (!aLightSpot.IsNull())
8120 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
8123 else if (anArgCase.IsEqual ("CONSTATTEN")
8124 || anArgCase.IsEqual ("CONSTATTENUATION"))
8126 if (++anArgIt >= theArgsNb)
8128 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8132 if (!aLightPos.IsNull())
8134 aLightPos->Attenuation (anAtten[0], anAtten[1]);
8135 anAtten[0] = Atof (theArgVec[anArgIt]);
8136 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
8138 else if (!aLightSpot.IsNull())
8140 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
8141 anAtten[0] = Atof (theArgVec[anArgIt]);
8142 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
8146 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8150 else if (anArgCase.IsEqual ("LINATTEN")
8151 || anArgCase.IsEqual ("LINEARATTEN")
8152 || anArgCase.IsEqual ("LINEARATTENUATION"))
8154 if (++anArgIt >= theArgsNb)
8156 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8160 if (!aLightPos.IsNull())
8162 aLightPos->Attenuation (anAtten[0], anAtten[1]);
8163 anAtten[1] = Atof (theArgVec[anArgIt]);
8164 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
8166 else if (!aLightSpot.IsNull())
8168 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
8169 anAtten[1] = Atof (theArgVec[anArgIt]);
8170 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
8174 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8178 else if (anArgCase.IsEqual ("EXP")
8179 || anArgCase.IsEqual ("EXPONENT")
8180 || anArgCase.IsEqual ("SPOTEXP")
8181 || anArgCase.IsEqual ("SPOTEXPONENT"))
8183 if (++anArgIt >= theArgsNb)
8185 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8189 if (!aLightSpot.IsNull())
8191 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
8195 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8199 else if (anArgCase.IsEqual ("HEAD")
8200 || anArgCase.IsEqual ("HEADLIGHT"))
8202 if (++anArgIt >= theArgsNb)
8204 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8208 if (aLightAmb.IsNull()
8209 && !aLightCurr.IsNull())
8211 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
8215 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8221 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
8225 addLight (aLightNew, isGlobal);
8226 aViewer->UpdateLights();
8231 //=======================================================================
8232 //function : VRenderParams
8233 //purpose : Enables/disables rendering features
8234 //=======================================================================
8236 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
8237 Standard_Integer theArgNb,
8238 const char** theArgVec)
8240 Handle(V3d_View) aView = ViewerTest::CurrentView();
8243 std::cerr << "Error: no active viewer!\n";
8247 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
8248 TCollection_AsciiString aCmdName (theArgVec[0]);
8249 aCmdName.LowerCase();
8250 if (aCmdName == "vraytrace")
8254 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
8257 else if (theArgNb == 2)
8259 TCollection_AsciiString aValue (theArgVec[1]);
8264 aParams.Method = Graphic3d_RM_RAYTRACING;
8268 else if (aValue == "off"
8271 aParams.Method = Graphic3d_RM_RASTERIZATION;
8277 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
8283 std::cout << "Error: wrong number of arguments\n";
8290 theDI << "renderMode: ";
8291 switch (aParams.Method)
8293 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
8294 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
8297 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
8298 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
8299 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
8300 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
8301 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
8302 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
8303 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
8304 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
8305 theDI << "shadingModel: ";
8306 switch (aView->ShadingModel())
8308 case V3d_COLOR: theDI << "color"; break;
8309 case V3d_FLAT: theDI << "flat"; break;
8310 case V3d_GOURAUD: theDI << "gouraud"; break;
8311 case V3d_PHONG: theDI << "phong"; break;
8317 Standard_Boolean toPrint = Standard_False;
8318 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
8319 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
8321 Standard_CString anArg (theArgVec[anArgIter]);
8322 TCollection_AsciiString aFlag (anArg);
8324 if (anUpdateTool.parseRedrawMode (aFlag))
8328 else if (aFlag == "-echo"
8329 || aFlag == "-print")
8331 toPrint = Standard_True;
8332 anUpdateTool.Invalidate();
8334 else if (aFlag == "-mode"
8335 || aFlag == "-rendermode"
8336 || aFlag == "-render_mode")
8340 switch (aParams.Method)
8342 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
8343 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
8349 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8353 else if (aFlag == "-ray"
8354 || aFlag == "-raytrace")
8358 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
8362 aParams.Method = Graphic3d_RM_RAYTRACING;
8364 else if (aFlag == "-rast"
8365 || aFlag == "-raster"
8366 || aFlag == "-rasterization")
8370 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
8374 aParams.Method = Graphic3d_RM_RASTERIZATION;
8376 else if (aFlag == "-msaa")
8380 theDI << aParams.NbMsaaSamples << " ";
8383 else if (++anArgIter >= theArgNb)
8385 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8389 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
8392 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
8397 aParams.NbMsaaSamples = aNbSamples;
8400 else if (aFlag == "-raydepth"
8401 || aFlag == "-ray_depth")
8405 theDI << aParams.RaytracingDepth << " ";
8408 else if (++anArgIter >= theArgNb)
8410 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8414 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
8416 // We allow RaytracingDepth be more than 10 in case of GI enabled
8417 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
8419 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
8424 aParams.RaytracingDepth = aDepth;
8427 else if (aFlag == "-shad"
8428 || aFlag == "-shadows")
8432 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
8436 Standard_Boolean toEnable = Standard_True;
8437 if (++anArgIter < theArgNb
8438 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8442 aParams.IsShadowEnabled = toEnable;
8444 else if (aFlag == "-refl"
8445 || aFlag == "-reflections")
8449 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
8453 Standard_Boolean toEnable = Standard_True;
8454 if (++anArgIter < theArgNb
8455 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8459 aParams.IsReflectionEnabled = toEnable;
8461 else if (aFlag == "-fsaa")
8465 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
8469 Standard_Boolean toEnable = Standard_True;
8470 if (++anArgIter < theArgNb
8471 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8475 aParams.IsAntialiasingEnabled = toEnable;
8477 else if (aFlag == "-gleam")
8481 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
8485 Standard_Boolean toEnable = Standard_True;
8486 if (++anArgIter < theArgNb
8487 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8491 aParams.IsTransparentShadowEnabled = toEnable;
8493 else if (aFlag == "-gi")
8497 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
8501 Standard_Boolean toEnable = Standard_True;
8502 if (++anArgIter < theArgNb
8503 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8507 aParams.IsGlobalIlluminationEnabled = toEnable;
8510 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
8513 else if (aFlag == "-blockedrng"
8514 || aFlag == "-brng")
8518 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
8522 Standard_Boolean toEnable = Standard_True;
8523 if (++anArgIter < theArgNb
8524 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8528 aParams.CoherentPathTracingMode = toEnable;
8530 else if (aFlag == "-env")
8534 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
8538 Standard_Boolean toEnable = Standard_True;
8539 if (++anArgIter < theArgNb
8540 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8544 aParams.UseEnvironmentMapBackground = toEnable;
8546 else if (aFlag == "-shademodel"
8547 || aFlag == "-shadingmodel"
8548 || aFlag == "-shading")
8552 switch (aView->ShadingModel())
8554 case V3d_COLOR: theDI << "color "; break;
8555 case V3d_FLAT: theDI << "flat "; break;
8556 case V3d_GOURAUD: theDI << "gouraud "; break;
8557 case V3d_PHONG: theDI << "phong "; break;
8562 if (++anArgIter >= theArgNb)
8564 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8567 TCollection_AsciiString aMode (theArgVec[anArgIter]);
8569 if (aMode == "color"
8572 aView->SetShadingModel (V3d_COLOR);
8574 else if (aMode == "flat"
8575 || aMode == "facet")
8577 aView->SetShadingModel (V3d_FLAT);
8579 else if (aMode == "gouraud"
8580 || aMode == "vertex"
8583 aView->SetShadingModel (V3d_GOURAUD);
8585 else if (aMode == "phong"
8586 || aMode == "fragment"
8588 || aMode == "pixel")
8590 aView->SetShadingModel (V3d_PHONG);
8594 std::cout << "Error: unknown shading model '" << aMode << "'\n";
8598 else if (aFlag == "-resolution")
8600 if (++anArgIter >= theArgNb)
8602 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8606 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
8607 if (aResolution.IsIntegerValue())
8609 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
8613 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
8619 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
8627 //=======================================================================
8628 //function : VProgressiveMode
8630 //=======================================================================
8632 static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
8633 Standard_Integer /*theNbArgs*/,
8634 const char** /*theArgs*/)
8636 Handle(V3d_View) aView = ViewerTest::CurrentView();
8639 std::cerr << "Error: no active viewer!\n";
8643 std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
8649 Standard_Boolean toExit = Standard_False;
8652 while (PeekMessage (&aMsg, NULL, NULL, NULL, PM_REMOVE))
8654 if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
8656 toExit = Standard_True;
8659 TranslateMessage (&aMsg);
8660 DispatchMessage (&aMsg);
8673 //=======================================================================
8674 //function : VFrustumCulling
8675 //purpose : enables/disables view volume's culling.
8676 //=======================================================================
8677 static int VFrustumCulling (Draw_Interpretor& theDI,
8678 Standard_Integer theArgNb,
8679 const char** theArgVec)
8681 Handle(V3d_View) aView = ViewerTest::CurrentView();
8684 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
8690 theDI << (aView->IsCullingEnabled() ? "on" : "off");
8693 else if (theArgNb != 2)
8695 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
8699 TCollection_AsciiString aModeStr (theArgVec[1]);
8700 aModeStr.LowerCase();
8701 Standard_Boolean toEnable = 0;
8702 if (aModeStr == "on")
8706 else if (aModeStr == "off")
8712 toEnable = Draw::Atoi (theArgVec[1]) != 0;
8715 aView->SetFrustumCulling (toEnable);
8720 //=======================================================================
8721 //function : VHighlightSelected
8723 //=======================================================================
8724 static int VHighlightSelected (Draw_Interpretor& theDI,
8725 Standard_Integer theArgNb,
8726 const char** theArgVec)
8728 if (ViewerTest::GetAISContext().IsNull())
8730 std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n";
8734 const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8738 theDI << (aContext->ToHilightSelected() ? "on" : "off");
8744 std::cout << theArgVec[0] << " error : wrong number of parameters."
8745 << "Type 'help" << theArgVec[0] << "' for more information.";
8750 TCollection_AsciiString aMode (theArgVec[1]);
8752 Standard_Boolean toEnable = Standard_False;
8753 if (aMode.IsEqual ("on"))
8755 toEnable = Standard_True;
8757 else if (aMode.IsEqual ("off"))
8759 toEnable = Standard_False;
8763 toEnable = Draw::Atoi (theArgVec[1]) != 0;
8766 if (toEnable != aContext->ToHilightSelected())
8768 aContext->SetToHilightSelected (toEnable);
8770 // Move cursor to null position and back to process updating of detection
8771 // and highlighting of selected object immediatly.
8772 Standard_Integer aPixX = 0;
8773 Standard_Integer aPixY = 0;
8774 const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager();
8776 anEventManager->GetCurrentPosition (aPixX, aPixY);
8777 anEventManager->MoveTo (0, 0);
8778 anEventManager->MoveTo (aPixX, aPixY);
8784 //=======================================================================
8785 //function : VXRotate
8787 //=======================================================================
8788 static Standard_Integer VXRotate (Draw_Interpretor& di,
8789 Standard_Integer argc,
8792 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8793 if (aContext.IsNull())
8795 di << argv[0] << "ERROR : use 'vinit' command before \n";
8801 di << "ERROR : Usage : " << argv[0] << " name angle\n";
8805 TCollection_AsciiString aName (argv[1]);
8806 Standard_Real anAngle = Draw::Atof (argv[2]);
8809 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
8810 Handle(AIS_InteractiveObject) anIObj;
8811 if (!aMap.IsBound2 (aName) )
8813 di << "Use 'vdisplay' before\n";
8818 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
8821 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
8822 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
8824 aContext->SetLocation (anIObj, aTransform);
8825 aContext->UpdateCurrentViewer();
8831 //=======================================================================
8832 //function : ViewerCommands
8834 //=======================================================================
8836 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
8839 const char *group = "ZeViewer";
8840 theCommands.Add("vinit",
8841 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
8842 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
8844 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
8846 " - Creates new View window with specified name view_name.\n"
8847 "By default the new view is created in the viewer and in"
8848 " graphic driver shared with active view.\n"
8849 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
8850 "If driverName isn't specified the driver will be shared with active view.\n"
8851 "If viewerName isn't specified the viewer will be shared with active view.\n"
8852 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
8853 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
8854 "is used in creation of graphic driver\n"
8856 " - l, t: pixel position of left top corner of the window\n"
8857 " - w,h: width and heigth of window respectively.\n"
8858 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
8859 __FILE__,VInit,group);
8860 theCommands.Add("vclose" ,
8861 "[view_id [keep_context=0|1]]\n"
8862 "or vclose ALL - to remove all created views\n"
8863 " - removes view(viewer window) defined by its view_id.\n"
8864 " - keep_context: by default 0; if 1 and the last view is deleted"
8865 " the current context is not removed.",
8866 __FILE__,VClose,group);
8867 theCommands.Add("vactivate" ,
8869 " - activates view(viewer window) defined by its view_id",
8870 __FILE__,VActivate,group);
8871 theCommands.Add("vviewlist",
8872 "vviewlist [format={tree, long}]"
8873 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
8874 " - format: format of result output, if tree the output is a tree view;"
8875 "otherwise it's a list of full view names. By default format = tree",
8876 __FILE__,VViewList,group);
8877 theCommands.Add("vhelp" ,
8878 "vhelp : display help on the viewer commands",
8879 __FILE__,VHelp,group);
8880 theCommands.Add("vtop" ,
8881 "vtop or <T> : Top view. Orientation +X+Y" ,
8882 __FILE__,VTop,group);
8883 theCommands.Add("vbottom" ,
8884 "vbottom : Bottom view. Orientation +X-Y" ,
8885 __FILE__,VBottom,group);
8886 theCommands.Add("vleft" ,
8887 "vleft : Left view. Orientation -Y+Z" ,
8888 __FILE__,VLeft,group);
8889 theCommands.Add("vright" ,
8890 "vright : Right view. Orientation +Y+Z" ,
8891 __FILE__,VRight,group);
8892 theCommands.Add("vaxo" ,
8893 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
8894 __FILE__,VAxo,group);
8895 theCommands.Add("vfront" ,
8896 "vfront : Front view. Orientation +X+Z" ,
8897 __FILE__,VFront,group);
8898 theCommands.Add("vback" ,
8899 "vback : Back view. Orientation -X+Z" ,
8900 __FILE__,VBack,group);
8901 theCommands.Add("vpick" ,
8902 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
8904 theCommands.Add("vfit" ,
8905 "vfit or <F> [-selected]"
8906 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
8907 __FILE__,VFit,group);
8908 theCommands.Add ("vfitarea",
8909 "vfitarea x1 y1 x2 y2"
8910 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
8911 "\n\t\t: Fit view to show area located between two points"
8912 "\n\t\t: given in world 2D or 3D corrdinates.",
8913 __FILE__, VFitArea, group);
8914 theCommands.Add ("vzfit", "vzfit [scale]\n"
8915 " Matches Z near, Z far view volume planes to the displayed objects.\n"
8916 " \"scale\" - specifies factor to scale computed z range.\n",
8917 __FILE__, VZFit, group);
8918 theCommands.Add("vrepaint",
8919 "vrepaint : vrepaint, force redraw",
8920 __FILE__,VRepaint,group);
8921 theCommands.Add("vclear",
8923 "\n\t\t: remove all the object from the viewer",
8924 __FILE__,VClear,group);
8925 theCommands.Add("vsetbg",
8926 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
8927 __FILE__,VSetBg,group);
8928 theCommands.Add("vsetbgmode",
8929 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
8930 __FILE__,VSetBgMode,group);
8931 theCommands.Add("vsetgradientbg",
8932 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
8933 __FILE__,VSetGradientBg,group);
8934 theCommands.Add("vsetgrbgmode",
8935 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
8936 __FILE__,VSetGradientBgMode,group);
8937 theCommands.Add("vsetcolorbg",
8938 "vsetcolorbg : vsetcolorbg r g b : Set background color",
8939 __FILE__,VSetColorBg,group);
8940 theCommands.Add("vsetdefaultbg",
8941 "vsetdefaultbg r g b\n"
8942 "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode"
8943 "\n\t\t: Set default viewer background fill color (flat/gradient).",
8944 __FILE__,VSetDefaultBg,group);
8945 theCommands.Add("vscale",
8946 "vscale : vscale X Y Z",
8947 __FILE__,VScale,group);
8948 theCommands.Add("vzbufftrihedron",
8949 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
8950 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
8951 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
8952 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
8953 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
8954 "\n\t\t: Displays a trihedron",
8955 __FILE__,VZBuffTrihedron,group);
8956 theCommands.Add("vrotate",
8957 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
8958 "\n : Option -mouseStart starts rotation according to the mouse position"
8959 "\n : Option -mouseMove continues rotation with angle computed"
8960 "\n : from last and new mouse position."
8961 "\n : vrotate AX AY AZ [X Y Z]",
8962 __FILE__,VRotate,group);
8963 theCommands.Add("vzoom",
8964 "vzoom : vzoom coef",
8965 __FILE__,VZoom,group);
8966 theCommands.Add("vpan",
8967 "vpan : vpan dx dy",
8968 __FILE__,VPan,group);
8969 theCommands.Add("vexport",
8970 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
8971 " : exports the view to a vector file of a given format"
8972 " : notice that EMF format requires patched gl2ps",
8973 __FILE__,VExport,group);
8974 theCommands.Add("vcolorscale",
8975 "vcolorscale : vcolorscale name [-range RangeMin = 0 RangeMax = 100 Intervals = 10 -font HeightFont = 16 -textpos "
8976 "Position = left -xy X = 0 Y = 0] [-noupdate|-update]: draw color scale\n"
8977 "-demo/-demoversion draw a demoversion of color scale.\n"
8978 "-show/display display color scale.\n"
8979 "-hide/erase erase color scale.\n"
8980 "Please note that -show/-hide option must be the first argument!\n"
8981 "-color Index R G B: set color for indexed interval\n"
8982 "-color Index ColorName: set color for indexed interval\n"
8983 "-colors R G B R G B ...: set colors for all intervals\n"
8984 "-colors ColorName1 ColorName2 ...: set colors for all intervals\n"
8985 "-colors supports both color names and rgb values in one call\n"
8986 "-label Index Text: set label for indexed interval\n"
8987 "-labels Text Text Text ...: set labels for all intervals\n"
8988 "-title Title [Position]: set the title for color scale with certain position. Default position = center;\n"
8989 "Available text positions: left, right, center, none;\n",
8990 __FILE__,VColorScale,group);
8991 theCommands.Add("vgraduatedtrihedron",
8992 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
8993 "\t[-namefont Name] [-valuesfont Name]\n"
8994 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
8995 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
8996 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
8997 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
8998 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
8999 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
9000 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
9001 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
9002 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
9003 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
9004 " - Displays or erases graduated trihedron"
9005 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
9006 " - namefont - font of axes names. Default: Arial\n"
9007 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
9008 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
9009 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
9010 " - valuesfont - font of axes values. Default: Arial\n"
9011 " - xcolor, ycolor, zcolor - color of axis and values\n"
9012 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
9013 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
9014 __FILE__,VGraduatedTrihedron,group);
9015 theCommands.Add("vprintview" ,
9016 "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
9017 __FILE__,VPrintView,group);
9018 theCommands.Add("vzlayer",
9019 "vzlayer add/del/get/settings/enable/disable [id]\n"
9020 " add - add new z layer to viewer and print its id\n"
9021 " del - del z layer by its id\n"
9022 " get - print sequence of z layers in increasing order of their overlay level\n"
9023 " settings - print status of z layer settings\n"
9024 " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n"
9025 " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n"
9026 " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n"
9027 "\nWhere id is the layer identificator\n"
9030 " vzlayer enable poffset 1\n"
9031 " vzlayer disable depthtest 1\n"
9033 __FILE__,VZLayer,group);
9034 theCommands.Add("vlayerline",
9035 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
9036 __FILE__,VLayerLine,group);
9037 theCommands.Add ("vgrid",
9038 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
9039 " : Mode - rectangular or circular"
9040 " : Type - lines or points",
9041 __FILE__, VGrid, group);
9042 theCommands.Add ("vpriviledgedplane",
9043 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
9044 "\n\t\t: Ox, Oy, Oz - plane origin"
9045 "\n\t\t: Nx, Ny, Nz - plane normal direction"
9046 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
9047 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
9048 __FILE__, VPriviledgedPlane, group);
9049 theCommands.Add ("vconvert",
9050 "vconvert v [Mode={window|view}]"
9051 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
9052 "\n\t\t: vconvert x y z [Mode={window|grid}]"
9053 "\n\t\t: window - convert to window coordinates, pixels"
9054 "\n\t\t: view - convert to view projection plane"
9055 "\n\t\t: grid - convert to model coordinates, given on grid"
9056 "\n\t\t: ray - convert projection ray to model coordiantes"
9057 "\n\t\t: - vconvert v window : convert view to window;"
9058 "\n\t\t: - vconvert v view : convert window to view;"
9059 "\n\t\t: - vconvert x y window : convert view to window;"
9060 "\n\t\t: - vconvert x y view : convert window to view;"
9061 "\n\t\t: - vconvert x y : convert window to model;"
9062 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
9063 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
9064 "\n\t\t: - vconvert x y z window : convert model to window;"
9065 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
9066 "\n\t\t: Converts the given coordinates to window/view/model space.",
9067 __FILE__, VConvert, group);
9068 theCommands.Add ("vfps",
9069 "vfps [framesNb=100] : estimate average frame rate for active view",
9070 __FILE__, VFps, group);
9071 theCommands.Add ("vgldebug",
9072 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
9073 "\n\t\t: [-extraMsg {0|1}] [{0|1}]"
9074 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
9075 "\n\t\t: Debug context can be requested only on Windows"
9076 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
9077 "\n\t\t: -sync - request synchronized debug GL context"
9078 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
9079 "\n\t\t: which are suppressed by default,"
9080 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
9081 "\n\t\t: which are suppressed by default",
9082 __FILE__, VGlDebug, group);
9083 theCommands.Add ("vvbo",
9084 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
9085 __FILE__, VVbo, group);
9086 theCommands.Add ("vstereo",
9087 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
9088 "\n\t\t: [-anaglyph Filter]"
9089 "\n\t\t: Control stereo output mode. Available modes for -mode:"
9090 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
9091 "\n\t\t: requires driver support."
9092 "\n\t\t: Should be called BEFORE vinit!"
9093 "\n\t\t: anaglyph - Anaglyph glasses"
9094 "\n\t\t: rowInterlaced - row-interlaced display"
9095 "\n\t\t: columnInterlaced - column-interlaced display"
9096 "\n\t\t: chessBoard - chess-board output"
9097 "\n\t\t: sideBySide - horizontal pair"
9098 "\n\t\t: overUnder - vertical pair"
9099 "\n\t\t: Available Anaglyph filters for -anaglyph:"
9100 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
9101 "\n\t\t: greenMagentaSimple",
9102 __FILE__, VStereo, group);
9103 theCommands.Add ("vcaps",
9104 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
9105 "\n\t\t: [-compatibleProfile {0|1}]"
9106 "\n\t\t: [-vsync {0|1}]"
9107 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
9108 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
9109 "\n\t\t: Modify particular graphic driver options:"
9110 "\n\t\t: FFP - use fixed-function pipeline instead of"
9111 "\n\t\t: built-in GLSL programs"
9112 "\n\t\t: (requires compatible profile)"
9113 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
9114 "\n\t\t: arrays to GPU memory)"
9115 "\n\t\t: sprite - use textured sprites instead of bitmaps"
9116 "\n\t\t: vsync - switch VSync on or off"
9117 "\n\t\t: Context creation options:"
9118 "\n\t\t: softMode - software OpenGL implementation"
9119 "\n\t\t: compatibleProfile - backward-compatible profile"
9120 "\n\t\t: quadbuffer - QuadBuffer"
9121 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
9122 "\n\t\t: rendering paths producing the same visual result when"
9124 "\n\t\t: Command is intended for testing old hardware compatibility.",
9125 __FILE__, VCaps, group);
9126 theCommands.Add ("vmemgpu",
9127 "vmemgpu [f]: print system-dependent GPU memory information if available;"
9128 " with f option returns free memory in bytes",
9129 __FILE__, VMemGpu, group);
9130 theCommands.Add ("vreadpixel",
9131 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
9132 " : Read pixel value for active view",
9133 __FILE__, VReadPixel, group);
9134 theCommands.Add("diffimage",
9135 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
9136 __FILE__, VDiffImage, group);
9137 theCommands.Add ("vselect",
9138 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
9139 "- emulates different types of selection:\n"
9140 "- 1) single click selection\n"
9141 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
9142 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
9143 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
9144 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
9145 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
9146 " (partial inclusion - overlap - is not allowed by default)\n"
9147 "- 5) any of these selections with shift button pressed",
9148 __FILE__, VSelect, group);
9149 theCommands.Add ("vmoveto",
9151 "- emulates cursor movement to pixel postion (x,y)",
9152 __FILE__, VMoveTo, group);
9153 theCommands.Add ("vviewparams", "vviewparams usage:\n"
9155 "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n"
9156 " [-proj [x y z]] [-center x y] [-size sx]\n"
9157 "- Gets or sets current view parameters.\n"
9158 "- If called without arguments, all view parameters are printed.\n"
9159 "- The options are:\n"
9160 " -scale [s] : prints or sets viewport relative scale.\n"
9161 " -eye [x y z] : prints or sets eye location.\n"
9162 " -at [x y z] : prints or sets center of look.\n"
9163 " -up [x y z] : prints or sets direction of up vector.\n"
9164 " -proj [x y z] : prints or sets direction of look.\n"
9165 " -center x y : sets location of center of the screen in pixels.\n"
9166 " -size [sx] : prints viewport projection width and height sizes\n"
9167 " : or changes the size of its maximum dimension.\n",
9168 __FILE__, VViewParams, group);
9169 theCommands.Add("vchangeselected",
9170 "vchangeselected shape"
9171 "- adds to shape to selection or remove one from it",
9172 __FILE__, VChangeSelected, group);
9173 theCommands.Add("vzclipping",
9174 "vzclipping [mode] [depth width]\n"
9175 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
9176 "- gets or sets ZClipping mode, width and depth",
9177 __FILE__,VZClipping,group);
9178 theCommands.Add ("vnbselected",
9180 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
9181 theCommands.Add ("vcamera",
9182 "vcamera [-ortho] [-projtype]"
9184 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
9185 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
9186 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
9187 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
9188 "\n\t\t: Manage camera parameters."
9189 "\n\t\t: Prints current value when option called without argument."
9190 "\n\t\t: Orthographic camera:"
9191 "\n\t\t: -ortho activate orthographic projection"
9192 "\n\t\t: Perspective camera:"
9193 "\n\t\t: -persp activate perspective projection (mono)"
9194 "\n\t\t: -fovy field of view in y axis, in degrees"
9195 "\n\t\t: -distance distance of eye from camera center"
9196 "\n\t\t: Stereoscopic camera:"
9197 "\n\t\t: -stereo perspective projection (stereo)"
9198 "\n\t\t: -leftEye perspective projection (left eye)"
9199 "\n\t\t: -rightEye perspective projection (right eye)"
9200 "\n\t\t: -iod intraocular distance value"
9201 "\n\t\t: -iodType distance type, absolute or relative"
9202 "\n\t\t: -zfocus stereographic focus value"
9203 "\n\t\t: -zfocusType focus type, absolute or relative",
9204 __FILE__, VCamera, group);
9205 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
9206 "- vautozfit [on={1|0}] [scale]\n"
9207 " Prints or changes parameters of automatic z-fit mode:\n"
9208 " \"on\" - turns automatic z-fit on or off\n"
9209 " \"scale\" - specifies factor to scale computed z range.\n",
9210 __FILE__, VAutoZFit, group);
9211 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
9212 " vzrange - without parameters shows current values\n"
9213 " vzrange [znear] [zfar] - applies provided values to view",
9214 __FILE__,VZRange, group);
9215 theCommands.Add("vantialiasing",
9217 "\n\t\t: Switches altialiasing on or off",
9218 __FILE__,VAntialiasing,group);
9219 theCommands.Add ("vpurgedisplay",
9221 "- removes structures which don't belong to objects displayed in neutral point",
9222 __FILE__, VPurgeDisplay, group);
9223 theCommands.Add("vsetviewsize",
9224 "vsetviewsize size",
9225 __FILE__,VSetViewSize,group);
9226 theCommands.Add("vmoveview",
9227 "vmoveview Dx Dy Dz [Start = 1|0]",
9228 __FILE__,VMoveView,group);
9229 theCommands.Add("vtranslateview",
9230 "vtranslateview Dx Dy Dz [Start = 1|0)]",
9231 __FILE__,VTranslateView,group);
9232 theCommands.Add("vturnview",
9233 "vturnview Ax Ay Az [Start = 1|0]",
9234 __FILE__,VTurnView,group);
9235 theCommands.Add("vtextureenv",
9236 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
9237 "or user-defined file and optionally applying texture mapping parameters\n"
9239 " vtextureenv off - disables environment mapping\n"
9240 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
9241 " std_texture = (0..7)\n"
9242 " rep = {clamp|repeat}\n"
9243 " mod = {decal|modulate}\n"
9244 " flt = {nearest|bilinear|trilinear}\n"
9245 " ss, st - scale factors for s and t texture coordinates\n"
9246 " ts, tt - translation for s and t texture coordinates\n"
9247 " rot - texture rotation angle in degrees",
9248 __FILE__, VTextureEnv, group);
9249 theCommands.Add("vhlr" ,
9250 "is_enabled={on|off} [show_hidden={1|0}]"
9251 " - Hidden line removal algorithm:"
9252 " - is_enabled: if is on HLR algorithm is applied\n"
9253 " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n",
9254 __FILE__,VHLR,group);
9255 theCommands.Add("vhlrtype" ,
9256 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
9257 " - Changes the type of HLR algorithm using for shapes."
9258 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
9259 " if equals to polyalgo, polygonal HLR algorithm is applied."
9260 "If shapes are not given HLR algoithm of given type is applied"
9261 " to all shapes in the view\n",
9262 __FILE__,VHLRType,group);
9263 theCommands.Add("vclipplane", "vclipplane usage: \n"
9264 " maxplanes <view_name> - get plane limit for view.\n"
9265 " create <plane_name> - create new plane.\n"
9266 " delete <plane_name> - delete plane.\n"
9267 " clone <source_plane> <plane_name> - clone the plane definition.\n"
9268 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
9269 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
9270 " change <plane_name> on/off - turn clipping on/off.\n"
9271 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
9272 " change <plane_name> capping on/off - turn capping on/off.\n"
9273 " change <plane_name> capping color <r> <g> <b> - set color.\n"
9274 " change <plane name> capping texname <texture> - set texture.\n"
9275 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
9276 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
9277 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
9278 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
9279 " please use VSetTextureMode command to enable texture rendering in view.\n"
9280 , __FILE__, VClipPlane, group);
9281 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
9283 " 0 - no textures enabled in view.\n"
9284 " 1 - only environment textures enabled.\n"
9285 " 2 - all textures enabled.\n"
9286 " this command sets texture details mode for the specified view.\n"
9287 , __FILE__, VSetTextureMode, group);
9288 theCommands.Add("vdefaults",
9289 "vdefaults [-absDefl value]"
9290 "\n\t\t: [-devCoeff value]"
9291 "\n\t\t: [-angDefl value]"
9292 "\n\t\t: [-autoTriang {off/on | 0/1}]"
9293 , __FILE__, VDefaults, group);
9294 theCommands.Add("vlight",
9295 "tool to manage light sources, without arguments shows list of lights."
9296 "\n Main commands: "
9297 "\n 'clear' to clear lights"
9298 "\n '{def}aults' to load deafault lights"
9299 "\n 'add' (or 'new') <type> to add any light source"
9300 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
9301 "\n 'change' <lightId> to edit light source with specified lightId"
9302 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
9303 "\n {pos}ition X Y Z"
9304 "\n {dir}ection X Y Z (for directional light or for spotlight)"
9305 "\n color colorName"
9306 "\n {head}light 0|1"
9307 "\n {sm}oothness value"
9308 "\n {int}ensity value"
9309 "\n {constAtten}uation value"
9310 "\n {linearAtten}uation value"
9312 "\n {spotexp}onent value"
9314 "\n\n example: vlight add positional head 1 pos 0 1 1 color red"
9315 "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
9316 __FILE__, VLight, group);
9317 theCommands.Add("vraytrace",
9319 "\n\t\t: Turns on/off ray-tracing renderer."
9320 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
9321 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
9322 __FILE__, VRenderParams, group);
9323 theCommands.Add("vrenderparams",
9324 "\n Manages rendering parameters: "
9325 "\n '-raster' Disables GPU ray-tracing"
9326 "\n '-msaa 0..4' Specifies number of samples for MSAA"
9327 "\n '-rayTrace' Enables GPU ray-tracing"
9328 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
9329 "\n '-shadows on|off' Enables/disables shadows rendering"
9330 "\n '-reflections on|off' Enables/disables specular reflections"
9331 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
9332 "\n '-gleam on|off' Enables/disables transparency shadow effects"
9333 "\n '-gi on|off' Enables/disables global illumination effects"
9334 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
9335 "\n '-env on|off' Enables/disables environment map background"
9336 "\n '-shadingModel model' Controls shading model from enumeration"
9337 "\n color, flat, gouraud, phong"
9338 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
9339 "\n Unlike vcaps, these parameters dramatically change visual properties."
9340 "\n Command is intended to control presentation quality depending on"
9341 "\n hardware capabilities and performance.",
9342 __FILE__, VRenderParams, group);
9343 theCommands.Add("vfrustumculling",
9344 "vfrustumculling [toEnable]: enables/disables objects clipping",
9345 __FILE__,VFrustumCulling,group);
9346 theCommands.Add("vhighlightselected",
9347 "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n"
9348 "Without arguments it shows if highlighting of selected objects is enabled now.",
9349 __FILE__,VHighlightSelected,group);
9350 theCommands.Add ("vplace",
9352 "\n\t\t: Places the point (in pixels) at the center of the window",
9353 __FILE__, VPlace, group);
9354 theCommands.Add("vxrotate",
9356 __FILE__,VXRotate,group);
9359 theCommands.Add("vprogressive",
9361 __FILE__, VProgressiveMode, group);