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_Shape.hxx>
19 #include <AIS_InteractiveObject.hxx>
20 #include <AIS_ListOfInteractive.hxx>
21 #include <AIS_ListIteratorOfListOfInteractive.hxx>
23 #include <Graphic3d_ArrayOfPolylines.hxx>
24 #include <Graphic3d_AspectMarker3d.hxx>
25 #include <Graphic3d_ExportFormat.hxx>
26 #include <Graphic3d_NameOfTextureEnv.hxx>
27 #include <Graphic3d_GraduatedTrihedron.hxx>
28 #include <Graphic3d_TextureEnv.hxx>
29 #include <Graphic3d_TextureParams.hxx>
30 #include <Graphic3d_TypeOfTextureFilter.hxx>
31 #include <Graphic3d_AspectFillArea3d.hxx>
32 #include <ViewerTest.hxx>
33 #include <ViewerTest_AutoUpdater.hxx>
34 #include <ViewerTest_EventManager.hxx>
35 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
36 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
37 #include <Visual3d_View.hxx>
38 #include <Visual3d_ViewManager.hxx>
39 #include <V3d_AmbientLight.hxx>
40 #include <V3d_ColorScale.hxx>
41 #include <V3d_DirectionalLight.hxx>
42 #include <V3d_LayerMgr.hxx>
43 #include <V3d_LayerMgrPointer.hxx>
44 #include <V3d_PositionalLight.hxx>
45 #include <V3d_SpotLight.hxx>
46 #include <NCollection_DoubleMap.hxx>
47 #include <NCollection_List.hxx>
48 #include <NCollection_Vector.hxx>
49 #include <AIS_InteractiveContext.hxx>
50 #include <Draw_Interpretor.hxx>
52 #include <Draw_Appli.hxx>
53 #include <Aspect_PrintAlgo.hxx>
54 #include <Image_AlienPixMap.hxx>
55 #include <OpenGl_GraphicDriver.hxx>
56 #include <OSD_Timer.hxx>
57 #include <TColStd_HSequenceOfAsciiString.hxx>
58 #include <TColStd_SequenceOfInteger.hxx>
59 #include <TColStd_HSequenceOfReal.hxx>
60 #include <TColgp_Array1OfPnt2d.hxx>
61 #include <TColStd_MapOfAsciiString.hxx>
62 #include <Visual3d_LayerItem.hxx>
63 #include <Aspect_TypeOfLine.hxx>
64 #include <Image_Diff.hxx>
65 #include <Aspect_DisplayConnection.hxx>
69 #include <PrsMgr_PresentableObject.hxx>
70 #include <Graphic3d_ClipPlane.hxx>
71 #include <NCollection_DataMap.hxx>
72 #include <Graphic3d_Texture2Dmanual.hxx>
73 #include <Prs3d_ShadingAspect.hxx>
74 #include <Prs3d_Drawer.hxx>
75 #include <Prs3d_LineAspect.hxx>
76 #include <Prs3d_Root.hxx>
82 #include <Visual3d_Layer.hxx>
86 #include <WNT_WClass.hxx>
87 #include <WNT_Window.hxx>
90 #define _CRT_SECURE_NO_DEPRECATE
91 #pragma warning (disable:4996)
93 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
94 #include <Cocoa_Window.hxx>
96 #include <Xw_Window.hxx>
97 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
98 #include <X11/Xutil.h>
102 inline Standard_Boolean parseOnOff (Standard_CString theArg,
103 Standard_Boolean& theIsOn)
105 TCollection_AsciiString aFlag (theArg);
110 theIsOn = Standard_True;
111 return Standard_True;
113 else if (aFlag == "off"
116 theIsOn = Standard_False;
117 return Standard_True;
119 return Standard_False;
122 // Auxiliary definitions
123 static const char THE_KEY_DELETE = 127;
125 //==============================================================================
126 // VIEWER GLOBAL VARIABLES
127 //==============================================================================
129 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
130 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
132 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
133 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
135 extern int VErase (Draw_Interpretor& theDI,
136 Standard_Integer theArgNb,
137 const char** theArgVec);
140 static Handle(WNT_Window)& VT_GetWindow() {
141 static Handle(WNT_Window) WNTWin;
144 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
145 static Handle(Cocoa_Window)& VT_GetWindow()
147 static Handle(Cocoa_Window) aWindow;
150 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
151 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
152 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
155 static Handle(Xw_Window)& VT_GetWindow(){
156 static Handle(Xw_Window) XWWin;
160 static void VProcessEvents(ClientData,int);
163 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
165 static Handle(Aspect_DisplayConnection) aDisplayConnection;
166 return aDisplayConnection;
169 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
171 GetDisplayConnection() = theDisplayConnection;
174 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
175 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
177 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
179 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
180 if (!aWindow.IsNull())
181 return aWindow->HWindow();
182 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
183 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
184 if (!aWindow.IsNull())
185 return aWindow->XWindow();
187 return aWindowHandle;
191 static Standard_Boolean MyHLRIsOn = Standard_False;
193 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
194 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
195 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
196 static OpenGl_Caps ViewerTest_myDefaultCaps;
198 #define ZCLIPWIDTH 1.
200 static void OSWindowSetup();
204 Quantity_Color FlatColor;
205 Quantity_Color GradientColor1;
206 Quantity_Color GradientColor2;
207 Aspect_GradientFillMethod FillMethod;
208 } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
210 //==============================================================================
211 // EVENT GLOBAL VARIABLES
212 //==============================================================================
214 static int Start_Rot = 0;
215 static int ZClipIsOn = 0;
216 int X_Motion = 0; // Current cursor position
218 int X_ButtonPress = 0; // Last ButtonPress position
219 int Y_ButtonPress = 0;
220 Standard_Boolean IsDragged = Standard_False;
221 Standard_Boolean DragFirst = Standard_False;
223 //==============================================================================
226 static LRESULT WINAPI ViewerWindowProc(
231 static LRESULT WINAPI AdvViewerWindowProc(
239 //==============================================================================
242 //==============================================================================
244 const Handle(MMgt_TShared)& ViewerTest::WClass()
246 static Handle(MMgt_TShared) theWClass;
248 if (theWClass.IsNull())
250 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
251 CS_VREDRAW | CS_HREDRAW, 0, 0,
252 ::LoadCursor (NULL, IDC_ARROW));
258 //==============================================================================
259 //function : CreateName
260 //purpose : Create numerical name for new object in theMap
261 //==============================================================================
262 template <typename ObjectType>
263 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
264 const TCollection_AsciiString& theDefaultString)
266 if (theObjectMap.IsEmpty())
267 return theDefaultString + TCollection_AsciiString(1);
269 Standard_Integer aNextKey = 1;
270 Standard_Boolean isFound = Standard_False;
273 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
274 // Look for objects with default names
275 if (theObjectMap.IsBound1(aStringKey))
280 isFound = Standard_True;
283 return theDefaultString + TCollection_AsciiString(aNextKey);
286 //==============================================================================
287 //structure : ViewerTest_Names
288 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
289 //==============================================================================
290 struct ViewerTest_Names
293 TCollection_AsciiString myDriverName;
294 TCollection_AsciiString myViewerName;
295 TCollection_AsciiString myViewName;
299 const TCollection_AsciiString& GetDriverName () const
303 void SetDriverName (const TCollection_AsciiString& theDriverName)
305 myDriverName = theDriverName;
307 const TCollection_AsciiString& GetViewerName () const
311 void SetViewerName (const TCollection_AsciiString& theViewerName)
313 myViewerName = theViewerName;
315 const TCollection_AsciiString& GetViewName () const
319 void SetViewName (const TCollection_AsciiString& theViewName)
321 myViewName = theViewName;
324 //===========================================================================
325 //function : Constructor for ViewerTest_Names
326 //purpose : Get view, viewer, driver names from custom string
327 //===========================================================================
329 ViewerTest_Names (const TCollection_AsciiString& theInputString)
331 TCollection_AsciiString aName(theInputString);
332 if (theInputString.IsEmpty())
334 // Get current configuration
335 if (ViewerTest_myDrivers.IsEmpty())
336 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
337 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
339 myDriverName = ViewerTest_myDrivers.Find2
340 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
342 if(ViewerTest_myContexts.IsEmpty())
344 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
345 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
348 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
350 myViewName = CreateName <Handle(V3d_View)>
351 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
355 // There is at least view name
356 Standard_Integer aParserNumber = 0;
357 for (Standard_Integer i = 0; i < 3; ++i)
359 Standard_Integer aParserPos = aName.SearchFromEnd("/");
363 aName.Split(aParserPos-1);
368 if (aParserNumber == 0)
371 if (!ViewerTest::GetAISContext().IsNull())
373 myDriverName = ViewerTest_myDrivers.Find2
374 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
375 myViewerName = ViewerTest_myContexts.Find2
376 (ViewerTest::GetAISContext());
380 // There is no opened contexts here, need to create names for viewer and driver
381 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
382 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
384 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
385 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
387 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
389 else if (aParserNumber == 1)
391 // Here is viewerName/viewName
392 if (!ViewerTest::GetAISContext().IsNull())
393 myDriverName = ViewerTest_myDrivers.Find2
394 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
397 // There is no opened contexts here, need to create name for driver
398 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
399 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
401 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
403 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
407 //Here is driverName/viewerName/viewName
408 myDriverName = TCollection_AsciiString(aName);
410 TCollection_AsciiString aViewerName(theInputString);
411 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
412 myViewerName = TCollection_AsciiString(aViewerName);
414 myViewName = TCollection_AsciiString(theInputString);
420 //==============================================================================
421 //function : FindContextByView
422 //purpose : Find AIS_InteractiveContext by View
423 //==============================================================================
425 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
427 Handle(AIS_InteractiveContext) anAISContext;
429 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
430 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
432 if (anIter.Value()->CurrentViewer() == theView->Viewer())
433 return anIter.Key2();
439 //==============================================================================
440 //function : SetWindowTitle
441 //purpose : Set window title
442 //==============================================================================
444 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
445 Standard_CString theTitle)
448 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
450 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
451 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
453 if(GetDisplayConnection()->GetDisplay())
456 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
457 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
462 //==============================================================================
463 //function : IsWindowOverlapped
464 //purpose : Check if theWindow overlapp another view
465 //==============================================================================
467 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
468 const Standard_Integer thePxTop,
469 const Standard_Integer thePxRight,
470 const Standard_Integer thePxBottom,
471 TCollection_AsciiString& theViewId)
473 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
474 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
476 Standard_Integer aTop = 0,
480 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
481 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
482 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
483 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
484 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
486 theViewId = anIter.Key1();
487 return Standard_True;
490 return Standard_False;
493 // Workaround: to create and delete non-orthographic views outside ViewerTest
494 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
496 ViewerTest_myViews.UnBind1 (theName);
499 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
500 const Handle(V3d_View)& theView)
502 ViewerTest_myViews.Bind (theName, theView);
505 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
507 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
509 //==============================================================================
510 //function : ViewerInit
511 //purpose : Create the window viewer and initialize all the global variable
512 //==============================================================================
514 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
515 const Standard_Integer thePxTop,
516 const Standard_Integer thePxWidth,
517 const Standard_Integer thePxHeight,
518 Standard_CString theViewName,
519 Standard_CString theDisplayName)
521 // Default position and dimension of the viewer window.
522 // Note that left top corner is set to be sufficiently small to have
523 // window fit in the small screens (actual for remote desktops, see #23003).
524 // The position corresponds to the window's client area, thus some
525 // gap is added for window frame to be visible.
526 Standard_Integer aPxLeft = 20;
527 Standard_Integer aPxTop = 40;
528 Standard_Integer aPxWidth = 409;
529 Standard_Integer aPxHeight = 409;
530 Standard_Boolean toCreateViewer = Standard_False;
532 Handle(OpenGl_GraphicDriver) aGraphicDriver;
533 ViewerTest_Names aViewNames(theViewName);
534 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
535 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
542 aPxWidth = thePxWidth;
543 if (thePxHeight != 0)
544 aPxHeight = thePxHeight;
546 // Get graphic driver (create it or get from another view)
547 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
549 // Get connection string
550 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
551 TCollection_AsciiString aDisplayName(theDisplayName);
552 if (!aDisplayName.IsEmpty())
553 SetDisplayConnection (new Aspect_DisplayConnection ());
555 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
557 (void)theDisplayName; // avoid warning on unused argument
558 SetDisplayConnection (new Aspect_DisplayConnection ());
560 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
561 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
562 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
563 toCreateViewer = Standard_True;
567 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
570 //Dispose the window if input parameters are default
571 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
573 Standard_Integer aTop = 0,
580 // Get screen resolution
581 #if defined(_WIN32) || defined(__WIN32__)
583 GetClientRect(GetDesktopWindow(), &aWindowSize);
584 aScreenHeight = aWindowSize.bottom;
585 aScreenWidth = aWindowSize.right;
586 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
587 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
589 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
590 aScreenWidth = WidthOfScreen(aScreen);
591 aScreenHeight = HeightOfScreen(aScreen);
594 TCollection_AsciiString anOverlappedViewId("");
596 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
598 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
600 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
601 && aRight + 2*aPxWidth + 40 > aScreenWidth)
603 if (aBottom + aPxHeight + 40 > aScreenHeight)
610 aPxTop = aBottom + 40;
613 aPxLeft = aRight + 20;
618 TCollection_AsciiString aTitle("3D View - ");
619 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
621 // Change name of current active window
622 if (!ViewerTest::CurrentView().IsNull())
624 TCollection_AsciiString aTitle("3D View - ");
626 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
627 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
631 Handle(V3d_Viewer) a3DViewer;
632 // If it's the single view, we first look for empty context
633 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
635 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
636 anIter(ViewerTest_myContexts);
638 ViewerTest::SetAISContext (anIter.Value());
639 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
641 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
643 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
644 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
646 else if (a3DViewer.IsNull())
648 toCreateViewer = Standard_True;
649 TCollection_ExtendedString NameOfWindow("Viewer3D");
650 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
651 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
652 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
653 ViewerTest_DefaultBackground.GradientColor2,
654 ViewerTest_DefaultBackground.FillMethod);
658 if (ViewerTest::GetAISContext().IsNull() ||
659 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
661 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
662 ViewerTest::SetAISContext (aContext);
663 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
667 ViewerTest::ResetEventManager();
672 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
673 Handle(WNT_WClass)::DownCast (WClass()),
674 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
678 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
679 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
681 aPxWidth, aPxHeight);
682 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
684 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
687 aPxWidth, aPxHeight);
689 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
692 Handle(V3d_View) aView = a3DViewer->CreateView();
693 aView->SetWindow (VT_GetWindow());
694 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
696 ViewerTest::CurrentView(aView);
697 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
699 // Setup for X11 or NT
702 // Set parameters for V3d_View and V3d_Viewer
703 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
704 aV3dView->SetComputedMode(Standard_False);
705 MyHLRIsOn = aV3dView->ComputedMode();
706 aV3dView->SetZClippingDepth(0.5);
707 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
709 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
712 a3DViewer->SetDefaultLights();
713 a3DViewer->SetLightOn();
716 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
717 #if TCL_MAJOR_VERSION < 8
718 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
719 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
721 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
722 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
726 VT_GetWindow()->Map();
728 // Set the handle of created view in the event manager
729 ViewerTest::ResetEventManager();
731 ViewerTest::CurrentView()->Redraw();
736 return aViewNames.GetViewName();
739 //==============================================================================
740 //function : RedrawAllViews
741 //purpose : Redraw all created views
742 //==============================================================================
743 void ViewerTest::RedrawAllViews()
745 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
746 for (; aViewIt.More(); aViewIt.Next())
748 const Handle(V3d_View)& aView = aViewIt.Key2();
753 //==============================================================================
755 //purpose : Create the window viewer and initialize all the global variable
756 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
757 //==============================================================================
759 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
763 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
764 << "Type help for more information.\n";
768 TCollection_AsciiString aViewName, aDisplayName;
769 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
770 TCollection_AsciiString aName, aValue;
771 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
773 const TCollection_AsciiString anArg = theArgVec[anArgIt];
774 TCollection_AsciiString anArgCase = anArg;
775 anArgCase.UpperCase();
776 if (ViewerTest::SplitParameter (anArg, aName, aValue))
779 if (aName.IsEqual ("NAME"))
783 else if (aName.IsEqual ("L")
784 || aName.IsEqual ("LEFT"))
786 aPxLeft = aValue.IntegerValue();
788 else if (aName.IsEqual ("T")
789 || aName.IsEqual ("TOP"))
791 aPxTop = aValue.IntegerValue();
793 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
794 else if (aName.IsEqual ("DISP")
795 || aName.IsEqual ("DISPLAY"))
797 aDisplayName = aValue;
800 else if (aName.IsEqual ("W")
801 || aName.IsEqual ("WIDTH"))
803 aPxWidth = aValue.IntegerValue();
805 else if (aName.IsEqual ("H")
806 || aName.IsEqual ("HEIGHT"))
808 aPxHeight = aValue.IntegerValue();
812 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
815 else if (aViewName.IsEmpty())
821 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
825 ViewerTest_Names aViewNames (aViewName);
826 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
828 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
829 theDi.Eval (aCommand.ToCString());
833 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
834 aViewName.ToCString(),
835 aDisplayName.ToCString());
840 //==============================================================================
842 //purpose : hidden lines removal algorithm
843 //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}]
844 //==============================================================================
846 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
848 if (ViewerTest::CurrentView().IsNull())
850 di << argv[0] << ": Call vinit before this command, please.\n";
856 di << argv[0] << ": Wrong number of command arguments.\n"
857 << "Type help " << argv[0] << " for more information.\n";
861 // Enable or disable HLR mode.
862 Standard_Boolean isHLROn =
863 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
865 if (isHLROn != MyHLRIsOn)
868 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
871 // Show or hide hidden lines in HLR mode.
872 Standard_Boolean isCurrentShowHidden
873 = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine();
875 Standard_Boolean isShowHidden =
876 (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False)
877 : isCurrentShowHidden;
880 if (isShowHidden != isCurrentShowHidden)
884 ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine();
888 ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine();
894 AIS_ListOfInteractive aListOfShapes;
895 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
897 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
899 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value());
904 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
909 ViewerTest::CurrentView()->Update();
913 //==============================================================================
914 //function : VHLRType
915 //purpose : change type of using HLR algorithm
916 //==============================================================================
918 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
920 if (ViewerTest::CurrentView().IsNull())
922 di << argv[0] << ": Call vinit before this command, please.\n";
928 di << argv[0] << ": Wrong number of command arguments.\n"
929 << "Type help " << argv[0] << " for more information.\n";
933 Prs3d_TypeOfHLR aTypeOfHLR =
934 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
938 AIS_ListOfInteractive aListOfShapes;
939 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
940 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
941 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
942 anIter.More(); anIter.Next())
944 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
947 if (aShape->TypeOfHLR() != aTypeOfHLR)
948 aShape->SetTypeOfHLR (aTypeOfHLR);
950 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
952 ViewerTest::CurrentView()->Update();
957 for (Standard_Integer i = 2; i < argc; ++i)
959 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
960 TCollection_AsciiString aName (argv[i]);
962 if (!aMap.IsBound2 (aName))
964 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
967 Handle(AIS_Shape) anAISObject =
968 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
969 if (anAISObject.IsNull())
971 anAISObject->SetTypeOfHLR (aTypeOfHLR);
973 ViewerTest::GetAISContext()->Redisplay (anAISObject, Standard_False);
975 ViewerTest::CurrentView()->Update();
981 //==============================================================================
982 //function : FindViewIdByWindowHandle
983 //purpose : Find theView Id in the map of views by window handle
984 //==============================================================================
985 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
986 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
988 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
989 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
991 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
992 if (aWindowHandle == theWindowHandle)
993 return anIter.Key1();
995 return TCollection_AsciiString("");
999 //==============================================================================
1000 //function : ActivateView
1001 //purpose : Make the view active
1002 //==============================================================================
1004 void ActivateView (const TCollection_AsciiString& theViewName)
1006 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1007 if (!aView.IsNull())
1009 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1010 if (!anAISContext.IsNull())
1012 if (!ViewerTest::CurrentView().IsNull())
1014 TCollection_AsciiString aTitle("3D View - ");
1015 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1016 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1019 ViewerTest::CurrentView (aView);
1020 // Update degenerate mode
1021 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
1022 ViewerTest::SetAISContext (anAISContext);
1023 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
1024 aTitle = aTitle + theViewName + "(*)";
1025 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1026 #if defined(_WIN32) || defined(__WIN32__)
1027 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1028 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1029 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1031 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1033 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1034 ViewerTest::CurrentView()->Redraw();
1039 //==============================================================================
1040 //function : RemoveView
1042 //==============================================================================
1043 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1044 const Standard_Boolean theToRemoveContext)
1046 if (!ViewerTest_myViews.IsBound2 (theView))
1051 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1052 RemoveView (aViewName, theToRemoveContext);
1055 //==============================================================================
1056 //function : RemoveView
1057 //purpose : Close and remove view from display, clear maps if neccessary
1058 //==============================================================================
1059 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1061 if (!ViewerTest_myViews.IsBound1(theViewName))
1063 cout << "Wrong view name\n";
1067 // Activate another view if it's active now
1068 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1070 if (ViewerTest_myViews.Extent() > 1)
1072 TCollection_AsciiString aNewViewName;
1073 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
1074 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1075 if (anIter.Key1() != theViewName)
1077 aNewViewName = anIter.Key1();
1080 ActivateView (aNewViewName);
1084 Handle(V3d_View) anEmptyView;
1085 #if defined(_WIN32) || defined(__WIN32__)
1086 Handle(WNT_Window) anEmptyWindow;
1087 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1088 Handle(Cocoa_Window) anEmptyWindow;
1090 Handle(Xw_Window) anEmptyWindow;
1092 VT_GetWindow() = anEmptyWindow;
1093 ViewerTest::CurrentView (anEmptyView);
1094 if (isContextRemoved)
1096 Handle(AIS_InteractiveContext) anEmptyContext;
1097 ViewerTest::SetAISContext(anEmptyContext);
1103 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1104 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1106 // Remove view resources
1107 ViewerTest_myViews.UnBind1(theViewName);
1110 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1111 XFlush (GetDisplayConnection()->GetDisplay());
1114 // Keep context opened only if the closed view is last to avoid
1115 // unused empty contexts
1116 if (!aCurrentContext.IsNull())
1118 // Check if there are more difined views in the viewer
1119 aCurrentContext->CurrentViewer()->InitDefinedViews();
1120 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1122 // Remove driver if there is no viewers that use it
1123 Standard_Boolean isRemoveDriver = Standard_True;
1124 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1125 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1127 if (aCurrentContext != anIter.Key2() &&
1128 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1130 isRemoveDriver = Standard_False;
1136 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1137 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1138 #if TCL_MAJOR_VERSION < 8
1139 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1141 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1146 ViewerTest_myContexts.UnBind2(aCurrentContext);
1149 cout << "3D View - " << theViewName << " was deleted.\n";
1153 //==============================================================================
1155 //purpose : Remove the view defined by its name
1156 //==============================================================================
1158 static int VClose (Draw_Interpretor& /*theDi*/,
1159 Standard_Integer theArgsNb,
1160 const char** theArgVec)
1162 NCollection_List<TCollection_AsciiString> aViewList;
1165 TCollection_AsciiString anArg (theArgVec[1]);
1167 if (anArg.IsEqual ("ALL")
1168 || anArg.IsEqual ("*"))
1170 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1171 anIter.More(); anIter.Next())
1173 aViewList.Append (anIter.Key1());
1175 if (aViewList.IsEmpty())
1177 std::cout << "No view to close\n";
1183 ViewerTest_Names aViewName (theArgVec[1]);
1184 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1186 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1189 aViewList.Append (aViewName.GetViewName());
1194 // close active view
1195 if (ViewerTest::CurrentView().IsNull())
1197 std::cerr << "No active view!\n";
1200 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1203 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1204 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1205 anIter.More(); anIter.Next())
1207 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1213 //==============================================================================
1214 //function : VActivate
1215 //purpose : Activate the view defined by its ID
1216 //==============================================================================
1218 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1222 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1223 << "Usage: " << theArgVec[0] << " ViewID\n";
1228 theDi.Eval("vviewlist");
1232 TCollection_AsciiString aNameString(theArgVec[1]);
1233 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1235 TCollection_AsciiString aTitle("3D View - ");
1236 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1237 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1238 Handle(V3d_View) anEmptyView;
1239 #if defined(_WIN32) || defined(__WIN32__)
1240 Handle(WNT_Window) anEmptyWindow;
1241 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1242 Handle(Cocoa_Window) anEmptyWindow;
1244 Handle(Xw_Window) anEmptyWindow;
1246 VT_GetWindow() = anEmptyWindow;
1247 ViewerTest::CurrentView (anEmptyView);
1248 ViewerTest::ResetEventManager();
1249 theDi << theArgVec[0] << ": all views are inactive\n";
1253 ViewerTest_Names aViewNames(aNameString);
1255 // Check if this view exists in the viewer with the driver
1256 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1258 theDi << "Wrong view name\n";
1262 // Check if it is active already
1263 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1265 theDi << theArgVec[0] << ": the view is active already\n";
1269 ActivateView (aViewNames.GetViewName());
1273 //==============================================================================
1274 //function : VViewList
1275 //purpose : Print current list of views per viewer and graphic driver ID
1276 // shared between viewers
1277 //==============================================================================
1279 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1283 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1284 << "Usage: " << theArgVec[0] << " name";
1287 if (ViewerTest_myContexts.Size() < 1)
1290 Standard_Boolean isTreeView =
1291 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1294 theDi << theArgVec[0] <<":\n";
1296 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1297 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1300 theDi << aDriverIter.Key1() << ":\n";
1302 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1303 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1305 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1309 TCollection_AsciiString aContextName(aContextIter.Key1());
1310 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1313 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1314 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1316 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1318 TCollection_AsciiString aViewName(aViewIter.Key1());
1321 if (aViewIter.Value() == ViewerTest::CurrentView())
1322 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1324 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1328 theDi << aViewName << " ";
1338 //==============================================================================
1339 //function : VT_ProcessKeyPress
1340 //purpose : Handle KeyPress event from a CString
1341 //==============================================================================
1342 void VT_ProcessKeyPress (const char* buf_ret)
1344 //cout << "KeyPress" << endl;
1345 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1346 // Letter in alphabetic order
1348 if (!strcasecmp (buf_ret, "A"))
1351 aView->SetProj(V3d_XposYnegZpos);
1353 else if (!strcasecmp (buf_ret, "D"))
1358 else if (!strcasecmp (buf_ret, "F"))
1360 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1362 ViewerTest::GetAISContext()->FitSelected (aView);
1370 else if (!strcasecmp (buf_ret, "H"))
1373 cout << "HLR" << endl;
1374 aView->SetComputedMode (!aView->ComputedMode());
1375 MyHLRIsOn = aView->ComputedMode();
1377 else if (!strcasecmp (buf_ret, "P"))
1380 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1381 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1382 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1384 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1385 if (aContext->NbSelected()==0)
1387 AIS_ListOfInteractive aListOfShapes;
1388 aContext->DisplayedObjects(aListOfShapes);
1389 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1390 anIter.More(); anIter.Next())
1392 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1393 if (aShape.IsNull())
1395 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1396 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1398 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1399 aContext->Redisplay (aShape, Standard_False);
1404 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
1406 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
1407 if (aShape.IsNull())
1409 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1410 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1412 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1413 aContext->Redisplay (aShape, Standard_False);
1417 aContext->UpdateCurrentViewer();
1420 else if (!strcasecmp (buf_ret, "S"))
1422 std::cout << "setup Shaded display mode" << std::endl;
1424 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1425 if(Ctx->NbSelected()==0)
1426 Ctx->SetDisplayMode(AIS_Shaded);
1428 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1429 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
1430 Ctx->UpdateCurrentViewer();
1433 else if (!strcasecmp (buf_ret, "U"))
1435 // Unset display mode
1436 std::cout << "reset display mode to defaults" << std::endl;
1438 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1439 if(Ctx->NbSelected()==0)
1440 Ctx->SetDisplayMode(AIS_WireFrame);
1442 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1443 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
1444 Ctx->UpdateCurrentViewer();
1448 else if (!strcasecmp (buf_ret, "T"))
1451 aView->SetProj(V3d_Zpos);
1453 else if (!strcasecmp (buf_ret, "B"))
1456 aView->SetProj(V3d_Zneg);
1458 else if (!strcasecmp (buf_ret, "L"))
1461 aView->SetProj(V3d_Xneg);
1463 else if (!strcasecmp (buf_ret, "R"))
1466 aView->SetProj(V3d_Xpos);
1468 else if (!strcasecmp (buf_ret, "W"))
1470 std::cout << "setup WireFrame display mode" << std::endl;
1471 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1472 if(Ctx->NbSelected()==0)
1473 Ctx->SetDisplayMode(AIS_WireFrame);
1475 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1476 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
1477 Ctx->UpdateCurrentViewer();
1480 else if (!strcasecmp (buf_ret, "Z"))
1484 cout << "ZClipping OFF" << endl;
1487 aView->SetZClippingType(V3d_OFF);
1491 cout << "ZClipping ON" << endl;
1494 aView->SetZClippingType(V3d_FRONT);
1498 else if (!strcasecmp (buf_ret, ","))
1500 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1502 else if (!strcasecmp (buf_ret, "."))
1504 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1506 else if (!strcasecmp (buf_ret, "/"))
1508 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1509 if (aCamera->IsStereo())
1511 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1515 else if (!strcasecmp (buf_ret, "*"))
1517 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1518 if (aCamera->IsStereo())
1520 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1524 else if (*buf_ret == THE_KEY_DELETE)
1526 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1528 && aCtx->NbSelected() > 0)
1530 Draw_Interprete ("verase");
1536 Standard_Integer Num = Draw::Atoi(buf_ret);
1537 if(Num>=0 && Num<=7)
1538 ViewerTest::StandardModeActivation(Num);
1542 //==============================================================================
1543 //function : VT_ProcessExpose
1544 //purpose : Redraw the View on an Expose Event
1545 //==============================================================================
1546 void VT_ProcessExpose()
1548 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1549 if (!aView3d.IsNull())
1555 //==============================================================================
1556 //function : VT_ProcessConfigure
1557 //purpose : Resize the View on an Configure Event
1558 //==============================================================================
1559 void VT_ProcessConfigure()
1561 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1562 if (aView3d.IsNull())
1567 aView3d->MustBeResized();
1572 //==============================================================================
1573 //function : VT_ProcessButton1Press
1575 //==============================================================================
1576 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1577 const char** theArgVec,
1578 Standard_Boolean theToPick,
1579 Standard_Boolean theIsShift)
1583 Standard_Real X, Y, Z;
1584 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1586 Draw::Set (theArgVec[1], X);
1587 Draw::Set (theArgVec[2], Y);
1588 Draw::Set (theArgVec[3], Z);
1593 ViewerTest::CurrentEventManager()->ShiftSelect();
1597 ViewerTest::CurrentEventManager()->Select();
1600 return Standard_False;
1603 //==============================================================================
1604 //function : VT_ProcessButton1Release
1605 //purpose : End selecting
1606 //==============================================================================
1607 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1611 IsDragged = Standard_False;
1612 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1615 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1616 X_Motion, Y_Motion);
1620 EM->Select (X_ButtonPress, Y_ButtonPress,
1621 X_Motion, Y_Motion);
1626 //==============================================================================
1627 //function : VT_ProcessButton3Press
1628 //purpose : Start Rotation
1629 //==============================================================================
1630 void VT_ProcessButton3Press()
1635 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1637 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1640 //==============================================================================
1641 //function : VT_ProcessButton3Release
1642 //purpose : End rotation
1643 //==============================================================================
1644 void VT_ProcessButton3Release()
1651 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1656 //==============================================================================
1657 //function : ProcessZClipMotion
1659 //==============================================================================
1661 void ProcessZClipMotion()
1663 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1664 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1666 //Quantity_Length VDX, VDY;
1667 //a3DView->Size(VDX,VDY);
1668 //Standard_Real VDZ = a3DView->ZSize();
1669 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1671 Quantity_Length aDx = a3DView->Convert(X_Motion - X_ButtonPress);
1673 // Front = Depth + width/2.
1674 Standard_Real aDepth = 0.5;
1675 Standard_Real aWidth = 0.1;
1676 a3DView->ZClipping(aDepth,aWidth);
1680 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1682 a3DView->SetZClippingDepth(aDepth);
1686 X_ButtonPress = X_Motion;
1687 Y_ButtonPress = Y_Motion;
1691 //==============================================================================
1692 //function : ProcessControlButton1Motion
1694 //==============================================================================
1696 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1697 static void ProcessControlButton1Motion()
1699 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1701 X_ButtonPress = X_Motion;
1702 Y_ButtonPress = Y_Motion;
1706 //==============================================================================
1707 //function : VT_ProcessControlButton2Motion
1709 //==============================================================================
1710 void VT_ProcessControlButton2Motion()
1712 Standard_Integer aDx = X_Motion - X_ButtonPress;
1713 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1715 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1717 ViewerTest::CurrentView()->Pan (aDx, aDy);
1719 X_ButtonPress = X_Motion;
1720 Y_ButtonPress = Y_Motion;
1723 //==============================================================================
1724 //function : VT_ProcessControlButton3Motion
1725 //purpose : Rotation
1726 //==============================================================================
1727 void VT_ProcessControlButton3Motion()
1731 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1735 //==============================================================================
1736 //function : VT_ProcessMotion
1738 //==============================================================================
1739 void VT_ProcessMotion()
1741 //pre-hilights detected objects at mouse position
1743 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1744 EM->MoveTo(X_Motion, Y_Motion);
1748 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1750 Xpix = X_Motion;Ypix=Y_Motion;
1753 //==============================================================================
1754 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1755 //purpose : Switches to an axonometric, top, left and other views
1756 //==============================================================================
1758 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1760 if ( ViewerTest::CurrentView().IsNull() )
1762 di<<"Call vinit before this command, please"<<"\n";
1766 ViewerTest::CurrentView()->SetProj(ori);
1770 //==============================================================================
1772 //purpose : Switch to an Axonometric view
1773 //Draw arg : No args
1774 //==============================================================================
1776 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1778 return ViewProject(di, V3d_XposYnegZpos);
1781 //==============================================================================
1783 //purpose : Switch to a Top View
1784 //Draw arg : No args
1785 //==============================================================================
1787 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1789 return ViewProject(di, V3d_Zpos);
1792 //==============================================================================
1793 //function : VBottom
1794 //purpose : Switch to a Bottom View
1795 //Draw arg : No args
1796 //==============================================================================
1798 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1800 return ViewProject(di, V3d_Zneg);
1803 //==============================================================================
1805 //purpose : Switch to a Left View
1806 //Draw arg : No args
1807 //==============================================================================
1809 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1811 return ViewProject(di, V3d_Ypos);
1814 //==============================================================================
1816 //purpose : Switch to a Right View
1817 //Draw arg : No args
1818 //==============================================================================
1820 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1822 return ViewProject(di, V3d_Yneg);
1825 //==============================================================================
1827 //purpose : Switch to a Front View
1828 //Draw arg : No args
1829 //==============================================================================
1831 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1833 return ViewProject(di, V3d_Xpos);
1836 //==============================================================================
1838 //purpose : Switch to a Back View
1839 //Draw arg : No args
1840 //==============================================================================
1842 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1844 return ViewProject(di, V3d_Xneg);
1847 //==============================================================================
1849 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1850 //Draw arg : No args
1851 //==============================================================================
1853 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1856 di << "Q : Quit the application" << "\n";
1858 di << "========================="<<"\n";
1859 di << "F : FitAll" << "\n";
1860 di << "T : TopView" << "\n";
1861 di << "B : BottomView" << "\n";
1862 di << "R : RightView" << "\n";
1863 di << "L : LeftView" << "\n";
1864 di << "A : AxonometricView" << "\n";
1865 di << "D : ResetView" << "\n";
1867 di << "========================="<<"\n";
1868 di << "S : Shading" << "\n";
1869 di << "W : Wireframe" << "\n";
1870 di << "H : HidelLineRemoval" << "\n";
1871 di << "U : Unset display mode" << "\n";
1872 di << "Delete : Remove selection from viewer" << "\n";
1874 di << "========================="<<"\n";
1875 di << "Selection mode "<<"\n";
1876 di << "0 : Shape" <<"\n";
1877 di << "1 : Vertex" <<"\n";
1878 di << "2 : Edge" <<"\n";
1879 di << "3 : Wire" <<"\n";
1880 di << "4 : Face" <<"\n";
1881 di << "5 : Shell" <<"\n";
1882 di << "6 : Solid" <<"\n";
1883 di << "7 : Compound" <<"\n";
1885 di << "========================="<<"\n";
1886 di << "Z : Switch Z clipping On/Off" << "\n";
1887 di << ", : Hilight next detected" << "\n";
1888 di << ". : Hilight previous detected" << "\n";
1895 static Standard_Boolean Ppick = 0;
1896 static Standard_Integer Pargc = 0;
1897 static const char** Pargv = NULL;
1900 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1905 if (!ViewerTest_myViews.IsEmpty()) {
1907 WPARAM fwKeys = wParam;
1912 // Delete view from map of views
1913 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1918 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1919 || ViewerTest::CurrentView().IsNull())
1921 // Activate inactive window
1922 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1924 ActivateView (FindViewIdByWindowHandle(hwnd));
1931 HDC hdc = GetDC( hwnd );
1932 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1933 SetROP2( hdc, R2_NOT );
1934 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1935 ReleaseDC( hwnd, hdc );
1936 VT_ProcessButton1Release (fwKeys & MK_SHIFT);
1938 IsDragged = Standard_False;
1939 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1941 case WM_LBUTTONDOWN:
1942 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1944 IsDragged = Standard_True;
1945 DragFirst = Standard_True;
1946 X_ButtonPress = LOWORD(lParam);
1947 Y_ButtonPress = HIWORD(lParam);
1949 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1956 HDC hdc = GetDC( hwnd );
1958 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1959 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1960 SetROP2( hdc, R2_NOT );
1963 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1965 DragFirst = Standard_False;
1966 X_Motion = LOWORD(lParam);
1967 Y_Motion = HIWORD(lParam);
1969 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1971 SelectObject( hdc, anObj );
1973 ReleaseDC( hwnd, hdc );
1976 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1980 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1984 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1988 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1994 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
1997 return DefWindowProc( hwnd, Msg, wParam, lParam );
2004 BeginPaint(hwnd, &ps);
2005 EndPaint(hwnd, &ps);
2010 VT_ProcessConfigure();
2015 switch (aView->RenderingParams().StereoMode)
2017 case Graphic3d_StereoMode_RowInterlaced:
2018 case Graphic3d_StereoMode_ColumnInterlaced:
2019 case Graphic3d_StereoMode_ChessBoard:
2020 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2028 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2031 c[0] = (char) wParam;
2033 if (wParam == VK_DELETE)
2035 c[0] = THE_KEY_DELETE;
2038 else if (wParam == VK_OEM_COMMA)
2043 else if (wParam == VK_OEM_PERIOD)
2047 else if (wParam == VK_DIVIDE)
2052 else if (wParam == VK_MULTIPLY)
2056 VT_ProcessKeyPress (c);
2064 VT_ProcessButton3Release();
2067 case WM_LBUTTONDOWN:
2068 case WM_MBUTTONDOWN:
2069 case WM_RBUTTONDOWN:
2071 WPARAM fwKeys = wParam;
2075 X_ButtonPress = LOWORD(lParam);
2076 Y_ButtonPress = HIWORD(lParam);
2078 if (Msg == WM_LBUTTONDOWN)
2080 if (fwKeys & MK_CONTROL)
2082 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2086 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2089 else if (Msg == WM_RBUTTONDOWN)
2092 VT_ProcessButton3Press();
2099 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2100 if (wParam & MK_CONTROL)
2102 if (aView->Camera()->IsStereo())
2104 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2108 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2115 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2122 //cout << "\t WM_MOUSEMOVE" << endl;
2123 WPARAM fwKeys = wParam;
2124 X_Motion = LOWORD(lParam);
2125 Y_Motion = HIWORD(lParam);
2128 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2130 X_ButtonPress = LOWORD(lParam);
2131 Y_ButtonPress = HIWORD(lParam);
2133 if ( fwKeys & MK_RBUTTON ) {
2135 VT_ProcessButton3Press();
2139 if ( fwKeys & MK_CONTROL ) {
2140 if ( fwKeys & MK_LBUTTON ) {
2141 ProcessControlButton1Motion();
2143 else if ( fwKeys & MK_MBUTTON ||
2144 ((fwKeys&MK_LBUTTON) &&
2145 (fwKeys&MK_RBUTTON) ) ){
2146 VT_ProcessControlButton2Motion();
2148 else if ( fwKeys & MK_RBUTTON ) {
2149 VT_ProcessControlButton3Motion();
2153 else if ( fwKeys & MK_SHIFT ) {
2154 if ( fwKeys & MK_MBUTTON ||
2155 ((fwKeys&MK_LBUTTON) &&
2156 (fwKeys&MK_RBUTTON) ) ) {
2157 cout << "ProcessZClipMotion()" << endl;
2158 ProcessZClipMotion();
2162 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2164 if ((fwKeys & MK_MBUTTON
2165 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2167 ProcessZClipMotion();
2178 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2186 //==============================================================================
2187 //function : ViewerMainLoop
2188 //purpose : Get a Event on the view and dispatch it
2189 //==============================================================================
2192 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2194 Ppick = (argc > 0)? 1 : 0;
2202 cout << "Start picking" << endl;
2204 while ( Ppick == 1 ) {
2205 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2206 if (GetMessage(&msg, NULL, 0, 0) ) {
2207 TranslateMessage(&msg);
2208 DispatchMessage(&msg);
2212 cout << "Picking done" << endl;
2218 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2220 int min( int a, int b )
2228 int max( int a, int b )
2236 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2239 static XEvent aReport;
2240 Standard_Boolean pick = argc > 0;
2241 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2242 XNextEvent (aDisplay, &aReport);
2244 // Handle event for the chosen display connection
2245 switch (aReport.type) {
2248 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2251 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2257 // Activate inactive view
2258 Window aWindow = GetWindowHandle(VT_GetWindow());
2259 if(aWindow != aReport.xfocus.window)
2261 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2270 case ConfigureNotify:
2272 VT_ProcessConfigure();
2281 XComposeStatus status_in_out;
2283 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2284 (char *) buf_ret , 10 ,
2285 &ks_ret , &status_in_out ) ;
2288 buf_ret[ret_len] = '\0' ;
2292 VT_ProcessKeyPress (buf_ret);
2298 X_ButtonPress = aReport.xbutton.x;
2299 Y_ButtonPress = aReport.xbutton.y;
2301 if (aReport.xbutton.button == Button1)
2303 if (aReport.xbutton.state & ControlMask)
2305 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2309 IsDragged = Standard_True;
2310 DragFirst = Standard_True;
2313 else if (aReport.xbutton.button == Button3)
2316 VT_ProcessButton3Press();
2326 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2327 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2328 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2331 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2332 if( aContext.IsNull() )
2334 cout << "The context is null. Please use vinit before createmesh" << endl;
2338 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2339 if( aReport.xbutton.button==1 )
2343 aContext->ShiftSelect();
2352 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2353 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2354 ViewerTest::CurrentView());
2358 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2359 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2360 ViewerTest::CurrentView() );
2363 VT_ProcessButton3Release();
2365 IsDragged = Standard_False;
2368 VT_ProcessButton3Release();
2373 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2379 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2380 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2381 XSetFunction( aDisplay, gc, GXinvert );
2384 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2386 X_Motion = aReport.xmotion.x;
2387 Y_Motion = aReport.xmotion.y;
2388 DragFirst = Standard_False;
2390 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2394 X_Motion = aReport.xmotion.x;
2395 Y_Motion = aReport.xmotion.y;
2397 // remove all the ButtonMotionMaskr
2398 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2400 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2401 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2403 Quantity_Length VDX, VDY;
2405 ViewerTest::CurrentView()->Size(VDX,VDY);
2406 Standard_Real VDZ =0 ;
2407 VDZ = ViewerTest::CurrentView()->ZSize();
2409 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2411 Quantity_Length dx = 0 ;
2412 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2416 dx = dx / VDX * VDZ;
2420 ViewerTest::CurrentView()->Redraw();
2424 if ( aReport.xmotion.state & ControlMask ) {
2425 if ( aReport.xmotion.state & Button1Mask ) {
2426 ProcessControlButton1Motion();
2428 else if ( aReport.xmotion.state & Button2Mask ) {
2429 VT_ProcessControlButton2Motion();
2431 else if ( aReport.xmotion.state & Button3Mask ) {
2432 VT_ProcessControlButton3Motion();
2446 //==============================================================================
2447 //function : VProcessEvents
2448 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2449 // event in the Viewer window
2450 //==============================================================================
2452 static void VProcessEvents(ClientData,int)
2454 NCollection_Vector<int> anEventNumbers;
2455 // Get number of messages from every display
2456 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2457 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2459 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2461 // Handle events for every display
2462 int anEventIter = 0;
2463 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2464 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2466 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2467 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2469 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2470 int anEventResult = ViewerMainLoop( 0, NULL);
2471 // If window is closed or context was not found finish current event processing loop
2477 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2482 //==============================================================================
2483 //function : OSWindowSetup
2484 //purpose : Setup for the X11 window to be able to cath the event
2485 //==============================================================================
2488 static void OSWindowSetup()
2490 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2493 Window window = VT_GetWindow()->XWindow();
2494 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2495 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2496 XSynchronize(aDisplay, 1);
2498 // X11 : For keyboard on SUN
2500 wmhints.flags = InputHint;
2503 XSetWMHints( aDisplay, window, &wmhints);
2505 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2506 ButtonPressMask | ButtonReleaseMask |
2507 StructureNotifyMask |
2509 Button1MotionMask | Button2MotionMask |
2510 Button3MotionMask | FocusChangeMask
2512 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2513 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2515 XSynchronize(aDisplay, 0);
2523 //==============================================================================
2526 //purpose : Fitall, no DRAW arguments
2527 //Draw arg : No args
2528 //==============================================================================
2530 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgc, const char** theArgv)
2534 std::cout << "Wrong number of arguments! Use: vfit [-selected]" << std::endl;
2537 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2541 TCollection_AsciiString anArg (theArgv[1]);
2543 if (anArg == "-selected")
2545 ViewerTest::GetAISContext()->FitSelected (aView);
2549 if (aView.IsNull() == Standard_False) {
2556 //=======================================================================
2557 //function : VFitArea
2558 //purpose : Fit view to show area located between two points
2559 // : given in world 2D or 3D coordinates.
2560 //=======================================================================
2561 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2563 Handle(V3d_View) aView = ViewerTest::CurrentView();
2566 std::cerr << theArgVec[0] << "Error: No active view.\n";
2571 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2572 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2576 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2577 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2578 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2579 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2581 else if (theArgNb == 7)
2583 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2584 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2585 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2586 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2587 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2588 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2592 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2593 theDI.PrintHelp(theArgVec[0]);
2597 // Convert model coordinates to view space
2598 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2599 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2600 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2602 // Determine fit area
2603 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2604 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2606 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2608 if (aDiagonal < Precision::Confusion())
2610 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2614 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2618 //==============================================================================
2620 //purpose : ZFitall, no DRAW arguments
2621 //Draw arg : No args
2622 //==============================================================================
2623 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2625 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2627 if (aCurrentView.IsNull())
2629 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2635 aCurrentView->View()->ZFitAll();
2636 aCurrentView->Redraw();
2640 Standard_Real aScale = 1.0;
2644 aScale = Draw::Atoi (theArgVec[1]);
2647 aCurrentView->View()->ZFitAll (aScale);
2648 aCurrentView->Redraw();
2653 //==============================================================================
2654 //function : VRepaint
2656 //==============================================================================
2657 static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
2659 Handle(V3d_View) V = ViewerTest::CurrentView();
2660 if ( !V.IsNull() ) V->Redraw(); return 0;
2663 //==============================================================================
2665 //purpose : Remove all the object from the viewer
2666 //Draw arg : No args
2667 //==============================================================================
2669 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2671 Handle(V3d_View) V = ViewerTest::CurrentView();
2673 ViewerTest::Clear();
2677 //==============================================================================
2680 //==============================================================================
2682 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2683 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2686 di << argv[0] << "Invalid number of arguments" << "\n";
2690 while (ViewerMainLoop( argc, argv)) {
2696 //==============================================================================
2698 //purpose : Load image as background
2699 //==============================================================================
2701 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2703 if (argc < 2 || argc > 3)
2705 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2706 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2710 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2711 if(AISContext.IsNull())
2713 di << "use 'vinit' command before " << argv[0] << "\n";
2717 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2720 const char* szType = argv[2];
2721 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2722 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2723 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2724 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2727 di << "Wrong fill type : " << szType << "\n";
2728 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2733 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2734 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2739 //==============================================================================
2740 //function : VSetBgMode
2741 //purpose : Change background image fill type
2742 //==============================================================================
2744 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2748 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2749 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2753 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2754 if(AISContext.IsNull())
2756 di << "use 'vinit' command before " << argv[0] << "\n";
2759 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2760 const char* szType = argv[1];
2761 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2762 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2763 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2764 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2767 di << "Wrong fill type : " << szType << "\n";
2768 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2771 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2772 V3dView->SetBgImageStyle(aFillType, Standard_True);
2776 //==============================================================================
2777 //function : VSetGradientBg
2778 //purpose : Mount gradient background
2779 //==============================================================================
2780 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2784 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2785 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2786 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2787 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2791 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2792 if(AISContext.IsNull())
2794 di << "use 'vinit' command before " << argv[0] << "\n";
2800 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2801 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2802 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2803 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2805 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2806 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2807 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2809 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2810 int aType = Draw::Atoi(argv[7]);
2811 if( aType < 0 || aType > 8 )
2813 di << "Wrong fill type " << "\n";
2814 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2815 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2819 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2821 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2822 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2828 //==============================================================================
2829 //function : VSetGradientBgMode
2830 //purpose : Change gradient background fill style
2831 //==============================================================================
2832 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2836 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2837 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2838 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2842 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2843 if(AISContext.IsNull())
2845 di << "use 'vinit' command before " << argv[0] << "\n";
2850 int aType = Draw::Atoi(argv[1]);
2851 if( aType < 0 || aType > 8 )
2853 di << "Wrong fill type " << "\n";
2854 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2855 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2859 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2861 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2862 V3dView->SetBgGradientStyle( aMethod, 1 );
2868 //==============================================================================
2869 //function : VSetColorBg
2870 //purpose : Set color background
2871 //==============================================================================
2872 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2876 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2877 di << "R,G,B = [0..255]" << "\n";
2881 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2882 if(AISContext.IsNull())
2884 di << "use 'vinit' command before " << argv[0] << "\n";
2890 Standard_Real R = Draw::Atof(argv[1])/255.;
2891 Standard_Real G = Draw::Atof(argv[2])/255.;
2892 Standard_Real B = Draw::Atof(argv[3])/255.;
2893 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2895 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2896 V3dView->SetBackgroundColor( aColor );
2903 //==============================================================================
2904 //function : VSetDefaultBg
2905 //purpose : Set default viewer background fill color
2906 //==============================================================================
2907 static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2912 std::cout << "Error: wrong syntax! See usage:\n";
2913 theDI.PrintHelp (theArgVec[0]);
2917 ViewerTest_DefaultBackground.FillMethod =
2918 theArgNb == 4 ? Aspect_GFM_NONE
2919 : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]);
2923 Standard_Real R = Draw::Atof (theArgVec[1]) / 255.;
2924 Standard_Real G = Draw::Atof (theArgVec[2]) / 255.;
2925 Standard_Real B = Draw::Atof (theArgVec[3]) / 255.;
2926 ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB);
2930 Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.;
2931 Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.;
2932 Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.;
2933 ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB);
2935 Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.;
2936 Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.;
2937 Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.;
2938 ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB);
2941 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
2942 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
2944 const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer();
2945 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
2946 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
2947 ViewerTest_DefaultBackground.GradientColor2,
2948 ViewerTest_DefaultBackground.FillMethod);
2954 //==============================================================================
2956 //purpose : View Scaling
2957 //==============================================================================
2959 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2961 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2962 if ( V3dView.IsNull() ) return 1;
2965 di << argv[0] << "Invalid number of arguments" << "\n";
2968 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2971 //==============================================================================
2972 //function : VZBuffTrihedron
2974 //==============================================================================
2976 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
2977 Standard_Integer theArgNb,
2978 const char** theArgVec)
2980 Handle(V3d_View) aView = ViewerTest::CurrentView();
2983 std::cout << "Error: no active viewer!\n";
2987 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
2989 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2990 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
2991 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
2992 Quantity_Color anArrowColorX = Quantity_NOC_RED;
2993 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
2994 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
2995 Standard_Real aScale = 0.1;
2996 Standard_Real aSizeRatio = 0.8;
2997 Standard_Real anArrowDiam = 0.05;
2998 Standard_Integer aNbFacets = 12;
2999 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3001 Standard_CString anArg = theArgVec[anArgIter];
3002 TCollection_AsciiString aFlag (anArg);
3004 if (anUpdateTool.parseRedrawMode (aFlag))
3008 else if (aFlag == "-on")
3012 else if (aFlag == "-off")
3014 aView->TriedronErase();
3017 else if (aFlag == "-pos"
3018 || aFlag == "-position"
3019 || aFlag == "-corner")
3021 if (++anArgIter >= theArgNb)
3023 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3027 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3028 aPosName.LowerCase();
3029 if (aPosName == "center")
3031 aPosition = Aspect_TOTP_CENTER;
3033 else if (aPosName == "left_lower"
3034 || aPosName == "lower_left"
3035 || aPosName == "leftlower"
3036 || aPosName == "lowerleft")
3038 aPosition = Aspect_TOTP_LEFT_LOWER;
3040 else if (aPosName == "left_upper"
3041 || aPosName == "upper_left"
3042 || aPosName == "leftupper"
3043 || aPosName == "upperleft")
3045 aPosition = Aspect_TOTP_LEFT_UPPER;
3047 else if (aPosName == "right_lower"
3048 || aPosName == "lower_right"
3049 || aPosName == "rightlower"
3050 || aPosName == "lowerright")
3052 aPosition = Aspect_TOTP_RIGHT_LOWER;
3054 else if (aPosName == "right_upper"
3055 || aPosName == "upper_right"
3056 || aPosName == "rightupper"
3057 || aPosName == "upperright")
3059 aPosition = Aspect_TOTP_RIGHT_UPPER;
3063 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3067 else if (aFlag == "-type")
3069 if (++anArgIter >= theArgNb)
3071 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3075 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3076 aTypeName.LowerCase();
3077 if (aTypeName == "wireframe"
3078 || aTypeName == "wire")
3080 aVisType = V3d_WIREFRAME;
3082 else if (aTypeName == "zbuffer"
3083 || aTypeName == "shaded")
3085 aVisType = V3d_ZBUFFER;
3089 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3092 else if (aFlag == "-scale")
3094 if (++anArgIter >= theArgNb)
3096 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3100 aScale = Draw::Atof (theArgVec[anArgIter]);
3102 else if (aFlag == "-size"
3103 || aFlag == "-sizeratio")
3105 if (++anArgIter >= theArgNb)
3107 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3111 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3113 else if (aFlag == "-arrowdiam"
3114 || aFlag == "-arrowdiameter")
3116 if (++anArgIter >= theArgNb)
3118 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3122 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3124 else if (aFlag == "-nbfacets")
3126 if (++anArgIter >= theArgNb)
3128 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3132 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3134 else if (aFlag == "-colorlabel"
3135 || aFlag == "-colorlabels")
3137 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3138 theArgVec + anArgIter + 1,
3142 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3145 anArgIter += aNbParsed;
3147 else if (aFlag == "-colorarrowx")
3149 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3150 theArgVec + anArgIter + 1,
3154 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3157 anArgIter += aNbParsed;
3159 else if (aFlag == "-colorarrowy")
3161 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3162 theArgVec + anArgIter + 1,
3166 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3169 anArgIter += aNbParsed;
3171 else if (aFlag == "-colorarrowz")
3173 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3174 theArgVec + anArgIter + 1,
3178 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3181 anArgIter += aNbParsed;
3185 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3190 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3191 aSizeRatio, anArrowDiam, aNbFacets);
3192 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
3193 aView->View()->ZFitAll();
3197 //==============================================================================
3198 //function : VRotate
3199 //purpose : Camera Rotating
3200 //==============================================================================
3202 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3204 Handle(V3d_View) aView = ViewerTest::CurrentView();
3207 std::cout << "No active view!\n";
3211 Standard_Boolean hasFlags = Standard_False;
3212 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3214 Standard_CString anArg (theArgVec[anArgIter]);
3215 TCollection_AsciiString aFlag (anArg);
3217 if (aFlag == "-mousestart"
3218 || aFlag == "-mousefrom")
3220 hasFlags = Standard_True;
3221 if (anArgIter + 2 >= theArgNb)
3223 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3227 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3228 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3229 aView->StartRotation (anX, anY);
3231 else if (aFlag == "-mousemove")
3233 hasFlags = Standard_True;
3234 if (anArgIter + 2 >= theArgNb)
3236 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3240 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3241 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3242 aView->Rotation (anX, anY);
3244 else if (theArgNb != 4
3247 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3256 else if (theArgNb == 4)
3258 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3259 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3260 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3261 aView->Rotate (anAX, anAY, anAZ);
3264 else if (theArgNb == 7)
3266 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3267 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3268 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3270 Standard_Real anX = Draw::Atof (theArgVec[4]);
3271 Standard_Real anY = Draw::Atof (theArgVec[5]);
3272 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3274 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3278 std::cout << "Error: Invalid number of arguments\n";
3282 //==============================================================================
3284 //purpose : View zoom in / out (relative to current zoom)
3285 //==============================================================================
3287 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3288 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3289 if ( V3dView.IsNull() ) {
3294 Standard_Real coef = Draw::Atof(argv[1]);
3295 if ( coef <= 0.0 ) {
3296 di << argv[1] << "Invalid value" << "\n";
3299 V3dView->SetZoom( Draw::Atof(argv[1]) );
3302 di << argv[0] << " Invalid number of arguments" << "\n";
3307 //==============================================================================
3309 //purpose : View panning (in pixels)
3310 //==============================================================================
3312 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3313 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3314 if ( V3dView.IsNull() ) return 1;
3317 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
3320 di << argv[0] << " Invalid number of arguments" << "\n";
3325 //==============================================================================
3327 //purpose : Place the point (in pixels) at the center of the window
3328 //==============================================================================
3329 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3331 Handle(V3d_View) aView = ViewerTest::CurrentView();
3334 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3340 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3344 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3349 //==============================================================================
3350 //function : VExport
3351 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
3352 //==============================================================================
3354 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3356 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3357 if (V3dView.IsNull())
3362 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
3366 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
3367 TCollection_AsciiString aFormatStr;
3369 TCollection_AsciiString aFileName (argv[1]);
3370 Standard_Integer aLen = aFileName.Length();
3374 aFormatStr = TCollection_AsciiString (argv[2]);
3378 if (aFileName.Value (aLen - 2) == '.')
3380 aFormatStr = aFileName.ToCString() + aLen - 2;
3382 else if (aFileName.Value (aLen - 3) == '.')
3384 aFormatStr = aFileName.ToCString() + aLen - 3;
3388 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3394 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3398 aFormatStr.UpperCase();
3399 if (aFormatStr == "PS")
3400 anExpFormat = Graphic3d_EF_PostScript;
3401 else if (aFormatStr == "EPS")
3402 anExpFormat = Graphic3d_EF_EnhPostScript;
3403 else if (aFormatStr == "TEX")
3404 anExpFormat = Graphic3d_EF_TEX;
3405 else if (aFormatStr == "PDF")
3406 anExpFormat = Graphic3d_EF_PDF;
3407 else if (aFormatStr == "SVG")
3408 anExpFormat = Graphic3d_EF_SVG;
3409 else if (aFormatStr == "PGF")
3410 anExpFormat = Graphic3d_EF_PGF;
3411 else if (aFormatStr == "EMF")
3412 anExpFormat = Graphic3d_EF_EMF;
3415 std::cout << "Invalid export format '" << aFormatStr << "'\n";
3420 if (!V3dView->View()->Export (argv[1], anExpFormat))
3422 di << "Error: export of image to " << aFormatStr << " failed!\n";
3425 catch (Standard_Failure)
3427 di << "Error: export of image to " << aFormatStr << " failed";
3428 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
3433 //==============================================================================
3434 //function : VColorScale
3435 //purpose : representation color scale
3436 //==============================================================================
3438 static Standard_Boolean checkColor (const TCollection_AsciiString& theRed,
3439 const TCollection_AsciiString& theGreen,
3440 const TCollection_AsciiString& theBlue,
3441 Standard_Real& theRedValue,
3442 Standard_Real& theGreenValue,
3443 Standard_Real& theBlueValue)
3445 if (!theRed.IsRealValue()
3446 || !theGreen.IsRealValue()
3447 || !theBlue.IsRealValue())
3449 std::cout << "Error: RGB color values should be real!\n";
3450 return Standard_True;
3452 theRedValue = theRed .RealValue();
3453 theGreenValue = theGreen.RealValue();
3454 theBlueValue = theBlue .RealValue();
3455 if (theRedValue < 0.0 || theRedValue > 1.0
3456 || theGreenValue < 0.0 || theGreenValue > 1.0
3457 || theBlueValue < 0.0 || theBlueValue > 1.0)
3459 std::cout << "Error: RGB color values should be within range 0..1!\n";
3460 return Standard_True;
3462 return Standard_False;
3465 static int VColorScale (Draw_Interpretor& theDI,
3466 Standard_Integer theArgNb,
3467 const char** theArgVec)
3469 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3470 Handle(V3d_View) aView = ViewerTest::CurrentView();
3471 if (aContext.IsNull())
3473 std::cout << "Error: no active view!\n";
3477 Handle(V3d_ColorScale) aCS = Handle(V3d_ColorScale)::DownCast (aView->ColorScale());
3480 std::cout << "Error: color scale is undefined!\n";
3484 Standard_Real aMinRange = aCS->GetMin();
3485 Standard_Real aMaxRange = aCS->GetMax();
3486 Standard_Integer aNbIntervals = aCS->GetNumberOfIntervals();
3487 Standard_Integer aTextHeight = aCS->GetTextHeight();
3488 Aspect_TypeOfColorScalePosition aLabPosition = aCS->GetLabelPosition();
3489 gp_XY aPos (aCS->GetXPosition(), aCS->GetYPosition());
3491 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
3495 theDI << "Current color scale parameters:\n"
3496 << "Min range: " << aMinRange << "\n"
3497 << "Max range: " << aMaxRange << "\n"
3498 << "Number of intervals: " << aNbIntervals << "\n"
3499 << "Text height: " << aTextHeight << "\n"
3500 << "Color scale position: " << aPos.X() <<" "<< aPos.Y()<< "\n"
3501 << "Color scale title: " << aCS->GetTitle() << "\n"
3502 << "Label position: ";
3503 switch (aLabPosition)
3505 case Aspect_TOCSP_NONE:
3508 case Aspect_TOCSP_LEFT:
3511 case Aspect_TOCSP_RIGHT:
3514 case Aspect_TOCSP_CENTER:
3515 theDI << "Center\n";
3520 Standard_CString aFirstArg = theArgVec[1];
3521 TCollection_AsciiString aFlag (aFirstArg);
3523 if (aFlag == "-hide" ||
3528 std::cout << "Error: wrong syntax at argument '" << theArgVec[1] << "'!\n";
3531 if (!aView->ColorScaleIsDisplayed())
3533 std::cout << "Error: color scale is not displayed!\n";
3538 aView->ColorScaleErase();
3542 else if (aFlag == "-show" ||
3543 aFlag == "-display")
3547 std::cout << "Error: wrong syntax at argument '" << theArgVec[1] << "'!\n";
3550 aView->ColorScaleDisplay();
3554 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3556 Standard_CString anArg = theArgVec[anArgIter];
3557 TCollection_AsciiString aFlag (anArg);
3559 if (anUpdateTool.parseRedrawMode (aFlag))
3563 else if (aFlag == "-range")
3565 if (anArgIter + 3 >= theArgNb)
3567 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3571 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
3572 TCollection_AsciiString anArg2 (theArgVec[++anArgIter]);
3573 TCollection_AsciiString anArg3 (theArgVec[++anArgIter]);
3574 if (!anArg1.IsRealValue())
3576 std::cout << "Error: the minRange value should be real!\n";
3579 else if (!anArg2.IsRealValue())
3581 std::cout << "Error: the maxRange value should be real!\n";
3584 else if (!anArg3.IsIntegerValue())
3586 std::cout << "Error: the number of intervals should be integer!\n";
3590 aMinRange = anArg1.RealValue();
3591 aMaxRange = anArg2.RealValue();
3592 aNbIntervals = anArg3.IntegerValue();
3594 else if (aFlag == "-font")
3596 if (anArgIter + 1 >= theArgNb)
3598 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3601 TCollection_AsciiString anArg (theArgVec[anArgIter + 1]);
3602 if (!anArg.IsIntegerValue())
3604 std::cout << "Error: HeightFont value should be integer!\n";
3608 aTextHeight = anArg.IntegerValue();
3611 else if (aFlag == "-textpos")
3613 if (anArgIter + 1 >= theArgNb)
3615 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3618 TCollection_AsciiString anArg (theArgVec[++anArgIter]);
3620 if (anArg == "none")
3622 aLabPosition = Aspect_TOCSP_NONE;
3624 else if (anArg == "left")
3626 aLabPosition = Aspect_TOCSP_LEFT;
3628 else if (anArg == "right")
3630 aLabPosition = Aspect_TOCSP_RIGHT;
3632 else if (anArg == "center")
3634 aLabPosition = Aspect_TOCSP_CENTER;
3638 std::cout << "Error: unknown position '" << anArg << "'!\n";
3642 else if (aFlag == "-xy")
3644 if (anArgIter + 2 >= theArgNb)
3646 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3650 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3651 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3652 if (!aX.IsRealValue()
3653 || !aY.IsRealValue())
3655 std::cout << "Error: coordinates should be real values!\n";
3659 aPos.SetCoord (aX.RealValue(), aY.RealValue());
3661 else if (aFlag == "-color")
3663 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3665 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3669 Quantity_NameOfColor aColorName;
3670 if (anArgIter + 4 >= theArgNb)
3672 if (anArgIter + 2 >= theArgNb)
3674 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3677 else if (!Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3679 std::cout << "Error: wrong color name: '" << theArgVec[anArgIter + 2] << "' !\n";
3684 TCollection_AsciiString anInd (theArgVec[anArgIter + 1]);
3685 if (!anInd.IsIntegerValue())
3687 std::cout << "Error: Index value should be integer!\n";
3691 Standard_Integer anIndex = anInd.IntegerValue();
3693 || anIndex > aNbIntervals - 1)
3695 std::cout << "Error: Index value should be within range 0..." << (aNbIntervals - 1) <<"!\n";
3699 if (Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3701 aCS->SetColor (Quantity_Color (aColorName), anIndex);
3702 aCS->SetColorType(Aspect_TOCSD_USER);
3707 TCollection_AsciiString aRed (theArgVec[anArgIter + 2]);
3708 TCollection_AsciiString aGreen (theArgVec[anArgIter + 3]);
3709 TCollection_AsciiString aBlue (theArgVec[anArgIter + 4]);
3710 Standard_Real aRedValue,aGreenValue, aBlueValue;
3711 if(checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3715 aCS->SetColor (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB), anIndex);
3716 aCS->SetColorType (Aspect_TOCSD_USER);
3719 else if (aFlag == "-label")
3721 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3723 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
3726 else if (anArgIter + 2 >= theArgNb)
3728 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3732 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
3734 || anIndex > aNbIntervals)
3736 std::cout << "Error: Index value should be within range 0..." << aNbIntervals <<"!\n";
3740 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
3741 aCS->SetLabel (aText, anIndex);
3742 aCS->SetLabelType (Aspect_TOCSD_USER);
3745 else if (aFlag == "-colors")
3747 Aspect_SequenceOfColor aSeq;
3748 if (anArgIter + aNbIntervals + 1 > theArgNb)
3750 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3751 << aNbIntervals << " intervals\n";
3755 Standard_Integer aColorIter = anArgIter + 1;
3756 while (aColorIter < theArgNb)
3758 if (theArgVec[aColorIter][0] == '-')
3763 else if (theArgVec[aColorIter][0] >= 97
3764 && theArgVec[aColorIter][0] <= 122)
3766 Quantity_NameOfColor aColorName;
3767 if (!Quantity_Color::ColorFromName (theArgVec[aColorIter], aColorName))
3769 std::cout << "Error: wrong color name: " << theArgVec[aColorIter] << " !\n";
3772 aSeq.Append (Quantity_Color (aColorName));
3778 TCollection_AsciiString aRed (theArgVec[aColorIter]);
3779 TCollection_AsciiString aGreen (theArgVec[aColorIter + 1]);
3780 TCollection_AsciiString aBlue (theArgVec[aColorIter + 2]);
3781 Standard_Real aRedValue,aGreenValue, aBlueValue;
3782 if (checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3786 aSeq.Append (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB));
3791 if (aSeq.Length() < aNbIntervals)
3793 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3794 << aNbIntervals << " intervals\n";
3798 aCS->SetColors (aSeq);
3799 aCS->SetColorType (Aspect_TOCSD_USER);
3801 else if (aFlag == "-labels")
3803 if (anArgIter + aNbIntervals + 1 >= theArgNb)
3805 std::cout << "Error: not enough arguments! You should provide " << (aNbIntervals + 1)
3806 << " text labels for " << aNbIntervals << " intervals.\n";
3810 TColStd_SequenceOfExtendedString aSeq;
3811 for (int aLabelIter = anArgIter + 1; aLabelIter <= anArgIter + aNbIntervals + 1; aLabelIter += 1)
3813 aSeq.Append (TCollection_ExtendedString (theArgVec[aLabelIter]));
3815 aCS->SetLabels (aSeq);
3816 aCS->SetLabelType (Aspect_TOCSD_USER);
3817 anArgIter += aSeq.Length();
3819 else if (aFlag == "-title")
3821 if (anArgIter + 1 >= theArgNb)
3823 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3827 Standard_Boolean isTwoArgs = Standard_False;
3828 if (anArgIter + 2 < theArgNb)
3830 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
3831 aSecondArg.LowerCase();
3832 if (aSecondArg == "none")
3834 aCS->SetTitlePosition (Aspect_TOCSP_NONE);
3835 isTwoArgs = Standard_True;
3837 else if (aSecondArg == "left")
3839 aCS->SetTitlePosition (Aspect_TOCSP_LEFT);
3840 isTwoArgs = Standard_True;
3842 else if (aSecondArg == "right")
3844 aCS->SetTitlePosition (Aspect_TOCSP_RIGHT);
3845 isTwoArgs = Standard_True;
3847 else if (aSecondArg == "center")
3849 aCS->SetTitlePosition (Aspect_TOCSP_CENTER);
3850 isTwoArgs = Standard_True;
3854 aCS->SetTitle (theArgVec[anArgIter + 1]);
3861 else if (aFlag == "-demoversion"
3862 || aFlag == "-demo")
3864 aPos.SetCoord (0.0, 0.0);
3869 aLabPosition = Aspect_TOCSP_RIGHT;
3870 aCS->SetColorType(Aspect_TOCSD_AUTO);
3871 aCS->SetLabelType(Aspect_TOCSD_AUTO);
3875 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
3880 aCS->SetPosition (aPos.X(), aPos.Y());
3881 aCS->SetHeight (0.95);
3882 aCS->SetTextHeight (aTextHeight);
3883 aCS->SetRange (aMinRange, aMaxRange);
3884 aCS->SetNumberOfIntervals (aNbIntervals);
3885 aCS->SetLabelPosition (aLabPosition);
3887 if (!aView->ColorScaleIsDisplayed())
3889 aView->ColorScaleDisplay();
3895 //==============================================================================
3896 //function : VGraduatedTrihedron
3897 //purpose : Displays or hides a graduated trihedron
3898 //==============================================================================
3899 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
3900 Quantity_Color& theColor)
3902 Quantity_NameOfColor aColorName;
3903 TCollection_AsciiString aVal = theValue;
3905 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
3907 return Standard_False;
3909 theColor = Quantity_Color (aColorName);
3910 return Standard_True;
3913 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
3917 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
3918 << theArgs[0] <<"' for more information.\n";
3919 return 1; //TCL_ERROR
3922 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
3923 TCollection_AsciiString aParseKey;
3924 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
3926 TCollection_AsciiString anArg (theArgs [anArgIt]);
3928 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3931 aParseKey.Remove (1);
3932 aParseKey.LowerCase();
3933 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
3937 if (aParseKey.IsEmpty())
3942 aMapOfArgs(aParseKey)->Append (anArg);
3946 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
3947 aMapIt.More(); aMapIt.Next())
3949 const TCollection_AsciiString& aKey = aMapIt.Key();
3950 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
3952 // Bool key, without arguments
3953 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
3954 && anArgs->IsEmpty())
3960 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
3961 && anArgs->Length() == 1)
3967 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
3968 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
3969 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
3970 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
3971 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
3976 // One string argument
3977 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
3978 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
3979 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
3984 // One integer argument
3985 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
3986 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
3987 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
3988 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
3989 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
3994 // One real argument
3995 if ( aKey.IsEqual ("arrowlength")
3996 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
4001 // Two string arguments
4002 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
4003 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4008 TCollection_AsciiString aLowerKey;
4011 aLowerKey.LowerCase();
4012 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
4013 std::cout << "Type help for more information.\n";
4017 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4018 if (anAISContext.IsNull())
4020 std::cout << theArgs[0] << ": " << " please use 'vinit' command to initialize view.\n";
4024 Standard_Boolean toDisplay = Standard_True;
4025 Quantity_Color aColor;
4026 Graphic3d_GraduatedTrihedron aTrihedronData;
4027 // Process parameters
4028 Handle(TColStd_HSequenceOfAsciiString) aValues;
4029 if (aMapOfArgs.Find ("off", aValues))
4031 toDisplay = Standard_False;
4035 if (aMapOfArgs.Find ("xname", aValues))
4037 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
4039 if (aMapOfArgs.Find ("yname", aValues))
4041 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
4043 if (aMapOfArgs.Find ("zname", aValues))
4045 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
4047 if (aMapOfArgs.Find ("xdrawname", aValues))
4049 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4051 if (aMapOfArgs.Find ("ydrawname", aValues))
4053 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4055 if (aMapOfArgs.Find ("zdrawname", aValues))
4057 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4059 if (aMapOfArgs.Find ("xnameoffset", aValues))
4061 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4063 if (aMapOfArgs.Find ("ynameoffset", aValues))
4065 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4067 if (aMapOfArgs.Find ("znameoffset", aValues))
4069 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4073 if (aMapOfArgs.Find ("xnamecolor", aValues))
4075 if (!GetColor (aValues->Value(1), aColor))
4077 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
4080 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
4082 if (aMapOfArgs.Find ("ynamecolor", aValues))
4084 if (!GetColor (aValues->Value(1), aColor))
4086 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
4089 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
4091 if (aMapOfArgs.Find ("znamecolor", aValues))
4093 if (!GetColor (aValues->Value(1), aColor))
4095 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
4098 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
4100 if (aMapOfArgs.Find ("xcolor", aValues))
4102 if (!GetColor (aValues->Value(1), aColor))
4104 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
4107 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
4109 if (aMapOfArgs.Find ("ycolor", aValues))
4111 if (!GetColor (aValues->Value(1), aColor))
4113 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
4116 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
4118 if (aMapOfArgs.Find ("zcolor", aValues))
4120 if (!GetColor (aValues->Value(1), aColor))
4122 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
4125 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
4129 if (aMapOfArgs.Find ("xticks", aValues))
4131 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4133 if (aMapOfArgs.Find ("yticks", aValues))
4135 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4137 if (aMapOfArgs.Find ("zticks", aValues))
4139 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4141 if (aMapOfArgs.Find ("xticklength", aValues))
4143 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4145 if (aMapOfArgs.Find ("yticklength", aValues))
4147 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4149 if (aMapOfArgs.Find ("zticklength", aValues))
4151 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4153 if (aMapOfArgs.Find ("xdrawticks", aValues))
4155 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4157 if (aMapOfArgs.Find ("ydrawticks", aValues))
4159 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4161 if (aMapOfArgs.Find ("zdrawticks", aValues))
4163 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4167 if (aMapOfArgs.Find ("xdrawvalues", aValues))
4169 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4171 if (aMapOfArgs.Find ("ydrawvalues", aValues))
4173 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4175 if (aMapOfArgs.Find ("zdrawvalues", aValues))
4177 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4179 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
4181 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4183 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
4185 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4187 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
4189 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4193 if (aMapOfArgs.Find ("arrowlength", aValues))
4195 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
4199 if (aMapOfArgs.Find ("namefont", aValues))
4201 aTrihedronData.SetNamesFont (aValues->Value(1));
4203 if (aMapOfArgs.Find ("valuesfont", aValues))
4205 aTrihedronData.SetValuesFont (aValues->Value(1));
4208 if (aMapOfArgs.Find ("drawgrid", aValues))
4210 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
4212 if (aMapOfArgs.Find ("drawaxes", aValues))
4214 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
4217 // The final step: display of erase trihedron
4220 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
4224 ViewerTest::CurrentView()->GraduatedTrihedronErase();
4227 ViewerTest::GetAISContext()->UpdateCurrentViewer();
4228 ViewerTest::CurrentView()->Redraw();
4233 //==============================================================================
4234 //function : VPrintView
4235 //purpose : Test printing algorithm, print the view to image file with given
4236 // width and height. Printing implemented only for WNT.
4237 //==============================================================================
4238 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
4242 di << "Printing implemented only for wnt!\n";
4246 Handle(AIS_InteractiveContext) aContextAIS = NULL;
4247 Handle(V3d_View) aView = NULL;
4248 aContextAIS = ViewerTest::GetAISContext();
4249 if (!aContextAIS.IsNull())
4251 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
4252 Vwr->InitActiveViews();
4253 if(Vwr->MoreActiveViews())
4254 aView = Vwr->ActiveView();
4260 di << "Call vinit before!\n";
4265 di << "Use: " << argv[0];
4266 di << " width height filename [print algo=0] [tile_width tile_height]\n";
4267 di << "width, height of the intermediate buffer for operation\n";
4268 di << "algo : {0|1}\n";
4269 di << " 0 - stretch algorithm\n";
4270 di << " 1 - tile algorithm\n";
4271 di << "test printing algorithms into an intermediate buffer\n";
4272 di << "using specific tile size if provided\n";
4273 di << "with saving output to an image file\n";
4277 // get the input params
4278 Standard_Integer aWidth = Draw::Atoi (argv[1]);
4279 Standard_Integer aHeight = Draw::Atoi (argv[2]);
4280 Standard_Integer aMode = 0;
4281 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
4283 aMode = Draw::Atoi (argv[4]);
4285 Standard_Integer aTileWidth = 0;
4286 Standard_Integer aTileHeight = 0;
4287 Standard_Boolean isTileSizeProvided = Standard_False;
4290 isTileSizeProvided = Standard_True;
4291 aTileWidth = Draw::Atoi (argv[5]);
4292 aTileHeight = Draw::Atoi (argv[6]);
4295 // check the input parameters
4296 if (aWidth <= 0 || aHeight <= 0)
4298 di << "Width and height must be positive values!\n";
4301 if (aMode != 0 && aMode != 1)
4304 // define compatible bitmap
4305 HDC anDC = CreateCompatibleDC(0);
4306 BITMAPINFO aBitmapData;
4307 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
4308 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
4309 aBitmapData.bmiHeader.biWidth = aWidth ;
4310 aBitmapData.bmiHeader.biHeight = aHeight;
4311 aBitmapData.bmiHeader.biPlanes = 1;
4312 aBitmapData.bmiHeader.biBitCount = 24;
4313 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
4314 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
4315 aBitmapData.bmiHeader.biClrUsed = 0;
4316 aBitmapData.bmiHeader.biClrImportant = 0;
4317 aBitmapData.bmiHeader.biCompression = BI_RGB;
4318 aBitmapData.bmiHeader.biSizeImage = 0;
4320 // Create Device Independent Bitmap
4321 void* aBitsOut = NULL;
4322 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
4323 &aBitsOut, NULL, 0);
4324 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
4326 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
4327 if (aBitsOut != NULL)
4330 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
4333 if (isTileSizeProvided)
4335 Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView());
4336 Graphic3d_PtrFrameBuffer anOldBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO);
4337 aCView->ptrFBO = aView->View()->FBOCreate (aTileWidth, aTileHeight);
4339 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
4341 Graphic3d_PtrFrameBuffer aNewBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO);
4342 aView->View()->FBORelease (aNewBuffer);
4343 aCView->ptrFBO = anOldBuffer;
4347 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
4351 // succesfully printed into an intermediate buffer
4354 Image_PixMap aWrapper;
4355 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
4356 aWrapper.SetTopDown (false);
4358 Image_AlienPixMap anImageBitmap;
4359 anImageBitmap.InitCopy (aWrapper);
4360 isSaved = anImageBitmap.Save (aFileName);
4364 di << "Print operation failed due to printing errors or\n";
4365 di << "insufficient memory available\n";
4366 di << "Please, try to use smaller dimensions for this test\n";
4367 di << "command, as it allocates intermediate buffer for storing\n";
4368 di << "the result\n";
4373 di << "Can't allocate memory for intermediate buffer\n";
4374 di << "Please use smaller dimensions\n";
4379 SelectObject (anDC, anOldBitmap);
4380 DeleteObject (aMemoryBitmap);
4386 di << "Save to file operation failed. This operation may fail\n";
4387 di << "if you don't have enough available memory, then you can\n";
4388 di << "use smaller dimensions for the output file\n";
4397 //==============================================================================
4398 //function : VZLayer
4399 //purpose : Test z layer operations for v3d viewer
4400 //==============================================================================
4401 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4403 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
4404 if (aContextAIS.IsNull())
4406 di << "Call vinit before!\n";
4411 di << "Use: vzlayer ";
4412 di << " add/del/get/settings/enable/disable [id]\n";
4413 di << " add - add new z layer to viewer and print its id\n";
4414 di << " del - del z layer by its id\n";
4415 di << " get - print sequence of z layers in increasing order of their overlay level\n";
4416 di << " settings - print status of z layer settings\n";
4417 di << " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n";
4418 di << " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n";
4419 di << " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n";
4420 di << "\nWhere id is the layer identificator\n";
4421 di << "\nExamples:\n";
4422 di << " vzlayer add\n";
4423 di << " vzlayer enable poffset 1\n";
4424 di << " vzlayer disable depthtest 1\n";
4425 di << " vzlayer del 1\n";
4429 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
4430 if (aViewer.IsNull())
4432 di << "No active viewer!\n";
4436 // perform operation
4437 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
4440 Standard_Integer aNewId;
4441 if (!aViewer->AddZLayer (aNewId))
4443 di << "Impossible to add new z layer!\n";
4447 di << "New z layer added with index: " << aNewId << "\n";
4449 else if (anOp == "del")
4453 di << "Please also provide as argument id of z layer to remove\n";
4457 Standard_Integer aDelId = Draw::Atoi (argv[2]);
4458 if (!aViewer->RemoveZLayer (aDelId))
4460 di << "Impossible to remove the z layer or invalid id!\n";
4464 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4465 anObjIter.More(); anObjIter.Next())
4467 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1());
4469 || aPrs->ZLayer() != aDelId)
4473 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4476 di << "Z layer " << aDelId << " has been removed\n";
4478 else if (anOp == "get")
4480 TColStd_SequenceOfInteger anIds;
4481 aViewer->GetAllZLayers (anIds);
4482 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
4484 di << anIds.Value (aSeqIdx) << " ";
4489 else if (anOp == "settings")
4493 di << "Please also provide an id\n";
4497 Standard_Integer anId = Draw::Atoi (argv[2]);
4498 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4500 di << "Depth test - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthTest) ? "enabled" : "disabled") << "\n";
4501 di << "Depth write - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthWrite) ? "enabled" : "disabled") << "\n";
4502 di << "Depth buffer clearing - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthClear) ? "enabled" : "disabled") << "\n";
4503 di << "Depth offset - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthOffset) ? "enabled" : "disabled") << "\n";
4506 else if (anOp == "enable")
4510 di << "Please also provide an option to enable\n";
4516 di << "Please also provide a layer id\n";
4520 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
4521 Standard_Integer anId = Draw::Atoi (argv[3]);
4522 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4524 if (aSubOp == "depthtest" || aSubOp == "test")
4526 aSettings.EnableSetting (Graphic3d_ZLayerDepthTest);
4528 else if (aSubOp == "depthwrite" || aSubOp == "write")
4530 aSettings.EnableSetting (Graphic3d_ZLayerDepthWrite);
4532 else if (aSubOp == "depthclear" || aSubOp == "clear")
4534 aSettings.EnableSetting (Graphic3d_ZLayerDepthClear);
4536 else if (aSubOp == "depthoffset" || aSubOp == "offset")
4540 di << "Please also provide a factor and units values for depth offset\n";
4541 di << "Format is: vzlayer enable offset [factor] [units] [layerId]\n";
4545 Standard_ShortReal aFactor = static_cast<Standard_ShortReal> (Draw::Atof (argv[3]));
4546 Standard_ShortReal aUnits = static_cast<Standard_ShortReal> (Draw::Atof (argv[4]));
4547 anId = Draw::Atoi (argv[5]);
4548 aSettings = aViewer->ZLayerSettings (anId);
4550 aSettings.DepthOffsetFactor = aFactor;
4551 aSettings.DepthOffsetUnits = aUnits;
4553 aSettings.EnableSetting (Graphic3d_ZLayerDepthOffset);
4555 else if (aSubOp == "positiveoffset" || aSubOp == "poffset")
4557 aSettings.SetDepthOffsetPositive();
4559 else if (aSubOp == "negativeoffset" || aSubOp == "noffset")
4561 aSettings.SetDepthOffsetNegative();
4564 aViewer->SetZLayerSettings (anId, aSettings);
4566 else if (anOp == "disable")
4570 di << "Please also provide an option to disable\n";
4576 di << "Please also provide a layer id\n";
4580 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
4581 Standard_Integer anId = Draw::Atoi (argv[3]);
4582 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4584 if (aSubOp == "depthtest" || aSubOp == "test")
4586 aSettings.DisableSetting (Graphic3d_ZLayerDepthTest);
4588 else if (aSubOp == "depthwrite" || aSubOp == "write")
4590 aSettings.DisableSetting (Graphic3d_ZLayerDepthWrite);
4592 else if (aSubOp == "depthclear" || aSubOp == "clear")
4594 aSettings.DisableSetting (Graphic3d_ZLayerDepthClear);
4596 else if (aSubOp == "depthoffset" || aSubOp == "offset")
4598 aSettings.DisableSetting (Graphic3d_ZLayerDepthOffset);
4601 aViewer->SetZLayerSettings (anId, aSettings);
4605 di << "Invalid operation, please use { add / del / get / settings / enable / disable}\n";
4612 // The Visual3d_LayerItem line item for "vlayerline" command
4613 // it provides a presentation of line with user-defined
4614 // linewidth, linetype and transparency.
4615 class V3d_LineItem : public AIS_InteractiveObject
4619 DEFINE_STANDARD_RTTI(V3d_LineItem, AIS_InteractiveObject)
4622 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4623 Standard_Real X2, Standard_Real Y2,
4624 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
4625 Standard_Real theWidth = 0.5,
4626 Standard_Real theTransp = 1.0);
4630 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4631 const Handle(Prs3d_Presentation)& thePresentation,
4632 const Standard_Integer theMode);
4634 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
4635 const Standard_Integer /*aMode*/){};
4639 Standard_Real myX1, myY1, myX2, myY2;
4640 Aspect_TypeOfLine myType;
4641 Standard_Real myWidth;
4644 // default constructor for line item
4645 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4646 Standard_Real X2, Standard_Real Y2,
4647 Aspect_TypeOfLine theType,
4648 Standard_Real theWidth,
4649 Standard_Real theTransp) :
4650 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
4651 myType(theType), myWidth(theWidth)
4653 SetTransparency (1-theTransp);
4657 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
4658 const Handle(Prs3d_Presentation)& thePresentation,
4659 const Standard_Integer /*theMode*/)
4661 thePresentation->Clear();
4662 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
4663 Standard_Integer aWidth, aHeight;
4664 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
4665 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
4666 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
4667 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
4668 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
4669 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
4670 aGroup->SetPrimitivesAspect (anAspect->Aspect());
4671 aGroup->AddPrimitiveArray (aPrim);
4674 //=============================================================================
4675 //function : VLayerLine
4676 //purpose : Draws line in the v3d view layer with given attributes: linetype,
4677 // : linewidth, transparency coefficient
4678 //============================================================================
4679 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4681 // get the active view
4682 Handle(V3d_View) aView = ViewerTest::CurrentView();
4685 di << "Call vinit before!\n";
4690 di << "Use: " << argv[0];
4691 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
4692 di << " linetype : { 0 | 1 | 2 | 3 } \n";
4693 di << " 0 - solid \n";
4694 di << " 1 - dashed \n";
4695 di << " 2 - dot \n";
4696 di << " 3 - dashdot\n";
4697 di << " transparency : { 0.0 - 1.0 } \n";
4698 di << " 0.0 - transparent\n";
4699 di << " 1.0 - visible \n";
4703 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4704 // get the input params
4705 Standard_Real X1 = Draw::Atof(argv[1]);
4706 Standard_Real Y1 = Draw::Atof(argv[2]);
4707 Standard_Real X2 = Draw::Atof(argv[3]);
4708 Standard_Real Y2 = Draw::Atof(argv[4]);
4710 Standard_Real aWidth = 0.5;
4711 Standard_Integer aType = 0;
4712 Standard_Real aTransparency = 1.0;
4716 aWidth = Draw::Atof(argv[5]);
4720 aType = (Standard_Integer) Draw::Atoi(argv[6]);
4725 aTransparency = Draw::Atof(argv[7]);
4726 if (aTransparency < 0 || aTransparency > 1.0)
4727 aTransparency = 1.0;
4730 // select appropriate line type
4731 Aspect_TypeOfLine aLineType;
4735 aLineType = Aspect_TOL_DASH;
4739 aLineType = Aspect_TOL_DOT;
4743 aLineType = Aspect_TOL_DOTDASH;
4747 aLineType = Aspect_TOL_SOLID;
4750 static Handle (V3d_LineItem) aLine;
4751 if (!aLine.IsNull())
4753 aContext->Erase (aLine);
4755 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
4759 aLine->SetTransformPersistence (Graphic3d_TMF_2d,gp_Pnt(-1,-1,0));
4760 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
4761 aLine->SetToUpdate();
4762 aContext->Display (aLine, Standard_True);
4768 //==============================================================================
4771 //==============================================================================
4773 static int VGrid (Draw_Interpretor& /*theDI*/,
4774 Standard_Integer theArgNb,
4775 const char** theArgVec)
4777 // get the active view
4778 Handle(V3d_View) aView = ViewerTest::CurrentView();
4779 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4780 if (aView.IsNull() || aViewer.IsNull())
4782 std::cerr << "No active view. Please call vinit.\n";
4786 Aspect_GridType aType = aViewer->GridType();
4787 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
4789 Standard_Integer anIter = 1;
4790 for (; anIter < theArgNb; ++anIter)
4792 const char* aValue = theArgVec[anIter];
4795 aType = Aspect_GT_Rectangular;
4797 else if (*aValue == 'c')
4799 aType = Aspect_GT_Circular;
4801 else if (*aValue == 'l')
4803 aMode = Aspect_GDM_Lines;
4805 else if (*aValue == 'p')
4807 aMode = Aspect_GDM_Points;
4809 else if (strcmp (aValue, "off" ) == 0)
4811 aViewer->DeactivateGrid();
4820 Standard_Integer aTail = (theArgNb - anIter);
4823 aViewer->ActivateGrid (aType, aMode);
4826 else if (aTail != 2 && aTail != 5)
4828 std::cerr << "Incorrect arguments number! Usage:\n"
4829 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
4833 Quantity_Length anOriginX, anOriginY;
4834 Quantity_PlaneAngle aRotAngle;
4835 if (aType == Aspect_GT_Rectangular)
4837 Quantity_Length aRStepX, aRStepY;
4838 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4840 anOriginX = Draw::Atof (theArgVec[anIter++]);
4841 anOriginY = Draw::Atof (theArgVec[anIter++]);
4844 aRStepX = Draw::Atof (theArgVec[anIter++]);
4845 aRStepY = Draw::Atof (theArgVec[anIter++]);
4846 aRotAngle = Draw::Atof (theArgVec[anIter++]);
4848 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4849 aViewer->ActivateGrid (aType, aMode);
4851 else if (aType == Aspect_GT_Circular)
4853 Quantity_Length aRadiusStep;
4854 Standard_Integer aDivisionNumber;
4855 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
4857 anOriginX = Draw::Atof (theArgVec[anIter++]);
4858 anOriginY = Draw::Atof (theArgVec[anIter++]);
4861 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
4862 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
4863 aRotAngle = Draw::Atof (theArgVec[anIter++]);
4866 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
4867 aViewer->ActivateGrid (aType, aMode);
4873 //==============================================================================
4874 //function : VPriviledgedPlane
4876 //==============================================================================
4878 static int VPriviledgedPlane (Draw_Interpretor& theDI,
4879 Standard_Integer theArgNb,
4880 const char** theArgVec)
4882 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
4884 std::cerr << "Error: wrong number of arguments! See usage:\n";
4885 theDI.PrintHelp (theArgVec[0]);
4889 // get the active viewer
4890 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4891 if (aViewer.IsNull())
4893 std::cerr << "Error: no active viewer. Please call vinit.\n";
4899 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
4900 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
4901 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
4902 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
4903 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
4904 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
4905 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
4909 Standard_Integer anArgIdx = 1;
4910 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
4911 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
4912 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
4913 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
4914 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
4915 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
4917 gp_Ax3 aPriviledgedPlane;
4918 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
4919 gp_Dir aNorm (aNormX, aNormY, aNormZ);
4922 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
4923 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
4924 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
4925 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
4926 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
4930 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
4933 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
4938 //==============================================================================
4939 //function : VConvert
4941 //==============================================================================
4943 static int VConvert (Draw_Interpretor& theDI,
4944 Standard_Integer theArgNb,
4945 const char** theArgVec)
4947 // get the active view
4948 Handle(V3d_View) aView = ViewerTest::CurrentView();
4951 std::cerr << "Error: no active view. Please call vinit.\n";
4955 enum { Model, Ray, View, Window, Grid } aMode = Model;
4957 // access coordinate arguments
4958 TColStd_SequenceOfReal aCoord;
4959 Standard_Integer anArgIdx = 1;
4960 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
4962 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
4963 if (!anArg.IsRealValue())
4967 aCoord.Append (anArg.RealValue());
4970 // non-numeric argument too early
4971 if (aCoord.IsEmpty())
4973 std::cerr << "Error: wrong number of arguments! See usage:\n";
4974 theDI.PrintHelp (theArgVec[0]);
4978 // collect all other arguments and options
4979 for (; anArgIdx < theArgNb; ++anArgIdx)
4981 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
4983 if (anArg == "window") aMode = Window;
4984 else if (anArg == "view") aMode = View;
4985 else if (anArg == "grid") aMode = Grid;
4986 else if (anArg == "ray") aMode = Ray;
4989 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
4990 theDI.PrintHelp (theArgVec[0]);
4995 // complete input checks
4996 if ((aCoord.Length() == 1 && theArgNb > 3) ||
4997 (aCoord.Length() == 2 && theArgNb > 4) ||
4998 (aCoord.Length() == 3 && theArgNb > 5))
5000 std::cerr << "Error: wrong number of arguments! See usage:\n";
5001 theDI.PrintHelp (theArgVec[0]);
5005 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
5006 Standard_Integer aXYp[2] = {0, 0};
5008 // convert one-dimensional coordinate
5009 if (aCoord.Length() == 1)
5013 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer) aCoord (1)); return 0;
5014 case Window : theDI << "Window Vp: " << aView->Convert ((Quantity_Length) aCoord (1)); return 0;
5016 std::cerr << "Error: wrong arguments! See usage:\n";
5017 theDI.PrintHelp (theArgVec[0]);
5022 // convert 2D coordinates from projection or view reference space
5023 if (aCoord.Length() == 2)
5028 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5029 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5033 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5034 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5038 aView->Convert ((V3d_Coordinate) aCoord (1), (V3d_Coordinate) aCoord (2), aXYp[0], aXYp[1]);
5039 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5043 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5044 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5045 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5049 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5050 (Standard_Integer) aCoord (2),
5051 aXYZ[0], aXYZ[1], aXYZ[2],
5052 aXYZ[3], aXYZ[4], aXYZ[5]);
5053 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5057 std::cerr << "Error: wrong arguments! See usage:\n";
5058 theDI.PrintHelp (theArgVec[0]);
5063 // convert 3D coordinates from view reference space
5064 else if (aCoord.Length() == 3)
5069 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5070 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5074 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5075 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5079 std::cerr << "Error: wrong arguments! See usage:\n";
5080 theDI.PrintHelp (theArgVec[0]);
5088 //==============================================================================
5091 //==============================================================================
5093 static int VFps (Draw_Interpretor& theDI,
5094 Standard_Integer theArgNb,
5095 const char** theArgVec)
5097 // get the active view
5098 Handle(V3d_View) aView = ViewerTest::CurrentView();
5101 std::cerr << "No active view. Please call vinit.\n";
5105 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
5108 std::cerr << "Incorrect arguments!\n";
5112 // the time is meaningless for first call
5113 // due to async OpenGl rendering
5116 // redraw view in loop to estimate average values
5119 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
5125 const Standard_Real aTime = aTimer.ElapsedTime();
5126 aTimer.OSD_Chronometer::Show (aCpu);
5128 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
5129 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
5131 // return statistics
5132 theDI << "FPS: " << aFpsAver << "\n"
5133 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5135 // compute additional statistics in ray-tracing mode
5136 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
5138 if (aParams.Method == Graphic3d_RM_RAYTRACING)
5140 Standard_Integer aSizeX;
5141 Standard_Integer aSizeY;
5143 aView->Window()->Size (aSizeX, aSizeY);
5145 // 1 shadow ray and 1 secondary ray pew each bounce
5146 const Standard_Real aMRays = aSizeX * aSizeY * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
5148 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
5154 //==============================================================================
5155 //function : VGlDebug
5157 //==============================================================================
5159 static int VGlDebug (Draw_Interpretor& theDI,
5160 Standard_Integer theArgNb,
5161 const char** theArgVec)
5163 Handle(OpenGl_GraphicDriver) aDriver;
5164 Handle(V3d_View) aView = ViewerTest::CurrentView();
5165 if (!aView.IsNull())
5167 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5169 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
5170 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
5174 TCollection_AsciiString aDebActive, aSyncActive;
5181 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
5182 "GL_ARB_debug_output");
5183 aDebActive = isActive ? " (active)" : " (inactive)";
5186 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
5187 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
5191 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
5192 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
5193 << "glslWarn:" << (aCaps->glslWarnings ? "1" : "0") << "\n"
5194 << "extraMsg:" << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
5198 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5200 Standard_CString anArg = theArgVec[anArgIter];
5201 TCollection_AsciiString anArgCase (anArg);
5202 anArgCase.LowerCase();
5203 Standard_Boolean toEnableDebug = Standard_True;
5204 if (anArgCase == "-glsl"
5205 || anArgCase == "-glslwarn"
5206 || anArgCase == "-glslwarns"
5207 || anArgCase == "-glslwarnings")
5209 Standard_Boolean toShowWarns = Standard_True;
5210 if (++anArgIter < theArgNb
5211 && !parseOnOff (theArgVec[anArgIter], toShowWarns))
5215 aDefCaps->glslWarnings = toShowWarns;
5218 aCaps->glslWarnings = toShowWarns;
5221 else if (anArgCase == "-extra"
5222 || anArgCase == "-extramsg"
5223 || anArgCase == "-extramessages")
5225 Standard_Boolean toShow = Standard_True;
5226 if (++anArgIter < theArgNb
5227 && !parseOnOff (theArgVec[anArgIter], toShow))
5231 aDefCaps->suppressExtraMsg = !toShow;
5234 aCaps->suppressExtraMsg = !toShow;
5237 else if (anArgCase == "-noextra"
5238 || anArgCase == "-noextramsg"
5239 || anArgCase == "-noextramessages")
5241 Standard_Boolean toSuppress = Standard_True;
5242 if (++anArgIter < theArgNb
5243 && !parseOnOff (theArgVec[anArgIter], toSuppress))
5247 aDefCaps->suppressExtraMsg = toSuppress;
5250 aCaps->suppressExtraMsg = toSuppress;
5253 else if (anArgCase == "-sync")
5255 Standard_Boolean toSync = Standard_True;
5256 if (++anArgIter < theArgNb
5257 && !parseOnOff (theArgVec[anArgIter], toSync))
5261 aDefCaps->contextSyncDebug = toSync;
5264 aDefCaps->contextDebug = Standard_True;
5267 else if (anArgCase == "-debug")
5269 if (++anArgIter < theArgNb
5270 && !parseOnOff (theArgVec[anArgIter], toEnableDebug))
5274 aDefCaps->contextDebug = toEnableDebug;
5276 else if (parseOnOff (anArg, toEnableDebug)
5277 && (anArgIter + 1 == theArgNb))
5279 // simple alias to turn on almost everything
5280 aDefCaps->contextDebug = toEnableDebug;
5281 aDefCaps->contextSyncDebug = toEnableDebug;
5282 aDefCaps->glslWarnings = toEnableDebug;
5286 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
5294 //==============================================================================
5297 //==============================================================================
5299 static int VVbo (Draw_Interpretor& theDI,
5300 Standard_Integer theArgNb,
5301 const char** theArgVec)
5303 const Standard_Boolean toSet = (theArgNb > 1);
5304 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
5307 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
5311 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5312 if (aContextAIS.IsNull())
5316 std::cerr << "No active view!\n";
5320 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5321 if (!aDriver.IsNull())
5325 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
5329 aDriver->ChangeOptions().vboDisable = toUseVbo;
5336 //==============================================================================
5339 //==============================================================================
5341 static int VCaps (Draw_Interpretor& theDI,
5342 Standard_Integer theArgNb,
5343 const char** theArgVec)
5345 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
5346 Handle(OpenGl_GraphicDriver) aDriver;
5347 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5348 if (!aContext.IsNull())
5350 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
5351 aCaps = &aDriver->ChangeOptions();
5356 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
5357 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
5358 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
5359 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
5360 theDI << "VSync: " << aCaps->swapInterval << "\n";
5361 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
5362 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
5366 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5367 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5369 Standard_CString anArg = theArgVec[anArgIter];
5370 TCollection_AsciiString anArgCase (anArg);
5371 anArgCase.LowerCase();
5372 if (anUpdateTool.parseRedrawMode (anArg))
5376 else if (anArgCase == "-vsync"
5377 || anArgCase == "-swapinterval")
5379 Standard_Boolean toEnable = Standard_True;
5380 if (++anArgIter < theArgNb
5381 && !parseOnOff (theArgVec[anArgIter], toEnable))
5385 aCaps->swapInterval = toEnable;
5387 else if (anArgCase == "-ffp")
5389 Standard_Boolean toEnable = Standard_True;
5390 if (++anArgIter < theArgNb
5391 && !parseOnOff (theArgVec[anArgIter], toEnable))
5395 aCaps->ffpEnable = toEnable;
5397 else if (anArgCase == "-vbo")
5399 Standard_Boolean toEnable = Standard_True;
5400 if (++anArgIter < theArgNb
5401 && !parseOnOff (theArgVec[anArgIter], toEnable))
5405 aCaps->vboDisable = !toEnable;
5407 else if (anArgCase == "-sprite"
5408 || anArgCase == "-sprites")
5410 Standard_Boolean toEnable = Standard_True;
5411 if (++anArgIter < theArgNb
5412 && !parseOnOff (theArgVec[anArgIter], toEnable))
5416 aCaps->pntSpritesDisable = !toEnable;
5418 else if (anArgCase == "-softmode")
5420 Standard_Boolean toEnable = Standard_True;
5421 if (++anArgIter < theArgNb
5422 && !parseOnOff (theArgVec[anArgIter], toEnable))
5426 aCaps->contextNoAccel = toEnable;
5428 else if (anArgCase == "-accel"
5429 || anArgCase == "-acceleration")
5431 Standard_Boolean toEnable = Standard_True;
5432 if (++anArgIter < theArgNb
5433 && !parseOnOff (theArgVec[anArgIter], toEnable))
5437 aCaps->contextNoAccel = !toEnable;
5439 else if (anArgCase == "-compat"
5440 || anArgCase == "-compatprofile"
5441 || anArgCase == "-compatible"
5442 || anArgCase == "-compatibleprofile")
5444 Standard_Boolean toEnable = Standard_True;
5445 if (++anArgIter < theArgNb
5446 && !parseOnOff (theArgVec[anArgIter], toEnable))
5450 aCaps->contextCompatible = toEnable;
5451 if (!aCaps->contextCompatible)
5453 aCaps->ffpEnable = Standard_False;
5456 else if (anArgCase == "-core"
5457 || anArgCase == "-coreprofile")
5459 Standard_Boolean toEnable = Standard_True;
5460 if (++anArgIter < theArgNb
5461 && !parseOnOff (theArgVec[anArgIter], toEnable))
5465 aCaps->contextCompatible = !toEnable;
5466 if (!aCaps->contextCompatible)
5468 aCaps->ffpEnable = Standard_False;
5471 else if (anArgCase == "-stereo"
5472 || anArgCase == "-quadbuffer")
5474 Standard_Boolean toEnable = Standard_True;
5475 if (++anArgIter < theArgNb
5476 && !parseOnOff (theArgVec[anArgIter], toEnable))
5480 aCaps->contextStereo = toEnable;
5484 std::cout << "Error: unknown argument '" << anArg << "'\n";
5488 if (aCaps != &ViewerTest_myDefaultCaps)
5490 ViewerTest_myDefaultCaps = *aCaps;
5495 //==============================================================================
5496 //function : VMemGpu
5498 //==============================================================================
5500 static int VMemGpu (Draw_Interpretor& theDI,
5501 Standard_Integer theArgNb,
5502 const char** theArgVec)
5505 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5506 if (aContextAIS.IsNull())
5508 std::cerr << "No active view. Please call vinit.\n";
5512 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
5513 if (aDriver.IsNull())
5515 std::cerr << "Graphic driver not available.\n";
5519 Standard_Size aFreeBytes = 0;
5520 TCollection_AsciiString anInfo;
5521 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
5523 std::cerr << "Information not available.\n";
5527 if (theArgNb > 1 && *theArgVec[1] == 'f')
5529 theDI << Standard_Real (aFreeBytes);
5539 // ==============================================================================
5540 // function : VReadPixel
5542 // ==============================================================================
5543 static int VReadPixel (Draw_Interpretor& theDI,
5544 Standard_Integer theArgNb,
5545 const char** theArgVec)
5547 // get the active view
5548 Handle(V3d_View) aView = ViewerTest::CurrentView();
5551 std::cerr << "No active view. Please call vinit.\n";
5554 else if (theArgNb < 3)
5556 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
5560 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
5561 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
5563 Standard_Integer aWidth, aHeight;
5564 aView->Window()->Size (aWidth, aHeight);
5565 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
5566 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
5567 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
5569 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
5573 Standard_Boolean toShowName = Standard_False;
5574 Standard_Boolean toShowHls = Standard_False;
5575 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
5577 const char* aParam = theArgVec[anIter];
5578 if ( strcasecmp( aParam, "rgb" ) == 0 )
5580 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
5581 aBufferType = Graphic3d_BT_RGB;
5583 else if ( strcasecmp( aParam, "hls" ) == 0 )
5585 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
5586 aBufferType = Graphic3d_BT_RGB;
5587 toShowHls = Standard_True;
5589 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
5591 aFormat = Image_PixMap::ImgRGBF;
5592 aBufferType = Graphic3d_BT_RGB;
5594 else if ( strcasecmp( aParam, "rgba" ) == 0 )
5596 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
5597 aBufferType = Graphic3d_BT_RGBA;
5599 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
5601 aFormat = Image_PixMap::ImgRGBAF;
5602 aBufferType = Graphic3d_BT_RGBA;
5604 else if ( strcasecmp( aParam, "depth" ) == 0 )
5606 aFormat = Image_PixMap::ImgGrayF;
5607 aBufferType = Graphic3d_BT_Depth;
5609 else if ( strcasecmp( aParam, "name" ) == 0 )
5611 toShowName = Standard_True;
5615 Image_PixMap anImage;
5616 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
5618 std::cerr << "Image allocation failed\n";
5621 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
5623 std::cerr << "Image dump failed\n";
5627 Quantity_Parameter anAlpha;
5628 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
5631 if (aBufferType == Graphic3d_BT_RGBA)
5633 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha;
5637 theDI << Quantity_Color::StringName (aColor.Name());
5642 switch (aBufferType)
5645 case Graphic3d_BT_RGB:
5649 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation();
5653 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue();
5657 case Graphic3d_BT_RGBA:
5659 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha;
5662 case Graphic3d_BT_Depth:
5664 theDI << aColor.Red();
5673 //==============================================================================
5674 //function : VDiffImage
5675 //purpose : The draw-command compares two images.
5676 //==============================================================================
5678 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
5682 theDI << "Not enough arguments.\n";
5687 const char* anImgPathRef = theArgVec[1];
5688 const char* anImgPathNew = theArgVec[2];
5690 // get string tolerance and check its validity
5691 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
5692 if (aTolColor < 0.0)
5694 if (aTolColor > 1.0)
5697 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
5698 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
5700 // image file of difference
5701 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
5703 // compare the images
5704 Image_Diff aComparer;
5705 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
5710 aComparer.SetColorTolerance (aTolColor);
5711 aComparer.SetBorderFilterOn (isBorderFilterOn);
5712 Standard_Integer aDiffColorsNb = aComparer.Compare();
5713 theDI << aDiffColorsNb << "\n";
5715 // save image of difference
5716 if (aDiffColorsNb >0 && aDiffImagePath != NULL)
5718 aComparer.SaveDiffImage (aDiffImagePath);
5724 //=======================================================================
5725 //function : VSelect
5726 //purpose : Emulates different types of selection by mouse:
5727 // 1) single click selection
5728 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
5729 // 3) selection with polygon having corners at
5730 // pixel positions (x1,y1),...,(xn,yn)
5731 // 4) any of these selections with shift button pressed
5732 //=======================================================================
5733 static Standard_Integer VSelect (Draw_Interpretor& di,
5734 Standard_Integer argc,
5739 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
5743 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
5744 if(myAIScontext.IsNull())
5746 di << "use 'vinit' command before " << argv[0] << "\n";
5750 const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1));
5751 Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1;
5752 TCollection_AsciiString anArg;
5753 anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2];
5755 if (anArg == "-allowoverlap")
5757 Standard_Boolean isValidated = isShiftSelection ? argc == 8
5761 di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection";
5765 Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
5766 myAIScontext->MainSelector()->AllowOverlapDetection((Standard_Boolean)isToAllow);
5770 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
5771 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
5774 if(isShiftSelection)
5775 aCurrentEventManager->ShiftSelect();
5777 aCurrentEventManager->Select();
5779 else if(aCoordsNb == 4)
5781 if(isShiftSelection)
5782 aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
5784 aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
5788 TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2);
5790 for(Standard_Integer i=1;i<=aCoordsNb / 2;++i)
5791 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
5793 if(isShiftSelection)
5794 aCurrentEventManager->ShiftSelect(aPolyline);
5796 aCurrentEventManager->Select(aPolyline);
5801 //=======================================================================
5802 //function : VMoveTo
5803 //purpose : Emulates cursor movement to defined pixel position
5804 //=======================================================================
5805 static Standard_Integer VMoveTo (Draw_Interpretor& di,
5806 Standard_Integer argc,
5811 di << "Usage : " << argv[0] << " x y" << "\n";
5815 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5816 if(aContext.IsNull())
5818 di << "use 'vinit' command before " << argv[0] << "\n";
5821 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
5825 //=================================================================================================
5826 //function : VViewParams
5827 //purpose : Gets or sets AIS View characteristics
5828 //=================================================================================================
5829 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5831 Handle(V3d_View) anAISView = ViewerTest::CurrentView();
5832 if (anAISView.IsNull())
5834 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
5840 // print all of the available view parameters
5841 Quantity_Factor anAISViewScale = anAISView->Scale();
5843 Standard_Real anAISViewProjX = 0.0;
5844 Standard_Real anAISViewProjY = 0.0;
5845 Standard_Real anAISViewProjZ = 0.0;
5846 anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
5848 Standard_Real anAISViewUpX = 0.0;
5849 Standard_Real anAISViewUpY = 0.0;
5850 Standard_Real anAISViewUpZ = 0.0;
5851 anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
5853 Standard_Real anAISViewAtX = 0.0;
5854 Standard_Real anAISViewAtY = 0.0;
5855 Standard_Real anAISViewAtZ = 0.0;
5856 anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
5858 Standard_Real anAISViewEyeX = 0.0;
5859 Standard_Real anAISViewEyeY = 0.0;
5860 Standard_Real anAISViewEyeZ = 0.0;
5861 anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ);
5863 theDi << "Scale of current view: " << anAISViewScale << "\n";
5864 theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
5865 theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
5866 theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
5867 theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n";
5871 // -------------------------
5872 // Parse options and values
5873 // -------------------------
5875 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues;
5876 TCollection_AsciiString aParseKey;
5877 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5879 TCollection_AsciiString anArg (theArgVec [anArgIt]);
5881 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
5884 aParseKey.Remove (1);
5885 aParseKey.UpperCase();
5886 aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
5890 if (aParseKey.IsEmpty())
5892 std::cout << theArgVec[0] << ": values should be passed with key.\n";
5893 std::cout << "Type help for more information.\n";
5897 aMapOfKeysByValues(aParseKey)->Append (anArg);
5900 // ---------------------------------------------
5901 // Change or print parameters, order plays role
5902 // ---------------------------------------------
5904 // Check arguments for validity
5905 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues);
5906 for (; aMapIt.More(); aMapIt.Next())
5908 const TCollection_AsciiString& aKey = aMapIt.Key();
5909 const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value();
5911 if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5912 && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5913 && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty()))
5914 && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty()))
5915 && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty()))
5916 && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty()))
5917 && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2))
5919 TCollection_AsciiString aLowerKey;
5922 aLowerKey.LowerCase();
5923 std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n";
5924 std::cout << "Type help for more information.\n";
5929 Handle(TColStd_HSequenceOfAsciiString) aValues;
5931 // Change view parameters in proper order
5932 if (aMapOfKeysByValues.Find ("SCALE", aValues))
5934 if (aValues->IsEmpty())
5936 theDi << "Scale: " << anAISView->Scale() << "\n";
5940 anAISView->SetScale (aValues->Value(1).RealValue());
5943 if (aMapOfKeysByValues.Find ("SIZE", aValues))
5945 if (aValues->IsEmpty())
5947 Standard_Real aSizeX = 0.0;
5948 Standard_Real aSizeY = 0.0;
5949 anAISView->Size (aSizeX, aSizeY);
5950 theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n";
5954 anAISView->SetSize (aValues->Value(1).RealValue());
5957 if (aMapOfKeysByValues.Find ("EYE", aValues))
5959 if (aValues->IsEmpty())
5961 Standard_Real anEyeX = 0.0;
5962 Standard_Real anEyeY = 0.0;
5963 Standard_Real anEyeZ = 0.0;
5964 anAISView->Eye (anEyeX, anEyeY, anEyeZ);
5965 theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n";
5969 anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5972 if (aMapOfKeysByValues.Find ("AT", aValues))
5974 if (aValues->IsEmpty())
5976 Standard_Real anAtX = 0.0;
5977 Standard_Real anAtY = 0.0;
5978 Standard_Real anAtZ = 0.0;
5979 anAISView->At (anAtX, anAtY, anAtZ);
5980 theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n";
5984 anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5987 if (aMapOfKeysByValues.Find ("PROJ", aValues))
5989 if (aValues->IsEmpty())
5991 Standard_Real aProjX = 0.0;
5992 Standard_Real aProjY = 0.0;
5993 Standard_Real aProjZ = 0.0;
5994 anAISView->Proj (aProjX, aProjY, aProjZ);
5995 theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n";
5999 anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6002 if (aMapOfKeysByValues.Find ("UP", aValues))
6004 if (aValues->IsEmpty())
6006 Standard_Real anUpX = 0.0;
6007 Standard_Real anUpY = 0.0;
6008 Standard_Real anUpZ = 0.0;
6009 anAISView->Up (anUpX, anUpY, anUpZ);
6010 theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n";
6014 anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6017 if (aMapOfKeysByValues.Find ("CENTER", aValues))
6019 anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue());
6025 //=======================================================================
6026 //function : VChangeSelected
6027 //purpose : Adds the shape to selection or remove one from it
6028 //=======================================================================
6029 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
6030 Standard_Integer argc,
6035 di<<"Usage : " << argv[0] << " shape \n";
6039 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6040 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
6041 TCollection_AsciiString aName(argv[1]);
6042 Handle(AIS_InteractiveObject) anAISObject;
6044 if(!aMap.IsBound2(aName))
6046 di<<"Use 'vdisplay' before";
6051 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
6052 if(anAISObject.IsNull()){
6053 di<<"No interactive object \n";
6057 aContext->AddOrRemoveSelected(anAISObject);
6062 //=======================================================================
6063 //function : VZClipping
6064 //purpose : Gets or sets ZClipping mode, width and depth
6065 //=======================================================================
6066 static Standard_Integer VZClipping (Draw_Interpretor& di,
6067 Standard_Integer argc,
6072 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6073 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6076 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6077 if(aContext.IsNull())
6079 di << "use 'vinit' command before " << argv[0] << "\n";
6082 Handle(V3d_View) aView = ViewerTest::CurrentView();
6083 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
6086 TCollection_AsciiString aZClippingModeString;
6087 Quantity_Length aDepth, aWidth;
6088 aZClippingMode = aView->ZClipping(aDepth, aWidth);
6089 switch (aZClippingMode)
6092 aZClippingModeString.Copy("OFF");
6095 aZClippingModeString.Copy("BACK");
6098 aZClippingModeString.Copy("FRONT");
6101 aZClippingModeString.Copy("SLICE");
6104 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
6107 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
6108 << "ZClipping depth = " << aDepth << "\n"
6109 << "ZClipping width = " << aWidth << "\n";
6115 Standard_Integer aStatus = 0;
6116 if ( strcmp (argv [1], "OFF") == 0 ) {
6118 aZClippingMode = V3d_OFF;
6120 if ( strcmp (argv [1], "BACK") == 0 ) {
6122 aZClippingMode = V3d_BACK;
6124 if ( strcmp (argv [1], "FRONT") == 0 ) {
6126 aZClippingMode = V3d_FRONT;
6128 if ( strcmp (argv [1], "SLICE") == 0 ) {
6130 aZClippingMode = V3d_SLICE;
6134 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6135 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6138 aView->SetZClippingType(aZClippingMode);
6142 Quantity_Length aDepth = 0., aWidth = 1.;
6145 aDepth = Draw::Atof (argv[1]);
6146 aWidth = Draw::Atof (argv[2]);
6150 aDepth = Draw::Atof (argv[2]);
6151 aWidth = Draw::Atof (argv[3]);
6154 if(aDepth<0. || aDepth>1.)
6156 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6157 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6160 if(aWidth<0. || aWidth>1.)
6162 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6163 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6167 aView->SetZClippingDepth(aDepth);
6168 aView->SetZClippingWidth(aWidth);
6175 //=======================================================================
6176 //function : VNbSelected
6177 //purpose : Returns number of selected objects
6178 //=======================================================================
6179 static Standard_Integer VNbSelected (Draw_Interpretor& di,
6180 Standard_Integer argc,
6185 di << "Usage : " << argv[0] << "\n";
6188 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6189 if(aContext.IsNull())
6191 di << "use 'vinit' command before " << argv[0] << "\n";
6194 di << aContext->NbSelected() << "\n";
6198 //=======================================================================
6199 //function : VAntialiasing
6200 //purpose : Switches altialiasing on or off
6201 //=======================================================================
6202 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
6203 Standard_Integer argc,
6208 di << "Usage : " << argv[0] << " [1|0]" << "\n";
6212 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6213 if(aContext.IsNull())
6215 di << "use 'vinit' command before " << argv[0] << "\n";
6219 Handle(V3d_View) aView = ViewerTest::CurrentView();
6221 if((argc == 2) && (atof(argv[1]) == 0))
6222 aView->SetAntialiasingOff();
6224 aView->SetAntialiasingOn();
6229 //=======================================================================
6230 //function : VPurgeDisplay
6231 //purpose : Switches altialiasing on or off
6232 //=======================================================================
6233 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
6234 Standard_Integer argc,
6239 di << "Usage : " << argv[0] << "\n";
6242 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6243 if (aContext.IsNull())
6245 di << "use 'vinit' command before " << argv[0] << "\n";
6248 aContext->CloseAllContexts(Standard_False);
6249 di << aContext->PurgeDisplay() << "\n";
6253 //=======================================================================
6254 //function : VSetViewSize
6256 //=======================================================================
6257 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
6258 Standard_Integer argc,
6261 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6262 if(aContext.IsNull())
6264 di << "use 'vinit' command before " << argv[0] << "\n";
6269 di<<"Usage : " << argv[0] << " Size\n";
6272 Standard_Real aSize = Draw::Atof (argv[1]);
6275 di<<"Bad Size value : " << aSize << "\n";
6279 Handle(V3d_View) aView = ViewerTest::CurrentView();
6280 aView->SetSize(aSize);
6284 //=======================================================================
6285 //function : VMoveView
6287 //=======================================================================
6288 static Standard_Integer VMoveView (Draw_Interpretor& di,
6289 Standard_Integer argc,
6292 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6293 if(aContext.IsNull())
6295 di << "use 'vinit' command before " << argv[0] << "\n";
6298 if(argc < 4 || argc > 5)
6300 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
6303 Standard_Real Dx = Draw::Atof (argv[1]);
6304 Standard_Real Dy = Draw::Atof (argv[2]);
6305 Standard_Real Dz = Draw::Atof (argv[3]);
6306 Standard_Boolean aStart = Standard_True;
6309 aStart = (Draw::Atoi (argv[4]) > 0);
6312 Handle(V3d_View) aView = ViewerTest::CurrentView();
6313 aView->Move(Dx,Dy,Dz,aStart);
6317 //=======================================================================
6318 //function : VTranslateView
6320 //=======================================================================
6321 static Standard_Integer VTranslateView (Draw_Interpretor& di,
6322 Standard_Integer argc,
6325 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6326 if(aContext.IsNull())
6328 di << "use 'vinit' command before " << argv[0] << "\n";
6331 if(argc < 4 || argc > 5)
6333 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
6336 Standard_Real Dx = Draw::Atof (argv[1]);
6337 Standard_Real Dy = Draw::Atof (argv[2]);
6338 Standard_Real Dz = Draw::Atof (argv[3]);
6339 Standard_Boolean aStart = Standard_True;
6342 aStart = (Draw::Atoi (argv[4]) > 0);
6345 Handle(V3d_View) aView = ViewerTest::CurrentView();
6346 aView->Translate(Dx,Dy,Dz,aStart);
6350 //=======================================================================
6351 //function : VTurnView
6353 //=======================================================================
6354 static Standard_Integer VTurnView (Draw_Interpretor& di,
6355 Standard_Integer argc,
6358 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6359 if(aContext.IsNull()) {
6360 di << "use 'vinit' command before " << argv[0] << "\n";
6363 if(argc < 4 || argc > 5){
6364 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
6367 Standard_Real Ax = Draw::Atof (argv[1]);
6368 Standard_Real Ay = Draw::Atof (argv[2]);
6369 Standard_Real Az = Draw::Atof (argv[3]);
6370 Standard_Boolean aStart = Standard_True;
6373 aStart = (Draw::Atoi (argv[4]) > 0);
6376 Handle(V3d_View) aView = ViewerTest::CurrentView();
6377 aView->Turn(Ax,Ay,Az,aStart);
6381 //==============================================================================
6382 //function : VTextureEnv
6383 //purpose : ENables or disables environment mapping
6384 //==============================================================================
6385 class OCC_TextureEnv : public Graphic3d_TextureEnv
6388 OCC_TextureEnv(const Standard_CString FileName);
6389 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
6390 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
6391 const Standard_Boolean theModulateFlag,
6392 const Graphic3d_TypeOfTextureFilter theFilter,
6393 const Standard_ShortReal theXScale,
6394 const Standard_ShortReal theYScale,
6395 const Standard_ShortReal theXShift,
6396 const Standard_ShortReal theYShift,
6397 const Standard_ShortReal theAngle);
6398 DEFINE_STANDARD_RTTI(OCC_TextureEnv, Graphic3d_TextureEnv);
6400 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
6405 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
6406 : Graphic3d_TextureEnv(theFileName)
6410 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
6411 : Graphic3d_TextureEnv(theTexId)
6415 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
6416 const Standard_Boolean theModulateFlag,
6417 const Graphic3d_TypeOfTextureFilter theFilter,
6418 const Standard_ShortReal theXScale,
6419 const Standard_ShortReal theYScale,
6420 const Standard_ShortReal theXShift,
6421 const Standard_ShortReal theYShift,
6422 const Standard_ShortReal theAngle)
6424 myParams->SetRepeat (theRepeatFlag);
6425 myParams->SetModulate (theModulateFlag);
6426 myParams->SetFilter (theFilter);
6427 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
6428 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
6429 myParams->SetRotation (theAngle);
6432 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
6434 // get the active view
6435 Handle(V3d_View) aView = ViewerTest::CurrentView();
6438 std::cerr << "No active view. Please call vinit.\n";
6442 // Checking the input arguments
6443 Standard_Boolean anEnableFlag = Standard_False;
6444 Standard_Boolean isOk = theArgNb >= 2;
6447 TCollection_AsciiString anEnableOpt(theArgVec[1]);
6448 anEnableFlag = anEnableOpt.IsEqual("on");
6449 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
6453 isOk = (theArgNb == 3 || theArgNb == 11);
6456 TCollection_AsciiString aTextureOpt(theArgVec[2]);
6457 isOk = (!aTextureOpt.IsIntegerValue() ||
6458 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
6460 if (isOk && theArgNb == 11)
6462 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
6463 aModulateOpt(theArgVec[4]),
6464 aFilterOpt (theArgVec[5]),
6465 aSScaleOpt (theArgVec[6]),
6466 aTScaleOpt (theArgVec[7]),
6467 aSTransOpt (theArgVec[8]),
6468 aTTransOpt (theArgVec[9]),
6469 anAngleOpt (theArgVec[10]);
6470 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
6471 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
6472 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
6473 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
6474 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
6475 anAngleOpt.IsRealValue());
6482 std::cerr << "Usage :" << std::endl;
6483 std::cerr << theArgVec[0] << " off" << std::endl;
6484 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;
6490 TCollection_AsciiString aTextureOpt(theArgVec[2]);
6491 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
6492 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
6493 new OCC_TextureEnv(theArgVec[2]);
6497 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
6498 aTexEnv->SetTextureParameters(
6499 aRepeatOpt. IsEqual("repeat"),
6500 aModulateOpt.IsEqual("modulate"),
6501 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
6502 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
6503 Graphic3d_TOTF_TRILINEAR,
6504 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
6505 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
6506 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
6507 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
6508 (Standard_ShortReal)Draw::Atof(theArgVec[10])
6511 aView->SetTextureEnv(aTexEnv);
6512 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
6514 else // Disabling environment mapping
6516 aView->SetSurfaceDetail(V3d_TEX_NONE);
6517 Handle(Graphic3d_TextureEnv) aTexture;
6518 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
6525 //===============================================================================================
6526 //function : VClipPlane
6528 //===============================================================================================
6529 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6531 // use short-cut for created clip planes map of created (or "registered by name") clip planes
6532 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
6533 static MapOfPlanes aRegPlanes;
6537 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
6541 TCollection_AsciiString aCommand (theArgVec[1]);
6543 // print maximum number of planes for current viewer
6544 if (aCommand == "maxplanes")
6548 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
6552 TCollection_AsciiString aViewName (theArgVec[2]);
6554 if (!ViewerTest_myViews.IsBound1 (aViewName))
6556 theDi << theArgVec[0] << ": view is not found.\n";
6560 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
6562 theDi << theArgVec[0] << ": "
6563 << aView->Viewer()->Driver()->InquirePlaneLimit()
6564 << " plane slots provided by driver."
6565 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
6570 // create / delete plane instance
6571 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
6575 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
6579 Standard_Boolean toCreate = (aCommand == "create");
6580 Standard_Boolean toClone = (aCommand == "clone");
6581 TCollection_AsciiString aPlane (theArgVec[2]);
6585 if (aRegPlanes.IsBound (aPlane))
6587 theDi << theArgVec[0] << ": plane name is in use.\n";
6591 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
6593 else if (toClone) // toClone
6595 if (!aRegPlanes.IsBound (aPlane))
6597 theDi << theArgVec[0] << ": no such plane.\n";
6603 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
6607 TCollection_AsciiString aClone (theArgVec[3]);
6608 if (aRegPlanes.IsBound (aClone))
6610 theDi << theArgVec[0] << ": plane name is in use.\n";
6614 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6616 aRegPlanes.Bind (aClone, aClipPlane->Clone());
6620 if (!aRegPlanes.IsBound (aPlane))
6622 theDi << theArgVec[0] << ": no such plane.\n";
6626 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
6627 aRegPlanes.UnBind (aPlane);
6629 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
6630 for (; anIObjIt.More(); anIObjIt.Next())
6632 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
6633 aPrs->RemoveClipPlane(aClipPlane);
6636 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
6637 for (; aViewIt.More(); aViewIt.Next())
6639 const Handle(V3d_View)& aView = aViewIt.Key2();
6640 aView->RemoveClipPlane(aClipPlane);
6643 ViewerTest::RedrawAllViews();
6649 // set / unset plane command
6650 if (aCommand == "set" || aCommand == "unset")
6654 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6658 Standard_Boolean toSet = (aCommand == "set");
6659 TCollection_AsciiString aPlane (theArgVec [2]);
6660 if (!aRegPlanes.IsBound (aPlane))
6662 theDi << theArgVec[0] << ": no such plane.\n";
6666 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6668 TCollection_AsciiString aTarget (theArgVec [3]);
6669 if (aTarget != "object" && aTarget != "view")
6671 theDi << theArgVec[0] << ": invalid target.\n";
6675 if (aTarget == "object" || aTarget == "view")
6679 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6683 Standard_Boolean isObject = (aTarget == "object");
6685 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
6687 TCollection_AsciiString anEntityName (theArgVec[anIt]);
6688 if (isObject) // to object
6690 if (!GetMapOfAIS().IsBound2 (anEntityName))
6692 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
6696 Handle(AIS_InteractiveObject) aIObj =
6697 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
6700 aIObj->AddClipPlane (aClipPlane);
6702 aIObj->RemoveClipPlane (aClipPlane);
6706 if (!ViewerTest_myViews.IsBound1 (anEntityName))
6708 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
6712 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
6714 aView->AddClipPlane (aClipPlane);
6716 aView->RemoveClipPlane (aClipPlane);
6720 ViewerTest::RedrawAllViews();
6726 // change plane command
6727 if (aCommand == "change")
6731 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6735 TCollection_AsciiString aPlane (theArgVec [2]);
6736 if (!aRegPlanes.IsBound (aPlane))
6738 theDi << theArgVec[0] << ": no such plane.\n";
6742 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6744 TCollection_AsciiString aChangeArg (theArgVec [3]);
6745 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
6747 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
6751 if (aChangeArg == "on" || aChangeArg == "off") // on / off
6753 aClipPlane->SetOn (aChangeArg == "on");
6755 else if (aChangeArg == "equation") // change equation
6759 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6763 Standard_Real aCoeffA = Draw::Atof (theArgVec [4]);
6764 Standard_Real aCoeffB = Draw::Atof (theArgVec [5]);
6765 Standard_Real aCoeffC = Draw::Atof (theArgVec [6]);
6766 Standard_Real aCoeffD = Draw::Atof (theArgVec [7]);
6767 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
6769 else if (aChangeArg == "capping") // change capping aspects
6773 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6777 TCollection_AsciiString aCappingArg (theArgVec [4]);
6778 if (aCappingArg != "on" && aCappingArg != "off" &&
6779 aCappingArg != "color" && aCappingArg != "texname" &&
6780 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
6781 aCappingArg != "texrotate" && aCappingArg != "hatch")
6783 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
6787 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
6789 aClipPlane->SetCapping (aCappingArg == "on");
6791 else if (aCappingArg == "color") // color aspect for capping
6795 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6799 Standard_Real aRed = Draw::Atof (theArgVec [5]);
6800 Standard_Real aGrn = Draw::Atof (theArgVec [6]);
6801 Standard_Real aBlu = Draw::Atof (theArgVec [7]);
6803 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
6804 Quantity_Color aColor (aRed, aGrn, aBlu, Quantity_TOC_RGB);
6805 aMat.SetAmbientColor (aColor);
6806 aMat.SetDiffuseColor (aColor);
6807 aClipPlane->SetCappingMaterial (aMat);
6809 else if (aCappingArg == "texname") // texture name
6813 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6817 TCollection_AsciiString aTextureName (theArgVec [5]);
6819 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
6820 if (!aTexture->IsDone ())
6822 aClipPlane->SetCappingTexture (NULL);
6826 aTexture->EnableModulate();
6827 aTexture->EnableRepeat();
6828 aClipPlane->SetCappingTexture (aTexture);
6831 else if (aCappingArg == "texscale") // texture scale
6833 if (aClipPlane->CappingTexture().IsNull())
6835 theDi << theArgVec[0] << ": no texture is set.\n";
6841 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6845 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
6846 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
6848 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
6850 else if (aCappingArg == "texorigin") // texture origin
6852 if (aClipPlane->CappingTexture().IsNull())
6854 theDi << theArgVec[0] << ": no texture is set.\n";
6860 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6864 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
6865 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
6867 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
6869 else if (aCappingArg == "texrotate") // texture rotation
6871 if (aClipPlane->CappingTexture().IsNull())
6873 theDi << theArgVec[0] << ": no texture is set.\n";
6879 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6883 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
6885 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
6887 else if (aCappingArg == "hatch") // hatch style
6891 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6895 TCollection_AsciiString aHatchStr (theArgVec [5]);
6896 if (aHatchStr == "on")
6898 aClipPlane->SetCappingHatchOn();
6900 else if (aHatchStr == "off")
6902 aClipPlane->SetCappingHatchOff();
6906 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
6911 ViewerTest::RedrawAllViews();
6916 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
6920 //===============================================================================================
6921 //function : VSetTextureMode
6923 //===============================================================================================
6924 static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6928 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
6932 TCollection_AsciiString aViewName (theArgVec[1]);
6933 if (!ViewerTest_myViews.IsBound1 (aViewName))
6935 theDi << theArgVec[0] << ": view is not found.\n";
6939 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
6940 switch (atoi (theArgVec[2]))
6942 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
6943 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
6944 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
6946 theDi << theArgVec[0] << ": invalid mode.\n";
6954 //===============================================================================================
6955 //function : VZRange
6957 //===============================================================================================
6958 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6960 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
6962 if (aCurrentView.IsNull())
6964 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
6968 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
6972 theDi << "ZNear: " << aCamera->ZNear() << "\n";
6973 theDi << "ZFar: " << aCamera->ZFar() << "\n";
6979 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
6980 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
6982 if (aNewZNear >= aNewZFar)
6984 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
6988 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
6990 std::cout << theArgVec[0] << ": invalid arguments: ";
6991 std::cout << "znear, zfar should be positive for perspective camera.\n";
6995 aCamera->SetZRange (aNewZNear, aNewZFar);
6999 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
7003 aCurrentView->Redraw();
7008 //===============================================================================================
7009 //function : VAutoZFit
7011 //===============================================================================================
7012 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7014 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
7016 if (aCurrentView.IsNull())
7018 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
7022 Standard_Real aScale = aCurrentView->View()->AutoZFitScaleFactor();
7026 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
7032 theDi << "Auto z-fit mode: " << "\n"
7033 << "On: " << (aCurrentView->View()->AutoZFitMode() ? "enabled" : "disabled") << "\n"
7034 << "Scale: " << aScale << "\n";
7038 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
7042 aScale = Draw::Atoi (theArgVec[2]);
7045 aCurrentView->View()->SetAutoZFitMode (isOn, aScale);
7046 aCurrentView->View()->AutoZFit();
7047 aCurrentView->Redraw();
7052 //! Auxiliary function to print projection type
7053 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
7055 switch (theProjType)
7057 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
7058 case Graphic3d_Camera::Projection_Perspective: return "perspective";
7059 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
7060 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
7061 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
7066 //===============================================================================================
7067 //function : VCamera
7069 //===============================================================================================
7070 static int VCamera (Draw_Interpretor& theDI,
7071 Standard_Integer theArgsNb,
7072 const char** theArgVec)
7074 Handle(V3d_View) aView = ViewerTest::CurrentView();
7077 std::cout << "Error: no active view.\n";
7081 Handle(Graphic3d_Camera) aCamera = aView->Camera();
7084 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
7085 theDI << "FOVy: " << aCamera->FOVy() << "\n";
7086 theDI << "Distance: " << aCamera->Distance() << "\n";
7087 theDI << "IOD: " << aCamera->IOD() << "\n";
7088 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
7089 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
7090 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
7094 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7096 Standard_CString anArg = theArgVec[anArgIter];
7097 TCollection_AsciiString anArgCase (anArg);
7098 anArgCase.LowerCase();
7099 if (anArgCase == "-proj"
7100 || anArgCase == "-projection"
7101 || anArgCase == "-projtype"
7102 || anArgCase == "-projectiontype")
7104 theDI << projTypeName (aCamera->ProjectionType()) << " ";
7106 else if (anArgCase == "-ortho"
7107 || anArgCase == "-orthographic")
7109 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
7111 else if (anArgCase == "-persp"
7112 || anArgCase == "-perspective"
7113 || anArgCase == "-perspmono"
7114 || anArgCase == "-perspectivemono"
7115 || anArgCase == "-mono")
7117 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
7119 else if (anArgCase == "-stereo"
7120 || anArgCase == "-stereoscopic"
7121 || anArgCase == "-perspstereo"
7122 || anArgCase == "-perspectivestereo")
7124 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7126 else if (anArgCase == "-left"
7127 || anArgCase == "-lefteye"
7128 || anArgCase == "-monoleft"
7129 || anArgCase == "-monolefteye"
7130 || anArgCase == "-perpsleft"
7131 || anArgCase == "-perpslefteye")
7133 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
7135 else if (anArgCase == "-right"
7136 || anArgCase == "-righteye"
7137 || anArgCase == "-monoright"
7138 || anArgCase == "-monorighteye"
7139 || anArgCase == "-perpsright")
7141 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
7143 else if (anArgCase == "-dist"
7144 || anArgCase == "-distance")
7146 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7147 if (anArgValue != NULL
7148 && *anArgValue != '-')
7151 aCamera->SetDistance (Draw::Atof (anArgValue));
7154 theDI << aCamera->Distance() << " ";
7156 else if (anArgCase == "-iod")
7158 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7159 if (anArgValue != NULL
7160 && *anArgValue != '-')
7163 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
7166 theDI << aCamera->IOD() << " ";
7168 else if (anArgCase == "-iodtype")
7170 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
7171 TCollection_AsciiString anValueCase (anArgValue);
7172 anValueCase.LowerCase();
7173 if (anValueCase == "abs"
7174 || anValueCase == "absolute")
7177 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
7180 else if (anValueCase == "rel"
7181 || anValueCase == "relative")
7184 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
7187 else if (*anArgValue != '-')
7189 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
7192 switch (aCamera->GetIODType())
7194 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
7195 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
7198 else if (anArgCase == "-zfocus")
7200 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7201 if (anArgValue != NULL
7202 && *anArgValue != '-')
7205 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
7208 theDI << aCamera->ZFocus() << " ";
7210 else if (anArgCase == "-zfocustype")
7212 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
7213 TCollection_AsciiString anValueCase (anArgValue);
7214 anValueCase.LowerCase();
7215 if (anValueCase == "abs"
7216 || anValueCase == "absolute")
7219 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
7222 else if (anValueCase == "rel"
7223 || anValueCase == "relative")
7226 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
7229 else if (*anArgValue != '-')
7231 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
7234 switch (aCamera->ZFocusType())
7236 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
7237 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
7240 else if (anArgCase == "-fov"
7241 || anArgCase == "-fovy")
7243 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7244 if (anArgValue != NULL
7245 && *anArgValue != '-')
7248 aCamera->SetFOVy (Draw::Atof (anArgValue));
7251 theDI << aCamera->FOVy() << " ";
7255 std::cout << "Error: unknown argument '" << anArg << "'\n";
7260 aView->View()->AutoZFit();
7266 //! Parse stereo output mode
7267 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
7268 Graphic3d_StereoMode& theMode)
7270 TCollection_AsciiString aFlag (theArg);
7272 if (aFlag == "quadbuffer")
7274 theMode = Graphic3d_StereoMode_QuadBuffer;
7276 else if (aFlag == "anaglyph")
7278 theMode = Graphic3d_StereoMode_Anaglyph;
7280 else if (aFlag == "row"
7281 || aFlag == "rowinterlaced")
7283 theMode = Graphic3d_StereoMode_RowInterlaced;
7285 else if (aFlag == "col"
7286 || aFlag == "colinterlaced"
7287 || aFlag == "columninterlaced")
7289 theMode = Graphic3d_StereoMode_ColumnInterlaced;
7291 else if (aFlag == "chess"
7292 || aFlag == "chessboard")
7294 theMode = Graphic3d_StereoMode_ChessBoard;
7296 else if (aFlag == "sbs"
7297 || aFlag == "sidebyside")
7299 theMode = Graphic3d_StereoMode_SideBySide;
7301 else if (aFlag == "ou"
7302 || aFlag == "overunder")
7304 theMode = Graphic3d_StereoMode_OverUnder;
7306 else if (aFlag == "pageflip"
7307 || aFlag == "softpageflip")
7309 theMode = Graphic3d_StereoMode_SoftPageFlip;
7313 return Standard_False;
7315 return Standard_True;
7318 //! Parse anaglyph filter
7319 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
7320 Graphic3d_RenderingParams::Anaglyph& theFilter)
7322 TCollection_AsciiString aFlag (theArg);
7324 if (aFlag == "redcyansimple")
7326 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
7328 else if (aFlag == "redcyan"
7329 || aFlag == "redcyanoptimized")
7331 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
7333 else if (aFlag == "yellowbluesimple")
7335 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
7337 else if (aFlag == "yellowblue"
7338 || aFlag == "yellowblueoptimized")
7340 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
7342 else if (aFlag == "greenmagenta"
7343 || aFlag == "greenmagentasimple")
7345 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
7349 return Standard_False;
7351 return Standard_True;
7354 //==============================================================================
7355 //function : VStereo
7357 //==============================================================================
7359 static int VStereo (Draw_Interpretor& theDI,
7360 Standard_Integer theArgNb,
7361 const char** theArgVec)
7363 Handle(V3d_View) aView = ViewerTest::CurrentView();
7368 std::cout << "Error: no active viewer!\n";
7372 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
7373 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
7377 Handle(Graphic3d_Camera) aCamera;
7378 Graphic3d_RenderingParams* aParams = NULL;
7379 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
7380 if (!aView.IsNull())
7382 aParams = &aView->ChangeRenderingParams();
7383 aMode = aParams->StereoMode;
7384 aCamera = aView->Camera();
7387 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7388 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7390 Standard_CString anArg = theArgVec[anArgIter];
7391 TCollection_AsciiString aFlag (anArg);
7393 if (anUpdateTool.parseRedrawMode (aFlag))
7397 else if (aFlag == "0"
7400 if (++anArgIter < theArgNb)
7402 std::cout << "Error: wrong number of arguments!\n";
7406 if (!aCamera.IsNull()
7407 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
7409 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
7411 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
7414 else if (aFlag == "1"
7417 if (++anArgIter < theArgNb)
7419 std::cout << "Error: wrong number of arguments!\n";
7423 if (!aCamera.IsNull())
7425 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7427 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
7430 else if (aFlag == "-reverse"
7431 || aFlag == "-reversed"
7432 || aFlag == "-swap")
7434 Standard_Boolean toEnable = Standard_True;
7435 if (++anArgIter < theArgNb
7436 && !parseOnOff (theArgVec[anArgIter], toEnable))
7440 aParams->ToReverseStereo = toEnable;
7442 else if (aFlag == "-noreverse"
7443 || aFlag == "-noswap")
7445 Standard_Boolean toDisable = Standard_True;
7446 if (++anArgIter < theArgNb
7447 && !parseOnOff (theArgVec[anArgIter], toDisable))
7451 aParams->ToReverseStereo = !toDisable;
7453 else if (aFlag == "-mode"
7454 || aFlag == "-stereomode")
7456 if (++anArgIter >= theArgNb
7457 || !parseStereoMode (theArgVec[anArgIter], aMode))
7459 std::cout << "Error: syntax error at '" << anArg << "'\n";
7463 if (aMode == Graphic3d_StereoMode_QuadBuffer)
7465 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
7468 else if (aFlag == "-anaglyph"
7469 || aFlag == "-anaglyphfilter")
7471 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
7472 if (++anArgIter >= theArgNb
7473 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
7475 std::cout << "Error: syntax error at '" << anArg << "'\n";
7479 aMode = Graphic3d_StereoMode_Anaglyph;
7480 aParams->AnaglyphFilter = aFilter;
7482 else if (parseStereoMode (anArg, aMode)) // short syntax
7484 if (aMode == Graphic3d_StereoMode_QuadBuffer)
7486 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
7491 std::cout << "Error: syntax error at '" << anArg << "'\n";
7496 if (!aView.IsNull())
7498 aParams->StereoMode = aMode;
7499 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7504 //===============================================================================================
7505 //function : VDefaults
7507 //===============================================================================================
7508 static int VDefaults (Draw_Interpretor& theDi,
7509 Standard_Integer theArgsNb,
7510 const char** theArgVec)
7512 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
7515 std::cerr << "No active viewer!\n";
7519 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
7522 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
7524 theDi << "DeflType: relative\n"
7525 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
7529 theDi << "DeflType: absolute\n"
7530 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
7532 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
7533 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
7537 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7539 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7541 if (anArg == "-ABSDEFL"
7542 || anArg == "-ABSOLUTEDEFLECTION"
7544 || anArg == "-DEFLECTION")
7546 if (++anArgIter >= theArgsNb)
7548 std::cout << "Error: wrong syntax at " << anArg << "\n";
7551 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
7552 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
7554 else if (anArg == "-RELDEFL"
7555 || anArg == "-RELATIVEDEFLECTION"
7556 || anArg == "-DEVCOEFF"
7557 || anArg == "-DEVIATIONCOEFF"
7558 || anArg == "-DEVIATIONCOEFFICIENT")
7560 if (++anArgIter >= theArgsNb)
7562 std::cout << "Error: wrong syntax at " << anArg << "\n";
7565 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
7566 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
7568 else if (anArg == "-ANGDEFL"
7569 || anArg == "-ANGULARDEFL"
7570 || anArg == "-ANGULARDEFLECTION")
7572 if (++anArgIter >= theArgsNb)
7574 std::cout << "Error: wrong syntax at " << anArg << "\n";
7577 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
7578 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
7580 else if (anArg == "-AUTOTR"
7581 || anArg == "-AUTOTRIANG"
7582 || anArg == "-AUTOTRIANGULATION")
7584 if (++anArgIter >= theArgsNb)
7586 std::cout << "Error: wrong syntax at " << anArg << "\n";
7589 TCollection_AsciiString aValue (theArgVec[anArgIter]);
7594 aDefParams->SetAutoTriangulation (Standard_True);
7596 else if (aValue == "off"
7599 aDefParams->SetAutoTriangulation (Standard_False);
7604 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
7611 //! Auxiliary method
7612 inline void addLight (const Handle(V3d_Light)& theLightNew,
7613 const Standard_Boolean theIsGlobal)
7615 if (theLightNew.IsNull())
7622 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
7626 ViewerTest::CurrentView()->SetLightOn (theLightNew);
7630 //! Auxiliary method
7631 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
7633 TCollection_AsciiString anArgNextCase (theArgNext);
7634 anArgNextCase.UpperCase();
7635 if (anArgNextCase.Length() > 5
7636 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
7638 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
7642 return theArgNext.IntegerValue();
7646 //===============================================================================================
7649 //===============================================================================================
7650 static int VLight (Draw_Interpretor& theDi,
7651 Standard_Integer theArgsNb,
7652 const char** theArgVec)
7654 Handle(V3d_View) aView = ViewerTest::CurrentView();
7655 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
7657 || aViewer.IsNull())
7659 std::cerr << "No active viewer!\n";
7663 Standard_Real anXYZ[3];
7664 Quantity_Coefficient anAtten[2];
7667 // print lights info
7668 Standard_Integer aLightId = 0;
7669 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId)
7671 Handle(V3d_Light) aLight = aView->ActiveLight();
7672 const Quantity_Color aColor = aLight->Color();
7673 theDi << "Light" << aLightId << "\n";
7674 switch (aLight->Type())
7678 theDi << " Type: Ambient\n";
7679 theDi << " Intensity: " << aLight->Intensity() << "\n";
7682 case V3d_DIRECTIONAL:
7684 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
7685 theDi << " Type: Directional\n";
7686 theDi << " Intensity: " << aLight->Intensity() << "\n";
7687 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7688 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
7689 if (!aLightDir.IsNull())
7691 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7692 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7693 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
7694 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7698 case V3d_POSITIONAL:
7700 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
7701 theDi << " Type: Positional\n";
7702 theDi << " Intensity: " << aLight->Intensity() << "\n";
7703 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7704 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
7705 if (!aLightPos.IsNull())
7707 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7708 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7709 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7710 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
7716 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
7717 theDi << " Type: Spot\n";
7718 theDi << " Intensity: " << aLight->Intensity() << "\n";
7719 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7720 if (!aLightSpot.IsNull())
7722 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7723 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7724 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
7725 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7726 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7727 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
7728 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
7729 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
7735 theDi << " Type: UNKNOWN\n";
7739 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
7743 Handle(V3d_Light) aLightNew;
7744 Handle(V3d_Light) aLightOld;
7745 Standard_Boolean isGlobal = Standard_True;
7746 Standard_Boolean toCreate = Standard_False;
7747 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
7749 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
7750 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
7751 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
7752 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
7753 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
7755 TCollection_AsciiString aName, aValue;
7756 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
7757 TCollection_AsciiString anArgCase (anArg);
7758 anArgCase.UpperCase();
7759 if (anArgCase.IsEqual ("NEW")
7760 || anArgCase.IsEqual ("ADD")
7761 || anArgCase.IsEqual ("CREATE"))
7763 toCreate = Standard_True;
7765 else if (anArgCase.IsEqual ("GLOB")
7766 || anArgCase.IsEqual ("GLOBAL"))
7768 isGlobal = Standard_True;
7770 else if (anArgCase.IsEqual ("LOC")
7771 || anArgCase.IsEqual ("LOCAL"))
7773 isGlobal = Standard_False;
7775 else if (anArgCase.IsEqual ("DEF")
7776 || anArgCase.IsEqual ("DEFAULTS"))
7778 toCreate = Standard_False;
7779 aViewer->SetDefaultLights();
7781 else if (anArgCase.IsEqual ("CLR")
7782 || anArgCase.IsEqual ("CLEAR"))
7784 toCreate = Standard_False;
7785 aView->InitActiveLights();
7786 while (aView->MoreActiveLights())
7788 aViewer->DelLight (aView->ActiveLight());
7789 aView->InitActiveLights();
7792 else if (anArgCase.IsEqual ("AMB")
7793 || anArgCase.IsEqual ("AMBIENT")
7794 || anArgCase.IsEqual ("AMBLIGHT"))
7796 addLight (aLightNew, isGlobal);
7799 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7802 toCreate = Standard_False;
7803 aLightNew = new V3d_AmbientLight (aViewer);
7805 else if (anArgCase.IsEqual ("DIRECTIONAL")
7806 || anArgCase.IsEqual ("DIRLIGHT"))
7808 addLight (aLightNew, isGlobal);
7811 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7814 toCreate = Standard_False;
7815 aLightNew = new V3d_DirectionalLight (aViewer);
7817 else if (anArgCase.IsEqual ("SPOT")
7818 || anArgCase.IsEqual ("SPOTLIGHT"))
7820 addLight (aLightNew, isGlobal);
7823 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7826 toCreate = Standard_False;
7827 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
7829 else if (anArgCase.IsEqual ("POSLIGHT")
7830 || anArgCase.IsEqual ("POSITIONAL"))
7832 addLight (aLightNew, isGlobal);
7835 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7838 toCreate = Standard_False;
7839 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
7841 else if (anArgCase.IsEqual ("CHANGE"))
7843 addLight (aLightNew, isGlobal);
7844 aLightNew.Nullify();
7845 if (++anArgIt >= theArgsNb)
7847 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7851 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
7852 Standard_Integer aLightIt = 0;
7853 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
7855 if (aLightIt == aLightId)
7857 aLightOld = aView->ActiveLight();
7862 if (aLightOld.IsNull())
7864 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
7868 else if (anArgCase.IsEqual ("DEL")
7869 || anArgCase.IsEqual ("DELETE"))
7871 Handle(V3d_Light) aLightDel;
7872 if (++anArgIt >= theArgsNb)
7874 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7878 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
7879 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
7880 Standard_Integer aLightIt = 0;
7881 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
7883 aLightDel = aView->ActiveLight();
7884 if (aLightIt == aLightDelId)
7889 if (!aLightDel.IsNull())
7891 aViewer->DelLight (aLightDel);
7894 else if (anArgCase.IsEqual ("COLOR")
7895 || anArgCase.IsEqual ("COLOUR"))
7897 if (++anArgIt >= theArgsNb)
7899 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7903 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
7904 anArgNext.UpperCase();
7905 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
7906 if (!aLightCurr.IsNull())
7908 aLightCurr->SetColor (aColor);
7911 else if (anArgCase.IsEqual ("POS")
7912 || anArgCase.IsEqual ("POSITION"))
7914 if ((anArgIt + 3) >= theArgsNb)
7916 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7920 anXYZ[0] = Atof (theArgVec[++anArgIt]);
7921 anXYZ[1] = Atof (theArgVec[++anArgIt]);
7922 anXYZ[2] = Atof (theArgVec[++anArgIt]);
7923 if (!aLightDir.IsNull())
7925 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7927 else if (!aLightPos.IsNull())
7929 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7931 else if (!aLightSpot.IsNull())
7933 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7937 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7941 else if (anArgCase.IsEqual ("DIR")
7942 || anArgCase.IsEqual ("DIRECTION"))
7944 if ((anArgIt + 3) >= theArgsNb)
7946 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7950 anXYZ[0] = Atof (theArgVec[++anArgIt]);
7951 anXYZ[1] = Atof (theArgVec[++anArgIt]);
7952 anXYZ[2] = Atof (theArgVec[++anArgIt]);
7953 if (!aLightDir.IsNull())
7955 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
7957 else if (!aLightSpot.IsNull())
7959 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
7963 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7967 else if (anArgCase.IsEqual ("SM")
7968 || anArgCase.IsEqual ("SMOOTHNESS"))
7970 if (++anArgIt >= theArgsNb)
7972 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7976 Standard_Real aSmoothness = Atof (theArgVec[anArgIt]);
7978 if (fabs (aSmoothness) < Precision::Confusion())
7980 aLightCurr->SetIntensity (1.f);
7982 else if (fabs (aLightCurr->Smoothness()) < Precision::Confusion())
7984 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
7988 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
7989 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
7992 if (!aLightPos.IsNull())
7994 aLightPos->SetSmoothRadius (aSmoothness);
7996 else if (!aLightDir.IsNull())
7998 aLightDir->SetSmoothAngle (aSmoothness);
8001 else if (anArgCase.IsEqual ("INT")
8002 || anArgCase.IsEqual ("INTENSITY"))
8004 if (++anArgIt >= theArgsNb)
8006 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8010 Standard_Real aIntensity = Atof (theArgVec[anArgIt]);
8012 if (!aLightCurr.IsNull())
8014 aLightCurr->SetIntensity (aIntensity);
8017 else if (anArgCase.IsEqual ("ANG")
8018 || anArgCase.IsEqual ("ANGLE"))
8020 if (++anArgIt >= theArgsNb)
8022 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8026 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
8028 if (!aLightSpot.IsNull())
8030 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
8033 else if (anArgCase.IsEqual ("CONSTATTEN")
8034 || anArgCase.IsEqual ("CONSTATTENUATION"))
8036 if (++anArgIt >= theArgsNb)
8038 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8042 if (!aLightPos.IsNull())
8044 aLightPos->Attenuation (anAtten[0], anAtten[1]);
8045 anAtten[0] = Atof (theArgVec[anArgIt]);
8046 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
8048 else if (!aLightSpot.IsNull())
8050 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
8051 anAtten[0] = Atof (theArgVec[anArgIt]);
8052 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
8056 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8060 else if (anArgCase.IsEqual ("LINATTEN")
8061 || anArgCase.IsEqual ("LINEARATTEN")
8062 || anArgCase.IsEqual ("LINEARATTENUATION"))
8064 if (++anArgIt >= theArgsNb)
8066 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8070 if (!aLightPos.IsNull())
8072 aLightPos->Attenuation (anAtten[0], anAtten[1]);
8073 anAtten[1] = Atof (theArgVec[anArgIt]);
8074 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
8076 else if (!aLightSpot.IsNull())
8078 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
8079 anAtten[1] = Atof (theArgVec[anArgIt]);
8080 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
8084 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8088 else if (anArgCase.IsEqual ("EXP")
8089 || anArgCase.IsEqual ("EXPONENT")
8090 || anArgCase.IsEqual ("SPOTEXP")
8091 || anArgCase.IsEqual ("SPOTEXPONENT"))
8093 if (++anArgIt >= theArgsNb)
8095 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8099 if (!aLightSpot.IsNull())
8101 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
8105 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8109 else if (anArgCase.IsEqual ("HEAD")
8110 || anArgCase.IsEqual ("HEADLIGHT"))
8112 if (++anArgIt >= theArgsNb)
8114 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8118 if (aLightAmb.IsNull()
8119 && !aLightCurr.IsNull())
8121 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
8125 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8131 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
8135 addLight (aLightNew, isGlobal);
8136 aViewer->UpdateLights();
8141 //=======================================================================
8142 //function : VRenderParams
8143 //purpose : Enables/disables rendering features
8144 //=======================================================================
8146 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
8147 Standard_Integer theArgNb,
8148 const char** theArgVec)
8150 Handle(V3d_View) aView = ViewerTest::CurrentView();
8153 std::cerr << "Error: no active viewer!\n";
8157 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
8158 TCollection_AsciiString aCmdName (theArgVec[0]);
8159 aCmdName.LowerCase();
8160 if (aCmdName == "vraytrace")
8164 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
8167 else if (theArgNb == 2)
8169 TCollection_AsciiString aValue (theArgVec[1]);
8174 aParams.Method = Graphic3d_RM_RAYTRACING;
8178 else if (aValue == "off"
8181 aParams.Method = Graphic3d_RM_RASTERIZATION;
8187 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
8193 std::cout << "Error: wrong number of arguments\n";
8200 theDI << "renderMode: ";
8201 switch (aParams.Method)
8203 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
8204 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
8207 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
8208 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
8209 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
8210 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
8211 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
8212 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
8213 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
8214 theDI << "shadingModel: ";
8215 switch (aView->ShadingModel())
8217 case V3d_COLOR: theDI << "color"; break;
8218 case V3d_FLAT: theDI << "flat"; break;
8219 case V3d_GOURAUD: theDI << "gouraud"; break;
8220 case V3d_PHONG: theDI << "phong"; break;
8226 Standard_Boolean toPrint = Standard_False;
8227 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
8228 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
8230 Standard_CString anArg (theArgVec[anArgIter]);
8231 TCollection_AsciiString aFlag (anArg);
8233 if (anUpdateTool.parseRedrawMode (aFlag))
8237 else if (aFlag == "-echo"
8238 || aFlag == "-print")
8240 toPrint = Standard_True;
8241 anUpdateTool.Invalidate();
8243 else if (aFlag == "-mode"
8244 || aFlag == "-rendermode"
8245 || aFlag == "-render_mode")
8249 switch (aParams.Method)
8251 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
8252 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
8258 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8262 else if (aFlag == "-ray"
8263 || aFlag == "-raytrace")
8267 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
8271 aParams.Method = Graphic3d_RM_RAYTRACING;
8273 else if (aFlag == "-rast"
8274 || aFlag == "-raster"
8275 || aFlag == "-rasterization")
8279 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
8283 aParams.Method = Graphic3d_RM_RASTERIZATION;
8285 else if (aFlag == "-raydepth"
8286 || aFlag == "-ray_depth")
8290 theDI << aParams.RaytracingDepth << " ";
8293 else if (++anArgIter >= theArgNb)
8295 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8299 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
8301 // We allow RaytracingDepth be more than 10 in case of GI enabled
8302 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
8304 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
8309 aParams.RaytracingDepth = aDepth;
8312 else if (aFlag == "-shad"
8313 || aFlag == "-shadows")
8317 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
8321 Standard_Boolean toEnable = Standard_True;
8322 if (++anArgIter < theArgNb
8323 && !parseOnOff (theArgVec[anArgIter], toEnable))
8327 aParams.IsShadowEnabled = toEnable;
8329 else if (aFlag == "-refl"
8330 || aFlag == "-reflections")
8334 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
8338 Standard_Boolean toEnable = Standard_True;
8339 if (++anArgIter < theArgNb
8340 && !parseOnOff (theArgVec[anArgIter], toEnable))
8344 aParams.IsReflectionEnabled = toEnable;
8346 else if (aFlag == "-fsaa")
8350 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
8354 Standard_Boolean toEnable = Standard_True;
8355 if (++anArgIter < theArgNb
8356 && !parseOnOff (theArgVec[anArgIter], toEnable))
8360 aParams.IsAntialiasingEnabled = toEnable;
8362 else if (aFlag == "-gleam")
8366 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
8370 Standard_Boolean toEnable = Standard_True;
8371 if (++anArgIter < theArgNb
8372 && !parseOnOff (theArgVec[anArgIter], toEnable))
8376 aParams.IsTransparentShadowEnabled = toEnable;
8378 else if (aFlag == "-gi")
8382 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
8386 Standard_Boolean toEnable = Standard_True;
8387 if (++anArgIter < theArgNb
8388 && !parseOnOff (theArgVec[anArgIter], toEnable))
8392 aParams.IsGlobalIlluminationEnabled = toEnable;
8395 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
8398 else if (aFlag == "-blockedrng"
8399 || aFlag == "-brng")
8403 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
8407 Standard_Boolean toEnable = Standard_True;
8408 if (++anArgIter < theArgNb
8409 && !parseOnOff (theArgVec[anArgIter], toEnable))
8413 aParams.CoherentPathTracingMode = toEnable;
8415 else if (aFlag == "-env")
8419 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
8423 Standard_Boolean toEnable = Standard_True;
8424 if (++anArgIter < theArgNb
8425 && !parseOnOff (theArgVec[anArgIter], toEnable))
8429 aParams.UseEnvironmentMapBackground = toEnable;
8431 else if (aFlag == "-shademodel"
8432 || aFlag == "-shadingmodel"
8433 || aFlag == "-shading")
8437 switch (aView->ShadingModel())
8439 case V3d_COLOR: theDI << "color "; break;
8440 case V3d_FLAT: theDI << "flat "; break;
8441 case V3d_GOURAUD: theDI << "gouraud "; break;
8442 case V3d_PHONG: theDI << "phong "; break;
8447 if (++anArgIter >= theArgNb)
8449 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8452 TCollection_AsciiString aMode (theArgVec[anArgIter]);
8454 if (aMode == "color"
8457 aView->SetShadingModel (V3d_COLOR);
8459 else if (aMode == "flat"
8460 || aMode == "facet")
8462 aView->SetShadingModel (V3d_FLAT);
8464 else if (aMode == "gouraud"
8465 || aMode == "vertex"
8468 aView->SetShadingModel (V3d_GOURAUD);
8470 else if (aMode == "phong"
8471 || aMode == "fragment"
8473 || aMode == "pixel")
8475 aView->SetShadingModel (V3d_PHONG);
8479 std::cout << "Error: unknown shading model '" << aMode << "'\n";
8485 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
8493 //=======================================================================
8494 //function : VProgressiveMode
8496 //=======================================================================
8498 static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
8499 Standard_Integer /*theNbArgs*/,
8500 const char** /*theArgs*/)
8502 Handle(V3d_View) aView = ViewerTest::CurrentView();
8505 std::cerr << "Error: no active viewer!\n";
8509 std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
8515 Standard_Boolean toExit = Standard_False;
8518 while (PeekMessage (&aMsg, NULL, NULL, NULL, PM_REMOVE))
8520 if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
8522 toExit = Standard_True;
8525 TranslateMessage (&aMsg);
8526 DispatchMessage (&aMsg);
8539 //=======================================================================
8540 //function : VFrustumCulling
8541 //purpose : enables/disables view volume's culling.
8542 //=======================================================================
8543 static int VFrustumCulling (Draw_Interpretor& theDI,
8544 Standard_Integer theArgNb,
8545 const char** theArgVec)
8547 Handle(V3d_View) aView = ViewerTest::CurrentView();
8550 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
8556 theDI << (aView->IsCullingEnabled() ? "on" : "off");
8559 else if (theArgNb != 2)
8561 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
8565 TCollection_AsciiString aModeStr (theArgVec[1]);
8566 aModeStr.LowerCase();
8567 Standard_Boolean toEnable = 0;
8568 if (aModeStr == "on")
8572 else if (aModeStr == "off")
8578 toEnable = Draw::Atoi (theArgVec[1]) != 0;
8581 aView->SetFrustumCulling (toEnable);
8586 //=======================================================================
8587 //function : VHighlightSelected
8589 //=======================================================================
8590 static int VHighlightSelected (Draw_Interpretor& theDI,
8591 Standard_Integer theArgNb,
8592 const char** theArgVec)
8594 if (ViewerTest::GetAISContext().IsNull())
8596 std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n";
8600 const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8604 theDI << (aContext->ToHilightSelected() ? "on" : "off");
8610 std::cout << theArgVec[0] << " error : wrong number of parameters."
8611 << "Type 'help" << theArgVec[0] << "' for more information.";
8616 TCollection_AsciiString aMode (theArgVec[1]);
8618 Standard_Boolean toEnable = Standard_False;
8619 if (aMode.IsEqual ("on"))
8621 toEnable = Standard_True;
8623 else if (aMode.IsEqual ("off"))
8625 toEnable = Standard_False;
8629 toEnable = Draw::Atoi (theArgVec[1]) != 0;
8632 if (toEnable != aContext->ToHilightSelected())
8634 aContext->SetToHilightSelected (toEnable);
8636 // Move cursor to null position and back to process updating of detection
8637 // and highlighting of selected object immediatly.
8638 Standard_Integer aPixX = 0;
8639 Standard_Integer aPixY = 0;
8640 const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager();
8642 anEventManager->GetCurrentPosition (aPixX, aPixY);
8643 anEventManager->MoveTo (0, 0);
8644 anEventManager->MoveTo (aPixX, aPixY);
8650 //=======================================================================
8651 //function : VXRotate
8653 //=======================================================================
8654 static Standard_Integer VXRotate (Draw_Interpretor& di,
8655 Standard_Integer argc,
8658 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8659 if (aContext.IsNull())
8661 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
8667 di << "ERROR : Usage : " << argv[0] << " name angle" << "\n";
8671 TCollection_AsciiString aName (argv[1]);
8672 Standard_Real anAngle = Draw::Atof (argv[2]);
8675 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
8676 Handle(AIS_InteractiveObject) anIObj;
8677 if (!aMap.IsBound2 (aName) )
8679 di << "Use 'vdisplay' before" << "\n";
8684 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
8687 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
8688 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
8690 aContext->SetLocation (anIObj, aTransform);
8691 aContext->UpdateCurrentViewer();
8697 //=======================================================================
8698 //function : ViewerCommands
8700 //=======================================================================
8702 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
8705 const char *group = "ZeViewer";
8706 theCommands.Add("vinit",
8707 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
8708 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
8710 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
8712 " - Creates new View window with specified name view_name.\n"
8713 "By default the new view is created in the viewer and in"
8714 " graphic driver shared with active view.\n"
8715 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
8716 "If driverName isn't specified the driver will be shared with active view.\n"
8717 "If viewerName isn't specified the viewer will be shared with active view.\n"
8718 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
8719 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
8720 "is used in creation of graphic driver\n"
8722 " - l, t: pixel position of left top corner of the window\n"
8723 " - w,h: width and heigth of window respectively.\n"
8724 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
8725 __FILE__,VInit,group);
8726 theCommands.Add("vclose" ,
8727 "[view_id [keep_context=0|1]]\n"
8728 "or vclose ALL - to remove all created views\n"
8729 " - removes view(viewer window) defined by its view_id.\n"
8730 " - keep_context: by default 0; if 1 and the last view is deleted"
8731 " the current context is not removed.",
8732 __FILE__,VClose,group);
8733 theCommands.Add("vactivate" ,
8735 " - activates view(viewer window) defined by its view_id",
8736 __FILE__,VActivate,group);
8737 theCommands.Add("vviewlist",
8738 "vviewlist [format={tree, long}]"
8739 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
8740 " - format: format of result output, if tree the output is a tree view;"
8741 "otherwise it's a list of full view names. By default format = tree",
8742 __FILE__,VViewList,group);
8743 theCommands.Add("vhelp" ,
8744 "vhelp : display help on the viewer commands",
8745 __FILE__,VHelp,group);
8746 theCommands.Add("vtop" ,
8747 "vtop or <T> : Top view" ,
8748 __FILE__,VTop,group);
8749 theCommands.Add("vbottom" ,
8750 "vbottom : Bottom view" ,
8751 __FILE__,VBottom,group);
8752 theCommands.Add("vleft" ,
8753 "vleft : Left view" ,
8754 __FILE__,VLeft,group);
8755 theCommands.Add("vright" ,
8756 "vright : Right view" ,
8757 __FILE__,VRight,group);
8758 theCommands.Add("vaxo" ,
8759 " vaxo or <A> : Axonometric view ",
8760 __FILE__,VAxo,group);
8761 theCommands.Add("vfront" ,
8762 "vfront : Front view" ,
8763 __FILE__,VFront,group);
8764 theCommands.Add("vback" ,
8765 "vback : Back view" ,
8766 __FILE__,VBack,group);
8767 theCommands.Add("vpick" ,
8768 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
8770 theCommands.Add("vfit" ,
8771 "vfit or <F> [-selected]"
8772 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
8773 __FILE__,VFit,group);
8774 theCommands.Add ("vfitarea",
8775 "vfitarea x1 y1 x2 y2"
8776 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
8777 "\n\t\t: Fit view to show area located between two points"
8778 "\n\t\t: given in world 2D or 3D corrdinates.",
8779 __FILE__, VFitArea, group);
8780 theCommands.Add ("vzfit", "vzfit [scale]\n"
8781 " Matches Z near, Z far view volume planes to the displayed objects.\n"
8782 " \"scale\" - specifies factor to scale computed z range.\n",
8783 __FILE__, VZFit, group);
8784 theCommands.Add("vrepaint",
8785 "vrepaint : vrepaint, force redraw",
8786 __FILE__,VRepaint,group);
8787 theCommands.Add("vclear",
8789 __FILE__,VClear,group);
8790 theCommands.Add("vsetbg",
8791 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
8792 __FILE__,VSetBg,group);
8793 theCommands.Add("vsetbgmode",
8794 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
8795 __FILE__,VSetBgMode,group);
8796 theCommands.Add("vsetgradientbg",
8797 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
8798 __FILE__,VSetGradientBg,group);
8799 theCommands.Add("vsetgrbgmode",
8800 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
8801 __FILE__,VSetGradientBgMode,group);
8802 theCommands.Add("vsetcolorbg",
8803 "vsetcolorbg : vsetcolorbg r g b : Set background color",
8804 __FILE__,VSetColorBg,group);
8805 theCommands.Add("vsetdefaultbg",
8806 "vsetdefaultbg r g b\n"
8807 "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode"
8808 "\n\t\t: Set default viewer background fill color (flat/gradient).",
8809 __FILE__,VSetDefaultBg,group);
8810 theCommands.Add("vscale",
8811 "vscale : vscale X Y Z",
8812 __FILE__,VScale,group);
8813 theCommands.Add("vzbufftrihedron",
8814 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
8815 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
8816 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
8817 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
8818 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
8819 "\n\t\t: Displays a trihedron",
8820 __FILE__,VZBuffTrihedron,group);
8821 theCommands.Add("vrotate",
8822 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
8823 "\n : Option -mouseStart starts rotation according to the mouse position"
8824 "\n : Option -mouseMove continues rotation with angle computed"
8825 "\n : from last and new mouse position."
8826 "\n : vrotate AX AY AZ [X Y Z]",
8827 __FILE__,VRotate,group);
8828 theCommands.Add("vzoom",
8829 "vzoom : vzoom coef",
8830 __FILE__,VZoom,group);
8831 theCommands.Add("vpan",
8832 "vpan : vpan dx dy",
8833 __FILE__,VPan,group);
8834 theCommands.Add("vexport",
8835 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
8836 " : exports the view to a vector file of a given format"
8837 " : notice that EMF format requires patched gl2ps",
8838 __FILE__,VExport,group);
8839 theCommands.Add("vcolorscale",
8840 "vcolorscale : vcolorscale [-range RangeMin = 0 RangeMax = 100 Intervals = 10 -font HeightFont = 16 -textpos "
8841 "Position = left -xy X = 0 Y = 0] [-noupdate|-update]: draw color scale\n"
8842 "-demo/-demoversion draw a demoversion of color scale.\n"
8843 "-show/display display color scale.\n"
8844 "-hide/erase erase color scale.\n"
8845 "Please note that -show/-hide option must be the first argument!\n"
8846 "-color Index R G B: set color for indexed interval\n"
8847 "-color Index ColorName: set color for indexed interval\n"
8848 "-colors R G B R G B ...: set colors for all intervals\n"
8849 "-colors ColorName1 ColorName2 ...: set colors for all intervals\n"
8850 "-colors supports both color names and rgb values in one call\n"
8851 "-label Index Text: set label for indexed interval\n"
8852 "-labels Text Text Text ...: set labels for all intervals\n"
8853 "-title Title [Position]: set the title for color scale with certain position. Default position = center;\n"
8854 "Available text positions: left, right, center, none;\n",
8855 __FILE__,VColorScale,group);
8856 theCommands.Add("vgraduatedtrihedron",
8857 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
8858 "\t[-namefont Name] [-valuesfont Name]\n"
8859 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
8860 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
8861 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
8862 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
8863 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
8864 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
8865 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
8866 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
8867 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
8868 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
8869 " - Displays or erases graduated trihedron"
8870 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
8871 " - namefont - font of axes names. Default: Arial\n"
8872 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
8873 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
8874 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
8875 " - valuesfont - font of axes values. Default: Arial\n"
8876 " - xcolor, ycolor, zcolor - color of axis and values\n"
8877 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
8878 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
8879 __FILE__,VGraduatedTrihedron,group);
8880 theCommands.Add("vprintview" ,
8881 "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
8882 __FILE__,VPrintView,group);
8883 theCommands.Add("vzlayer",
8884 "vzlayer add/del/get/settings/enable/disable [id]\n"
8885 " add - add new z layer to viewer and print its id\n"
8886 " del - del z layer by its id\n"
8887 " get - print sequence of z layers in increasing order of their overlay level\n"
8888 " settings - print status of z layer settings\n"
8889 " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n"
8890 " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n"
8891 " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n"
8892 "\nWhere id is the layer identificator\n"
8895 " vzlayer enable poffset 1\n"
8896 " vzlayer disable depthtest 1\n"
8898 __FILE__,VZLayer,group);
8899 theCommands.Add("vlayerline",
8900 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
8901 __FILE__,VLayerLine,group);
8902 theCommands.Add ("vgrid",
8903 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
8904 " : Mode - rectangular or circular"
8905 " : Type - lines or points",
8906 __FILE__, VGrid, group);
8907 theCommands.Add ("vpriviledgedplane",
8908 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
8909 "\n\t\t: Ox, Oy, Oz - plane origin"
8910 "\n\t\t: Nx, Ny, Nz - plane normal direction"
8911 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
8912 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
8913 __FILE__, VPriviledgedPlane, group);
8914 theCommands.Add ("vconvert",
8915 "vconvert v [Mode={window|view}]"
8916 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
8917 "\n\t\t: vconvert x y z [Mode={window|grid}]"
8918 "\n\t\t: window - convert to window coordinates, pixels"
8919 "\n\t\t: view - convert to view projection plane"
8920 "\n\t\t: grid - convert to model coordinates, given on grid"
8921 "\n\t\t: ray - convert projection ray to model coordiantes"
8922 "\n\t\t: - vconvert v window : convert view to window;"
8923 "\n\t\t: - vconvert v view : convert window to view;"
8924 "\n\t\t: - vconvert x y window : convert view to window;"
8925 "\n\t\t: - vconvert x y view : convert window to view;"
8926 "\n\t\t: - vconvert x y : convert window to model;"
8927 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
8928 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
8929 "\n\t\t: - vconvert x y z window : convert model to window;"
8930 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
8931 "\n\t\t: Converts the given coordinates to window/view/model space.",
8932 __FILE__, VConvert, group);
8933 theCommands.Add ("vfps",
8934 "vfps [framesNb=100] : estimate average frame rate for active view",
8935 __FILE__, VFps, group);
8936 theCommands.Add ("vgldebug",
8937 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
8938 "\n\t\t: [-extraMsg {0|1}] [{0|1}]"
8939 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
8940 "\n\t\t: Debug context can be requested only on Windows"
8941 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
8942 "\n\t\t: -sync - request synchronized debug GL context"
8943 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
8944 "\n\t\t: which are suppressed by default,"
8945 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
8946 "\n\t\t: which are suppressed by default",
8947 __FILE__, VGlDebug, group);
8948 theCommands.Add ("vvbo",
8949 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
8950 __FILE__, VVbo, group);
8951 theCommands.Add ("vstereo",
8952 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
8953 "\n\t\t: [-anaglyph Filter]"
8954 "\n\t\t: Control stereo output mode. Available modes for -mode:"
8955 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
8956 "\n\t\t: requires driver support."
8957 "\n\t\t: Should be called BEFORE vinit!"
8958 "\n\t\t: anaglyph - Anaglyph glasses"
8959 "\n\t\t: rowInterlaced - row-interlaced display"
8960 "\n\t\t: columnInterlaced - column-interlaced display"
8961 "\n\t\t: chessBoard - chess-board output"
8962 "\n\t\t: sideBySide - horizontal pair"
8963 "\n\t\t: overUnder - vertical pair"
8964 "\n\t\t: Available Anaglyph filters for -anaglyph:"
8965 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
8966 "\n\t\t: greenMagentaSimple",
8967 __FILE__, VStereo, group);
8968 theCommands.Add ("vcaps",
8969 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
8970 "\n\t\t: [-compatibleContext {0|1}]"
8971 "\n\t\t: [-vsync {0|1}]"
8972 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
8973 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
8974 "\n\t\t: Modify particular graphic driver options:"
8975 "\n\t\t: FFP - use fixed-function pipeline instead of"
8976 "\n\t\t: built-in GLSL programs"
8977 "\n\t\t: (requires compatible profile)"
8978 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
8979 "\n\t\t: arrays to GPU memory)"
8980 "\n\t\t: sprite - use textured sprites instead of bitmaps"
8981 "\n\t\t: vsync - switch VSync on or off"
8982 "\n\t\t: Context creation options:"
8983 "\n\t\t: softMode - software OpenGL implementation"
8984 "\n\t\t: compatibleProfile - backward-compatible profile"
8985 "\n\t\t: quadbuffer - QuadBuffer"
8986 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
8987 "\n\t\t: rendering paths producing the same visual result when"
8989 "\n\t\t: Command is intended for testing old hardware compatibility.",
8990 __FILE__, VCaps, group);
8991 theCommands.Add ("vmemgpu",
8992 "vmemgpu [f]: print system-dependent GPU memory information if available;"
8993 " with f option returns free memory in bytes",
8994 __FILE__, VMemGpu, group);
8995 theCommands.Add ("vreadpixel",
8996 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
8997 " : Read pixel value for active view",
8998 __FILE__, VReadPixel, group);
8999 theCommands.Add("diffimage",
9000 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
9001 __FILE__, VDiffImage, group);
9002 theCommands.Add ("vselect",
9003 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
9004 "- emulates different types of selection:\n"
9005 "- 1) single click selection\n"
9006 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
9007 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
9008 "- 4) -allowoverlap determines will partially included objects be selected in rectangular selection"
9009 " (partial inclusion - overlap - is not allowed by default)\n"
9010 "- 5) any of these selections with shift button pressed",
9011 __FILE__, VSelect, group);
9012 theCommands.Add ("vmoveto",
9014 "- emulates cursor movement to pixel postion (x,y)",
9015 __FILE__, VMoveTo, group);
9016 theCommands.Add ("vviewparams", "vviewparams usage:\n"
9018 "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n"
9019 " [-proj [x y z]] [-center x y] [-size sx]\n"
9020 "- Gets or sets current view parameters.\n"
9021 "- If called without arguments, all view parameters are printed.\n"
9022 "- The options are:\n"
9023 " -scale [s] : prints or sets viewport relative scale.\n"
9024 " -eye [x y z] : prints or sets eye location.\n"
9025 " -at [x y z] : prints or sets center of look.\n"
9026 " -up [x y z] : prints or sets direction of up vector.\n"
9027 " -proj [x y z] : prints or sets direction of look.\n"
9028 " -center x y : sets location of center of the screen in pixels.\n"
9029 " -size [sx] : prints viewport projection width and height sizes\n"
9030 " : or changes the size of its maximum dimension.\n",
9031 __FILE__, VViewParams, group);
9032 theCommands.Add("vchangeselected",
9033 "vchangeselected shape"
9034 "- adds to shape to selection or remove one from it",
9035 __FILE__, VChangeSelected, group);
9036 theCommands.Add("vzclipping",
9037 "vzclipping [mode] [depth width]\n"
9038 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
9039 "- gets or sets ZClipping mode, width and depth",
9040 __FILE__,VZClipping,group);
9041 theCommands.Add ("vnbselected",
9042 "vnbselected", __FILE__, VNbSelected, group);
9043 theCommands.Add ("vcamera",
9044 "vcamera [-ortho] [-projtype]"
9046 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
9047 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
9048 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
9049 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
9050 "\n\t\t: Manage camera parameters."
9051 "\n\t\t: Prints current value when option called without argument."
9052 "\n\t\t: Orthographic camera:"
9053 "\n\t\t: -ortho activate orthographic projection"
9054 "\n\t\t: Perspective camera:"
9055 "\n\t\t: -persp activate perspective projection (mono)"
9056 "\n\t\t: -fovy field of view in y axis, in degrees"
9057 "\n\t\t: -distance distance of eye from camera center"
9058 "\n\t\t: Stereoscopic camera:"
9059 "\n\t\t: -stereo perspective projection (stereo)"
9060 "\n\t\t: -leftEye perspective projection (left eye)"
9061 "\n\t\t: -rightEye perspective projection (right eye)"
9062 "\n\t\t: -iod intraocular distance value"
9063 "\n\t\t: -iodType distance type, absolute or relative"
9064 "\n\t\t: -zfocus stereographic focus value"
9065 "\n\t\t: -zfocusType focus type, absolute or relative",
9066 __FILE__, VCamera, group);
9067 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
9068 "- vautozfit [on={1|0}] [scale]\n"
9069 " Prints or changes parameters of automatic z-fit mode:\n"
9070 " \"on\" - turns automatic z-fit on or off\n"
9071 " \"scale\" - specifies factor to scale computed z range.\n",
9072 __FILE__, VAutoZFit, group);
9073 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
9074 " vzrange - without parameters shows current values\n"
9075 " vzrange [znear] [zfar] - applies provided values to view",
9076 __FILE__,VZRange, group);
9077 theCommands.Add("vantialiasing",
9078 "vantialiasing 1|0",
9079 __FILE__,VAntialiasing,group);
9080 theCommands.Add ("vpurgedisplay",
9082 "- removes structures which don't belong to objects displayed in neutral point",
9083 __FILE__, VPurgeDisplay, group);
9084 theCommands.Add("vsetviewsize",
9085 "vsetviewsize size",
9086 __FILE__,VSetViewSize,group);
9087 theCommands.Add("vmoveview",
9088 "vmoveview Dx Dy Dz [Start = 1|0]",
9089 __FILE__,VMoveView,group);
9090 theCommands.Add("vtranslateview",
9091 "vtranslateview Dx Dy Dz [Start = 1|0)]",
9092 __FILE__,VTranslateView,group);
9093 theCommands.Add("vturnview",
9094 "vturnview Ax Ay Az [Start = 1|0]",
9095 __FILE__,VTurnView,group);
9096 theCommands.Add("vtextureenv",
9097 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
9098 "or user-defined file and optionally applying texture mapping parameters\n"
9100 " vtextureenv off - disables environment mapping\n"
9101 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
9102 " std_texture = (0..7)\n"
9103 " rep = {clamp|repeat}\n"
9104 " mod = {decal|modulate}\n"
9105 " flt = {nearest|bilinear|trilinear}\n"
9106 " ss, st - scale factors for s and t texture coordinates\n"
9107 " ts, tt - translation for s and t texture coordinates\n"
9108 " rot - texture rotation angle in degrees",
9109 __FILE__, VTextureEnv, group);
9110 theCommands.Add("vhlr" ,
9111 "is_enabled={on|off} [show_hidden={1|0}]"
9112 " - Hidden line removal algorithm:"
9113 " - is_enabled: if is on HLR algorithm is applied\n"
9114 " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n",
9115 __FILE__,VHLR,group);
9116 theCommands.Add("vhlrtype" ,
9117 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
9118 " - Changes the type of HLR algorithm using for shapes."
9119 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
9120 " if equals to polyalgo, polygonal HLR algorithm is applied."
9121 "If shapes are not given HLR algoithm of given type is applied"
9122 " to all shapes in the view\n",
9123 __FILE__,VHLRType,group);
9124 theCommands.Add("vclipplane", "vclipplane usage: \n"
9125 " maxplanes <view_name> - get plane limit for view.\n"
9126 " create <plane_name> - create new plane.\n"
9127 " delete <plane_name> - delete plane.\n"
9128 " clone <source_plane> <plane_name> - clone the plane definition.\n"
9129 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
9130 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
9131 " change <plane_name> on/off - turn clipping on/off.\n"
9132 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
9133 " change <plane_name> capping on/off - turn capping on/off.\n"
9134 " change <plane_name> capping color <r> <g> <b> - set color.\n"
9135 " change <plane name> capping texname <texture> - set texture.\n"
9136 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
9137 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
9138 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
9139 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
9140 " please use VSetTextureMode command to enable texture rendering in view.\n"
9141 , __FILE__, VClipPlane, group);
9142 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
9144 " 0 - no textures enabled in view.\n"
9145 " 1 - only environment textures enabled.\n"
9146 " 2 - all textures enabled.\n"
9147 " this command sets texture details mode for the specified view.\n"
9148 , __FILE__, VSetTextureMode, group);
9149 theCommands.Add("vdefaults",
9150 "vdefaults [-absDefl value]"
9151 "\n\t\t: [-devCoeff value]"
9152 "\n\t\t: [-angDefl value]"
9153 "\n\t\t: [-autoTriang {off/on | 0/1}]"
9154 , __FILE__, VDefaults, group);
9155 theCommands.Add("vlight",
9156 "tool to manage light sources, without arguments shows list of lights."
9157 "\n Main commands: "
9158 "\n 'clear' to clear lights"
9159 "\n '{def}aults' to load deafault lights"
9160 "\n 'add' (or 'new') <type> to add any light source"
9161 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
9162 "\n 'change' <lightId> to edit light source with specified lightId"
9163 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
9164 "\n {pos}ition X Y Z"
9165 "\n {dir}ection X Y Z (for directional light or for spotlight)"
9166 "\n color colorName"
9167 "\n {head}light 0|1"
9168 "\n {sm}oothness value"
9169 "\n {int}ensity value"
9170 "\n {constAtten}uation value"
9171 "\n {linearAtten}uation value"
9173 "\n {spotexp}onent value"
9175 "\n\n example: vlight add positional head 1 pos 0 1 1 color red"
9176 "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
9177 __FILE__, VLight, group);
9178 theCommands.Add("vraytrace",
9180 "\n\t\t: Turns on/off ray-tracing renderer."
9181 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
9182 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
9183 __FILE__, VRenderParams, group);
9184 theCommands.Add("vrenderparams",
9185 "\n Manages rendering parameters: "
9186 "\n '-rayTrace' Enables GPU ray-tracing"
9187 "\n '-raster' Disables GPU ray-tracing"
9188 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
9189 "\n '-shadows on|off' Enables/disables shadows rendering"
9190 "\n '-reflections on|off' Enables/disables specular reflections"
9191 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
9192 "\n '-gleam on|off' Enables/disables transparency shadow effects"
9193 "\n '-gi on|off' Enables/disables global illumination effects"
9194 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
9195 "\n '-env on|off' Enables/disables environment map background"
9196 "\n '-shadingModel model' Controls shading model from enumeration"
9197 "\n color, flat, gouraud, phong"
9198 "\n Unlike vcaps, these parameters dramatically change visual properties."
9199 "\n Command is intended to control presentation quality depending on"
9200 "\n hardware capabilities and performance.",
9201 __FILE__, VRenderParams, group);
9202 theCommands.Add("vfrustumculling",
9203 "vfrustumculling [toEnable]: enables/disables objects clipping",
9204 __FILE__,VFrustumCulling,group);
9205 theCommands.Add("vhighlightselected",
9206 "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n"
9207 "Without arguments it shows if highlighting of selected objects is enabled now.",
9208 __FILE__,VHighlightSelected,group);
9209 theCommands.Add ("vplace",
9211 "\n\t\t: Places the point (in pixels) at the center of the window",
9212 __FILE__, VPlace, group);
9213 theCommands.Add("vxrotate",
9215 __FILE__,VXRotate,group);
9218 theCommands.Add("vprogressive",
9220 __FILE__, VProgressiveMode, group);