1 // Created on: 1998-09-01
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <OpenGl_GlCore20.hxx>
18 #include <AIS_Shape.hxx>
19 #include <AIS_InteractiveObject.hxx>
20 #include <AIS_ListOfInteractive.hxx>
21 #include <AIS_ListIteratorOfListOfInteractive.hxx>
23 #include <Graphic3d_AspectMarker3d.hxx>
24 #include <Graphic3d_ExportFormat.hxx>
25 #include <Graphic3d_NameOfTextureEnv.hxx>
26 #include <Graphic3d_GraduatedTrihedron.hxx>
27 #include <Graphic3d_TextureEnv.hxx>
28 #include <Graphic3d_TextureParams.hxx>
29 #include <Graphic3d_TypeOfTextureFilter.hxx>
30 #include <Graphic3d_AspectFillArea3d.hxx>
31 #include <ViewerTest.hxx>
32 #include <ViewerTest_AutoUpdater.hxx>
33 #include <ViewerTest_EventManager.hxx>
34 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
35 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
36 #include <Visual3d_View.hxx>
37 #include <Visual3d_ViewManager.hxx>
38 #include <V3d_AmbientLight.hxx>
39 #include <V3d_ColorScale.hxx>
40 #include <V3d_DirectionalLight.hxx>
41 #include <V3d_LayerMgr.hxx>
42 #include <V3d_LayerMgrPointer.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 <NIS_View.hxx>
49 #include <NIS_Triangulated.hxx>
50 #include <NIS_InteractiveContext.hxx>
51 #include <AIS_InteractiveContext.hxx>
52 #include <Draw_Interpretor.hxx>
54 #include <Draw_Appli.hxx>
55 #include <Aspect_PrintAlgo.hxx>
56 #include <Image_AlienPixMap.hxx>
57 #include <OpenGl_GraphicDriver.hxx>
58 #include <OSD_Timer.hxx>
59 #include <TColStd_HSequenceOfAsciiString.hxx>
60 #include <TColStd_SequenceOfInteger.hxx>
61 #include <TColStd_HSequenceOfReal.hxx>
62 #include <TColgp_Array1OfPnt2d.hxx>
63 #include <TColStd_MapOfAsciiString.hxx>
64 #include <Visual3d_LayerItem.hxx>
65 #include <Aspect_TypeOfLine.hxx>
66 #include <Image_Diff.hxx>
67 #include <Aspect_DisplayConnection.hxx>
71 #include <PrsMgr_PresentableObject.hxx>
72 #include <Graphic3d_ClipPlane.hxx>
73 #include <NCollection_DataMap.hxx>
74 #include <Graphic3d_Texture2Dmanual.hxx>
75 #include <Prs3d_ShadingAspect.hxx>
76 #include <Prs3d_Drawer.hxx>
82 #include <Visual3d_Layer.hxx>
86 #include <WNT_WClass.hxx>
87 #include <WNT_Window.hxx>
90 #define _CRT_SECURE_NO_DEPRECATE
91 #pragma warning (disable:4996)
93 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
94 #include <Cocoa_Window.hxx>
96 #include <Xw_Window.hxx>
97 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
98 #include <X11/Xutil.h>
102 inline Standard_Boolean parseOnOff (Standard_CString theArg,
103 Standard_Boolean& theIsOn)
105 TCollection_AsciiString aFlag (theArg);
110 theIsOn = Standard_True;
111 return Standard_True;
113 else if (aFlag == "off"
116 theIsOn = Standard_False;
117 return Standard_True;
119 return Standard_False;
122 // Auxiliary definitions
123 static const char THE_KEY_DELETE = 127;
125 //==============================================================================
126 // VIEWER GLOBAL VARIABLES
127 //==============================================================================
129 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
130 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
132 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
133 extern const Handle(NIS_InteractiveContext)& TheNISContext();
134 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
136 extern int VErase (Draw_Interpretor& theDI,
137 Standard_Integer theArgNb,
138 const char** theArgVec);
141 static Handle(WNT_Window)& VT_GetWindow() {
142 static Handle(WNT_Window) WNTWin;
145 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
146 static Handle(Cocoa_Window)& VT_GetWindow()
148 static Handle(Cocoa_Window) aWindow;
151 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
152 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
153 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
156 static Handle(Xw_Window)& VT_GetWindow(){
157 static Handle(Xw_Window) XWWin;
161 static void VProcessEvents(ClientData,int);
164 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
166 static Handle(Aspect_DisplayConnection) aDisplayConnection;
167 return aDisplayConnection;
170 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
172 GetDisplayConnection() = theDisplayConnection;
175 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
176 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
178 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
180 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
181 if (!aWindow.IsNull())
182 return aWindow->HWindow();
183 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
184 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
185 if (!aWindow.IsNull())
186 return aWindow->XWindow();
188 return aWindowHandle;
192 static Standard_Boolean MyHLRIsOn = Standard_False;
194 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
195 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
196 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
197 static OpenGl_Caps ViewerTest_myDefaultCaps;
199 #define ZCLIPWIDTH 1.
201 static void OSWindowSetup();
203 //==============================================================================
204 // EVENT GLOBAL VARIABLES
205 //==============================================================================
207 static int Start_Rot = 0;
208 static int ZClipIsOn = 0;
209 int X_Motion = 0; // Current cursor position
211 int X_ButtonPress = 0; // Last ButtonPress position
212 int Y_ButtonPress = 0;
213 Standard_Boolean IsDragged = Standard_False;
214 Standard_Boolean DragFirst = Standard_False;
216 //==============================================================================
219 static LRESULT WINAPI ViewerWindowProc(
224 static LRESULT WINAPI AdvViewerWindowProc(
232 //==============================================================================
235 //==============================================================================
237 const Handle(MMgt_TShared)& ViewerTest::WClass()
239 static Handle(MMgt_TShared) theWClass;
241 if (theWClass.IsNull())
243 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
244 CS_VREDRAW | CS_HREDRAW, 0, 0,
245 ::LoadCursor (NULL, IDC_ARROW));
251 //==============================================================================
252 //function : CreateName
253 //purpose : Create numerical name for new object in theMap
254 //==============================================================================
255 template <typename ObjectType>
256 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
257 const TCollection_AsciiString& theDefaultString)
259 if (theObjectMap.IsEmpty())
260 return theDefaultString + TCollection_AsciiString(1);
262 Standard_Integer aNextKey = 1;
263 Standard_Boolean isFound = Standard_False;
266 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
267 // Look for objects with default names
268 if (theObjectMap.IsBound1(aStringKey))
273 isFound = Standard_True;
276 return theDefaultString + TCollection_AsciiString(aNextKey);
279 //==============================================================================
280 //structure : ViewerTest_Names
281 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
282 //==============================================================================
283 struct ViewerTest_Names
286 TCollection_AsciiString myDriverName;
287 TCollection_AsciiString myViewerName;
288 TCollection_AsciiString myViewName;
292 const TCollection_AsciiString& GetDriverName () const
296 void SetDriverName (const TCollection_AsciiString& theDriverName)
298 myDriverName = theDriverName;
300 const TCollection_AsciiString& GetViewerName () const
304 void SetViewerName (const TCollection_AsciiString& theViewerName)
306 myViewerName = theViewerName;
308 const TCollection_AsciiString& GetViewName () const
312 void SetViewName (const TCollection_AsciiString& theViewName)
314 myViewName = theViewName;
317 //===========================================================================
318 //function : Constructor for ViewerTest_Names
319 //purpose : Get view, viewer, driver names from custom string
320 //===========================================================================
322 ViewerTest_Names (const TCollection_AsciiString& theInputString)
324 TCollection_AsciiString aName(theInputString);
325 if (theInputString.IsEmpty())
327 // Get current configuration
328 if (ViewerTest_myDrivers.IsEmpty())
329 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
330 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
332 myDriverName = ViewerTest_myDrivers.Find2
333 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
335 if(ViewerTest_myContexts.IsEmpty())
337 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
338 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
341 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
343 myViewName = CreateName <Handle(V3d_View)>
344 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
348 // There is at least view name
349 Standard_Integer aParserNumber = 0;
350 for (Standard_Integer i = 0; i < 3; ++i)
352 Standard_Integer aParserPos = aName.SearchFromEnd("/");
356 aName.Split(aParserPos-1);
361 if (aParserNumber == 0)
364 if (!ViewerTest::GetAISContext().IsNull())
366 myDriverName = ViewerTest_myDrivers.Find2
367 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
368 myViewerName = ViewerTest_myContexts.Find2
369 (ViewerTest::GetAISContext());
373 // There is no opened contexts here, need to create names for viewer and driver
374 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
375 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
377 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
378 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
380 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
382 else if (aParserNumber == 1)
384 // Here is viewerName/viewName
385 if (!ViewerTest::GetAISContext().IsNull())
386 myDriverName = ViewerTest_myDrivers.Find2
387 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
390 // There is no opened contexts here, need to create name for driver
391 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
392 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
394 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
396 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
400 //Here is driverName/viewerName/viewName
401 myDriverName = TCollection_AsciiString(aName);
403 TCollection_AsciiString aViewerName(theInputString);
404 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
405 myViewerName = TCollection_AsciiString(aViewerName);
407 myViewName = TCollection_AsciiString(theInputString);
413 //==============================================================================
414 //function : FindContextByView
415 //purpose : Find AIS_InteractiveContext by View
416 //==============================================================================
418 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
420 Handle(AIS_InteractiveContext) anAISContext;
422 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
423 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
425 if (anIter.Value()->CurrentViewer() == theView->Viewer())
426 return anIter.Key2();
432 //==============================================================================
433 //function : SetWindowTitle
434 //purpose : Set window title
435 //==============================================================================
437 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
438 Standard_CString theTitle)
441 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
443 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
444 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
446 if(GetDisplayConnection()->GetDisplay())
449 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
450 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
455 //==============================================================================
456 //function : IsWindowOverlapped
457 //purpose : Check if theWindow overlapp another view
458 //==============================================================================
460 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
461 const Standard_Integer thePxTop,
462 const Standard_Integer thePxRight,
463 const Standard_Integer thePxBottom,
464 TCollection_AsciiString& theViewId)
466 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
467 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
469 Standard_Integer aTop = 0,
473 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
474 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
475 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
476 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
477 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
479 theViewId = anIter.Key1();
480 return Standard_True;
483 return Standard_False;
486 // Workaround: to create and delete non-orthographic views outside ViewerTest
487 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
489 ViewerTest_myViews.UnBind1 (theName);
492 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
493 const Handle(V3d_View)& theView)
495 ViewerTest_myViews.Bind (theName, theView);
498 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
500 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
502 //==============================================================================
503 //function : ViewerInit
504 //purpose : Create the window viewer and initialize all the global variable
505 //==============================================================================
507 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
508 const Standard_Integer thePxTop,
509 const Standard_Integer thePxWidth,
510 const Standard_Integer thePxHeight,
511 Standard_CString theViewName,
512 Standard_CString theDisplayName)
514 // Default position and dimension of the viewer window.
515 // Note that left top corner is set to be sufficiently small to have
516 // window fit in the small screens (actual for remote desktops, see #23003).
517 // The position corresponds to the window's client area, thus some
518 // gap is added for window frame to be visible.
519 Standard_Integer aPxLeft = 20;
520 Standard_Integer aPxTop = 40;
521 Standard_Integer aPxWidth = 409;
522 Standard_Integer aPxHeight = 409;
523 Standard_Boolean toCreateViewer = Standard_False;
525 Handle(OpenGl_GraphicDriver) aGraphicDriver;
526 ViewerTest_Names aViewNames(theViewName);
527 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
528 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
535 aPxWidth = thePxWidth;
536 if (thePxHeight != 0)
537 aPxHeight = thePxHeight;
539 // Get graphic driver (create it or get from another view)
540 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
542 // Get connection string
543 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
544 TCollection_AsciiString aDisplayName(theDisplayName);
545 if (!aDisplayName.IsEmpty())
546 SetDisplayConnection (new Aspect_DisplayConnection ());
548 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
550 (void)theDisplayName; // avoid warning on unused argument
551 SetDisplayConnection (new Aspect_DisplayConnection ());
553 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
554 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
555 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
556 toCreateViewer = Standard_True;
560 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
563 //Dispose the window if input parameters are default
564 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
566 Standard_Integer aTop = 0,
573 // Get screen resolution
574 #if defined(_WIN32) || defined(__WIN32__)
576 GetClientRect(GetDesktopWindow(), &aWindowSize);
577 aScreenHeight = aWindowSize.bottom;
578 aScreenWidth = aWindowSize.right;
579 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
580 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
582 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
583 aScreenWidth = WidthOfScreen(aScreen);
584 aScreenHeight = HeightOfScreen(aScreen);
587 TCollection_AsciiString anOverlappedViewId("");
589 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
591 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
593 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
594 && aRight + 2*aPxWidth + 40 > aScreenWidth)
596 if (aBottom + aPxHeight + 40 > aScreenHeight)
603 aPxTop = aBottom + 40;
606 aPxLeft = aRight + 20;
611 TCollection_AsciiString aTitle("3D View - ");
612 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
614 // Change name of current active window
615 if (!ViewerTest::CurrentView().IsNull())
617 TCollection_AsciiString aTitle("3D View - ");
619 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
620 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
624 Handle(V3d_Viewer) a3DViewer;
625 // If it's the single view, we first look for empty context
626 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
628 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
629 anIter(ViewerTest_myContexts);
631 ViewerTest::SetAISContext (anIter.Value());
632 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
634 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
636 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
637 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
639 else if (a3DViewer.IsNull())
641 toCreateViewer = Standard_True;
642 TCollection_ExtendedString NameOfWindow("Viewer3D");
643 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
645 NameOfWindow = TCollection_ExtendedString("Collector");
647 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
651 if (ViewerTest::GetAISContext().IsNull() ||
652 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
654 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
655 ViewerTest::SetAISContext (aContext);
656 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
660 ViewerTest::ResetEventManager();
665 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
666 Handle(WNT_WClass)::DownCast (WClass()),
667 Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
671 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
672 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
674 aPxWidth, aPxHeight);
675 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
677 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
680 aPxWidth, aPxHeight);
682 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
685 Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
687 ViewerTest::CurrentView(aView);
688 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
689 TheNISContext()->AttachView (aView);
691 // Setup for X11 or NT
694 // Set parameters for V3d_View and V3d_Viewer
695 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
696 aV3dView->SetComputedMode(Standard_False);
697 MyHLRIsOn = aV3dView->ComputedMode();
698 aV3dView->SetZClippingDepth(0.5);
699 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
701 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
704 a3DViewer->SetDefaultLights();
705 a3DViewer->SetLightOn();
708 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
709 #if TCL_MAJOR_VERSION < 8
710 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
711 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
713 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
714 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
718 VT_GetWindow()->Map();
720 // Set the handle of created view in the event manager
721 ViewerTest::ResetEventManager();
723 ViewerTest::CurrentView()->Redraw();
728 return aViewNames.GetViewName();
731 //==============================================================================
732 //function : RedrawAllViews
733 //purpose : Redraw all created views
734 //==============================================================================
735 void ViewerTest::RedrawAllViews()
737 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
738 for (; aViewIt.More(); aViewIt.Next())
740 const Handle(V3d_View)& aView = aViewIt.Key2();
745 //==============================================================================
747 //purpose : Create the window viewer and initialize all the global variable
748 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
749 //==============================================================================
751 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
755 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
756 << "Type help for more information.\n";
760 TCollection_AsciiString aViewName, aDisplayName;
761 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
762 TCollection_AsciiString aName, aValue;
763 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
765 const TCollection_AsciiString anArg = theArgVec[anArgIt];
766 TCollection_AsciiString anArgCase = anArg;
767 anArgCase.UpperCase();
768 if (ViewerTest::SplitParameter (anArg, aName, aValue))
771 if (aName.IsEqual ("NAME"))
775 else if (aName.IsEqual ("L")
776 || aName.IsEqual ("LEFT"))
778 aPxLeft = aValue.IntegerValue();
780 else if (aName.IsEqual ("T")
781 || aName.IsEqual ("TOP"))
783 aPxTop = aValue.IntegerValue();
785 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
786 else if (aName.IsEqual ("DISP")
787 || aName.IsEqual ("DISPLAY"))
789 aDisplayName = aValue;
792 else if (aName.IsEqual ("W")
793 || aName.IsEqual ("WIDTH"))
795 aPxWidth = aValue.IntegerValue();
797 else if (aName.IsEqual ("H")
798 || aName.IsEqual ("HEIGHT"))
800 aPxHeight = aValue.IntegerValue();
804 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
807 else if (aViewName.IsEmpty())
813 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
817 ViewerTest_Names aViewNames (aViewName);
818 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
820 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
821 theDi.Eval (aCommand.ToCString());
825 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
826 aViewName.ToCString(),
827 aDisplayName.ToCString());
832 //==============================================================================
834 //purpose : hidden lines removal algorithm
835 //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}]
836 //==============================================================================
838 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
840 if (ViewerTest::CurrentView().IsNull())
842 di << argv[0] << ": Call vinit before this command, please.\n";
848 di << argv[0] << ": Wrong number of command arguments.\n"
849 << "Type help " << argv[0] << " for more information.\n";
853 // Enable or disable HLR mode.
854 Standard_Boolean isHLROn =
855 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
857 if (isHLROn != MyHLRIsOn)
860 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
863 // Show or hide hidden lines in HLR mode.
864 Standard_Boolean isCurrentShowHidden
865 = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine();
867 Standard_Boolean isShowHidden =
868 (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False)
869 : isCurrentShowHidden;
872 if (isShowHidden != isCurrentShowHidden)
876 ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine();
880 ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine();
886 AIS_ListOfInteractive aListOfShapes;
887 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
889 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
891 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value());
896 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
901 ViewerTest::CurrentView()->Update();
905 //==============================================================================
906 //function : VHLRType
907 //purpose : change type of using HLR algorithm
908 //==============================================================================
910 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
912 if (ViewerTest::CurrentView().IsNull())
914 di << argv[0] << ": Call vinit before this command, please.\n";
920 di << argv[0] << ": Wrong number of command arguments.\n"
921 << "Type help " << argv[0] << " for more information.\n";
925 Prs3d_TypeOfHLR aTypeOfHLR =
926 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
930 AIS_ListOfInteractive aListOfShapes;
931 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
932 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
933 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
934 anIter.More(); anIter.Next())
936 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
939 if (aShape->TypeOfHLR() != aTypeOfHLR)
940 aShape->SetTypeOfHLR (aTypeOfHLR);
942 ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
944 ViewerTest::CurrentView()->Update();
949 for (Standard_Integer i = 2; i < argc; ++i)
951 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
952 TCollection_AsciiString aName (argv[i]);
954 if (!aMap.IsBound2 (aName))
956 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
959 Handle(AIS_Shape) anAISObject =
960 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
961 if (anAISObject.IsNull())
963 anAISObject->SetTypeOfHLR (aTypeOfHLR);
965 ViewerTest::GetAISContext()->Redisplay (anAISObject, Standard_False);
967 ViewerTest::CurrentView()->Update();
973 //==============================================================================
974 //function : FindViewIdByWindowHandle
975 //purpose : Find theView Id in the map of views by window handle
976 //==============================================================================
977 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
978 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
980 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
981 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
983 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
984 if (aWindowHandle == theWindowHandle)
985 return anIter.Key1();
987 return TCollection_AsciiString("");
991 //==============================================================================
992 //function : ActivateView
993 //purpose : Make the view active
994 //==============================================================================
996 void ActivateView (const TCollection_AsciiString& theViewName)
998 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1001 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1002 if (!anAISContext.IsNull())
1004 if (!ViewerTest::CurrentView().IsNull())
1006 TCollection_AsciiString aTitle("3D View - ");
1007 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1008 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1011 ViewerTest::CurrentView (aView);
1012 // Update degenerate mode
1013 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
1014 ViewerTest::SetAISContext (anAISContext);
1015 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
1016 aTitle = aTitle + theViewName + "(*)";
1017 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1018 #if defined(_WIN32) || defined(__WIN32__)
1019 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1020 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1021 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1023 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1025 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1026 ViewerTest::CurrentView()->Redraw();
1031 //==============================================================================
1032 //function : RemoveView
1034 //==============================================================================
1035 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1036 const Standard_Boolean theToRemoveContext)
1038 if (!ViewerTest_myViews.IsBound2 (theView))
1043 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1044 RemoveView (aViewName, theToRemoveContext);
1047 //==============================================================================
1048 //function : RemoveView
1049 //purpose : Close and remove view from display, clear maps if neccessary
1050 //==============================================================================
1051 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1053 if (!ViewerTest_myViews.IsBound1(theViewName))
1055 cout << "Wrong view name\n";
1059 // Activate another view if it's active now
1060 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1062 if (ViewerTest_myViews.Extent() > 1)
1064 TCollection_AsciiString aNewViewName;
1065 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
1066 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1067 if (anIter.Key1() != theViewName)
1069 aNewViewName = anIter.Key1();
1072 ActivateView (aNewViewName);
1076 Handle(V3d_View) anEmptyView;
1077 #if defined(_WIN32) || defined(__WIN32__)
1078 Handle(WNT_Window) anEmptyWindow;
1079 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1080 Handle(Cocoa_Window) anEmptyWindow;
1082 Handle(Xw_Window) anEmptyWindow;
1084 VT_GetWindow() = anEmptyWindow;
1085 ViewerTest::CurrentView (anEmptyView);
1086 if (isContextRemoved)
1088 Handle(AIS_InteractiveContext) anEmptyContext;
1089 ViewerTest::SetAISContext(anEmptyContext);
1095 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1096 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1098 // Remove view resources
1099 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1100 ViewerTest_myViews.UnBind1(theViewName);
1103 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1104 XFlush (GetDisplayConnection()->GetDisplay());
1107 // Keep context opened only if the closed view is last to avoid
1108 // unused empty contexts
1109 if (!aCurrentContext.IsNull())
1111 // Check if there are more difined views in the viewer
1112 aCurrentContext->CurrentViewer()->InitDefinedViews();
1113 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1115 // Remove driver if there is no viewers that use it
1116 Standard_Boolean isRemoveDriver = Standard_True;
1117 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1118 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1120 if (aCurrentContext != anIter.Key2() &&
1121 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1123 isRemoveDriver = Standard_False;
1129 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1130 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1131 #if TCL_MAJOR_VERSION < 8
1132 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1134 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1139 ViewerTest_myContexts.UnBind2(aCurrentContext);
1142 cout << "3D View - " << theViewName << " was deleted.\n";
1146 //==============================================================================
1148 //purpose : Remove the view defined by its name
1149 //==============================================================================
1151 static int VClose (Draw_Interpretor& /*theDi*/,
1152 Standard_Integer theArgsNb,
1153 const char** theArgVec)
1155 NCollection_List<TCollection_AsciiString> aViewList;
1158 TCollection_AsciiString anArg (theArgVec[1]);
1160 if (anArg.IsEqual ("ALL")
1161 || anArg.IsEqual ("*"))
1163 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1164 anIter.More(); anIter.Next())
1166 aViewList.Append (anIter.Key1());
1168 if (aViewList.IsEmpty())
1170 std::cout << "No view to close\n";
1176 ViewerTest_Names aViewName (theArgVec[1]);
1177 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1179 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1182 aViewList.Append (aViewName.GetViewName());
1187 // close active view
1188 if (ViewerTest::CurrentView().IsNull())
1190 std::cerr << "No active view!\n";
1193 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1196 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1197 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1198 anIter.More(); anIter.Next())
1200 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1206 //==============================================================================
1207 //function : VActivate
1208 //purpose : Activate the view defined by its ID
1209 //==============================================================================
1211 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1215 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1216 << "Usage: " << theArgVec[0] << " ViewID\n";
1221 theDi.Eval("vviewlist");
1225 TCollection_AsciiString aNameString(theArgVec[1]);
1226 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1228 TCollection_AsciiString aTitle("3D View - ");
1229 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1230 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1231 Handle(V3d_View) anEmptyView;
1232 #if defined(_WIN32) || defined(__WIN32__)
1233 Handle(WNT_Window) anEmptyWindow;
1234 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1235 Handle(Cocoa_Window) anEmptyWindow;
1237 Handle(Xw_Window) anEmptyWindow;
1239 VT_GetWindow() = anEmptyWindow;
1240 ViewerTest::CurrentView (anEmptyView);
1241 ViewerTest::ResetEventManager();
1242 theDi << theArgVec[0] << ": all views are inactive\n";
1246 ViewerTest_Names aViewNames(aNameString);
1248 // Check if this view exists in the viewer with the driver
1249 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1251 theDi << "Wrong view name\n";
1255 // Check if it is active already
1256 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1258 theDi << theArgVec[0] << ": the view is active already\n";
1262 ActivateView (aViewNames.GetViewName());
1266 //==============================================================================
1267 //function : VViewList
1268 //purpose : Print current list of views per viewer and graphic driver ID
1269 // shared between viewers
1270 //==============================================================================
1272 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1276 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1277 << "Usage: " << theArgVec[0] << " name";
1280 if (ViewerTest_myContexts.Size() < 1)
1283 Standard_Boolean isTreeView =
1284 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1287 theDi << theArgVec[0] <<":\n";
1289 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1290 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1293 theDi << aDriverIter.Key1() << ":\n";
1295 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1296 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1298 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1302 TCollection_AsciiString aContextName(aContextIter.Key1());
1303 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1306 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1307 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1309 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1311 TCollection_AsciiString aViewName(aViewIter.Key1());
1314 if (aViewIter.Value() == ViewerTest::CurrentView())
1315 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1317 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1321 theDi << aViewName << " ";
1331 //==============================================================================
1332 //function : VT_ProcessKeyPress
1333 //purpose : Handle KeyPress event from a CString
1334 //==============================================================================
1335 void VT_ProcessKeyPress (const char* buf_ret)
1337 //cout << "KeyPress" << endl;
1338 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1339 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1340 // Letter in alphabetic order
1342 if (!strcasecmp (buf_ret, "A"))
1345 aView->SetProj(V3d_XposYnegZpos);
1347 else if (!strcasecmp (buf_ret, "D"))
1352 else if (!strcasecmp (buf_ret, "F"))
1355 if (aNisView.IsNull())
1358 aNisView->FitAll3d();
1360 else if (!strcasecmp (buf_ret, "H"))
1363 cout << "HLR" << endl;
1364 aView->SetComputedMode (!aView->ComputedMode());
1365 MyHLRIsOn = aView->ComputedMode();
1367 else if (!strcasecmp (buf_ret, "P"))
1370 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1371 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1372 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1374 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1375 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1377 AIS_ListOfInteractive aListOfShapes;
1378 aContext->DisplayedObjects(aListOfShapes);
1379 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1380 anIter.More(); anIter.Next())
1382 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1383 if (aShape.IsNull())
1385 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1386 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1388 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1389 aContext->Redisplay (aShape, Standard_False);
1394 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1396 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1397 if (aShape.IsNull())
1399 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1400 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1402 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1403 aContext->Redisplay (aShape, Standard_False);
1407 aContext->UpdateCurrentViewer();
1410 else if (!strcasecmp (buf_ret, "S"))
1412 std::cout << "setup Shaded display mode" << std::endl;
1414 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1415 if(Ctx->NbCurrents()==0 ||
1416 Ctx->NbSelected()==0)
1417 Ctx->SetDisplayMode(AIS_Shaded);
1419 if(Ctx->HasOpenedContext()){
1420 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1421 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1424 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1425 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1427 Ctx->UpdateCurrentViewer();
1430 else if (!strcasecmp (buf_ret, "U"))
1432 // Unset display mode
1433 std::cout << "reset display mode to defaults" << std::endl;
1435 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1436 if(Ctx->NbCurrents()==0 ||
1437 Ctx->NbSelected()==0)
1438 Ctx->SetDisplayMode(AIS_WireFrame);
1440 if(Ctx->HasOpenedContext()){
1441 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1442 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1445 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1446 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1448 Ctx->UpdateCurrentViewer();
1452 else if (!strcasecmp (buf_ret, "T"))
1455 aView->SetProj(V3d_Zpos);
1457 else if (!strcasecmp (buf_ret, "B"))
1460 aView->SetProj(V3d_Zneg);
1462 else if (!strcasecmp (buf_ret, "L"))
1465 aView->SetProj(V3d_Xneg);
1467 else if (!strcasecmp (buf_ret, "R"))
1470 aView->SetProj(V3d_Xpos);
1472 else if (!strcasecmp (buf_ret, "W"))
1474 std::cout << "setup WireFrame display mode" << std::endl;
1475 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1476 if(Ctx->NbCurrents()==0 ||
1477 Ctx->NbSelected()==0)
1478 Ctx->SetDisplayMode(AIS_WireFrame);
1480 if(Ctx->HasOpenedContext()){
1481 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1482 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1485 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1486 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1488 Ctx->UpdateCurrentViewer();
1491 else if (!strcasecmp (buf_ret, "Z"))
1495 cout << "ZClipping OFF" << endl;
1498 aView->SetZClippingType(V3d_OFF);
1502 cout << "ZClipping ON" << endl;
1505 aView->SetZClippingType(V3d_FRONT);
1509 else if (!strcasecmp (buf_ret, ","))
1511 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1513 else if (!strcasecmp (buf_ret, "."))
1515 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1517 else if (*buf_ret == THE_KEY_DELETE)
1519 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1521 && aCtx->NbCurrents() > 0
1522 && aCtx->NbSelected() > 0)
1524 Draw_Interprete ("verase");
1530 Standard_Integer Num = Draw::Atoi(buf_ret);
1531 if(Num>=0 && Num<=7)
1532 ViewerTest::StandardModeActivation(Num);
1536 //==============================================================================
1537 //function : VT_ProcessExpose
1538 //purpose : Redraw the View on an Expose Event
1539 //==============================================================================
1540 void VT_ProcessExpose()
1542 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1543 if (!aView3d.IsNull())
1549 //==============================================================================
1550 //function : VT_ProcessConfigure
1551 //purpose : Resize the View on an Configure Event
1552 //==============================================================================
1553 void VT_ProcessConfigure()
1555 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1556 if (aView3d.IsNull())
1561 aView3d->MustBeResized();
1566 //==============================================================================
1567 //function : VT_ProcessButton1Press
1569 //==============================================================================
1570 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1571 const char** theArgVec,
1572 Standard_Boolean theToPick,
1573 Standard_Boolean theIsShift)
1577 Standard_Real X, Y, Z;
1578 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1580 Draw::Set (theArgVec[1], X);
1581 Draw::Set (theArgVec[2], Y);
1582 Draw::Set (theArgVec[3], Z);
1587 ViewerTest::CurrentEventManager()->ShiftSelect();
1591 ViewerTest::CurrentEventManager()->Select();
1594 return Standard_False;
1597 //==============================================================================
1598 //function : VT_ProcessButton1Release
1599 //purpose : End selecting
1600 //==============================================================================
1601 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1605 IsDragged = Standard_False;
1606 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1609 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1610 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1614 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1615 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1620 //==============================================================================
1621 //function : VT_ProcessButton3Press
1622 //purpose : Start Rotation
1623 //==============================================================================
1624 void VT_ProcessButton3Press()
1629 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1631 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1634 //==============================================================================
1635 //function : VT_ProcessButton3Release
1636 //purpose : End rotation
1637 //==============================================================================
1638 void VT_ProcessButton3Release()
1645 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1650 //==============================================================================
1651 //function : ProcessZClipMotion
1653 //==============================================================================
1655 void ProcessZClipMotion()
1657 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1658 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1660 //Quantity_Length VDX, VDY;
1661 //a3DView->Size(VDX,VDY);
1662 //Standard_Real VDZ = a3DView->ZSize();
1663 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1665 Quantity_Length aDx = a3DView->Convert(X_Motion - X_ButtonPress);
1667 // Front = Depth + width/2.
1668 Standard_Real aDepth = 0.5;
1669 Standard_Real aWidth = 0.1;
1670 a3DView->ZClipping(aDepth,aWidth);
1674 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1676 a3DView->SetZClippingDepth(aDepth);
1680 X_ButtonPress = X_Motion;
1681 Y_ButtonPress = Y_Motion;
1685 //==============================================================================
1686 //function : ProcessControlButton1Motion
1688 //==============================================================================
1690 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1691 static void ProcessControlButton1Motion()
1693 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1695 X_ButtonPress = X_Motion;
1696 Y_ButtonPress = Y_Motion;
1700 //==============================================================================
1701 //function : VT_ProcessControlButton2Motion
1703 //==============================================================================
1704 void VT_ProcessControlButton2Motion()
1706 Standard_Integer aDx = X_Motion - X_ButtonPress;
1707 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1709 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1711 ViewerTest::CurrentView()->Pan (aDx, aDy);
1713 X_ButtonPress = X_Motion;
1714 Y_ButtonPress = Y_Motion;
1717 //==============================================================================
1718 //function : VT_ProcessControlButton3Motion
1719 //purpose : Rotation
1720 //==============================================================================
1721 void VT_ProcessControlButton3Motion()
1725 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1729 //==============================================================================
1730 //function : VT_ProcessMotion
1732 //==============================================================================
1733 void VT_ProcessMotion()
1735 //pre-hilights detected objects at mouse position
1737 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1738 EM->MoveTo(X_Motion, Y_Motion);
1742 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1744 Xpix = X_Motion;Ypix=Y_Motion;
1747 //==============================================================================
1748 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1749 //purpose : Switches to an axonometric, top, left and other views
1750 //==============================================================================
1752 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1754 if ( ViewerTest::CurrentView().IsNull() )
1756 di<<"Call vinit before this command, please"<<"\n";
1760 ViewerTest::CurrentView()->SetProj(ori);
1764 //==============================================================================
1766 //purpose : Switch to an Axonometric view
1767 //Draw arg : No args
1768 //==============================================================================
1770 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1772 return ViewProject(di, V3d_XposYnegZpos);
1775 //==============================================================================
1777 //purpose : Switch to a Top View
1778 //Draw arg : No args
1779 //==============================================================================
1781 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1783 return ViewProject(di, V3d_Zpos);
1786 //==============================================================================
1787 //function : VBottom
1788 //purpose : Switch to a Bottom View
1789 //Draw arg : No args
1790 //==============================================================================
1792 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1794 return ViewProject(di, V3d_Zneg);
1797 //==============================================================================
1799 //purpose : Switch to a Left View
1800 //Draw arg : No args
1801 //==============================================================================
1803 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1805 return ViewProject(di, V3d_Ypos);
1808 //==============================================================================
1810 //purpose : Switch to a Right View
1811 //Draw arg : No args
1812 //==============================================================================
1814 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1816 return ViewProject(di, V3d_Yneg);
1819 //==============================================================================
1821 //purpose : Switch to a Front View
1822 //Draw arg : No args
1823 //==============================================================================
1825 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1827 return ViewProject(di, V3d_Xpos);
1830 //==============================================================================
1832 //purpose : Switch to a Back View
1833 //Draw arg : No args
1834 //==============================================================================
1836 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1838 return ViewProject(di, V3d_Xneg);
1841 //==============================================================================
1843 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1844 //Draw arg : No args
1845 //==============================================================================
1847 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1850 di << "Q : Quit the application" << "\n";
1852 di << "========================="<<"\n";
1853 di << "F : FitAll" << "\n";
1854 di << "T : TopView" << "\n";
1855 di << "B : BottomView" << "\n";
1856 di << "R : RightView" << "\n";
1857 di << "L : LeftView" << "\n";
1858 di << "A : AxonometricView" << "\n";
1859 di << "D : ResetView" << "\n";
1861 di << "========================="<<"\n";
1862 di << "S : Shading" << "\n";
1863 di << "W : Wireframe" << "\n";
1864 di << "H : HidelLineRemoval" << "\n";
1865 di << "U : Unset display mode" << "\n";
1866 di << "Delete : Remove selection from viewer" << "\n";
1868 di << "========================="<<"\n";
1869 di << "Selection mode "<<"\n";
1870 di << "0 : Shape" <<"\n";
1871 di << "1 : Vertex" <<"\n";
1872 di << "2 : Edge" <<"\n";
1873 di << "3 : Wire" <<"\n";
1874 di << "4 : Face" <<"\n";
1875 di << "5 : Shell" <<"\n";
1876 di << "6 : Solid" <<"\n";
1877 di << "7 : Compound" <<"\n";
1879 di << "========================="<<"\n";
1880 di << "Z : Switch Z clipping On/Off" << "\n";
1881 di << ", : Hilight next detected" << "\n";
1882 di << ". : Hilight previous detected" << "\n";
1889 static Standard_Boolean Ppick = 0;
1890 static Standard_Integer Pargc = 0;
1891 static const char** Pargv = NULL;
1894 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1899 if (!ViewerTest_myViews.IsEmpty()) {
1901 WPARAM fwKeys = wParam;
1906 // Delete view from map of views
1907 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1912 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1913 || ViewerTest::CurrentView().IsNull())
1915 // Activate inactive window
1916 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1918 ActivateView (FindViewIdByWindowHandle(hwnd));
1925 HDC hdc = GetDC( hwnd );
1926 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1927 SetROP2( hdc, R2_NOT );
1928 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1929 ReleaseDC( hwnd, hdc );
1930 VT_ProcessButton1Release (fwKeys & MK_SHIFT);
1932 IsDragged = Standard_False;
1933 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1935 case WM_LBUTTONDOWN:
1936 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1938 IsDragged = Standard_True;
1939 DragFirst = Standard_True;
1940 X_ButtonPress = LOWORD(lParam);
1941 Y_ButtonPress = HIWORD(lParam);
1943 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1950 HDC hdc = GetDC( hwnd );
1952 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1953 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1954 SetROP2( hdc, R2_NOT );
1957 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1959 DragFirst = Standard_False;
1960 X_Motion = LOWORD(lParam);
1961 Y_Motion = HIWORD(lParam);
1963 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1965 SelectObject( hdc, anObj );
1967 ReleaseDC( hwnd, hdc );
1970 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1974 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1978 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1982 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1989 if ( !ViewerTest::CurrentView().IsNull() ) {
1994 BeginPaint(hwnd, &ps);
1995 EndPaint(hwnd, &ps);
2000 VT_ProcessConfigure();
2004 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2007 c[0] = (char) wParam;
2009 if (wParam == VK_DELETE)
2011 c[0] = THE_KEY_DELETE;
2014 else if (wParam == VK_OEM_COMMA)
2019 else if (wParam == VK_OEM_PERIOD)
2023 VT_ProcessKeyPress (c);
2031 VT_ProcessButton3Release();
2034 case WM_LBUTTONDOWN:
2035 case WM_MBUTTONDOWN:
2036 case WM_RBUTTONDOWN:
2038 WPARAM fwKeys = wParam;
2042 X_ButtonPress = LOWORD(lParam);
2043 Y_ButtonPress = HIWORD(lParam);
2045 if (Msg == WM_LBUTTONDOWN)
2047 if (fwKeys & MK_CONTROL)
2049 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2053 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2056 else if (Msg == WM_RBUTTONDOWN)
2059 VT_ProcessButton3Press();
2066 //cout << "\t WM_MOUSEMOVE" << endl;
2067 WPARAM fwKeys = wParam;
2068 X_Motion = LOWORD(lParam);
2069 Y_Motion = HIWORD(lParam);
2072 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2074 X_ButtonPress = LOWORD(lParam);
2075 Y_ButtonPress = HIWORD(lParam);
2077 if ( fwKeys & MK_RBUTTON ) {
2079 VT_ProcessButton3Press();
2083 if ( fwKeys & MK_CONTROL ) {
2084 if ( fwKeys & MK_LBUTTON ) {
2085 ProcessControlButton1Motion();
2087 else if ( fwKeys & MK_MBUTTON ||
2088 ((fwKeys&MK_LBUTTON) &&
2089 (fwKeys&MK_RBUTTON) ) ){
2090 VT_ProcessControlButton2Motion();
2092 else if ( fwKeys & MK_RBUTTON ) {
2093 VT_ProcessControlButton3Motion();
2097 else if ( fwKeys & MK_SHIFT ) {
2098 if ( fwKeys & MK_MBUTTON ||
2099 ((fwKeys&MK_LBUTTON) &&
2100 (fwKeys&MK_RBUTTON) ) ) {
2101 cout << "ProcessZClipMotion()" << endl;
2102 ProcessZClipMotion();
2106 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2108 if ((fwKeys & MK_MBUTTON
2109 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2111 ProcessZClipMotion();
2122 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2127 return DefWindowProc( hwnd, Msg, wParam, lParam );
2133 //==============================================================================
2134 //function : ViewerMainLoop
2135 //purpose : Get a Event on the view and dispatch it
2136 //==============================================================================
2139 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2141 Ppick = (argc > 0)? 1 : 0;
2149 cout << "Start picking" << endl;
2151 while ( Ppick == 1 ) {
2152 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2153 if (GetMessage(&msg, NULL, 0, 0) ) {
2154 TranslateMessage(&msg);
2155 DispatchMessage(&msg);
2159 cout << "Picking done" << endl;
2165 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2167 int min( int a, int b )
2175 int max( int a, int b )
2183 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2186 static XEvent aReport;
2187 Standard_Boolean pick = argc > 0;
2188 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2189 XNextEvent (aDisplay, &aReport);
2191 // Handle event for the chosen display connection
2192 switch (aReport.type) {
2195 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2198 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2204 // Activate inactive view
2205 Window aWindow = GetWindowHandle(VT_GetWindow());
2206 if(aWindow != aReport.xfocus.window)
2208 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2217 case ConfigureNotify:
2219 VT_ProcessConfigure();
2228 XComposeStatus status_in_out;
2230 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2231 (char *) buf_ret , 10 ,
2232 &ks_ret , &status_in_out ) ;
2235 buf_ret[ret_len] = '\0' ;
2239 VT_ProcessKeyPress (buf_ret);
2245 X_ButtonPress = aReport.xbutton.x;
2246 Y_ButtonPress = aReport.xbutton.y;
2248 if (aReport.xbutton.button == Button1)
2250 if (aReport.xbutton.state & ControlMask)
2252 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2256 IsDragged = Standard_True;
2257 DragFirst = Standard_True;
2260 else if (aReport.xbutton.button == Button3)
2263 VT_ProcessButton3Press();
2273 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2274 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2275 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2278 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2279 if( aContext.IsNull() )
2281 cout << "The context is null. Please use vinit before createmesh" << endl;
2285 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2286 if( aReport.xbutton.button==1 )
2290 aContext->ShiftSelect();
2299 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2300 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2301 ViewerTest::CurrentView());
2305 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2306 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2307 ViewerTest::CurrentView() );
2310 VT_ProcessButton3Release();
2312 IsDragged = Standard_False;
2315 VT_ProcessButton3Release();
2320 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2326 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2327 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2328 XSetFunction( aDisplay, gc, GXinvert );
2331 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2333 X_Motion = aReport.xmotion.x;
2334 Y_Motion = aReport.xmotion.y;
2335 DragFirst = Standard_False;
2337 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2341 X_Motion = aReport.xmotion.x;
2342 Y_Motion = aReport.xmotion.y;
2344 // remove all the ButtonMotionMaskr
2345 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2347 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2348 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2350 Quantity_Length VDX, VDY;
2352 ViewerTest::CurrentView()->Size(VDX,VDY);
2353 Standard_Real VDZ =0 ;
2354 VDZ = ViewerTest::CurrentView()->ZSize();
2356 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2358 Quantity_Length dx = 0 ;
2359 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2363 dx = dx / VDX * VDZ;
2367 ViewerTest::CurrentView()->Redraw();
2371 if ( aReport.xmotion.state & ControlMask ) {
2372 if ( aReport.xmotion.state & Button1Mask ) {
2373 ProcessControlButton1Motion();
2375 else if ( aReport.xmotion.state & Button2Mask ) {
2376 VT_ProcessControlButton2Motion();
2378 else if ( aReport.xmotion.state & Button3Mask ) {
2379 VT_ProcessControlButton3Motion();
2393 //==============================================================================
2394 //function : VProcessEvents
2395 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2396 // event in the Viewer window
2397 //==============================================================================
2399 static void VProcessEvents(ClientData,int)
2401 NCollection_Vector<int> anEventNumbers;
2402 // Get number of messages from every display
2403 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2404 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2406 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2408 // Handle events for every display
2409 int anEventIter = 0;
2410 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2411 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2413 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2414 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2416 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2417 int anEventResult = ViewerMainLoop( 0, NULL);
2418 // If window is closed or context was not found finish current event processing loop
2424 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2429 //==============================================================================
2430 //function : OSWindowSetup
2431 //purpose : Setup for the X11 window to be able to cath the event
2432 //==============================================================================
2435 static void OSWindowSetup()
2437 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2440 Window window = VT_GetWindow()->XWindow();
2441 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2442 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2443 XSynchronize(aDisplay, 1);
2445 // X11 : For keyboard on SUN
2447 wmhints.flags = InputHint;
2450 XSetWMHints( aDisplay, window, &wmhints);
2452 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2453 ButtonPressMask | ButtonReleaseMask |
2454 StructureNotifyMask |
2456 Button1MotionMask | Button2MotionMask |
2457 Button3MotionMask | FocusChangeMask
2459 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2460 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2462 XSynchronize(aDisplay, 0);
2471 //==============================================================================
2474 //purpose : Fitall, no DRAW arguments
2475 //Draw arg : No args
2476 //==============================================================================
2478 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2480 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2481 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2482 if (V.IsNull() == Standard_False) {
2484 } else if (aView.IsNull() == Standard_False) {
2490 //=======================================================================
2491 //function : VFitArea
2492 //purpose : Fit view to show area located between two points
2493 // : given in world 2D or 3D coordinates.
2494 //=======================================================================
2495 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2497 Handle(V3d_View) aView = ViewerTest::CurrentView();
2500 std::cerr << theArgVec[0] << "Error: No active view.\n";
2505 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2506 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2510 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2511 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2512 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2513 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2515 else if (theArgNb == 7)
2517 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2518 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2519 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2520 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2521 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2522 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2526 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2527 theDI.PrintHelp(theArgVec[0]);
2531 // Convert model coordinates to view space
2532 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2533 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2534 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2536 // Determine fit area
2537 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2538 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2540 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2542 if (aDiagonal < Precision::Confusion())
2544 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2548 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2552 //==============================================================================
2554 //purpose : ZFitall, no DRAW arguments
2555 //Draw arg : No args
2556 //==============================================================================
2557 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2559 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2561 if (aCurrentView.IsNull())
2563 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2569 aCurrentView->View()->ZFitAll();
2570 aCurrentView->Redraw();
2574 Standard_Real aScale = 1.0;
2578 aScale = Draw::Atoi (theArgVec[1]);
2581 aCurrentView->View()->ZFitAll (aScale);
2582 aCurrentView->Redraw();
2587 //==============================================================================
2588 //function : VRepaint
2590 //==============================================================================
2591 static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
2593 Handle(V3d_View) V = ViewerTest::CurrentView();
2594 if ( !V.IsNull() ) V->Redraw(); return 0;
2597 //==============================================================================
2599 //purpose : Remove all the object from the viewer
2600 //Draw arg : No args
2601 //==============================================================================
2603 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2605 Handle(V3d_View) V = ViewerTest::CurrentView();
2607 ViewerTest::Clear();
2611 //==============================================================================
2614 //==============================================================================
2616 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2617 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2620 di << argv[0] << "Invalid number of arguments" << "\n";
2624 while (ViewerMainLoop( argc, argv)) {
2630 //==============================================================================
2632 //purpose : Load image as background
2633 //==============================================================================
2635 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2637 if (argc < 2 || argc > 3)
2639 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2640 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2644 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2645 if(AISContext.IsNull())
2647 di << "use 'vinit' command before " << argv[0] << "\n";
2651 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2654 const char* szType = argv[2];
2655 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2656 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2657 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2658 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2661 di << "Wrong fill type : " << szType << "\n";
2662 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2667 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2668 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2673 //==============================================================================
2674 //function : VSetBgMode
2675 //purpose : Change background image fill type
2676 //==============================================================================
2678 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2682 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2683 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2687 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2688 if(AISContext.IsNull())
2690 di << "use 'vinit' command before " << argv[0] << "\n";
2693 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2694 const char* szType = argv[1];
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";
2705 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2706 V3dView->SetBgImageStyle(aFillType, Standard_True);
2710 //==============================================================================
2711 //function : VSetGradientBg
2712 //purpose : Mount gradient background
2713 //==============================================================================
2714 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2718 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2719 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2720 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2721 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2725 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2726 if(AISContext.IsNull())
2728 di << "use 'vinit' command before " << argv[0] << "\n";
2734 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2735 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2736 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2737 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2739 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2740 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2741 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2743 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2744 int aType = Draw::Atoi(argv[7]);
2745 if( aType < 0 || aType > 8 )
2747 di << "Wrong fill type " << "\n";
2748 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2749 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2753 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2755 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2756 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2762 //==============================================================================
2763 //function : VSetGradientBgMode
2764 //purpose : Change gradient background fill style
2765 //==============================================================================
2766 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2770 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2771 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2772 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2776 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2777 if(AISContext.IsNull())
2779 di << "use 'vinit' command before " << argv[0] << "\n";
2784 int aType = Draw::Atoi(argv[1]);
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->SetBgGradientStyle( aMethod, 1 );
2802 //==============================================================================
2803 //function : VSetColorBg
2804 //purpose : Set color background
2805 //==============================================================================
2806 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2810 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2811 di << "R,G,B = [0..255]" << "\n";
2815 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2816 if(AISContext.IsNull())
2818 di << "use 'vinit' command before " << argv[0] << "\n";
2824 Standard_Real R = Draw::Atof(argv[1])/255.;
2825 Standard_Real G = Draw::Atof(argv[2])/255.;
2826 Standard_Real B = Draw::Atof(argv[3])/255.;
2827 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2829 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2830 V3dView->SetBackgroundColor( aColor );
2837 //==============================================================================
2839 //purpose : View Scaling
2840 //==============================================================================
2842 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2844 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2845 if ( V3dView.IsNull() ) return 1;
2848 di << argv[0] << "Invalid number of arguments" << "\n";
2851 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2854 //==============================================================================
2855 //function : VZBuffTrihedron
2857 //==============================================================================
2859 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
2860 Standard_Integer theArgNb,
2861 const char** theArgVec)
2863 Handle(V3d_View) aView = ViewerTest::CurrentView();
2866 std::cout << "Error: no active viewer!\n";
2870 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
2872 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2873 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
2874 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
2875 Quantity_Color anArrowColorX = Quantity_NOC_RED;
2876 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
2877 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
2878 Standard_Real aScale = 0.1;
2879 Standard_Real aSizeRatio = 0.8;
2880 Standard_Real anArrowDiam = 0.05;
2881 Standard_Integer aNbFacets = 12;
2882 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2884 Standard_CString anArg = theArgVec[anArgIter];
2885 TCollection_AsciiString aFlag (anArg);
2887 if (anUpdateTool.parseRedrawMode (aFlag))
2891 else if (aFlag == "-on")
2895 else if (aFlag == "-off")
2897 aView->TriedronErase();
2900 else if (aFlag == "-pos"
2901 || aFlag == "-position"
2902 || aFlag == "-corner")
2904 if (++anArgIter >= theArgNb)
2906 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
2910 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
2911 aPosName.LowerCase();
2912 if (aPosName == "center")
2914 aPosition = Aspect_TOTP_CENTER;
2916 else if (aPosName == "left_lower"
2917 || aPosName == "lower_left"
2918 || aPosName == "leftlower"
2919 || aPosName == "lowerleft")
2921 aPosition = Aspect_TOTP_LEFT_LOWER;
2923 else if (aPosName == "left_upper"
2924 || aPosName == "upper_left"
2925 || aPosName == "leftupper"
2926 || aPosName == "upperleft")
2928 aPosition = Aspect_TOTP_LEFT_UPPER;
2930 else if (aPosName == "right_lower"
2931 || aPosName == "lower_right"
2932 || aPosName == "rightlower"
2933 || aPosName == "lowerright")
2935 aPosition = Aspect_TOTP_RIGHT_LOWER;
2937 else if (aPosName == "right_upper"
2938 || aPosName == "upper_right"
2939 || aPosName == "rightupper"
2940 || aPosName == "upperright")
2942 aPosition = Aspect_TOTP_RIGHT_UPPER;
2946 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
2950 else if (aFlag == "-type")
2952 if (++anArgIter >= theArgNb)
2954 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
2958 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
2959 aTypeName.LowerCase();
2960 if (aTypeName == "wireframe"
2961 || aTypeName == "wire")
2963 aVisType = V3d_WIREFRAME;
2965 else if (aTypeName == "zbuffer"
2966 || aTypeName == "shaded")
2968 aVisType = V3d_ZBUFFER;
2972 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
2975 else if (aFlag == "-scale")
2977 if (++anArgIter >= theArgNb)
2979 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
2983 aScale = Draw::Atof (theArgVec[anArgIter]);
2985 else if (aFlag == "-size"
2986 || aFlag == "-sizeratio")
2988 if (++anArgIter >= theArgNb)
2990 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
2994 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
2996 else if (aFlag == "-arrowdiam"
2997 || aFlag == "-arrowdiameter")
2999 if (++anArgIter >= theArgNb)
3001 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3005 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3007 else if (aFlag == "-nbfacets")
3009 if (++anArgIter >= theArgNb)
3011 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3015 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3017 else if (aFlag == "-colorlabel"
3018 || aFlag == "-colorlabels")
3020 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3021 theArgVec + anArgIter + 1,
3025 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3028 anArgIter += aNbParsed;
3030 else if (aFlag == "-colorarrowx")
3032 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3033 theArgVec + anArgIter + 1,
3037 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3040 anArgIter += aNbParsed;
3042 else if (aFlag == "-colorarrowy")
3044 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3045 theArgVec + anArgIter + 1,
3049 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3052 anArgIter += aNbParsed;
3054 else if (aFlag == "-colorarrowz")
3056 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3057 theArgVec + anArgIter + 1,
3061 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3064 anArgIter += aNbParsed;
3068 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3073 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3074 aSizeRatio, anArrowDiam, aNbFacets);
3075 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
3076 aView->View()->ZFitAll();
3080 //==============================================================================
3081 //function : VRotate
3082 //purpose : Camera Rotating
3083 //==============================================================================
3085 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3087 Handle(V3d_View) aView = ViewerTest::CurrentView();
3090 std::cout << "No active view!\n";
3094 Standard_Boolean hasFlags = Standard_False;
3095 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3097 Standard_CString anArg (theArgVec[anArgIter]);
3098 TCollection_AsciiString aFlag (anArg);
3100 if (aFlag == "-mousestart"
3101 || aFlag == "-mousefrom")
3103 hasFlags = Standard_True;
3104 if (anArgIter + 2 >= theArgNb)
3106 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3110 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3111 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3112 aView->StartRotation (anX, anY);
3114 else if (aFlag == "-mousemove")
3116 hasFlags = Standard_True;
3117 if (anArgIter + 2 >= theArgNb)
3119 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3123 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3124 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3125 aView->Rotation (anX, anY);
3127 else if (theArgNb != 4
3130 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3139 else if (theArgNb == 4)
3141 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3142 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3143 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3144 aView->Rotate (anAX, anAY, anAZ);
3147 else if (theArgNb == 7)
3149 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3150 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3151 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3153 Standard_Real anX = Draw::Atof (theArgVec[4]);
3154 Standard_Real anY = Draw::Atof (theArgVec[5]);
3155 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3157 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3161 std::cout << "Error: Invalid number of arguments\n";
3165 //==============================================================================
3167 //purpose : View zoom in / out (relative to current zoom)
3168 //==============================================================================
3170 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3171 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3172 if ( V3dView.IsNull() ) {
3177 Standard_Real coef = Draw::Atof(argv[1]);
3178 if ( coef <= 0.0 ) {
3179 di << argv[1] << "Invalid value" << "\n";
3182 V3dView->SetZoom( Draw::Atof(argv[1]) );
3185 di << argv[0] << " Invalid number of arguments" << "\n";
3190 //==============================================================================
3192 //purpose : View panning (in pixels)
3193 //==============================================================================
3195 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3196 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3197 if ( V3dView.IsNull() ) return 1;
3200 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
3203 di << argv[0] << " Invalid number of arguments" << "\n";
3208 //==============================================================================
3210 //purpose : Place the point (in pixels) at the center of the window
3211 //==============================================================================
3212 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3214 Handle(V3d_View) aView = ViewerTest::CurrentView();
3217 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3223 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3227 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3232 //==============================================================================
3233 //function : VExport
3234 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
3235 //==============================================================================
3237 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3239 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3240 if (V3dView.IsNull())
3245 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
3249 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
3250 TCollection_AsciiString aFormatStr;
3252 TCollection_AsciiString aFileName (argv[1]);
3253 Standard_Integer aLen = aFileName.Length();
3257 aFormatStr = TCollection_AsciiString (argv[2]);
3261 if (aFileName.Value (aLen - 2) == '.')
3263 aFormatStr = aFileName.SubString (aLen - 1, aLen);
3265 else if (aFileName.Value (aLen - 3) == '.')
3267 aFormatStr = aFileName.SubString (aLen - 2, aLen);
3271 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3277 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3281 aFormatStr.UpperCase();
3282 if (aFormatStr == "PS")
3283 anExpFormat = Graphic3d_EF_PostScript;
3284 else if (aFormatStr == "EPS")
3285 anExpFormat = Graphic3d_EF_EnhPostScript;
3286 else if (aFormatStr == "TEX")
3287 anExpFormat = Graphic3d_EF_TEX;
3288 else if (aFormatStr == "PDF")
3289 anExpFormat = Graphic3d_EF_PDF;
3290 else if (aFormatStr == "SVG")
3291 anExpFormat = Graphic3d_EF_SVG;
3292 else if (aFormatStr == "PGF")
3293 anExpFormat = Graphic3d_EF_PGF;
3294 else if (aFormatStr == "EMF")
3295 anExpFormat = Graphic3d_EF_EMF;
3298 std::cout << "Invalid export format '" << aFormatStr << "'\n";
3303 if (!V3dView->View()->Export (argv[1], anExpFormat))
3305 di << "Error: export of image to " << aFormatStr << " failed!\n";
3308 catch (Standard_Failure)
3310 di << "Error: export of image to " << aFormatStr << " failed";
3311 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
3316 //==============================================================================
3317 //function : VColorScale
3318 //purpose : representation color scale
3319 //==============================================================================
3321 static Standard_Boolean checkColor (const TCollection_AsciiString& theRed,
3322 const TCollection_AsciiString& theGreen,
3323 const TCollection_AsciiString& theBlue,
3324 Standard_Real& theRedValue,
3325 Standard_Real& theGreenValue,
3326 Standard_Real& theBlueValue)
3328 if (!theRed.IsRealValue()
3329 || !theGreen.IsRealValue()
3330 || !theBlue.IsRealValue())
3332 std::cout << "Error: RGB color values should be real!\n";
3333 return Standard_True;
3335 theRedValue = theRed .RealValue();
3336 theGreenValue = theGreen.RealValue();
3337 theBlueValue = theBlue .RealValue();
3338 if (theRedValue < 0.0 || theRedValue > 1.0
3339 || theGreenValue < 0.0 || theGreenValue > 1.0
3340 || theBlueValue < 0.0 || theBlueValue > 1.0)
3342 std::cout << "Error: RGB color values should be within range 0..1!\n";
3343 return Standard_True;
3345 return Standard_False;
3348 static int VColorScale (Draw_Interpretor& theDI,
3349 Standard_Integer theArgNb,
3350 const char** theArgVec)
3352 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3353 Handle(V3d_View) aView = ViewerTest::CurrentView();
3354 if (aContext.IsNull())
3356 std::cout << "Error: no active view!\n";
3360 Handle(V3d_ColorScale) aCS = Handle(V3d_ColorScale)::DownCast (aView->ColorScale());
3363 std::cout << "Error: color scale is undefined!\n";
3367 Standard_Real aMinRange = aCS->GetMin();
3368 Standard_Real aMaxRange = aCS->GetMax();
3369 Standard_Integer aNbIntervals = aCS->GetNumberOfIntervals();
3370 Standard_Integer aTextHeight = aCS->GetTextHeight();
3371 Aspect_TypeOfColorScalePosition aLabPosition = aCS->GetLabelPosition();
3372 gp_XY aPos (aCS->GetXPosition(), aCS->GetYPosition());
3374 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
3378 theDI << "Current color scale parameters:\n"
3379 << "Min range: " << aMinRange << "\n"
3380 << "Max range: " << aMaxRange << "\n"
3381 << "Number of intervals: " << aNbIntervals << "\n"
3382 << "Text height: " << aTextHeight << "\n"
3383 << "Color scale position: " << aPos.X() <<" "<< aPos.Y()<< "\n"
3384 << "Color scale title: " << aCS->GetTitle() << "\n"
3385 << "Label position: ";
3386 switch (aLabPosition)
3388 case Aspect_TOCSP_NONE:
3391 case Aspect_TOCSP_LEFT:
3394 case Aspect_TOCSP_RIGHT:
3397 case Aspect_TOCSP_CENTER:
3398 theDI << "Center\n";
3403 Standard_CString aFirstArg = theArgVec[1];
3404 TCollection_AsciiString aFlag (aFirstArg);
3406 if (aFlag == "-hide" ||
3411 std::cout << "Error: wrong syntax at argument '" << theArgVec[1] << "'!\n";
3414 if (!aView->ColorScaleIsDisplayed())
3416 std::cout << "Error: color scale is not displayed!\n";
3421 aView->ColorScaleErase();
3425 else if (aFlag == "-show" ||
3426 aFlag == "-display")
3430 std::cout << "Error: wrong syntax at argument '" << theArgVec[1] << "'!\n";
3433 aView->ColorScaleDisplay();
3437 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3439 Standard_CString anArg = theArgVec[anArgIter];
3440 TCollection_AsciiString aFlag (anArg);
3442 if (anUpdateTool.parseRedrawMode (aFlag))
3446 else if (aFlag == "-range")
3448 if (anArgIter + 3 >= theArgNb)
3450 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3454 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
3455 TCollection_AsciiString anArg2 (theArgVec[++anArgIter]);
3456 TCollection_AsciiString anArg3 (theArgVec[++anArgIter]);
3457 if (!anArg1.IsRealValue())
3459 std::cout << "Error: the minRange value should be real!\n";
3462 else if (!anArg2.IsRealValue())
3464 std::cout << "Error: the maxRange value should be real!\n";
3467 else if (!anArg3.IsIntegerValue())
3469 std::cout << "Error: the number of intervals should be integer!\n";
3473 aMinRange = anArg1.RealValue();
3474 aMaxRange = anArg2.RealValue();
3475 aNbIntervals = anArg3.IntegerValue();
3477 else if (aFlag == "-font")
3479 if (anArgIter + 1 >= theArgNb)
3481 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3484 TCollection_AsciiString anArg (theArgVec[anArgIter + 1]);
3485 if (!anArg.IsIntegerValue())
3487 std::cout << "Error: HeightFont value should be integer!\n";
3491 aTextHeight = anArg.IntegerValue();
3494 else if (aFlag == "-textpos")
3496 if (anArgIter + 1 >= theArgNb)
3498 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3501 TCollection_AsciiString anArg (theArgVec[++anArgIter]);
3503 if (anArg == "none")
3505 aLabPosition = Aspect_TOCSP_NONE;
3507 else if (anArg == "left")
3509 aLabPosition = Aspect_TOCSP_LEFT;
3511 else if (anArg == "right")
3513 aLabPosition = Aspect_TOCSP_RIGHT;
3515 else if (anArg == "center")
3517 aLabPosition = Aspect_TOCSP_CENTER;
3521 std::cout << "Error: unknown position '" << anArg << "'!\n";
3525 else if (aFlag == "-xy")
3527 if (anArgIter + 2 >= theArgNb)
3529 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3533 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3534 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3535 if (!aX.IsRealValue()
3536 || !aY.IsRealValue())
3538 std::cout << "Error: coordinates should be real values!\n";
3542 aPos.SetCoord (aX.RealValue(), aY.RealValue());
3544 else if (aFlag == "-color")
3546 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3548 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3552 Quantity_NameOfColor aColorName;
3553 if (anArgIter + 4 >= theArgNb)
3555 if (anArgIter + 2 >= theArgNb)
3557 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3560 else if (!Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3562 std::cout << "Error: wrong color name: '" << theArgVec[anArgIter + 2] << "' !\n";
3567 TCollection_AsciiString anInd (theArgVec[anArgIter + 1]);
3568 if (!anInd.IsIntegerValue())
3570 std::cout << "Error: Index value should be integer!\n";
3574 Standard_Integer anIndex = anInd.IntegerValue();
3576 || anIndex > aNbIntervals - 1)
3578 std::cout << "Error: Index value should be within range 0..." << (aNbIntervals - 1) <<"!\n";
3582 if (Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3584 aCS->SetColor (Quantity_Color (aColorName), anIndex);
3585 aCS->SetColorType(Aspect_TOCSD_USER);
3590 TCollection_AsciiString aRed (theArgVec[anArgIter + 2]);
3591 TCollection_AsciiString aGreen (theArgVec[anArgIter + 3]);
3592 TCollection_AsciiString aBlue (theArgVec[anArgIter + 4]);
3593 Standard_Real aRedValue,aGreenValue, aBlueValue;
3594 if(checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3598 aCS->SetColor (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB), anIndex);
3599 aCS->SetColorType (Aspect_TOCSD_USER);
3602 else if (aFlag == "-label")
3604 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3606 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
3609 else if (anArgIter + 2 >= theArgNb)
3611 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3615 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
3617 || anIndex > aNbIntervals)
3619 std::cout << "Error: Index value should be within range 0..." << aNbIntervals <<"!\n";
3623 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
3624 aCS->SetLabel (aText, anIndex);
3625 aCS->SetLabelType (Aspect_TOCSD_USER);
3628 else if (aFlag == "-colors")
3630 Aspect_SequenceOfColor aSeq;
3631 if (anArgIter + aNbIntervals + 1 > theArgNb)
3633 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3634 << aNbIntervals << " intervals\n";
3638 Standard_Integer aColorIter = anArgIter + 1;
3639 while (aColorIter < theArgNb)
3641 if (theArgVec[aColorIter][0] == '-')
3646 else if (theArgVec[aColorIter][0] >= 97
3647 && theArgVec[aColorIter][0] <= 122)
3649 Quantity_NameOfColor aColorName;
3650 if (!Quantity_Color::ColorFromName (theArgVec[aColorIter], aColorName))
3652 std::cout << "Error: wrong color name: " << theArgVec[aColorIter] << " !\n";
3655 aSeq.Append (Quantity_Color (aColorName));
3661 TCollection_AsciiString aRed (theArgVec[aColorIter]);
3662 TCollection_AsciiString aGreen (theArgVec[aColorIter + 1]);
3663 TCollection_AsciiString aBlue (theArgVec[aColorIter + 2]);
3664 Standard_Real aRedValue,aGreenValue, aBlueValue;
3665 if (checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3669 aSeq.Append (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB));
3674 if (aSeq.Length() < aNbIntervals)
3676 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3677 << aNbIntervals << " intervals\n";
3681 aCS->SetColors (aSeq);
3682 aCS->SetColorType (Aspect_TOCSD_USER);
3684 else if (aFlag == "-labels")
3686 if (anArgIter + aNbIntervals + 1 >= theArgNb)
3688 std::cout << "Error: not enough arguments! You should provide " << (aNbIntervals + 1)
3689 << " text labels for " << aNbIntervals << " intervals.\n";
3693 TColStd_SequenceOfExtendedString aSeq;
3694 for (int aLabelIter = anArgIter + 1; aLabelIter <= anArgIter + aNbIntervals + 1; aLabelIter += 1)
3696 aSeq.Append (TCollection_ExtendedString (theArgVec[aLabelIter]));
3698 aCS->SetLabels (aSeq);
3699 aCS->SetLabelType (Aspect_TOCSD_USER);
3700 anArgIter += aSeq.Length();
3702 else if (aFlag == "-title")
3704 if (anArgIter + 1 >= theArgNb)
3706 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3710 Standard_Boolean isTwoArgs = Standard_False;
3711 if (anArgIter + 2 < theArgNb)
3713 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
3714 aSecondArg.LowerCase();
3715 if (aSecondArg == "none")
3717 aCS->SetTitlePosition (Aspect_TOCSP_NONE);
3718 isTwoArgs = Standard_True;
3720 else if (aSecondArg == "left")
3722 aCS->SetTitlePosition (Aspect_TOCSP_LEFT);
3723 isTwoArgs = Standard_True;
3725 else if (aSecondArg == "right")
3727 aCS->SetTitlePosition (Aspect_TOCSP_RIGHT);
3728 isTwoArgs = Standard_True;
3730 else if (aSecondArg == "center")
3732 aCS->SetTitlePosition (Aspect_TOCSP_CENTER);
3733 isTwoArgs = Standard_True;
3737 aCS->SetTitle (theArgVec[anArgIter + 1]);
3744 else if (aFlag == "-demoversion"
3745 || aFlag == "-demo")
3747 aPos.SetCoord (0.0, 0.0);
3752 aLabPosition = Aspect_TOCSP_RIGHT;
3753 aCS->SetColorType(Aspect_TOCSD_AUTO);
3754 aCS->SetLabelType(Aspect_TOCSD_AUTO);
3758 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
3763 aCS->SetPosition (aPos.X(), aPos.Y());
3764 aCS->SetHeight (0.95);
3765 aCS->SetTextHeight (aTextHeight);
3766 aCS->SetRange (aMinRange, aMaxRange);
3767 aCS->SetNumberOfIntervals (aNbIntervals);
3768 aCS->SetLabelPosition (aLabPosition);
3770 if (!aView->ColorScaleIsDisplayed())
3772 aView->ColorScaleDisplay();
3778 //==============================================================================
3779 //function : VGraduatedTrihedron
3780 //purpose : Displays or hides a graduated trihedron
3781 //==============================================================================
3782 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
3783 Quantity_Color& theColor)
3785 Quantity_NameOfColor aColorName;
3786 TCollection_AsciiString aVal = theValue;
3788 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
3790 return Standard_False;
3792 theColor = Quantity_Color (aColorName);
3793 return Standard_True;
3796 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
3800 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
3801 << theArgs[0] <<"' for more information.\n";
3802 return 1; //TCL_ERROR
3805 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
3806 TCollection_AsciiString aParseKey;
3807 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
3809 TCollection_AsciiString anArg (theArgs [anArgIt]);
3811 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3814 aParseKey.Remove (1);
3815 aParseKey.LowerCase();
3816 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
3820 if (aParseKey.IsEmpty())
3825 aMapOfArgs(aParseKey)->Append (anArg);
3829 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
3830 aMapIt.More(); aMapIt.Next())
3832 const TCollection_AsciiString& aKey = aMapIt.Key();
3833 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
3835 // Bool key, without arguments
3836 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
3837 && anArgs->IsEmpty())
3843 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
3844 && anArgs->Length() == 1)
3850 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
3851 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
3852 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
3853 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
3854 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
3859 // One string argument
3860 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
3861 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
3862 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
3867 // One integer argument
3868 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
3869 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
3870 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
3871 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
3872 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
3877 // One real argument
3878 if ( aKey.IsEqual ("arrowlength")
3879 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
3884 // Two string arguments
3885 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
3886 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
3891 TCollection_AsciiString aLowerKey;
3894 aLowerKey.LowerCase();
3895 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3896 std::cout << "Type help for more information.\n";
3900 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3901 if (anAISContext.IsNull())
3903 std::cout << theArgs[0] << ": " << " please use 'vinit' command to initialize view.\n";
3907 Standard_Boolean toDisplay = Standard_True;
3908 Quantity_Color aColor;
3909 Graphic3d_GraduatedTrihedron aTrihedronData;
3910 // Process parameters
3911 Handle(TColStd_HSequenceOfAsciiString) aValues;
3912 if (aMapOfArgs.Find ("off", aValues))
3914 toDisplay = Standard_False;
3918 if (aMapOfArgs.Find ("xname", aValues))
3920 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
3922 if (aMapOfArgs.Find ("yname", aValues))
3924 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
3926 if (aMapOfArgs.Find ("zname", aValues))
3928 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
3930 if (aMapOfArgs.Find ("xdrawname", aValues))
3932 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
3934 if (aMapOfArgs.Find ("ydrawname", aValues))
3936 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
3938 if (aMapOfArgs.Find ("zdrawname", aValues))
3940 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
3942 if (aMapOfArgs.Find ("xnameoffset", aValues))
3944 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
3946 if (aMapOfArgs.Find ("ynameoffset", aValues))
3948 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
3950 if (aMapOfArgs.Find ("znameoffset", aValues))
3952 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
3956 if (aMapOfArgs.Find ("xnamecolor", aValues))
3958 if (!GetColor (aValues->Value(1), aColor))
3960 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
3963 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
3965 if (aMapOfArgs.Find ("ynamecolor", aValues))
3967 if (!GetColor (aValues->Value(1), aColor))
3969 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
3972 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
3974 if (aMapOfArgs.Find ("znamecolor", aValues))
3976 if (!GetColor (aValues->Value(1), aColor))
3978 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
3981 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
3983 if (aMapOfArgs.Find ("xcolor", aValues))
3985 if (!GetColor (aValues->Value(1), aColor))
3987 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
3990 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
3992 if (aMapOfArgs.Find ("ycolor", aValues))
3994 if (!GetColor (aValues->Value(1), aColor))
3996 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
3999 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
4001 if (aMapOfArgs.Find ("zcolor", aValues))
4003 if (!GetColor (aValues->Value(1), aColor))
4005 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
4008 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
4012 if (aMapOfArgs.Find ("xticks", aValues))
4014 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4016 if (aMapOfArgs.Find ("yticks", aValues))
4018 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4020 if (aMapOfArgs.Find ("zticks", aValues))
4022 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4024 if (aMapOfArgs.Find ("xticklength", aValues))
4026 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4028 if (aMapOfArgs.Find ("yticklength", aValues))
4030 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4032 if (aMapOfArgs.Find ("zticklength", aValues))
4034 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4036 if (aMapOfArgs.Find ("xdrawticks", aValues))
4038 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4040 if (aMapOfArgs.Find ("ydrawticks", aValues))
4042 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4044 if (aMapOfArgs.Find ("zdrawticks", aValues))
4046 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4050 if (aMapOfArgs.Find ("xdrawvalues", aValues))
4052 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4054 if (aMapOfArgs.Find ("ydrawvalues", aValues))
4056 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4058 if (aMapOfArgs.Find ("zdrawvalues", aValues))
4060 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4062 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
4064 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4066 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
4068 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4070 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
4072 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4076 if (aMapOfArgs.Find ("arrowlength", aValues))
4078 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
4082 if (aMapOfArgs.Find ("namefont", aValues))
4084 aTrihedronData.SetNamesFont (aValues->Value(1));
4086 if (aMapOfArgs.Find ("valuesfont", aValues))
4088 aTrihedronData.SetValuesFont (aValues->Value(1));
4091 if (aMapOfArgs.Find ("drawgrid", aValues))
4093 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
4095 if (aMapOfArgs.Find ("drawaxes", aValues))
4097 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
4100 // The final step: display of erase trihedron
4103 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
4107 ViewerTest::CurrentView()->GraduatedTrihedronErase();
4110 ViewerTest::GetAISContext()->UpdateCurrentViewer();
4111 ViewerTest::CurrentView()->Redraw();
4116 //==============================================================================
4117 //function : VPrintView
4118 //purpose : Test printing algorithm, print the view to image file with given
4119 // width and height. Printing implemented only for WNT.
4120 //==============================================================================
4121 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
4125 di << "Printing implemented only for wnt!\n";
4129 Handle(AIS_InteractiveContext) aContextAIS = NULL;
4130 Handle(V3d_View) aView = NULL;
4131 aContextAIS = ViewerTest::GetAISContext();
4132 if (!aContextAIS.IsNull())
4134 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
4135 Vwr->InitActiveViews();
4136 if(Vwr->MoreActiveViews())
4137 aView = Vwr->ActiveView();
4143 di << "Call vinit before!\n";
4148 di << "Use: " << argv[0];
4149 di << " width height filename [print algo=0] [tile_width tile_height]\n";
4150 di << "width, height of the intermediate buffer for operation\n";
4151 di << "algo : {0|1}\n";
4152 di << " 0 - stretch algorithm\n";
4153 di << " 1 - tile algorithm\n";
4154 di << "test printing algorithms into an intermediate buffer\n";
4155 di << "using specific tile size if provided\n";
4156 di << "with saving output to an image file\n";
4160 // get the input params
4161 Standard_Integer aWidth = Draw::Atoi (argv[1]);
4162 Standard_Integer aHeight = Draw::Atoi (argv[2]);
4163 Standard_Integer aMode = 0;
4164 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
4166 aMode = Draw::Atoi (argv[4]);
4168 Standard_Integer aTileWidth = 0;
4169 Standard_Integer aTileHeight = 0;
4170 Standard_Boolean isTileSizeProvided = Standard_False;
4173 isTileSizeProvided = Standard_True;
4174 aTileWidth = Draw::Atoi (argv[5]);
4175 aTileHeight = Draw::Atoi (argv[6]);
4178 // check the input parameters
4179 if (aWidth <= 0 || aHeight <= 0)
4181 di << "Width and height must be positive values!\n";
4184 if (aMode != 0 && aMode != 1)
4187 // define compatible bitmap
4188 HDC anDC = CreateCompatibleDC(0);
4189 BITMAPINFO aBitmapData;
4190 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
4191 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
4192 aBitmapData.bmiHeader.biWidth = aWidth ;
4193 aBitmapData.bmiHeader.biHeight = aHeight;
4194 aBitmapData.bmiHeader.biPlanes = 1;
4195 aBitmapData.bmiHeader.biBitCount = 24;
4196 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
4197 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
4198 aBitmapData.bmiHeader.biClrUsed = 0;
4199 aBitmapData.bmiHeader.biClrImportant = 0;
4200 aBitmapData.bmiHeader.biCompression = BI_RGB;
4201 aBitmapData.bmiHeader.biSizeImage = 0;
4203 // Create Device Independent Bitmap
4204 void* aBitsOut = NULL;
4205 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
4206 &aBitsOut, NULL, 0);
4207 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
4209 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
4210 if (aBitsOut != NULL)
4213 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
4216 if (isTileSizeProvided)
4218 Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView());
4219 Graphic3d_PtrFrameBuffer anOldBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO);
4220 aCView->ptrFBO = aView->View()->FBOCreate (aTileWidth, aTileHeight);
4222 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
4224 Graphic3d_PtrFrameBuffer aNewBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO);
4225 aView->View()->FBORelease (aNewBuffer);
4226 aCView->ptrFBO = anOldBuffer;
4230 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
4234 // succesfully printed into an intermediate buffer
4237 Image_PixMap aWrapper;
4238 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
4239 aWrapper.SetTopDown (false);
4241 Image_AlienPixMap anImageBitmap;
4242 anImageBitmap.InitCopy (aWrapper);
4243 isSaved = anImageBitmap.Save (aFileName);
4247 di << "Print operation failed due to printing errors or\n";
4248 di << "insufficient memory available\n";
4249 di << "Please, try to use smaller dimensions for this test\n";
4250 di << "command, as it allocates intermediate buffer for storing\n";
4251 di << "the result\n";
4256 di << "Can't allocate memory for intermediate buffer\n";
4257 di << "Please use smaller dimensions\n";
4262 SelectObject (anDC, anOldBitmap);
4263 DeleteObject (aMemoryBitmap);
4269 di << "Save to file operation failed. This operation may fail\n";
4270 di << "if you don't have enough available memory, then you can\n";
4271 di << "use smaller dimensions for the output file\n";
4280 //==============================================================================
4281 //function : VZLayer
4282 //purpose : Test z layer operations for v3d viewer
4283 //==============================================================================
4284 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4286 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
4287 if (aContextAIS.IsNull())
4289 di << "Call vinit before!\n";
4294 di << "Use: vzlayer ";
4295 di << " add/del/get/settings/enable/disable [id]\n";
4296 di << " add - add new z layer to viewer and print its id\n";
4297 di << " del - del z layer by its id\n";
4298 di << " get - print sequence of z layers in increasing order of their overlay level\n";
4299 di << " settings - print status of z layer settings\n";
4300 di << " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n";
4301 di << " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n";
4302 di << " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n";
4303 di << "\nWhere id is the layer identificator\n";
4304 di << "\nExamples:\n";
4305 di << " vzlayer add\n";
4306 di << " vzlayer enable poffset 1\n";
4307 di << " vzlayer disable depthtest 1\n";
4308 di << " vzlayer del 1\n";
4312 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
4313 if (aViewer.IsNull())
4315 di << "No active viewer!\n";
4319 // perform operation
4320 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
4323 Standard_Integer aNewId;
4324 if (!aViewer->AddZLayer (aNewId))
4326 di << "Impossible to add new z layer!\n";
4330 di << "New z layer added with index: " << aNewId << "\n";
4332 else if (anOp == "del")
4336 di << "Please also provide as argument id of z layer to remove\n";
4340 Standard_Integer aDelId = Draw::Atoi (argv[2]);
4341 if (!aViewer->RemoveZLayer (aDelId))
4343 di << "Impossible to remove the z layer or invalid id!\n";
4347 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4348 anObjIter.More(); anObjIter.Next())
4350 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1());
4352 || aPrs->ZLayer() != aDelId)
4356 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4359 di << "Z layer " << aDelId << " has been removed\n";
4361 else if (anOp == "get")
4363 TColStd_SequenceOfInteger anIds;
4364 aViewer->GetAllZLayers (anIds);
4365 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
4367 di << anIds.Value (aSeqIdx) << " ";
4372 else if (anOp == "settings")
4376 di << "Please also provide an id\n";
4380 Standard_Integer anId = Draw::Atoi (argv[2]);
4381 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4383 di << "Depth test - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthTest) ? "enabled" : "disabled") << "\n";
4384 di << "Depth write - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthWrite) ? "enabled" : "disabled") << "\n";
4385 di << "Depth buffer clearing - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthClear) ? "enabled" : "disabled") << "\n";
4386 di << "Depth offset - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthOffset) ? "enabled" : "disabled") << "\n";
4389 else if (anOp == "enable")
4393 di << "Please also provide an option to enable\n";
4399 di << "Please also provide a layer id\n";
4403 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
4404 Standard_Integer anId = Draw::Atoi (argv[3]);
4405 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4407 if (aSubOp == "depthtest" || aSubOp == "test")
4409 aSettings.EnableSetting (Graphic3d_ZLayerDepthTest);
4411 else if (aSubOp == "depthwrite" || aSubOp == "write")
4413 aSettings.EnableSetting (Graphic3d_ZLayerDepthWrite);
4415 else if (aSubOp == "depthclear" || aSubOp == "clear")
4417 aSettings.EnableSetting (Graphic3d_ZLayerDepthClear);
4419 else if (aSubOp == "depthoffset" || aSubOp == "offset")
4423 di << "Please also provide a factor and units values for depth offset\n";
4424 di << "Format is: vzlayer enable offset [factor] [units] [layerId]\n";
4428 Standard_ShortReal aFactor = static_cast<Standard_ShortReal> (Draw::Atof (argv[3]));
4429 Standard_ShortReal aUnits = static_cast<Standard_ShortReal> (Draw::Atof (argv[4]));
4430 anId = Draw::Atoi (argv[5]);
4431 aSettings = aViewer->ZLayerSettings (anId);
4433 aSettings.DepthOffsetFactor = aFactor;
4434 aSettings.DepthOffsetUnits = aUnits;
4436 aSettings.EnableSetting (Graphic3d_ZLayerDepthOffset);
4438 else if (aSubOp == "positiveoffset" || aSubOp == "poffset")
4440 aSettings.SetDepthOffsetPositive();
4442 else if (aSubOp == "negativeoffset" || aSubOp == "noffset")
4444 aSettings.SetDepthOffsetNegative();
4447 aViewer->SetZLayerSettings (anId, aSettings);
4449 else if (anOp == "disable")
4453 di << "Please also provide an option to disable\n";
4459 di << "Please also provide a layer id\n";
4463 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
4464 Standard_Integer anId = Draw::Atoi (argv[3]);
4465 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4467 if (aSubOp == "depthtest" || aSubOp == "test")
4469 aSettings.DisableSetting (Graphic3d_ZLayerDepthTest);
4471 else if (aSubOp == "depthwrite" || aSubOp == "write")
4473 aSettings.DisableSetting (Graphic3d_ZLayerDepthWrite);
4475 else if (aSubOp == "depthclear" || aSubOp == "clear")
4477 aSettings.DisableSetting (Graphic3d_ZLayerDepthClear);
4479 else if (aSubOp == "depthoffset" || aSubOp == "offset")
4481 aSettings.DisableSetting (Graphic3d_ZLayerDepthOffset);
4484 aViewer->SetZLayerSettings (anId, aSettings);
4488 di << "Invalid operation, please use { add / del / get / settings / enable / disable}\n";
4495 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
4497 // this class provides a presentation of text item in v3d view under-/overlayer
4498 class V3d_TextItem : public Visual3d_LayerItem
4503 DEFINE_STANDARD_RTTI(V3d_TextItem)
4506 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
4507 const Standard_Real theX1,
4508 const Standard_Real theY1,
4509 const Standard_Real theHeight,
4510 const TCollection_AsciiString& theFontName,
4511 const Quantity_Color& theColor,
4512 const Quantity_Color& theSubtitleColor,
4513 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
4514 const Handle(Visual3d_Layer)& theLayer);
4517 Standard_EXPORT void RedrawLayerPrs();
4523 TCollection_AsciiString myText;
4524 Standard_Real myHeight;
4525 Handle(Visual3d_Layer) myLayer;
4526 Quantity_Color myColor;
4527 Quantity_Color mySubtitleColor;
4528 Aspect_TypeOfDisplayText myType;
4529 TCollection_AsciiString myFontName;
4532 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
4533 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
4535 // create and add to display the text item
4536 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
4537 const Standard_Real theX1,
4538 const Standard_Real theY1,
4539 const Standard_Real theHeight,
4540 const TCollection_AsciiString& theFontName,
4541 const Quantity_Color& theColor,
4542 const Quantity_Color& theSubtitleColor,
4543 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
4544 const Handle(Visual3d_Layer)& theLayer)
4545 : myX1 (theX1), myY1 (theY1),
4547 myHeight (theHeight),
4550 mySubtitleColor (theSubtitleColor),
4551 myType (theTypeOfDisplay),
4552 myFontName (theFontName)
4554 if (!myLayer.IsNull ())
4555 myLayer->AddLayerItem (this);
4559 void V3d_TextItem::RedrawLayerPrs ()
4561 if (myLayer.IsNull ())
4564 myLayer->SetColor (myColor);
4565 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
4566 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
4569 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
4571 // The Visual3d_LayerItem line item for "vlayerline" command
4572 // it provides a presentation of line with user-defined
4573 // linewidth, linetype and transparency.
4574 class V3d_LineItem : public Visual3d_LayerItem
4578 DEFINE_STANDARD_RTTI(V3d_LineItem)
4581 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4582 Standard_Real X2, Standard_Real Y2,
4583 V3d_LayerMgrPointer theLayerMgr,
4584 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
4585 Standard_Real theWidth = 0.5,
4586 Standard_Real theTransp = 1.0);
4589 Standard_EXPORT void RedrawLayerPrs();
4593 Standard_Real myX1, myY1, myX2, myY2;
4594 V3d_LayerMgrPointer myLayerMgr;
4595 Aspect_TypeOfLine myType;
4596 Standard_Real myWidth;
4597 Standard_Real myTransparency;
4600 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
4601 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
4603 // default constructor for line item
4604 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4605 Standard_Real X2, Standard_Real Y2,
4606 V3d_LayerMgrPointer theLayerMgr,
4607 Aspect_TypeOfLine theType,
4608 Standard_Real theWidth,
4609 Standard_Real theTransp) :
4610 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
4611 myType(theType), myWidth(theWidth), myTransparency(theTransp)
4613 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
4614 myLayerMgr->Overlay()->AddLayerItem (this);
4618 void V3d_LineItem::RedrawLayerPrs ()
4620 Handle (Visual3d_Layer) aOverlay;
4623 aOverlay = myLayerMgr->Overlay();
4625 if (!aOverlay.IsNull())
4627 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
4628 aOverlay->SetColor(aColor);
4629 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
4630 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
4631 aOverlay->BeginPolyline();
4632 aOverlay->AddVertex(myX1, myY1);
4633 aOverlay->AddVertex(myX2, myY2);
4634 aOverlay->ClosePrimitive();
4638 //=============================================================================
4639 //function : VLayerLine
4640 //purpose : Draws line in the v3d view layer with given attributes: linetype,
4641 // : linewidth, transparency coefficient
4642 //============================================================================
4643 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4645 // get the active view
4646 Handle(V3d_View) aView = ViewerTest::CurrentView();
4649 di << "Call vinit before!\n";
4654 di << "Use: " << argv[0];
4655 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
4656 di << " linetype : { 0 | 1 | 2 | 3 } \n";
4657 di << " 0 - solid \n";
4658 di << " 1 - dashed \n";
4659 di << " 2 - dot \n";
4660 di << " 3 - dashdot\n";
4661 di << " transparency : { 0.0 - 1.0 } \n";
4662 di << " 0.0 - transparent\n";
4663 di << " 1.0 - visible \n";
4667 // get the input params
4668 Standard_Real X1 = Draw::Atof(argv[1]);
4669 Standard_Real Y1 = Draw::Atof(argv[2]);
4670 Standard_Real X2 = Draw::Atof(argv[3]);
4671 Standard_Real Y2 = Draw::Atof(argv[4]);
4673 Standard_Real aWidth = 0.5;
4674 Standard_Integer aType = 0;
4675 Standard_Real aTransparency = 1.0;
4679 aWidth = Draw::Atof(argv[5]);
4683 aType = (Standard_Integer) Draw::Atoi(argv[6]);
4688 aTransparency = Draw::Atof(argv[7]);
4689 if (aTransparency < 0 || aTransparency > 1.0)
4690 aTransparency = 1.0;
4693 // select appropriate line type
4694 Aspect_TypeOfLine aLineType;
4698 aLineType = Aspect_TOL_DASH;
4702 aLineType = Aspect_TOL_DOT;
4706 aLineType = Aspect_TOL_DOTDASH;
4710 aLineType = Aspect_TOL_SOLID;
4713 // replace layer manager
4714 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
4715 aView->SetLayerMgr(aMgr);
4718 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
4724 aView->MustBeResized();
4730 //=======================================================================
4731 //function : VOverlayText
4732 //purpose : Test text displaying in view overlay
4733 //=======================================================================
4734 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
4736 // get the active view
4737 Handle(V3d_View) aView = ViewerTest::CurrentView();
4740 di << "No active view. Please call vinit.\n";
4743 else if (argc < 4 || argc > 13)
4745 di << "Use: " << argv[0];
4746 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
4747 di << "[background_color: R G B]\n";
4748 di << " height - pixel height of the text (default=10.0)\n";
4749 di << " font_name - name of font (default=courier)\n";
4750 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
4751 di << " display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n";
4752 di << " background_color- R G B values used for subtitle and decal text\n";
4753 di << "(default=255.0 255.0 255.0)\n";
4757 TCollection_AsciiString aText (argv[1]);
4758 Standard_Real aPosX = Draw::Atof(argv[2]);
4759 Standard_Real aPosY = Draw::Atof(argv[3]);
4760 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
4763 TCollection_AsciiString aFontName = "Courier";
4765 aFontName = TCollection_AsciiString (argv[5]);
4768 Quantity_Parameter aColorRed = 1.0;
4769 Quantity_Parameter aColorGreen = 1.0;
4770 Quantity_Parameter aColorBlue = 1.0;
4773 aColorRed = Draw::Atof (argv[6])/255.;
4774 aColorGreen = Draw::Atof (argv[7])/255.;
4775 aColorBlue = Draw::Atof (argv[8])/255.;
4779 TCollection_AsciiString aDispStr;
4781 aDispStr = TCollection_AsciiString (argv[9]);
4783 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
4784 if (aDispStr.IsEqual ("subtitle"))
4785 aTextType = Aspect_TODT_SUBTITLE;
4786 else if (aDispStr.IsEqual ("decal"))
4787 aTextType = Aspect_TODT_DEKALE;
4788 else if (aDispStr.IsEqual ("blend"))
4789 aTextType = Aspect_TODT_BLEND;
4790 else if (aDispStr.IsEqual ("dimension"))
4791 aTextType = Aspect_TODT_DIMENSION;
4794 Quantity_Parameter aSubRed = 1.0;
4795 Quantity_Parameter aSubGreen = 1.0;
4796 Quantity_Parameter aSubBlue = 1.0;
4799 aSubRed = Draw::Atof (argv[10])/255.;
4800 aSubGreen = Draw::Atof (argv[11])/255.;
4801 aSubBlue = Draw::Atof (argv[12])/255.;
4804 // check fo current overlay
4805 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
4806 if (anOverlay.IsNull ())
4808 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
4809 anOverlay = aMgr->Overlay ();
4810 aView->SetLayerMgr (aMgr);
4813 Quantity_Color aTextColor (aColorRed, aColorGreen,
4814 aColorBlue, Quantity_TOC_RGB);
4815 Quantity_Color aSubtColor (aSubRed, aSubGreen,
4816 aSubBlue, Quantity_TOC_RGB);
4819 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
4820 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
4823 aView->MustBeResized();
4829 //==============================================================================
4832 //==============================================================================
4834 static int VGrid (Draw_Interpretor& /*theDI*/,
4835 Standard_Integer theArgNb,
4836 const char** theArgVec)
4838 // get the active view
4839 Handle(V3d_View) aView = ViewerTest::CurrentView();
4840 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4841 if (aView.IsNull() || aViewer.IsNull())
4843 std::cerr << "No active view. Please call vinit.\n";
4847 Aspect_GridType aType = aViewer->GridType();
4848 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
4850 Standard_Integer anIter = 1;
4851 for (; anIter < theArgNb; ++anIter)
4853 const char* aValue = theArgVec[anIter];
4856 aType = Aspect_GT_Rectangular;
4858 else if (*aValue == 'c')
4860 aType = Aspect_GT_Circular;
4862 else if (*aValue == 'l')
4864 aMode = Aspect_GDM_Lines;
4866 else if (*aValue == 'p')
4868 aMode = Aspect_GDM_Points;
4870 else if (strcmp (aValue, "off" ) == 0)
4872 aViewer->DeactivateGrid();
4881 Standard_Integer aTail = (theArgNb - anIter);
4884 aViewer->ActivateGrid (aType, aMode);
4887 else if (aTail != 2 && aTail != 5)
4889 std::cerr << "Incorrect arguments number! Usage:\n"
4890 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
4894 Quantity_Length anOriginX, anOriginY;
4895 Quantity_PlaneAngle aRotAngle;
4896 if (aType == Aspect_GT_Rectangular)
4898 Quantity_Length aRStepX, aRStepY;
4899 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4901 anOriginX = Draw::Atof (theArgVec[anIter++]);
4902 anOriginY = Draw::Atof (theArgVec[anIter++]);
4905 aRStepX = Draw::Atof (theArgVec[anIter++]);
4906 aRStepY = Draw::Atof (theArgVec[anIter++]);
4907 aRotAngle = Draw::Atof (theArgVec[anIter++]);
4909 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4910 aViewer->ActivateGrid (aType, aMode);
4912 else if (aType == Aspect_GT_Circular)
4914 Quantity_Length aRadiusStep;
4915 Standard_Integer aDivisionNumber;
4916 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
4918 anOriginX = Draw::Atof (theArgVec[anIter++]);
4919 anOriginY = Draw::Atof (theArgVec[anIter++]);
4922 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
4923 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
4924 aRotAngle = Draw::Atof (theArgVec[anIter++]);
4927 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
4928 aViewer->ActivateGrid (aType, aMode);
4934 //==============================================================================
4935 //function : VPriviledgedPlane
4937 //==============================================================================
4939 static int VPriviledgedPlane (Draw_Interpretor& theDI,
4940 Standard_Integer theArgNb,
4941 const char** theArgVec)
4943 if (theArgNb != 1 && theArgNb != 7 && theArgNb != 10)
4945 std::cerr << "Error: wrong number of arguments! See usage:\n";
4946 theDI.PrintHelp (theArgVec[0]);
4950 // get the active viewer
4951 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4952 if (aViewer.IsNull())
4954 std::cerr << "Error: no active viewer. Please call vinit.\n";
4960 gp_Ax3 aPriviledgedPlane = aViewer->PrivilegedPlane();
4961 const gp_Pnt& anOrig = aPriviledgedPlane.Location();
4962 const gp_Dir& aNorm = aPriviledgedPlane.Direction();
4963 const gp_Dir& aXDir = aPriviledgedPlane.XDirection();
4964 theDI << "Origin: " << anOrig.X() << " " << anOrig.Y() << " " << anOrig.Z() << " "
4965 << "Normal: " << aNorm.X() << " " << aNorm.Y() << " " << aNorm.Z() << " "
4966 << "X-dir: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
4970 Standard_Integer anArgIdx = 1;
4971 Standard_Real anOrigX = Draw::Atof (theArgVec[anArgIdx++]);
4972 Standard_Real anOrigY = Draw::Atof (theArgVec[anArgIdx++]);
4973 Standard_Real anOrigZ = Draw::Atof (theArgVec[anArgIdx++]);
4974 Standard_Real aNormX = Draw::Atof (theArgVec[anArgIdx++]);
4975 Standard_Real aNormY = Draw::Atof (theArgVec[anArgIdx++]);
4976 Standard_Real aNormZ = Draw::Atof (theArgVec[anArgIdx++]);
4978 gp_Ax3 aPriviledgedPlane;
4979 gp_Pnt anOrig (anOrigX, anOrigY, anOrigZ);
4980 gp_Dir aNorm (aNormX, aNormY, aNormZ);
4983 Standard_Real aXDirX = Draw::Atof (theArgVec[anArgIdx++]);
4984 Standard_Real aXDirY = Draw::Atof (theArgVec[anArgIdx++]);
4985 Standard_Real aXDirZ = Draw::Atof (theArgVec[anArgIdx++]);
4986 gp_Dir aXDir (aXDirX, aXDirY, aXDirZ);
4987 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm, aXDir);
4991 aPriviledgedPlane = gp_Ax3 (anOrig, aNorm);
4994 aViewer->SetPrivilegedPlane (aPriviledgedPlane);
4999 //==============================================================================
5000 //function : VConvert
5002 //==============================================================================
5004 static int VConvert (Draw_Interpretor& theDI,
5005 Standard_Integer theArgNb,
5006 const char** theArgVec)
5008 // get the active view
5009 Handle(V3d_View) aView = ViewerTest::CurrentView();
5012 std::cerr << "Error: no active view. Please call vinit.\n";
5016 enum { Model, Ray, View, Window, Grid } aMode = Model;
5018 // access coordinate arguments
5019 TColStd_SequenceOfReal aCoord;
5020 Standard_Integer anArgIdx = 1;
5021 for (; anArgIdx < 4 && anArgIdx < theArgNb; ++anArgIdx)
5023 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5024 if (!anArg.IsRealValue())
5028 aCoord.Append (anArg.RealValue());
5031 // non-numeric argument too early
5032 if (aCoord.IsEmpty())
5034 std::cerr << "Error: wrong number of arguments! See usage:\n";
5035 theDI.PrintHelp (theArgVec[0]);
5039 // collect all other arguments and options
5040 for (; anArgIdx < theArgNb; ++anArgIdx)
5042 TCollection_AsciiString anArg (theArgVec[anArgIdx]);
5044 if (anArg == "window") aMode = Window;
5045 else if (anArg == "view") aMode = View;
5046 else if (anArg == "grid") aMode = Grid;
5047 else if (anArg == "ray") aMode = Ray;
5050 std::cerr << "Error: wrong argument " << anArg << "! See usage:\n";
5051 theDI.PrintHelp (theArgVec[0]);
5056 // complete input checks
5057 if ((aCoord.Length() == 1 && theArgNb > 3) ||
5058 (aCoord.Length() == 2 && theArgNb > 4) ||
5059 (aCoord.Length() == 3 && theArgNb > 5))
5061 std::cerr << "Error: wrong number of arguments! See usage:\n";
5062 theDI.PrintHelp (theArgVec[0]);
5066 Standard_Real aXYZ[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
5067 Standard_Integer aXYp[2] = {0, 0};
5069 // convert one-dimensional coordinate
5070 if (aCoord.Length() == 1)
5074 case View : theDI << "View Vv: " << aView->Convert ((Standard_Integer) aCoord (1)); return 0;
5075 case Window : theDI << "Window Vp: " << aView->Convert ((Quantity_Length) aCoord (1)); return 0;
5077 std::cerr << "Error: wrong arguments! See usage:\n";
5078 theDI.PrintHelp (theArgVec[0]);
5083 // convert 2D coordinates from projection or view reference space
5084 if (aCoord.Length() == 2)
5089 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5090 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5094 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1]);
5095 theDI << "View Xv,Yv: " << aXYZ[0] << " " << aXYZ[1] << "\n";
5099 aView->Convert ((V3d_Coordinate) aCoord (1), (V3d_Coordinate) aCoord (2), aXYp[0], aXYp[1]);
5100 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5104 aView->Convert ((Standard_Integer) aCoord (1), (Standard_Integer) aCoord (2), aXYZ[0], aXYZ[1], aXYZ[2]);
5105 aView->ConvertToGrid (aXYZ[0], aXYZ[1], aXYZ[2], aXYZ[3], aXYZ[4], aXYZ[5]);
5106 theDI << "Model X,Y,Z: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5110 aView->ConvertWithProj ((Standard_Integer) aCoord (1),
5111 (Standard_Integer) aCoord (2),
5112 aXYZ[0], aXYZ[1], aXYZ[2],
5113 aXYZ[3], aXYZ[4], aXYZ[5]);
5114 theDI << "Model DX,DY,DZ: " << aXYZ[3] << " " << aXYZ[4] << " " << aXYZ[5] << "\n";
5118 std::cerr << "Error: wrong arguments! See usage:\n";
5119 theDI.PrintHelp (theArgVec[0]);
5124 // convert 3D coordinates from view reference space
5125 else if (aCoord.Length() == 3)
5130 aView->Convert (aCoord (1), aCoord (2), aCoord (3), aXYp[0], aXYp[1]);
5131 theDI << "Window Xp,Yp: " << aXYp[0] << " " << aXYp[1] << "\n";
5135 aView->ConvertToGrid (aCoord (1), aCoord (2), aCoord (3), aXYZ[0], aXYZ[1], aXYZ[2]);
5136 theDI << "Model X,Y,Z: " << aXYZ[0] << " " << aXYZ[1] << " " << aXYZ[2] << "\n";
5140 std::cerr << "Error: wrong arguments! See usage:\n";
5141 theDI.PrintHelp (theArgVec[0]);
5149 //==============================================================================
5152 //==============================================================================
5154 static int VFps (Draw_Interpretor& theDI,
5155 Standard_Integer theArgNb,
5156 const char** theArgVec)
5158 // get the active view
5159 Handle(V3d_View) aView = ViewerTest::CurrentView();
5162 std::cerr << "No active view. Please call vinit.\n";
5166 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
5169 std::cerr << "Incorrect arguments!\n";
5173 // the time is meaningless for first call
5174 // due to async OpenGl rendering
5177 // redraw view in loop to estimate average values
5180 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
5186 const Standard_Real aTime = aTimer.ElapsedTime();
5187 aTimer.OSD_Chronometer::Show (aCpu);
5189 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
5190 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
5192 // return statistics
5193 theDI << "FPS: " << aFpsAver << "\n"
5194 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
5199 //==============================================================================
5200 //function : VGlDebug
5202 //==============================================================================
5204 static int VGlDebug (Draw_Interpretor& theDI,
5205 Standard_Integer theArgNb,
5206 const char** theArgVec)
5208 Handle(OpenGl_GraphicDriver) aDriver;
5209 Handle(V3d_View) aView = ViewerTest::CurrentView();
5210 if (!aView.IsNull())
5212 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5214 OpenGl_Caps* aDefCaps = &ViewerTest_myDefaultCaps;
5215 OpenGl_Caps* aCaps = !aDriver.IsNull() ? &aDriver->ChangeOptions() : NULL;
5219 TCollection_AsciiString aDebActive, aSyncActive;
5226 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )::glGetString (GL_EXTENSIONS),
5227 "GL_ARB_debug_output");
5228 aDebActive = isActive ? " (active)" : " (inactive)";
5231 // GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
5232 aSyncActive = ::glIsEnabled (0x8242) == GL_TRUE ? " (active)" : " (inactive)";
5236 theDI << "debug: " << (aCaps->contextDebug ? "1" : "0") << aDebActive << "\n"
5237 << "sync: " << (aCaps->contextSyncDebug ? "1" : "0") << aSyncActive << "\n"
5238 << "glslWarn:" << (aCaps->glslWarnings ? "1" : "0") << "\n"
5239 << "extraMsg:" << (aCaps->suppressExtraMsg ? "0" : "1") << "\n";
5243 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5245 Standard_CString anArg = theArgVec[anArgIter];
5246 TCollection_AsciiString anArgCase (anArg);
5247 anArgCase.LowerCase();
5248 Standard_Boolean toEnableDebug = Standard_True;
5249 if (anArgCase == "-glsl"
5250 || anArgCase == "-glslwarn"
5251 || anArgCase == "-glslwarns"
5252 || anArgCase == "-glslwarnings")
5254 Standard_Boolean toShowWarns = Standard_True;
5255 if (++anArgIter < theArgNb
5256 && !parseOnOff (theArgVec[anArgIter], toShowWarns))
5260 aDefCaps->glslWarnings = toShowWarns;
5263 aCaps->glslWarnings = toShowWarns;
5266 else if (anArgCase == "-extra"
5267 || anArgCase == "-extramsg"
5268 || anArgCase == "-extramessages")
5270 Standard_Boolean toShow = Standard_True;
5271 if (++anArgIter < theArgNb
5272 && !parseOnOff (theArgVec[anArgIter], toShow))
5276 aDefCaps->suppressExtraMsg = !toShow;
5279 aCaps->suppressExtraMsg = !toShow;
5282 else if (anArgCase == "-noextra"
5283 || anArgCase == "-noextramsg"
5284 || anArgCase == "-noextramessages")
5286 Standard_Boolean toSuppress = Standard_True;
5287 if (++anArgIter < theArgNb
5288 && !parseOnOff (theArgVec[anArgIter], toSuppress))
5292 aDefCaps->suppressExtraMsg = toSuppress;
5295 aCaps->suppressExtraMsg = toSuppress;
5298 else if (anArgCase == "-sync")
5300 Standard_Boolean toSync = Standard_True;
5301 if (++anArgIter < theArgNb
5302 && !parseOnOff (theArgVec[anArgIter], toSync))
5306 aDefCaps->contextSyncDebug = toSync;
5309 aDefCaps->contextDebug = Standard_True;
5312 else if (anArgCase == "-debug")
5314 if (++anArgIter < theArgNb
5315 && !parseOnOff (theArgVec[anArgIter], toEnableDebug))
5319 aDefCaps->contextDebug = toEnableDebug;
5321 else if (parseOnOff (anArg, toEnableDebug)
5322 && (anArgIter + 1 == theArgNb))
5324 // simple alias to turn on almost everything
5325 aDefCaps->contextDebug = toEnableDebug;
5326 aDefCaps->contextSyncDebug = toEnableDebug;
5327 aDefCaps->glslWarnings = toEnableDebug;
5331 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
5339 //==============================================================================
5342 //==============================================================================
5344 static int VVbo (Draw_Interpretor& theDI,
5345 Standard_Integer theArgNb,
5346 const char** theArgVec)
5348 const Standard_Boolean toSet = (theArgNb > 1);
5349 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
5352 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
5356 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5357 if (aContextAIS.IsNull())
5361 std::cerr << "No active view!\n";
5365 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5366 if (!aDriver.IsNull())
5370 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
5374 aDriver->ChangeOptions().vboDisable = toUseVbo;
5381 //==============================================================================
5384 //==============================================================================
5386 static int VCaps (Draw_Interpretor& theDI,
5387 Standard_Integer theArgNb,
5388 const char** theArgVec)
5390 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
5391 Handle(OpenGl_GraphicDriver) aDriver;
5392 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5393 if (!aContext.IsNull())
5395 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
5396 aCaps = &aDriver->ChangeOptions();
5401 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
5402 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
5403 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
5404 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
5405 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
5409 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5410 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5412 Standard_CString anArg = theArgVec[anArgIter];
5413 TCollection_AsciiString anArgCase (anArg);
5414 anArgCase.LowerCase();
5415 if (anUpdateTool.parseRedrawMode (anArg))
5419 else if (anArgCase == "-ffp")
5421 Standard_Boolean toEnable = Standard_True;
5422 if (++anArgIter < theArgNb
5423 && !parseOnOff (theArgVec[anArgIter], toEnable))
5427 aCaps->ffpEnable = toEnable;
5429 else if (anArgCase == "-vbo")
5431 Standard_Boolean toEnable = Standard_True;
5432 if (++anArgIter < theArgNb
5433 && !parseOnOff (theArgVec[anArgIter], toEnable))
5437 aCaps->vboDisable = !toEnable;
5439 else if (anArgCase == "-sprite"
5440 || anArgCase == "-sprites")
5442 Standard_Boolean toEnable = Standard_True;
5443 if (++anArgIter < theArgNb
5444 && !parseOnOff (theArgVec[anArgIter], toEnable))
5448 aCaps->pntSpritesDisable = !toEnable;
5450 else if (anArgCase == "-softmode")
5452 Standard_Boolean toEnable = Standard_True;
5453 if (++anArgIter < theArgNb
5454 && !parseOnOff (theArgVec[anArgIter], toEnable))
5458 aCaps->contextNoAccel = toEnable;
5460 else if (anArgCase == "-accel"
5461 || anArgCase == "-acceleration")
5463 Standard_Boolean toEnable = Standard_True;
5464 if (++anArgIter < theArgNb
5465 && !parseOnOff (theArgVec[anArgIter], toEnable))
5469 aCaps->contextNoAccel = !toEnable;
5471 else if (anArgCase == "-compat"
5472 || anArgCase == "-compatprofile"
5473 || anArgCase == "-compatible"
5474 || anArgCase == "-compatibleprofile")
5476 Standard_Boolean toEnable = Standard_True;
5477 if (++anArgIter < theArgNb
5478 && !parseOnOff (theArgVec[anArgIter], toEnable))
5482 aCaps->contextCompatible = toEnable;
5483 if (!aCaps->contextCompatible)
5485 aCaps->ffpEnable = Standard_False;
5488 else if (anArgCase == "-core"
5489 || anArgCase == "-coreprofile")
5491 Standard_Boolean toEnable = Standard_True;
5492 if (++anArgIter < theArgNb
5493 && !parseOnOff (theArgVec[anArgIter], toEnable))
5497 aCaps->contextCompatible = !toEnable;
5498 if (!aCaps->contextCompatible)
5500 aCaps->ffpEnable = Standard_False;
5505 std::cout << "Error: unknown argument '" << anArg << "'\n";
5509 if (aCaps != &ViewerTest_myDefaultCaps)
5511 ViewerTest_myDefaultCaps = *aCaps;
5516 //==============================================================================
5517 //function : VMemGpu
5519 //==============================================================================
5521 static int VMemGpu (Draw_Interpretor& theDI,
5522 Standard_Integer theArgNb,
5523 const char** theArgVec)
5526 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5527 if (aContextAIS.IsNull())
5529 std::cerr << "No active view. Please call vinit.\n";
5533 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
5534 if (aDriver.IsNull())
5536 std::cerr << "Graphic driver not available.\n";
5540 Standard_Size aFreeBytes = 0;
5541 TCollection_AsciiString anInfo;
5542 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
5544 std::cerr << "Information not available.\n";
5548 if (theArgNb > 1 && *theArgVec[1] == 'f')
5550 theDI << Standard_Real (aFreeBytes);
5560 // ==============================================================================
5561 // function : VReadPixel
5563 // ==============================================================================
5564 static int VReadPixel (Draw_Interpretor& theDI,
5565 Standard_Integer theArgNb,
5566 const char** theArgVec)
5568 // get the active view
5569 Handle(V3d_View) aView = ViewerTest::CurrentView();
5572 std::cerr << "No active view. Please call vinit.\n";
5575 else if (theArgNb < 3)
5577 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
5581 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
5582 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
5584 Standard_Integer aWidth, aHeight;
5585 aView->Window()->Size (aWidth, aHeight);
5586 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
5587 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
5588 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
5590 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
5594 Standard_Boolean toShowName = Standard_False;
5595 Standard_Boolean toShowHls = Standard_False;
5596 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
5598 const char* aParam = theArgVec[anIter];
5599 if ( strcasecmp( aParam, "rgb" ) == 0 )
5601 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
5602 aBufferType = Graphic3d_BT_RGB;
5604 else if ( strcasecmp( aParam, "hls" ) == 0 )
5606 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
5607 aBufferType = Graphic3d_BT_RGB;
5608 toShowHls = Standard_True;
5610 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
5612 aFormat = Image_PixMap::ImgRGBF;
5613 aBufferType = Graphic3d_BT_RGB;
5615 else if ( strcasecmp( aParam, "rgba" ) == 0 )
5617 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
5618 aBufferType = Graphic3d_BT_RGBA;
5620 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
5622 aFormat = Image_PixMap::ImgRGBAF;
5623 aBufferType = Graphic3d_BT_RGBA;
5625 else if ( strcasecmp( aParam, "depth" ) == 0 )
5627 aFormat = Image_PixMap::ImgGrayF;
5628 aBufferType = Graphic3d_BT_Depth;
5630 else if ( strcasecmp( aParam, "name" ) == 0 )
5632 toShowName = Standard_True;
5636 Image_PixMap anImage;
5637 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
5639 std::cerr << "Image allocation failed\n";
5642 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
5644 std::cerr << "Image dump failed\n";
5648 Quantity_Parameter anAlpha;
5649 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
5652 if (aBufferType == Graphic3d_BT_RGBA)
5654 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha;
5658 theDI << Quantity_Color::StringName (aColor.Name());
5663 switch (aBufferType)
5666 case Graphic3d_BT_RGB:
5670 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation();
5674 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue();
5678 case Graphic3d_BT_RGBA:
5680 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha;
5683 case Graphic3d_BT_Depth:
5685 theDI << aColor.Red();
5694 //==============================================================================
5695 //function : VDiffImage
5696 //purpose : The draw-command compares two images.
5697 //==============================================================================
5699 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
5703 theDI << "Not enough arguments.\n";
5708 const char* anImgPathRef = theArgVec[1];
5709 const char* anImgPathNew = theArgVec[2];
5711 // get string tolerance and check its validity
5712 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
5713 if (aTolColor < 0.0)
5715 if (aTolColor > 1.0)
5718 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
5719 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
5721 // image file of difference
5722 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
5724 // compare the images
5725 Image_Diff aComparer;
5726 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
5731 aComparer.SetColorTolerance (aTolColor);
5732 aComparer.SetBorderFilterOn (isBorderFilterOn);
5733 Standard_Integer aDiffColorsNb = aComparer.Compare();
5734 theDI << aDiffColorsNb << "\n";
5736 // save image of difference
5737 if (aDiffColorsNb >0 && aDiffImagePath != NULL)
5739 aComparer.SaveDiffImage (aDiffImagePath);
5745 //=======================================================================
5746 //function : VSelect
5747 //purpose : Emulates different types of selection by mouse:
5748 // 1) single click selection
5749 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
5750 // 3) selection with polygon having corners at
5751 // pixel positions (x1,y1),...,(xn,yn)
5752 // 4) any of these selections with shift button pressed
5753 //=======================================================================
5754 static Standard_Integer VSelect (Draw_Interpretor& di,
5755 Standard_Integer argc,
5760 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
5764 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
5765 if(myAIScontext.IsNull())
5767 di << "use 'vinit' command before " << argv[0] << "\n";
5770 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
5771 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
5772 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
5775 if(isShiftSelection)
5776 aCurrentEventManager->ShiftSelect();
5778 aCurrentEventManager->Select();
5782 if(isShiftSelection)
5783 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
5785 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
5789 Standard_Integer anUpper = 0;
5791 if(isShiftSelection)
5792 anUpper = (argc-1)/2;
5795 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
5797 for(Standard_Integer i=1;i<=anUpper;++i)
5798 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
5800 if(isShiftSelection)
5801 aCurrentEventManager->ShiftSelect(aPolyline);
5803 aCurrentEventManager->Select(aPolyline);
5808 //=======================================================================
5809 //function : VMoveTo
5810 //purpose : Emulates cursor movement to defined pixel position
5811 //=======================================================================
5812 static Standard_Integer VMoveTo (Draw_Interpretor& di,
5813 Standard_Integer argc,
5818 di << "Usage : " << argv[0] << " x y" << "\n";
5822 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5823 if(aContext.IsNull())
5825 di << "use 'vinit' command before " << argv[0] << "\n";
5828 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
5832 //=================================================================================================
5833 //function : VViewParams
5834 //purpose : Gets or sets AIS View characteristics
5835 //=================================================================================================
5836 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5838 Handle(V3d_View) anAISView = ViewerTest::CurrentView();
5839 if (anAISView.IsNull())
5841 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
5847 // print all of the available view parameters
5848 Quantity_Factor anAISViewScale = anAISView->Scale();
5850 Standard_Real anAISViewProjX = 0.0;
5851 Standard_Real anAISViewProjY = 0.0;
5852 Standard_Real anAISViewProjZ = 0.0;
5853 anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
5855 Standard_Real anAISViewUpX = 0.0;
5856 Standard_Real anAISViewUpY = 0.0;
5857 Standard_Real anAISViewUpZ = 0.0;
5858 anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
5860 Standard_Real anAISViewAtX = 0.0;
5861 Standard_Real anAISViewAtY = 0.0;
5862 Standard_Real anAISViewAtZ = 0.0;
5863 anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
5865 Standard_Real anAISViewEyeX = 0.0;
5866 Standard_Real anAISViewEyeY = 0.0;
5867 Standard_Real anAISViewEyeZ = 0.0;
5868 anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ);
5870 theDi << "Scale of current view: " << anAISViewScale << "\n";
5871 theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
5872 theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
5873 theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
5874 theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n";
5878 // -------------------------
5879 // Parse options and values
5880 // -------------------------
5882 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues;
5883 TCollection_AsciiString aParseKey;
5884 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5886 TCollection_AsciiString anArg (theArgVec [anArgIt]);
5888 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
5891 aParseKey.Remove (1);
5892 aParseKey.UpperCase();
5893 aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
5897 if (aParseKey.IsEmpty())
5899 std::cout << theArgVec[0] << ": values should be passed with key.\n";
5900 std::cout << "Type help for more information.\n";
5904 aMapOfKeysByValues(aParseKey)->Append (anArg);
5907 // ---------------------------------------------
5908 // Change or print parameters, order plays role
5909 // ---------------------------------------------
5911 // Check arguments for validity
5912 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues);
5913 for (; aMapIt.More(); aMapIt.Next())
5915 const TCollection_AsciiString& aKey = aMapIt.Key();
5916 const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value();
5918 if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5919 && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5920 && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty()))
5921 && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty()))
5922 && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty()))
5923 && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty()))
5924 && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2))
5926 TCollection_AsciiString aLowerKey;
5929 aLowerKey.LowerCase();
5930 std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n";
5931 std::cout << "Type help for more information.\n";
5936 Handle(TColStd_HSequenceOfAsciiString) aValues;
5938 // Change view parameters in proper order
5939 if (aMapOfKeysByValues.Find ("SCALE", aValues))
5941 if (aValues->IsEmpty())
5943 theDi << "Scale: " << anAISView->Scale() << "\n";
5947 anAISView->SetScale (aValues->Value(1).RealValue());
5950 if (aMapOfKeysByValues.Find ("SIZE", aValues))
5952 if (aValues->IsEmpty())
5954 Standard_Real aSizeX = 0.0;
5955 Standard_Real aSizeY = 0.0;
5956 anAISView->Size (aSizeX, aSizeY);
5957 theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n";
5961 anAISView->SetSize (aValues->Value(1).RealValue());
5964 if (aMapOfKeysByValues.Find ("EYE", aValues))
5966 if (aValues->IsEmpty())
5968 Standard_Real anEyeX = 0.0;
5969 Standard_Real anEyeY = 0.0;
5970 Standard_Real anEyeZ = 0.0;
5971 anAISView->Eye (anEyeX, anEyeY, anEyeZ);
5972 theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n";
5976 anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5979 if (aMapOfKeysByValues.Find ("AT", aValues))
5981 if (aValues->IsEmpty())
5983 Standard_Real anAtX = 0.0;
5984 Standard_Real anAtY = 0.0;
5985 Standard_Real anAtZ = 0.0;
5986 anAISView->At (anAtX, anAtY, anAtZ);
5987 theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n";
5991 anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5994 if (aMapOfKeysByValues.Find ("PROJ", aValues))
5996 if (aValues->IsEmpty())
5998 Standard_Real aProjX = 0.0;
5999 Standard_Real aProjY = 0.0;
6000 Standard_Real aProjZ = 0.0;
6001 anAISView->Proj (aProjX, aProjY, aProjZ);
6002 theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n";
6006 anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6009 if (aMapOfKeysByValues.Find ("UP", aValues))
6011 if (aValues->IsEmpty())
6013 Standard_Real anUpX = 0.0;
6014 Standard_Real anUpY = 0.0;
6015 Standard_Real anUpZ = 0.0;
6016 anAISView->Up (anUpX, anUpY, anUpZ);
6017 theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n";
6021 anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
6024 if (aMapOfKeysByValues.Find ("CENTER", aValues))
6026 anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue());
6032 //=======================================================================
6033 //function : VChangeSelected
6034 //purpose : Adds the shape to selection or remove one from it
6035 //=======================================================================
6036 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
6037 Standard_Integer argc,
6042 di<<"Usage : " << argv[0] << " shape \n";
6046 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6047 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
6048 TCollection_AsciiString aName(argv[1]);
6049 Handle(AIS_InteractiveObject) anAISObject;
6051 if(!aMap.IsBound2(aName))
6053 di<<"Use 'vdisplay' before";
6058 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
6059 if(anAISObject.IsNull()){
6060 di<<"No interactive object \n";
6064 if(aContext->HasOpenedContext())
6066 aContext->AddOrRemoveSelected(anAISObject);
6070 aContext->AddOrRemoveCurrentObject(anAISObject);
6076 //=======================================================================
6077 //function : VZClipping
6078 //purpose : Gets or sets ZClipping mode, width and depth
6079 //=======================================================================
6080 static Standard_Integer VZClipping (Draw_Interpretor& di,
6081 Standard_Integer argc,
6086 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6087 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6090 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6091 if(aContext.IsNull())
6093 di << "use 'vinit' command before " << argv[0] << "\n";
6096 Handle(V3d_View) aView = ViewerTest::CurrentView();
6097 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
6100 TCollection_AsciiString aZClippingModeString;
6101 Quantity_Length aDepth, aWidth;
6102 aZClippingMode = aView->ZClipping(aDepth, aWidth);
6103 switch (aZClippingMode)
6106 aZClippingModeString.Copy("OFF");
6109 aZClippingModeString.Copy("BACK");
6112 aZClippingModeString.Copy("FRONT");
6115 aZClippingModeString.Copy("SLICE");
6118 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
6121 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
6122 << "ZClipping depth = " << aDepth << "\n"
6123 << "ZClipping width = " << aWidth << "\n";
6129 Standard_Integer aStatus = 0;
6130 if ( strcmp (argv [1], "OFF") == 0 ) {
6132 aZClippingMode = V3d_OFF;
6134 if ( strcmp (argv [1], "BACK") == 0 ) {
6136 aZClippingMode = V3d_BACK;
6138 if ( strcmp (argv [1], "FRONT") == 0 ) {
6140 aZClippingMode = V3d_FRONT;
6142 if ( strcmp (argv [1], "SLICE") == 0 ) {
6144 aZClippingMode = V3d_SLICE;
6148 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6149 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6152 aView->SetZClippingType(aZClippingMode);
6156 Quantity_Length aDepth = 0., aWidth = 1.;
6159 aDepth = Draw::Atof (argv[1]);
6160 aWidth = Draw::Atof (argv[2]);
6164 aDepth = Draw::Atof (argv[2]);
6165 aWidth = Draw::Atof (argv[3]);
6168 if(aDepth<0. || aDepth>1.)
6170 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6171 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6174 if(aWidth<0. || aWidth>1.)
6176 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
6177 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
6181 aView->SetZClippingDepth(aDepth);
6182 aView->SetZClippingWidth(aWidth);
6189 //=======================================================================
6190 //function : VNbSelected
6191 //purpose : Returns number of selected objects
6192 //=======================================================================
6193 static Standard_Integer VNbSelected (Draw_Interpretor& di,
6194 Standard_Integer argc,
6199 di << "Usage : " << argv[0] << "\n";
6202 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6203 if(aContext.IsNull())
6205 di << "use 'vinit' command before " << argv[0] << "\n";
6208 di << aContext->NbSelected() << "\n";
6212 //=======================================================================
6213 //function : VAntialiasing
6214 //purpose : Switches altialiasing on or off
6215 //=======================================================================
6216 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
6217 Standard_Integer argc,
6222 di << "Usage : " << argv[0] << " [1|0]" << "\n";
6226 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6227 if(aContext.IsNull())
6229 di << "use 'vinit' command before " << argv[0] << "\n";
6233 Handle(V3d_View) aView = ViewerTest::CurrentView();
6235 if((argc == 2) && (atof(argv[1]) == 0))
6236 aView->SetAntialiasingOff();
6238 aView->SetAntialiasingOn();
6243 //=======================================================================
6244 //function : VPurgeDisplay
6245 //purpose : Switches altialiasing on or off
6246 //=======================================================================
6247 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
6248 Standard_Integer argc,
6253 di << "Usage : " << argv[0] << "\n";
6256 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6257 if (aContext.IsNull())
6259 di << "use 'vinit' command before " << argv[0] << "\n";
6262 aContext->CloseAllContexts(Standard_False);
6263 di << aContext->PurgeDisplay() << "\n";
6267 //=======================================================================
6268 //function : VSetViewSize
6270 //=======================================================================
6271 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
6272 Standard_Integer argc,
6275 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6276 if(aContext.IsNull())
6278 di << "use 'vinit' command before " << argv[0] << "\n";
6283 di<<"Usage : " << argv[0] << " Size\n";
6286 Standard_Real aSize = Draw::Atof (argv[1]);
6289 di<<"Bad Size value : " << aSize << "\n";
6293 Handle(V3d_View) aView = ViewerTest::CurrentView();
6294 aView->SetSize(aSize);
6298 //=======================================================================
6299 //function : VMoveView
6301 //=======================================================================
6302 static Standard_Integer VMoveView (Draw_Interpretor& di,
6303 Standard_Integer argc,
6306 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6307 if(aContext.IsNull())
6309 di << "use 'vinit' command before " << argv[0] << "\n";
6312 if(argc < 4 || argc > 5)
6314 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
6317 Standard_Real Dx = Draw::Atof (argv[1]);
6318 Standard_Real Dy = Draw::Atof (argv[2]);
6319 Standard_Real Dz = Draw::Atof (argv[3]);
6320 Standard_Boolean aStart = Standard_True;
6323 aStart = (Draw::Atoi (argv[4]) > 0);
6326 Handle(V3d_View) aView = ViewerTest::CurrentView();
6327 aView->Move(Dx,Dy,Dz,aStart);
6331 //=======================================================================
6332 //function : VTranslateView
6334 //=======================================================================
6335 static Standard_Integer VTranslateView (Draw_Interpretor& di,
6336 Standard_Integer argc,
6339 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6340 if(aContext.IsNull())
6342 di << "use 'vinit' command before " << argv[0] << "\n";
6345 if(argc < 4 || argc > 5)
6347 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
6350 Standard_Real Dx = Draw::Atof (argv[1]);
6351 Standard_Real Dy = Draw::Atof (argv[2]);
6352 Standard_Real Dz = Draw::Atof (argv[3]);
6353 Standard_Boolean aStart = Standard_True;
6356 aStart = (Draw::Atoi (argv[4]) > 0);
6359 Handle(V3d_View) aView = ViewerTest::CurrentView();
6360 aView->Translate(Dx,Dy,Dz,aStart);
6364 //=======================================================================
6365 //function : VTurnView
6367 //=======================================================================
6368 static Standard_Integer VTurnView (Draw_Interpretor& di,
6369 Standard_Integer argc,
6372 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6373 if(aContext.IsNull()) {
6374 di << "use 'vinit' command before " << argv[0] << "\n";
6377 if(argc < 4 || argc > 5){
6378 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
6381 Standard_Real Ax = Draw::Atof (argv[1]);
6382 Standard_Real Ay = Draw::Atof (argv[2]);
6383 Standard_Real Az = Draw::Atof (argv[3]);
6384 Standard_Boolean aStart = Standard_True;
6387 aStart = (Draw::Atoi (argv[4]) > 0);
6390 Handle(V3d_View) aView = ViewerTest::CurrentView();
6391 aView->Turn(Ax,Ay,Az,aStart);
6395 //==============================================================================
6396 //function : VTextureEnv
6397 //purpose : ENables or disables environment mapping
6398 //==============================================================================
6399 class OCC_TextureEnv : public Graphic3d_TextureEnv
6402 OCC_TextureEnv(const Standard_CString FileName);
6403 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
6404 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
6405 const Standard_Boolean theModulateFlag,
6406 const Graphic3d_TypeOfTextureFilter theFilter,
6407 const Standard_ShortReal theXScale,
6408 const Standard_ShortReal theYScale,
6409 const Standard_ShortReal theXShift,
6410 const Standard_ShortReal theYShift,
6411 const Standard_ShortReal theAngle);
6412 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
6414 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
6415 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
6416 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
6418 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
6419 : Graphic3d_TextureEnv(theFileName)
6423 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
6424 : Graphic3d_TextureEnv(theTexId)
6428 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
6429 const Standard_Boolean theModulateFlag,
6430 const Graphic3d_TypeOfTextureFilter theFilter,
6431 const Standard_ShortReal theXScale,
6432 const Standard_ShortReal theYScale,
6433 const Standard_ShortReal theXShift,
6434 const Standard_ShortReal theYShift,
6435 const Standard_ShortReal theAngle)
6437 myParams->SetRepeat (theRepeatFlag);
6438 myParams->SetModulate (theModulateFlag);
6439 myParams->SetFilter (theFilter);
6440 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
6441 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
6442 myParams->SetRotation (theAngle);
6445 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
6447 // get the active view
6448 Handle(V3d_View) aView = ViewerTest::CurrentView();
6451 std::cerr << "No active view. Please call vinit.\n";
6455 // Checking the input arguments
6456 Standard_Boolean anEnableFlag = Standard_False;
6457 Standard_Boolean isOk = theArgNb >= 2;
6460 TCollection_AsciiString anEnableOpt(theArgVec[1]);
6461 anEnableFlag = anEnableOpt.IsEqual("on");
6462 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
6466 isOk = (theArgNb == 3 || theArgNb == 11);
6469 TCollection_AsciiString aTextureOpt(theArgVec[2]);
6470 isOk = (!aTextureOpt.IsIntegerValue() ||
6471 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
6473 if (isOk && theArgNb == 11)
6475 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
6476 aModulateOpt(theArgVec[4]),
6477 aFilterOpt (theArgVec[5]),
6478 aSScaleOpt (theArgVec[6]),
6479 aTScaleOpt (theArgVec[7]),
6480 aSTransOpt (theArgVec[8]),
6481 aTTransOpt (theArgVec[9]),
6482 anAngleOpt (theArgVec[10]);
6483 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
6484 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
6485 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
6486 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
6487 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
6488 anAngleOpt.IsRealValue());
6495 std::cerr << "Usage :" << std::endl;
6496 std::cerr << theArgVec[0] << " off" << std::endl;
6497 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;
6503 TCollection_AsciiString aTextureOpt(theArgVec[2]);
6504 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
6505 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
6506 new OCC_TextureEnv(theArgVec[2]);
6510 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
6511 aTexEnv->SetTextureParameters(
6512 aRepeatOpt. IsEqual("repeat"),
6513 aModulateOpt.IsEqual("modulate"),
6514 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
6515 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
6516 Graphic3d_TOTF_TRILINEAR,
6517 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
6518 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
6519 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
6520 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
6521 (Standard_ShortReal)Draw::Atof(theArgVec[10])
6524 aView->SetTextureEnv(aTexEnv);
6525 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
6527 else // Disabling environment mapping
6529 aView->SetSurfaceDetail(V3d_TEX_NONE);
6530 Handle(Graphic3d_TextureEnv) aTexture;
6531 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
6538 //===============================================================================================
6539 //function : VClipPlane
6541 //===============================================================================================
6542 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6544 // use short-cut for created clip planes map of created (or "registered by name") clip planes
6545 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
6546 static MapOfPlanes aRegPlanes;
6550 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
6554 TCollection_AsciiString aCommand (theArgVec[1]);
6556 // print maximum number of planes for current viewer
6557 if (aCommand == "maxplanes")
6561 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
6565 TCollection_AsciiString aViewName (theArgVec[2]);
6567 if (!ViewerTest_myViews.IsBound1 (aViewName))
6569 theDi << theArgVec[0] << ": view is not found.\n";
6573 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
6575 theDi << theArgVec[0] << ": "
6576 << aView->Viewer()->Driver()->InquirePlaneLimit()
6577 << " plane slots provided by driver."
6578 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
6583 // create / delete plane instance
6584 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
6588 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
6592 Standard_Boolean toCreate = (aCommand == "create");
6593 Standard_Boolean toClone = (aCommand == "clone");
6594 TCollection_AsciiString aPlane (theArgVec[2]);
6598 if (aRegPlanes.IsBound (aPlane))
6600 theDi << theArgVec[0] << ": plane name is in use.\n";
6604 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
6606 else if (toClone) // toClone
6608 if (!aRegPlanes.IsBound (aPlane))
6610 theDi << theArgVec[0] << ": no such plane.\n";
6616 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
6620 TCollection_AsciiString aClone (theArgVec[3]);
6621 if (aRegPlanes.IsBound (aClone))
6623 theDi << theArgVec[0] << ": plane name is in use.\n";
6627 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6629 aRegPlanes.Bind (aClone, aClipPlane->Clone());
6633 if (!aRegPlanes.IsBound (aPlane))
6635 theDi << theArgVec[0] << ": no such plane.\n";
6639 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
6640 aRegPlanes.UnBind (aPlane);
6642 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
6643 for (; anIObjIt.More(); anIObjIt.Next())
6645 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
6646 aPrs->RemoveClipPlane(aClipPlane);
6649 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
6650 for (; aViewIt.More(); aViewIt.Next())
6652 const Handle(V3d_View)& aView = aViewIt.Key2();
6653 aView->RemoveClipPlane(aClipPlane);
6656 ViewerTest::RedrawAllViews();
6662 // set / unset plane command
6663 if (aCommand == "set" || aCommand == "unset")
6667 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6671 Standard_Boolean toSet = (aCommand == "set");
6672 TCollection_AsciiString aPlane (theArgVec [2]);
6673 if (!aRegPlanes.IsBound (aPlane))
6675 theDi << theArgVec[0] << ": no such plane.\n";
6679 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6681 TCollection_AsciiString aTarget (theArgVec [3]);
6682 if (aTarget != "object" && aTarget != "view")
6684 theDi << theArgVec[0] << ": invalid target.\n";
6688 if (aTarget == "object" || aTarget == "view")
6692 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6696 Standard_Boolean isObject = (aTarget == "object");
6698 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
6700 TCollection_AsciiString anEntityName (theArgVec[anIt]);
6701 if (isObject) // to object
6703 if (!GetMapOfAIS().IsBound2 (anEntityName))
6705 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
6709 Handle(AIS_InteractiveObject) aIObj =
6710 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
6713 aIObj->AddClipPlane (aClipPlane);
6715 aIObj->RemoveClipPlane (aClipPlane);
6719 if (!ViewerTest_myViews.IsBound1 (anEntityName))
6721 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
6725 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
6727 aView->AddClipPlane (aClipPlane);
6729 aView->RemoveClipPlane (aClipPlane);
6733 ViewerTest::RedrawAllViews();
6739 // change plane command
6740 if (aCommand == "change")
6744 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6748 TCollection_AsciiString aPlane (theArgVec [2]);
6749 if (!aRegPlanes.IsBound (aPlane))
6751 theDi << theArgVec[0] << ": no such plane.\n";
6755 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6757 TCollection_AsciiString aChangeArg (theArgVec [3]);
6758 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
6760 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
6764 if (aChangeArg == "on" || aChangeArg == "off") // on / off
6766 aClipPlane->SetOn (aChangeArg == "on");
6768 else if (aChangeArg == "equation") // change equation
6772 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6776 Standard_Real aCoeffA = Draw::Atof (theArgVec [4]);
6777 Standard_Real aCoeffB = Draw::Atof (theArgVec [5]);
6778 Standard_Real aCoeffC = Draw::Atof (theArgVec [6]);
6779 Standard_Real aCoeffD = Draw::Atof (theArgVec [7]);
6780 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
6782 else if (aChangeArg == "capping") // change capping aspects
6786 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6790 TCollection_AsciiString aCappingArg (theArgVec [4]);
6791 if (aCappingArg != "on" && aCappingArg != "off" &&
6792 aCappingArg != "color" && aCappingArg != "texname" &&
6793 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
6794 aCappingArg != "texrotate" && aCappingArg != "hatch")
6796 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
6800 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
6802 aClipPlane->SetCapping (aCappingArg == "on");
6804 else if (aCappingArg == "color") // color aspect for capping
6808 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6812 Standard_Real aRed = Draw::Atof (theArgVec [5]);
6813 Standard_Real aGrn = Draw::Atof (theArgVec [6]);
6814 Standard_Real aBlu = Draw::Atof (theArgVec [7]);
6816 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
6817 Quantity_Color aColor (aRed, aGrn, aBlu, Quantity_TOC_RGB);
6818 aMat.SetAmbientColor (aColor);
6819 aMat.SetDiffuseColor (aColor);
6820 aClipPlane->SetCappingMaterial (aMat);
6822 else if (aCappingArg == "texname") // texture name
6826 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6830 TCollection_AsciiString aTextureName (theArgVec [5]);
6832 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
6833 if (!aTexture->IsDone ())
6835 aClipPlane->SetCappingTexture (NULL);
6839 aTexture->EnableModulate();
6840 aTexture->EnableRepeat();
6841 aClipPlane->SetCappingTexture (aTexture);
6844 else if (aCappingArg == "texscale") // texture scale
6846 if (aClipPlane->CappingTexture().IsNull())
6848 theDi << theArgVec[0] << ": no texture is set.\n";
6854 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6858 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
6859 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
6861 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
6863 else if (aCappingArg == "texorigin") // texture origin
6865 if (aClipPlane->CappingTexture().IsNull())
6867 theDi << theArgVec[0] << ": no texture is set.\n";
6873 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6877 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
6878 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
6880 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
6882 else if (aCappingArg == "texrotate") // texture rotation
6884 if (aClipPlane->CappingTexture().IsNull())
6886 theDi << theArgVec[0] << ": no texture is set.\n";
6892 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6896 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
6898 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
6900 else if (aCappingArg == "hatch") // hatch style
6904 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6908 TCollection_AsciiString aHatchStr (theArgVec [5]);
6909 if (aHatchStr == "on")
6911 aClipPlane->SetCappingHatchOn();
6913 else if (aHatchStr == "off")
6915 aClipPlane->SetCappingHatchOff();
6919 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
6924 ViewerTest::RedrawAllViews();
6929 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
6933 //===============================================================================================
6934 //function : VSetTextureMode
6936 //===============================================================================================
6937 static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6941 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
6945 TCollection_AsciiString aViewName (theArgVec[1]);
6946 if (!ViewerTest_myViews.IsBound1 (aViewName))
6948 theDi << theArgVec[0] << ": view is not found.\n";
6952 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
6953 switch (atoi (theArgVec[2]))
6955 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
6956 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
6957 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
6959 theDi << theArgVec[0] << ": invalid mode.\n";
6967 //===============================================================================================
6968 //function : VZRange
6970 //===============================================================================================
6971 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6973 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
6975 if (aCurrentView.IsNull())
6977 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
6981 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
6985 theDi << "ZNear: " << aCamera->ZNear() << "\n";
6986 theDi << "ZFar: " << aCamera->ZFar() << "\n";
6992 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
6993 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
6995 if (aNewZNear >= aNewZFar)
6997 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
7001 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
7003 std::cout << theArgVec[0] << ": invalid arguments: ";
7004 std::cout << "znear, zfar should be positive for perspective camera.\n";
7008 aCamera->SetZRange (aNewZNear, aNewZFar);
7012 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
7016 aCurrentView->Redraw();
7021 //===============================================================================================
7022 //function : VAutoZFit
7024 //===============================================================================================
7025 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
7027 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
7029 if (aCurrentView.IsNull())
7031 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
7035 Standard_Real aScale = aCurrentView->View()->AutoZFitScaleFactor();
7039 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
7045 theDi << "Auto z-fit mode: " << "\n"
7046 << "On: " << (aCurrentView->View()->AutoZFitMode() ? "enabled" : "disabled") << "\n"
7047 << "Scale: " << aScale << "\n";
7051 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
7055 aScale = Draw::Atoi (theArgVec[2]);
7058 aCurrentView->View()->SetAutoZFitMode (isOn, aScale);
7059 aCurrentView->View()->AutoZFit();
7060 aCurrentView->Redraw();
7065 //! Auxiliary function to print projection type
7066 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
7068 switch (theProjType)
7070 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
7071 case Graphic3d_Camera::Projection_Perspective: return "perspective";
7072 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
7073 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
7074 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
7079 //===============================================================================================
7080 //function : VCamera
7082 //===============================================================================================
7083 static int VCamera (Draw_Interpretor& theDI,
7084 Standard_Integer theArgsNb,
7085 const char** theArgVec)
7087 Handle(V3d_View) aView = ViewerTest::CurrentView();
7090 std::cout << "Error: no active view.\n";
7094 Handle(Graphic3d_Camera) aCamera = aView->Camera();
7097 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
7098 theDI << "FOVy: " << aCamera->FOVy() << "\n";
7099 theDI << "Distance: " << aCamera->Distance() << "\n";
7100 theDI << "IOD: " << aCamera->IOD() << "\n";
7101 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
7102 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
7103 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
7107 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7109 Standard_CString anArg = theArgVec[anArgIter];
7110 TCollection_AsciiString anArgCase (anArg);
7111 anArgCase.LowerCase();
7112 if (anArgCase == "-proj"
7113 || anArgCase == "-projection"
7114 || anArgCase == "-projtype"
7115 || anArgCase == "-projectiontype")
7117 theDI << projTypeName (aCamera->ProjectionType()) << " ";
7119 else if (anArgCase == "-ortho"
7120 || anArgCase == "-orthographic")
7122 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
7124 else if (anArgCase == "-persp"
7125 || anArgCase == "-perspective"
7126 || anArgCase == "-perspmono"
7127 || anArgCase == "-perspectivemono"
7128 || anArgCase == "-mono")
7130 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
7132 else if (anArgCase == "-stereo"
7133 || anArgCase == "-stereoscopic"
7134 || anArgCase == "-perspstereo"
7135 || anArgCase == "-perspectivestereo")
7137 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
7139 else if (anArgCase == "-left"
7140 || anArgCase == "-lefteye"
7141 || anArgCase == "-monoleft"
7142 || anArgCase == "-monolefteye"
7143 || anArgCase == "-perpsleft"
7144 || anArgCase == "-perpslefteye")
7146 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
7148 else if (anArgCase == "-right"
7149 || anArgCase == "-righteye"
7150 || anArgCase == "-monoright"
7151 || anArgCase == "-monorighteye"
7152 || anArgCase == "-perpsright")
7154 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
7156 else if (anArgCase == "-dist"
7157 || anArgCase == "-distance")
7159 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7160 if (anArgValue != NULL
7161 && *anArgValue != '-')
7164 aCamera->SetDistance (Draw::Atof (anArgValue));
7167 theDI << aCamera->Distance() << " ";
7169 else if (anArgCase == "-iod")
7171 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7172 if (anArgValue != NULL
7173 && *anArgValue != '-')
7176 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
7179 theDI << aCamera->IOD() << " ";
7181 else if (anArgCase == "-iodtype")
7183 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
7184 TCollection_AsciiString anValueCase (anArgValue);
7185 anValueCase.LowerCase();
7186 if (anValueCase == "abs"
7187 || anValueCase == "absolute")
7190 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
7193 else if (anValueCase == "rel"
7194 || anValueCase == "relative")
7197 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
7200 else if (*anArgValue != '-')
7202 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
7205 switch (aCamera->GetIODType())
7207 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
7208 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
7211 else if (anArgCase == "-zfocus")
7213 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7214 if (anArgValue != NULL
7215 && *anArgValue != '-')
7218 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
7221 theDI << aCamera->ZFocus() << " ";
7223 else if (anArgCase == "-zfocustype")
7225 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
7226 TCollection_AsciiString anValueCase (anArgValue);
7227 anValueCase.LowerCase();
7228 if (anValueCase == "abs"
7229 || anValueCase == "absolute")
7232 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
7235 else if (anValueCase == "rel"
7236 || anValueCase == "relative")
7239 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
7242 else if (*anArgValue != '-')
7244 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
7247 switch (aCamera->ZFocusType())
7249 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
7250 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
7253 else if (anArgCase == "-fov"
7254 || anArgCase == "-fovy")
7256 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
7257 if (anArgValue != NULL
7258 && *anArgValue != '-')
7261 aCamera->SetFOVy (Draw::Atof (anArgValue));
7264 theDI << aCamera->FOVy() << " ";
7268 std::cout << "Error: unknown argument '" << anArg << "'\n";
7273 aView->View()->AutoZFit();
7279 //==============================================================================
7280 //function : VStereo
7282 //==============================================================================
7284 static int VStereo (Draw_Interpretor& theDI,
7285 Standard_Integer theArgNb,
7286 const char** theArgVec)
7290 Handle(V3d_View) aView = ViewerTest::CurrentView();
7293 std::cerr << "No active view. Please call vinit.\n";
7297 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
7298 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
7302 ViewerTest_myDefaultCaps.contextStereo = Draw::Atoi (theArgVec[1]) != 0;
7306 //===============================================================================================
7307 //function : VDefaults
7309 //===============================================================================================
7310 static int VDefaults (Draw_Interpretor& theDi,
7311 Standard_Integer theArgsNb,
7312 const char** theArgVec)
7314 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
7317 std::cerr << "No active viewer!\n";
7321 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
7324 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
7326 theDi << "DeflType: relative\n"
7327 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
7331 theDi << "DeflType: absolute\n"
7332 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
7334 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
7335 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
7339 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7341 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7343 if (anArg == "-ABSDEFL"
7344 || anArg == "-ABSOLUTEDEFLECTION"
7346 || anArg == "-DEFLECTION")
7348 if (++anArgIter >= theArgsNb)
7350 std::cout << "Error: wrong syntax at " << anArg << "\n";
7353 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
7354 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
7356 else if (anArg == "-RELDEFL"
7357 || anArg == "-RELATIVEDEFLECTION"
7358 || anArg == "-DEVCOEFF"
7359 || anArg == "-DEVIATIONCOEFF"
7360 || anArg == "-DEVIATIONCOEFFICIENT")
7362 if (++anArgIter >= theArgsNb)
7364 std::cout << "Error: wrong syntax at " << anArg << "\n";
7367 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
7368 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
7370 else if (anArg == "-ANGDEFL"
7371 || anArg == "-ANGULARDEFL"
7372 || anArg == "-ANGULARDEFLECTION")
7374 if (++anArgIter >= theArgsNb)
7376 std::cout << "Error: wrong syntax at " << anArg << "\n";
7379 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
7380 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
7382 if (anArg == "-AUTOTR"
7383 || anArg == "-AUTOTRIANG"
7384 || anArg == "-AUTOTRIANGULATION")
7386 if (++anArgIter >= theArgsNb)
7388 std::cout << "Error: wrong syntax at " << anArg << "\n";
7391 TCollection_AsciiString aValue (theArgVec[anArgIter]);
7396 aDefParams->SetAutoTriangulation (Standard_True);
7398 else if (aValue == "off"
7401 aDefParams->SetAutoTriangulation (Standard_False);
7406 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
7413 //! Auxiliary method
7414 inline void addLight (const Handle(V3d_Light)& theLightNew,
7415 const Standard_Boolean theIsGlobal)
7417 if (theLightNew.IsNull())
7424 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
7428 ViewerTest::CurrentView()->SetLightOn (theLightNew);
7432 //! Auxiliary method
7433 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
7435 TCollection_AsciiString anArgNextCase (theArgNext);
7436 anArgNextCase.UpperCase();
7437 if (anArgNextCase.Length() > 5
7438 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
7440 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
7444 return theArgNext.IntegerValue();
7448 //===============================================================================================
7451 //===============================================================================================
7452 static int VLight (Draw_Interpretor& theDi,
7453 Standard_Integer theArgsNb,
7454 const char** theArgVec)
7456 Handle(V3d_View) aView = ViewerTest::CurrentView();
7457 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
7459 || aViewer.IsNull())
7461 std::cerr << "No active viewer!\n";
7465 Standard_Real anXYZ[3];
7466 Quantity_Coefficient anAtten[2];
7469 // print lights info
7470 Standard_Integer aLightId = 0;
7471 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId)
7473 Handle(V3d_Light) aLight = aView->ActiveLight();
7474 const Quantity_Color aColor = aLight->Color();
7475 theDi << "Light" << aLightId << "\n";
7476 switch (aLight->Type())
7480 theDi << " Type: Ambient\n";
7483 case V3d_DIRECTIONAL:
7485 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
7486 theDi << " Type: Directional\n";
7487 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7488 if (!aLightDir.IsNull())
7490 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7491 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7492 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
7493 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7497 case V3d_POSITIONAL:
7499 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
7500 theDi << " Type: Positional\n";
7501 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7502 if (!aLightPos.IsNull())
7504 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7505 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7506 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7507 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
7513 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
7514 theDi << " Type: Spot\n";
7515 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7516 if (!aLightSpot.IsNull())
7518 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7519 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7520 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
7521 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7522 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7523 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
7524 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
7525 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
7531 theDi << " Type: UNKNOWN\n";
7535 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
7539 Handle(V3d_Light) aLightNew;
7540 Handle(V3d_Light) aLightOld;
7541 Standard_Boolean isGlobal = Standard_True;
7542 Standard_Boolean toCreate = Standard_False;
7543 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
7545 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
7546 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
7547 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
7548 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
7549 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
7551 TCollection_AsciiString aName, aValue;
7552 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
7553 TCollection_AsciiString anArgCase (anArg);
7554 anArgCase.UpperCase();
7555 if (anArgCase.IsEqual ("NEW")
7556 || anArgCase.IsEqual ("ADD")
7557 || anArgCase.IsEqual ("CREATE"))
7559 toCreate = Standard_True;
7561 else if (anArgCase.IsEqual ("GLOB")
7562 || anArgCase.IsEqual ("GLOBAL"))
7564 isGlobal = Standard_True;
7566 else if (anArgCase.IsEqual ("LOC")
7567 || anArgCase.IsEqual ("LOCAL"))
7569 isGlobal = Standard_False;
7571 else if (anArgCase.IsEqual ("DEF")
7572 || anArgCase.IsEqual ("DEFAULTS"))
7574 toCreate = Standard_False;
7575 aViewer->SetDefaultLights();
7577 else if (anArgCase.IsEqual ("CLR")
7578 || anArgCase.IsEqual ("CLEAR"))
7580 toCreate = Standard_False;
7581 aView->InitActiveLights();
7582 while (aView->MoreActiveLights())
7584 aViewer->DelLight (aView->ActiveLight());
7585 aView->InitActiveLights();
7588 else if (anArgCase.IsEqual ("AMB")
7589 || anArgCase.IsEqual ("AMBIENT")
7590 || anArgCase.IsEqual ("AMBLIGHT"))
7592 addLight (aLightNew, isGlobal);
7595 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7598 toCreate = Standard_False;
7599 aLightNew = new V3d_AmbientLight (aViewer);
7601 else if (anArgCase.IsEqual ("DIRECTIONAL")
7602 || anArgCase.IsEqual ("DIRLIGHT"))
7604 addLight (aLightNew, isGlobal);
7607 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7610 toCreate = Standard_False;
7611 aLightNew = new V3d_DirectionalLight (aViewer);
7613 else if (anArgCase.IsEqual ("SPOT")
7614 || anArgCase.IsEqual ("SPOTLIGHT"))
7616 addLight (aLightNew, isGlobal);
7619 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7622 toCreate = Standard_False;
7623 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
7625 else if (anArgCase.IsEqual ("POSLIGHT")
7626 || anArgCase.IsEqual ("POSITIONAL"))
7628 addLight (aLightNew, isGlobal);
7631 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7634 toCreate = Standard_False;
7635 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
7637 else if (anArgCase.IsEqual ("CHANGE"))
7639 addLight (aLightNew, isGlobal);
7640 aLightNew.Nullify();
7641 if (++anArgIt >= theArgsNb)
7643 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7647 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
7648 Standard_Integer aLightIt = 0;
7649 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
7651 if (aLightIt == aLightId)
7653 aLightOld = aView->ActiveLight();
7658 if (aLightOld.IsNull())
7660 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
7664 else if (anArgCase.IsEqual ("DEL")
7665 || anArgCase.IsEqual ("DELETE"))
7667 Handle(V3d_Light) aLightDel;
7668 if (++anArgIt >= theArgsNb)
7670 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7674 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
7675 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
7676 Standard_Integer aLightIt = 0;
7677 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
7679 aLightDel = aView->ActiveLight();
7680 if (aLightIt == aLightDelId)
7685 if (!aLightDel.IsNull())
7687 aViewer->DelLight (aLightDel);
7690 else if (anArgCase.IsEqual ("COLOR")
7691 || anArgCase.IsEqual ("COLOUR"))
7693 if (++anArgIt >= theArgsNb)
7695 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7699 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
7700 anArgNext.UpperCase();
7701 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
7702 if (!aLightCurr.IsNull())
7704 aLightCurr->SetColor (aColor);
7707 else if (anArgCase.IsEqual ("POS")
7708 || anArgCase.IsEqual ("POSITION"))
7710 if ((anArgIt + 3) >= theArgsNb)
7712 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7716 anXYZ[0] = Atof (theArgVec[++anArgIt]);
7717 anXYZ[1] = Atof (theArgVec[++anArgIt]);
7718 anXYZ[2] = Atof (theArgVec[++anArgIt]);
7719 if (!aLightDir.IsNull())
7721 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7723 else if (!aLightPos.IsNull())
7725 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7727 else if (!aLightSpot.IsNull())
7729 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7733 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7737 else if (anArgCase.IsEqual ("DIR")
7738 || anArgCase.IsEqual ("DIRECTION"))
7740 if ((anArgIt + 3) >= theArgsNb)
7742 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7746 anXYZ[0] = Atof (theArgVec[++anArgIt]);
7747 anXYZ[1] = Atof (theArgVec[++anArgIt]);
7748 anXYZ[2] = Atof (theArgVec[++anArgIt]);
7749 if (!aLightDir.IsNull())
7751 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
7753 else if (!aLightSpot.IsNull())
7755 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
7759 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7763 else if (anArgCase.IsEqual ("ANG")
7764 || anArgCase.IsEqual ("ANGLE"))
7766 if (++anArgIt >= theArgsNb)
7768 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7772 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
7774 if (!aLightSpot.IsNull())
7776 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
7779 else if (anArgCase.IsEqual ("CONSTATTEN")
7780 || anArgCase.IsEqual ("CONSTATTENUATION"))
7782 if (++anArgIt >= theArgsNb)
7784 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7788 if (!aLightPos.IsNull())
7790 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7791 anAtten[0] = Atof (theArgVec[anArgIt]);
7792 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
7794 else if (!aLightSpot.IsNull())
7796 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7797 anAtten[0] = Atof (theArgVec[anArgIt]);
7798 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
7802 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7806 else if (anArgCase.IsEqual ("LINATTEN")
7807 || anArgCase.IsEqual ("LINEARATTEN")
7808 || anArgCase.IsEqual ("LINEARATTENUATION"))
7810 if (++anArgIt >= theArgsNb)
7812 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7816 if (!aLightPos.IsNull())
7818 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7819 anAtten[1] = Atof (theArgVec[anArgIt]);
7820 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
7822 else if (!aLightSpot.IsNull())
7824 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7825 anAtten[1] = Atof (theArgVec[anArgIt]);
7826 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
7830 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7834 else if (anArgCase.IsEqual ("EXP")
7835 || anArgCase.IsEqual ("EXPONENT")
7836 || anArgCase.IsEqual ("SPOTEXP")
7837 || anArgCase.IsEqual ("SPOTEXPONENT"))
7839 if (++anArgIt >= theArgsNb)
7841 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7845 if (!aLightSpot.IsNull())
7847 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
7851 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7855 else if (anArgCase.IsEqual ("HEAD")
7856 || anArgCase.IsEqual ("HEADLIGHT"))
7858 if (++anArgIt >= theArgsNb)
7860 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7864 if (aLightAmb.IsNull()
7865 && !aLightCurr.IsNull())
7867 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
7871 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7877 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
7881 addLight (aLightNew, isGlobal);
7882 aViewer->UpdateLights();
7887 //=======================================================================
7888 //function : VRenderParams
7889 //purpose : Enables/disables rendering features
7890 //=======================================================================
7892 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
7893 Standard_Integer theArgNb,
7894 const char** theArgVec)
7896 Handle(V3d_View) aView = ViewerTest::CurrentView();
7899 std::cerr << "Error: no active viewer!\n";
7903 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
7904 TCollection_AsciiString aCmdName (theArgVec[0]);
7905 aCmdName.LowerCase();
7906 if (aCmdName == "vraytrace")
7910 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
7913 else if (theArgNb == 2)
7915 TCollection_AsciiString aValue (theArgVec[1]);
7920 aParams.Method = Graphic3d_RM_RAYTRACING;
7924 else if (aValue == "off"
7927 aParams.Method = Graphic3d_RM_RASTERIZATION;
7933 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
7939 std::cout << "Error: wrong number of arguments\n";
7946 theDI << "renderMode: ";
7947 switch (aParams.Method)
7949 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
7950 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
7953 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
7954 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
7955 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
7956 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
7957 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
7958 theDI << "shadingModel: ";
7959 switch (aView->ShadingModel())
7961 case V3d_COLOR: theDI << "color"; break;
7962 case V3d_FLAT: theDI << "flat"; break;
7963 case V3d_GOURAUD: theDI << "gouraud"; break;
7964 case V3d_PHONG: theDI << "phong"; break;
7970 Standard_Boolean toPrint = Standard_False;
7971 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7972 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7974 Standard_CString anArg (theArgVec[anArgIter]);
7975 TCollection_AsciiString aFlag (anArg);
7977 if (anUpdateTool.parseRedrawMode (aFlag))
7981 else if (aFlag == "-echo"
7982 || aFlag == "-print")
7984 toPrint = Standard_True;
7985 anUpdateTool.Invalidate();
7987 else if (aFlag == "-mode"
7988 || aFlag == "-rendermode"
7989 || aFlag == "-render_mode")
7993 switch (aParams.Method)
7995 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
7996 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
8002 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8006 else if (aFlag == "-ray"
8007 || aFlag == "-raytrace")
8011 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
8015 aParams.Method = Graphic3d_RM_RAYTRACING;
8017 else if (aFlag == "-rast"
8018 || aFlag == "-raster"
8019 || aFlag == "-rasterization")
8023 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
8027 aParams.Method = Graphic3d_RM_RASTERIZATION;
8029 else if (aFlag == "-raydepth"
8030 || aFlag == "-ray_depth")
8034 theDI << aParams.RaytracingDepth << " ";
8037 else if (++anArgIter >= theArgNb)
8039 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8043 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
8044 if (aDepth < 1 || aDepth > 10)
8046 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
8051 aParams.RaytracingDepth = aDepth;
8054 else if (aFlag == "-shad"
8055 || aFlag == "-shadows")
8059 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
8063 Standard_Boolean toEnable = Standard_True;
8064 if (++anArgIter < theArgNb
8065 && !parseOnOff (theArgVec[anArgIter], toEnable))
8069 aParams.IsShadowEnabled = toEnable;
8071 else if (aFlag == "-refl"
8072 || aFlag == "-reflections")
8076 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
8080 Standard_Boolean toEnable = Standard_True;
8081 if (++anArgIter < theArgNb
8082 && !parseOnOff (theArgVec[anArgIter], toEnable))
8086 aParams.IsReflectionEnabled = toEnable;
8088 else if (aFlag == "-fsaa")
8092 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
8096 Standard_Boolean toEnable = Standard_True;
8097 if (++anArgIter < theArgNb
8098 && !parseOnOff (theArgVec[anArgIter], toEnable))
8102 aParams.IsAntialiasingEnabled = toEnable;
8104 else if (aFlag == "-gleam")
8108 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
8112 Standard_Boolean toEnable = Standard_True;
8113 if (++anArgIter < theArgNb
8114 && !parseOnOff (theArgVec[anArgIter], toEnable))
8118 aParams.IsTransparentShadowEnabled = toEnable;
8120 else if (aFlag == "-shademodel"
8121 || aFlag == "-shadingmodel"
8122 || aFlag == "-shading")
8126 switch (aView->ShadingModel())
8128 case V3d_COLOR: theDI << "color "; break;
8129 case V3d_FLAT: theDI << "flat "; break;
8130 case V3d_GOURAUD: theDI << "gouraud "; break;
8131 case V3d_PHONG: theDI << "phong "; break;
8136 if (++anArgIter >= theArgNb)
8138 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
8141 TCollection_AsciiString aMode (theArgVec[anArgIter]);
8143 if (aMode == "color"
8146 aView->SetShadingModel (V3d_COLOR);
8148 else if (aMode == "flat"
8149 || aMode == "facet")
8151 aView->SetShadingModel (V3d_FLAT);
8153 else if (aMode == "gouraud"
8154 || aMode == "vertex"
8157 aView->SetShadingModel (V3d_GOURAUD);
8159 else if (aMode == "phong"
8160 || aMode == "fragment"
8162 || aMode == "pixel")
8164 aView->SetShadingModel (V3d_PHONG);
8168 std::cout << "Error: unknown shading model '" << aMode << "'\n";
8174 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
8181 //=======================================================================
8182 //function : VFrustumCulling
8183 //purpose : enables/disables view volume's culling.
8184 //=======================================================================
8185 static int VFrustumCulling (Draw_Interpretor& theDI,
8186 Standard_Integer theArgNb,
8187 const char** theArgVec)
8189 Handle(V3d_View) aView = ViewerTest::CurrentView();
8192 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
8198 theDI << (aView->IsCullingEnabled() ? "on" : "off");
8201 else if (theArgNb != 2)
8203 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
8207 TCollection_AsciiString aModeStr (theArgVec[1]);
8208 aModeStr.LowerCase();
8209 Standard_Boolean toEnable = 0;
8210 if (aModeStr == "on")
8214 else if (aModeStr == "off")
8220 toEnable = Draw::Atoi (theArgVec[1]) != 0;
8223 aView->SetFrustumCulling (toEnable);
8228 //=======================================================================
8229 //function : VHighlightSelected
8231 //=======================================================================
8232 static int VHighlightSelected (Draw_Interpretor& theDI,
8233 Standard_Integer theArgNb,
8234 const char** theArgVec)
8236 if (ViewerTest::GetAISContext().IsNull())
8238 std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n";
8242 const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8246 theDI << (aContext->ToHilightSelected() ? "on" : "off");
8252 std::cout << theArgVec[0] << " error : wrong number of parameters."
8253 << "Type 'help" << theArgVec[0] << "' for more information.";
8258 TCollection_AsciiString aMode (theArgVec[1]);
8260 Standard_Boolean toEnable = Standard_False;
8261 if (aMode.IsEqual ("on"))
8263 toEnable = Standard_True;
8265 else if (aMode.IsEqual ("off"))
8267 toEnable = Standard_False;
8271 toEnable = Draw::Atoi (theArgVec[1]) != 0;
8274 if (toEnable != aContext->ToHilightSelected())
8276 aContext->SetToHilightSelected (toEnable);
8278 // Move cursor to null position and back to process updating of detection
8279 // and highlighting of selected object immediatly.
8280 Standard_Integer aPixX = 0;
8281 Standard_Integer aPixY = 0;
8282 const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager();
8284 anEventManager->GetCurrentPosition (aPixX, aPixY);
8285 anEventManager->MoveTo (0, 0);
8286 anEventManager->MoveTo (aPixX, aPixY);
8292 //=======================================================================
8293 //function : VXRotate
8295 //=======================================================================
8296 static Standard_Integer VXRotate (Draw_Interpretor& di,
8297 Standard_Integer argc,
8300 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
8301 if (aContext.IsNull())
8303 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
8309 di << "ERROR : Usage : " << argv[0] << " name angle" << "\n";
8313 TCollection_AsciiString aName (argv[1]);
8314 Standard_Real anAngle = Draw::Atof (argv[2]);
8317 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
8318 Handle(AIS_InteractiveObject) anIObj;
8319 if (!aMap.IsBound2 (aName) )
8321 di << "Use 'vdisplay' before" << "\n";
8326 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
8329 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
8330 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
8332 aContext->SetLocation (anIObj, aTransform);
8333 aContext->UpdateCurrentViewer();
8339 //=======================================================================
8340 //function : ViewerCommands
8342 //=======================================================================
8344 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
8347 const char *group = "ZeViewer";
8348 theCommands.Add("vinit",
8349 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
8350 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
8352 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
8354 " - Creates new View window with specified name view_name.\n"
8355 "By default the new view is created in the viewer and in"
8356 " graphic driver shared with active view.\n"
8357 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
8358 "If driverName isn't specified the driver will be shared with active view.\n"
8359 "If viewerName isn't specified the viewer will be shared with active view.\n"
8360 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
8361 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
8362 "is used in creation of graphic driver\n"
8364 " - l, t: pixel position of left top corner of the window\n"
8365 " - w,h: width and heigth of window respectively.\n"
8366 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
8367 __FILE__,VInit,group);
8368 theCommands.Add("vclose" ,
8369 "[view_id [keep_context=0|1]]\n"
8370 "or vclose ALL - to remove all created views\n"
8371 " - removes view(viewer window) defined by its view_id.\n"
8372 " - keep_context: by default 0; if 1 and the last view is deleted"
8373 " the current context is not removed.",
8374 __FILE__,VClose,group);
8375 theCommands.Add("vactivate" ,
8377 " - activates view(viewer window) defined by its view_id",
8378 __FILE__,VActivate,group);
8379 theCommands.Add("vviewlist",
8380 "vviewlist [format={tree, long}]"
8381 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
8382 " - format: format of result output, if tree the output is a tree view;"
8383 "otherwise it's a list of full view names. By default format = tree",
8384 __FILE__,VViewList,group);
8385 theCommands.Add("vhelp" ,
8386 "vhelp : display help on the viewer commands",
8387 __FILE__,VHelp,group);
8388 theCommands.Add("vtop" ,
8389 "vtop or <T> : Top view" ,
8390 __FILE__,VTop,group);
8391 theCommands.Add("vbottom" ,
8392 "vbottom : Bottom view" ,
8393 __FILE__,VBottom,group);
8394 theCommands.Add("vleft" ,
8395 "vleft : Left view" ,
8396 __FILE__,VLeft,group);
8397 theCommands.Add("vright" ,
8398 "vright : Right view" ,
8399 __FILE__,VRight,group);
8400 theCommands.Add("vaxo" ,
8401 " vaxo or <A> : Axonometric view ",
8402 __FILE__,VAxo,group);
8403 theCommands.Add("vfront" ,
8404 "vfront : Front view" ,
8405 __FILE__,VFront,group);
8406 theCommands.Add("vback" ,
8407 "vback : Back view" ,
8408 __FILE__,VBack,group);
8409 theCommands.Add("vpick" ,
8410 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
8412 theCommands.Add("vfit" ,
8413 "vfit or <F> : vfit",
8414 __FILE__,VFit,group);
8415 theCommands.Add ("vfitarea",
8416 "vfitarea x1 y1 x2 y2"
8417 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
8418 "\n\t\t: Fit view to show area located between two points"
8419 "\n\t\t: given in world 2D or 3D corrdinates.",
8420 __FILE__, VFitArea, group);
8421 theCommands.Add ("vzfit", "vzfit [scale]\n"
8422 " Matches Z near, Z far view volume planes to the displayed objects.\n"
8423 " \"scale\" - specifies factor to scale computed z range.\n",
8424 __FILE__, VZFit, group);
8425 theCommands.Add("vrepaint",
8426 "vrepaint : vrepaint, force redraw",
8427 __FILE__,VRepaint,group);
8428 theCommands.Add("vclear",
8430 __FILE__,VClear,group);
8431 theCommands.Add("vsetbg",
8432 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
8433 __FILE__,VSetBg,group);
8434 theCommands.Add("vsetbgmode",
8435 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
8436 __FILE__,VSetBgMode,group);
8437 theCommands.Add("vsetgradientbg",
8438 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
8439 __FILE__,VSetGradientBg,group);
8440 theCommands.Add("vsetgrbgmode",
8441 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
8442 __FILE__,VSetGradientBgMode,group);
8443 theCommands.Add("vsetcolorbg",
8444 "vsetcolorbg : vsetcolorbg r g b : Set background color",
8445 __FILE__,VSetColorBg,group);
8446 theCommands.Add("vscale",
8447 "vscale : vscale X Y Z",
8448 __FILE__,VScale,group);
8449 theCommands.Add("vzbufftrihedron",
8450 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
8451 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
8452 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
8453 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
8454 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
8455 "\n\t\t: Displays a trihedron",
8456 __FILE__,VZBuffTrihedron,group);
8457 theCommands.Add("vrotate",
8458 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
8459 "\n : Option -mouseStart starts rotation according to the mouse position"
8460 "\n : Option -mouseMove continues rotation with angle computed"
8461 "\n : from last and new mouse position."
8462 "\n : vrotate AX AY AZ [X Y Z]",
8463 __FILE__,VRotate,group);
8464 theCommands.Add("vzoom",
8465 "vzoom : vzoom coef",
8466 __FILE__,VZoom,group);
8467 theCommands.Add("vpan",
8468 "vpan : vpan dx dy",
8469 __FILE__,VPan,group);
8470 theCommands.Add("vexport",
8471 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
8472 " : exports the view to a vector file of a given format"
8473 " : notice that EMF format requires patched gl2ps",
8474 __FILE__,VExport,group);
8475 theCommands.Add("vcolorscale",
8476 "vcolorscale : vcolorscale [-range RangeMin = 0 RangeMax = 100 Intervals = 10 -font HeightFont = 16 -textpos "
8477 "Position = left -xy X = 0 Y = 0] [-noupdate|-update]: draw color scale\n"
8478 "-demo/-demoversion draw a demoversion of color scale.\n"
8479 "-show/display display color scale.\n"
8480 "-hide/erase erase color scale.\n"
8481 "Please note that -show/-hide option must be the first argument!\n"
8482 "-color Index R G B: set color for indexed interval\n"
8483 "-color Index ColorName: set color for indexed interval\n"
8484 "-colors R G B R G B ...: set colors for all intervals\n"
8485 "-colors ColorName1 ColorName2 ...: set colors for all intervals\n"
8486 "-colors supports both color names and rgb values in one call\n"
8487 "-label Index Text: set label for indexed interval\n"
8488 "-labels Text Text Text ...: set labels for all intervals\n"
8489 "-title Title [Position]: set the title for color scale with certain position. Default position = center;\n"
8490 "Available text positions: left, right, center, none;\n",
8491 __FILE__,VColorScale,group);
8492 theCommands.Add("vgraduatedtrihedron",
8493 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
8494 "\t[-namefont Name] [-valuesfont Name]\n"
8495 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
8496 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
8497 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
8498 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
8499 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
8500 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
8501 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
8502 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
8503 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
8504 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
8505 " - Displays or erases graduated trihedron"
8506 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
8507 " - namefont - font of axes names. Default: Arial\n"
8508 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
8509 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
8510 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
8511 " - valuesfont - font of axes values. Default: Arial\n"
8512 " - xcolor, ycolor, zcolor - color of axis and values\n"
8513 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
8514 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
8515 __FILE__,VGraduatedTrihedron,group);
8516 theCommands.Add("vprintview" ,
8517 "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
8518 __FILE__,VPrintView,group);
8519 theCommands.Add("vzlayer",
8520 "vzlayer add/del/get/settings/enable/disable [id]\n"
8521 " add - add new z layer to viewer and print its id\n"
8522 " del - del z layer by its id\n"
8523 " get - print sequence of z layers in increasing order of their overlay level\n"
8524 " settings - print status of z layer settings\n"
8525 " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n"
8526 " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n"
8527 " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n"
8528 "\nWhere id is the layer identificator\n"
8531 " vzlayer enable poffset 1\n"
8532 " vzlayer disable depthtest 1\n"
8534 __FILE__,VZLayer,group);
8535 theCommands.Add("voverlaytext",
8536 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
8537 " : height - pixel height of the text (default=10.0)"
8538 " : font_name - name of font (default=courier)"
8539 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
8540 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
8541 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
8542 __FILE__,VOverlayText,group);
8543 theCommands.Add("vlayerline",
8544 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
8545 __FILE__,VLayerLine,group);
8546 theCommands.Add ("vgrid",
8547 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
8548 " : Mode - rectangular or circular"
8549 " : Type - lines or points",
8550 __FILE__, VGrid, group);
8551 theCommands.Add ("vpriviledgedplane",
8552 "vpriviledgedplane [Ox Oy Oz Nx Ny Nz [Xx Xy Xz]]"
8553 "\n\t\t: Ox, Oy, Oz - plane origin"
8554 "\n\t\t: Nx, Ny, Nz - plane normal direction"
8555 "\n\t\t: Xx, Xy, Xz - plane x-reference axis direction"
8556 "\n\t\t: Sets or prints viewer's priviledged plane geometry.",
8557 __FILE__, VPriviledgedPlane, group);
8558 theCommands.Add ("vconvert",
8559 "vconvert v [Mode={window|view}]"
8560 "\n\t\t: vconvert x y [Mode={window|view|grid|ray}]"
8561 "\n\t\t: vconvert x y z [Mode={window|grid}]"
8562 "\n\t\t: window - convert to window coordinates, pixels"
8563 "\n\t\t: view - convert to view projection plane"
8564 "\n\t\t: grid - convert to model coordinates, given on grid"
8565 "\n\t\t: ray - convert projection ray to model coordiantes"
8566 "\n\t\t: - vconvert v window : convert view to window;"
8567 "\n\t\t: - vconvert v view : convert window to view;"
8568 "\n\t\t: - vconvert x y window : convert view to window;"
8569 "\n\t\t: - vconvert x y view : convert window to view;"
8570 "\n\t\t: - vconvert x y : convert window to model;"
8571 "\n\t\t: - vconvert x y grid : convert window to model using grid;"
8572 "\n\t\t: - vconvert x y ray : convert window projection line to model;"
8573 "\n\t\t: - vconvert x y z window : convert model to window;"
8574 "\n\t\t: - vconvert x y z grid : convert view to model using grid;"
8575 "\n\t\t: Converts the given coordinates to window/view/model space.",
8576 __FILE__, VConvert, group);
8577 theCommands.Add ("vfps",
8578 "vfps [framesNb=100] : estimate average frame rate for active view",
8579 __FILE__, VFps, group);
8580 theCommands.Add ("vgldebug",
8581 "vgldebug [-sync {0|1}] [-debug {0|1}] [-glslWarn {0|1}]"
8582 "\n\t\t: [-extraMsg {0|1}] [{0|1}]"
8583 "\n\t\t: Request debug GL context. Should be called BEFORE vinit."
8584 "\n\t\t: Debug context can be requested only on Windows"
8585 "\n\t\t: with GL_ARB_debug_output extension implemented by GL driver!"
8586 "\n\t\t: -sync - request synchronized debug GL context"
8587 "\n\t\t: -glslWarn - log GLSL compiler/linker warnings,"
8588 "\n\t\t: which are suppressed by default,"
8589 "\n\t\t: -extraMsg - log extra diagnostic messages from GL context,"
8590 "\n\t\t: which are suppressed by default",
8591 __FILE__, VGlDebug, group);
8592 theCommands.Add ("vvbo",
8593 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
8594 __FILE__, VVbo, group);
8595 theCommands.Add ("vstereo",
8596 "\nvstereo [{0|1}] : turn stereo usage On/Off; affects only newly displayed objects",
8597 __FILE__, VStereo, group);
8598 theCommands.Add ("vcaps",
8599 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
8600 "\n\t\t: [-compatibleContext {0|1}]"
8601 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
8602 "\n\t\t: Modify particular graphic driver options:"
8603 "\n\t\t: FFP - use fixed-function pipeline instead of"
8604 "\n\t\t: built-in GLSL programs"
8605 "\n\t\t: (requires compatible profile)"
8606 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
8607 "\n\t\t: arrays to GPU memory)"
8608 "\n\t\t: sprite - use textured sprites instead of bitmaps"
8609 "\n\t\t: Context creation options:"
8610 "\n\t\t: softMode - software OpenGL implementation"
8611 "\n\t\t: compatibleProfile - backward-compatible profile"
8612 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
8613 "\n\t\t: rendering paths producing the same visual result when"
8615 "\n\t\t: Command is intended for testing old hardware compatibility.",
8616 __FILE__, VCaps, group);
8617 theCommands.Add ("vmemgpu",
8618 "vmemgpu [f]: print system-dependent GPU memory information if available;"
8619 " with f option returns free memory in bytes",
8620 __FILE__, VMemGpu, group);
8621 theCommands.Add ("vreadpixel",
8622 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
8623 " : Read pixel value for active view",
8624 __FILE__, VReadPixel, group);
8625 theCommands.Add("diffimage",
8626 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
8627 __FILE__, VDiffImage, group);
8628 theCommands.Add ("vselect",
8629 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
8630 "- emulates different types of selection:\n"
8631 "- 1) single click selection\n"
8632 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
8633 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
8634 "- 4) any of these selections with shift button pressed",
8635 __FILE__, VSelect, group);
8636 theCommands.Add ("vmoveto",
8638 "- emulates cursor movement to pixel postion (x,y)",
8639 __FILE__, VMoveTo, group);
8640 theCommands.Add ("vviewparams", "vviewparams usage:\n"
8642 "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n"
8643 " [-proj [x y z]] [-center x y] [-size sx]\n"
8644 "- Gets or sets current view parameters.\n"
8645 "- If called without arguments, all view parameters are printed.\n"
8646 "- The options are:\n"
8647 " -scale [s] : prints or sets viewport relative scale.\n"
8648 " -eye [x y z] : prints or sets eye location.\n"
8649 " -at [x y z] : prints or sets center of look.\n"
8650 " -up [x y z] : prints or sets direction of up vector.\n"
8651 " -proj [x y z] : prints or sets direction of look.\n"
8652 " -center x y : sets location of center of the screen in pixels.\n"
8653 " -size [sx] : prints viewport projection width and height sizes\n"
8654 " : or changes the size of its maximum dimension.\n",
8655 __FILE__, VViewParams, group);
8656 theCommands.Add("vchangeselected",
8657 "vchangeselected shape"
8658 "- adds to shape to selection or remove one from it",
8659 __FILE__, VChangeSelected, group);
8660 theCommands.Add("vzclipping",
8661 "vzclipping [mode] [depth width]\n"
8662 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
8663 "- gets or sets ZClipping mode, width and depth",
8664 __FILE__,VZClipping,group);
8665 theCommands.Add ("vnbselected",
8666 "vnbselected", __FILE__, VNbSelected, group);
8667 theCommands.Add ("vcamera",
8668 "vcamera [-ortho] [-projtype]"
8670 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
8671 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
8672 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
8673 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
8674 "\n\t\t: Manage camera parameters."
8675 "\n\t\t: Prints current value when option called without argument."
8676 "\n\t\t: Orthographic camera:"
8677 "\n\t\t: -ortho activate orthographic projection"
8678 "\n\t\t: Perspective camera:"
8679 "\n\t\t: -persp activate perspective projection (mono)"
8680 "\n\t\t: -fovy field of view in y axis, in degrees"
8681 "\n\t\t: -distance distance of eye from camera center"
8682 "\n\t\t: Stereoscopic camera:"
8683 "\n\t\t: -stereo perspective projection (stereo)"
8684 "\n\t\t: -leftEye perspective projection (left eye)"
8685 "\n\t\t: -rightEye perspective projection (right eye)"
8686 "\n\t\t: -iod intraocular distance value"
8687 "\n\t\t: -iodType distance type, absolute or relative"
8688 "\n\t\t: -zfocus stereographic focus value"
8689 "\n\t\t: -zfocusType focus type, absolute or relative",
8690 __FILE__, VCamera, group);
8691 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
8692 "- vautozfit [on={1|0}] [scale]\n"
8693 " Prints or changes parameters of automatic z-fit mode:\n"
8694 " \"on\" - turns automatic z-fit on or off\n"
8695 " \"scale\" - specifies factor to scale computed z range.\n",
8696 __FILE__, VAutoZFit, group);
8697 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
8698 " vzrange - without parameters shows current values\n"
8699 " vzrange [znear] [zfar] - applies provided values to view",
8700 __FILE__,VZRange, group);
8701 theCommands.Add("vantialiasing",
8702 "vantialiasing 1|0",
8703 __FILE__,VAntialiasing,group);
8704 theCommands.Add ("vpurgedisplay",
8706 "- removes structures which don't belong to objects displayed in neutral point",
8707 __FILE__, VPurgeDisplay, group);
8708 theCommands.Add("vsetviewsize",
8709 "vsetviewsize size",
8710 __FILE__,VSetViewSize,group);
8711 theCommands.Add("vmoveview",
8712 "vmoveview Dx Dy Dz [Start = 1|0]",
8713 __FILE__,VMoveView,group);
8714 theCommands.Add("vtranslateview",
8715 "vtranslateview Dx Dy Dz [Start = 1|0)]",
8716 __FILE__,VTranslateView,group);
8717 theCommands.Add("vturnview",
8718 "vturnview Ax Ay Az [Start = 1|0]",
8719 __FILE__,VTurnView,group);
8720 theCommands.Add("vtextureenv",
8721 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
8722 "or user-defined file and optionally applying texture mapping parameters\n"
8724 " vtextureenv off - disables environment mapping\n"
8725 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
8726 " std_texture = (0..7)\n"
8727 " rep = {clamp|repeat}\n"
8728 " mod = {decal|modulate}\n"
8729 " flt = {nearest|bilinear|trilinear}\n"
8730 " ss, st - scale factors for s and t texture coordinates\n"
8731 " ts, tt - translation for s and t texture coordinates\n"
8732 " rot - texture rotation angle in degrees",
8733 __FILE__, VTextureEnv, group);
8734 theCommands.Add("vhlr" ,
8735 "is_enabled={on|off} [show_hidden={1|0}]"
8736 " - Hidden line removal algorithm:"
8737 " - is_enabled: if is on HLR algorithm is applied\n"
8738 " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n",
8739 __FILE__,VHLR,group);
8740 theCommands.Add("vhlrtype" ,
8741 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
8742 " - Changes the type of HLR algorithm using for shapes."
8743 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
8744 " if equals to polyalgo, polygonal HLR algorithm is applied."
8745 "If shapes are not given HLR algoithm of given type is applied"
8746 " to all shapes in the view\n",
8747 __FILE__,VHLRType,group);
8748 theCommands.Add("vclipplane", "vclipplane usage: \n"
8749 " maxplanes <view_name> - get plane limit for view.\n"
8750 " create <plane_name> - create new plane.\n"
8751 " delete <plane_name> - delete plane.\n"
8752 " clone <source_plane> <plane_name> - clone the plane definition.\n"
8753 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
8754 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
8755 " change <plane_name> on/off - turn clipping on/off.\n"
8756 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
8757 " change <plane_name> capping on/off - turn capping on/off.\n"
8758 " change <plane_name> capping color <r> <g> <b> - set color.\n"
8759 " change <plane name> capping texname <texture> - set texture.\n"
8760 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
8761 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
8762 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
8763 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
8764 " please use VSetTextureMode command to enable texture rendering in view.\n"
8765 , __FILE__, VClipPlane, group);
8766 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
8768 " 0 - no textures enabled in view.\n"
8769 " 1 - only environment textures enabled.\n"
8770 " 2 - all textures enabled.\n"
8771 " this command sets texture details mode for the specified view.\n"
8772 , __FILE__, VSetTextureMode, group);
8773 theCommands.Add("vdefaults",
8774 "vdefaults [-absDefl value]"
8775 "\n\t\t: [-devCoeff value]"
8776 "\n\t\t: [-angDefl value]"
8777 "\n\t\t: [-autoTriang {off/on | 0/1}]"
8778 , __FILE__, VDefaults, group);
8779 theCommands.Add("vlight",
8780 "tool to manage light sources, without arguments shows list of lights."
8781 "\n Main commands: "
8782 "\n 'clear' to clear lights"
8783 "\n '{def}aults' to load deafault lights"
8784 "\n 'add' (or 'new') <type> to add any light source"
8785 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
8786 "\n 'change' <lightId> to edit light source with specified lightId"
8787 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
8788 "\n {pos}ition X Y Z"
8789 "\n {dir}ection X Y Z (for directional light or for spotlight)"
8790 "\n color colorName"
8791 "\n {head}light 0|1"
8792 "\n {constAtten}uation value"
8793 "\n {linearAtten}uation value"
8795 "\n {spotexp}onent value"
8797 "\n\n example: vlight add positional head 1 pos 0 1 1 color red"
8798 "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
8799 __FILE__, VLight, group);
8800 theCommands.Add("vraytrace",
8802 "\n\t\t: Turn on/off raytracing renderer."
8803 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
8804 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
8805 __FILE__, VRenderParams, group);
8806 theCommands.Add("vrenderparams",
8807 "\n Manages rendering parameters: "
8808 "\n '-rayTrace' Enables GPU ray-tracing"
8809 "\n '-raster' Disables GPU ray-tracing"
8810 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
8811 "\n '-shadows on|off' Enables/disables shadows rendering"
8812 "\n '-reflections on|off' Enables/disables specular reflections"
8813 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
8814 "\n '-gleam on|off' Enables/disables transparency shadow effects"
8815 "\n '-shadingModel model' Controls shading model from enumeration"
8816 "\n color, flat, gouraud, phong"
8817 "\n Unlike vcaps, these parameters dramatically change visual properties."
8818 "\n Command is intended to control presentation quality depending on"
8819 "\n hardware capabilities and performance.",
8820 __FILE__, VRenderParams, group);
8821 theCommands.Add("vfrustumculling",
8822 "vfrustumculling [toEnable]: enables/disables objects clipping",
8823 __FILE__,VFrustumCulling,group);
8824 theCommands.Add("vhighlightselected",
8825 "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n"
8826 "Without arguments it shows if highlighting of selected objects is enabled now.",
8827 __FILE__,VHighlightSelected,group);
8828 theCommands.Add ("vplace",
8830 "\n\t\t: Places the point (in pixels) at the center of the window",
8831 __FILE__, VPlace, group);
8832 theCommands.Add("vxrotate",
8834 __FILE__,VXRotate,group);