1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <OpenGl_GlCore20.hxx>
18 #include <AIS_ColorScale.hxx>
19 #include <AIS_Manipulator.hxx>
20 #include <AIS_RubberBand.hxx>
21 #include <AIS_Shape.hxx>
22 #include <AIS_InteractiveObject.hxx>
23 #include <AIS_ListOfInteractive.hxx>
24 #include <AIS_ListIteratorOfListOfInteractive.hxx>
26 #include <Graphic3d_ArrayOfPolylines.hxx>
27 #include <Graphic3d_AspectMarker3d.hxx>
28 #include <Graphic3d_ExportFormat.hxx>
29 #include <Graphic3d_NameOfTextureEnv.hxx>
30 #include <Graphic3d_GraduatedTrihedron.hxx>
31 #include <Graphic3d_TextureEnv.hxx>
32 #include <Graphic3d_TextureParams.hxx>
33 #include <Graphic3d_TypeOfTextureFilter.hxx>
34 #include <Graphic3d_AspectFillArea3d.hxx>
35 #include <ViewerTest.hxx>
36 #include <ViewerTest_AutoUpdater.hxx>
37 #include <ViewerTest_EventManager.hxx>
38 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
39 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
40 #include <ViewerTest_CmdParser.hxx>
41 #include <V3d_AmbientLight.hxx>
42 #include <V3d_DirectionalLight.hxx>
43 #include <V3d_PositionalLight.hxx>
44 #include <V3d_SpotLight.hxx>
45 #include <NCollection_DoubleMap.hxx>
46 #include <NCollection_List.hxx>
47 #include <NCollection_Vector.hxx>
48 #include <AIS_InteractiveContext.hxx>
49 #include <Draw_Interpretor.hxx>
51 #include <Draw_Appli.hxx>
52 #include <Image_AlienPixMap.hxx>
53 #include <OpenGl_GraphicDriver.hxx>
54 #include <OSD_Timer.hxx>
55 #include <TColStd_HSequenceOfAsciiString.hxx>
56 #include <TColStd_SequenceOfInteger.hxx>
57 #include <TColStd_HSequenceOfReal.hxx>
58 #include <TColgp_Array1OfPnt2d.hxx>
59 #include <TColStd_MapOfAsciiString.hxx>
60 #include <Aspect_TypeOfLine.hxx>
61 #include <Image_Diff.hxx>
62 #include <Aspect_DisplayConnection.hxx>
66 #include <PrsMgr_PresentableObject.hxx>
67 #include <Graphic3d_ClipPlane.hxx>
68 #include <NCollection_DataMap.hxx>
69 #include <Graphic3d_Texture2Dmanual.hxx>
70 #include <Prs3d_ShadingAspect.hxx>
71 #include <Prs3d_Drawer.hxx>
72 #include <Prs3d_LineAspect.hxx>
73 #include <Prs3d_Root.hxx>
82 #include <WNT_WClass.hxx>
83 #include <WNT_Window.hxx>
84 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
85 #include <Cocoa_Window.hxx>
87 #include <Xw_Window.hxx>
88 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
89 #include <X11/Xutil.h>
93 // Auxiliary definitions
94 static const char THE_KEY_DELETE = 127;
96 //==============================================================================
97 // VIEWER GLOBAL VARIABLES
98 //==============================================================================
100 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
101 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
103 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
104 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
106 extern int VErase (Draw_Interpretor& theDI,
107 Standard_Integer theArgNb,
108 const char** theArgVec);
111 static Handle(WNT_Window)& VT_GetWindow() {
112 static Handle(WNT_Window) WNTWin;
115 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
116 static Handle(Cocoa_Window)& VT_GetWindow()
118 static Handle(Cocoa_Window) aWindow;
121 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
122 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
123 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
126 static Handle(Xw_Window)& VT_GetWindow(){
127 static Handle(Xw_Window) XWWin;
131 static void VProcessEvents(ClientData,int);
134 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
136 static Handle(Aspect_DisplayConnection) aDisplayConnection;
137 return aDisplayConnection;
140 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
142 GetDisplayConnection() = theDisplayConnection;
145 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
146 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
148 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
150 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
151 if (!aWindow.IsNull())
152 return aWindow->HWindow();
153 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
154 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
155 if (!aWindow.IsNull())
156 return aWindow->XWindow();
158 return aWindowHandle;
162 static Standard_Boolean MyHLRIsOn = Standard_False;
164 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
165 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
166 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
167 static OpenGl_Caps ViewerTest_myDefaultCaps;
169 static void OSWindowSetup();
173 Quantity_Color FlatColor;
174 Quantity_Color GradientColor1;
175 Quantity_Color GradientColor2;
176 Aspect_GradientFillMethod FillMethod;
177 } ViewerTest_DefaultBackground = { Quantity_NOC_BLACK, Quantity_NOC_BLACK, Quantity_NOC_BLACK, Aspect_GFM_NONE };
179 //==============================================================================
180 // EVENT GLOBAL VARIABLES
181 //==============================================================================
183 static int Start_Rot = 0;
184 int X_Motion = 0; // Current cursor position
186 int X_ButtonPress = 0; // Last ButtonPress position
187 int Y_ButtonPress = 0;
188 Standard_Boolean IsDragged = Standard_False;
189 Standard_Boolean DragFirst = Standard_False;
192 Standard_EXPORT const Handle(AIS_RubberBand)& GetRubberBand()
194 static Handle(AIS_RubberBand) aBand;
197 aBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE, 0.4, 1.0);
198 aBand->SetDisplayMode (0);
203 typedef NCollection_Map<AIS_Manipulator*> ViewerTest_MapOfAISManipulators;
205 Standard_EXPORT ViewerTest_MapOfAISManipulators& GetMapOfAISManipulators()
207 static ViewerTest_MapOfAISManipulators aMap;
211 Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator()
213 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
214 for (; anIt.More(); anIt.Next())
216 if (anIt.Value()->HasActiveMode())
224 //==============================================================================
227 static LRESULT WINAPI ViewerWindowProc(
232 static LRESULT WINAPI AdvViewerWindowProc(
240 //==============================================================================
243 //==============================================================================
245 const Handle(MMgt_TShared)& ViewerTest::WClass()
247 static Handle(MMgt_TShared) theWClass;
249 if (theWClass.IsNull())
251 theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
252 CS_VREDRAW | CS_HREDRAW, 0, 0,
253 ::LoadCursor (NULL, IDC_ARROW));
259 //==============================================================================
260 //function : CreateName
261 //purpose : Create numerical name for new object in theMap
262 //==============================================================================
263 template <typename ObjectType>
264 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
265 const TCollection_AsciiString& theDefaultString)
267 if (theObjectMap.IsEmpty())
268 return theDefaultString + TCollection_AsciiString(1);
270 Standard_Integer aNextKey = 1;
271 Standard_Boolean isFound = Standard_False;
274 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
275 // Look for objects with default names
276 if (theObjectMap.IsBound1(aStringKey))
281 isFound = Standard_True;
284 return theDefaultString + TCollection_AsciiString(aNextKey);
287 //==============================================================================
288 //structure : ViewerTest_Names
289 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
290 //==============================================================================
291 struct ViewerTest_Names
294 TCollection_AsciiString myDriverName;
295 TCollection_AsciiString myViewerName;
296 TCollection_AsciiString myViewName;
300 const TCollection_AsciiString& GetDriverName () const
304 void SetDriverName (const TCollection_AsciiString& theDriverName)
306 myDriverName = theDriverName;
308 const TCollection_AsciiString& GetViewerName () const
312 void SetViewerName (const TCollection_AsciiString& theViewerName)
314 myViewerName = theViewerName;
316 const TCollection_AsciiString& GetViewName () const
320 void SetViewName (const TCollection_AsciiString& theViewName)
322 myViewName = theViewName;
325 //===========================================================================
326 //function : Constructor for ViewerTest_Names
327 //purpose : Get view, viewer, driver names from custom string
328 //===========================================================================
330 ViewerTest_Names (const TCollection_AsciiString& theInputString)
332 TCollection_AsciiString aName(theInputString);
333 if (theInputString.IsEmpty())
335 // Get current configuration
336 if (ViewerTest_myDrivers.IsEmpty())
337 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
338 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
340 myDriverName = ViewerTest_myDrivers.Find2
341 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
343 if(ViewerTest_myContexts.IsEmpty())
345 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
346 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
349 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
351 myViewName = CreateName <Handle(V3d_View)>
352 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
356 // There is at least view name
357 Standard_Integer aParserNumber = 0;
358 for (Standard_Integer i = 0; i < 3; ++i)
360 Standard_Integer aParserPos = aName.SearchFromEnd("/");
364 aName.Split(aParserPos-1);
369 if (aParserNumber == 0)
372 if (!ViewerTest::GetAISContext().IsNull())
374 myDriverName = ViewerTest_myDrivers.Find2
375 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
376 myViewerName = ViewerTest_myContexts.Find2
377 (ViewerTest::GetAISContext());
381 // There is no opened contexts here, need to create names for viewer and driver
382 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
383 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
385 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
386 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
388 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
390 else if (aParserNumber == 1)
392 // Here is viewerName/viewName
393 if (!ViewerTest::GetAISContext().IsNull())
394 myDriverName = ViewerTest_myDrivers.Find2
395 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
398 // There is no opened contexts here, need to create name for driver
399 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
400 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
402 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
404 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
408 //Here is driverName/viewerName/viewName
409 myDriverName = TCollection_AsciiString(aName);
411 TCollection_AsciiString aViewerName(theInputString);
412 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
413 myViewerName = TCollection_AsciiString(aViewerName);
415 myViewName = TCollection_AsciiString(theInputString);
421 //==============================================================================
422 //function : FindContextByView
423 //purpose : Find AIS_InteractiveContext by View
424 //==============================================================================
426 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
428 Handle(AIS_InteractiveContext) anAISContext;
430 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
431 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
433 if (anIter.Value()->CurrentViewer() == theView->Viewer())
434 return anIter.Key2();
440 //==============================================================================
441 //function : SetWindowTitle
442 //purpose : Set window title
443 //==============================================================================
445 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
446 Standard_CString theTitle)
449 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
451 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
452 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
454 if(GetDisplayConnection()->GetDisplay())
457 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
458 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
463 //==============================================================================
464 //function : IsWindowOverlapped
465 //purpose : Check if theWindow overlapp another view
466 //==============================================================================
468 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
469 const Standard_Integer thePxTop,
470 const Standard_Integer thePxRight,
471 const Standard_Integer thePxBottom,
472 TCollection_AsciiString& theViewId)
474 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
475 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
477 Standard_Integer aTop = 0,
481 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
482 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
483 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
484 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
485 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
487 theViewId = anIter.Key1();
488 return Standard_True;
491 return Standard_False;
494 // Workaround: to create and delete non-orthographic views outside ViewerTest
495 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
497 ViewerTest_myViews.UnBind1 (theName);
500 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
501 const Handle(V3d_View)& theView)
503 ViewerTest_myViews.Bind (theName, theView);
506 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
508 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
510 //==============================================================================
511 //function : ViewerInit
512 //purpose : Create the window viewer and initialize all the global variable
513 //==============================================================================
515 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
516 const Standard_Integer thePxTop,
517 const Standard_Integer thePxWidth,
518 const Standard_Integer thePxHeight,
519 Standard_CString theViewName,
520 Standard_CString theDisplayName)
522 // Default position and dimension of the viewer window.
523 // Note that left top corner is set to be sufficiently small to have
524 // window fit in the small screens (actual for remote desktops, see #23003).
525 // The position corresponds to the window's client area, thus some
526 // gap is added for window frame to be visible.
527 Standard_Integer aPxLeft = 20;
528 Standard_Integer aPxTop = 40;
529 Standard_Integer aPxWidth = 409;
530 Standard_Integer aPxHeight = 409;
531 Standard_Boolean toCreateViewer = Standard_False;
533 Handle(OpenGl_GraphicDriver) aGraphicDriver;
534 ViewerTest_Names aViewNames(theViewName);
535 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
536 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
543 aPxWidth = thePxWidth;
544 if (thePxHeight != 0)
545 aPxHeight = thePxHeight;
547 // Get graphic driver (create it or get from another view)
548 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
550 // Get connection string
551 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
552 TCollection_AsciiString aDisplayName(theDisplayName);
553 if (!aDisplayName.IsEmpty())
554 SetDisplayConnection (new Aspect_DisplayConnection ());
556 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
558 (void)theDisplayName; // avoid warning on unused argument
559 SetDisplayConnection (new Aspect_DisplayConnection ());
562 if (Draw_VirtualWindows)
564 // don't waste the time waiting for VSync when window is not displayed on the screen
565 ViewerTest_myDefaultCaps.swapInterval = 0;
566 // alternatively we can disable buffer swap at all, but this might be inappropriate for testing
567 //ViewerTest_myDefaultCaps.buffersNoSwap = true;
569 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
570 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
572 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
573 toCreateViewer = Standard_True;
577 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
580 //Dispose the window if input parameters are default
581 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
583 Standard_Integer aTop = 0,
590 // Get screen resolution
591 #if defined(_WIN32) || defined(__WIN32__)
593 GetClientRect(GetDesktopWindow(), &aWindowSize);
594 aScreenHeight = aWindowSize.bottom;
595 aScreenWidth = aWindowSize.right;
596 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
597 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
599 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
600 aScreenWidth = WidthOfScreen(aScreen);
601 aScreenHeight = HeightOfScreen(aScreen);
604 TCollection_AsciiString anOverlappedViewId("");
606 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
608 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
610 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
611 && aRight + 2*aPxWidth + 40 > aScreenWidth)
613 if (aBottom + aPxHeight + 40 > aScreenHeight)
620 aPxTop = aBottom + 40;
623 aPxLeft = aRight + 20;
628 TCollection_AsciiString aTitle("3D View - ");
629 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
631 // Change name of current active window
632 if (!ViewerTest::CurrentView().IsNull())
634 TCollection_AsciiString anActiveWindowTitle("3D View - ");
635 anActiveWindowTitle = anActiveWindowTitle
636 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
637 SetWindowTitle (ViewerTest::CurrentView()->Window(), anActiveWindowTitle.ToCString());
641 Handle(V3d_Viewer) a3DViewer;
642 // If it's the single view, we first look for empty context
643 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
645 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
646 anIter(ViewerTest_myContexts);
648 ViewerTest::SetAISContext (anIter.Value());
649 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
651 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
653 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
654 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
656 else if (a3DViewer.IsNull())
658 toCreateViewer = Standard_True;
659 TCollection_ExtendedString NameOfWindow("Viewer3D");
660 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
661 a3DViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
662 a3DViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
663 ViewerTest_DefaultBackground.GradientColor2,
664 ViewerTest_DefaultBackground.FillMethod);
668 if (ViewerTest::GetAISContext().IsNull() ||
669 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
671 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
672 ViewerTest::SetAISContext (aContext);
673 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
677 ViewerTest::ResetEventManager();
682 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
683 Handle(WNT_WClass)::DownCast (WClass()),
684 Draw_VirtualWindows ? WS_POPUP : WS_OVERLAPPEDWINDOW,
688 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
689 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
691 aPxWidth, aPxHeight);
692 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
694 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
697 aPxWidth, aPxHeight);
699 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
702 Handle(V3d_View) aView = a3DViewer->CreateView();
703 aView->SetWindow (VT_GetWindow());
704 ViewerTest::GetAISContext()->RedrawImmediate (a3DViewer);
706 ViewerTest::CurrentView(aView);
707 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
709 // Setup for X11 or NT
712 // Set parameters for V3d_View and V3d_Viewer
713 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
714 aV3dView->SetComputedMode(Standard_False);
715 MyHLRIsOn = aV3dView->ComputedMode();
717 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
720 a3DViewer->SetDefaultLights();
721 a3DViewer->SetLightOn();
724 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
725 #if TCL_MAJOR_VERSION < 8
726 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
727 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
729 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
730 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
734 VT_GetWindow()->Map();
736 // Set the handle of created view in the event manager
737 ViewerTest::ResetEventManager();
739 ViewerTest::CurrentView()->Redraw();
744 return aViewNames.GetViewName();
747 //==============================================================================
748 //function : RedrawAllViews
749 //purpose : Redraw all created views
750 //==============================================================================
751 void ViewerTest::RedrawAllViews()
753 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
754 for (; aViewIt.More(); aViewIt.Next())
756 const Handle(V3d_View)& aView = aViewIt.Key2();
761 //==============================================================================
763 //purpose : Create the window viewer and initialize all the global variable
764 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
765 //==============================================================================
767 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
771 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
772 << "Type help for more information.\n";
776 TCollection_AsciiString aViewName, aDisplayName;
777 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
778 TCollection_AsciiString aName, aValue;
779 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
781 const TCollection_AsciiString anArg = theArgVec[anArgIt];
782 TCollection_AsciiString anArgCase = anArg;
783 anArgCase.UpperCase();
784 if (ViewerTest::SplitParameter (anArg, aName, aValue))
787 if (aName.IsEqual ("NAME"))
791 else if (aName.IsEqual ("L")
792 || aName.IsEqual ("LEFT"))
794 aPxLeft = aValue.IntegerValue();
796 else if (aName.IsEqual ("T")
797 || aName.IsEqual ("TOP"))
799 aPxTop = aValue.IntegerValue();
801 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
802 else if (aName.IsEqual ("DISP")
803 || aName.IsEqual ("DISPLAY"))
805 aDisplayName = aValue;
808 else if (aName.IsEqual ("W")
809 || aName.IsEqual ("WIDTH"))
811 aPxWidth = aValue.IntegerValue();
813 else if (aName.IsEqual ("H")
814 || aName.IsEqual ("HEIGHT"))
816 aPxHeight = aValue.IntegerValue();
820 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
823 else if (aViewName.IsEmpty())
829 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
833 ViewerTest_Names aViewNames (aViewName);
834 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
836 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
837 theDi.Eval (aCommand.ToCString());
841 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
842 aViewName.ToCString(),
843 aDisplayName.ToCString());
848 //==============================================================================
850 //purpose : hidden lines removal algorithm
851 //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}]
852 //==============================================================================
854 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
856 if (ViewerTest::CurrentView().IsNull())
858 di << argv[0] << ": Call vinit before this command, please.\n";
864 di << argv[0] << ": Wrong number of command arguments.\n"
865 << "Type help " << argv[0] << " for more information.\n";
869 // Enable or disable HLR mode.
870 Standard_Boolean isHLROn =
871 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
873 if (isHLROn != MyHLRIsOn)
876 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
879 // Show or hide hidden lines in HLR mode.
880 Standard_Boolean isCurrentShowHidden
881 = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine();
883 Standard_Boolean isShowHidden =
884 (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False)
885 : isCurrentShowHidden;
888 if (isShowHidden != isCurrentShowHidden)
892 ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine();
896 ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine();
902 AIS_ListOfInteractive aListOfShapes;
903 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
905 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
907 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value());
912 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
917 ViewerTest::CurrentView()->Update();
921 //==============================================================================
922 //function : VHLRType
923 //purpose : change type of using HLR algorithm
924 //==============================================================================
926 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
928 if (ViewerTest::CurrentView().IsNull())
930 di << argv[0] << ": Call vinit before this command, please.\n";
936 di << argv[0] << ": Wrong number of command arguments.\n"
937 << "Type help " << argv[0] << " for more information.\n";
941 Prs3d_TypeOfHLR aTypeOfHLR =
942 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
946 AIS_ListOfInteractive aListOfShapes;
947 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
948 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
949 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
950 anIter.More(); anIter.Next())
952 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
955 if (aShape->TypeOfHLR() != aTypeOfHLR)
956 aShape->SetTypeOfHLR (aTypeOfHLR);
958 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
960 ViewerTest::CurrentView()->Update();
965 for (Standard_Integer i = 2; i < argc; ++i)
967 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
968 TCollection_AsciiString aName (argv[i]);
970 if (!aMap.IsBound2 (aName))
972 di << argv[0] << ": Wrong shape name:" << aName.ToCString() << ".\n";
975 Handle(AIS_Shape) anAISObject =
976 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
977 if (anAISObject.IsNull())
979 anAISObject->SetTypeOfHLR (aTypeOfHLR);
981 ViewerTest::GetAISContext()->Redisplay (anAISObject, Standard_False);
983 ViewerTest::CurrentView()->Update();
989 //==============================================================================
990 //function : FindViewIdByWindowHandle
991 //purpose : Find theView Id in the map of views by window handle
992 //==============================================================================
993 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
994 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
996 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
997 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
999 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
1000 if (aWindowHandle == theWindowHandle)
1001 return anIter.Key1();
1003 return TCollection_AsciiString("");
1007 //==============================================================================
1008 //function : ActivateView
1009 //purpose : Make the view active
1010 //==============================================================================
1012 void ActivateView (const TCollection_AsciiString& theViewName)
1014 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1015 if (!aView.IsNull())
1017 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1018 if (!anAISContext.IsNull())
1020 if (!ViewerTest::CurrentView().IsNull())
1022 TCollection_AsciiString aTitle("3D View - ");
1023 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1024 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1027 ViewerTest::CurrentView (aView);
1028 // Update degenerate mode
1029 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
1030 ViewerTest::SetAISContext (anAISContext);
1031 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
1032 aTitle = aTitle + theViewName + "(*)";
1033 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1034 #if defined(_WIN32) || defined(__WIN32__)
1035 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1036 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1037 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1039 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1041 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1042 ViewerTest::CurrentView()->Redraw();
1047 //==============================================================================
1048 //function : RemoveView
1050 //==============================================================================
1051 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1052 const Standard_Boolean theToRemoveContext)
1054 if (!ViewerTest_myViews.IsBound2 (theView))
1059 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1060 RemoveView (aViewName, theToRemoveContext);
1063 //==============================================================================
1064 //function : RemoveView
1065 //purpose : Close and remove view from display, clear maps if neccessary
1066 //==============================================================================
1067 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1069 if (!ViewerTest_myViews.IsBound1(theViewName))
1071 cout << "Wrong view name\n";
1075 // Activate another view if it's active now
1076 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1078 if (ViewerTest_myViews.Extent() > 1)
1080 TCollection_AsciiString aNewViewName;
1081 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
1082 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1083 if (anIter.Key1() != theViewName)
1085 aNewViewName = anIter.Key1();
1088 ActivateView (aNewViewName);
1092 Handle(V3d_View) anEmptyView;
1093 #if defined(_WIN32) || defined(__WIN32__)
1094 Handle(WNT_Window) anEmptyWindow;
1095 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1096 Handle(Cocoa_Window) anEmptyWindow;
1098 Handle(Xw_Window) anEmptyWindow;
1100 VT_GetWindow() = anEmptyWindow;
1101 ViewerTest::CurrentView (anEmptyView);
1102 if (isContextRemoved)
1104 Handle(AIS_InteractiveContext) anEmptyContext;
1105 ViewerTest::SetAISContext(anEmptyContext);
1111 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1112 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1114 // Remove view resources
1115 ViewerTest_myViews.UnBind1(theViewName);
1118 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1119 XFlush (GetDisplayConnection()->GetDisplay());
1122 // Keep context opened only if the closed view is last to avoid
1123 // unused empty contexts
1124 if (!aCurrentContext.IsNull())
1126 // Check if there are more difined views in the viewer
1127 aCurrentContext->CurrentViewer()->InitDefinedViews();
1128 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1130 // Remove driver if there is no viewers that use it
1131 Standard_Boolean isRemoveDriver = Standard_True;
1132 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1133 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1135 if (aCurrentContext != anIter.Key2() &&
1136 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1138 isRemoveDriver = Standard_False;
1144 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1145 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1146 #if TCL_MAJOR_VERSION < 8
1147 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1149 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1154 ViewerTest_myContexts.UnBind2(aCurrentContext);
1157 cout << "3D View - " << theViewName << " was deleted.\n";
1161 //==============================================================================
1163 //purpose : Remove the view defined by its name
1164 //==============================================================================
1166 static int VClose (Draw_Interpretor& /*theDi*/,
1167 Standard_Integer theArgsNb,
1168 const char** theArgVec)
1170 NCollection_List<TCollection_AsciiString> aViewList;
1173 TCollection_AsciiString anArg (theArgVec[1]);
1175 if (anArg.IsEqual ("ALL")
1176 || anArg.IsEqual ("*"))
1178 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1179 anIter.More(); anIter.Next())
1181 aViewList.Append (anIter.Key1());
1183 if (aViewList.IsEmpty())
1185 std::cout << "No view to close\n";
1191 ViewerTest_Names aViewName (theArgVec[1]);
1192 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1194 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1197 aViewList.Append (aViewName.GetViewName());
1202 // close active view
1203 if (ViewerTest::CurrentView().IsNull())
1205 std::cerr << "No active view!\n";
1208 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1211 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1212 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1213 anIter.More(); anIter.Next())
1215 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1221 //==============================================================================
1222 //function : VActivate
1223 //purpose : Activate the view defined by its ID
1224 //==============================================================================
1226 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1230 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1231 << "Usage: " << theArgVec[0] << " ViewID\n";
1236 theDi.Eval("vviewlist");
1240 TCollection_AsciiString aNameString(theArgVec[1]);
1241 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1243 TCollection_AsciiString aTitle("3D View - ");
1244 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1245 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1246 Handle(V3d_View) anEmptyView;
1247 #if defined(_WIN32) || defined(__WIN32__)
1248 Handle(WNT_Window) anEmptyWindow;
1249 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1250 Handle(Cocoa_Window) anEmptyWindow;
1252 Handle(Xw_Window) anEmptyWindow;
1254 VT_GetWindow() = anEmptyWindow;
1255 ViewerTest::CurrentView (anEmptyView);
1256 ViewerTest::ResetEventManager();
1257 theDi << theArgVec[0] << ": all views are inactive\n";
1261 ViewerTest_Names aViewNames(aNameString);
1263 // Check if this view exists in the viewer with the driver
1264 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1266 theDi << "Wrong view name\n";
1270 // Check if it is active already
1271 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1273 theDi << theArgVec[0] << ": the view is active already\n";
1277 ActivateView (aViewNames.GetViewName());
1281 //==============================================================================
1282 //function : VViewList
1283 //purpose : Print current list of views per viewer and graphic driver ID
1284 // shared between viewers
1285 //==============================================================================
1287 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1291 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1292 << "Usage: " << theArgVec[0] << " name";
1295 if (ViewerTest_myContexts.Size() < 1)
1298 Standard_Boolean isTreeView =
1299 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1302 theDi << theArgVec[0] <<":\n";
1304 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1305 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1308 theDi << aDriverIter.Key1() << ":\n";
1310 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1311 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1313 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1317 TCollection_AsciiString aContextName(aContextIter.Key1());
1318 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":\n";
1321 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1322 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1324 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1326 TCollection_AsciiString aViewName(aViewIter.Key1());
1329 if (aViewIter.Value() == ViewerTest::CurrentView())
1330 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)\n";
1332 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1336 theDi << aViewName << " ";
1346 //==============================================================================
1347 //function : VT_ProcessKeyPress
1348 //purpose : Handle KeyPress event from a CString
1349 //==============================================================================
1350 void VT_ProcessKeyPress (const char* buf_ret)
1352 //cout << "KeyPress" << endl;
1353 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1354 // Letter in alphabetic order
1356 if (!strcasecmp (buf_ret, "A"))
1359 aView->SetProj(V3d_XposYnegZpos);
1361 else if (!strcasecmp (buf_ret, "D"))
1366 else if (!strcasecmp (buf_ret, "F"))
1368 if (ViewerTest::GetAISContext()->NbSelected() > 0)
1370 ViewerTest::GetAISContext()->FitSelected (aView);
1378 else if (!strcasecmp (buf_ret, "H"))
1381 cout << "HLR" << endl;
1382 aView->SetComputedMode (!aView->ComputedMode());
1383 MyHLRIsOn = aView->ComputedMode();
1385 else if (!strcasecmp (buf_ret, "P"))
1388 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1389 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1390 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1392 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1393 if (aContext->NbSelected()==0)
1395 AIS_ListOfInteractive aListOfShapes;
1396 aContext->DisplayedObjects(aListOfShapes);
1397 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1398 anIter.More(); anIter.Next())
1400 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1401 if (aShape.IsNull())
1403 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1404 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1406 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1407 aContext->Redisplay (aShape, Standard_False);
1412 for (aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected())
1414 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
1415 if (aShape.IsNull())
1417 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1418 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1420 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1421 aContext->Redisplay (aShape, Standard_False);
1425 aContext->UpdateCurrentViewer();
1428 else if (!strcasecmp (buf_ret, "S"))
1430 std::cout << "setup Shaded display mode" << std::endl;
1432 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1433 if(Ctx->NbSelected()==0)
1434 Ctx->SetDisplayMode(AIS_Shaded);
1436 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1437 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),1,Standard_False);
1438 Ctx->UpdateCurrentViewer();
1441 else if (!strcasecmp (buf_ret, "U"))
1443 // Unset display mode
1444 std::cout << "reset display mode to defaults" << std::endl;
1446 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1447 if(Ctx->NbSelected()==0)
1448 Ctx->SetDisplayMode(AIS_WireFrame);
1450 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1451 Ctx->UnsetDisplayMode(Ctx->SelectedInteractive(),Standard_False);
1452 Ctx->UpdateCurrentViewer();
1456 else if (!strcasecmp (buf_ret, "T"))
1459 aView->SetProj(V3d_Zpos);
1461 else if (!strcasecmp (buf_ret, "B"))
1464 aView->SetProj(V3d_Zneg);
1466 else if (!strcasecmp (buf_ret, "L"))
1469 aView->SetProj(V3d_Xneg);
1471 else if (!strcasecmp (buf_ret, "R"))
1474 aView->SetProj(V3d_Xpos);
1476 else if (!strcasecmp (buf_ret, "W"))
1478 std::cout << "setup WireFrame display mode" << std::endl;
1479 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1480 if(Ctx->NbSelected()==0)
1481 Ctx->SetDisplayMode(AIS_WireFrame);
1483 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1484 Ctx->SetDisplayMode(Ctx->SelectedInteractive(),0,Standard_False);
1485 Ctx->UpdateCurrentViewer();
1488 else if (!strcasecmp (buf_ret, ","))
1490 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1492 else if (!strcasecmp (buf_ret, "."))
1494 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1496 else if (!strcasecmp (buf_ret, "/"))
1498 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1499 if (aCamera->IsStereo())
1501 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
1505 else if (!strcasecmp (buf_ret, "*"))
1507 Handle(Graphic3d_Camera) aCamera = aView->Camera();
1508 if (aCamera->IsStereo())
1510 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
1514 else if (*buf_ret == THE_KEY_DELETE)
1516 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1518 && aCtx->NbSelected() > 0)
1520 Draw_Interprete ("verase");
1526 Standard_Integer Num = Draw::Atoi(buf_ret);
1527 if(Num>=0 && Num<=7)
1528 ViewerTest::StandardModeActivation(Num);
1532 //==============================================================================
1533 //function : VT_ProcessExpose
1534 //purpose : Redraw the View on an Expose Event
1535 //==============================================================================
1536 void VT_ProcessExpose()
1538 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1539 if (!aView3d.IsNull())
1545 //==============================================================================
1546 //function : VT_ProcessConfigure
1547 //purpose : Resize the View on an Configure Event
1548 //==============================================================================
1549 void VT_ProcessConfigure()
1551 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1552 if (aView3d.IsNull())
1557 aView3d->MustBeResized();
1562 //==============================================================================
1563 //function : VT_ProcessButton1Press
1565 //==============================================================================
1566 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1567 const char** theArgVec,
1568 Standard_Boolean theToPick,
1569 Standard_Boolean theIsShift)
1573 Standard_Real X, Y, Z;
1574 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1576 Draw::Set (theArgVec[1], X);
1577 Draw::Set (theArgVec[2], Y);
1578 Draw::Set (theArgVec[3], Z);
1583 ViewerTest::CurrentEventManager()->ShiftSelect();
1587 ViewerTest::CurrentEventManager()->Select();
1590 return Standard_False;
1593 //==============================================================================
1594 //function : VT_ProcessButton1Release
1595 //purpose : End selecting
1596 //==============================================================================
1597 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1601 IsDragged = Standard_False;
1602 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1605 EM->ShiftSelect (X_ButtonPress, Y_ButtonPress,
1606 X_Motion, Y_Motion);
1610 EM->Select (X_ButtonPress, Y_ButtonPress,
1611 X_Motion, Y_Motion);
1616 //==============================================================================
1617 //function : VT_ProcessButton3Press
1618 //purpose : Start Rotation
1619 //==============================================================================
1620 void VT_ProcessButton3Press()
1625 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1627 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1630 //==============================================================================
1631 //function : VT_ProcessButton3Release
1632 //purpose : End rotation
1633 //==============================================================================
1634 void VT_ProcessButton3Release()
1641 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1646 //==============================================================================
1647 //function : ProcessControlButton1Motion
1649 //==============================================================================
1651 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1652 static void ProcessControlButton1Motion()
1654 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1656 X_ButtonPress = X_Motion;
1657 Y_ButtonPress = Y_Motion;
1661 //==============================================================================
1662 //function : VT_ProcessControlButton2Motion
1664 //==============================================================================
1665 void VT_ProcessControlButton2Motion()
1667 Standard_Integer aDx = X_Motion - X_ButtonPress;
1668 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1670 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1672 ViewerTest::CurrentView()->Pan (aDx, aDy);
1674 X_ButtonPress = X_Motion;
1675 Y_ButtonPress = Y_Motion;
1678 //==============================================================================
1679 //function : VT_ProcessControlButton3Motion
1680 //purpose : Rotation
1681 //==============================================================================
1682 void VT_ProcessControlButton3Motion()
1686 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1690 //==============================================================================
1691 //function : VT_ProcessMotion
1693 //==============================================================================
1694 void VT_ProcessMotion()
1696 //pre-hilights detected objects at mouse position
1698 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1699 EM->MoveTo(X_Motion, Y_Motion);
1703 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1705 Xpix = X_Motion;Ypix=Y_Motion;
1708 //==============================================================================
1709 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1710 //purpose : Switches to an axonometric, top, left and other views
1711 //==============================================================================
1713 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1715 if ( ViewerTest::CurrentView().IsNull() )
1717 di<<"Call vinit before this command, please\n";
1721 ViewerTest::CurrentView()->SetProj(ori);
1725 //==============================================================================
1727 //purpose : Switch to an Axonometric view
1728 //Draw arg : No args
1729 //==============================================================================
1731 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1733 return ViewProject(di, V3d_XposYnegZpos);
1736 //==============================================================================
1738 //purpose : Switch to a Top View
1739 //Draw arg : No args
1740 //==============================================================================
1742 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1744 return ViewProject(di, V3d_Zpos);
1747 //==============================================================================
1748 //function : VBottom
1749 //purpose : Switch to a Bottom View
1750 //Draw arg : No args
1751 //==============================================================================
1753 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1755 return ViewProject(di, V3d_Zneg);
1758 //==============================================================================
1760 //purpose : Switch to a Left View
1761 //Draw arg : No args
1762 //==============================================================================
1764 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1766 return ViewProject(di, V3d_Xneg);
1769 //==============================================================================
1771 //purpose : Switch to a Right View
1772 //Draw arg : No args
1773 //==============================================================================
1775 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1777 return ViewProject(di, V3d_Xpos);
1780 //==============================================================================
1782 //purpose : Switch to a Front View
1783 //Draw arg : No args
1784 //==============================================================================
1786 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1788 return ViewProject(di, V3d_Yneg);
1791 //==============================================================================
1793 //purpose : Switch to a Back View
1794 //Draw arg : No args
1795 //==============================================================================
1797 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1799 return ViewProject(di, V3d_Ypos);
1802 //==============================================================================
1804 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1805 //Draw arg : No args
1806 //==============================================================================
1808 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1811 di << "Q : Quit the application\n";
1813 di << "=========================\n";
1814 di << "F : FitAll\n";
1815 di << "T : TopView\n";
1816 di << "B : BottomView\n";
1817 di << "R : RightView\n";
1818 di << "L : LeftView\n";
1819 di << "A : AxonometricView\n";
1820 di << "D : ResetView\n";
1822 di << "=========================\n";
1823 di << "S : Shading\n";
1824 di << "W : Wireframe\n";
1825 di << "H : HidelLineRemoval\n";
1826 di << "U : Unset display mode\n";
1827 di << "Delete : Remove selection from viewer\n";
1829 di << "=========================\n";
1830 di << "Selection mode \n";
1831 di << "0 : Shape\n";
1832 di << "1 : Vertex\n";
1836 di << "5 : Shell\n";
1837 di << "6 : Solid\n";
1838 di << "7 : Compound\n";
1840 di << "=========================\n";
1841 di << "Z : Switch Z clipping On/Off\n";
1842 di << ", : Hilight next detected\n";
1843 di << ". : Hilight previous detected\n";
1850 static Standard_Boolean Ppick = 0;
1851 static Standard_Integer Pargc = 0;
1852 static const char** Pargv = NULL;
1855 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1860 if (!ViewerTest_myViews.IsEmpty()) {
1862 WPARAM fwKeys = wParam;
1867 // Delete view from map of views
1868 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1873 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1874 || ViewerTest::CurrentView().IsNull())
1876 // Activate inactive window
1877 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1879 ActivateView (FindViewIdByWindowHandle(hwnd));
1885 if (IsDragged && !DragFirst)
1887 if (!GetActiveAISManipulator().IsNull())
1889 GetActiveAISManipulator()->StopTransform();
1890 ViewerTest::GetAISContext()->ClearSelected();
1893 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
1895 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
1896 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
1899 VT_ProcessButton1Release ((fwKeys & MK_SHIFT) != 0);
1901 IsDragged = Standard_False;
1902 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1905 if (IsDragged && !DragFirst)
1907 if (!GetActiveAISManipulator().IsNull())
1909 GetActiveAISManipulator()->StopTransform (Standard_False);
1910 ViewerTest::GetAISContext()->ClearSelected();
1912 IsDragged = Standard_False;
1914 return ViewerWindowProc (hwnd, Msg, wParam, lParam);
1916 case WM_LBUTTONDOWN:
1917 if (!GetActiveAISManipulator().IsNull())
1919 IsDragged = ( fwKeys == MK_LBUTTON );
1923 IsDragged = ( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) );
1928 DragFirst = Standard_True;
1929 X_ButtonPress = LOWORD(lParam);
1930 Y_ButtonPress = HIWORD(lParam);
1932 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1937 X_Motion = LOWORD (lParam);
1938 Y_Motion = HIWORD (lParam);
1939 if (!GetActiveAISManipulator().IsNull())
1943 GetActiveAISManipulator()->StartTransform (X_ButtonPress, Y_ButtonPress, ViewerTest::CurrentView());
1947 GetActiveAISManipulator()->Transform (X_Motion, Y_Motion, ViewerTest::CurrentView());
1948 ViewerTest::GetAISContext()->CurrentViewer()->Redraw();
1953 bool toRedraw = false;
1954 if (!DragFirst && ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
1956 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
1961 if (GetClientRect (hwnd, &aRect))
1963 int aHeight = aRect.bottom - aRect.top;
1964 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
1965 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed);
1970 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
1974 DragFirst = Standard_False;
1977 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1981 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1985 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1989 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1995 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
1998 return DefWindowProc( hwnd, Msg, wParam, lParam );
2005 BeginPaint(hwnd, &ps);
2006 EndPaint(hwnd, &ps);
2011 VT_ProcessConfigure();
2016 switch (aView->RenderingParams().StereoMode)
2018 case Graphic3d_StereoMode_RowInterlaced:
2019 case Graphic3d_StereoMode_ColumnInterlaced:
2020 case Graphic3d_StereoMode_ChessBoard:
2021 VT_ProcessConfigure(); // track window moves to reverse stereo pair
2029 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2032 c[0] = (char) wParam;
2034 if (wParam == VK_DELETE)
2036 c[0] = THE_KEY_DELETE;
2039 else if (wParam == VK_OEM_COMMA)
2044 else if (wParam == VK_OEM_PERIOD)
2048 else if (wParam == VK_DIVIDE)
2053 else if (wParam == VK_MULTIPLY)
2057 VT_ProcessKeyPress (c);
2065 VT_ProcessButton3Release();
2068 case WM_LBUTTONDOWN:
2069 case WM_MBUTTONDOWN:
2070 case WM_RBUTTONDOWN:
2072 WPARAM fwKeys = wParam;
2076 X_ButtonPress = LOWORD(lParam);
2077 Y_ButtonPress = HIWORD(lParam);
2079 if (Msg == WM_LBUTTONDOWN)
2081 if ((fwKeys & MK_CONTROL) != 0)
2083 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2087 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) != 0);
2090 else if (Msg == WM_RBUTTONDOWN)
2093 VT_ProcessButton3Press();
2100 int aDelta = GET_WHEEL_DELTA_WPARAM (wParam);
2101 if (wParam & MK_CONTROL)
2103 if (aView->Camera()->IsStereo())
2105 Standard_Real aFocus = aView->Camera()->ZFocus() + (aDelta > 0 ? 0.05 : -0.05);
2109 aView->Camera()->SetZFocus (aView->Camera()->ZFocusType(), aFocus);
2116 aView->Zoom (0, 0, aDelta / 40, aDelta / 40);
2123 //cout << "\t WM_MOUSEMOVE" << endl;
2124 WPARAM fwKeys = wParam;
2125 X_Motion = LOWORD(lParam);
2126 Y_Motion = HIWORD(lParam);
2129 (fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON )) != 0 )
2132 X_ButtonPress = LOWORD(lParam);
2133 Y_ButtonPress = HIWORD(lParam);
2135 if ((fwKeys & MK_RBUTTON) != 0) {
2137 VT_ProcessButton3Press();
2141 if ((fwKeys & MK_CONTROL) != 0)
2143 if ((fwKeys & MK_LBUTTON) != 0)
2145 ProcessControlButton1Motion();
2147 else if ((fwKeys & MK_MBUTTON) != 0
2148 || ((fwKeys & MK_LBUTTON) != 0
2149 && (fwKeys & MK_RBUTTON) != 0))
2151 VT_ProcessControlButton2Motion();
2153 else if ((fwKeys & MK_RBUTTON) != 0)
2155 VT_ProcessControlButton3Motion();
2158 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2166 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2174 //==============================================================================
2175 //function : ViewerMainLoop
2176 //purpose : Get a Event on the view and dispatch it
2177 //==============================================================================
2180 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2182 Ppick = (argc > 0)? 1 : 0;
2190 cout << "Start picking" << endl;
2192 while ( Ppick == 1 ) {
2193 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2194 if (GetMessage(&msg, NULL, 0, 0) ) {
2195 TranslateMessage(&msg);
2196 DispatchMessage(&msg);
2200 cout << "Picking done" << endl;
2206 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2208 int min( int a, int b )
2216 int max( int a, int b )
2224 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2227 static XEvent aReport;
2228 Standard_Boolean pick = argc > 0;
2229 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2230 XNextEvent (aDisplay, &aReport);
2232 // Handle event for the chosen display connection
2233 switch (aReport.type) {
2236 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2239 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2245 // Activate inactive view
2246 Window aWindow = GetWindowHandle(VT_GetWindow());
2247 if(aWindow != aReport.xfocus.window)
2249 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2258 case ConfigureNotify:
2260 VT_ProcessConfigure();
2269 XComposeStatus status_in_out;
2271 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2272 (char *) buf_ret , 10 ,
2273 &ks_ret , &status_in_out ) ;
2276 buf_ret[ret_len] = '\0' ;
2280 VT_ProcessKeyPress (buf_ret);
2286 X_ButtonPress = aReport.xbutton.x;
2287 Y_ButtonPress = aReport.xbutton.y;
2289 if (aReport.xbutton.button == Button1)
2291 if (aReport.xbutton.state & ControlMask)
2293 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2297 IsDragged = Standard_True;
2298 DragFirst = Standard_True;
2301 else if (aReport.xbutton.button == Button3)
2304 VT_ProcessButton3Press();
2314 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2316 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2317 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2321 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2322 if( aContext.IsNull() )
2324 cout << "The context is null. Please use vinit before createmesh" << endl;
2328 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2329 if( aReport.xbutton.button==1 )
2333 aContext->ShiftSelect();
2342 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2343 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2344 ViewerTest::CurrentView());
2348 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2349 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2350 ViewerTest::CurrentView() );
2353 VT_ProcessButton3Release();
2355 IsDragged = Standard_False;
2358 VT_ProcessButton3Release();
2363 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2371 if (ViewerTest::GetAISContext()->IsDisplayed (GetRubberBand()))
2373 ViewerTest::GetAISContext()->Remove (GetRubberBand(), Standard_False);
2377 X_Motion = aReport.xmotion.x;
2378 Y_Motion = aReport.xmotion.y;
2379 DragFirst = Standard_False;
2381 Window aWindow = GetWindowHandle(VT_GetWindow());
2384 unsigned int aWidth, aHeight, aBorderWidth, aDepth;
2385 XGetGeometry (aDisplay, aWindow, &aRoot, &anX, &anY, &aWidth, &aHeight, &aBorderWidth, &aDepth);
2386 GetRubberBand()->SetRectangle (X_ButtonPress, aHeight - Y_ButtonPress, X_Motion, aHeight - Y_Motion);
2387 ViewerTest::GetAISContext()->Display (GetRubberBand(), 0, -1, Standard_False, Standard_True, AIS_DS_Displayed);
2388 ViewerTest::GetAISContext()->CurrentViewer()->RedrawImmediate();
2392 X_Motion = aReport.xmotion.x;
2393 Y_Motion = aReport.xmotion.y;
2395 // remove all the ButtonMotionMaskr
2396 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2398 if ( aReport.xmotion.state & ControlMask ) {
2399 if ( aReport.xmotion.state & Button1Mask ) {
2400 ProcessControlButton1Motion();
2402 else if ( aReport.xmotion.state & Button2Mask ) {
2403 VT_ProcessControlButton2Motion();
2405 else if ( aReport.xmotion.state & Button3Mask ) {
2406 VT_ProcessControlButton3Motion();
2420 //==============================================================================
2421 //function : VProcessEvents
2422 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2423 // event in the Viewer window
2424 //==============================================================================
2426 static void VProcessEvents(ClientData,int)
2428 NCollection_Vector<int> anEventNumbers;
2429 // Get number of messages from every display
2430 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2431 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2433 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2435 // Handle events for every display
2436 int anEventIter = 0;
2437 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2438 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2440 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2441 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2443 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2444 int anEventResult = ViewerMainLoop( 0, NULL);
2445 // If window is closed or context was not found finish current event processing loop
2451 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2456 //==============================================================================
2457 //function : OSWindowSetup
2458 //purpose : Setup for the X11 window to be able to cath the event
2459 //==============================================================================
2462 static void OSWindowSetup()
2464 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2467 Window window = VT_GetWindow()->XWindow();
2468 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2469 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2470 XSynchronize(aDisplay, 1);
2472 // X11 : For keyboard on SUN
2474 wmhints.flags = InputHint;
2477 XSetWMHints( aDisplay, window, &wmhints);
2479 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2480 ButtonPressMask | ButtonReleaseMask |
2481 StructureNotifyMask |
2483 Button1MotionMask | Button2MotionMask |
2484 Button3MotionMask | FocusChangeMask
2486 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2487 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2489 XSynchronize(aDisplay, 0);
2497 //==============================================================================
2500 //purpose : Fitall, no DRAW arguments
2501 //Draw arg : No args
2502 //==============================================================================
2504 static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgc, const char** theArgv)
2508 std::cout << "Wrong number of arguments! Use: vfit [-selected]" << std::endl;
2511 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2515 TCollection_AsciiString anArg (theArgv[1]);
2517 if (anArg == "-selected")
2519 ViewerTest::GetAISContext()->FitSelected (aView);
2523 if (aView.IsNull() == Standard_False) {
2530 //=======================================================================
2531 //function : VFitArea
2532 //purpose : Fit view to show area located between two points
2533 // : given in world 2D or 3D coordinates.
2534 //=======================================================================
2535 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2537 Handle(V3d_View) aView = ViewerTest::CurrentView();
2540 std::cerr << theArgVec[0] << "Error: No active view.\n";
2545 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2546 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2550 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2551 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2552 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2553 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2555 else if (theArgNb == 7)
2557 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2558 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2559 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2560 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2561 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2562 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2566 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2567 theDI.PrintHelp(theArgVec[0]);
2571 // Convert model coordinates to view space
2572 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2573 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2574 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2576 // Determine fit area
2577 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2578 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2580 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2582 if (aDiagonal < Precision::Confusion())
2584 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2588 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2592 //==============================================================================
2594 //purpose : ZFitall, no DRAW arguments
2595 //Draw arg : No args
2596 //==============================================================================
2597 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2599 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2601 if (aCurrentView.IsNull())
2603 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2609 aCurrentView->ZFitAll();
2610 aCurrentView->Redraw();
2614 Standard_Real aScale = 1.0;
2618 aScale = Draw::Atoi (theArgVec[1]);
2621 aCurrentView->ZFitAll (aScale);
2622 aCurrentView->Redraw();
2627 //==============================================================================
2628 //function : VRepaint
2630 //==============================================================================
2631 static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
2633 Handle(V3d_View) V = ViewerTest::CurrentView();
2634 if ( !V.IsNull() ) V->Redraw(); return 0;
2637 //==============================================================================
2639 //purpose : Remove all the object from the viewer
2640 //Draw arg : No args
2641 //==============================================================================
2643 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2645 Handle(V3d_View) V = ViewerTest::CurrentView();
2647 ViewerTest::Clear();
2651 //==============================================================================
2654 //==============================================================================
2656 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2657 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2660 di << argv[0] << "Invalid number of arguments\n";
2664 while (ViewerMainLoop( argc, argv)) {
2670 //==============================================================================
2672 //purpose : Load image as background
2673 //==============================================================================
2675 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2677 if (argc < 2 || argc > 3)
2679 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n";
2680 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE\n";
2684 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2685 if(AISContext.IsNull())
2687 di << "use 'vinit' command before " << argv[0] << "\n";
2691 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2694 const char* szType = argv[2];
2695 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2696 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2697 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2698 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2701 di << "Wrong fill type : " << szType << "\n";
2702 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
2707 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2708 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2713 //==============================================================================
2714 //function : VSetBgMode
2715 //purpose : Change background image fill type
2716 //==============================================================================
2718 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2722 di << "Usage : " << argv[0] << " filltype : Change background image mode\n";
2723 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE\n";
2727 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2728 if(AISContext.IsNull())
2730 di << "use 'vinit' command before " << argv[0] << "\n";
2733 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2734 const char* szType = argv[1];
2735 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2736 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2737 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2738 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2741 di << "Wrong fill type : " << szType << "\n";
2742 di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
2745 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2746 V3dView->SetBgImageStyle(aFillType, Standard_True);
2750 //==============================================================================
2751 //function : VSetGradientBg
2752 //purpose : Mount gradient background
2753 //==============================================================================
2754 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2758 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background\n";
2759 di << "R1,G1,B1,R2,G2,B2 = [0..255]\n";
2760 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2761 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
2765 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2766 if(AISContext.IsNull())
2768 di << "use 'vinit' command before " << argv[0] << "\n";
2774 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2775 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2776 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2777 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2779 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2780 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2781 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2783 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2784 int aType = Draw::Atoi(argv[7]);
2785 if( aType < 0 || aType > 8 )
2787 di << "Wrong fill type \n";
2788 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2789 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
2793 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2795 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2796 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2802 //==============================================================================
2803 //function : VSetGradientBgMode
2804 //purpose : Change gradient background fill style
2805 //==============================================================================
2806 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2810 di << "Usage : " << argv[0] << " Type : Change gradient background fill type\n";
2811 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2812 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
2816 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2817 if(AISContext.IsNull())
2819 di << "use 'vinit' command before " << argv[0] << "\n";
2824 int aType = Draw::Atoi(argv[1]);
2825 if( aType < 0 || aType > 8 )
2827 di << "Wrong fill type \n";
2828 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2\n";
2829 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4\n";
2833 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2835 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2836 V3dView->SetBgGradientStyle( aMethod, 1 );
2842 //==============================================================================
2843 //function : VSetColorBg
2844 //purpose : Set color background
2845 //==============================================================================
2846 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2850 di << "Usage : " << argv[0] << " R G B : Set color background\n";
2851 di << "R,G,B = [0..255]\n";
2855 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2856 if(AISContext.IsNull())
2858 di << "use 'vinit' command before " << argv[0] << "\n";
2864 Standard_Real R = Draw::Atof(argv[1])/255.;
2865 Standard_Real G = Draw::Atof(argv[2])/255.;
2866 Standard_Real B = Draw::Atof(argv[3])/255.;
2867 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2869 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2870 V3dView->SetBackgroundColor( aColor );
2877 //==============================================================================
2878 //function : VSetDefaultBg
2879 //purpose : Set default viewer background fill color
2880 //==============================================================================
2881 static int VSetDefaultBg (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2886 std::cout << "Error: wrong syntax! See usage:\n";
2887 theDI.PrintHelp (theArgVec[0]);
2891 ViewerTest_DefaultBackground.FillMethod =
2892 theArgNb == 4 ? Aspect_GFM_NONE
2893 : (Aspect_GradientFillMethod) Draw::Atoi (theArgVec[7]);
2897 Standard_Real R = Draw::Atof (theArgVec[1]) / 255.;
2898 Standard_Real G = Draw::Atof (theArgVec[2]) / 255.;
2899 Standard_Real B = Draw::Atof (theArgVec[3]) / 255.;
2900 ViewerTest_DefaultBackground.FlatColor.SetValues (R, G, B, Quantity_TOC_RGB);
2904 Standard_Real R1 = Draw::Atof (theArgVec[1]) / 255.;
2905 Standard_Real G1 = Draw::Atof (theArgVec[2]) / 255.;
2906 Standard_Real B1 = Draw::Atof (theArgVec[3]) / 255.;
2907 ViewerTest_DefaultBackground.GradientColor1.SetValues (R1, G1, B1, Quantity_TOC_RGB);
2909 Standard_Real R2 = Draw::Atof (theArgVec[4]) / 255.;
2910 Standard_Real G2 = Draw::Atof (theArgVec[5]) / 255.;
2911 Standard_Real B2 = Draw::Atof (theArgVec[6]) / 255.;
2912 ViewerTest_DefaultBackground.GradientColor2.SetValues (R2, G2, B2, Quantity_TOC_RGB);
2915 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
2916 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
2918 const Handle(V3d_Viewer)& aViewer = anIter.Value()->CurrentViewer();
2919 aViewer->SetDefaultBackgroundColor (ViewerTest_DefaultBackground.FlatColor);
2920 aViewer->SetDefaultBgGradientColors (ViewerTest_DefaultBackground.GradientColor1,
2921 ViewerTest_DefaultBackground.GradientColor2,
2922 ViewerTest_DefaultBackground.FillMethod);
2928 //==============================================================================
2930 //purpose : View Scaling
2931 //==============================================================================
2933 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2935 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2936 if ( V3dView.IsNull() ) return 1;
2939 di << argv[0] << "Invalid number of arguments\n";
2942 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2945 //==============================================================================
2946 //function : VZBuffTrihedron
2948 //==============================================================================
2950 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
2951 Standard_Integer theArgNb,
2952 const char** theArgVec)
2954 Handle(V3d_View) aView = ViewerTest::CurrentView();
2957 std::cout << "Error: no active viewer!\n";
2961 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
2963 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2964 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
2965 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
2966 Quantity_Color anArrowColorX = Quantity_NOC_RED;
2967 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
2968 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
2969 Standard_Real aScale = 0.1;
2970 Standard_Real aSizeRatio = 0.8;
2971 Standard_Real anArrowDiam = 0.05;
2972 Standard_Integer aNbFacets = 12;
2973 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2975 Standard_CString anArg = theArgVec[anArgIter];
2976 TCollection_AsciiString aFlag (anArg);
2978 if (anUpdateTool.parseRedrawMode (aFlag))
2982 else if (aFlag == "-on")
2986 else if (aFlag == "-off")
2988 aView->TriedronErase();
2991 else if (aFlag == "-pos"
2992 || aFlag == "-position"
2993 || aFlag == "-corner")
2995 if (++anArgIter >= theArgNb)
2997 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3001 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
3002 aPosName.LowerCase();
3003 if (aPosName == "center")
3005 aPosition = Aspect_TOTP_CENTER;
3007 else if (aPosName == "left_lower"
3008 || aPosName == "lower_left"
3009 || aPosName == "leftlower"
3010 || aPosName == "lowerleft")
3012 aPosition = Aspect_TOTP_LEFT_LOWER;
3014 else if (aPosName == "left_upper"
3015 || aPosName == "upper_left"
3016 || aPosName == "leftupper"
3017 || aPosName == "upperleft")
3019 aPosition = Aspect_TOTP_LEFT_UPPER;
3021 else if (aPosName == "right_lower"
3022 || aPosName == "lower_right"
3023 || aPosName == "rightlower"
3024 || aPosName == "lowerright")
3026 aPosition = Aspect_TOTP_RIGHT_LOWER;
3028 else if (aPosName == "right_upper"
3029 || aPosName == "upper_right"
3030 || aPosName == "rightupper"
3031 || aPosName == "upperright")
3033 aPosition = Aspect_TOTP_RIGHT_UPPER;
3037 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
3041 else if (aFlag == "-type")
3043 if (++anArgIter >= theArgNb)
3045 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3049 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
3050 aTypeName.LowerCase();
3051 if (aTypeName == "wireframe"
3052 || aTypeName == "wire")
3054 aVisType = V3d_WIREFRAME;
3056 else if (aTypeName == "zbuffer"
3057 || aTypeName == "shaded")
3059 aVisType = V3d_ZBUFFER;
3063 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
3066 else if (aFlag == "-scale")
3068 if (++anArgIter >= theArgNb)
3070 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3074 aScale = Draw::Atof (theArgVec[anArgIter]);
3076 else if (aFlag == "-size"
3077 || aFlag == "-sizeratio")
3079 if (++anArgIter >= theArgNb)
3081 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3085 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3087 else if (aFlag == "-arrowdiam"
3088 || aFlag == "-arrowdiameter")
3090 if (++anArgIter >= theArgNb)
3092 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3096 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3098 else if (aFlag == "-nbfacets")
3100 if (++anArgIter >= theArgNb)
3102 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3106 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3108 else if (aFlag == "-colorlabel"
3109 || aFlag == "-colorlabels")
3111 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3112 theArgVec + anArgIter + 1,
3116 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3119 anArgIter += aNbParsed;
3121 else if (aFlag == "-colorarrowx")
3123 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3124 theArgVec + anArgIter + 1,
3128 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3131 anArgIter += aNbParsed;
3133 else if (aFlag == "-colorarrowy")
3135 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3136 theArgVec + anArgIter + 1,
3140 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3143 anArgIter += aNbParsed;
3145 else if (aFlag == "-colorarrowz")
3147 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3148 theArgVec + anArgIter + 1,
3152 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3155 anArgIter += aNbParsed;
3159 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3164 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3165 aSizeRatio, anArrowDiam, aNbFacets);
3166 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
3171 //==============================================================================
3172 //function : VRotate
3173 //purpose : Camera Rotating
3174 //==============================================================================
3176 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3178 Handle(V3d_View) aView = ViewerTest::CurrentView();
3181 std::cout << "No active view!\n";
3185 Standard_Boolean hasFlags = Standard_False;
3186 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3188 Standard_CString anArg (theArgVec[anArgIter]);
3189 TCollection_AsciiString aFlag (anArg);
3191 if (aFlag == "-mousestart"
3192 || aFlag == "-mousefrom")
3194 hasFlags = Standard_True;
3195 if (anArgIter + 2 >= theArgNb)
3197 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3201 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3202 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3203 aView->StartRotation (anX, anY);
3205 else if (aFlag == "-mousemove")
3207 hasFlags = Standard_True;
3208 if (anArgIter + 2 >= theArgNb)
3210 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3214 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3215 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3216 aView->Rotation (anX, anY);
3218 else if (theArgNb != 4
3221 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3230 else if (theArgNb == 4)
3232 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3233 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3234 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3235 aView->Rotate (anAX, anAY, anAZ);
3238 else if (theArgNb == 7)
3240 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3241 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3242 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3244 Standard_Real anX = Draw::Atof (theArgVec[4]);
3245 Standard_Real anY = Draw::Atof (theArgVec[5]);
3246 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3248 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3252 std::cout << "Error: Invalid number of arguments\n";
3256 //==============================================================================
3258 //purpose : View zoom in / out (relative to current zoom)
3259 //==============================================================================
3261 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3262 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3263 if ( V3dView.IsNull() ) {
3268 Standard_Real coef = Draw::Atof(argv[1]);
3269 if ( coef <= 0.0 ) {
3270 di << argv[1] << "Invalid value\n";
3273 V3dView->SetZoom( Draw::Atof(argv[1]) );
3276 di << argv[0] << " Invalid number of arguments\n";
3281 //==============================================================================
3283 //purpose : View panning (in pixels)
3284 //==============================================================================
3286 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3287 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3288 if ( V3dView.IsNull() ) return 1;
3291 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
3294 di << argv[0] << " Invalid number of arguments\n";
3299 //==============================================================================
3301 //purpose : Place the point (in pixels) at the center of the window
3302 //==============================================================================
3303 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3305 Handle(V3d_View) aView = ViewerTest::CurrentView();
3308 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3314 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3318 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3323 //==============================================================================
3324 //function : VExport
3325 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
3326 //==============================================================================
3328 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3330 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3331 if (V3dView.IsNull())
3336 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
3340 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
3341 TCollection_AsciiString aFormatStr;
3343 TCollection_AsciiString aFileName (argv[1]);
3344 Standard_Integer aLen = aFileName.Length();
3348 aFormatStr = TCollection_AsciiString (argv[2]);
3352 if (aFileName.Value (aLen - 2) == '.')
3354 aFormatStr = aFileName.ToCString() + aLen - 2;
3356 else if (aFileName.Value (aLen - 3) == '.')
3358 aFormatStr = aFileName.ToCString() + aLen - 3;
3362 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3368 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3372 aFormatStr.UpperCase();
3373 if (aFormatStr == "PS")
3374 anExpFormat = Graphic3d_EF_PostScript;
3375 else if (aFormatStr == "EPS")
3376 anExpFormat = Graphic3d_EF_EnhPostScript;
3377 else if (aFormatStr == "TEX")
3378 anExpFormat = Graphic3d_EF_TEX;
3379 else if (aFormatStr == "PDF")
3380 anExpFormat = Graphic3d_EF_PDF;
3381 else if (aFormatStr == "SVG")
3382 anExpFormat = Graphic3d_EF_SVG;
3383 else if (aFormatStr == "PGF")
3384 anExpFormat = Graphic3d_EF_PGF;
3385 else if (aFormatStr == "EMF")
3386 anExpFormat = Graphic3d_EF_EMF;
3389 std::cout << "Invalid export format '" << aFormatStr << "'\n";
3395 Standard_DISABLE_DEPRECATION_WARNINGS
3396 if (!V3dView->Export (argv[1], anExpFormat))
3397 Standard_ENABLE_DEPRECATION_WARNINGS
3399 di << "Error: export of image to " << aFormatStr << " failed!\n";
3402 catch (Standard_Failure)
3404 di << "Error: export of image to " << aFormatStr << " failed";
3405 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
3410 //==============================================================================
3411 //function : VColorScale
3412 //purpose : representation color scale
3413 //==============================================================================
3415 static Standard_Boolean checkColor (const TCollection_AsciiString& theRed,
3416 const TCollection_AsciiString& theGreen,
3417 const TCollection_AsciiString& theBlue,
3418 Standard_Real& theRedValue,
3419 Standard_Real& theGreenValue,
3420 Standard_Real& theBlueValue)
3422 if (!theRed.IsRealValue()
3423 || !theGreen.IsRealValue()
3424 || !theBlue.IsRealValue())
3426 std::cout << "Error: RGB color values should be real!\n";
3427 return Standard_True;
3429 theRedValue = theRed .RealValue();
3430 theGreenValue = theGreen.RealValue();
3431 theBlueValue = theBlue .RealValue();
3432 if (theRedValue < 0.0 || theRedValue > 1.0
3433 || theGreenValue < 0.0 || theGreenValue > 1.0
3434 || theBlueValue < 0.0 || theBlueValue > 1.0)
3436 std::cout << "Error: RGB color values should be within range 0..1!\n";
3437 return Standard_True;
3439 return Standard_False;
3442 static int VColorScale (Draw_Interpretor& theDI,
3443 Standard_Integer theArgNb,
3444 const char** theArgVec)
3446 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3447 Handle(V3d_View) aView = ViewerTest::CurrentView();
3448 if (aContext.IsNull())
3450 std::cout << "Error: no active view!\n";
3455 std::cout << "Error: wrong syntax at command '" << theArgVec[0] << "'!\n";
3459 Handle(AIS_ColorScale) aCS;
3461 Handle(AIS_InteractiveObject) anIObj;
3462 if (GetMapOfAIS().IsBound2 (theArgVec[1]))
3464 aCS = Handle(AIS_ColorScale)::DownCast (GetMapOfAIS().Find2 (theArgVec[1]));
3467 std::cout << "Error: object '" << theArgVec[1] << "'is already defined and is not a color scale!\n";
3473 aCS = new AIS_ColorScale();
3474 GetMapOfAIS().Bind (aCS,theArgVec[1]);
3477 if (aCS->ZLayer() != Graphic3d_ZLayerId_TopOSD)
3479 aCS->SetZLayer (Graphic3d_ZLayerId_TopOSD);
3481 if (aCS->GetTransformPersistenceMode() != Graphic3d_TMF_2d)
3483 aContext->SetTransformPersistence (aCS, Graphic3d_TMF_2d, gp_Pnt (-1.0, -1.0, 0.0));
3486 Standard_Real aMinRange = aCS->GetMin();
3487 Standard_Real aMaxRange = aCS->GetMax();
3488 Standard_Integer aBreadth = aCS->GetBreadth();
3489 Standard_Integer aHeight = aCS->GetHeight();
3490 Standard_Integer aNbIntervals = aCS->GetNumberOfIntervals();
3491 Standard_Integer aTextHeight = aCS->GetTextHeight();
3492 Aspect_TypeOfColorScalePosition aLabPosition = aCS->GetLabelPosition();
3493 Standard_Integer aPosX = aCS->GetXPosition();
3494 Standard_Integer aPosY = aCS->GetYPosition();
3496 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
3500 theDI << "Color scale parameters for '"<< theArgVec[1] << "':\n"
3501 << "Min range: " << aMinRange << "\n"
3502 << "Max range: " << aMaxRange << "\n"
3503 << "Number of intervals: " << aNbIntervals << "\n"
3504 << "Text height: " << aTextHeight << "\n"
3505 << "Color scale position: " << aPosX <<" "<< aPosY<< "\n"
3506 << "Color scale title: " << aCS->GetTitle() << "\n"
3507 << "Label position: ";
3508 switch (aLabPosition)
3510 case Aspect_TOCSP_NONE:
3513 case Aspect_TOCSP_LEFT:
3516 case Aspect_TOCSP_RIGHT:
3519 case Aspect_TOCSP_CENTER:
3520 theDI << "Center\n";
3526 for (Standard_Integer anArgIter = 2; anArgIter < theArgNb; ++anArgIter)
3528 Standard_CString anArg = theArgVec[anArgIter];
3529 TCollection_AsciiString aFlag (anArg);
3531 if (anUpdateTool.parseRedrawMode (aFlag))
3535 else if (aFlag == "-range")
3537 if (anArgIter + 3 >= theArgNb)
3539 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3543 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
3544 TCollection_AsciiString anArg2 (theArgVec[++anArgIter]);
3545 TCollection_AsciiString anArg3 (theArgVec[++anArgIter]);
3546 if (!anArg1.IsRealValue())
3548 std::cout << "Error: the minRange value should be real!\n";
3551 else if (!anArg2.IsRealValue())
3553 std::cout << "Error: the maxRange value should be real!\n";
3556 else if (!anArg3.IsIntegerValue())
3558 std::cout << "Error: the number of intervals should be integer!\n";
3562 aMinRange = anArg1.RealValue();
3563 aMaxRange = anArg2.RealValue();
3564 aNbIntervals = anArg3.IntegerValue();
3566 else if (aFlag == "-font")
3568 if (anArgIter + 1 >= theArgNb)
3570 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3573 TCollection_AsciiString aFontArg(theArgVec[anArgIter + 1]);
3574 if (!aFontArg.IsIntegerValue())
3576 std::cout << "Error: HeightFont value should be integer!\n";
3580 aTextHeight = aFontArg.IntegerValue();
3583 else if (aFlag == "-textpos")
3585 if (anArgIter + 1 >= theArgNb)
3587 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3590 TCollection_AsciiString aTextPosArg(theArgVec[++anArgIter]);
3591 aTextPosArg.LowerCase();
3592 if (aTextPosArg == "none")
3594 aLabPosition = Aspect_TOCSP_NONE;
3596 else if (aTextPosArg == "left")
3598 aLabPosition = Aspect_TOCSP_LEFT;
3600 else if (aTextPosArg == "right")
3602 aLabPosition = Aspect_TOCSP_RIGHT;
3604 else if (aTextPosArg == "center")
3606 aLabPosition = Aspect_TOCSP_CENTER;
3610 std::cout << "Error: unknown position '" << aTextPosArg << "'!\n";
3614 else if (aFlag == "-logarithmic"
3617 if (anArgIter + 1 >= theArgNb)
3619 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3622 Standard_Boolean IsLog;
3623 if (!ViewerTest::ParseOnOff(theArgVec[++anArgIter], IsLog))
3625 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3628 aCS->SetLogarithmic (IsLog);
3630 else if (aFlag == "-xy")
3632 if (anArgIter + 2 >= theArgNb)
3634 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3638 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3639 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3640 if (!aX.IsIntegerValue()
3641 || !aY.IsIntegerValue())
3643 std::cout << "Error: coordinates should be integer values!\n";
3647 aPosX = aX.IntegerValue();
3648 aPosY = aY.IntegerValue();
3650 else if (aFlag == "-width"
3653 if (anArgIter + 1 >= theArgNb)
3655 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3659 TCollection_AsciiString aW (theArgVec[++anArgIter]);
3660 if (!aW.IsIntegerValue())
3662 std::cout << "Error: a width should be an integer value!\n";
3666 aBreadth = aW.IntegerValue();
3668 else if (aFlag == "-height"
3671 if (anArgIter + 1 >= theArgNb)
3673 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3677 TCollection_AsciiString aH (theArgVec[++anArgIter]);
3678 if (!aH.IsIntegerValue())
3680 std::cout << "Error: a width should be an integer value!\n";
3684 aHeight = aH.IntegerValue();
3686 else if (aFlag == "-color")
3688 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3690 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3694 Quantity_NameOfColor aColorName;
3695 if (anArgIter + 4 >= theArgNb)
3697 if (anArgIter + 2 >= theArgNb)
3699 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3702 else if (!Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3704 std::cout << "Error: wrong color name: '" << theArgVec[anArgIter + 2] << "' !\n";
3709 TCollection_AsciiString anInd (theArgVec[anArgIter + 1]);
3710 if (!anInd.IsIntegerValue())
3712 std::cout << "Error: Index value should be integer!\n";
3716 Standard_Integer anIndex = anInd.IntegerValue();
3717 if (anIndex <= 0 || anIndex > aNbIntervals)
3719 std::cout << "Error: Index value should be within range 1.." << aNbIntervals <<"!\n";
3723 if (Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3725 aCS->SetIntervalColor (Quantity_Color (aColorName), anIndex);
3726 aCS->SetColorType (Aspect_TOCSD_USER);
3731 TCollection_AsciiString aRed (theArgVec[anArgIter + 2]);
3732 TCollection_AsciiString aGreen (theArgVec[anArgIter + 3]);
3733 TCollection_AsciiString aBlue (theArgVec[anArgIter + 4]);
3734 Standard_Real aRedValue,aGreenValue, aBlueValue;
3735 if(checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3739 aCS->SetIntervalColor (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB), anIndex);
3740 aCS->SetColorType (Aspect_TOCSD_USER);
3743 else if (aFlag == "-label")
3745 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3747 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
3750 else if (anArgIter + 2 >= theArgNb)
3752 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3756 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
3757 if (anIndex <= 0 || anIndex > aNbIntervals+1)
3759 std::cout << "Error: Index value should be within range 1.." << aNbIntervals+1 <<"!\n";
3763 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
3764 aCS->SetLabel (aText, anIndex);
3765 aCS->SetLabelType (Aspect_TOCSD_USER);
3768 else if (aFlag == "-colors")
3770 Aspect_SequenceOfColor aSeq;
3771 if (anArgIter + aNbIntervals + 1 > theArgNb)
3773 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3774 << aNbIntervals << " intervals\n";
3778 Standard_Integer aColorIter = anArgIter + 1;
3779 while (aColorIter < theArgNb)
3781 if (theArgVec[aColorIter][0] == '-')
3786 else if (theArgVec[aColorIter][0] >= 97
3787 && theArgVec[aColorIter][0] <= 122)
3789 Quantity_NameOfColor aColorName;
3790 if (!Quantity_Color::ColorFromName (theArgVec[aColorIter], aColorName))
3792 std::cout << "Error: wrong color name: " << theArgVec[aColorIter] << " !\n";
3795 aSeq.Append (Quantity_Color (aColorName));
3801 TCollection_AsciiString aRed (theArgVec[aColorIter]);
3802 TCollection_AsciiString aGreen (theArgVec[aColorIter + 1]);
3803 TCollection_AsciiString aBlue (theArgVec[aColorIter + 2]);
3804 Standard_Real aRedValue,aGreenValue, aBlueValue;
3805 if (checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3809 aSeq.Append (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB));
3814 if (aSeq.Length() < aNbIntervals)
3816 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3817 << aNbIntervals << " intervals\n";
3821 aCS->SetColors (aSeq);
3822 aCS->SetColorType (Aspect_TOCSD_USER);
3824 else if (aFlag == "-labels")
3826 if (anArgIter + aNbIntervals + 1 >= theArgNb)
3828 std::cout << "Error: not enough arguments! You should provide " << (aNbIntervals + 1)
3829 << " text labels for " << aNbIntervals << " intervals.\n";
3833 TColStd_SequenceOfExtendedString aSeq;
3834 for (int aLabelIter = anArgIter + 1; aLabelIter <= anArgIter + aNbIntervals + 1; aLabelIter += 1)
3836 aSeq.Append (TCollection_ExtendedString (theArgVec[aLabelIter]));
3838 aCS->SetLabels (aSeq);
3839 aCS->SetLabelType (Aspect_TOCSD_USER);
3840 anArgIter += aSeq.Length();
3842 else if (aFlag == "-title")
3844 if (anArgIter + 1 >= theArgNb)
3846 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3850 Standard_Boolean isTwoArgs = Standard_False;
3851 if (anArgIter + 2 < theArgNb)
3853 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
3854 aSecondArg.LowerCase();
3855 if (aSecondArg == "none")
3857 aCS->SetTitlePosition (Aspect_TOCSP_NONE);
3858 isTwoArgs = Standard_True;
3860 else if (aSecondArg == "left")
3862 aCS->SetTitlePosition (Aspect_TOCSP_LEFT);
3863 isTwoArgs = Standard_True;
3865 else if (aSecondArg == "right")
3867 aCS->SetTitlePosition (Aspect_TOCSP_RIGHT);
3868 isTwoArgs = Standard_True;
3870 else if (aSecondArg == "center")
3872 aCS->SetTitlePosition (Aspect_TOCSP_CENTER);
3873 isTwoArgs = Standard_True;
3877 aCS->SetTitle (theArgVec[anArgIter + 1]);
3884 else if (aFlag == "-demoversion"
3885 || aFlag == "-demo")
3895 aLabPosition = Aspect_TOCSP_RIGHT;
3896 aCS->SetColorType (Aspect_TOCSD_AUTO);
3897 aCS->SetLabelType (Aspect_TOCSD_AUTO);
3899 else if (aFlag == "-findcolor")
3901 if (anArgIter + 1 >= theArgNb)
3903 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3907 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
3909 if (!anArg1.IsRealValue())
3911 std::cout << "Error: the value should be real!\n";
3915 Quantity_Color aColor;
3916 aCS->FindColor (anArg1.RealValue(), aColor);
3917 theDI << Quantity_Color::StringName (aColor.Name());
3922 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
3926 if (!aBreadth || !aHeight)
3928 Standard_Integer aWinWidth, aWinHeight;
3929 aView->Window()->Size (aWinWidth, aWinHeight);
3932 aBreadth = aWinWidth;
3936 aHeight = aWinHeight;
3939 aCS->SetSize (aBreadth, aHeight);
3940 aCS->SetPosition (aPosX, aPosY);
3941 aCS->SetTextHeight (aTextHeight);
3942 aCS->SetRange (aMinRange, aMaxRange);
3943 aCS->SetNumberOfIntervals (aNbIntervals);
3944 aCS->SetLabelPosition (aLabPosition);
3945 // aCS->SetColor (aView->BackgroundColor().Invert());
3947 aContext->Display (aCS);
3952 //==============================================================================
3953 //function : VGraduatedTrihedron
3954 //purpose : Displays or hides a graduated trihedron
3955 //==============================================================================
3956 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
3957 Quantity_Color& theColor)
3959 Quantity_NameOfColor aColorName;
3960 TCollection_AsciiString aVal = theValue;
3962 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
3964 return Standard_False;
3966 theColor = Quantity_Color (aColorName);
3967 return Standard_True;
3970 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
3974 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
3975 << theArgs[0] <<"' for more information.\n";
3976 return 1; //TCL_ERROR
3979 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
3980 TCollection_AsciiString aParseKey;
3981 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
3983 TCollection_AsciiString anArg (theArgs [anArgIt]);
3985 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3988 aParseKey.Remove (1);
3989 aParseKey.LowerCase();
3990 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
3994 if (aParseKey.IsEmpty())
3999 aMapOfArgs(aParseKey)->Append (anArg);
4003 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
4004 aMapIt.More(); aMapIt.Next())
4006 const TCollection_AsciiString& aKey = aMapIt.Key();
4007 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
4009 // Bool key, without arguments
4010 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
4011 && anArgs->IsEmpty())
4017 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
4018 && anArgs->Length() == 1)
4024 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
4025 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
4026 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
4027 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
4028 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
4033 // One string argument
4034 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
4035 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
4036 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4041 // One integer argument
4042 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
4043 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
4044 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
4045 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
4046 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
4051 // One real argument
4052 if ( aKey.IsEqual ("arrowlength")
4053 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
4058 // Two string arguments
4059 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
4060 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
4065 TCollection_AsciiString aLowerKey;
4068 aLowerKey.LowerCase();
4069 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
4070 std::cout << "Type help for more information.\n";
4074 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
4075 if (anAISContext.IsNull())
4077 std::cout << theArgs[0] << ": please use 'vinit' command to initialize view.\n";
4081 Standard_Boolean toDisplay = Standard_True;
4082 Quantity_Color aColor;
4083 Graphic3d_GraduatedTrihedron aTrihedronData;
4084 // Process parameters
4085 Handle(TColStd_HSequenceOfAsciiString) aValues;
4086 if (aMapOfArgs.Find ("off", aValues))
4088 toDisplay = Standard_False;
4092 if (aMapOfArgs.Find ("xname", aValues))
4094 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
4096 if (aMapOfArgs.Find ("yname", aValues))
4098 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
4100 if (aMapOfArgs.Find ("zname", aValues))
4102 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
4104 if (aMapOfArgs.Find ("xdrawname", aValues))
4106 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4108 if (aMapOfArgs.Find ("ydrawname", aValues))
4110 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4112 if (aMapOfArgs.Find ("zdrawname", aValues))
4114 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
4116 if (aMapOfArgs.Find ("xnameoffset", aValues))
4118 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4120 if (aMapOfArgs.Find ("ynameoffset", aValues))
4122 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4124 if (aMapOfArgs.Find ("znameoffset", aValues))
4126 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
4130 if (aMapOfArgs.Find ("xnamecolor", aValues))
4132 if (!GetColor (aValues->Value(1), aColor))
4134 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
4137 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
4139 if (aMapOfArgs.Find ("ynamecolor", aValues))
4141 if (!GetColor (aValues->Value(1), aColor))
4143 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
4146 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
4148 if (aMapOfArgs.Find ("znamecolor", aValues))
4150 if (!GetColor (aValues->Value(1), aColor))
4152 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
4155 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
4157 if (aMapOfArgs.Find ("xcolor", aValues))
4159 if (!GetColor (aValues->Value(1), aColor))
4161 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
4164 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
4166 if (aMapOfArgs.Find ("ycolor", aValues))
4168 if (!GetColor (aValues->Value(1), aColor))
4170 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
4173 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
4175 if (aMapOfArgs.Find ("zcolor", aValues))
4177 if (!GetColor (aValues->Value(1), aColor))
4179 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
4182 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
4186 if (aMapOfArgs.Find ("xticks", aValues))
4188 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4190 if (aMapOfArgs.Find ("yticks", aValues))
4192 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4194 if (aMapOfArgs.Find ("zticks", aValues))
4196 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4198 if (aMapOfArgs.Find ("xticklength", aValues))
4200 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4202 if (aMapOfArgs.Find ("yticklength", aValues))
4204 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4206 if (aMapOfArgs.Find ("zticklength", aValues))
4208 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4210 if (aMapOfArgs.Find ("xdrawticks", aValues))
4212 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4214 if (aMapOfArgs.Find ("ydrawticks", aValues))
4216 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4218 if (aMapOfArgs.Find ("zdrawticks", aValues))
4220 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4224 if (aMapOfArgs.Find ("xdrawvalues", aValues))
4226 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4228 if (aMapOfArgs.Find ("ydrawvalues", aValues))
4230 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4232 if (aMapOfArgs.Find ("zdrawvalues", aValues))
4234 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4236 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
4238 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4240 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
4242 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4244 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
4246 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4250 if (aMapOfArgs.Find ("arrowlength", aValues))
4252 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
4256 if (aMapOfArgs.Find ("namefont", aValues))
4258 aTrihedronData.SetNamesFont (aValues->Value(1));
4260 if (aMapOfArgs.Find ("valuesfont", aValues))
4262 aTrihedronData.SetValuesFont (aValues->Value(1));
4265 if (aMapOfArgs.Find ("drawgrid", aValues))
4267 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
4269 if (aMapOfArgs.Find ("drawaxes", aValues))
4271 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
4274 // The final step: display of erase trihedron
4277 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
4281 ViewerTest::CurrentView()->GraduatedTrihedronErase();
4284 ViewerTest::GetAISContext()->UpdateCurrentViewer();
4285 ViewerTest::CurrentView()->Redraw();
4290 //==============================================================================
4293 //==============================================================================
4294 static int VTile (Draw_Interpretor& theDI,
4295 Standard_Integer theArgNb,
4296 const char** theArgVec)
4298 Handle(V3d_View) aView = ViewerTest::CurrentView();
4301 std::cerr << "Error: no active viewer.\n";
4305 Graphic3d_CameraTile aTile = aView->Camera()->Tile();
4308 theDI << "Total size: " << aTile.TotalSize.x() << " " << aTile.TotalSize.y() << "\n"
4309 << "Tile size: " << aTile.TileSize.x() << " " << aTile.TileSize.y() << "\n"
4310 << "Lower left: " << aTile.Offset.x() << " " << aTile.Offset.y() << "\n";
4314 aView->Window()->Size (aTile.TileSize.x(), aTile.TileSize.y());
4315 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4317 TCollection_AsciiString anArg (theArgVec[anArgIter]);
4319 if (anArg == "-lowerleft"
4320 || anArg == "-upperleft")
4322 if (anArgIter + 3 < theArgNb)
4324 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4327 aTile.IsTopDown = (anArg == "-upperleft") == Standard_True;
4328 aTile.Offset.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4329 aTile.Offset.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4331 else if (anArg == "-total"
4332 || anArg == "-totalsize"
4333 || anArg == "-viewsize")
4335 if (anArgIter + 3 < theArgNb)
4337 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4340 aTile.TotalSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4341 aTile.TotalSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4342 if (aTile.TotalSize.x() < 1
4343 || aTile.TotalSize.y() < 1)
4345 std::cerr << "Error: total size is incorrect.\n";
4349 else if (anArg == "-tilesize")
4351 if (anArgIter + 3 < theArgNb)
4353 std::cerr << "Syntax error at '" << theArgVec[anArgIter] << "'.\n";
4357 aTile.TileSize.x() = Draw::Atoi (theArgVec[anArgIter + 1]);
4358 aTile.TileSize.y() = Draw::Atoi (theArgVec[anArgIter + 2]);
4359 if (aTile.TileSize.x() < 1
4360 || aTile.TileSize.y() < 1)
4362 std::cerr << "Error: tile size is incorrect.\n";
4366 else if (anArg == "-unset")
4368 aView->Camera()->SetTile (Graphic3d_CameraTile());
4374 if (aTile.TileSize.x() < 1
4375 || aTile.TileSize.y() < 1)
4377 std::cerr << "Error: tile size is undefined.\n";
4380 else if (aTile.TotalSize.x() < 1
4381 || aTile.TotalSize.y() < 1)
4383 std::cerr << "Error: total size is undefined.\n";
4387 aView->Camera()->SetTile (aTile);
4392 //==============================================================================
4393 //function : VZLayer
4394 //purpose : Test z layer operations for v3d viewer
4395 //==============================================================================
4396 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4398 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
4399 if (aContextAIS.IsNull())
4401 di << "Call vinit before!\n";
4406 di << di.PrintHelp (argv[0]);
4410 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
4411 if (aViewer.IsNull())
4413 di << "No active viewer!\n";
4417 // perform operation
4418 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
4421 Standard_Integer aNewId;
4422 if (!aViewer->AddZLayer (aNewId))
4424 di << "Impossible to add new z layer!\n";
4428 di << "New z layer added with index: " << aNewId << "\n";
4430 else if (anOp == "del")
4434 di << "Please also provide as argument id of z layer to remove\n";
4438 Standard_Integer aDelId = Draw::Atoi (argv[2]);
4439 if (!aViewer->RemoveZLayer (aDelId))
4441 di << "Impossible to remove the z layer or invalid id!\n";
4445 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4446 anObjIter.More(); anObjIter.Next())
4448 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1());
4450 || aPrs->ZLayer() != aDelId)
4454 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4457 di << "Z layer " << aDelId << " has been removed\n";
4459 else if (anOp == "get")
4461 TColStd_SequenceOfInteger anIds;
4462 aViewer->GetAllZLayers (anIds);
4463 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
4465 di << anIds.Value (aSeqIdx) << " ";
4470 else if (anOp == "settings")
4474 di << "Please also provide an id\n";
4478 Standard_Integer anId = Draw::Atoi (argv[2]);
4479 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4481 di << "Depth test - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthTest) ? "enabled" : "disabled") << "\n";
4482 di << "Depth write - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthWrite) ? "enabled" : "disabled") << "\n";
4483 di << "Depth buffer clearing - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthClear) ? "enabled" : "disabled") << "\n";
4484 di << "Depth offset - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthOffset) ? "enabled" : "disabled") << "\n";
4487 else if (anOp == "enable")
4491 di << "Please also provide an option to enable\n";
4497 di << "Please also provide a layer id\n";
4501 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
4502 Standard_Integer anId = Draw::Atoi (argv[3]);
4503 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4505 if (aSubOp == "depthtest" || aSubOp == "test")
4507 aSettings.EnableSetting (Graphic3d_ZLayerDepthTest);
4509 else if (aSubOp == "depthwrite" || aSubOp == "write")
4511 aSettings.EnableSetting (Graphic3d_ZLayerDepthWrite);
4513 else if (aSubOp == "depthclear" || aSubOp == "clear")
4515 aSettings.EnableSetting (Graphic3d_ZLayerDepthClear);
4517 else if (aSubOp == "depthoffset" || aSubOp == "offset")
4521 di << "Please also provide a factor and units values for depth offset\n";
4522 di << "Format is: vzlayer enable offset [factor] [units] [layerId]\n";
4526 Standard_ShortReal aFactor = static_cast<Standard_ShortReal> (Draw::Atof (argv[3]));
4527 Standard_ShortReal aUnits = static_cast<Standard_ShortReal> (Draw::Atof (argv[4]));
4528 anId = Draw::Atoi (argv[5]);
4529 aSettings = aViewer->ZLayerSettings (anId);
4531 aSettings.DepthOffsetFactor = aFactor;
4532 aSettings.DepthOffsetUnits = aUnits;
4534 aSettings.EnableSetting (Graphic3d_ZLayerDepthOffset);
4536 else if (aSubOp == "positiveoffset" || aSubOp == "poffset")
4538 aSettings.SetDepthOffsetPositive();
4540 else if (aSubOp == "negativeoffset" || aSubOp == "noffset")
4542 aSettings.SetDepthOffsetNegative();
4544 else if (aSubOp == "textureenv")
4546 aSettings.UseEnvironmentTexture = true;
4549 aViewer->SetZLayerSettings (anId, aSettings);
4551 else if (anOp == "disable")
4555 di << "Please also provide an option to disable\n";
4561 di << "Please also provide a layer id\n";
4565 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
4566 Standard_Integer anId = Draw::Atoi (argv[3]);
4567 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4569 if (aSubOp == "depthtest" || aSubOp == "test")
4571 aSettings.DisableSetting (Graphic3d_ZLayerDepthTest);
4573 else if (aSubOp == "depthwrite" || aSubOp == "write")
4575 aSettings.DisableSetting (Graphic3d_ZLayerDepthWrite);
4577 else if (aSubOp == "depthclear" || aSubOp == "clear")
4579 aSettings.DisableSetting (Graphic3d_ZLayerDepthClear);
4581 else if (aSubOp == "depthoffset" || aSubOp == "offset")
4583 aSettings.DisableSetting (Graphic3d_ZLayerDepthOffset);
4585 else if (aSubOp == "textureenv")
4587 aSettings.UseEnvironmentTexture = false;
4590 aViewer->SetZLayerSettings (anId, aSettings);
4594 di << "Invalid operation, please use { add / del / get / settings / enable / disable}\n";
4601 // The interactive presentation of 2d layer item
4602 // for "vlayerline" command it provides a presentation of
4603 // line with user-defined linewidth, linetype and transparency.
4604 class V3d_LineItem : public AIS_InteractiveObject
4608 DEFINE_STANDARD_RTTI_INLINE(V3d_LineItem,AIS_InteractiveObject)
4611 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4612 Standard_Real X2, Standard_Real Y2,
4613 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
4614 Standard_Real theWidth = 0.5,
4615 Standard_Real theTransp = 1.0);
4619 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
4620 const Handle(Prs3d_Presentation)& thePresentation,
4621 const Standard_Integer theMode) Standard_OVERRIDE;
4623 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
4624 const Standard_Integer /*aMode*/) Standard_OVERRIDE
4629 Standard_Real myX1, myY1, myX2, myY2;
4630 Aspect_TypeOfLine myType;
4631 Standard_Real myWidth;
4634 // default constructor for line item
4635 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4636 Standard_Real X2, Standard_Real Y2,
4637 Aspect_TypeOfLine theType,
4638 Standard_Real theWidth,
4639 Standard_Real theTransp) :
4640 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2),
4641 myType(theType), myWidth(theWidth)
4643 SetTransparency (1-theTransp);
4647 void V3d_LineItem::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
4648 const Handle(Prs3d_Presentation)& thePresentation,
4649 const Standard_Integer /*theMode*/)
4651 thePresentation->Clear();
4652 Quantity_Color aColor (1.0, 0, 0, Quantity_TOC_RGB);
4653 Standard_Integer aWidth, aHeight;
4654 ViewerTest::CurrentView()->Window()->Size (aWidth, aHeight);
4655 Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePresentation);
4656 Handle(Graphic3d_ArrayOfPolylines) aPrim = new Graphic3d_ArrayOfPolylines(5);
4657 aPrim->AddVertex(myX1, aHeight-myY1, 0.);
4658 aPrim->AddVertex(myX2, aHeight-myY2, 0.);
4659 Handle(Prs3d_LineAspect) anAspect = new Prs3d_LineAspect (aColor, (Aspect_TypeOfLine)myType, myWidth);
4660 aGroup->SetPrimitivesAspect (anAspect->Aspect());
4661 aGroup->AddPrimitiveArray (aPrim);
4664 //=============================================================================
4665 //function : VLayerLine
4666 //purpose : Draws line in the v3d view layer with given attributes: linetype,
4667 // : linewidth, transparency coefficient
4668 //============================================================================
4669 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4671 // get the active view
4672 Handle(V3d_View) aView = ViewerTest::CurrentView();
4675 di << "Call vinit before!\n";
4680 di << "Use: " << argv[0];
4681 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
4682 di << " linetype : { 0 | 1 | 2 | 3 } \n";
4683 di << " 0 - solid \n";
4684 di << " 1 - dashed \n";
4685 di << " 2 - dot \n";
4686 di << " 3 - dashdot\n";
4687 di << " transparency : { 0.0 - 1.0 } \n";
4688 di << " 0.0 - transparent\n";
4689 di << " 1.0 - visible \n";
4693 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4694 // get the input params
4695 Standard_Real X1 = Draw::Atof(argv[1]);
4696 Standard_Real Y1 = Draw::Atof(argv[2]);
4697 Standard_Real X2 = Draw::Atof(argv[3]);
4698 Standard_Real Y2 = Draw::Atof(argv[4]);
4700 Standard_Real aWidth = 0.5;
4701 Standard_Integer aType = 0;
4702 Standard_Real aTransparency = 1.0;
4706 aWidth = Draw::Atof(argv[5]);
4710 aType = (Standard_Integer) Draw::Atoi(argv[6]);
4715 aTransparency = Draw::Atof(argv[7]);
4716 if (aTransparency < 0 || aTransparency > 1.0)
4717 aTransparency = 1.0;
4720 // select appropriate line type
4721 Aspect_TypeOfLine aLineType;
4725 aLineType = Aspect_TOL_DASH;
4729 aLineType = Aspect_TOL_DOT;
4733 aLineType = Aspect_TOL_DOTDASH;
4737 aLineType = Aspect_TOL_SOLID;
4740 static Handle (V3d_LineItem) aLine;
4741 if (!aLine.IsNull())
4743 aContext->Erase (aLine);
4745 aLine = new V3d_LineItem (X1, Y1, X2, Y2,
4749 aContext->SetTransformPersistence (aLine, Graphic3d_TMF_2d, gp_Pnt (-1.0, -1.0, 0.0));
4750 aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD);
4751 aLine->SetToUpdate();
4752 aContext->Display (aLine, Standard_True);
4758 //==============================================================================
4761 //==============================================================================
4763 static int VGrid (Draw_Interpretor& /*theDI*/,
4764 Standard_Integer theArgNb,
4765 const char** theArgVec)
4767 // get the active view
4768 Handle(V3d_View) aView = ViewerTest::CurrentView();
4769 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4770 if (aView.IsNull() || aViewer.IsNull())
4772 std::cerr << "No active view. Please call vinit.\n";
4776 Aspect_GridType aType = aViewer->GridType();
4777 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
4779 Standard_Integer anIter = 1;
4780 for (; anIter < theArgNb; ++anIter)
4782 const char* aValue = theArgVec[anIter];
4785 aType = Aspect_GT_Rectangular;
4787 else if (*aValue == 'c')
4789 aType = Aspect_GT_Circular;
4791 else if (*aValue == 'l')
4793 aMode = Aspect_GDM_Lines;
4795 else if (*aValue == 'p')
4797 aMode = Aspect_GDM_Points;
4799 else if (strcmp (aValue, "off" ) == 0)
4801 aViewer->DeactivateGrid();
4810 Standard_Integer aTail = (theArgNb - anIter);
4813 aViewer->ActivateGrid (aType, aMode);
4816 else if (aTail != 2 && aTail != 5)
4818 std::cerr << "Incorrect arguments number! Usage:\n"
4819 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
4823 Quantity_Length anOriginX, anOriginY;
4824 Quantity_PlaneAngle aRotAngle;
4825 if (aType == Aspect_GT_Rectangular)
4827 Quantity_Length aRStepX, aRStepY;
4828 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4830 anOriginX = Draw::Atof (theArgVec[anIter++]);
4831 anOriginY = Draw::Atof (theArgVec[anIter++]);
4834 aRStepX = Draw::Atof (theArgVec[anIter++]);
4835 aRStepY = Draw::Atof (theArgVec[anIter++]);
4836 aRotAngle = Draw::Atof (theArgVec[anIter++]);
4838 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4839 aViewer->ActivateGrid (aType, aMode);
4841 else if (aType == Aspect_GT_Circular)
4843 Quantity_Length aRadiusStep;
4844 Standard_Integer aDivisionNumber;
4845 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
4847 anOriginX = Draw::Atof (theArgVec[anIter++]);
4848 anOriginY = Draw::Atof (theArgVec[anIter++]);
4851 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
4852 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
4853 aRotAngle = Draw::Atof (theArgVec[anIter++]);
4856 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
4857 aViewer->ActivateGrid (aType, aMode);
4863 //==============================================================================
4864 //function : VPriviledgedPlane
4866 //==============================================================================
4868 static int VPriviledgedPlane (Draw_Interpretor& theDI,
4869 Standard_Integer theArgNb,
4870 const char** theArgVec)
4872 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
4874 std::cerr << "Error: wrong number of arguments! See usage:\n";
4875 theDI.PrintHelp (theArgVec[0]);
4879 // get the active viewer
4880 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4881 if (aViewer.IsNull())
4883 std::cerr << "Error: no active viewer. Please call vinit.\n";
4889 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
4890 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
4891 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
4892 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
4893 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
4894 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
4895 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
4899 Standard_Integer anArgIdx = 1;
4900 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
4901 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
4902 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
4903 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
4904 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
4905 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
4907 gp_Ax3 aPriviledgedPlane;
4908 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
4909 gp_Dir aNorm (aNormX, aNormY, aNormZ);
4912 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
4913 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
4914 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
4915 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
4916 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
4920 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
4923 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
4928 //==============================================================================
4929 //function : VConvert
4931 //==============================================================================
4933 static int VConvert (Draw_Interpretor& theDI,
4934 Standard_Integer theArgNb,
4935 const char** theArgVec)
4937 // get the active view
4938 Handle(V3d_View) aView = ViewerTest::CurrentView();
4941 std::cerr << "Error: no active view. Please call vinit.\n";
4945 enum { Model, Ray, View, Window, Grid } aMode = Model;
4947 // access coordinate arguments
4948 TColStd_SequenceOfReal aCoord;
4949 Standard_Integer anArgIdx = 1;
4950 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
4952 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
4953 if (!anArg.IsRealValue())
4957 aCoord.Append (anArg.RealValue());
4960 // non-numeric argument too early
4961 if (aCoord.IsEmpty())
4963 std::cerr << "Error: wrong number of arguments! See usage:\n";
4964 theDI.PrintHelp (theArgVec[0]);
4968 // collect all other arguments and options
4969 for (; anArgIdx < theArgNb; ++anArgIdx)
4971 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
4973 if (anArg == "window") aMode = Window;
4974 else if (anArg == "view") aMode = View;
4975 else if (anArg == "grid") aMode = Grid;
4976 else if (anArg == "ray") aMode = Ray;
4979 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
4980 theDI.PrintHelp (theArgVec[0]);
4985 // complete input checks
4986 if ((aCoord.Length() == 1 && theArgNb > 3) ||
4987 (aCoord.Length() == 2 && theArgNb > 4) ||
4988 (aCoord.Length() == 3 && theArgNb > 5))
4990 std::cerr << "Error: wrong number of arguments! See usage:\n";
4991 theDI.PrintHelp (theArgVec[0]);
4995 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
4996 Standard_Integer aXYp[2] = {0, 0};
4998 // convert one-dimensional coordinate
4999 if (aCoord.Length() == 1)
5003 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer) aCoord (1)); return 0;
5004 case Window : theDI << "Window Vp: " << aView->Convert ((Quantity_Length) aCoord (1)); return 0;
5006 std::cerr << "Error: wrong arguments! See usage:\n";
5007 theDI.PrintHelp (theArgVec[0]);
5012 // convert 2D coordinates from projection or view reference space
5013 if (aCoord.Length() == 2)
5018 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5019 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5023 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5024 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5028 aView->Convert ((V3d_Coordinate) aCoord (1), (V3d_Coordinate) aCoord (2), aXYp[0], aXYp[1]);
5029 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5033 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5034 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5035 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5039 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5040 (Standard_Integer) aCoord (2),
5041 aXYZ[0], aXYZ[1], aXYZ[2],
5042 aXYZ[3], aXYZ[4], aXYZ[5]);
5043 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5047 std::cerr << "Error: wrong arguments! See usage:\n";
5048 theDI.PrintHelp (theArgVec[0]);
5053 // convert 3D coordinates from view reference space
5054 else if (aCoord.Length() == 3)
5059 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5060 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5064 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5065 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5069 std::cerr << "Error: wrong arguments! See usage:\n";
5070 theDI.PrintHelp (theArgVec[0]);
5078 //==============================================================================
5081 //==============================================================================
5083 static int VFps (Draw_Interpretor& theDI,
5084 Standard_Integer theArgNb,
5085 const char** theArgVec)
5087 // get the active view
5088 Handle(V3d_View) aView = ViewerTest::CurrentView();
5091 std::cerr << "No active view. Please call vinit.\n";
5095 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
5098 std::cerr << "Incorrect arguments!\n";
5102 // the time is meaningless for first call
5103 // due to async OpenGl rendering
5106 // redraw view in loop to estimate average values
5109 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
5115 const Standard_Real aTime = aTimer.ElapsedTime();
5116 aTimer.OSD_Chronometer::Show (aCpu);
5118 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
5119 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
5121 // return statistics
5122 theDI << "FPS: " << aFpsAver << "\n"
5123 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5125 // compute additional statistics in ray-tracing mode
5126 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
5128 if (aParams.Method == Graphic3d_RM_RAYTRACING)
5130 Standard_Integer aSizeX;
5131 Standard_Integer aSizeY;
5133 aView->Window()->Size (aSizeX, aSizeY);
5135 // 1 shadow ray and 1 secondary ray pew each bounce
5136 const Standard_Real aMRays = aSizeX * aSizeY * aFpsAver * aParams.RaytracingDepth * 2 / 1.0e6f;
5138 theDI << "MRays/sec (upper bound): " << aMRays << "\n";
5144 //==============================================================================
5145 //function : VGlDebug
5147 //==============================================================================
5149 static int VGlDebug (Draw_Interpretor& theDI,
5150 Standard_Integer theArgNb,
5151 const char** theArgVec)
5153 Handle(OpenGl_GraphicDriver) aDriver;
5154 Handle(V3d_View) aView = ViewerTest::CurrentView();
5155 if (!aView.IsNull())
5157 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5159 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
5160 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
5164 TCollection_AsciiString aDebActive, aSyncActive;
5171 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
5172 "GL_ARB_debug_output");
5173 aDebActive = isActive ? " (active)" : " (inactive)";
5176 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
5177 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
5181 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
5182 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
5183 << "glslWarn:" << (aCaps->glslWarnings ? "1" : "0") << "\n"
5184 << "extraMsg:" << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
5188 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5190 Standard_CString anArg = theArgVec[anArgIter];
5191 TCollection_AsciiString anArgCase (anArg);
5192 anArgCase.LowerCase();
5193 Standard_Boolean toEnableDebug = Standard_True;
5194 if (anArgCase == "-glsl"
5195 || anArgCase == "-glslwarn"
5196 || anArgCase == "-glslwarns"
5197 || anArgCase == "-glslwarnings")
5199 Standard_Boolean toShowWarns = Standard_True;
5200 if (++anArgIter < theArgNb
5201 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShowWarns))
5205 aDefCaps->glslWarnings = toShowWarns;
5208 aCaps->glslWarnings = toShowWarns;
5211 else if (anArgCase == "-extra"
5212 || anArgCase == "-extramsg"
5213 || anArgCase == "-extramessages")
5215 Standard_Boolean toShow = Standard_True;
5216 if (++anArgIter < theArgNb
5217 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toShow))
5221 aDefCaps->suppressExtraMsg = !toShow;
5224 aCaps->suppressExtraMsg = !toShow;
5227 else if (anArgCase == "-noextra"
5228 || anArgCase == "-noextramsg"
5229 || anArgCase == "-noextramessages")
5231 Standard_Boolean toSuppress = Standard_True;
5232 if (++anArgIter < theArgNb
5233 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSuppress))
5237 aDefCaps->suppressExtraMsg = toSuppress;
5240 aCaps->suppressExtraMsg = toSuppress;
5243 else if (anArgCase == "-sync")
5245 Standard_Boolean toSync = Standard_True;
5246 if (++anArgIter < theArgNb
5247 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toSync))
5251 aDefCaps->contextSyncDebug = toSync;
5254 aDefCaps->contextDebug = Standard_True;
5257 else if (anArgCase == "-debug")
5259 if (++anArgIter < theArgNb
5260 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnableDebug))
5264 aDefCaps->contextDebug = toEnableDebug;
5266 else if (ViewerTest::ParseOnOff (anArg, toEnableDebug)
5267 && (anArgIter + 1 == theArgNb))
5269 // simple alias to turn on almost everything
5270 aDefCaps->contextDebug = toEnableDebug;
5271 aDefCaps->contextSyncDebug = toEnableDebug;
5272 aDefCaps->glslWarnings = toEnableDebug;
5276 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
5284 //==============================================================================
5287 //==============================================================================
5289 static int VVbo (Draw_Interpretor& theDI,
5290 Standard_Integer theArgNb,
5291 const char** theArgVec)
5293 const Standard_Boolean toSet = (theArgNb > 1);
5294 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
5297 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
5301 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5302 if (aContextAIS.IsNull())
5306 std::cerr << "No active view!\n";
5310 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5311 if (!aDriver.IsNull())
5315 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
5319 aDriver->ChangeOptions().vboDisable = toUseVbo;
5326 //==============================================================================
5329 //==============================================================================
5331 static int VCaps (Draw_Interpretor& theDI,
5332 Standard_Integer theArgNb,
5333 const char** theArgVec)
5335 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
5336 Handle(OpenGl_GraphicDriver) aDriver;
5337 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5338 if (!aContext.IsNull())
5340 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
5341 aCaps = &aDriver->ChangeOptions();
5346 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
5347 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
5348 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
5349 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
5350 theDI << "VSync: " << aCaps->swapInterval << "\n";
5351 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
5352 theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
5356 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5357 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5359 Standard_CString anArg = theArgVec[anArgIter];
5360 TCollection_AsciiString anArgCase (anArg);
5361 anArgCase.LowerCase();
5362 if (anUpdateTool.parseRedrawMode (anArg))
5366 else if (anArgCase == "-vsync"
5367 || anArgCase == "-swapinterval")
5369 Standard_Boolean toEnable = Standard_True;
5370 if (++anArgIter < theArgNb
5371 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5375 aCaps->swapInterval = toEnable;
5377 else if (anArgCase == "-ffp")
5379 Standard_Boolean toEnable = Standard_True;
5380 if (++anArgIter < theArgNb
5381 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5385 aCaps->ffpEnable = toEnable;
5387 else if (anArgCase == "-vbo")
5389 Standard_Boolean toEnable = Standard_True;
5390 if (++anArgIter < theArgNb
5391 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5395 aCaps->vboDisable = !toEnable;
5397 else if (anArgCase == "-sprite"
5398 || anArgCase == "-sprites")
5400 Standard_Boolean toEnable = Standard_True;
5401 if (++anArgIter < theArgNb
5402 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5406 aCaps->pntSpritesDisable = !toEnable;
5408 else if (anArgCase == "-softmode")
5410 Standard_Boolean toEnable = Standard_True;
5411 if (++anArgIter < theArgNb
5412 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5416 aCaps->contextNoAccel = toEnable;
5418 else if (anArgCase == "-accel"
5419 || anArgCase == "-acceleration")
5421 Standard_Boolean toEnable = Standard_True;
5422 if (++anArgIter < theArgNb
5423 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5427 aCaps->contextNoAccel = !toEnable;
5429 else if (anArgCase == "-compat"
5430 || anArgCase == "-compatprofile"
5431 || anArgCase == "-compatible"
5432 || anArgCase == "-compatibleprofile")
5434 Standard_Boolean toEnable = Standard_True;
5435 if (++anArgIter < theArgNb
5436 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5440 aCaps->contextCompatible = toEnable;
5441 if (!aCaps->contextCompatible)
5443 aCaps->ffpEnable = Standard_False;
5446 else if (anArgCase == "-core"
5447 || anArgCase == "-coreprofile")
5449 Standard_Boolean toEnable = Standard_True;
5450 if (++anArgIter < theArgNb
5451 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5455 aCaps->contextCompatible = !toEnable;
5456 if (!aCaps->contextCompatible)
5458 aCaps->ffpEnable = Standard_False;
5461 else if (anArgCase == "-stereo"
5462 || anArgCase == "-quadbuffer")
5464 Standard_Boolean toEnable = Standard_True;
5465 if (++anArgIter < theArgNb
5466 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
5470 aCaps->contextStereo = toEnable;
5474 std::cout << "Error: unknown argument '" << anArg << "'\n";
5478 if (aCaps != &ViewerTest_myDefaultCaps)
5480 ViewerTest_myDefaultCaps = *aCaps;
5485 //==============================================================================
5486 //function : VMemGpu
5488 //==============================================================================
5490 static int VMemGpu (Draw_Interpretor& theDI,
5491 Standard_Integer theArgNb,
5492 const char** theArgVec)
5495 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5496 if (aContextAIS.IsNull())
5498 std::cerr << "No active view. Please call vinit.\n";
5502 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
5503 if (aDriver.IsNull())
5505 std::cerr << "Graphic driver not available.\n";
5509 Standard_Size aFreeBytes = 0;
5510 TCollection_AsciiString anInfo;
5511 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
5513 std::cerr << "Information not available.\n";
5517 if (theArgNb > 1 && *theArgVec[1] == 'f')
5519 theDI << Standard_Real (aFreeBytes);
5529 // ==============================================================================
5530 // function : VReadPixel
5532 // ==============================================================================
5533 static int VReadPixel (Draw_Interpretor& theDI,
5534 Standard_Integer theArgNb,
5535 const char** theArgVec)
5537 // get the active view
5538 Handle(V3d_View) aView = ViewerTest::CurrentView();
5541 std::cerr << "No active view. Please call vinit.\n";
5544 else if (theArgNb < 3)
5546 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
5550 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
5551 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
5553 Standard_Integer aWidth, aHeight;
5554 aView->Window()->Size (aWidth, aHeight);
5555 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
5556 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
5557 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
5559 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
5563 Standard_Boolean toShowName = Standard_False;
5564 Standard_Boolean toShowHls = Standard_False;
5565 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
5567 const char* aParam = theArgVec[anIter];
5568 if ( strcasecmp( aParam, "rgb" ) == 0 )
5570 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
5571 aBufferType = Graphic3d_BT_RGB;
5573 else if ( strcasecmp( aParam, "hls" ) == 0 )
5575 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
5576 aBufferType = Graphic3d_BT_RGB;
5577 toShowHls = Standard_True;
5579 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
5581 aFormat = Image_PixMap::ImgRGBF;
5582 aBufferType = Graphic3d_BT_RGB;
5584 else if ( strcasecmp( aParam, "rgba" ) == 0 )
5586 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
5587 aBufferType = Graphic3d_BT_RGBA;
5589 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
5591 aFormat = Image_PixMap::ImgRGBAF;
5592 aBufferType = Graphic3d_BT_RGBA;
5594 else if ( strcasecmp( aParam, "depth" ) == 0 )
5596 aFormat = Image_PixMap::ImgGrayF;
5597 aBufferType = Graphic3d_BT_Depth;
5599 else if ( strcasecmp( aParam, "name" ) == 0 )
5601 toShowName = Standard_True;
5605 Image_PixMap anImage;
5606 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
5608 std::cerr << "Image allocation failed\n";
5611 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
5613 std::cerr << "Image dump failed\n";
5617 Quantity_Parameter anAlpha;
5618 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
5621 if (aBufferType == Graphic3d_BT_RGBA)
5623 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha;
5627 theDI << Quantity_Color::StringName (aColor.Name());
5632 switch (aBufferType)
5635 case Graphic3d_BT_RGB:
5639 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation();
5643 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue();
5647 case Graphic3d_BT_RGBA:
5649 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha;
5652 case Graphic3d_BT_Depth:
5654 theDI << aColor.Red();
5663 //==============================================================================
5664 //function : VDiffImage
5665 //purpose : The draw-command compares two images.
5666 //==============================================================================
5668 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
5672 theDI << "Not enough arguments.\n";
5677 const char* anImgPathRef = theArgVec[1];
5678 const char* anImgPathNew = theArgVec[2];
5680 // get string tolerance and check its validity
5681 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
5682 if (aTolColor < 0.0)
5684 if (aTolColor > 1.0)
5687 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
5688 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
5690 // image file of difference
5691 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
5693 // compare the images
5694 Image_Diff aComparer;
5695 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
5700 aComparer.SetColorTolerance (aTolColor);
5701 aComparer.SetBorderFilterOn (isBorderFilterOn);
5702 Standard_Integer aDiffColorsNb = aComparer.Compare();
5703 theDI << aDiffColorsNb << "\n";
5705 // save image of difference
5706 if (aDiffColorsNb >0 && aDiffImagePath != NULL)
5708 aComparer.SaveDiffImage (aDiffImagePath);
5714 //=======================================================================
5715 //function : VSelect
5716 //purpose : Emulates different types of selection by mouse:
5717 // 1) single click selection
5718 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
5719 // 3) selection with polygon having corners at
5720 // pixel positions (x1,y1),...,(xn,yn)
5721 // 4) any of these selections with shift button pressed
5722 //=======================================================================
5723 static Standard_Integer VSelect (Draw_Interpretor& di,
5724 Standard_Integer argc,
5729 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]\n";
5733 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
5734 if(myAIScontext.IsNull())
5736 di << "use 'vinit' command before " << argv[0] << "\n";
5740 const Standard_Boolean isShiftSelection = (argc > 3 && !(argc % 2) && (atoi (argv[argc - 1]) == 1));
5741 Standard_Integer aCoordsNb = isShiftSelection ? argc - 2 : argc - 1;
5742 TCollection_AsciiString anArg;
5743 anArg = isShiftSelection ? argv[argc - 3] : argv[argc - 2];
5745 if (anArg == "-allowoverlap")
5747 Standard_Boolean isValidated = isShiftSelection ? argc == 8
5751 di << "Wrong number of arguments! -allowoverlap key is applied only for rectangle selection";
5755 Standard_Integer isToAllow = isShiftSelection ? Draw::Atoi(argv[argc - 2]) : Draw::Atoi(argv[argc - 1]);
5756 myAIScontext->MainSelector()->AllowOverlapDetection (isToAllow != 0);
5760 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
5761 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
5764 if(isShiftSelection)
5765 aCurrentEventManager->ShiftSelect();
5767 aCurrentEventManager->Select();
5769 else if(aCoordsNb == 4)
5771 if(isShiftSelection)
5772 aCurrentEventManager->ShiftSelect (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
5774 aCurrentEventManager->Select (atoi (argv[1]), atoi (argv[2]), atoi (argv[3]), atoi (argv[4]), Standard_False);
5778 TColgp_Array1OfPnt2d aPolyline (1,aCoordsNb / 2);
5780 for(Standard_Integer i=1;i<=aCoordsNb / 2;++i)
5781 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
5783 if(isShiftSelection)
5784 aCurrentEventManager->ShiftSelect(aPolyline);
5786 aCurrentEventManager->Select(aPolyline);
5791 //=======================================================================
5792 //function : VMoveTo
5793 //purpose : Emulates cursor movement to defined pixel position
5794 //=======================================================================
5795 static Standard_Integer VMoveTo (Draw_Interpretor& di,
5796 Standard_Integer argc,
5801 di << "Usage : " << argv[0] << " x y\n";
5805 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5806 if(aContext.IsNull())
5808 di << "use 'vinit' command before " << argv[0] << "\n";
5811 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
5815 //=================================================================================================
5816 //function : VViewParams
5817 //purpose : Gets or sets AIS View characteristics
5818 //=================================================================================================
5819 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5821 Handle(V3d_View) anAISView = ViewerTest::CurrentView();
5822 if (anAISView.IsNull())
5824 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
5830 // print all of the available view parameters
5831 Quantity_Factor anAISViewScale = anAISView->Scale();
5833 Standard_Real anAISViewProjX = 0.0;
5834 Standard_Real anAISViewProjY = 0.0;
5835 Standard_Real anAISViewProjZ = 0.0;
5836 anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
5838 Standard_Real anAISViewUpX = 0.0;
5839 Standard_Real anAISViewUpY = 0.0;
5840 Standard_Real anAISViewUpZ = 0.0;
5841 anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
5843 Standard_Real anAISViewAtX = 0.0;
5844 Standard_Real anAISViewAtY = 0.0;
5845 Standard_Real anAISViewAtZ = 0.0;
5846 anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
5848 Standard_Real anAISViewEyeX = 0.0;
5849 Standard_Real anAISViewEyeY = 0.0;
5850 Standard_Real anAISViewEyeZ = 0.0;
5851 anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ);
5853 theDi << "Scale of current view: " << anAISViewScale << "\n";
5854 theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
5855 theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
5856 theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
5857 theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n";
5861 // -------------------------
5862 // Parse options and values
5863 // -------------------------
5865 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues;
5866 TCollection_AsciiString aParseKey;
5867 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5869 TCollection_AsciiString anArg (theArgVec [anArgIt]);
5871 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
5874 aParseKey.Remove (1);
5875 aParseKey.UpperCase();
5876 aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
5880 if (aParseKey.IsEmpty())
5882 std::cout << theArgVec[0] << ": values should be passed with key.\n";
5883 std::cout << "Type help for more information.\n";
5887 aMapOfKeysByValues(aParseKey)->Append (anArg);
5890 // ---------------------------------------------
5891 // Change or print parameters, order plays role
5892 // ---------------------------------------------
5894 // Check arguments for validity
5895 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues);
5896 for (; aMapIt.More(); aMapIt.Next())
5898 const TCollection_AsciiString& aKey = aMapIt.Key();
5899 const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value();
5901 if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5902 && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5903 && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty()))
5904 && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty()))
5905 && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty()))
5906 && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty()))
5907 && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2))
5909 TCollection_AsciiString aLowerKey;
5912 aLowerKey.LowerCase();
5913 std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n";
5914 std::cout << "Type help for more information.\n";
5919 Handle(TColStd_HSequenceOfAsciiString) aValues;
5921 // Change view parameters in proper order
5922 if (aMapOfKeysByValues.Find ("SCALE", aValues))
5924 if (aValues->IsEmpty())
5926 theDi << "Scale: " << anAISView->Scale() << "\n";
5930 anAISView->SetScale (aValues->Value(1).RealValue());
5933 if (aMapOfKeysByValues.Find ("SIZE", aValues))
5935 if (aValues->IsEmpty())
5937 Standard_Real aSizeX = 0.0;
5938 Standard_Real aSizeY = 0.0;
5939 anAISView->Size (aSizeX, aSizeY);
5940 theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n";
5944 anAISView->SetSize (aValues->Value(1).RealValue());
5947 if (aMapOfKeysByValues.Find ("EYE", aValues))
5949 if (aValues->IsEmpty())
5951 Standard_Real anEyeX = 0.0;
5952 Standard_Real anEyeY = 0.0;
5953 Standard_Real anEyeZ = 0.0;
5954 anAISView->Eye (anEyeX, anEyeY, anEyeZ);
5955 theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n";
5959 anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5962 if (aMapOfKeysByValues.Find ("AT", aValues))
5964 if (aValues->IsEmpty())
5966 Standard_Real anAtX = 0.0;
5967 Standard_Real anAtY = 0.0;
5968 Standard_Real anAtZ = 0.0;
5969 anAISView->At (anAtX, anAtY, anAtZ);
5970 theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n";
5974 anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5977 if (aMapOfKeysByValues.Find ("PROJ", aValues))
5979 if (aValues->IsEmpty())
5981 Standard_Real aProjX = 0.0;
5982 Standard_Real aProjY = 0.0;
5983 Standard_Real aProjZ = 0.0;
5984 anAISView->Proj (aProjX, aProjY, aProjZ);
5985 theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n";
5989 anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5992 if (aMapOfKeysByValues.Find ("UP", aValues))
5994 if (aValues->IsEmpty())
5996 Standard_Real anUpX = 0.0;
5997 Standard_Real anUpY = 0.0;
5998 Standard_Real anUpZ = 0.0;
5999 anAISView->Up (anUpX, anUpY, anUpZ);
6000 theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n";
6004 anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6007 if (aMapOfKeysByValues.Find ("CENTER", aValues))
6009 anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue());
6015 //=======================================================================
6016 //function : VChangeSelected
6017 //purpose : Adds the shape to selection or remove one from it
6018 //=======================================================================
6019 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
6020 Standard_Integer argc,
6025 di<<"Usage : " << argv[0] << " shape \n";
6029 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6030 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
6031 TCollection_AsciiString aName(argv[1]);
6032 Handle(AIS_InteractiveObject) anAISObject;
6034 if(!aMap.IsBound2(aName))
6036 di<<"Use 'vdisplay' before";
6041 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
6042 if(anAISObject.IsNull()){
6043 di<<"No interactive object \n";
6047 aContext->AddOrRemoveSelected(anAISObject);
6052 //=======================================================================
6053 //function : VNbSelected
6054 //purpose : Returns number of selected objects
6055 //=======================================================================
6056 static Standard_Integer VNbSelected (Draw_Interpretor& di,
6057 Standard_Integer argc,
6062 di << "Usage : " << argv[0] << "\n";
6065 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6066 if(aContext.IsNull())
6068 di << "use 'vinit' command before " << argv[0] << "\n";
6071 di << aContext->NbSelected() << "\n";
6075 //=======================================================================
6076 //function : VPurgeDisplay
6077 //purpose : Switches altialiasing on or off
6078 //=======================================================================
6079 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
6080 Standard_Integer argc,
6085 di << "Usage : " << argv[0] << "\n";
6088 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6089 if (aContext.IsNull())
6091 di << "use 'vinit' command before " << argv[0] << "\n";
6094 aContext->CloseAllContexts(Standard_False);
6095 di << aContext->PurgeDisplay() << "\n";
6099 //=======================================================================
6100 //function : VSetViewSize
6102 //=======================================================================
6103 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
6104 Standard_Integer argc,
6107 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6108 if(aContext.IsNull())
6110 di << "use 'vinit' command before " << argv[0] << "\n";
6115 di<<"Usage : " << argv[0] << " Size\n";
6118 Standard_Real aSize = Draw::Atof (argv[1]);
6121 di<<"Bad Size value : " << aSize << "\n";
6125 Handle(V3d_View) aView = ViewerTest::CurrentView();
6126 aView->SetSize(aSize);
6130 //=======================================================================
6131 //function : VMoveView
6133 //=======================================================================
6134 static Standard_Integer VMoveView (Draw_Interpretor& di,
6135 Standard_Integer argc,
6138 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6139 if(aContext.IsNull())
6141 di << "use 'vinit' command before " << argv[0] << "\n";
6144 if(argc < 4 || argc > 5)
6146 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
6149 Standard_Real Dx = Draw::Atof (argv[1]);
6150 Standard_Real Dy = Draw::Atof (argv[2]);
6151 Standard_Real Dz = Draw::Atof (argv[3]);
6152 Standard_Boolean aStart = Standard_True;
6155 aStart = (Draw::Atoi (argv[4]) > 0);
6158 Handle(V3d_View) aView = ViewerTest::CurrentView();
6159 aView->Move(Dx,Dy,Dz,aStart);
6163 //=======================================================================
6164 //function : VTranslateView
6166 //=======================================================================
6167 static Standard_Integer VTranslateView (Draw_Interpretor& di,
6168 Standard_Integer argc,
6171 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6172 if(aContext.IsNull())
6174 di << "use 'vinit' command before " << argv[0] << "\n";
6177 if(argc < 4 || argc > 5)
6179 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
6182 Standard_Real Dx = Draw::Atof (argv[1]);
6183 Standard_Real Dy = Draw::Atof (argv[2]);
6184 Standard_Real Dz = Draw::Atof (argv[3]);
6185 Standard_Boolean aStart = Standard_True;
6188 aStart = (Draw::Atoi (argv[4]) > 0);
6191 Handle(V3d_View) aView = ViewerTest::CurrentView();
6192 aView->Translate(Dx,Dy,Dz,aStart);
6196 //=======================================================================
6197 //function : VTurnView
6199 //=======================================================================
6200 static Standard_Integer VTurnView (Draw_Interpretor& di,
6201 Standard_Integer argc,
6204 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6205 if(aContext.IsNull()) {
6206 di << "use 'vinit' command before " << argv[0] << "\n";
6209 if(argc < 4 || argc > 5){
6210 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
6213 Standard_Real Ax = Draw::Atof (argv[1]);
6214 Standard_Real Ay = Draw::Atof (argv[2]);
6215 Standard_Real Az = Draw::Atof (argv[3]);
6216 Standard_Boolean aStart = Standard_True;
6219 aStart = (Draw::Atoi (argv[4]) > 0);
6222 Handle(V3d_View) aView = ViewerTest::CurrentView();
6223 aView->Turn(Ax,Ay,Az,aStart);
6227 //==============================================================================
6228 //function : VTextureEnv
6229 //purpose : ENables or disables environment mapping
6230 //==============================================================================
6231 class OCC_TextureEnv : public Graphic3d_TextureEnv
6234 OCC_TextureEnv(const Standard_CString FileName);
6235 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
6236 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
6237 const Standard_Boolean theModulateFlag,
6238 const Graphic3d_TypeOfTextureFilter theFilter,
6239 const Standard_ShortReal theXScale,
6240 const Standard_ShortReal theYScale,
6241 const Standard_ShortReal theXShift,
6242 const Standard_ShortReal theYShift,
6243 const Standard_ShortReal theAngle);
6244 DEFINE_STANDARD_RTTI_INLINE(OCC_TextureEnv,Graphic3d_TextureEnv)
6246 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv)
6248 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
6249 : Graphic3d_TextureEnv(theFileName)
6253 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
6254 : Graphic3d_TextureEnv(theTexId)
6258 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
6259 const Standard_Boolean theModulateFlag,
6260 const Graphic3d_TypeOfTextureFilter theFilter,
6261 const Standard_ShortReal theXScale,
6262 const Standard_ShortReal theYScale,
6263 const Standard_ShortReal theXShift,
6264 const Standard_ShortReal theYShift,
6265 const Standard_ShortReal theAngle)
6267 myParams->SetRepeat (theRepeatFlag);
6268 myParams->SetModulate (theModulateFlag);
6269 myParams->SetFilter (theFilter);
6270 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
6271 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
6272 myParams->SetRotation (theAngle);
6275 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
6277 // get the active view
6278 Handle(V3d_View) aView = ViewerTest::CurrentView();
6281 std::cerr << "No active view. Please call vinit.\n";
6285 // Checking the input arguments
6286 Standard_Boolean anEnableFlag = Standard_False;
6287 Standard_Boolean isOk = theArgNb >= 2;
6290 TCollection_AsciiString anEnableOpt(theArgVec[1]);
6291 anEnableFlag = anEnableOpt.IsEqual("on");
6292 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
6296 isOk = (theArgNb == 3 || theArgNb == 11);
6299 TCollection_AsciiString aTextureOpt(theArgVec[2]);
6300 isOk = (!aTextureOpt.IsIntegerValue() ||
6301 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
6303 if (isOk && theArgNb == 11)
6305 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
6306 aModulateOpt(theArgVec[4]),
6307 aFilterOpt (theArgVec[5]),
6308 aSScaleOpt (theArgVec[6]),
6309 aTScaleOpt (theArgVec[7]),
6310 aSTransOpt (theArgVec[8]),
6311 aTTransOpt (theArgVec[9]),
6312 anAngleOpt (theArgVec[10]);
6313 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
6314 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
6315 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
6316 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
6317 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
6318 anAngleOpt.IsRealValue());
6325 std::cerr << "Usage :" << std::endl;
6326 std::cerr << theArgVec[0] << " off" << std::endl;
6327 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;
6333 TCollection_AsciiString aTextureOpt(theArgVec[2]);
6334 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
6335 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
6336 new OCC_TextureEnv(theArgVec[2]);
6340 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
6341 aTexEnv->SetTextureParameters(
6342 aRepeatOpt. IsEqual("repeat"),
6343 aModulateOpt.IsEqual("modulate"),
6344 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
6345 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
6346 Graphic3d_TOTF_TRILINEAR,
6347 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
6348 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
6349 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
6350 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
6351 (Standard_ShortReal)Draw::Atof(theArgVec[10])
6354 aView->SetTextureEnv(aTexEnv);
6356 else // Disabling environment mapping
6358 Handle(Graphic3d_TextureEnv) aTexture;
6359 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
6368 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
6370 //! Remove registered clipping plane from all views and objects.
6371 static void removePlane (MapOfPlanes& theRegPlanes,
6372 const TCollection_AsciiString& theName)
6374 Handle(Graphic3d_ClipPlane) aClipPlane;
6375 if (!theRegPlanes.Find (theName, aClipPlane))
6377 std::cout << "Warning: no such plane.\n";
6381 theRegPlanes.UnBind (theName);
6382 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
6383 anIObjIt.More(); anIObjIt.Next())
6385 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
6386 aPrs->RemoveClipPlane (aClipPlane);
6389 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
6390 aViewIt.More(); aViewIt.Next())
6392 const Handle(V3d_View)& aView = aViewIt.Key2();
6393 aView->RemoveClipPlane(aClipPlane);
6396 ViewerTest::RedrawAllViews();
6400 //===============================================================================================
6401 //function : VClipPlane
6403 //===============================================================================================
6404 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6406 // use short-cut for created clip planes map of created (or "registered by name") clip planes
6407 static MapOfPlanes aRegPlanes;
6411 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More(); aPlaneIter.Next())
6413 theDi << aPlaneIter.Key() << " ";
6418 TCollection_AsciiString aCommand (theArgVec[1]);
6419 aCommand.LowerCase();
6420 const Handle(V3d_View)& anActiveView = ViewerTest::CurrentView();
6421 if (anActiveView.IsNull())
6423 std::cout << "Error: no active view.\n";
6427 // print maximum number of planes for current viewer
6428 if (aCommand == "-maxplanes"
6429 || aCommand == "maxplanes")
6431 theDi << anActiveView->Viewer()->Driver()->InquirePlaneLimit()
6432 << " plane slots provided by driver.\n";
6436 // create / delete plane instance
6437 if (aCommand == "-create"
6438 || aCommand == "create"
6439 || aCommand == "-delete"
6440 || aCommand == "delete"
6441 || aCommand == "-clone"
6442 || aCommand == "clone")
6446 std::cout << "Syntax error: plane name is required.\n";
6450 Standard_Boolean toCreate = aCommand == "-create"
6451 || aCommand == "create";
6452 Standard_Boolean toClone = aCommand == "-clone"
6453 || aCommand == "clone";
6454 Standard_Boolean toDelete = aCommand == "-delete"
6455 || aCommand == "delete";
6456 TCollection_AsciiString aPlane (theArgVec[2]);
6460 if (aRegPlanes.IsBound (aPlane))
6462 std::cout << "Warning: existing plane has been overridden.\n";
6467 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
6471 else if (toClone) // toClone
6473 if (!aRegPlanes.IsBound (aPlane))
6475 std::cout << "Error: no such plane.\n";
6478 else if (theArgsNb < 4)
6480 std::cout << "Syntax error: enter name for new plane.\n";
6484 TCollection_AsciiString aClone (theArgVec[3]);
6485 if (aRegPlanes.IsBound (aClone))
6487 std::cout << "Error: plane name is in use.\n";
6491 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6493 aRegPlanes.Bind (aClone, aClipPlane->Clone());
6503 for (MapOfPlanes::Iterator aPlaneIter (aRegPlanes); aPlaneIter.More();)
6505 aPlane = aPlaneIter.Key();
6506 removePlane (aRegPlanes, aPlane);
6507 aPlaneIter = MapOfPlanes::Iterator (aRegPlanes);
6512 removePlane (aRegPlanes, aPlane);
6518 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
6523 // set / unset plane command
6524 if (aCommand == "set"
6525 || aCommand == "unset")
6529 std::cout << "Syntax error: need more arguments.\n";
6533 // redirect to new syntax
6534 NCollection_Array1<const char*> anArgVec (1, theArgsNb - 1);
6535 anArgVec.SetValue (1, theArgVec[0]);
6536 anArgVec.SetValue (2, theArgVec[2]);
6537 anArgVec.SetValue (3, aCommand == "set" ? "-set" : "-unset");
6538 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
6540 anArgVec.SetValue (anIt, theArgVec[anIt]);
6543 return VClipPlane (theDi, anArgVec.Length(), &anArgVec.ChangeFirst());
6546 // change plane command
6547 TCollection_AsciiString aPlaneName;
6548 Handle(Graphic3d_ClipPlane) aClipPlane;
6549 Standard_Integer anArgIter = 0;
6550 if (aCommand == "-change"
6551 || aCommand == "change")
6553 // old syntax support
6556 std::cout << "Syntax error: need more arguments.\n";
6561 aPlaneName = theArgVec[2];
6562 if (!aRegPlanes.Find (aPlaneName, aClipPlane))
6564 std::cout << "Error: no such plane '" << aPlaneName << "'.\n";
6568 else if (aRegPlanes.Find (theArgVec[1], aClipPlane))
6571 aPlaneName = theArgVec[1];
6576 aPlaneName = theArgVec[1];
6577 aClipPlane = new Graphic3d_ClipPlane();
6578 aRegPlanes.Bind (aPlaneName, aClipPlane);
6579 theDi << "Created new plane " << aPlaneName << ".\n";
6582 if (theArgsNb - anArgIter < 1)
6584 std::cout << "Syntax error: need more arguments.\n";
6588 for (; anArgIter < theArgsNb; ++anArgIter)
6590 const char** aChangeArgs = theArgVec + anArgIter;
6591 Standard_Integer aNbChangeArgs = theArgsNb - anArgIter;
6592 TCollection_AsciiString aChangeArg (aChangeArgs[0]);
6593 aChangeArg.LowerCase();
6595 Standard_Boolean toEnable = Standard_True;
6596 if (ViewerTest::ParseOnOff (aChangeArgs[0], toEnable))
6598 aClipPlane->SetOn (toEnable);
6600 else if (aChangeArg == "-equation"
6601 || aChangeArg == "equation")
6603 if (aNbChangeArgs < 5)
6605 std::cout << "Syntax error: need more arguments.\n";
6609 Standard_Real aCoeffA = Draw::Atof (aChangeArgs [1]);
6610 Standard_Real aCoeffB = Draw::Atof (aChangeArgs [2]);
6611 Standard_Real aCoeffC = Draw::Atof (aChangeArgs [3]);
6612 Standard_Real aCoeffD = Draw::Atof (aChangeArgs [4]);
6613 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
6616 else if (aChangeArg == "-capping"
6617 || aChangeArg == "capping")
6619 if (aNbChangeArgs < 2)
6621 std::cout << "Syntax error: need more arguments.\n";
6625 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
6627 aClipPlane->SetCapping (toEnable);
6632 // just skip otherwise (old syntax)
6635 else if (aChangeArg == "-useobjectmaterial"
6636 || aChangeArg == "-useobjectmat"
6637 || aChangeArg == "-useobjmat"
6638 || aChangeArg == "-useobjmaterial")
6640 if (aNbChangeArgs < 2)
6642 std::cout << "Syntax error: need more arguments.\n";
6646 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
6648 aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
6652 else if (aChangeArg == "-useobjecttexture"
6653 || aChangeArg == "-useobjecttex"
6654 || aChangeArg == "-useobjtexture"
6655 || aChangeArg == "-useobjtex")
6657 if (aNbChangeArgs < 2)
6659 std::cout << "Syntax error: need more arguments.\n";
6663 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
6665 aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
6669 else if (aChangeArg == "-useobjectshader"
6670 || aChangeArg == "-useobjshader")
6672 if (aNbChangeArgs < 2)
6674 std::cout << "Syntax error: need more arguments.\n";
6678 if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
6680 aClipPlane->SetUseObjectShader (toEnable == Standard_True);
6684 else if (aChangeArg == "-color"
6685 || aChangeArg == "color")
6687 Quantity_Color aColor;
6688 Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
6693 std::cout << "Syntax error: need more arguments.\n";
6697 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
6698 aMat.SetAmbientColor (aColor);
6699 aMat.SetDiffuseColor (aColor);
6700 aClipPlane->SetCappingMaterial (aMat);
6701 anArgIter += aNbParsed;
6703 else if (aChangeArg == "-texname"
6704 || aChangeArg == "texname")
6706 if (aNbChangeArgs < 2)
6708 std::cout << "Syntax error: need more arguments.\n";
6712 TCollection_AsciiString aTextureName (aChangeArgs[1]);
6713 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
6714 if (!aTexture->IsDone())
6716 aClipPlane->SetCappingTexture (NULL);
6720 aTexture->EnableModulate();
6721 aTexture->EnableRepeat();
6722 aClipPlane->SetCappingTexture (aTexture);
6726 else if (aChangeArg == "-texscale"
6727 || aChangeArg == "texscale")
6729 if (aClipPlane->CappingTexture().IsNull())
6731 std::cout << "Error: no texture is set.\n";
6735 if (aNbChangeArgs < 3)
6737 std::cout << "Syntax error: need more arguments.\n";
6741 Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
6742 Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
6743 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
6746 else if (aChangeArg == "-texorigin"
6747 || aChangeArg == "texorigin") // texture origin
6749 if (aClipPlane->CappingTexture().IsNull())
6751 std::cout << "Error: no texture is set.\n";
6755 if (aNbChangeArgs < 3)
6757 std::cout << "Syntax error: need more arguments.\n";
6761 Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
6762 Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
6764 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
6767 else if (aChangeArg == "-texrotate"
6768 || aChangeArg == "texrotate") // texture rotation
6770 if (aClipPlane->CappingTexture().IsNull())
6772 std::cout << "Error: no texture is set.\n";
6776 if (aNbChangeArgs < 2)
6778 std::cout << "Syntax error: need more arguments.\n";
6782 Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
6783 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
6786 else if (aChangeArg == "-hatch"
6787 || aChangeArg == "hatch")
6789 if (aNbChangeArgs < 2)
6791 std::cout << "Syntax error: need more arguments.\n";
6795 TCollection_AsciiString aHatchStr (aChangeArgs[1]);
6796 aHatchStr.LowerCase();
6797 if (aHatchStr == "on")
6799 aClipPlane->SetCappingHatchOn();
6801 else if (aHatchStr == "off")
6803 aClipPlane->SetCappingHatchOff();
6807 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
6811 else if (aChangeArg == "-delete"
6812 || aChangeArg == "delete")
6814 removePlane (aRegPlanes, aPlaneName);
6817 else if (aChangeArg == "-set"
6818 || aChangeArg == "-unset")
6820 // set / unset plane command
6821 Standard_Boolean toSet = aChangeArg == "-set";
6822 Standard_Integer anIt = 1;
6823 for (; anIt < aNbChangeArgs; ++anIt)
6825 TCollection_AsciiString anEntityName (aChangeArgs[anIt]);
6826 if (anEntityName.IsEmpty()
6827 || anEntityName.Value (1) == '-')
6831 else if (ViewerTest_myViews.IsBound1 (anEntityName))
6833 Handle(V3d_View) aView = ViewerTest_myViews.Find1 (anEntityName);
6836 aView->AddClipPlane (aClipPlane);
6840 aView->RemoveClipPlane (aClipPlane);
6844 else if (GetMapOfAIS().IsBound2 (anEntityName))
6846 Handle(AIS_InteractiveObject) aIObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
6849 aIObj->AddClipPlane (aClipPlane);
6853 aIObj->RemoveClipPlane (aClipPlane);
6858 std::cout << "Error: object/view '" << anEntityName << "' is not found!\n";
6865 // apply to active view
6868 anActiveView->AddClipPlane (aClipPlane);
6872 anActiveView->RemoveClipPlane (aClipPlane);
6877 anArgIter = anArgIter + anIt - 1;
6882 std::cout << "Syntax error: unknown argument '" << aChangeArg << "'.\n";
6887 ViewerTest::RedrawAllViews();
6891 //===============================================================================================
6892 //function : VZRange
6894 //===============================================================================================
6895 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6897 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
6899 if (aCurrentView.IsNull())
6901 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
6905 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
6909 theDi << "ZNear: " << aCamera->ZNear() << "\n";
6910 theDi << "ZFar: " << aCamera->ZFar() << "\n";
6916 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
6917 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
6919 if (aNewZNear >= aNewZFar)
6921 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
6925 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
6927 std::cout << theArgVec[0] << ": invalid arguments: ";
6928 std::cout << "znear, zfar should be positive for perspective camera.\n";
6932 aCamera->SetZRange (aNewZNear, aNewZFar);
6936 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
6940 aCurrentView->Redraw();
6945 //===============================================================================================
6946 //function : VAutoZFit
6948 //===============================================================================================
6949 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6951 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
6953 if (aCurrentView.IsNull())
6955 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
6959 Standard_Real aScale = aCurrentView->AutoZFitScaleFactor();
6963 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
6969 theDi << "Auto z-fit mode: \n"
6970 << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n"
6971 << "Scale: " << aScale << "\n";
6975 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
6979 aScale = Draw::Atoi (theArgVec[2]);
6982 aCurrentView->SetAutoZFitMode (isOn, aScale);
6983 aCurrentView->AutoZFit();
6984 aCurrentView->Redraw();
6989 //! Auxiliary function to print projection type
6990 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
6992 switch (theProjType)
6994 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
6995 case Graphic3d_Camera::Projection_Perspective: return "perspective";
6996 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
6997 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
6998 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
7003 //===============================================================================================
7004 //function : VCamera
7006 //===============================================================================================
7007 static int VCamera (Draw_Interpretor& theDI,
7008 Standard_Integer theArgsNb,
7009 const char** theArgVec)
7011 Handle(V3d_View) aView = ViewerTest::CurrentView();
7014 std::cout << "Error: no active view.\n";
7018 Handle(Graphic3d_Camera) aCamera = aView->Camera();
7021 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
7022 theDI << "FOVy: " << aCamera->FOVy() << "\n";
7023 theDI << "Distance: " << aCamera->Distance() << "\n";
7024 theDI << "IOD: " << aCamera->IOD() << "\n";
7025 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
7026 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
7027 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
7031 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7033 Standard_CString anArg = theArgVec[anArgIter];
7034 TCollection_AsciiString anArgCase (anArg);
7035 anArgCase.LowerCase();
7036 if (anArgCase == "-proj"
7037 || anArgCase == "-projection"
7038 || anArgCase == "-projtype"
7039 || anArgCase == "-projectiontype")
7041 theDI << projTypeName (aCamera->ProjectionType()) << " ";
7043 else if (anArgCase == "-ortho"
7044 || anArgCase == "-orthographic")
7046 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
7048 else if (anArgCase == "-persp"
7049 || anArgCase == "-perspective"
7050 || anArgCase == "-perspmono"
7051 || anArgCase == "-perspectivemono"
7052 || anArgCase == "-mono")
7054 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
7056 else if (anArgCase == "-stereo"
7057 || anArgCase == "-stereoscopic"
7058 || anArgCase == "-perspstereo"
7059 || anArgCase == "-perspectivestereo")
7061 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7063 else if (anArgCase == "-left"
7064 || anArgCase == "-lefteye"
7065 || anArgCase == "-monoleft"
7066 || anArgCase == "-monolefteye"
7067 || anArgCase == "-perpsleft"
7068 || anArgCase == "-perpslefteye")
7070 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
7072 else if (anArgCase == "-right"
7073 || anArgCase == "-righteye"
7074 || anArgCase == "-monoright"
7075 || anArgCase == "-monorighteye"
7076 || anArgCase == "-perpsright")
7078 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
7080 else if (anArgCase == "-dist"
7081 || anArgCase == "-distance")
7083 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7084 if (anArgValue != NULL
7085 && *anArgValue != '-')
7088 aCamera->SetDistance (Draw::Atof (anArgValue));
7091 theDI << aCamera->Distance() << " ";
7093 else if (anArgCase == "-iod")
7095 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7096 if (anArgValue != NULL
7097 && *anArgValue != '-')
7100 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
7103 theDI << aCamera->IOD() << " ";
7105 else if (anArgCase == "-iodtype")
7107 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
7108 TCollection_AsciiString anValueCase (anArgValue);
7109 anValueCase.LowerCase();
7110 if (anValueCase == "abs"
7111 || anValueCase == "absolute")
7114 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
7117 else if (anValueCase == "rel"
7118 || anValueCase == "relative")
7121 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
7124 else if (*anArgValue != '-')
7126 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
7129 switch (aCamera->GetIODType())
7131 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
7132 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
7135 else if (anArgCase == "-zfocus")
7137 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7138 if (anArgValue != NULL
7139 && *anArgValue != '-')
7142 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
7145 theDI << aCamera->ZFocus() << " ";
7147 else if (anArgCase == "-zfocustype")
7149 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
7150 TCollection_AsciiString anValueCase (anArgValue);
7151 anValueCase.LowerCase();
7152 if (anValueCase == "abs"
7153 || anValueCase == "absolute")
7156 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
7159 else if (anValueCase == "rel"
7160 || anValueCase == "relative")
7163 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
7166 else if (*anArgValue != '-')
7168 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
7171 switch (aCamera->ZFocusType())
7173 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
7174 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
7177 else if (anArgCase == "-fov"
7178 || anArgCase == "-fovy")
7180 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7181 if (anArgValue != NULL
7182 && *anArgValue != '-')
7185 aCamera->SetFOVy (Draw::Atof (anArgValue));
7188 theDI << aCamera->FOVy() << " ";
7192 std::cout << "Error: unknown argument '" << anArg << "'\n";
7203 //! Parse stereo output mode
7204 inline Standard_Boolean parseStereoMode (Standard_CString theArg,
7205 Graphic3d_StereoMode& theMode)
7207 TCollection_AsciiString aFlag (theArg);
7209 if (aFlag == "quadbuffer")
7211 theMode = Graphic3d_StereoMode_QuadBuffer;
7213 else if (aFlag == "anaglyph")
7215 theMode = Graphic3d_StereoMode_Anaglyph;
7217 else if (aFlag == "row"
7218 || aFlag == "rowinterlaced")
7220 theMode = Graphic3d_StereoMode_RowInterlaced;
7222 else if (aFlag == "col"
7223 || aFlag == "colinterlaced"
7224 || aFlag == "columninterlaced")
7226 theMode = Graphic3d_StereoMode_ColumnInterlaced;
7228 else if (aFlag == "chess"
7229 || aFlag == "chessboard")
7231 theMode = Graphic3d_StereoMode_ChessBoard;
7233 else if (aFlag == "sbs"
7234 || aFlag == "sidebyside")
7236 theMode = Graphic3d_StereoMode_SideBySide;
7238 else if (aFlag == "ou"
7239 || aFlag == "overunder")
7241 theMode = Graphic3d_StereoMode_OverUnder;
7243 else if (aFlag == "pageflip"
7244 || aFlag == "softpageflip")
7246 theMode = Graphic3d_StereoMode_SoftPageFlip;
7250 return Standard_False;
7252 return Standard_True;
7255 //! Parse anaglyph filter
7256 inline Standard_Boolean parseAnaglyphFilter (Standard_CString theArg,
7257 Graphic3d_RenderingParams::Anaglyph& theFilter)
7259 TCollection_AsciiString aFlag (theArg);
7261 if (aFlag == "redcyansimple")
7263 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
7265 else if (aFlag == "redcyan"
7266 || aFlag == "redcyanoptimized")
7268 theFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
7270 else if (aFlag == "yellowbluesimple")
7272 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple;
7274 else if (aFlag == "yellowblue"
7275 || aFlag == "yellowblueoptimized")
7277 theFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
7279 else if (aFlag == "greenmagenta"
7280 || aFlag == "greenmagentasimple")
7282 theFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
7286 return Standard_False;
7288 return Standard_True;
7291 //==============================================================================
7292 //function : VStereo
7294 //==============================================================================
7296 static int VStereo (Draw_Interpretor& theDI,
7297 Standard_Integer theArgNb,
7298 const char** theArgVec)
7300 Handle(V3d_View) aView = ViewerTest::CurrentView();
7305 std::cout << "Error: no active viewer!\n";
7309 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
7310 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
7313 TCollection_AsciiString aMode;
7314 switch (aView->RenderingParams().StereoMode)
7316 case Graphic3d_StereoMode_QuadBuffer : aMode = "quadBuffer"; break;
7317 case Graphic3d_StereoMode_RowInterlaced : aMode = "rowInterlaced"; break;
7318 case Graphic3d_StereoMode_ColumnInterlaced : aMode = "columnInterlaced"; break;
7319 case Graphic3d_StereoMode_ChessBoard : aMode = "chessBoard"; break;
7320 case Graphic3d_StereoMode_SideBySide : aMode = "sideBySide"; break;
7321 case Graphic3d_StereoMode_OverUnder : aMode = "overUnder"; break;
7322 case Graphic3d_StereoMode_SoftPageFlip : aMode = "softpageflip"; break;
7323 case Graphic3d_StereoMode_Anaglyph :
7325 switch (aView->RenderingParams().AnaglyphFilter)
7327 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple : aMode.AssignCat (" (redCyanSimple)"); break;
7328 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized : aMode.AssignCat (" (redCyan)"); break;
7329 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple : aMode.AssignCat (" (yellowBlueSimple)"); break;
7330 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: aMode.AssignCat (" (yellowBlue)"); break;
7331 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple : aMode.AssignCat (" (greenMagentaSimple)"); break;
7336 theDI << "Mode " << aMode << "\n";
7341 Handle(Graphic3d_Camera) aCamera;
7342 Graphic3d_RenderingParams* aParams = NULL;
7343 Graphic3d_StereoMode aMode = Graphic3d_StereoMode_QuadBuffer;
7344 if (!aView.IsNull())
7346 aParams = &aView->ChangeRenderingParams();
7347 aMode = aParams->StereoMode;
7348 aCamera = aView->Camera();
7351 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7352 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7354 Standard_CString anArg = theArgVec[anArgIter];
7355 TCollection_AsciiString aFlag (anArg);
7357 if (anUpdateTool.parseRedrawMode (aFlag))
7361 else if (aFlag == "0"
7364 if (++anArgIter < theArgNb)
7366 std::cout << "Error: wrong number of arguments!\n";
7370 if (!aCamera.IsNull()
7371 && aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
7373 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
7375 ViewerTest_myDefaultCaps.contextStereo = Standard_False;
7378 else if (aFlag == "1"
7381 if (++anArgIter < theArgNb)
7383 std::cout << "Error: wrong number of arguments!\n";
7387 if (!aCamera.IsNull())
7389 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7391 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
7394 else if (aFlag == "-reverse"
7395 || aFlag == "-reversed"
7396 || aFlag == "-swap")
7398 Standard_Boolean toEnable = Standard_True;
7399 if (++anArgIter < theArgNb
7400 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
7404 aParams->ToReverseStereo = toEnable;
7406 else if (aFlag == "-noreverse"
7407 || aFlag == "-noswap")
7409 Standard_Boolean toDisable = Standard_True;
7410 if (++anArgIter < theArgNb
7411 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toDisable))
7415 aParams->ToReverseStereo = !toDisable;
7417 else if (aFlag == "-mode"
7418 || aFlag == "-stereomode")
7420 if (++anArgIter >= theArgNb
7421 || !parseStereoMode (theArgVec[anArgIter], aMode))
7423 std::cout << "Error: syntax error at '" << anArg << "'\n";
7427 if (aMode == Graphic3d_StereoMode_QuadBuffer)
7429 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
7432 else if (aFlag == "-anaglyph"
7433 || aFlag == "-anaglyphfilter")
7435 Graphic3d_RenderingParams::Anaglyph aFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple;
7436 if (++anArgIter >= theArgNb
7437 || !parseAnaglyphFilter (theArgVec[anArgIter], aFilter))
7439 std::cout << "Error: syntax error at '" << anArg << "'\n";
7443 aMode = Graphic3d_StereoMode_Anaglyph;
7444 aParams->AnaglyphFilter = aFilter;
7446 else if (parseStereoMode (anArg, aMode)) // short syntax
7448 if (aMode == Graphic3d_StereoMode_QuadBuffer)
7450 ViewerTest_myDefaultCaps.contextStereo = Standard_True;
7455 std::cout << "Error: syntax error at '" << anArg << "'\n";
7460 if (!aView.IsNull())
7462 aParams->StereoMode = aMode;
7463 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7468 //===============================================================================================
7469 //function : VDefaults
7471 //===============================================================================================
7472 static int VDefaults (Draw_Interpretor& theDi,
7473 Standard_Integer theArgsNb,
7474 const char** theArgVec)
7476 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
7479 std::cerr << "No active viewer!\n";
7483 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
7486 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
7488 theDi << "DeflType: relative\n"
7489 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
7493 theDi << "DeflType: absolute\n"
7494 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
7496 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
7497 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
7501 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7503 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7505 if (anArg == "-ABSDEFL"
7506 || anArg == "-ABSOLUTEDEFLECTION"
7508 || anArg == "-DEFLECTION")
7510 if (++anArgIter >= theArgsNb)
7512 std::cout << "Error: wrong syntax at " << anArg << "\n";
7515 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
7516 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
7518 else if (anArg == "-RELDEFL"
7519 || anArg == "-RELATIVEDEFLECTION"
7520 || anArg == "-DEVCOEFF"
7521 || anArg == "-DEVIATIONCOEFF"
7522 || anArg == "-DEVIATIONCOEFFICIENT")
7524 if (++anArgIter >= theArgsNb)
7526 std::cout << "Error: wrong syntax at " << anArg << "\n";
7529 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
7530 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
7532 else if (anArg == "-ANGDEFL"
7533 || anArg == "-ANGULARDEFL"
7534 || anArg == "-ANGULARDEFLECTION")
7536 if (++anArgIter >= theArgsNb)
7538 std::cout << "Error: wrong syntax at " << anArg << "\n";
7541 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
7542 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
7544 else if (anArg == "-AUTOTR"
7545 || anArg == "-AUTOTRIANG"
7546 || anArg == "-AUTOTRIANGULATION")
7548 if (++anArgIter >= theArgsNb)
7550 std::cout << "Error: wrong syntax at " << anArg << "\n";
7553 TCollection_AsciiString aValue (theArgVec[anArgIter]);
7558 aDefParams->SetAutoTriangulation (Standard_True);
7560 else if (aValue == "off"
7563 aDefParams->SetAutoTriangulation (Standard_False);
7568 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
7575 //! Auxiliary method
7576 inline void addLight (const Handle(V3d_Light)& theLightNew,
7577 const Standard_Boolean theIsGlobal)
7579 if (theLightNew.IsNull())
7586 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
7590 ViewerTest::CurrentView()->SetLightOn (theLightNew);
7594 //! Auxiliary method
7595 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
7597 TCollection_AsciiString anArgNextCase (theArgNext);
7598 anArgNextCase.UpperCase();
7599 if (anArgNextCase.Length() > 5
7600 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
7602 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
7606 return theArgNext.IntegerValue();
7610 //===============================================================================================
7613 //===============================================================================================
7614 static int VLight (Draw_Interpretor& theDi,
7615 Standard_Integer theArgsNb,
7616 const char** theArgVec)
7618 Handle(V3d_View) aView = ViewerTest::CurrentView();
7619 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
7621 || aViewer.IsNull())
7623 std::cerr << "No active viewer!\n";
7627 Standard_Real anXYZ[3];
7628 Quantity_Coefficient anAtten[2];
7631 // print lights info
7632 Standard_Integer aLightId = 0;
7633 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId)
7635 Handle(V3d_Light) aLight = aView->ActiveLight();
7636 const Quantity_Color aColor = aLight->Color();
7637 theDi << "Light" << aLightId << "\n";
7638 switch (aLight->Type())
7642 theDi << " Type: Ambient\n";
7643 theDi << " Intensity: " << aLight->Intensity() << "\n";
7646 case V3d_DIRECTIONAL:
7648 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
7649 theDi << " Type: Directional\n";
7650 theDi << " Intensity: " << aLight->Intensity() << "\n";
7651 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7652 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
7653 if (!aLightDir.IsNull())
7655 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7656 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7657 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
7658 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7662 case V3d_POSITIONAL:
7664 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
7665 theDi << " Type: Positional\n";
7666 theDi << " Intensity: " << aLight->Intensity() << "\n";
7667 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7668 theDi << " Smoothness: " << aLight->Smoothness() << "\n";
7669 if (!aLightPos.IsNull())
7671 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7672 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7673 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7674 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
7680 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
7681 theDi << " Type: Spot\n";
7682 theDi << " Intensity: " << aLight->Intensity() << "\n";
7683 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7684 if (!aLightSpot.IsNull())
7686 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7687 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7688 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
7689 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7690 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7691 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
7692 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
7693 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
7699 theDi << " Type: UNKNOWN\n";
7703 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
7707 Handle(V3d_Light) aLightNew;
7708 Handle(V3d_Light) aLightOld;
7709 Standard_Boolean isGlobal = Standard_True;
7710 Standard_Boolean toCreate = Standard_False;
7711 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
7713 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
7714 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
7715 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
7716 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
7717 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
7719 TCollection_AsciiString aName, aValue;
7720 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
7721 TCollection_AsciiString anArgCase (anArg);
7722 anArgCase.UpperCase();
7723 if (anArgCase.IsEqual ("NEW")
7724 || anArgCase.IsEqual ("ADD")
7725 || anArgCase.IsEqual ("CREATE"))
7727 toCreate = Standard_True;
7729 else if (anArgCase.IsEqual ("GLOB")
7730 || anArgCase.IsEqual ("GLOBAL"))
7732 isGlobal = Standard_True;
7734 else if (anArgCase.IsEqual ("LOC")
7735 || anArgCase.IsEqual ("LOCAL"))
7737 isGlobal = Standard_False;
7739 else if (anArgCase.IsEqual ("DEF")
7740 || anArgCase.IsEqual ("DEFAULTS"))
7742 toCreate = Standard_False;
7743 aViewer->SetDefaultLights();
7745 else if (anArgCase.IsEqual ("CLR")
7746 || anArgCase.IsEqual ("CLEAR"))
7748 toCreate = Standard_False;
7749 aView->InitActiveLights();
7750 while (aView->MoreActiveLights())
7752 aViewer->DelLight (aView->ActiveLight());
7753 aView->InitActiveLights();
7756 else if (anArgCase.IsEqual ("AMB")
7757 || anArgCase.IsEqual ("AMBIENT")
7758 || anArgCase.IsEqual ("AMBLIGHT"))
7760 addLight (aLightNew, isGlobal);
7763 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7766 toCreate = Standard_False;
7767 aLightNew = new V3d_AmbientLight (aViewer);
7769 else if (anArgCase.IsEqual ("DIRECTIONAL")
7770 || anArgCase.IsEqual ("DIRLIGHT"))
7772 addLight (aLightNew, isGlobal);
7775 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7778 toCreate = Standard_False;
7779 aLightNew = new V3d_DirectionalLight (aViewer);
7781 else if (anArgCase.IsEqual ("SPOT")
7782 || anArgCase.IsEqual ("SPOTLIGHT"))
7784 addLight (aLightNew, isGlobal);
7787 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7790 toCreate = Standard_False;
7791 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
7793 else if (anArgCase.IsEqual ("POSLIGHT")
7794 || anArgCase.IsEqual ("POSITIONAL"))
7796 addLight (aLightNew, isGlobal);
7799 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7802 toCreate = Standard_False;
7803 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
7805 else if (anArgCase.IsEqual ("CHANGE"))
7807 addLight (aLightNew, isGlobal);
7808 aLightNew.Nullify();
7809 if (++anArgIt >= theArgsNb)
7811 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7815 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
7816 Standard_Integer aLightIt = 0;
7817 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
7819 if (aLightIt == aLightId)
7821 aLightOld = aView->ActiveLight();
7826 if (aLightOld.IsNull())
7828 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
7832 else if (anArgCase.IsEqual ("DEL")
7833 || anArgCase.IsEqual ("DELETE"))
7835 Handle(V3d_Light) aLightDel;
7836 if (++anArgIt >= theArgsNb)
7838 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7842 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
7843 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
7844 Standard_Integer aLightIt = 0;
7845 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
7847 aLightDel = aView->ActiveLight();
7848 if (aLightIt == aLightDelId)
7853 if (!aLightDel.IsNull())
7855 aViewer->DelLight (aLightDel);
7858 else if (anArgCase.IsEqual ("COLOR")
7859 || anArgCase.IsEqual ("COLOUR"))
7861 if (++anArgIt >= theArgsNb)
7863 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7867 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
7868 anArgNext.UpperCase();
7869 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
7870 if (!aLightCurr.IsNull())
7872 aLightCurr->SetColor (aColor);
7875 else if (anArgCase.IsEqual ("POS")
7876 || anArgCase.IsEqual ("POSITION"))
7878 if ((anArgIt + 3) >= theArgsNb)
7880 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7884 anXYZ[0] = Atof (theArgVec[++anArgIt]);
7885 anXYZ[1] = Atof (theArgVec[++anArgIt]);
7886 anXYZ[2] = Atof (theArgVec[++anArgIt]);
7887 if (!aLightDir.IsNull())
7889 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7891 else if (!aLightPos.IsNull())
7893 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7895 else if (!aLightSpot.IsNull())
7897 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7901 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7905 else if (anArgCase.IsEqual ("DIR")
7906 || anArgCase.IsEqual ("DIRECTION"))
7908 if ((anArgIt + 3) >= theArgsNb)
7910 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7914 anXYZ[0] = Atof (theArgVec[++anArgIt]);
7915 anXYZ[1] = Atof (theArgVec[++anArgIt]);
7916 anXYZ[2] = Atof (theArgVec[++anArgIt]);
7917 if (!aLightDir.IsNull())
7919 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
7921 else if (!aLightSpot.IsNull())
7923 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
7927 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7931 else if (anArgCase.IsEqual ("SM")
7932 || anArgCase.IsEqual ("SMOOTHNESS"))
7934 if (++anArgIt >= theArgsNb)
7936 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7940 Standard_Real aSmoothness = Atof (theArgVec[anArgIt]);
7942 if (fabs (aSmoothness) < Precision::Confusion())
7944 aLightCurr->SetIntensity (1.f);
7946 else if (fabs (aLightCurr->Smoothness()) < Precision::Confusion())
7948 aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
7952 Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
7953 aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
7956 if (!aLightPos.IsNull())
7958 aLightPos->SetSmoothRadius (aSmoothness);
7960 else if (!aLightDir.IsNull())
7962 aLightDir->SetSmoothAngle (aSmoothness);
7965 else if (anArgCase.IsEqual ("INT")
7966 || anArgCase.IsEqual ("INTENSITY"))
7968 if (++anArgIt >= theArgsNb)
7970 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7974 Standard_Real aIntensity = Atof (theArgVec[anArgIt]);
7976 if (!aLightCurr.IsNull())
7978 aLightCurr->SetIntensity (aIntensity);
7981 else if (anArgCase.IsEqual ("ANG")
7982 || anArgCase.IsEqual ("ANGLE"))
7984 if (++anArgIt >= theArgsNb)
7986 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7990 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
7992 if (!aLightSpot.IsNull())
7994 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
7997 else if (anArgCase.IsEqual ("CONSTATTEN")
7998 || anArgCase.IsEqual ("CONSTATTENUATION"))
8000 if (++anArgIt >= theArgsNb)
8002 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8006 if (!aLightPos.IsNull())
8008 aLightPos->Attenuation (anAtten[0], anAtten[1]);
8009 anAtten[0] = Atof (theArgVec[anArgIt]);
8010 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
8012 else if (!aLightSpot.IsNull())
8014 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
8015 anAtten[0] = Atof (theArgVec[anArgIt]);
8016 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
8020 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8024 else if (anArgCase.IsEqual ("LINATTEN")
8025 || anArgCase.IsEqual ("LINEARATTEN")
8026 || anArgCase.IsEqual ("LINEARATTENUATION"))
8028 if (++anArgIt >= theArgsNb)
8030 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8034 if (!aLightPos.IsNull())
8036 aLightPos->Attenuation (anAtten[0], anAtten[1]);
8037 anAtten[1] = Atof (theArgVec[anArgIt]);
8038 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
8040 else if (!aLightSpot.IsNull())
8042 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
8043 anAtten[1] = Atof (theArgVec[anArgIt]);
8044 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
8048 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8052 else if (anArgCase.IsEqual ("EXP")
8053 || anArgCase.IsEqual ("EXPONENT")
8054 || anArgCase.IsEqual ("SPOTEXP")
8055 || anArgCase.IsEqual ("SPOTEXPONENT"))
8057 if (++anArgIt >= theArgsNb)
8059 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8063 if (!aLightSpot.IsNull())
8065 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
8069 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8073 else if (anArgCase.IsEqual ("HEAD")
8074 || anArgCase.IsEqual ("HEADLIGHT"))
8076 if (++anArgIt >= theArgsNb)
8078 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8082 if (aLightAmb.IsNull()
8083 && !aLightCurr.IsNull())
8085 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
8089 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
8095 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
8099 addLight (aLightNew, isGlobal);
8100 aViewer->UpdateLights();
8105 //=======================================================================
8106 //function : VRenderParams
8107 //purpose : Enables/disables rendering features
8108 //=======================================================================
8110 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
8111 Standard_Integer theArgNb,
8112 const char** theArgVec)
8114 Handle(V3d_View) aView = ViewerTest::CurrentView();
8117 std::cerr << "Error: no active viewer!\n";
8121 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
8122 TCollection_AsciiString aCmdName (theArgVec[0]);
8123 aCmdName.LowerCase();
8124 if (aCmdName == "vraytrace")
8128 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
8131 else if (theArgNb == 2)
8133 TCollection_AsciiString aValue (theArgVec[1]);
8138 aParams.Method = Graphic3d_RM_RAYTRACING;
8142 else if (aValue == "off"
8145 aParams.Method = Graphic3d_RM_RASTERIZATION;
8151 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
8157 std::cout << "Error: wrong number of arguments\n";
8164 theDI << "renderMode: ";
8165 switch (aParams.Method)
8167 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
8168 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
8171 theDI << "msaa: " << aParams.NbMsaaSamples << "\n";
8172 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
8173 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
8174 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
8175 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
8176 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
8177 theDI << "GI: " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
8178 theDI << "blocked RNG: " << (aParams.CoherentPathTracingMode ? "on" : "off") << "\n";
8179 theDI << "shadingModel: ";
8180 switch (aView->ShadingModel())
8182 case V3d_COLOR: theDI << "color"; break;
8183 case V3d_FLAT: theDI << "flat"; break;
8184 case V3d_GOURAUD: theDI << "gouraud"; break;
8185 case V3d_PHONG: theDI << "phong"; break;
8191 Standard_Boolean toPrint = Standard_False;
8192 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
8193 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
8195 Standard_CString anArg (theArgVec[anArgIter]);
8196 TCollection_AsciiString aFlag (anArg);
8198 if (anUpdateTool.parseRedrawMode (aFlag))
8202 else if (aFlag == "-echo"
8203 || aFlag == "-print")
8205 toPrint = Standard_True;
8206 anUpdateTool.Invalidate();
8208 else if (aFlag == "-mode"
8209 || aFlag == "-rendermode"
8210 || aFlag == "-render_mode")
8214 switch (aParams.Method)
8216 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
8217 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
8223 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8227 else if (aFlag == "-ray"
8228 || aFlag == "-raytrace")
8232 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
8236 aParams.Method = Graphic3d_RM_RAYTRACING;
8238 else if (aFlag == "-rast"
8239 || aFlag == "-raster"
8240 || aFlag == "-rasterization")
8244 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
8248 aParams.Method = Graphic3d_RM_RASTERIZATION;
8250 else if (aFlag == "-msaa")
8254 theDI << aParams.NbMsaaSamples << " ";
8257 else if (++anArgIter >= theArgNb)
8259 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8263 const Standard_Integer aNbSamples = Draw::Atoi (theArgVec[anArgIter]);
8266 std::cerr << "Error: invalid number of MSAA samples " << aNbSamples << ".\n";
8271 aParams.NbMsaaSamples = aNbSamples;
8274 else if (aFlag == "-raydepth"
8275 || aFlag == "-ray_depth")
8279 theDI << aParams.RaytracingDepth << " ";
8282 else if (++anArgIter >= theArgNb)
8284 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8288 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
8290 // We allow RaytracingDepth be more than 10 in case of GI enabled
8291 if (aDepth < 1 || (aDepth > 10 && !aParams.IsGlobalIlluminationEnabled))
8293 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
8298 aParams.RaytracingDepth = aDepth;
8301 else if (aFlag == "-shad"
8302 || aFlag == "-shadows")
8306 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
8310 Standard_Boolean toEnable = Standard_True;
8311 if (++anArgIter < theArgNb
8312 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8316 aParams.IsShadowEnabled = toEnable;
8318 else if (aFlag == "-refl"
8319 || aFlag == "-reflections")
8323 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
8327 Standard_Boolean toEnable = Standard_True;
8328 if (++anArgIter < theArgNb
8329 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8333 aParams.IsReflectionEnabled = toEnable;
8335 else if (aFlag == "-fsaa")
8339 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
8343 Standard_Boolean toEnable = Standard_True;
8344 if (++anArgIter < theArgNb
8345 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8349 aParams.IsAntialiasingEnabled = toEnable;
8351 else if (aFlag == "-gleam")
8355 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
8359 Standard_Boolean toEnable = Standard_True;
8360 if (++anArgIter < theArgNb
8361 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8365 aParams.IsTransparentShadowEnabled = toEnable;
8367 else if (aFlag == "-gi")
8371 theDI << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << " ";
8375 Standard_Boolean toEnable = Standard_True;
8376 if (++anArgIter < theArgNb
8377 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8381 aParams.IsGlobalIlluminationEnabled = toEnable;
8384 aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
8387 else if (aFlag == "-blockedrng"
8388 || aFlag == "-brng")
8392 theDI << (aParams.CoherentPathTracingMode ? "on" : "off") << " ";
8396 Standard_Boolean toEnable = Standard_True;
8397 if (++anArgIter < theArgNb
8398 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8402 aParams.CoherentPathTracingMode = toEnable;
8404 else if (aFlag == "-env")
8408 theDI << (aParams.UseEnvironmentMapBackground ? "on" : "off") << " ";
8412 Standard_Boolean toEnable = Standard_True;
8413 if (++anArgIter < theArgNb
8414 && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
8418 aParams.UseEnvironmentMapBackground = toEnable;
8420 else if (aFlag == "-shademodel"
8421 || aFlag == "-shadingmodel"
8422 || aFlag == "-shading")
8426 switch (aView->ShadingModel())
8428 case V3d_COLOR: theDI << "color "; break;
8429 case V3d_FLAT: theDI << "flat "; break;
8430 case V3d_GOURAUD: theDI << "gouraud "; break;
8431 case V3d_PHONG: theDI << "phong "; break;
8436 if (++anArgIter >= theArgNb)
8438 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8441 TCollection_AsciiString aMode (theArgVec[anArgIter]);
8443 if (aMode == "color"
8446 aView->SetShadingModel (V3d_COLOR);
8448 else if (aMode == "flat"
8449 || aMode == "facet")
8451 aView->SetShadingModel (V3d_FLAT);
8453 else if (aMode == "gouraud"
8454 || aMode == "vertex"
8457 aView->SetShadingModel (V3d_GOURAUD);
8459 else if (aMode == "phong"
8460 || aMode == "fragment"
8462 || aMode == "pixel")
8464 aView->SetShadingModel (V3d_PHONG);
8468 std::cout << "Error: unknown shading model '" << aMode << "'\n";
8472 else if (aFlag == "-resolution")
8474 if (++anArgIter >= theArgNb)
8476 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8480 TCollection_AsciiString aResolution (theArgVec[anArgIter]);
8481 if (aResolution.IsIntegerValue())
8483 aView->ChangeRenderingParams().Resolution = static_cast<unsigned int> (Draw::Atoi (aResolution.ToCString()));
8487 std::cout << "Error: wrong syntax at argument'" << anArg << "'.\n";
8493 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
8501 //=======================================================================
8502 //function : VProgressiveMode
8504 //=======================================================================
8506 static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
8507 Standard_Integer /*theNbArgs*/,
8508 const char** /*theArgs*/)
8510 Handle(V3d_View) aView = ViewerTest::CurrentView();
8513 std::cerr << "Error: no active viewer!\n";
8517 std::cout << "Press Enter or Escape key to exit progressive rendering mode" << std::endl;
8523 Standard_Boolean toExit = Standard_False;
8526 while (PeekMessage (&aMsg, NULL, 0, 0, PM_REMOVE))
8528 if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
8530 toExit = Standard_True;
8533 TranslateMessage (&aMsg);
8534 DispatchMessage (&aMsg);
8547 //=======================================================================
8548 //function : VFrustumCulling
8549 //purpose : enables/disables view volume's culling.
8550 //=======================================================================
8551 static int VFrustumCulling (Draw_Interpretor& theDI,
8552 Standard_Integer theArgNb,
8553 const char** theArgVec)
8555 Handle(V3d_View) aView = ViewerTest::CurrentView();
8558 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
8564 theDI << (aView->IsCullingEnabled() ? "on" : "off");
8567 else if (theArgNb != 2)
8569 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
8573 TCollection_AsciiString aModeStr (theArgVec[1]);
8574 aModeStr.LowerCase();
8575 Standard_Boolean toEnable = 0;
8576 if (aModeStr == "on")
8580 else if (aModeStr == "off")
8586 toEnable = Draw::Atoi (theArgVec[1]) != 0;
8589 aView->SetFrustumCulling (toEnable);
8594 //=======================================================================
8595 //function : VHighlightSelected
8597 //=======================================================================
8598 static int VHighlightSelected (Draw_Interpretor& theDI,
8599 Standard_Integer theArgNb,
8600 const char** theArgVec)
8602 if (ViewerTest::GetAISContext().IsNull())
8604 std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n";
8608 const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8612 theDI << (aContext->ToHilightSelected() ? "on" : "off");
8618 std::cout << theArgVec[0] << " error : wrong number of parameters."
8619 << "Type 'help" << theArgVec[0] << "' for more information.";
8624 TCollection_AsciiString aMode (theArgVec[1]);
8626 Standard_Boolean toEnable = Standard_False;
8627 if (aMode.IsEqual ("on"))
8629 toEnable = Standard_True;
8631 else if (aMode.IsEqual ("off"))
8633 toEnable = Standard_False;
8637 toEnable = Draw::Atoi (theArgVec[1]) != 0;
8640 if (toEnable != aContext->ToHilightSelected())
8642 aContext->SetToHilightSelected (toEnable);
8644 // Move cursor to null position and back to process updating of detection
8645 // and highlighting of selected object immediatly.
8646 Standard_Integer aPixX = 0;
8647 Standard_Integer aPixY = 0;
8648 const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager();
8650 anEventManager->GetCurrentPosition (aPixX, aPixY);
8651 anEventManager->MoveTo (0, 0);
8652 anEventManager->MoveTo (aPixX, aPixY);
8658 //=======================================================================
8659 //function : VXRotate
8661 //=======================================================================
8662 static Standard_Integer VXRotate (Draw_Interpretor& di,
8663 Standard_Integer argc,
8666 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8667 if (aContext.IsNull())
8669 di << argv[0] << "ERROR : use 'vinit' command before \n";
8675 di << "ERROR : Usage : " << argv[0] << " name angle\n";
8679 TCollection_AsciiString aName (argv[1]);
8680 Standard_Real anAngle = Draw::Atof (argv[2]);
8683 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
8684 Handle(AIS_InteractiveObject) anIObj;
8685 if (!aMap.IsBound2 (aName) )
8687 di << "Use 'vdisplay' before\n";
8692 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
8695 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
8696 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
8698 aContext->SetLocation (anIObj, aTransform);
8699 aContext->UpdateCurrentViewer();
8705 //===============================================================================================
8706 //class : ViewerTest_AISManipulator
8707 //purpose : Proxy class maintaining automated registry map to enlist existing AIS_Manipulator instances
8708 //===============================================================================================
8709 DEFINE_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
8711 class ViewerTest_AISManipulator : public AIS_Manipulator
8715 ViewerTest_AISManipulator() : AIS_Manipulator()
8717 GetMapOfAISManipulators().Add (this);
8720 virtual ~ViewerTest_AISManipulator()
8722 GetMapOfAISManipulators().Remove (this);
8725 DEFINE_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
8728 IMPLEMENT_STANDARD_HANDLE (ViewerTest_AISManipulator, AIS_Manipulator)
8729 IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_AISManipulator, AIS_Manipulator)
8731 //===============================================================================================
8732 //function : VManipulator
8734 //===============================================================================================
8735 static int VManipulator (Draw_Interpretor& theDi,
8736 Standard_Integer theArgsNb,
8737 const char** theArgVec)
8739 Handle(V3d_View) aView = ViewerTest::CurrentView();
8740 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
8741 ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_False);
8743 || aViewer.IsNull())
8745 std::cerr << "No active viewer!\n";
8749 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView());
8750 Standard_Integer anArgIter = 1;
8751 for (; anArgIter < theArgsNb; ++anArgIter)
8753 anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
8756 ViewerTest_CmdParser aCmd;
8757 aCmd.AddDescription ("Manages manipulator for interactive objects:");
8758 aCmd.AddOption ("attach", "... object - attach manipulator to an object");
8759 aCmd.AddOption ("adjustPosition", "... {0|1} - adjust position when attaching");
8760 aCmd.AddOption ("adjustSize", "... {0|1} - adjust size when attaching ");
8761 aCmd.AddOption ("enableModes", "... {0|1} - enable modes when attaching ");
8762 aCmd.AddOption ("detach", "... - detach manipulator");
8764 aCmd.AddOption ("startTransform", "... mouse_x mouse_y - invoke start transformation");
8765 aCmd.AddOption ("transform", "... mouse_x mouse_y - invoke transformation");
8766 aCmd.AddOption ("stopTransform", "... [abort] - invoke stop transformation");
8768 aCmd.AddOption ("move", "... x y z - move object");
8769 aCmd.AddOption ("rotate", "... x y z dx dy dz angle - rotate object");
8770 aCmd.AddOption ("scale", "... factor - scale object");
8772 aCmd.AddOption ("autoActivate", "... {0|1} - set activation on detection");
8773 aCmd.AddOption ("followTranslation", "... {0|1} - set following translation transform");
8774 aCmd.AddOption ("followRotation", "... {0|1} - set following rotation transform");
8775 aCmd.AddOption ("gap", "... value - set gap between sub-parts");
8776 aCmd.AddOption ("part", "... axis mode {0|1} - set visual part");
8777 aCmd.AddOption ("pos", "... x y z [nx ny nz [xx xy xz]] - set position of manipulator");
8778 aCmd.AddOption ("size", "... size - set size of manipulator");
8779 aCmd.AddOption ("zoomable", "... {0|1} - set zoom persistence");
8781 aCmd.Parse (theArgsNb, theArgVec);
8783 if (aCmd.HasOption ("help"))
8785 theDi.PrintHelp (theArgVec[0]);
8789 ViewerTest_DoubleMapOfInteractiveAndName& aMapAIS = GetMapOfAIS();
8791 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
8793 if (aName.IsEmpty())
8795 std::cerr << theArgVec[0] << " error: please specify AIS manipulator's name as the first argument.\n";
8799 // ----------------------------------
8800 // detach existing manipulator object
8801 // ----------------------------------
8803 if (aCmd.HasOption ("detach"))
8805 if (!aMapAIS.IsBound2 (aName))
8807 std::cerr << theArgVec[0] << " error: could not find \"" << aName << "\" AIS object.\n";
8811 Handle(AIS_Manipulator) aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
8812 if (aManipulator.IsNull())
8814 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
8818 aManipulator->Detach();
8819 aMapAIS.UnBind2 (aName);
8820 ViewerTest::GetAISContext()->Remove (aManipulator);
8825 // -----------------------------------------------
8826 // find or create manipulator if it does not exist
8827 // -----------------------------------------------
8829 Handle(AIS_Manipulator) aManipulator;
8830 if (!aMapAIS.IsBound2 (aName))
8832 std::cout << theArgVec[0] << ": AIS object \"" << aName << "\" has been created.\n";
8834 aManipulator = new ViewerTest_AISManipulator();
8835 aMapAIS.Bind (aManipulator, aName);
8839 aManipulator = Handle(AIS_Manipulator)::DownCast (aMapAIS.Find2 (aName));
8840 if (aManipulator.IsNull())
8842 std::cerr << theArgVec[0] << " error: \"" << aName << "\" is not an AIS manipulator.\n";
8847 // -----------------------------------------
8848 // change properties of manipulator instance
8849 // -----------------------------------------
8851 if (aCmd.HasOption ("autoActivate", 1, Standard_True))
8853 aManipulator->SetModeActivationOnDetection (aCmd.ArgBool ("autoActivate"));
8855 if (aCmd.HasOption ("followTranslation", 1, Standard_True))
8857 aManipulator->ChangeTransformBehavior().SetFollowTranslation (aCmd.ArgBool ("followTranslation"));
8859 if (aCmd.HasOption ("followRotation", 1, Standard_True))
8861 aManipulator->ChangeTransformBehavior().SetFollowRotation (aCmd.ArgBool ("followRotation"));
8863 if (aCmd.HasOption ("gap", 1, Standard_True))
8865 aManipulator->SetGap (aCmd.ArgFloat ("gap"));
8867 if (aCmd.HasOption ("part", 3, Standard_True))
8869 Standard_Integer anAxis = aCmd.ArgInt ("part", 0);
8870 Standard_Integer aMode = aCmd.ArgInt ("part", 1);
8871 Standard_Boolean aOnOff = aCmd.ArgBool ("part", 2);
8872 if (aMode < 1 || aMode > 3)
8874 std::cerr << theArgVec[0] << " error: mode value should be in range [1, 3].\n";
8878 aManipulator->SetPart (anAxis, static_cast<AIS_ManipulatorMode> (aMode), aOnOff);
8880 if (aCmd.HasOption ("pos", 3, Standard_True))
8882 gp_Pnt aLocation = aCmd.ArgPnt ("pos", 0);
8883 gp_Dir aVDir = aCmd.HasOption ("pos", 6) ? gp_Dir (aCmd.ArgVec ("pos", 3)) : aManipulator->Position().Direction();
8884 gp_Dir aXDir = aCmd.HasOption ("pos", 9) ? gp_Dir (aCmd.ArgVec ("pos", 6)) : aManipulator->Position().XDirection();
8886 aManipulator->SetPosition (gp_Ax2 (aLocation, aVDir, aXDir));
8888 if (aCmd.HasOption ("size", 1, Standard_True))
8890 aManipulator->SetSize (aCmd.ArgFloat ("size"));
8892 if (aCmd.HasOption ("zoomable", 1, Standard_True))
8894 aManipulator->SetZoomPersistence (!aCmd.ArgBool ("zoomable"));
8896 if (ViewerTest::GetAISContext()->IsDisplayed (aManipulator))
8898 ViewerTest::GetAISContext()->Remove (aManipulator, Standard_False);
8899 ViewerTest::GetAISContext()->Display (aManipulator, Standard_False);
8903 // ---------------------------------------------------
8904 // attach, detach or access manipulator from an object
8905 // ---------------------------------------------------
8907 if (aCmd.HasOption ("attach"))
8909 // Find an object and attach manipulator to it
8910 if (!aCmd.HasOption ("attach", 1, Standard_True))
8915 TCollection_AsciiString anObjName (aCmd.Arg ("attach", 0).c_str());
8916 if (!aMapAIS.IsBound2 (anObjName))
8918 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" does not exist.\n";
8922 Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (aMapAIS.Find2 (anObjName));
8923 ViewerTest_MapOfAISManipulators::Iterator anIt (GetMapOfAISManipulators());
8924 for (; anIt.More(); anIt.Next())
8926 if (anIt.Value()->IsAttached()
8927 && anIt.Value()->Object() == anObject)
8929 std::cerr << theArgVec[0] << " error: AIS object \"" << anObjName << "\" already has manipulator.\n";
8934 AIS_Manipulator::OptionsForAttach anOptions;
8935 if (aCmd.HasOption ("adjustPosition", 1, Standard_True))
8937 anOptions.SetAdjustPosition (aCmd.ArgBool ("adjustPosition"));
8939 if (aCmd.HasOption ("adjustSize", 1, Standard_True))
8941 anOptions.SetAdjustSize (aCmd.ArgBool ("adjustSize"));
8943 if (aCmd.HasOption ("enableModes", 1, Standard_True))
8945 anOptions.SetEnableModes (aCmd.ArgBool ("enableModes"));
8948 aManipulator->Attach (anObject, anOptions);
8951 // --------------------------------------
8952 // apply transformation using manipulator
8953 // --------------------------------------
8955 if (aCmd.HasOption ("startTransform", 2, Standard_True))
8957 aManipulator->StartTransform (aCmd.ArgInt ("startTransform", 0), aCmd.ArgInt ("startTransform", 1), ViewerTest::CurrentView());
8959 if (aCmd.HasOption ("transform", 2, Standard_True))
8961 aManipulator->Transform (aCmd.ArgInt ("transform", 0), aCmd.ArgInt ("transform", 1), ViewerTest::CurrentView());
8963 if (aCmd.HasOption ("stopTransform"))
8965 Standard_Boolean toApply = !aCmd.HasOption ("stopTransform", 1) || (aCmd.Arg ("stopTransform", 0) != "abort");
8967 aManipulator->StopTransform (toApply);
8971 if (aCmd.HasOption ("move", 3, Standard_True))
8973 aT.SetTranslationPart (aCmd.ArgVec ("move"));
8975 if (aCmd.HasOption ("rotate", 7, Standard_True))
8977 aT.SetRotation (gp_Ax1 (aCmd.ArgPnt ("rotate", 0), aCmd.ArgVec ("rotate", 3)), aCmd.ArgDouble ("rotate", 6));
8979 if (aCmd.HasOption ("scale", 1))
8981 aT.SetScale (gp_Pnt(), aCmd.ArgDouble("scale"));
8984 if (aT.Form() != gp_Identity)
8986 aManipulator->Transform (aT);
8989 ViewerTest::GetAISContext()->Redisplay (aManipulator);
8994 //=======================================================================
8995 //function : ViewerCommands
8997 //=======================================================================
8999 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
9002 const char *group = "ZeViewer";
9003 theCommands.Add("vinit",
9004 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
9005 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
9007 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
9009 " - Creates new View window with specified name view_name.\n"
9010 "By default the new view is created in the viewer and in"
9011 " graphic driver shared with active view.\n"
9012 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
9013 "If driverName isn't specified the driver will be shared with active view.\n"
9014 "If viewerName isn't specified the viewer will be shared with active view.\n"
9015 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
9016 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
9017 "is used in creation of graphic driver\n"
9019 " - l, t: pixel position of left top corner of the window\n"
9020 " - w,h: width and heigth of window respectively.\n"
9021 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
9022 __FILE__,VInit,group);
9023 theCommands.Add("vclose" ,
9024 "[view_id [keep_context=0|1]]\n"
9025 "or vclose ALL - to remove all created views\n"
9026 " - removes view(viewer window) defined by its view_id.\n"
9027 " - keep_context: by default 0; if 1 and the last view is deleted"
9028 " the current context is not removed.",
9029 __FILE__,VClose,group);
9030 theCommands.Add("vactivate" ,
9032 " - activates view(viewer window) defined by its view_id",
9033 __FILE__,VActivate,group);
9034 theCommands.Add("vviewlist",
9035 "vviewlist [format={tree, long}]"
9036 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
9037 " - format: format of result output, if tree the output is a tree view;"
9038 "otherwise it's a list of full view names. By default format = tree",
9039 __FILE__,VViewList,group);
9040 theCommands.Add("vhelp" ,
9041 "vhelp : display help on the viewer commands",
9042 __FILE__,VHelp,group);
9043 theCommands.Add("vtop" ,
9044 "vtop or <T> : Top view. Orientation +X+Y" ,
9045 __FILE__,VTop,group);
9046 theCommands.Add("vbottom" ,
9047 "vbottom : Bottom view. Orientation +X-Y" ,
9048 __FILE__,VBottom,group);
9049 theCommands.Add("vleft" ,
9050 "vleft : Left view. Orientation -Y+Z" ,
9051 __FILE__,VLeft,group);
9052 theCommands.Add("vright" ,
9053 "vright : Right view. Orientation +Y+Z" ,
9054 __FILE__,VRight,group);
9055 theCommands.Add("vaxo" ,
9056 " vaxo or <A> : Axonometric view. Orientation +X-Y+Z",
9057 __FILE__,VAxo,group);
9058 theCommands.Add("vfront" ,
9059 "vfront : Front view. Orientation +X+Z" ,
9060 __FILE__,VFront,group);
9061 theCommands.Add("vback" ,
9062 "vback : Back view. Orientation -X+Z" ,
9063 __FILE__,VBack,group);
9064 theCommands.Add("vpick" ,
9065 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
9067 theCommands.Add("vfit" ,
9068 "vfit or <F> [-selected]"
9069 "\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
9070 __FILE__,VFit,group);
9071 theCommands.Add ("vfitarea",
9072 "vfitarea x1 y1 x2 y2"
9073 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
9074 "\n\t\t: Fit view to show area located between two points"
9075 "\n\t\t: given in world 2D or 3D corrdinates.",
9076 __FILE__, VFitArea, group);
9077 theCommands.Add ("vzfit", "vzfit [scale]\n"
9078 " Matches Z near, Z far view volume planes to the displayed objects.\n"
9079 " \"scale\" - specifies factor to scale computed z range.\n",
9080 __FILE__, VZFit, group);
9081 theCommands.Add("vrepaint",
9082 "vrepaint : vrepaint, force redraw",
9083 __FILE__,VRepaint,group);
9084 theCommands.Add("vclear",
9086 "\n\t\t: remove all the object from the viewer",
9087 __FILE__,VClear,group);
9088 theCommands.Add("vsetbg",
9089 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
9090 __FILE__,VSetBg,group);
9091 theCommands.Add("vsetbgmode",
9092 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
9093 __FILE__,VSetBgMode,group);
9094 theCommands.Add("vsetgradientbg",
9095 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
9096 __FILE__,VSetGradientBg,group);
9097 theCommands.Add("vsetgrbgmode",
9098 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
9099 __FILE__,VSetGradientBgMode,group);
9100 theCommands.Add("vsetcolorbg",
9101 "vsetcolorbg : vsetcolorbg r g b : Set background color",
9102 __FILE__,VSetColorBg,group);
9103 theCommands.Add("vsetdefaultbg",
9104 "vsetdefaultbg r g b\n"
9105 "\n\t\t: vsetdefaultbg r1 g1 b1 r2 g2 b2 fillmode"
9106 "\n\t\t: Set default viewer background fill color (flat/gradient).",
9107 __FILE__,VSetDefaultBg,group);
9108 theCommands.Add("vscale",
9109 "vscale : vscale X Y Z",
9110 __FILE__,VScale,group);
9111 theCommands.Add("vzbufftrihedron",
9112 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
9113 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
9114 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
9115 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
9116 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
9117 "\n\t\t: Displays a trihedron",
9118 __FILE__,VZBuffTrihedron,group);
9119 theCommands.Add("vrotate",
9120 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
9121 "\n : Option -mouseStart starts rotation according to the mouse position"
9122 "\n : Option -mouseMove continues rotation with angle computed"
9123 "\n : from last and new mouse position."
9124 "\n : vrotate AX AY AZ [X Y Z]",
9125 __FILE__,VRotate,group);
9126 theCommands.Add("vzoom",
9127 "vzoom : vzoom coef",
9128 __FILE__,VZoom,group);
9129 theCommands.Add("vpan",
9130 "vpan : vpan dx dy",
9131 __FILE__,VPan,group);
9132 theCommands.Add("vexport",
9133 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
9134 " : exports the view to a vector file of a given format"
9135 " : notice that EMF format requires patched gl2ps",
9136 __FILE__,VExport,group);
9137 theCommands.Add("vcolorscale",
9138 "vcolorscale : vcolorscale name [-range RangeMin = 0 RangeMax = 100 Intervals = 10 -font HeightFont = 16 -textpos "
9139 "Position = left -xy X = 0 Y = 0] [-noupdate|-update]: draw color scale\n"
9140 "-demo/-demoversion draw a demoversion of color scale.\n"
9141 "-show/display display color scale.\n"
9142 "-hide/erase erase color scale.\n"
9143 "Please note that -show/-hide option must be the first argument!\n"
9144 "-color Index R G B: set color for indexed interval\n"
9145 "-color Index ColorName: set color for indexed interval\n"
9146 "-colors R G B R G B ...: set colors for all intervals\n"
9147 "-colors ColorName1 ColorName2 ...: set colors for all intervals\n"
9148 "-colors supports both color names and rgb values in one call\n"
9149 "-label Index Text: set label for indexed interval\n"
9150 "-labels Text Text Text ...: set labels for all intervals\n"
9151 "-title Title [Position]: set the title for color scale with certain position. Default position = center;\n"
9152 "Available text positions: left, right, center, none;\n",
9153 __FILE__,VColorScale,group);
9154 theCommands.Add("vgraduatedtrihedron",
9155 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
9156 "\t[-namefont Name] [-valuesfont Name]\n"
9157 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
9158 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
9159 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
9160 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
9161 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
9162 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
9163 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
9164 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
9165 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
9166 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
9167 " - Displays or erases graduated trihedron"
9168 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
9169 " - namefont - font of axes names. Default: Arial\n"
9170 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
9171 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
9172 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
9173 " - valuesfont - font of axes values. Default: Arial\n"
9174 " - xcolor, ycolor, zcolor - color of axis and values\n"
9175 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
9176 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
9177 __FILE__,VGraduatedTrihedron,group);
9178 theCommands.Add("vtile" ,
9179 "vtile [-totalSize W H] [-lowerLeft X Y] [-upperLeft X Y] [-tileSize W H]"
9180 "\n\t\t: Setup view to draw a tile (a part of virtual bigger viewport)."
9181 "\n\t\t: -totalSize the size of virtual bigger viewport"
9182 "\n\t\t: -tileSize tile size (the view size will be used if omitted)"
9183 "\n\t\t: -lowerLeft tile offset as lower left corner"
9184 "\n\t\t: -upperLeft tile offset as upper left corner",
9185 __FILE__, VTile, group);
9186 theCommands.Add("vzlayer",
9187 "vzlayer add/del/get/settings/enable/disable [id]\n"
9188 " add - add new z layer to viewer and print its id\n"
9189 " del - del z layer by its id\n"
9190 " get - print sequence of z layers in increasing order of their overlay level\n"
9191 " settings - print status of z layer settings\n"
9192 " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n"
9193 " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n"
9194 " enable textureenv \n enables environment texture mapping\n"
9195 " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n"
9196 " disable textureenv \n disables environment texture mapping\n"
9197 "\nWhere id is the layer identificator\n"
9200 " vzlayer enable poffset 1\n"
9201 " vzlayer disable depthtest 1\n"
9203 __FILE__,VZLayer,group);
9204 theCommands.Add("vlayerline",
9205 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
9206 __FILE__,VLayerLine,group);
9207 theCommands.Add ("vgrid",
9208 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
9209 " : Mode - rectangular or circular"
9210 " : Type - lines or points",
9211 __FILE__, VGrid, group);
9212 theCommands.Add ("vpriviledgedplane",
9213 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
9214 "\n\t\t: Ox, Oy, Oz - plane origin"
9215 "\n\t\t: Nx, Ny, Nz - plane normal direction"
9216 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
9217 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
9218 __FILE__, VPriviledgedPlane, group);
9219 theCommands.Add ("vconvert",
9220 "vconvert v [Mode={window|view}]"
9221 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
9222 "\n\t\t: vconvert x y z [Mode={window|grid}]"
9223 "\n\t\t: window - convert to window coordinates, pixels"
9224 "\n\t\t: view - convert to view projection plane"
9225 "\n\t\t: grid - convert to model coordinates, given on grid"
9226 "\n\t\t: ray - convert projection ray to model coordiantes"
9227 "\n\t\t: - vconvert v window : convert view to window;"
9228 "\n\t\t: - vconvert v view : convert window to view;"
9229 "\n\t\t: - vconvert x y window : convert view to window;"
9230 "\n\t\t: - vconvert x y view : convert window to view;"
9231 "\n\t\t: - vconvert x y : convert window to model;"
9232 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
9233 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
9234 "\n\t\t: - vconvert x y z window : convert model to window;"
9235 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
9236 "\n\t\t: Converts the given coordinates to window/view/model space.",
9237 __FILE__, VConvert, group);
9238 theCommands.Add ("vfps",
9239 "vfps [framesNb=100] : estimate average frame rate for active view",
9240 __FILE__, VFps, group);
9241 theCommands.Add ("vgldebug",
9242 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
9243 "\n\t\t: [-extraMsg {0|1}] [{0|1}]"
9244 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
9245 "\n\t\t: Debug context can be requested only on Windows"
9246 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
9247 "\n\t\t: -sync - request synchronized debug GL context"
9248 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
9249 "\n\t\t: which are suppressed by default,"
9250 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
9251 "\n\t\t: which are suppressed by default",
9252 __FILE__, VGlDebug, group);
9253 theCommands.Add ("vvbo",
9254 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
9255 __FILE__, VVbo, group);
9256 theCommands.Add ("vstereo",
9257 "vstereo [0|1] [-mode Mode] [-reverse {0|1}]"
9258 "\n\t\t: [-anaglyph Filter]"
9259 "\n\t\t: Control stereo output mode. Available modes for -mode:"
9260 "\n\t\t: quadBuffer - OpenGL QuadBuffer stereo,"
9261 "\n\t\t: requires driver support."
9262 "\n\t\t: Should be called BEFORE vinit!"
9263 "\n\t\t: anaglyph - Anaglyph glasses"
9264 "\n\t\t: rowInterlaced - row-interlaced display"
9265 "\n\t\t: columnInterlaced - column-interlaced display"
9266 "\n\t\t: chessBoard - chess-board output"
9267 "\n\t\t: sideBySide - horizontal pair"
9268 "\n\t\t: overUnder - vertical pair"
9269 "\n\t\t: Available Anaglyph filters for -anaglyph:"
9270 "\n\t\t: redCyan, redCyanSimple, yellowBlue, yellowBlueSimple,"
9271 "\n\t\t: greenMagentaSimple",
9272 __FILE__, VStereo, group);
9273 theCommands.Add ("vcaps",
9274 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
9275 "\n\t\t: [-compatibleProfile {0|1}]"
9276 "\n\t\t: [-vsync {0|1}]"
9277 "\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
9278 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
9279 "\n\t\t: Modify particular graphic driver options:"
9280 "\n\t\t: FFP - use fixed-function pipeline instead of"
9281 "\n\t\t: built-in GLSL programs"
9282 "\n\t\t: (requires compatible profile)"
9283 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
9284 "\n\t\t: arrays to GPU memory)"
9285 "\n\t\t: sprite - use textured sprites instead of bitmaps"
9286 "\n\t\t: vsync - switch VSync on or off"
9287 "\n\t\t: Context creation options:"
9288 "\n\t\t: softMode - software OpenGL implementation"
9289 "\n\t\t: compatibleProfile - backward-compatible profile"
9290 "\n\t\t: quadbuffer - QuadBuffer"
9291 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
9292 "\n\t\t: rendering paths producing the same visual result when"
9294 "\n\t\t: Command is intended for testing old hardware compatibility.",
9295 __FILE__, VCaps, group);
9296 theCommands.Add ("vmemgpu",
9297 "vmemgpu [f]: print system-dependent GPU memory information if available;"
9298 " with f option returns free memory in bytes",
9299 __FILE__, VMemGpu, group);
9300 theCommands.Add ("vreadpixel",
9301 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
9302 " : Read pixel value for active view",
9303 __FILE__, VReadPixel, group);
9304 theCommands.Add("diffimage",
9305 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
9306 __FILE__, VDiffImage, group);
9307 theCommands.Add ("vselect",
9308 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [-allowoverlap 0|1] [shift_selection = 0|1]\n"
9309 "- emulates different types of selection:\n"
9310 "- 1) single click selection\n"
9311 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
9312 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
9313 "- 4) -allowoverlap manages overlap and inclusion detection in rectangular selection.\n"
9314 " If the flag is set to 1, both sensitives that were included completely and overlapped partially by defined rectangle will be detected,\n"
9315 " otherwise algorithm will chose only fully included sensitives. Default behavior is to detect only full inclusion. "
9316 " (partial inclusion - overlap - is not allowed by default)\n"
9317 "- 5) any of these selections with shift button pressed",
9318 __FILE__, VSelect, group);
9319 theCommands.Add ("vmoveto",
9321 "- emulates cursor movement to pixel postion (x,y)",
9322 __FILE__, VMoveTo, group);
9323 theCommands.Add ("vviewparams", "vviewparams usage:\n"
9325 "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n"
9326 " [-proj [x y z]] [-center x y] [-size sx]\n"
9327 "- Gets or sets current view parameters.\n"
9328 "- If called without arguments, all view parameters are printed.\n"
9329 "- The options are:\n"
9330 " -scale [s] : prints or sets viewport relative scale.\n"
9331 " -eye [x y z] : prints or sets eye location.\n"
9332 " -at [x y z] : prints or sets center of look.\n"
9333 " -up [x y z] : prints or sets direction of up vector.\n"
9334 " -proj [x y z] : prints or sets direction of look.\n"
9335 " -center x y : sets location of center of the screen in pixels.\n"
9336 " -size [sx] : prints viewport projection width and height sizes\n"
9337 " : or changes the size of its maximum dimension.\n",
9338 __FILE__, VViewParams, group);
9339 theCommands.Add("vchangeselected",
9340 "vchangeselected shape"
9341 "- adds to shape to selection or remove one from it",
9342 __FILE__, VChangeSelected, group);
9343 theCommands.Add ("vnbselected",
9345 "\n\t\t: Returns number of selected objects", __FILE__, VNbSelected, group);
9346 theCommands.Add ("vcamera",
9347 "vcamera [-ortho] [-projtype]"
9349 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
9350 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
9351 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
9352 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
9353 "\n\t\t: Manage camera parameters."
9354 "\n\t\t: Prints current value when option called without argument."
9355 "\n\t\t: Orthographic camera:"
9356 "\n\t\t: -ortho activate orthographic projection"
9357 "\n\t\t: Perspective camera:"
9358 "\n\t\t: -persp activate perspective projection (mono)"
9359 "\n\t\t: -fovy field of view in y axis, in degrees"
9360 "\n\t\t: -distance distance of eye from camera center"
9361 "\n\t\t: Stereoscopic camera:"
9362 "\n\t\t: -stereo perspective projection (stereo)"
9363 "\n\t\t: -leftEye perspective projection (left eye)"
9364 "\n\t\t: -rightEye perspective projection (right eye)"
9365 "\n\t\t: -iod intraocular distance value"
9366 "\n\t\t: -iodType distance type, absolute or relative"
9367 "\n\t\t: -zfocus stereographic focus value"
9368 "\n\t\t: -zfocusType focus type, absolute or relative",
9369 __FILE__, VCamera, group);
9370 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
9371 "- vautozfit [on={1|0}] [scale]\n"
9372 " Prints or changes parameters of automatic z-fit mode:\n"
9373 " \"on\" - turns automatic z-fit on or off\n"
9374 " \"scale\" - specifies factor to scale computed z range.\n",
9375 __FILE__, VAutoZFit, group);
9376 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
9377 " vzrange - without parameters shows current values\n"
9378 " vzrange [znear] [zfar] - applies provided values to view",
9379 __FILE__,VZRange, group);
9380 theCommands.Add ("vpurgedisplay",
9382 "- removes structures which don't belong to objects displayed in neutral point",
9383 __FILE__, VPurgeDisplay, group);
9384 theCommands.Add("vsetviewsize",
9385 "vsetviewsize size",
9386 __FILE__,VSetViewSize,group);
9387 theCommands.Add("vmoveview",
9388 "vmoveview Dx Dy Dz [Start = 1|0]",
9389 __FILE__,VMoveView,group);
9390 theCommands.Add("vtranslateview",
9391 "vtranslateview Dx Dy Dz [Start = 1|0)]",
9392 __FILE__,VTranslateView,group);
9393 theCommands.Add("vturnview",
9394 "vturnview Ax Ay Az [Start = 1|0]",
9395 __FILE__,VTurnView,group);
9396 theCommands.Add("vtextureenv",
9397 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
9398 "or user-defined file and optionally applying texture mapping parameters\n"
9400 " vtextureenv off - disables environment mapping\n"
9401 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
9402 " std_texture = (0..7)\n"
9403 " rep = {clamp|repeat}\n"
9404 " mod = {decal|modulate}\n"
9405 " flt = {nearest|bilinear|trilinear}\n"
9406 " ss, st - scale factors for s and t texture coordinates\n"
9407 " ts, tt - translation for s and t texture coordinates\n"
9408 " rot - texture rotation angle in degrees",
9409 __FILE__, VTextureEnv, group);
9410 theCommands.Add("vhlr" ,
9411 "is_enabled={on|off} [show_hidden={1|0}]"
9412 " - Hidden line removal algorithm:"
9413 " - is_enabled: if is on HLR algorithm is applied\n"
9414 " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n",
9415 __FILE__,VHLR,group);
9416 theCommands.Add("vhlrtype" ,
9417 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
9418 " - Changes the type of HLR algorithm using for shapes."
9419 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
9420 " if equals to polyalgo, polygonal HLR algorithm is applied."
9421 "If shapes are not given HLR algoithm of given type is applied"
9422 " to all shapes in the view\n",
9423 __FILE__,VHLRType,group);
9424 theCommands.Add("vclipplane",
9425 "vclipplane planeName [{0|1}]"
9426 "\n\t\t: [-equation A B C D]"
9427 "\n\t\t: [-set|-unset [objects|views]]"
9428 "\n\t\t: [-maxPlanes]"
9429 "\n\t\t: [-capping {0|1}]"
9430 "\n\t\t: [-color R G B] [-hatch {on|off|ID}]"
9431 "\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
9432 "\n\t\t: [-texRotate Angle]"
9433 "\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
9434 "\n\t\t: [-useObjShader {0|1}]"
9435 "\n\t\t: Clipping planes management:"
9436 "\n\t\t: -maxPlanes print plane limit for view"
9437 "\n\t\t: -delete delete plane with given name"
9438 "\n\t\t: {off|on|0|1} turn clipping on/off"
9439 "\n\t\t: -set|-unset set/unset plane for Object or View list;"
9440 "\n\t\t: applied to active View when list is omitted"
9441 "\n\t\t: -equation A B C D change plane equation"
9442 "\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
9443 "\n\t\t: Capping options:"
9444 "\n\t\t: -capping {off|on|0|1} turn capping on/off"
9445 "\n\t\t: -color R G B set capping color"
9446 "\n\t\t: -texName Texture set capping texture"
9447 "\n\t\t: -texScale SX SY set capping tex scale"
9448 "\n\t\t: -texOrigin TX TY set capping tex origin"
9449 "\n\t\t: -texRotate Angle set capping tex rotation"
9450 "\n\t\t: -hatch {on|off|ID} set capping hatching mask"
9451 "\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
9452 "\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
9453 "\n\t\t: -useObjShader {off|on|0|1} use shader program of object",
9454 __FILE__, VClipPlane, group);
9455 theCommands.Add("vdefaults",
9456 "vdefaults [-absDefl value]"
9457 "\n\t\t: [-devCoeff value]"
9458 "\n\t\t: [-angDefl value]"
9459 "\n\t\t: [-autoTriang {off/on | 0/1}]"
9460 , __FILE__, VDefaults, group);
9461 theCommands.Add("vlight",
9462 "tool to manage light sources, without arguments shows list of lights."
9463 "\n Main commands: "
9464 "\n 'clear' to clear lights"
9465 "\n '{def}aults' to load deafault lights"
9466 "\n 'add' (or 'new') <type> to add any light source"
9467 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
9468 "\n 'change' <lightId> to edit light source with specified lightId"
9469 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
9470 "\n {pos}ition X Y Z"
9471 "\n {dir}ection X Y Z (for directional light or for spotlight)"
9472 "\n color colorName"
9473 "\n {head}light 0|1"
9474 "\n {sm}oothness value"
9475 "\n {int}ensity value"
9476 "\n {constAtten}uation value"
9477 "\n {linearAtten}uation value"
9479 "\n {spotexp}onent value"
9481 "\n\n example: vlight add positional head 1 pos 0 1 1 color red"
9482 "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
9483 __FILE__, VLight, group);
9484 theCommands.Add("vraytrace",
9486 "\n\t\t: Turns on/off ray-tracing renderer."
9487 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
9488 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
9489 __FILE__, VRenderParams, group);
9490 theCommands.Add("vrenderparams",
9491 "\n Manages rendering parameters: "
9492 "\n '-raster' Disables GPU ray-tracing"
9493 "\n '-msaa 0..4' Specifies number of samples for MSAA"
9494 "\n '-rayTrace' Enables GPU ray-tracing"
9495 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
9496 "\n '-shadows on|off' Enables/disables shadows rendering"
9497 "\n '-reflections on|off' Enables/disables specular reflections"
9498 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
9499 "\n '-gleam on|off' Enables/disables transparency shadow effects"
9500 "\n '-gi on|off' Enables/disables global illumination effects"
9501 "\n '-brng on|off' Enables/disables blocked RNG (fast coherent PT)"
9502 "\n '-env on|off' Enables/disables environment map background"
9503 "\n '-shadingModel model' Controls shading model from enumeration"
9504 "\n color, flat, gouraud, phong"
9505 "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"
9506 "\n Unlike vcaps, these parameters dramatically change visual properties."
9507 "\n Command is intended to control presentation quality depending on"
9508 "\n hardware capabilities and performance.",
9509 __FILE__, VRenderParams, group);
9510 theCommands.Add("vfrustumculling",
9511 "vfrustumculling [toEnable]: enables/disables objects clipping",
9512 __FILE__,VFrustumCulling,group);
9513 theCommands.Add("vhighlightselected",
9514 "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n"
9515 "Without arguments it shows if highlighting of selected objects is enabled now.",
9516 __FILE__,VHighlightSelected,group);
9517 theCommands.Add ("vplace",
9519 "\n\t\t: Places the point (in pixels) at the center of the window",
9520 __FILE__, VPlace, group);
9521 theCommands.Add("vxrotate",
9523 __FILE__,VXRotate,group);
9525 theCommands.Add("vmanipulator",
9526 "\n vmanipulator Name [-attach AISObject | -detach | ...]"
9527 "\n tool to create and manage AIS manipulators."
9529 "\n '-attach AISObject' attach manipulator to AISObject"
9530 "\n '-adjustPosition {0|1}' adjust position when attaching"
9531 "\n '-adjustSize {0|1}' adjust size when attaching"
9532 "\n '-enableModes {0|1}' enable modes when attaching"
9533 "\n '-detach' detach manipulator"
9534 "\n '-startTransform mouse_x mouse_y' - invoke start of transformation"
9535 "\n '-transform mouse_x mouse_y' - invoke transformation"
9536 "\n '-stopTransform [abort]' - invoke stop of transformation"
9537 "\n '-move x y z' - move attached object"
9538 "\n '-rotate x y z dx dy dz angle' - rotate attached object"
9539 "\n '-scale factor' - scale attached object"
9540 "\n '-autoActivate {0|1}' - set activation on detection"
9541 "\n '-followTranslation {0|1}' - set following translation transform"
9542 "\n '-followRotation {0|1}' - set following rotation transform"
9543 "\n '-gap value' - set gap between sub-parts"
9544 "\n '-part axis mode {0|1}' - set visual part"
9545 "\n '-pos x y z [nx ny nz [xx xy xz]' - set position of manipulator"
9546 "\n '-size value' - set size of manipulator"
9547 "\n '-zoomable {0|1}' - set zoom persistence",
9548 __FILE__, VManipulator, group);
9551 theCommands.Add("vprogressive",
9553 __FILE__, VProgressiveMode, group);