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 ) {
1659 static Standard_Real CurZPos = 0.;
1661 //Quantity_Length VDX, VDY;
1662 //a3DView->Size(VDX,VDY);
1663 //Standard_Real VDZ = a3DView->ZSize();
1664 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1666 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1668 // Front = Depth + width/2.
1669 Standard_Real D = 0.5;
1670 Standard_Real W = 0.1;
1676 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1678 a3DView->SetZClippingType(V3d_OFF);
1679 a3DView->SetZClippingDepth(D);
1680 a3DView->SetZClippingWidth(W);
1681 a3DView->SetZClippingType(V3d_FRONT);
1685 X_ButtonPress = X_Motion;
1686 Y_ButtonPress = Y_Motion;
1690 //==============================================================================
1691 //function : ProcessControlButton1Motion
1693 //==============================================================================
1695 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1696 static void ProcessControlButton1Motion()
1698 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1700 X_ButtonPress = X_Motion;
1701 Y_ButtonPress = Y_Motion;
1705 //==============================================================================
1706 //function : VT_ProcessControlButton2Motion
1708 //==============================================================================
1709 void VT_ProcessControlButton2Motion()
1711 Standard_Integer aDx = X_Motion - X_ButtonPress;
1712 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1714 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1716 ViewerTest::CurrentView()->Pan (aDx, aDy);
1718 X_ButtonPress = X_Motion;
1719 Y_ButtonPress = Y_Motion;
1722 //==============================================================================
1723 //function : VT_ProcessControlButton3Motion
1724 //purpose : Rotation
1725 //==============================================================================
1726 void VT_ProcessControlButton3Motion()
1730 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1734 //==============================================================================
1735 //function : VT_ProcessMotion
1737 //==============================================================================
1738 void VT_ProcessMotion()
1740 //pre-hilights detected objects at mouse position
1742 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1743 EM->MoveTo(X_Motion, Y_Motion);
1747 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1749 Xpix = X_Motion;Ypix=Y_Motion;
1752 //==============================================================================
1753 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1754 //purpose : Switches to an axonometric, top, left and other views
1755 //==============================================================================
1757 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1759 if ( ViewerTest::CurrentView().IsNull() )
1761 di<<"Call vinit before this command, please"<<"\n";
1765 ViewerTest::CurrentView()->SetProj(ori);
1769 //==============================================================================
1771 //purpose : Switch to an Axonometric view
1772 //Draw arg : No args
1773 //==============================================================================
1775 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1777 return ViewProject(di, V3d_XposYnegZpos);
1780 //==============================================================================
1782 //purpose : Switch to a Top View
1783 //Draw arg : No args
1784 //==============================================================================
1786 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1788 return ViewProject(di, V3d_Zpos);
1791 //==============================================================================
1792 //function : VBottom
1793 //purpose : Switch to a Bottom View
1794 //Draw arg : No args
1795 //==============================================================================
1797 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1799 return ViewProject(di, V3d_Zneg);
1802 //==============================================================================
1804 //purpose : Switch to a Left View
1805 //Draw arg : No args
1806 //==============================================================================
1808 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1810 return ViewProject(di, V3d_Ypos);
1813 //==============================================================================
1815 //purpose : Switch to a Right View
1816 //Draw arg : No args
1817 //==============================================================================
1819 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1821 return ViewProject(di, V3d_Yneg);
1824 //==============================================================================
1826 //purpose : Switch to a Front View
1827 //Draw arg : No args
1828 //==============================================================================
1830 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1832 return ViewProject(di, V3d_Xpos);
1835 //==============================================================================
1837 //purpose : Switch to a Back View
1838 //Draw arg : No args
1839 //==============================================================================
1841 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1843 return ViewProject(di, V3d_Xneg);
1846 //==============================================================================
1848 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1849 //Draw arg : No args
1850 //==============================================================================
1852 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1855 di << "Q : Quit the application" << "\n";
1857 di << "========================="<<"\n";
1858 di << "F : FitAll" << "\n";
1859 di << "T : TopView" << "\n";
1860 di << "B : BottomView" << "\n";
1861 di << "R : RightView" << "\n";
1862 di << "L : LeftView" << "\n";
1863 di << "A : AxonometricView" << "\n";
1864 di << "D : ResetView" << "\n";
1866 di << "========================="<<"\n";
1867 di << "S : Shading" << "\n";
1868 di << "W : Wireframe" << "\n";
1869 di << "H : HidelLineRemoval" << "\n";
1870 di << "U : Unset display mode" << "\n";
1871 di << "Delete : Remove selection from viewer" << "\n";
1873 di << "========================="<<"\n";
1874 di << "Selection mode "<<"\n";
1875 di << "0 : Shape" <<"\n";
1876 di << "1 : Vertex" <<"\n";
1877 di << "2 : Edge" <<"\n";
1878 di << "3 : Wire" <<"\n";
1879 di << "4 : Face" <<"\n";
1880 di << "5 : Shell" <<"\n";
1881 di << "6 : Solid" <<"\n";
1882 di << "7 : Compound" <<"\n";
1884 di << "========================="<<"\n";
1885 di << "Z : Switch Z clipping On/Off" << "\n";
1886 di << ", : Hilight next detected" << "\n";
1887 di << ". : Hilight previous detected" << "\n";
1894 static Standard_Boolean Ppick = 0;
1895 static Standard_Integer Pargc = 0;
1896 static const char** Pargv = NULL;
1899 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1904 if (!ViewerTest_myViews.IsEmpty()) {
1906 WPARAM fwKeys = wParam;
1911 // Delete view from map of views
1912 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1917 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1918 || ViewerTest::CurrentView().IsNull())
1920 // Activate inactive window
1921 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1923 ActivateView (FindViewIdByWindowHandle(hwnd));
1930 HDC hdc = GetDC( hwnd );
1931 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1932 SetROP2( hdc, R2_NOT );
1933 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1934 ReleaseDC( hwnd, hdc );
1935 VT_ProcessButton1Release (fwKeys & MK_SHIFT);
1937 IsDragged = Standard_False;
1938 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1940 case WM_LBUTTONDOWN:
1941 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1943 IsDragged = Standard_True;
1944 DragFirst = Standard_True;
1945 X_ButtonPress = LOWORD(lParam);
1946 Y_ButtonPress = HIWORD(lParam);
1948 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1955 HDC hdc = GetDC( hwnd );
1957 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1958 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1959 SetROP2( hdc, R2_NOT );
1962 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1964 DragFirst = Standard_False;
1965 X_Motion = LOWORD(lParam);
1966 Y_Motion = HIWORD(lParam);
1968 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1970 SelectObject( hdc, anObj );
1972 ReleaseDC( hwnd, hdc );
1975 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1979 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1983 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1987 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1994 if ( !ViewerTest::CurrentView().IsNull() ) {
1999 BeginPaint(hwnd, &ps);
2000 EndPaint(hwnd, &ps);
2005 VT_ProcessConfigure();
2009 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2012 c[0] = (char) wParam;
2014 if (wParam == VK_DELETE)
2016 c[0] = THE_KEY_DELETE;
2019 else if (wParam == VK_OEM_COMMA)
2024 else if (wParam == VK_OEM_PERIOD)
2028 VT_ProcessKeyPress (c);
2036 VT_ProcessButton3Release();
2039 case WM_LBUTTONDOWN:
2040 case WM_MBUTTONDOWN:
2041 case WM_RBUTTONDOWN:
2043 WPARAM fwKeys = wParam;
2047 X_ButtonPress = LOWORD(lParam);
2048 Y_ButtonPress = HIWORD(lParam);
2050 if (Msg == WM_LBUTTONDOWN)
2052 if (fwKeys & MK_CONTROL)
2054 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2058 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2061 else if (Msg == WM_RBUTTONDOWN)
2064 VT_ProcessButton3Press();
2071 //cout << "\t WM_MOUSEMOVE" << endl;
2072 WPARAM fwKeys = wParam;
2073 X_Motion = LOWORD(lParam);
2074 Y_Motion = HIWORD(lParam);
2077 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2079 X_ButtonPress = LOWORD(lParam);
2080 Y_ButtonPress = HIWORD(lParam);
2082 if ( fwKeys & MK_RBUTTON ) {
2084 VT_ProcessButton3Press();
2088 if ( fwKeys & MK_CONTROL ) {
2089 if ( fwKeys & MK_LBUTTON ) {
2090 ProcessControlButton1Motion();
2092 else if ( fwKeys & MK_MBUTTON ||
2093 ((fwKeys&MK_LBUTTON) &&
2094 (fwKeys&MK_RBUTTON) ) ){
2095 VT_ProcessControlButton2Motion();
2097 else if ( fwKeys & MK_RBUTTON ) {
2098 VT_ProcessControlButton3Motion();
2102 else if ( fwKeys & MK_SHIFT ) {
2103 if ( fwKeys & MK_MBUTTON ||
2104 ((fwKeys&MK_LBUTTON) &&
2105 (fwKeys&MK_RBUTTON) ) ) {
2106 cout << "ProcessZClipMotion()" << endl;
2107 ProcessZClipMotion();
2111 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2113 if ((fwKeys & MK_MBUTTON
2114 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2116 ProcessZClipMotion();
2127 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2132 return DefWindowProc( hwnd, Msg, wParam, lParam );
2138 //==============================================================================
2139 //function : ViewerMainLoop
2140 //purpose : Get a Event on the view and dispatch it
2141 //==============================================================================
2144 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2146 Ppick = (argc > 0)? 1 : 0;
2154 cout << "Start picking" << endl;
2156 while ( Ppick == 1 ) {
2157 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2158 if (GetMessage(&msg, NULL, 0, 0) ) {
2159 TranslateMessage(&msg);
2160 DispatchMessage(&msg);
2164 cout << "Picking done" << endl;
2170 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2172 int min( int a, int b )
2180 int max( int a, int b )
2188 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2191 static XEvent aReport;
2192 Standard_Boolean pick = argc > 0;
2193 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2194 XNextEvent (aDisplay, &aReport);
2196 // Handle event for the chosen display connection
2197 switch (aReport.type) {
2200 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2203 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2209 // Activate inactive view
2210 Window aWindow = GetWindowHandle(VT_GetWindow());
2211 if(aWindow != aReport.xfocus.window)
2213 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2222 case ConfigureNotify:
2224 VT_ProcessConfigure();
2233 XComposeStatus status_in_out;
2235 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2236 (char *) buf_ret , 10 ,
2237 &ks_ret , &status_in_out ) ;
2240 buf_ret[ret_len] = '\0' ;
2244 VT_ProcessKeyPress (buf_ret);
2250 X_ButtonPress = aReport.xbutton.x;
2251 Y_ButtonPress = aReport.xbutton.y;
2253 if (aReport.xbutton.button == Button1)
2255 if (aReport.xbutton.state & ControlMask)
2257 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2261 IsDragged = Standard_True;
2262 DragFirst = Standard_True;
2265 else if (aReport.xbutton.button == Button3)
2268 VT_ProcessButton3Press();
2278 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2279 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2280 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2283 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2284 if( aContext.IsNull() )
2286 cout << "The context is null. Please use vinit before createmesh" << endl;
2290 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2291 if( aReport.xbutton.button==1 )
2295 aContext->ShiftSelect();
2304 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2305 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2306 ViewerTest::CurrentView());
2310 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2311 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2312 ViewerTest::CurrentView() );
2315 VT_ProcessButton3Release();
2317 IsDragged = Standard_False;
2320 VT_ProcessButton3Release();
2325 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2331 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2332 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2333 XSetFunction( aDisplay, gc, GXinvert );
2336 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2338 X_Motion = aReport.xmotion.x;
2339 Y_Motion = aReport.xmotion.y;
2340 DragFirst = Standard_False;
2342 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2346 X_Motion = aReport.xmotion.x;
2347 Y_Motion = aReport.xmotion.y;
2349 // remove all the ButtonMotionMaskr
2350 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2352 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2353 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2355 Quantity_Length VDX, VDY;
2357 ViewerTest::CurrentView()->Size(VDX,VDY);
2358 Standard_Real VDZ =0 ;
2359 VDZ = ViewerTest::CurrentView()->ZSize();
2361 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2363 Quantity_Length dx = 0 ;
2364 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2368 dx = dx / VDX * VDZ;
2372 ViewerTest::CurrentView()->Redraw();
2376 if ( aReport.xmotion.state & ControlMask ) {
2377 if ( aReport.xmotion.state & Button1Mask ) {
2378 ProcessControlButton1Motion();
2380 else if ( aReport.xmotion.state & Button2Mask ) {
2381 VT_ProcessControlButton2Motion();
2383 else if ( aReport.xmotion.state & Button3Mask ) {
2384 VT_ProcessControlButton3Motion();
2398 //==============================================================================
2399 //function : VProcessEvents
2400 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2401 // event in the Viewer window
2402 //==============================================================================
2404 static void VProcessEvents(ClientData,int)
2406 NCollection_Vector<int> anEventNumbers;
2407 // Get number of messages from every display
2408 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2409 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2411 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2413 // Handle events for every display
2414 int anEventIter = 0;
2415 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2416 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2418 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2419 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2421 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2422 int anEventResult = ViewerMainLoop( 0, NULL);
2423 // If window is closed or context was not found finish current event processing loop
2429 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2434 //==============================================================================
2435 //function : OSWindowSetup
2436 //purpose : Setup for the X11 window to be able to cath the event
2437 //==============================================================================
2440 static void OSWindowSetup()
2442 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2445 Window window = VT_GetWindow()->XWindow();
2446 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2447 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2448 XSynchronize(aDisplay, 1);
2450 // X11 : For keyboard on SUN
2452 wmhints.flags = InputHint;
2455 XSetWMHints( aDisplay, window, &wmhints);
2457 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2458 ButtonPressMask | ButtonReleaseMask |
2459 StructureNotifyMask |
2461 Button1MotionMask | Button2MotionMask |
2462 Button3MotionMask | FocusChangeMask
2464 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2465 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2467 XSynchronize(aDisplay, 0);
2476 //==============================================================================
2479 //purpose : Fitall, no DRAW arguments
2480 //Draw arg : No args
2481 //==============================================================================
2483 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2485 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2486 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2487 if (V.IsNull() == Standard_False) {
2489 } else if (aView.IsNull() == Standard_False) {
2495 //=======================================================================
2496 //function : VFitArea
2497 //purpose : Fit view to show area located between two points
2498 // : given in world 2D or 3D coordinates.
2499 //=======================================================================
2500 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2502 Handle(V3d_View) aView = ViewerTest::CurrentView();
2505 std::cerr << theArgVec[0] << "Error: No active view.\n";
2510 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2511 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2515 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2516 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2517 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2518 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2520 else if (theArgNb == 7)
2522 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2523 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2524 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2525 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2526 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2527 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2531 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2532 theDI.PrintHelp(theArgVec[0]);
2536 // Convert model coordinates to view space
2537 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2538 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2539 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2541 // Determine fit area
2542 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2543 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2545 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2547 if (aDiagonal < Precision::Confusion())
2549 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2553 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2557 //==============================================================================
2559 //purpose : ZFitall, no DRAW arguments
2560 //Draw arg : No args
2561 //==============================================================================
2562 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2564 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2566 if (aCurrentView.IsNull())
2568 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2574 aCurrentView->View()->ZFitAll();
2575 aCurrentView->Redraw();
2579 Standard_Real aScale = 1.0;
2583 aScale = Draw::Atoi (theArgVec[1]);
2586 aCurrentView->View()->ZFitAll (aScale);
2587 aCurrentView->Redraw();
2592 //==============================================================================
2593 //function : VRepaint
2595 //==============================================================================
2596 static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
2598 Handle(V3d_View) V = ViewerTest::CurrentView();
2599 if ( !V.IsNull() ) V->Redraw(); return 0;
2602 //==============================================================================
2604 //purpose : Remove all the object from the viewer
2605 //Draw arg : No args
2606 //==============================================================================
2608 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2610 Handle(V3d_View) V = ViewerTest::CurrentView();
2612 ViewerTest::Clear();
2616 //==============================================================================
2619 //==============================================================================
2621 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2622 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2625 di << argv[0] << "Invalid number of arguments" << "\n";
2629 while (ViewerMainLoop( argc, argv)) {
2635 //==============================================================================
2637 //purpose : Load image as background
2638 //==============================================================================
2640 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2642 if (argc < 2 || argc > 3)
2644 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2645 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2649 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2650 if(AISContext.IsNull())
2652 di << "use 'vinit' command before " << argv[0] << "\n";
2656 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2659 const char* szType = argv[2];
2660 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2661 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2662 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2663 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2666 di << "Wrong fill type : " << szType << "\n";
2667 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2672 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2673 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2678 //==============================================================================
2679 //function : VSetBgMode
2680 //purpose : Change background image fill type
2681 //==============================================================================
2683 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2687 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2688 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2692 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2693 if(AISContext.IsNull())
2695 di << "use 'vinit' command before " << argv[0] << "\n";
2698 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2699 const char* szType = argv[1];
2700 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2701 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2702 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2703 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2706 di << "Wrong fill type : " << szType << "\n";
2707 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2710 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2711 V3dView->SetBgImageStyle(aFillType, Standard_True);
2715 //==============================================================================
2716 //function : VSetGradientBg
2717 //purpose : Mount gradient background
2718 //==============================================================================
2719 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2723 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2724 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2725 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2726 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2730 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2731 if(AISContext.IsNull())
2733 di << "use 'vinit' command before " << argv[0] << "\n";
2739 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2740 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2741 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2742 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2744 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2745 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2746 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2748 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2749 int aType = Draw::Atoi(argv[7]);
2750 if( aType < 0 || aType > 8 )
2752 di << "Wrong fill type " << "\n";
2753 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2754 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2758 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2760 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2761 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2767 //==============================================================================
2768 //function : VSetGradientBgMode
2769 //purpose : Change gradient background fill style
2770 //==============================================================================
2771 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2775 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2776 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2777 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2781 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2782 if(AISContext.IsNull())
2784 di << "use 'vinit' command before " << argv[0] << "\n";
2789 int aType = Draw::Atoi(argv[1]);
2790 if( aType < 0 || aType > 8 )
2792 di << "Wrong fill type " << "\n";
2793 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2794 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2798 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2800 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2801 V3dView->SetBgGradientStyle( aMethod, 1 );
2807 //==============================================================================
2808 //function : VSetColorBg
2809 //purpose : Set color background
2810 //==============================================================================
2811 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2815 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2816 di << "R,G,B = [0..255]" << "\n";
2820 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2821 if(AISContext.IsNull())
2823 di << "use 'vinit' command before " << argv[0] << "\n";
2829 Standard_Real R = Draw::Atof(argv[1])/255.;
2830 Standard_Real G = Draw::Atof(argv[2])/255.;
2831 Standard_Real B = Draw::Atof(argv[3])/255.;
2832 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2834 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2835 V3dView->SetBackgroundColor( aColor );
2842 //==============================================================================
2844 //purpose : View Scaling
2845 //==============================================================================
2847 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2849 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2850 if ( V3dView.IsNull() ) return 1;
2853 di << argv[0] << "Invalid number of arguments" << "\n";
2856 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2859 //==============================================================================
2860 //function : VZBuffTrihedron
2862 //==============================================================================
2864 static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/,
2865 Standard_Integer theArgNb,
2866 const char** theArgVec)
2868 Handle(V3d_View) aView = ViewerTest::CurrentView();
2871 std::cout << "Error: no active viewer!\n";
2875 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
2877 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2878 V3d_TypeOfVisualization aVisType = V3d_ZBUFFER;
2879 Quantity_Color aLabelsColor = Quantity_NOC_WHITE;
2880 Quantity_Color anArrowColorX = Quantity_NOC_RED;
2881 Quantity_Color anArrowColorY = Quantity_NOC_GREEN;
2882 Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1;
2883 Standard_Real aScale = 0.1;
2884 Standard_Real aSizeRatio = 0.8;
2885 Standard_Real anArrowDiam = 0.05;
2886 Standard_Integer aNbFacets = 12;
2887 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2889 Standard_CString anArg = theArgVec[anArgIter];
2890 TCollection_AsciiString aFlag (anArg);
2892 if (anUpdateTool.parseRedrawMode (aFlag))
2896 else if (aFlag == "-on")
2900 else if (aFlag == "-off")
2902 aView->TriedronErase();
2905 else if (aFlag == "-pos"
2906 || aFlag == "-position"
2907 || aFlag == "-corner")
2909 if (++anArgIter >= theArgNb)
2911 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
2915 TCollection_AsciiString aPosName (theArgVec[anArgIter]);
2916 aPosName.LowerCase();
2917 if (aPosName == "center")
2919 aPosition = Aspect_TOTP_CENTER;
2921 else if (aPosName == "left_lower"
2922 || aPosName == "lower_left"
2923 || aPosName == "leftlower"
2924 || aPosName == "lowerleft")
2926 aPosition = Aspect_TOTP_LEFT_LOWER;
2928 else if (aPosName == "left_upper"
2929 || aPosName == "upper_left"
2930 || aPosName == "leftupper"
2931 || aPosName == "upperleft")
2933 aPosition = Aspect_TOTP_LEFT_UPPER;
2935 else if (aPosName == "right_lower"
2936 || aPosName == "lower_right"
2937 || aPosName == "rightlower"
2938 || aPosName == "lowerright")
2940 aPosition = Aspect_TOTP_RIGHT_LOWER;
2942 else if (aPosName == "right_upper"
2943 || aPosName == "upper_right"
2944 || aPosName == "rightupper"
2945 || aPosName == "upperright")
2947 aPosition = Aspect_TOTP_RIGHT_UPPER;
2951 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n";
2955 else if (aFlag == "-type")
2957 if (++anArgIter >= theArgNb)
2959 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
2963 TCollection_AsciiString aTypeName (theArgVec[anArgIter]);
2964 aTypeName.LowerCase();
2965 if (aTypeName == "wireframe"
2966 || aTypeName == "wire")
2968 aVisType = V3d_WIREFRAME;
2970 else if (aTypeName == "zbuffer"
2971 || aTypeName == "shaded")
2973 aVisType = V3d_ZBUFFER;
2977 std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n";
2980 else if (aFlag == "-scale")
2982 if (++anArgIter >= theArgNb)
2984 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
2988 aScale = Draw::Atof (theArgVec[anArgIter]);
2990 else if (aFlag == "-size"
2991 || aFlag == "-sizeratio")
2993 if (++anArgIter >= theArgNb)
2995 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
2999 aSizeRatio = Draw::Atof (theArgVec[anArgIter]);
3001 else if (aFlag == "-arrowdiam"
3002 || aFlag == "-arrowdiameter")
3004 if (++anArgIter >= theArgNb)
3006 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3010 anArrowDiam = Draw::Atof (theArgVec[anArgIter]);
3012 else if (aFlag == "-nbfacets")
3014 if (++anArgIter >= theArgNb)
3016 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3020 aNbFacets = Draw::Atoi (theArgVec[anArgIter]);
3022 else if (aFlag == "-colorlabel"
3023 || aFlag == "-colorlabels")
3025 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3026 theArgVec + anArgIter + 1,
3030 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3033 anArgIter += aNbParsed;
3035 else if (aFlag == "-colorarrowx")
3037 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3038 theArgVec + anArgIter + 1,
3042 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3045 anArgIter += aNbParsed;
3047 else if (aFlag == "-colorarrowy")
3049 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3050 theArgVec + anArgIter + 1,
3054 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3057 anArgIter += aNbParsed;
3059 else if (aFlag == "-colorarrowz")
3061 Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1,
3062 theArgVec + anArgIter + 1,
3066 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3069 anArgIter += aNbParsed;
3073 std::cerr << "Error: wrong syntax at '" << anArg << "'\n";
3078 aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(),
3079 aSizeRatio, anArrowDiam, aNbFacets);
3080 aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType);
3081 aView->View()->ZFitAll();
3085 //==============================================================================
3086 //function : VRotate
3087 //purpose : Camera Rotating
3088 //==============================================================================
3090 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
3092 Handle(V3d_View) aView = ViewerTest::CurrentView();
3095 std::cout << "No active view!\n";
3099 Standard_Boolean hasFlags = Standard_False;
3100 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3102 Standard_CString anArg (theArgVec[anArgIter]);
3103 TCollection_AsciiString aFlag (anArg);
3105 if (aFlag == "-mousestart"
3106 || aFlag == "-mousefrom")
3108 hasFlags = Standard_True;
3109 if (anArgIter + 2 >= theArgNb)
3111 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3115 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3116 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3117 aView->StartRotation (anX, anY);
3119 else if (aFlag == "-mousemove")
3121 hasFlags = Standard_True;
3122 if (anArgIter + 2 >= theArgNb)
3124 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3128 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
3129 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
3130 aView->Rotation (anX, anY);
3132 else if (theArgNb != 4
3135 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3144 else if (theArgNb == 4)
3146 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3147 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3148 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3149 aView->Rotate (anAX, anAY, anAZ);
3152 else if (theArgNb == 7)
3154 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3155 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3156 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3158 Standard_Real anX = Draw::Atof (theArgVec[4]);
3159 Standard_Real anY = Draw::Atof (theArgVec[5]);
3160 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3162 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3166 std::cout << "Error: Invalid number of arguments\n";
3170 //==============================================================================
3172 //purpose : View zoom in / out (relative to current zoom)
3173 //==============================================================================
3175 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3176 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3177 if ( V3dView.IsNull() ) {
3182 Standard_Real coef = Draw::Atof(argv[1]);
3183 if ( coef <= 0.0 ) {
3184 di << argv[1] << "Invalid value" << "\n";
3187 V3dView->SetZoom( Draw::Atof(argv[1]) );
3190 di << argv[0] << " Invalid number of arguments" << "\n";
3195 //==============================================================================
3197 //purpose : View panning (in pixels)
3198 //==============================================================================
3200 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3201 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3202 if ( V3dView.IsNull() ) return 1;
3205 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
3208 di << argv[0] << " Invalid number of arguments" << "\n";
3213 //==============================================================================
3215 //purpose : Place the point (in pixels) at the center of the window
3216 //==============================================================================
3217 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3219 Handle(V3d_View) aView = ViewerTest::CurrentView();
3222 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3228 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3232 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3237 //==============================================================================
3238 //function : VExport
3239 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
3240 //==============================================================================
3242 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3244 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3245 if (V3dView.IsNull())
3250 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
3254 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
3255 TCollection_AsciiString aFormatStr;
3257 TCollection_AsciiString aFileName (argv[1]);
3258 Standard_Integer aLen = aFileName.Length();
3262 aFormatStr = TCollection_AsciiString (argv[2]);
3266 if (aFileName.Value (aLen - 2) == '.')
3268 aFormatStr = aFileName.SubString (aLen - 1, aLen);
3270 else if (aFileName.Value (aLen - 3) == '.')
3272 aFormatStr = aFileName.SubString (aLen - 2, aLen);
3276 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3282 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3286 aFormatStr.UpperCase();
3287 if (aFormatStr == "PS")
3288 anExpFormat = Graphic3d_EF_PostScript;
3289 else if (aFormatStr == "EPS")
3290 anExpFormat = Graphic3d_EF_EnhPostScript;
3291 else if (aFormatStr == "TEX")
3292 anExpFormat = Graphic3d_EF_TEX;
3293 else if (aFormatStr == "PDF")
3294 anExpFormat = Graphic3d_EF_PDF;
3295 else if (aFormatStr == "SVG")
3296 anExpFormat = Graphic3d_EF_SVG;
3297 else if (aFormatStr == "PGF")
3298 anExpFormat = Graphic3d_EF_PGF;
3299 else if (aFormatStr == "EMF")
3300 anExpFormat = Graphic3d_EF_EMF;
3303 std::cout << "Invalid export format '" << aFormatStr << "'\n";
3308 if (!V3dView->View()->Export (argv[1], anExpFormat))
3310 di << "Error: export of image to " << aFormatStr << " failed!\n";
3313 catch (Standard_Failure)
3315 di << "Error: export of image to " << aFormatStr << " failed";
3316 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
3321 //==============================================================================
3322 //function : VColorScale
3323 //purpose : representation color scale
3324 //==============================================================================
3326 static Standard_Boolean checkColor (const TCollection_AsciiString& theRed,
3327 const TCollection_AsciiString& theGreen,
3328 const TCollection_AsciiString& theBlue,
3329 Standard_Real& theRedValue,
3330 Standard_Real& theGreenValue,
3331 Standard_Real& theBlueValue)
3333 if (!theRed.IsRealValue()
3334 || !theGreen.IsRealValue()
3335 || !theBlue.IsRealValue())
3337 std::cout << "Error: RGB color values should be real!\n";
3338 return Standard_True;
3340 theRedValue = theRed .RealValue();
3341 theGreenValue = theGreen.RealValue();
3342 theBlueValue = theBlue .RealValue();
3343 if (theRedValue < 0.0 || theRedValue > 1.0
3344 || theGreenValue < 0.0 || theGreenValue > 1.0
3345 || theBlueValue < 0.0 || theBlueValue > 1.0)
3347 std::cout << "Error: RGB color values should be within range 0..1!\n";
3348 return Standard_True;
3350 return Standard_False;
3353 static int VColorScale (Draw_Interpretor& theDI,
3354 Standard_Integer theArgNb,
3355 const char** theArgVec)
3357 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3358 Handle(V3d_View) aView = ViewerTest::CurrentView();
3359 if (aContext.IsNull())
3361 std::cout << "Error: no active view!\n";
3365 Handle(V3d_ColorScale) aCS = Handle(V3d_ColorScale)::DownCast (aView->ColorScale());
3368 std::cout << "Error: color scale is undefined!\n";
3372 Standard_Real aMinRange = aCS->GetMin();
3373 Standard_Real aMaxRange = aCS->GetMax();
3374 Standard_Integer aNbIntervals = aCS->GetNumberOfIntervals();
3375 Standard_Integer aTextHeight = aCS->GetTextHeight();
3376 Aspect_TypeOfColorScalePosition aLabPosition = aCS->GetLabelPosition();
3377 gp_XY aPos (aCS->GetXPosition(), aCS->GetYPosition());
3379 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
3383 theDI << "Current color scale parameters:\n"
3384 << "Min range: " << aMinRange << "\n"
3385 << "Max range: " << aMaxRange << "\n"
3386 << "Number of intervals: " << aNbIntervals << "\n"
3387 << "Text height: " << aTextHeight << "\n"
3388 << "Color scale position: " << aPos.X() <<" "<< aPos.Y()<< "\n"
3389 << "Color scale title: " << aCS->GetTitle() << "\n"
3390 << "Label position: ";
3391 switch (aLabPosition)
3393 case Aspect_TOCSP_NONE:
3396 case Aspect_TOCSP_LEFT:
3399 case Aspect_TOCSP_RIGHT:
3402 case Aspect_TOCSP_CENTER:
3403 theDI << "Center\n";
3408 Standard_CString aFirstArg = theArgVec[1];
3409 TCollection_AsciiString aFlag (aFirstArg);
3411 if (aFlag == "-hide" ||
3416 std::cout << "Error: wrong syntax at argument '" << theArgVec[1] << "'!\n";
3419 if (!aView->ColorScaleIsDisplayed())
3421 std::cout << "Error: color scale is not displayed!\n";
3426 aView->ColorScaleErase();
3430 else if (aFlag == "-show" ||
3431 aFlag == "-display")
3435 std::cout << "Error: wrong syntax at argument '" << theArgVec[1] << "'!\n";
3438 aView->ColorScaleDisplay();
3442 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3444 Standard_CString anArg = theArgVec[anArgIter];
3445 TCollection_AsciiString aFlag (anArg);
3447 if (anUpdateTool.parseRedrawMode (aFlag))
3451 else if (aFlag == "-range")
3453 if (anArgIter + 3 >= theArgNb)
3455 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3459 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
3460 TCollection_AsciiString anArg2 (theArgVec[++anArgIter]);
3461 TCollection_AsciiString anArg3 (theArgVec[++anArgIter]);
3462 if (!anArg1.IsRealValue())
3464 std::cout << "Error: the minRange value should be real!\n";
3467 else if (!anArg2.IsRealValue())
3469 std::cout << "Error: the maxRange value should be real!\n";
3472 else if (!anArg3.IsIntegerValue())
3474 std::cout << "Error: the number of intervals should be integer!\n";
3478 aMinRange = anArg1.RealValue();
3479 aMaxRange = anArg2.RealValue();
3480 aNbIntervals = anArg3.IntegerValue();
3482 else if (aFlag == "-font")
3484 if (anArgIter + 1 >= theArgNb)
3486 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3489 TCollection_AsciiString anArg (theArgVec[anArgIter + 1]);
3490 if (!anArg.IsIntegerValue())
3492 std::cout << "Error: HeightFont value should be integer!\n";
3496 aTextHeight = anArg.IntegerValue();
3499 else if (aFlag == "-textpos")
3501 if (anArgIter + 1 >= theArgNb)
3503 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3506 TCollection_AsciiString anArg (theArgVec[++anArgIter]);
3508 if (anArg == "none")
3510 aLabPosition = Aspect_TOCSP_NONE;
3512 else if (anArg == "left")
3514 aLabPosition = Aspect_TOCSP_LEFT;
3516 else if (anArg == "right")
3518 aLabPosition = Aspect_TOCSP_RIGHT;
3520 else if (anArg == "center")
3522 aLabPosition = Aspect_TOCSP_CENTER;
3526 std::cout << "Error: unknown position '" << anArg << "'!\n";
3530 else if (aFlag == "-xy")
3532 if (anArgIter + 2 >= theArgNb)
3534 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3538 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3539 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3540 if (!aX.IsRealValue()
3541 || !aY.IsRealValue())
3543 std::cout << "Error: coordinates should be real values!\n";
3547 aPos.SetCoord (aX.RealValue(), aY.RealValue());
3549 else if (aFlag == "-color")
3551 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3553 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3557 Quantity_NameOfColor aColorName;
3558 if (anArgIter + 4 >= theArgNb)
3560 if (anArgIter + 2 >= theArgNb)
3562 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3565 else if (!Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3567 std::cout << "Error: wrong color name: '" << theArgVec[anArgIter + 2] << "' !\n";
3572 TCollection_AsciiString anInd (theArgVec[anArgIter + 1]);
3573 if (!anInd.IsIntegerValue())
3575 std::cout << "Error: Index value should be integer!\n";
3579 Standard_Integer anIndex = anInd.IntegerValue();
3581 || anIndex > aNbIntervals - 1)
3583 std::cout << "Error: Index value should be within range 0..." << (aNbIntervals - 1) <<"!\n";
3587 if (Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3589 aCS->SetColor (Quantity_Color (aColorName), anIndex);
3590 aCS->SetColorType(Aspect_TOCSD_USER);
3595 TCollection_AsciiString aRed (theArgVec[anArgIter + 2]);
3596 TCollection_AsciiString aGreen (theArgVec[anArgIter + 3]);
3597 TCollection_AsciiString aBlue (theArgVec[anArgIter + 4]);
3598 Standard_Real aRedValue,aGreenValue, aBlueValue;
3599 if(checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3603 aCS->SetColor (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB), anIndex);
3604 aCS->SetColorType (Aspect_TOCSD_USER);
3607 else if (aFlag == "-label")
3609 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3611 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
3614 else if (anArgIter + 2 >= theArgNb)
3616 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3620 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
3622 || anIndex > aNbIntervals)
3624 std::cout << "Error: Index value should be within range 0..." << aNbIntervals <<"!\n";
3628 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
3629 aCS->SetLabel (aText, anIndex);
3630 aCS->SetLabelType (Aspect_TOCSD_USER);
3633 else if (aFlag == "-colors")
3635 Aspect_SequenceOfColor aSeq;
3636 if (anArgIter + aNbIntervals + 1 > theArgNb)
3638 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3639 << aNbIntervals << " intervals\n";
3643 Standard_Integer aColorIter = anArgIter + 1;
3644 while (aColorIter < theArgNb)
3646 if (theArgVec[aColorIter][0] == '-')
3651 else if (theArgVec[aColorIter][0] >= 97
3652 && theArgVec[aColorIter][0] <= 122)
3654 Quantity_NameOfColor aColorName;
3655 if (!Quantity_Color::ColorFromName (theArgVec[aColorIter], aColorName))
3657 std::cout << "Error: wrong color name: " << theArgVec[aColorIter] << " !\n";
3660 aSeq.Append (Quantity_Color (aColorName));
3666 TCollection_AsciiString aRed (theArgVec[aColorIter]);
3667 TCollection_AsciiString aGreen (theArgVec[aColorIter + 1]);
3668 TCollection_AsciiString aBlue (theArgVec[aColorIter + 2]);
3669 Standard_Real aRedValue,aGreenValue, aBlueValue;
3670 if (checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3674 aSeq.Append (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB));
3679 if (aSeq.Length() < aNbIntervals)
3681 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3682 << aNbIntervals << " intervals\n";
3686 aCS->SetColors (aSeq);
3687 aCS->SetColorType (Aspect_TOCSD_USER);
3689 else if (aFlag == "-labels")
3691 if (anArgIter + aNbIntervals + 1 >= theArgNb)
3693 std::cout << "Error: not enough arguments! You should provide " << (aNbIntervals + 1)
3694 << " text labels for " << aNbIntervals << " intervals.\n";
3698 TColStd_SequenceOfExtendedString aSeq;
3699 for (int aLabelIter = anArgIter + 1; aLabelIter <= anArgIter + aNbIntervals + 1; aLabelIter += 1)
3701 aSeq.Append (TCollection_ExtendedString (theArgVec[aLabelIter]));
3703 aCS->SetLabels (aSeq);
3704 aCS->SetLabelType (Aspect_TOCSD_USER);
3705 anArgIter += aSeq.Length();
3707 else if (aFlag == "-title")
3709 if (anArgIter + 1 >= theArgNb)
3711 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3715 Standard_Boolean isTwoArgs = Standard_False;
3716 if (anArgIter + 2 < theArgNb)
3718 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
3719 aSecondArg.LowerCase();
3720 if (aSecondArg == "none")
3722 aCS->SetTitlePosition (Aspect_TOCSP_NONE);
3723 isTwoArgs = Standard_True;
3725 else if (aSecondArg == "left")
3727 aCS->SetTitlePosition (Aspect_TOCSP_LEFT);
3728 isTwoArgs = Standard_True;
3730 else if (aSecondArg == "right")
3732 aCS->SetTitlePosition (Aspect_TOCSP_RIGHT);
3733 isTwoArgs = Standard_True;
3735 else if (aSecondArg == "center")
3737 aCS->SetTitlePosition (Aspect_TOCSP_CENTER);
3738 isTwoArgs = Standard_True;
3742 aCS->SetTitle (theArgVec[anArgIter + 1]);
3749 else if (aFlag == "-demoversion"
3750 || aFlag == "-demo")
3752 aPos.SetCoord (0.0, 0.0);
3757 aLabPosition = Aspect_TOCSP_RIGHT;
3758 aCS->SetColorType(Aspect_TOCSD_AUTO);
3759 aCS->SetLabelType(Aspect_TOCSD_AUTO);
3763 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
3768 aCS->SetPosition (aPos.X(), aPos.Y());
3769 aCS->SetHeight (0.95);
3770 aCS->SetTextHeight (aTextHeight);
3771 aCS->SetRange (aMinRange, aMaxRange);
3772 aCS->SetNumberOfIntervals (aNbIntervals);
3773 aCS->SetLabelPosition (aLabPosition);
3775 if (!aView->ColorScaleIsDisplayed())
3777 aView->ColorScaleDisplay();
3783 //==============================================================================
3784 //function : VGraduatedTrihedron
3785 //purpose : Displays or hides a graduated trihedron
3786 //==============================================================================
3787 static Standard_Boolean GetColor (const TCollection_AsciiString& theValue,
3788 Quantity_Color& theColor)
3790 Quantity_NameOfColor aColorName;
3791 TCollection_AsciiString aVal = theValue;
3793 if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName))
3795 return Standard_False;
3797 theColor = Quantity_Color (aColorName);
3798 return Standard_True;
3801 static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs)
3805 std::cout << theArgs[0] << " error: wrong number of parameters. Type 'help"
3806 << theArgs[0] <<"' for more information.\n";
3807 return 1; //TCL_ERROR
3810 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
3811 TCollection_AsciiString aParseKey;
3812 for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt)
3814 TCollection_AsciiString anArg (theArgs [anArgIt]);
3816 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3819 aParseKey.Remove (1);
3820 aParseKey.LowerCase();
3821 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
3825 if (aParseKey.IsEmpty())
3830 aMapOfArgs(aParseKey)->Append (anArg);
3834 for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
3835 aMapIt.More(); aMapIt.Next())
3837 const TCollection_AsciiString& aKey = aMapIt.Key();
3838 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
3840 // Bool key, without arguments
3841 if ((aKey.IsEqual ("on") || aKey.IsEqual ("off"))
3842 && anArgs->IsEmpty())
3848 if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname"))
3849 && anArgs->Length() == 1)
3855 if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname")
3856 || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks")
3857 || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")
3858 || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes"))
3859 && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off")))
3864 // One string argument
3865 if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor")
3866 || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor"))
3867 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
3872 // One integer argument
3873 if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks")
3874 || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength")
3875 || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset")
3876 || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset"))
3877 && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue())
3882 // One real argument
3883 if ( aKey.IsEqual ("arrowlength")
3884 && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue()))
3889 // Two string arguments
3890 if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont"))
3891 && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue())
3896 TCollection_AsciiString aLowerKey;
3899 aLowerKey.LowerCase();
3900 std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3901 std::cout << "Type help for more information.\n";
3905 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3906 if (anAISContext.IsNull())
3908 std::cout << theArgs[0] << ": " << " please use 'vinit' command to initialize view.\n";
3912 Standard_Boolean toDisplay = Standard_True;
3913 Quantity_Color aColor;
3914 Graphic3d_GraduatedTrihedron aTrihedronData;
3915 // Process parameters
3916 Handle(TColStd_HSequenceOfAsciiString) aValues;
3917 if (aMapOfArgs.Find ("off", aValues))
3919 toDisplay = Standard_False;
3923 if (aMapOfArgs.Find ("xname", aValues))
3925 aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1));
3927 if (aMapOfArgs.Find ("yname", aValues))
3929 aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1));
3931 if (aMapOfArgs.Find ("zname", aValues))
3933 aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1));
3935 if (aMapOfArgs.Find ("xdrawname", aValues))
3937 aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
3939 if (aMapOfArgs.Find ("ydrawname", aValues))
3941 aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
3943 if (aMapOfArgs.Find ("zdrawname", aValues))
3945 aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on"));
3947 if (aMapOfArgs.Find ("xnameoffset", aValues))
3949 aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
3951 if (aMapOfArgs.Find ("ynameoffset", aValues))
3953 aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
3955 if (aMapOfArgs.Find ("znameoffset", aValues))
3957 aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue());
3961 if (aMapOfArgs.Find ("xnamecolor", aValues))
3963 if (!GetColor (aValues->Value(1), aColor))
3965 std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n";
3968 aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor);
3970 if (aMapOfArgs.Find ("ynamecolor", aValues))
3972 if (!GetColor (aValues->Value(1), aColor))
3974 std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n";
3977 aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor);
3979 if (aMapOfArgs.Find ("znamecolor", aValues))
3981 if (!GetColor (aValues->Value(1), aColor))
3983 std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n";
3986 aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor);
3988 if (aMapOfArgs.Find ("xcolor", aValues))
3990 if (!GetColor (aValues->Value(1), aColor))
3992 std::cout << theArgs[0] << "error: -xcolor wrong color name.\n";
3995 aTrihedronData.ChangeXAxisAspect().SetColor (aColor);
3997 if (aMapOfArgs.Find ("ycolor", aValues))
3999 if (!GetColor (aValues->Value(1), aColor))
4001 std::cout << theArgs[0] << "error: -ycolor wrong color name.\n";
4004 aTrihedronData.ChangeYAxisAspect().SetColor (aColor);
4006 if (aMapOfArgs.Find ("zcolor", aValues))
4008 if (!GetColor (aValues->Value(1), aColor))
4010 std::cout << theArgs[0] << "error: -zcolor wrong color name.\n";
4013 aTrihedronData.ChangeZAxisAspect().SetColor (aColor);
4017 if (aMapOfArgs.Find ("xticks", aValues))
4019 aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4021 if (aMapOfArgs.Find ("yticks", aValues))
4023 aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4025 if (aMapOfArgs.Find ("zticks", aValues))
4027 aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue());
4029 if (aMapOfArgs.Find ("xticklength", aValues))
4031 aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4033 if (aMapOfArgs.Find ("yticklength", aValues))
4035 aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4037 if (aMapOfArgs.Find ("zticklength", aValues))
4039 aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue());
4041 if (aMapOfArgs.Find ("xdrawticks", aValues))
4043 aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4045 if (aMapOfArgs.Find ("ydrawticks", aValues))
4047 aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4049 if (aMapOfArgs.Find ("zdrawticks", aValues))
4051 aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on"));
4055 if (aMapOfArgs.Find ("xdrawvalues", aValues))
4057 aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4059 if (aMapOfArgs.Find ("ydrawvalues", aValues))
4061 aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4063 if (aMapOfArgs.Find ("zdrawvalues", aValues))
4065 aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on"));
4067 if (aMapOfArgs.Find ("xvaluesoffset", aValues))
4069 aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4071 if (aMapOfArgs.Find ("yvaluesoffset", aValues))
4073 aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4075 if (aMapOfArgs.Find ("zvaluesoffset", aValues))
4077 aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue());
4081 if (aMapOfArgs.Find ("arrowlength", aValues))
4083 aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue());
4087 if (aMapOfArgs.Find ("namefont", aValues))
4089 aTrihedronData.SetNamesFont (aValues->Value(1));
4091 if (aMapOfArgs.Find ("valuesfont", aValues))
4093 aTrihedronData.SetValuesFont (aValues->Value(1));
4096 if (aMapOfArgs.Find ("drawgrid", aValues))
4098 aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on"));
4100 if (aMapOfArgs.Find ("drawaxes", aValues))
4102 aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on"));
4105 // The final step: display of erase trihedron
4108 ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData);
4112 ViewerTest::CurrentView()->GraduatedTrihedronErase();
4115 ViewerTest::GetAISContext()->UpdateCurrentViewer();
4116 ViewerTest::CurrentView()->Redraw();
4121 //==============================================================================
4122 //function : VPrintView
4123 //purpose : Test printing algorithm, print the view to image file with given
4124 // width and height. Printing implemented only for WNT.
4125 //==============================================================================
4126 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
4130 di << "Printing implemented only for wnt!\n";
4134 Handle(AIS_InteractiveContext) aContextAIS = NULL;
4135 Handle(V3d_View) aView = NULL;
4136 aContextAIS = ViewerTest::GetAISContext();
4137 if (!aContextAIS.IsNull())
4139 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
4140 Vwr->InitActiveViews();
4141 if(Vwr->MoreActiveViews())
4142 aView = Vwr->ActiveView();
4148 di << "Call vinit before!\n";
4153 di << "Use: " << argv[0];
4154 di << " width height filename [print algo=0] [tile_width tile_height]\n";
4155 di << "width, height of the intermediate buffer for operation\n";
4156 di << "algo : {0|1}\n";
4157 di << " 0 - stretch algorithm\n";
4158 di << " 1 - tile algorithm\n";
4159 di << "test printing algorithms into an intermediate buffer\n";
4160 di << "using specific tile size if provided\n";
4161 di << "with saving output to an image file\n";
4165 // get the input params
4166 Standard_Integer aWidth = Draw::Atoi (argv[1]);
4167 Standard_Integer aHeight = Draw::Atoi (argv[2]);
4168 Standard_Integer aMode = 0;
4169 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
4171 aMode = Draw::Atoi (argv[4]);
4173 Standard_Integer aTileWidth = 0;
4174 Standard_Integer aTileHeight = 0;
4175 Standard_Boolean isTileSizeProvided = Standard_False;
4178 isTileSizeProvided = Standard_True;
4179 aTileWidth = Draw::Atoi (argv[5]);
4180 aTileHeight = Draw::Atoi (argv[6]);
4183 // check the input parameters
4184 if (aWidth <= 0 || aHeight <= 0)
4186 di << "Width and height must be positive values!\n";
4189 if (aMode != 0 && aMode != 1)
4192 // define compatible bitmap
4193 HDC anDC = CreateCompatibleDC(0);
4194 BITMAPINFO aBitmapData;
4195 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
4196 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
4197 aBitmapData.bmiHeader.biWidth = aWidth ;
4198 aBitmapData.bmiHeader.biHeight = aHeight;
4199 aBitmapData.bmiHeader.biPlanes = 1;
4200 aBitmapData.bmiHeader.biBitCount = 24;
4201 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
4202 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
4203 aBitmapData.bmiHeader.biClrUsed = 0;
4204 aBitmapData.bmiHeader.biClrImportant = 0;
4205 aBitmapData.bmiHeader.biCompression = BI_RGB;
4206 aBitmapData.bmiHeader.biSizeImage = 0;
4208 // Create Device Independent Bitmap
4209 void* aBitsOut = NULL;
4210 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
4211 &aBitsOut, NULL, 0);
4212 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
4214 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
4215 if (aBitsOut != NULL)
4218 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
4221 if (isTileSizeProvided)
4223 Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView());
4224 Graphic3d_PtrFrameBuffer anOldBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO);
4225 aCView->ptrFBO = aView->View()->FBOCreate (aTileWidth, aTileHeight);
4227 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
4229 Graphic3d_PtrFrameBuffer aNewBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO);
4230 aView->View()->FBORelease (aNewBuffer);
4231 aCView->ptrFBO = anOldBuffer;
4235 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
4239 // succesfully printed into an intermediate buffer
4242 Image_PixMap aWrapper;
4243 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
4244 aWrapper.SetTopDown (false);
4246 Image_AlienPixMap anImageBitmap;
4247 anImageBitmap.InitCopy (aWrapper);
4248 isSaved = anImageBitmap.Save (aFileName);
4252 di << "Print operation failed due to printing errors or\n";
4253 di << "insufficient memory available\n";
4254 di << "Please, try to use smaller dimensions for this test\n";
4255 di << "command, as it allocates intermediate buffer for storing\n";
4256 di << "the result\n";
4261 di << "Can't allocate memory for intermediate buffer\n";
4262 di << "Please use smaller dimensions\n";
4267 SelectObject (anDC, anOldBitmap);
4268 DeleteObject (aMemoryBitmap);
4274 di << "Save to file operation failed. This operation may fail\n";
4275 di << "if you don't have enough available memory, then you can\n";
4276 di << "use smaller dimensions for the output file\n";
4285 //==============================================================================
4286 //function : VZLayer
4287 //purpose : Test z layer operations for v3d viewer
4288 //==============================================================================
4289 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4291 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
4292 if (aContextAIS.IsNull())
4294 di << "Call vinit before!\n";
4299 di << "Use: vzlayer ";
4300 di << " add/del/get/settings/enable/disable [id]\n";
4301 di << " add - add new z layer to viewer and print its id\n";
4302 di << " del - del z layer by its id\n";
4303 di << " get - print sequence of z layers in increasing order of their overlay level\n";
4304 di << " settings - print status of z layer settings\n";
4305 di << " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n";
4306 di << " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n";
4307 di << " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n";
4308 di << "\nWhere id is the layer identificator\n";
4309 di << "\nExamples:\n";
4310 di << " vzlayer add\n";
4311 di << " vzlayer enable poffset 1\n";
4312 di << " vzlayer disable depthtest 1\n";
4313 di << " vzlayer del 1\n";
4317 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
4318 if (aViewer.IsNull())
4320 di << "No active viewer!\n";
4324 // perform operation
4325 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
4328 Standard_Integer aNewId;
4329 if (!aViewer->AddZLayer (aNewId))
4331 di << "Impossible to add new z layer!\n";
4335 di << "New z layer added with index: " << aNewId << "\n";
4337 else if (anOp == "del")
4341 di << "Please also provide as argument id of z layer to remove\n";
4345 Standard_Integer aDelId = Draw::Atoi (argv[2]);
4346 if (!aViewer->RemoveZLayer (aDelId))
4348 di << "Impossible to remove the z layer or invalid id!\n";
4352 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4353 anObjIter.More(); anObjIter.Next())
4355 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1());
4357 || aPrs->ZLayer() != aDelId)
4361 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
4364 di << "Z layer " << aDelId << " has been removed\n";
4366 else if (anOp == "get")
4368 TColStd_SequenceOfInteger anIds;
4369 aViewer->GetAllZLayers (anIds);
4370 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
4372 di << anIds.Value (aSeqIdx) << " ";
4377 else if (anOp == "settings")
4381 di << "Please also provide an id\n";
4385 Standard_Integer anId = Draw::Atoi (argv[2]);
4386 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4388 di << "Depth test - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthTest) ? "enabled" : "disabled") << "\n";
4389 di << "Depth write - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthWrite) ? "enabled" : "disabled") << "\n";
4390 di << "Depth buffer clearing - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthClear) ? "enabled" : "disabled") << "\n";
4391 di << "Depth offset - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthOffset) ? "enabled" : "disabled") << "\n";
4394 else if (anOp == "enable")
4398 di << "Please also provide an option to enable\n";
4404 di << "Please also provide a layer id\n";
4408 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
4409 Standard_Integer anId = Draw::Atoi (argv[3]);
4410 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4412 if (aSubOp == "depthtest" || aSubOp == "test")
4414 aSettings.EnableSetting (Graphic3d_ZLayerDepthTest);
4416 else if (aSubOp == "depthwrite" || aSubOp == "write")
4418 aSettings.EnableSetting (Graphic3d_ZLayerDepthWrite);
4420 else if (aSubOp == "depthclear" || aSubOp == "clear")
4422 aSettings.EnableSetting (Graphic3d_ZLayerDepthClear);
4424 else if (aSubOp == "depthoffset" || aSubOp == "offset")
4428 di << "Please also provide a factor and units values for depth offset\n";
4429 di << "Format is: vzlayer enable offset [factor] [units] [layerId]\n";
4433 Standard_ShortReal aFactor = static_cast<Standard_ShortReal> (Draw::Atof (argv[3]));
4434 Standard_ShortReal aUnits = static_cast<Standard_ShortReal> (Draw::Atof (argv[4]));
4435 anId = Draw::Atoi (argv[5]);
4436 aSettings = aViewer->ZLayerSettings (anId);
4438 aSettings.DepthOffsetFactor = aFactor;
4439 aSettings.DepthOffsetUnits = aUnits;
4441 aSettings.EnableSetting (Graphic3d_ZLayerDepthOffset);
4443 else if (aSubOp == "positiveoffset" || aSubOp == "poffset")
4445 aSettings.SetDepthOffsetPositive();
4447 else if (aSubOp == "negativeoffset" || aSubOp == "noffset")
4449 aSettings.SetDepthOffsetNegative();
4452 aViewer->SetZLayerSettings (anId, aSettings);
4454 else if (anOp == "disable")
4458 di << "Please also provide an option to disable\n";
4464 di << "Please also provide a layer id\n";
4468 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
4469 Standard_Integer anId = Draw::Atoi (argv[3]);
4470 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4472 if (aSubOp == "depthtest" || aSubOp == "test")
4474 aSettings.DisableSetting (Graphic3d_ZLayerDepthTest);
4476 else if (aSubOp == "depthwrite" || aSubOp == "write")
4478 aSettings.DisableSetting (Graphic3d_ZLayerDepthWrite);
4480 else if (aSubOp == "depthclear" || aSubOp == "clear")
4482 aSettings.DisableSetting (Graphic3d_ZLayerDepthClear);
4484 else if (aSubOp == "depthoffset" || aSubOp == "offset")
4486 aSettings.DisableSetting (Graphic3d_ZLayerDepthOffset);
4489 aViewer->SetZLayerSettings (anId, aSettings);
4493 di << "Invalid operation, please use { add / del / get / settings / enable / disable}\n";
4500 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
4502 // this class provides a presentation of text item in v3d view under-/overlayer
4503 class V3d_TextItem : public Visual3d_LayerItem
4508 DEFINE_STANDARD_RTTI(V3d_TextItem)
4511 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
4512 const Standard_Real theX1,
4513 const Standard_Real theY1,
4514 const Standard_Real theHeight,
4515 const TCollection_AsciiString& theFontName,
4516 const Quantity_Color& theColor,
4517 const Quantity_Color& theSubtitleColor,
4518 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
4519 const Handle(Visual3d_Layer)& theLayer);
4522 Standard_EXPORT void RedrawLayerPrs();
4528 TCollection_AsciiString myText;
4529 Standard_Real myHeight;
4530 Handle(Visual3d_Layer) myLayer;
4531 Quantity_Color myColor;
4532 Quantity_Color mySubtitleColor;
4533 Aspect_TypeOfDisplayText myType;
4534 TCollection_AsciiString myFontName;
4537 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
4538 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
4540 // create and add to display the text item
4541 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
4542 const Standard_Real theX1,
4543 const Standard_Real theY1,
4544 const Standard_Real theHeight,
4545 const TCollection_AsciiString& theFontName,
4546 const Quantity_Color& theColor,
4547 const Quantity_Color& theSubtitleColor,
4548 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
4549 const Handle(Visual3d_Layer)& theLayer)
4550 : myX1 (theX1), myY1 (theY1),
4552 myHeight (theHeight),
4555 mySubtitleColor (theSubtitleColor),
4556 myType (theTypeOfDisplay),
4557 myFontName (theFontName)
4559 if (!myLayer.IsNull ())
4560 myLayer->AddLayerItem (this);
4564 void V3d_TextItem::RedrawLayerPrs ()
4566 if (myLayer.IsNull ())
4569 myLayer->SetColor (myColor);
4570 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
4571 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
4574 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
4576 // The Visual3d_LayerItem line item for "vlayerline" command
4577 // it provides a presentation of line with user-defined
4578 // linewidth, linetype and transparency.
4579 class V3d_LineItem : public Visual3d_LayerItem
4583 DEFINE_STANDARD_RTTI(V3d_LineItem)
4586 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4587 Standard_Real X2, Standard_Real Y2,
4588 V3d_LayerMgrPointer theLayerMgr,
4589 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
4590 Standard_Real theWidth = 0.5,
4591 Standard_Real theTransp = 1.0);
4594 Standard_EXPORT void RedrawLayerPrs();
4598 Standard_Real myX1, myY1, myX2, myY2;
4599 V3d_LayerMgrPointer myLayerMgr;
4600 Aspect_TypeOfLine myType;
4601 Standard_Real myWidth;
4602 Standard_Real myTransparency;
4605 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
4606 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
4608 // default constructor for line item
4609 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4610 Standard_Real X2, Standard_Real Y2,
4611 V3d_LayerMgrPointer theLayerMgr,
4612 Aspect_TypeOfLine theType,
4613 Standard_Real theWidth,
4614 Standard_Real theTransp) :
4615 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
4616 myType(theType), myWidth(theWidth), myTransparency(theTransp)
4618 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
4619 myLayerMgr->Overlay()->AddLayerItem (this);
4623 void V3d_LineItem::RedrawLayerPrs ()
4625 Handle (Visual3d_Layer) aOverlay;
4628 aOverlay = myLayerMgr->Overlay();
4630 if (!aOverlay.IsNull())
4632 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
4633 aOverlay->SetColor(aColor);
4634 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
4635 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
4636 aOverlay->BeginPolyline();
4637 aOverlay->AddVertex(myX1, myY1);
4638 aOverlay->AddVertex(myX2, myY2);
4639 aOverlay->ClosePrimitive();
4643 //=============================================================================
4644 //function : VLayerLine
4645 //purpose : Draws line in the v3d view layer with given attributes: linetype,
4646 // : linewidth, transparency coefficient
4647 //============================================================================
4648 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4650 // get the active view
4651 Handle(V3d_View) aView = ViewerTest::CurrentView();
4654 di << "Call vinit before!\n";
4659 di << "Use: " << argv[0];
4660 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
4661 di << " linetype : { 0 | 1 | 2 | 3 } \n";
4662 di << " 0 - solid \n";
4663 di << " 1 - dashed \n";
4664 di << " 2 - dot \n";
4665 di << " 3 - dashdot\n";
4666 di << " transparency : { 0.0 - 1.0 } \n";
4667 di << " 0.0 - transparent\n";
4668 di << " 1.0 - visible \n";
4672 // get the input params
4673 Standard_Real X1 = Draw::Atof(argv[1]);
4674 Standard_Real Y1 = Draw::Atof(argv[2]);
4675 Standard_Real X2 = Draw::Atof(argv[3]);
4676 Standard_Real Y2 = Draw::Atof(argv[4]);
4678 Standard_Real aWidth = 0.5;
4679 Standard_Integer aType = 0;
4680 Standard_Real aTransparency = 1.0;
4684 aWidth = Draw::Atof(argv[5]);
4688 aType = (Standard_Integer) Draw::Atoi(argv[6]);
4693 aTransparency = Draw::Atof(argv[7]);
4694 if (aTransparency < 0 || aTransparency > 1.0)
4695 aTransparency = 1.0;
4698 // select appropriate line type
4699 Aspect_TypeOfLine aLineType;
4703 aLineType = Aspect_TOL_DASH;
4707 aLineType = Aspect_TOL_DOT;
4711 aLineType = Aspect_TOL_DOTDASH;
4715 aLineType = Aspect_TOL_SOLID;
4718 // replace layer manager
4719 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
4720 aView->SetLayerMgr(aMgr);
4723 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
4729 aView->MustBeResized();
4735 //=======================================================================
4736 //function : VOverlayText
4737 //purpose : Test text displaying in view overlay
4738 //=======================================================================
4739 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
4741 // get the active view
4742 Handle(V3d_View) aView = ViewerTest::CurrentView();
4745 di << "No active view. Please call vinit.\n";
4748 else if (argc < 4 || argc > 13)
4750 di << "Use: " << argv[0];
4751 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
4752 di << "[background_color: R G B]\n";
4753 di << " height - pixel height of the text (default=10.0)\n";
4754 di << " font_name - name of font (default=courier)\n";
4755 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
4756 di << " display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n";
4757 di << " background_color- R G B values used for subtitle and decal text\n";
4758 di << "(default=255.0 255.0 255.0)\n";
4762 TCollection_AsciiString aText (argv[1]);
4763 Standard_Real aPosX = Draw::Atof(argv[2]);
4764 Standard_Real aPosY = Draw::Atof(argv[3]);
4765 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
4768 TCollection_AsciiString aFontName = "Courier";
4770 aFontName = TCollection_AsciiString (argv[5]);
4773 Quantity_Parameter aColorRed = 1.0;
4774 Quantity_Parameter aColorGreen = 1.0;
4775 Quantity_Parameter aColorBlue = 1.0;
4778 aColorRed = Draw::Atof (argv[6])/255.;
4779 aColorGreen = Draw::Atof (argv[7])/255.;
4780 aColorBlue = Draw::Atof (argv[8])/255.;
4784 TCollection_AsciiString aDispStr;
4786 aDispStr = TCollection_AsciiString (argv[9]);
4788 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
4789 if (aDispStr.IsEqual ("subtitle"))
4790 aTextType = Aspect_TODT_SUBTITLE;
4791 else if (aDispStr.IsEqual ("decal"))
4792 aTextType = Aspect_TODT_DEKALE;
4793 else if (aDispStr.IsEqual ("blend"))
4794 aTextType = Aspect_TODT_BLEND;
4795 else if (aDispStr.IsEqual ("dimension"))
4796 aTextType = Aspect_TODT_DIMENSION;
4799 Quantity_Parameter aSubRed = 1.0;
4800 Quantity_Parameter aSubGreen = 1.0;
4801 Quantity_Parameter aSubBlue = 1.0;
4804 aSubRed = Draw::Atof (argv[10])/255.;
4805 aSubGreen = Draw::Atof (argv[11])/255.;
4806 aSubBlue = Draw::Atof (argv[12])/255.;
4809 // check fo current overlay
4810 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
4811 if (anOverlay.IsNull ())
4813 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
4814 anOverlay = aMgr->Overlay ();
4815 aView->SetLayerMgr (aMgr);
4818 Quantity_Color aTextColor (aColorRed, aColorGreen,
4819 aColorBlue, Quantity_TOC_RGB);
4820 Quantity_Color aSubtColor (aSubRed, aSubGreen,
4821 aSubBlue, Quantity_TOC_RGB);
4824 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
4825 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
4828 aView->MustBeResized();
4834 //==============================================================================
4837 //==============================================================================
4839 static int VGrid (Draw_Interpretor& /*theDI*/,
4840 Standard_Integer theArgNb,
4841 const char** theArgVec)
4843 // get the active view
4844 Handle(V3d_View) aView = ViewerTest::CurrentView();
4845 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4846 if (aView.IsNull() || aViewer.IsNull())
4848 std::cerr << "No active view. Please call vinit.\n";
4852 Aspect_GridType aType = aViewer->GridType();
4853 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
4855 Standard_Integer anIter = 1;
4856 for (; anIter < theArgNb; ++anIter)
4858 const char* aValue = theArgVec[anIter];
4861 aType = Aspect_GT_Rectangular;
4863 else if (*aValue == 'c')
4865 aType = Aspect_GT_Circular;
4867 else if (*aValue == 'l')
4869 aMode = Aspect_GDM_Lines;
4871 else if (*aValue == 'p')
4873 aMode = Aspect_GDM_Points;
4875 else if (strcmp (aValue, "off" ) == 0)
4877 aViewer->DeactivateGrid();
4886 Standard_Integer aTail = (theArgNb - anIter);
4889 aViewer->ActivateGrid (aType, aMode);
4892 else if (aTail != 2 && aTail != 5)
4894 std::cerr << "Incorrect arguments number! Usage:\n"
4895 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
4899 Quantity_Length anOriginX, anOriginY;
4900 Quantity_PlaneAngle aRotAngle;
4901 if (aType == Aspect_GT_Rectangular)
4903 Quantity_Length aRStepX, aRStepY;
4904 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4906 anOriginX = Draw::Atof (theArgVec[anIter++]);
4907 anOriginY = Draw::Atof (theArgVec[anIter++]);
4910 aRStepX = Draw::Atof (theArgVec[anIter++]);
4911 aRStepY = Draw::Atof (theArgVec[anIter++]);
4912 aRotAngle = Draw::Atof (theArgVec[anIter++]);
4914 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4915 aViewer->ActivateGrid (aType, aMode);
4917 else if (aType == Aspect_GT_Circular)
4919 Quantity_Length aRadiusStep;
4920 Standard_Integer aDivisionNumber;
4921 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
4923 anOriginX = Draw::Atof (theArgVec[anIter++]);
4924 anOriginY = Draw::Atof (theArgVec[anIter++]);
4927 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
4928 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
4929 aRotAngle = Draw::Atof (theArgVec[anIter++]);
4932 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
4933 aViewer->ActivateGrid (aType, aMode);
4939 //==============================================================================
4942 //==============================================================================
4944 static int VFps (Draw_Interpretor& theDI,
4945 Standard_Integer theArgNb,
4946 const char** theArgVec)
4948 // get the active view
4949 Handle(V3d_View) aView = ViewerTest::CurrentView();
4952 std::cerr << "No active view. Please call vinit.\n";
4956 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
4959 std::cerr << "Incorrect arguments!\n";
4963 // the time is meaningless for first call
4964 // due to async OpenGl rendering
4967 // redraw view in loop to estimate average values
4970 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
4976 const Standard_Real aTime = aTimer.ElapsedTime();
4977 aTimer.OSD_Chronometer::Show (aCpu);
4979 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
4980 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
4982 // return statistics
4983 theDI << "FPS: " << aFpsAver << "\n"
4984 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
4989 //==============================================================================
4990 //function : VGlDebug
4992 //==============================================================================
4994 static int VGlDebug (Draw_Interpretor& theDI,
4995 Standard_Integer theArgNb,
4996 const char** theArgVec)
4998 Handle(OpenGl_GraphicDriver) aDriver;
4999 Handle(V3d_View) aView = ViewerTest::CurrentView();
5000 if (!aView.IsNull())
5002 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
5006 if (aDriver.IsNull())
5008 std::cerr << "No active view. Please call vinit.\n";
5012 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS),
5013 "GL_ARB_debug_output");
5014 std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n";
5015 theDI << (isActive ? "1" : "0");
5019 const Standard_Boolean toEnableDebug = Draw::Atoi (theArgVec[1]) != 0;
5020 ViewerTest_myDefaultCaps.contextDebug = toEnableDebug;
5021 ViewerTest_myDefaultCaps.glslWarnings = toEnableDebug;
5022 if (aDriver.IsNull())
5027 aDriver->ChangeOptions().glslWarnings = toEnableDebug;
5031 //==============================================================================
5034 //==============================================================================
5036 static int VVbo (Draw_Interpretor& theDI,
5037 Standard_Integer theArgNb,
5038 const char** theArgVec)
5040 const Standard_Boolean toSet = (theArgNb > 1);
5041 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
5044 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
5048 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5049 if (aContextAIS.IsNull())
5053 std::cerr << "No active view!\n";
5057 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
5058 if (!aDriver.IsNull())
5062 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
5066 aDriver->ChangeOptions().vboDisable = toUseVbo;
5073 //==============================================================================
5076 //==============================================================================
5078 static int VCaps (Draw_Interpretor& theDI,
5079 Standard_Integer theArgNb,
5080 const char** theArgVec)
5082 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
5083 Handle(OpenGl_GraphicDriver) aDriver;
5084 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5085 if (!aContext.IsNull())
5087 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
5088 aCaps = &aDriver->ChangeOptions();
5093 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
5094 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
5095 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
5096 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
5097 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
5101 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
5102 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5104 Standard_CString anArg = theArgVec[anArgIter];
5105 TCollection_AsciiString anArgCase (anArg);
5106 anArgCase.LowerCase();
5107 if (anUpdateTool.parseRedrawMode (anArg))
5111 else if (anArgCase == "-ffp")
5113 Standard_Boolean toEnable = Standard_True;
5114 if (++anArgIter < theArgNb
5115 && !parseOnOff (theArgVec[anArgIter], toEnable))
5119 aCaps->ffpEnable = toEnable;
5121 else if (anArgCase == "-vbo")
5123 Standard_Boolean toEnable = Standard_True;
5124 if (++anArgIter < theArgNb
5125 && !parseOnOff (theArgVec[anArgIter], toEnable))
5129 aCaps->vboDisable = !toEnable;
5131 else if (anArgCase == "-sprite"
5132 || anArgCase == "-sprites")
5134 Standard_Boolean toEnable = Standard_True;
5135 if (++anArgIter < theArgNb
5136 && !parseOnOff (theArgVec[anArgIter], toEnable))
5140 aCaps->pntSpritesDisable = !toEnable;
5142 else if (anArgCase == "-softmode")
5144 Standard_Boolean toEnable = Standard_True;
5145 if (++anArgIter < theArgNb
5146 && !parseOnOff (theArgVec[anArgIter], toEnable))
5150 aCaps->contextNoAccel = toEnable;
5152 else if (anArgCase == "-accel"
5153 || anArgCase == "-acceleration")
5155 Standard_Boolean toEnable = Standard_True;
5156 if (++anArgIter < theArgNb
5157 && !parseOnOff (theArgVec[anArgIter], toEnable))
5161 aCaps->contextNoAccel = !toEnable;
5163 else if (anArgCase == "-compat"
5164 || anArgCase == "-compatprofile"
5165 || anArgCase == "-compatible"
5166 || anArgCase == "-compatibleprofile")
5168 Standard_Boolean toEnable = Standard_True;
5169 if (++anArgIter < theArgNb
5170 && !parseOnOff (theArgVec[anArgIter], toEnable))
5174 aCaps->contextCompatible = toEnable;
5175 if (!aCaps->contextCompatible)
5177 aCaps->ffpEnable = Standard_False;
5180 else if (anArgCase == "-core"
5181 || anArgCase == "-coreprofile")
5183 Standard_Boolean toEnable = Standard_True;
5184 if (++anArgIter < theArgNb
5185 && !parseOnOff (theArgVec[anArgIter], toEnable))
5189 aCaps->contextCompatible = !toEnable;
5190 if (!aCaps->contextCompatible)
5192 aCaps->ffpEnable = Standard_False;
5197 std::cout << "Error: unknown argument '" << anArg << "'\n";
5201 if (aCaps != &ViewerTest_myDefaultCaps)
5203 ViewerTest_myDefaultCaps = *aCaps;
5208 //==============================================================================
5209 //function : VMemGpu
5211 //==============================================================================
5213 static int VMemGpu (Draw_Interpretor& theDI,
5214 Standard_Integer theArgNb,
5215 const char** theArgVec)
5218 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
5219 if (aContextAIS.IsNull())
5221 std::cerr << "No active view. Please call vinit.\n";
5225 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
5226 if (aDriver.IsNull())
5228 std::cerr << "Graphic driver not available.\n";
5232 Standard_Size aFreeBytes = 0;
5233 TCollection_AsciiString anInfo;
5234 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
5236 std::cerr << "Information not available.\n";
5240 if (theArgNb > 1 && *theArgVec[1] == 'f')
5242 theDI << Standard_Real (aFreeBytes);
5252 // ==============================================================================
5253 // function : VReadPixel
5255 // ==============================================================================
5256 static int VReadPixel (Draw_Interpretor& theDI,
5257 Standard_Integer theArgNb,
5258 const char** theArgVec)
5260 // get the active view
5261 Handle(V3d_View) aView = ViewerTest::CurrentView();
5264 std::cerr << "No active view. Please call vinit.\n";
5267 else if (theArgNb < 3)
5269 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
5273 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
5274 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
5276 Standard_Integer aWidth, aHeight;
5277 aView->Window()->Size (aWidth, aHeight);
5278 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
5279 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
5280 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
5282 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
5286 Standard_Boolean toShowName = Standard_False;
5287 Standard_Boolean toShowHls = Standard_False;
5288 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
5290 const char* aParam = theArgVec[anIter];
5291 if ( strcasecmp( aParam, "rgb" ) == 0 )
5293 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
5294 aBufferType = Graphic3d_BT_RGB;
5296 else if ( strcasecmp( aParam, "hls" ) == 0 )
5298 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
5299 aBufferType = Graphic3d_BT_RGB;
5300 toShowHls = Standard_True;
5302 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
5304 aFormat = Image_PixMap::ImgRGBF;
5305 aBufferType = Graphic3d_BT_RGB;
5307 else if ( strcasecmp( aParam, "rgba" ) == 0 )
5309 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
5310 aBufferType = Graphic3d_BT_RGBA;
5312 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
5314 aFormat = Image_PixMap::ImgRGBAF;
5315 aBufferType = Graphic3d_BT_RGBA;
5317 else if ( strcasecmp( aParam, "depth" ) == 0 )
5319 aFormat = Image_PixMap::ImgGrayF;
5320 aBufferType = Graphic3d_BT_Depth;
5322 else if ( strcasecmp( aParam, "name" ) == 0 )
5324 toShowName = Standard_True;
5328 Image_PixMap anImage;
5329 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
5331 std::cerr << "Image allocation failed\n";
5334 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
5336 std::cerr << "Image dump failed\n";
5340 Quantity_Parameter anAlpha;
5341 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
5344 if (aBufferType == Graphic3d_BT_RGBA)
5346 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha;
5350 theDI << Quantity_Color::StringName (aColor.Name());
5355 switch (aBufferType)
5358 case Graphic3d_BT_RGB:
5362 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation();
5366 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue();
5370 case Graphic3d_BT_RGBA:
5372 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha;
5375 case Graphic3d_BT_Depth:
5377 theDI << aColor.Red();
5386 //==============================================================================
5387 //function : VDiffImage
5388 //purpose : The draw-command compares two images.
5389 //==============================================================================
5391 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
5395 theDI << "Not enough arguments.\n";
5400 const char* anImgPathRef = theArgVec[1];
5401 const char* anImgPathNew = theArgVec[2];
5403 // get string tolerance and check its validity
5404 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
5405 if (aTolColor < 0.0)
5407 if (aTolColor > 1.0)
5410 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
5411 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
5413 // image file of difference
5414 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
5416 // compare the images
5417 Image_Diff aComparer;
5418 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
5423 aComparer.SetColorTolerance (aTolColor);
5424 aComparer.SetBorderFilterOn (isBorderFilterOn);
5425 Standard_Integer aDiffColorsNb = aComparer.Compare();
5426 theDI << aDiffColorsNb << "\n";
5428 // save image of difference
5429 if (aDiffColorsNb >0 && aDiffImagePath != NULL)
5431 aComparer.SaveDiffImage (aDiffImagePath);
5437 //=======================================================================
5438 //function : VSelect
5439 //purpose : Emulates different types of selection by mouse:
5440 // 1) single click selection
5441 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
5442 // 3) selection with polygon having corners at
5443 // pixel positions (x1,y1),...,(xn,yn)
5444 // 4) any of these selections with shift button pressed
5445 //=======================================================================
5446 static Standard_Integer VSelect (Draw_Interpretor& di,
5447 Standard_Integer argc,
5452 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
5456 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
5457 if(myAIScontext.IsNull())
5459 di << "use 'vinit' command before " << argv[0] << "\n";
5462 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
5463 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
5464 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
5467 if(isShiftSelection)
5468 aCurrentEventManager->ShiftSelect();
5470 aCurrentEventManager->Select();
5474 if(isShiftSelection)
5475 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
5477 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
5481 Standard_Integer anUpper = 0;
5483 if(isShiftSelection)
5484 anUpper = (argc-1)/2;
5487 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
5489 for(Standard_Integer i=1;i<=anUpper;++i)
5490 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
5492 if(isShiftSelection)
5493 aCurrentEventManager->ShiftSelect(aPolyline);
5495 aCurrentEventManager->Select(aPolyline);
5500 //=======================================================================
5501 //function : VMoveTo
5502 //purpose : Emulates cursor movement to defined pixel position
5503 //=======================================================================
5504 static Standard_Integer VMoveTo (Draw_Interpretor& di,
5505 Standard_Integer argc,
5510 di << "Usage : " << argv[0] << " x y" << "\n";
5514 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5515 if(aContext.IsNull())
5517 di << "use 'vinit' command before " << argv[0] << "\n";
5520 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
5524 //=================================================================================================
5525 //function : VViewParams
5526 //purpose : Gets or sets AIS View characteristics
5527 //=================================================================================================
5528 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5530 Handle(V3d_View) anAISView = ViewerTest::CurrentView();
5531 if (anAISView.IsNull())
5533 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
5539 // print all of the available view parameters
5540 Quantity_Factor anAISViewScale = anAISView->Scale();
5542 Standard_Real anAISViewProjX = 0.0;
5543 Standard_Real anAISViewProjY = 0.0;
5544 Standard_Real anAISViewProjZ = 0.0;
5545 anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
5547 Standard_Real anAISViewUpX = 0.0;
5548 Standard_Real anAISViewUpY = 0.0;
5549 Standard_Real anAISViewUpZ = 0.0;
5550 anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
5552 Standard_Real anAISViewAtX = 0.0;
5553 Standard_Real anAISViewAtY = 0.0;
5554 Standard_Real anAISViewAtZ = 0.0;
5555 anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
5557 Standard_Real anAISViewEyeX = 0.0;
5558 Standard_Real anAISViewEyeY = 0.0;
5559 Standard_Real anAISViewEyeZ = 0.0;
5560 anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ);
5562 theDi << "Scale of current view: " << anAISViewScale << "\n";
5563 theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
5564 theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
5565 theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
5566 theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n";
5570 // -------------------------
5571 // Parse options and values
5572 // -------------------------
5574 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues;
5575 TCollection_AsciiString aParseKey;
5576 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5578 TCollection_AsciiString anArg (theArgVec [anArgIt]);
5580 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
5583 aParseKey.Remove (1);
5584 aParseKey.UpperCase();
5585 aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
5589 if (aParseKey.IsEmpty())
5591 std::cout << theArgVec[0] << ": values should be passed with key.\n";
5592 std::cout << "Type help for more information.\n";
5596 aMapOfKeysByValues(aParseKey)->Append (anArg);
5599 // ---------------------------------------------
5600 // Change or print parameters, order plays role
5601 // ---------------------------------------------
5603 // Check arguments for validity
5604 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues);
5605 for (; aMapIt.More(); aMapIt.Next())
5607 const TCollection_AsciiString& aKey = aMapIt.Key();
5608 const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value();
5610 if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5611 && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5612 && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty()))
5613 && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty()))
5614 && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty()))
5615 && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty()))
5616 && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2))
5618 TCollection_AsciiString aLowerKey;
5621 aLowerKey.LowerCase();
5622 std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n";
5623 std::cout << "Type help for more information.\n";
5628 Handle(TColStd_HSequenceOfAsciiString) aValues;
5630 // Change view parameters in proper order
5631 if (aMapOfKeysByValues.Find ("SCALE", aValues))
5633 if (aValues->IsEmpty())
5635 theDi << "Scale: " << anAISView->Scale() << "\n";
5639 anAISView->SetScale (aValues->Value(1).RealValue());
5642 if (aMapOfKeysByValues.Find ("SIZE", aValues))
5644 if (aValues->IsEmpty())
5646 Standard_Real aSizeX = 0.0;
5647 Standard_Real aSizeY = 0.0;
5648 anAISView->Size (aSizeX, aSizeY);
5649 theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n";
5653 anAISView->SetSize (aValues->Value(1).RealValue());
5656 if (aMapOfKeysByValues.Find ("EYE", aValues))
5658 if (aValues->IsEmpty())
5660 Standard_Real anEyeX = 0.0;
5661 Standard_Real anEyeY = 0.0;
5662 Standard_Real anEyeZ = 0.0;
5663 anAISView->Eye (anEyeX, anEyeY, anEyeZ);
5664 theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n";
5668 anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5671 if (aMapOfKeysByValues.Find ("AT", aValues))
5673 if (aValues->IsEmpty())
5675 Standard_Real anAtX = 0.0;
5676 Standard_Real anAtY = 0.0;
5677 Standard_Real anAtZ = 0.0;
5678 anAISView->At (anAtX, anAtY, anAtZ);
5679 theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n";
5683 anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5686 if (aMapOfKeysByValues.Find ("PROJ", aValues))
5688 if (aValues->IsEmpty())
5690 Standard_Real aProjX = 0.0;
5691 Standard_Real aProjY = 0.0;
5692 Standard_Real aProjZ = 0.0;
5693 anAISView->Proj (aProjX, aProjY, aProjZ);
5694 theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n";
5698 anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5701 if (aMapOfKeysByValues.Find ("UP", aValues))
5703 if (aValues->IsEmpty())
5705 Standard_Real anUpX = 0.0;
5706 Standard_Real anUpY = 0.0;
5707 Standard_Real anUpZ = 0.0;
5708 anAISView->Up (anUpX, anUpY, anUpZ);
5709 theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n";
5713 anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5716 if (aMapOfKeysByValues.Find ("CENTER", aValues))
5718 anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue());
5724 //=======================================================================
5725 //function : VChangeSelected
5726 //purpose : Adds the shape to selection or remove one from it
5727 //=======================================================================
5728 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
5729 Standard_Integer argc,
5734 di<<"Usage : " << argv[0] << " shape \n";
5738 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5739 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5740 TCollection_AsciiString aName(argv[1]);
5741 Handle(AIS_InteractiveObject) anAISObject;
5743 if(!aMap.IsBound2(aName))
5745 di<<"Use 'vdisplay' before";
5750 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
5751 if(anAISObject.IsNull()){
5752 di<<"No interactive object \n";
5756 if(aContext->HasOpenedContext())
5758 aContext->AddOrRemoveSelected(anAISObject);
5762 aContext->AddOrRemoveCurrentObject(anAISObject);
5768 //=======================================================================
5769 //function : VZClipping
5770 //purpose : Gets or sets ZClipping mode, width and depth
5771 //=======================================================================
5772 static Standard_Integer VZClipping (Draw_Interpretor& di,
5773 Standard_Integer argc,
5778 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
5779 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
5782 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5783 if(aContext.IsNull())
5785 di << "use 'vinit' command before " << argv[0] << "\n";
5788 Handle(V3d_View) aView = ViewerTest::CurrentView();
5789 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
5792 TCollection_AsciiString aZClippingModeString;
5793 Quantity_Length aDepth, aWidth;
5794 aZClippingMode = aView->ZClipping(aDepth, aWidth);
5795 switch (aZClippingMode)
5798 aZClippingModeString.Copy("OFF");
5801 aZClippingModeString.Copy("BACK");
5804 aZClippingModeString.Copy("FRONT");
5807 aZClippingModeString.Copy("SLICE");
5810 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
5813 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
5814 << "ZClipping depth = " << aDepth << "\n"
5815 << "ZClipping width = " << aWidth << "\n";
5821 Standard_Integer aStatus = 0;
5822 if ( strcmp (argv [1], "OFF") == 0 ) {
5824 aZClippingMode = V3d_OFF;
5826 if ( strcmp (argv [1], "BACK") == 0 ) {
5828 aZClippingMode = V3d_BACK;
5830 if ( strcmp (argv [1], "FRONT") == 0 ) {
5832 aZClippingMode = V3d_FRONT;
5834 if ( strcmp (argv [1], "SLICE") == 0 ) {
5836 aZClippingMode = V3d_SLICE;
5840 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
5841 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
5844 aView->SetZClippingType(aZClippingMode);
5848 Quantity_Length aDepth = 0., aWidth = 1.;
5851 aDepth = Draw::Atof (argv[1]);
5852 aWidth = Draw::Atof (argv[2]);
5856 aDepth = Draw::Atof (argv[2]);
5857 aWidth = Draw::Atof (argv[3]);
5860 if(aDepth<0. || aDepth>1.)
5862 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
5863 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
5866 if(aWidth<0. || aWidth>1.)
5868 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
5869 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
5873 aView->SetZClippingDepth(aDepth);
5874 aView->SetZClippingWidth(aWidth);
5881 //=======================================================================
5882 //function : VNbSelected
5883 //purpose : Returns number of selected objects
5884 //=======================================================================
5885 static Standard_Integer VNbSelected (Draw_Interpretor& di,
5886 Standard_Integer argc,
5891 di << "Usage : " << argv[0] << "\n";
5894 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5895 if(aContext.IsNull())
5897 di << "use 'vinit' command before " << argv[0] << "\n";
5900 di << aContext->NbSelected() << "\n";
5904 //=======================================================================
5905 //function : VAntialiasing
5906 //purpose : Switches altialiasing on or off
5907 //=======================================================================
5908 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
5909 Standard_Integer argc,
5914 di << "Usage : " << argv[0] << " [1|0]" << "\n";
5918 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5919 if(aContext.IsNull())
5921 di << "use 'vinit' command before " << argv[0] << "\n";
5925 Handle(V3d_View) aView = ViewerTest::CurrentView();
5927 if((argc == 2) && (atof(argv[1]) == 0))
5928 aView->SetAntialiasingOff();
5930 aView->SetAntialiasingOn();
5935 //=======================================================================
5936 //function : VPurgeDisplay
5937 //purpose : Switches altialiasing on or off
5938 //=======================================================================
5939 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
5940 Standard_Integer argc,
5945 di << "Usage : " << argv[0] << "\n";
5948 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5949 if (aContext.IsNull())
5951 di << "use 'vinit' command before " << argv[0] << "\n";
5954 aContext->CloseAllContexts(Standard_False);
5955 di << aContext->PurgeDisplay() << "\n";
5959 //=======================================================================
5960 //function : VSetViewSize
5962 //=======================================================================
5963 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
5964 Standard_Integer argc,
5967 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5968 if(aContext.IsNull())
5970 di << "use 'vinit' command before " << argv[0] << "\n";
5975 di<<"Usage : " << argv[0] << " Size\n";
5978 Standard_Real aSize = Draw::Atof (argv[1]);
5981 di<<"Bad Size value : " << aSize << "\n";
5985 Handle(V3d_View) aView = ViewerTest::CurrentView();
5986 aView->SetSize(aSize);
5990 //=======================================================================
5991 //function : VMoveView
5993 //=======================================================================
5994 static Standard_Integer VMoveView (Draw_Interpretor& di,
5995 Standard_Integer argc,
5998 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5999 if(aContext.IsNull())
6001 di << "use 'vinit' command before " << argv[0] << "\n";
6004 if(argc < 4 || argc > 5)
6006 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
6009 Standard_Real Dx = Draw::Atof (argv[1]);
6010 Standard_Real Dy = Draw::Atof (argv[2]);
6011 Standard_Real Dz = Draw::Atof (argv[3]);
6012 Standard_Boolean aStart = Standard_True;
6015 aStart = (Draw::Atoi (argv[4]) > 0);
6018 Handle(V3d_View) aView = ViewerTest::CurrentView();
6019 aView->Move(Dx,Dy,Dz,aStart);
6023 //=======================================================================
6024 //function : VTranslateView
6026 //=======================================================================
6027 static Standard_Integer VTranslateView (Draw_Interpretor& di,
6028 Standard_Integer argc,
6031 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6032 if(aContext.IsNull())
6034 di << "use 'vinit' command before " << argv[0] << "\n";
6037 if(argc < 4 || argc > 5)
6039 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
6042 Standard_Real Dx = Draw::Atof (argv[1]);
6043 Standard_Real Dy = Draw::Atof (argv[2]);
6044 Standard_Real Dz = Draw::Atof (argv[3]);
6045 Standard_Boolean aStart = Standard_True;
6048 aStart = (Draw::Atoi (argv[4]) > 0);
6051 Handle(V3d_View) aView = ViewerTest::CurrentView();
6052 aView->Translate(Dx,Dy,Dz,aStart);
6056 //=======================================================================
6057 //function : VTurnView
6059 //=======================================================================
6060 static Standard_Integer VTurnView (Draw_Interpretor& di,
6061 Standard_Integer argc,
6064 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
6065 if(aContext.IsNull()) {
6066 di << "use 'vinit' command before " << argv[0] << "\n";
6069 if(argc < 4 || argc > 5){
6070 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
6073 Standard_Real Ax = Draw::Atof (argv[1]);
6074 Standard_Real Ay = Draw::Atof (argv[2]);
6075 Standard_Real Az = Draw::Atof (argv[3]);
6076 Standard_Boolean aStart = Standard_True;
6079 aStart = (Draw::Atoi (argv[4]) > 0);
6082 Handle(V3d_View) aView = ViewerTest::CurrentView();
6083 aView->Turn(Ax,Ay,Az,aStart);
6087 //==============================================================================
6088 //function : VTextureEnv
6089 //purpose : ENables or disables environment mapping
6090 //==============================================================================
6091 class OCC_TextureEnv : public Graphic3d_TextureEnv
6094 OCC_TextureEnv(const Standard_CString FileName);
6095 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
6096 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
6097 const Standard_Boolean theModulateFlag,
6098 const Graphic3d_TypeOfTextureFilter theFilter,
6099 const Standard_ShortReal theXScale,
6100 const Standard_ShortReal theYScale,
6101 const Standard_ShortReal theXShift,
6102 const Standard_ShortReal theYShift,
6103 const Standard_ShortReal theAngle);
6104 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
6106 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
6107 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
6108 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
6110 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
6111 : Graphic3d_TextureEnv(theFileName)
6115 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
6116 : Graphic3d_TextureEnv(theTexId)
6120 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
6121 const Standard_Boolean theModulateFlag,
6122 const Graphic3d_TypeOfTextureFilter theFilter,
6123 const Standard_ShortReal theXScale,
6124 const Standard_ShortReal theYScale,
6125 const Standard_ShortReal theXShift,
6126 const Standard_ShortReal theYShift,
6127 const Standard_ShortReal theAngle)
6129 myParams->SetRepeat (theRepeatFlag);
6130 myParams->SetModulate (theModulateFlag);
6131 myParams->SetFilter (theFilter);
6132 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
6133 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
6134 myParams->SetRotation (theAngle);
6137 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
6139 // get the active view
6140 Handle(V3d_View) aView = ViewerTest::CurrentView();
6143 std::cerr << "No active view. Please call vinit.\n";
6147 // Checking the input arguments
6148 Standard_Boolean anEnableFlag = Standard_False;
6149 Standard_Boolean isOk = theArgNb >= 2;
6152 TCollection_AsciiString anEnableOpt(theArgVec[1]);
6153 anEnableFlag = anEnableOpt.IsEqual("on");
6154 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
6158 isOk = (theArgNb == 3 || theArgNb == 11);
6161 TCollection_AsciiString aTextureOpt(theArgVec[2]);
6162 isOk = (!aTextureOpt.IsIntegerValue() ||
6163 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
6165 if (isOk && theArgNb == 11)
6167 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
6168 aModulateOpt(theArgVec[4]),
6169 aFilterOpt (theArgVec[5]),
6170 aSScaleOpt (theArgVec[6]),
6171 aTScaleOpt (theArgVec[7]),
6172 aSTransOpt (theArgVec[8]),
6173 aTTransOpt (theArgVec[9]),
6174 anAngleOpt (theArgVec[10]);
6175 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
6176 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
6177 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
6178 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
6179 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
6180 anAngleOpt.IsRealValue());
6187 std::cerr << "Usage :" << std::endl;
6188 std::cerr << theArgVec[0] << " off" << std::endl;
6189 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;
6195 TCollection_AsciiString aTextureOpt(theArgVec[2]);
6196 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
6197 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
6198 new OCC_TextureEnv(theArgVec[2]);
6202 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
6203 aTexEnv->SetTextureParameters(
6204 aRepeatOpt. IsEqual("repeat"),
6205 aModulateOpt.IsEqual("modulate"),
6206 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
6207 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
6208 Graphic3d_TOTF_TRILINEAR,
6209 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
6210 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
6211 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
6212 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
6213 (Standard_ShortReal)Draw::Atof(theArgVec[10])
6216 aView->SetTextureEnv(aTexEnv);
6217 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
6219 else // Disabling environment mapping
6221 aView->SetSurfaceDetail(V3d_TEX_NONE);
6222 Handle(Graphic3d_TextureEnv) aTexture;
6223 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
6230 //===============================================================================================
6231 //function : VClipPlane
6233 //===============================================================================================
6234 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6236 // use short-cut for created clip planes map of created (or "registered by name") clip planes
6237 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
6238 static MapOfPlanes aRegPlanes;
6242 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
6246 TCollection_AsciiString aCommand (theArgVec[1]);
6248 // print maximum number of planes for current viewer
6249 if (aCommand == "maxplanes")
6253 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
6257 TCollection_AsciiString aViewName (theArgVec[2]);
6259 if (!ViewerTest_myViews.IsBound1 (aViewName))
6261 theDi << theArgVec[0] << ": view is not found.\n";
6265 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
6267 theDi << theArgVec[0] << ": "
6268 << aView->Viewer()->Driver()->InquirePlaneLimit()
6269 << " plane slots provided by driver."
6270 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
6275 // create / delete plane instance
6276 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
6280 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
6284 Standard_Boolean toCreate = (aCommand == "create");
6285 Standard_Boolean toClone = (aCommand == "clone");
6286 TCollection_AsciiString aPlane (theArgVec[2]);
6290 if (aRegPlanes.IsBound (aPlane))
6292 theDi << theArgVec[0] << ": plane name is in use.\n";
6296 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
6298 else if (toClone) // toClone
6300 if (!aRegPlanes.IsBound (aPlane))
6302 theDi << theArgVec[0] << ": no such plane.\n";
6308 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
6312 TCollection_AsciiString aClone (theArgVec[3]);
6313 if (aRegPlanes.IsBound (aClone))
6315 theDi << theArgVec[0] << ": plane name is in use.\n";
6319 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6321 aRegPlanes.Bind (aClone, aClipPlane->Clone());
6325 if (!aRegPlanes.IsBound (aPlane))
6327 theDi << theArgVec[0] << ": no such plane.\n";
6331 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
6332 aRegPlanes.UnBind (aPlane);
6334 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
6335 for (; anIObjIt.More(); anIObjIt.Next())
6337 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
6338 aPrs->RemoveClipPlane(aClipPlane);
6341 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
6342 for (; aViewIt.More(); aViewIt.Next())
6344 const Handle(V3d_View)& aView = aViewIt.Key2();
6345 aView->RemoveClipPlane(aClipPlane);
6348 ViewerTest::RedrawAllViews();
6354 // set / unset plane command
6355 if (aCommand == "set" || aCommand == "unset")
6359 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6363 Standard_Boolean toSet = (aCommand == "set");
6364 TCollection_AsciiString aPlane (theArgVec [2]);
6365 if (!aRegPlanes.IsBound (aPlane))
6367 theDi << theArgVec[0] << ": no such plane.\n";
6371 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6373 TCollection_AsciiString aTarget (theArgVec [3]);
6374 if (aTarget != "object" && aTarget != "view")
6376 theDi << theArgVec[0] << ": invalid target.\n";
6380 if (aTarget == "object" || aTarget == "view")
6384 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6388 Standard_Boolean isObject = (aTarget == "object");
6390 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
6392 TCollection_AsciiString anEntityName (theArgVec[anIt]);
6393 if (isObject) // to object
6395 if (!GetMapOfAIS().IsBound2 (anEntityName))
6397 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
6401 Handle(AIS_InteractiveObject) aIObj =
6402 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
6405 aIObj->AddClipPlane (aClipPlane);
6407 aIObj->RemoveClipPlane (aClipPlane);
6411 if (!ViewerTest_myViews.IsBound1 (anEntityName))
6413 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
6417 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
6419 aView->AddClipPlane (aClipPlane);
6421 aView->RemoveClipPlane (aClipPlane);
6425 ViewerTest::RedrawAllViews();
6431 // change plane command
6432 if (aCommand == "change")
6436 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6440 TCollection_AsciiString aPlane (theArgVec [2]);
6441 if (!aRegPlanes.IsBound (aPlane))
6443 theDi << theArgVec[0] << ": no such plane.\n";
6447 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6449 TCollection_AsciiString aChangeArg (theArgVec [3]);
6450 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
6452 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
6456 if (aChangeArg == "on" || aChangeArg == "off") // on / off
6458 aClipPlane->SetOn (aChangeArg == "on");
6460 else if (aChangeArg == "equation") // change equation
6464 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6468 Standard_Real aCoeffA = Draw::Atof (theArgVec [4]);
6469 Standard_Real aCoeffB = Draw::Atof (theArgVec [5]);
6470 Standard_Real aCoeffC = Draw::Atof (theArgVec [6]);
6471 Standard_Real aCoeffD = Draw::Atof (theArgVec [7]);
6472 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
6474 else if (aChangeArg == "capping") // change capping aspects
6478 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6482 TCollection_AsciiString aCappingArg (theArgVec [4]);
6483 if (aCappingArg != "on" && aCappingArg != "off" &&
6484 aCappingArg != "color" && aCappingArg != "texname" &&
6485 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
6486 aCappingArg != "texrotate" && aCappingArg != "hatch")
6488 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
6492 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
6494 aClipPlane->SetCapping (aCappingArg == "on");
6496 else if (aCappingArg == "color") // color aspect for capping
6500 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6504 Standard_Real aRed = Draw::Atof (theArgVec [5]);
6505 Standard_Real aGrn = Draw::Atof (theArgVec [6]);
6506 Standard_Real aBlu = Draw::Atof (theArgVec [7]);
6508 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
6509 Quantity_Color aColor (aRed, aGrn, aBlu, Quantity_TOC_RGB);
6510 aMat.SetAmbientColor (aColor);
6511 aMat.SetDiffuseColor (aColor);
6512 aClipPlane->SetCappingMaterial (aMat);
6514 else if (aCappingArg == "texname") // texture name
6518 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6522 TCollection_AsciiString aTextureName (theArgVec [5]);
6524 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
6525 if (!aTexture->IsDone ())
6527 aClipPlane->SetCappingTexture (NULL);
6531 aTexture->EnableModulate();
6532 aTexture->EnableRepeat();
6533 aClipPlane->SetCappingTexture (aTexture);
6536 else if (aCappingArg == "texscale") // texture scale
6538 if (aClipPlane->CappingTexture().IsNull())
6540 theDi << theArgVec[0] << ": no texture is set.\n";
6546 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6550 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
6551 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
6553 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
6555 else if (aCappingArg == "texorigin") // texture origin
6557 if (aClipPlane->CappingTexture().IsNull())
6559 theDi << theArgVec[0] << ": no texture is set.\n";
6565 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6569 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
6570 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
6572 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
6574 else if (aCappingArg == "texrotate") // texture rotation
6576 if (aClipPlane->CappingTexture().IsNull())
6578 theDi << theArgVec[0] << ": no texture is set.\n";
6584 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6588 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
6590 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
6592 else if (aCappingArg == "hatch") // hatch style
6596 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6600 TCollection_AsciiString aHatchStr (theArgVec [5]);
6601 if (aHatchStr == "on")
6603 aClipPlane->SetCappingHatchOn();
6605 else if (aHatchStr == "off")
6607 aClipPlane->SetCappingHatchOff();
6611 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
6616 ViewerTest::RedrawAllViews();
6621 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
6625 //===============================================================================================
6626 //function : VSetTextureMode
6628 //===============================================================================================
6629 static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6633 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
6637 TCollection_AsciiString aViewName (theArgVec[1]);
6638 if (!ViewerTest_myViews.IsBound1 (aViewName))
6640 theDi << theArgVec[0] << ": view is not found.\n";
6644 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
6645 switch (atoi (theArgVec[2]))
6647 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
6648 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
6649 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
6651 theDi << theArgVec[0] << ": invalid mode.\n";
6659 //===============================================================================================
6660 //function : VZRange
6662 //===============================================================================================
6663 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6665 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
6667 if (aCurrentView.IsNull())
6669 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
6673 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
6677 theDi << "ZNear: " << aCamera->ZNear() << "\n";
6678 theDi << "ZFar: " << aCamera->ZFar() << "\n";
6684 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
6685 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
6687 if (aNewZNear >= aNewZFar)
6689 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
6693 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
6695 std::cout << theArgVec[0] << ": invalid arguments: ";
6696 std::cout << "znear, zfar should be positive for perspective camera.\n";
6700 aCamera->SetZRange (aNewZNear, aNewZFar);
6704 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
6708 aCurrentView->Redraw();
6713 //===============================================================================================
6714 //function : VAutoZFit
6716 //===============================================================================================
6717 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6719 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
6721 if (aCurrentView.IsNull())
6723 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
6727 Standard_Real aScale = aCurrentView->View()->AutoZFitScaleFactor();
6731 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
6737 theDi << "Auto z-fit mode: " << "\n"
6738 << "On: " << (aCurrentView->View()->AutoZFitMode() ? "enabled" : "disabled") << "\n"
6739 << "Scale: " << aScale << "\n";
6743 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
6747 aScale = Draw::Atoi (theArgVec[2]);
6750 aCurrentView->View()->SetAutoZFitMode (isOn, aScale);
6751 aCurrentView->View()->AutoZFit();
6752 aCurrentView->Redraw();
6757 //! Auxiliary function to print projection type
6758 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
6760 switch (theProjType)
6762 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
6763 case Graphic3d_Camera::Projection_Perspective: return "perspective";
6764 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
6765 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
6766 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
6771 //===============================================================================================
6772 //function : VCamera
6774 //===============================================================================================
6775 static int VCamera (Draw_Interpretor& theDI,
6776 Standard_Integer theArgsNb,
6777 const char** theArgVec)
6779 Handle(V3d_View) aView = ViewerTest::CurrentView();
6782 std::cout << "Error: no active view.\n";
6786 Handle(Graphic3d_Camera) aCamera = aView->Camera();
6789 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
6790 theDI << "FOVy: " << aCamera->FOVy() << "\n";
6791 theDI << "Distance: " << aCamera->Distance() << "\n";
6792 theDI << "IOD: " << aCamera->IOD() << "\n";
6793 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
6794 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
6795 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
6799 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
6801 Standard_CString anArg = theArgVec[anArgIter];
6802 TCollection_AsciiString anArgCase (anArg);
6803 anArgCase.LowerCase();
6804 if (anArgCase == "-proj"
6805 || anArgCase == "-projection"
6806 || anArgCase == "-projtype"
6807 || anArgCase == "-projectiontype")
6809 theDI << projTypeName (aCamera->ProjectionType()) << " ";
6811 else if (anArgCase == "-ortho"
6812 || anArgCase == "-orthographic")
6814 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
6816 else if (anArgCase == "-persp"
6817 || anArgCase == "-perspective"
6818 || anArgCase == "-perspmono"
6819 || anArgCase == "-perspectivemono"
6820 || anArgCase == "-mono")
6822 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
6824 else if (anArgCase == "-stereo"
6825 || anArgCase == "-stereoscopic"
6826 || anArgCase == "-perspstereo"
6827 || anArgCase == "-perspectivestereo")
6829 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
6831 else if (anArgCase == "-left"
6832 || anArgCase == "-lefteye"
6833 || anArgCase == "-monoleft"
6834 || anArgCase == "-monolefteye"
6835 || anArgCase == "-perpsleft"
6836 || anArgCase == "-perpslefteye")
6838 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
6840 else if (anArgCase == "-right"
6841 || anArgCase == "-righteye"
6842 || anArgCase == "-monoright"
6843 || anArgCase == "-monorighteye"
6844 || anArgCase == "-perpsright")
6846 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
6848 else if (anArgCase == "-dist"
6849 || anArgCase == "-distance")
6851 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
6852 if (anArgValue != NULL
6853 && *anArgValue != '-')
6856 aCamera->SetDistance (Draw::Atof (anArgValue));
6859 theDI << aCamera->Distance() << " ";
6861 else if (anArgCase == "-iod")
6863 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
6864 if (anArgValue != NULL
6865 && *anArgValue != '-')
6868 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
6871 theDI << aCamera->IOD() << " ";
6873 else if (anArgCase == "-iodtype")
6875 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
6876 TCollection_AsciiString anValueCase (anArgValue);
6877 anValueCase.LowerCase();
6878 if (anValueCase == "abs"
6879 || anValueCase == "absolute")
6882 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
6885 else if (anValueCase == "rel"
6886 || anValueCase == "relative")
6889 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
6892 else if (*anArgValue != '-')
6894 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
6897 switch (aCamera->GetIODType())
6899 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
6900 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
6903 else if (anArgCase == "-zfocus")
6905 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
6906 if (anArgValue != NULL
6907 && *anArgValue != '-')
6910 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
6913 theDI << aCamera->ZFocus() << " ";
6915 else if (anArgCase == "-zfocustype")
6917 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
6918 TCollection_AsciiString anValueCase (anArgValue);
6919 anValueCase.LowerCase();
6920 if (anValueCase == "abs"
6921 || anValueCase == "absolute")
6924 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
6927 else if (anValueCase == "rel"
6928 || anValueCase == "relative")
6931 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
6934 else if (*anArgValue != '-')
6936 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
6939 switch (aCamera->ZFocusType())
6941 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
6942 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
6945 else if (anArgCase == "-fov"
6946 || anArgCase == "-fovy")
6948 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
6949 if (anArgValue != NULL
6950 && *anArgValue != '-')
6953 aCamera->SetFOVy (Draw::Atof (anArgValue));
6956 theDI << aCamera->FOVy() << " ";
6960 std::cout << "Error: unknown argument '" << anArg << "'\n";
6965 aView->View()->AutoZFit();
6971 //==============================================================================
6972 //function : VStereo
6974 //==============================================================================
6976 static int VStereo (Draw_Interpretor& theDI,
6977 Standard_Integer theArgNb,
6978 const char** theArgVec)
6982 Handle(V3d_View) aView = ViewerTest::CurrentView();
6985 std::cerr << "No active view. Please call vinit.\n";
6989 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
6990 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
6994 ViewerTest_myDefaultCaps.contextStereo = Draw::Atoi (theArgVec[1]) != 0;
6998 //===============================================================================================
6999 //function : VDefaults
7001 //===============================================================================================
7002 static int VDefaults (Draw_Interpretor& theDi,
7003 Standard_Integer theArgsNb,
7004 const char** theArgVec)
7006 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
7009 std::cerr << "No active viewer!\n";
7013 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
7016 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
7018 theDi << "DeflType: relative\n"
7019 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
7023 theDi << "DeflType: absolute\n"
7024 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
7026 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
7027 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
7031 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
7033 TCollection_AsciiString anArg (theArgVec[anArgIter]);
7035 if (anArg == "-ABSDEFL"
7036 || anArg == "-ABSOLUTEDEFLECTION"
7038 || anArg == "-DEFLECTION")
7040 if (++anArgIter >= theArgsNb)
7042 std::cout << "Error: wrong syntax at " << anArg << "\n";
7045 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
7046 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
7048 else if (anArg == "-RELDEFL"
7049 || anArg == "-RELATIVEDEFLECTION"
7050 || anArg == "-DEVCOEFF"
7051 || anArg == "-DEVIATIONCOEFF"
7052 || anArg == "-DEVIATIONCOEFFICIENT")
7054 if (++anArgIter >= theArgsNb)
7056 std::cout << "Error: wrong syntax at " << anArg << "\n";
7059 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
7060 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
7062 else if (anArg == "-ANGDEFL"
7063 || anArg == "-ANGULARDEFL"
7064 || anArg == "-ANGULARDEFLECTION")
7066 if (++anArgIter >= theArgsNb)
7068 std::cout << "Error: wrong syntax at " << anArg << "\n";
7071 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
7072 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
7074 if (anArg == "-AUTOTR"
7075 || anArg == "-AUTOTRIANG"
7076 || anArg == "-AUTOTRIANGULATION")
7078 if (++anArgIter >= theArgsNb)
7080 std::cout << "Error: wrong syntax at " << anArg << "\n";
7083 TCollection_AsciiString aValue (theArgVec[anArgIter]);
7088 aDefParams->SetAutoTriangulation (Standard_True);
7090 else if (aValue == "off"
7093 aDefParams->SetAutoTriangulation (Standard_False);
7098 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
7105 //! Auxiliary method
7106 inline void addLight (const Handle(V3d_Light)& theLightNew,
7107 const Standard_Boolean theIsGlobal)
7109 if (theLightNew.IsNull())
7116 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
7120 ViewerTest::CurrentView()->SetLightOn (theLightNew);
7124 //! Auxiliary method
7125 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
7127 TCollection_AsciiString anArgNextCase (theArgNext);
7128 anArgNextCase.UpperCase();
7129 if (anArgNextCase.Length() > 5
7130 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
7132 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
7136 return theArgNext.IntegerValue();
7140 //===============================================================================================
7143 //===============================================================================================
7144 static int VLight (Draw_Interpretor& theDi,
7145 Standard_Integer theArgsNb,
7146 const char** theArgVec)
7148 Handle(V3d_View) aView = ViewerTest::CurrentView();
7149 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
7151 || aViewer.IsNull())
7153 std::cerr << "No active viewer!\n";
7157 Standard_Real anXYZ[3];
7158 Quantity_Coefficient anAtten[2];
7161 // print lights info
7162 Standard_Integer aLightId = 0;
7163 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId)
7165 Handle(V3d_Light) aLight = aView->ActiveLight();
7166 const Quantity_Color aColor = aLight->Color();
7167 theDi << "Light" << aLightId << "\n";
7168 switch (aLight->Type())
7172 theDi << " Type: Ambient\n";
7175 case V3d_DIRECTIONAL:
7177 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
7178 theDi << " Type: Directional\n";
7179 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7180 if (!aLightDir.IsNull())
7182 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7183 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7184 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
7185 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7189 case V3d_POSITIONAL:
7191 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
7192 theDi << " Type: Positional\n";
7193 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7194 if (!aLightPos.IsNull())
7196 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7197 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7198 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7199 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
7205 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
7206 theDi << " Type: Spot\n";
7207 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
7208 if (!aLightSpot.IsNull())
7210 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
7211 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7212 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
7213 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
7214 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7215 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
7216 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
7217 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
7223 theDi << " Type: UNKNOWN\n";
7227 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
7231 Handle(V3d_Light) aLightNew;
7232 Handle(V3d_Light) aLightOld;
7233 Standard_Boolean isGlobal = Standard_True;
7234 Standard_Boolean toCreate = Standard_False;
7235 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
7237 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
7238 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
7239 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
7240 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
7241 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
7243 TCollection_AsciiString aName, aValue;
7244 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
7245 TCollection_AsciiString anArgCase (anArg);
7246 anArgCase.UpperCase();
7247 if (anArgCase.IsEqual ("NEW")
7248 || anArgCase.IsEqual ("ADD")
7249 || anArgCase.IsEqual ("CREATE"))
7251 toCreate = Standard_True;
7253 else if (anArgCase.IsEqual ("GLOB")
7254 || anArgCase.IsEqual ("GLOBAL"))
7256 isGlobal = Standard_True;
7258 else if (anArgCase.IsEqual ("LOC")
7259 || anArgCase.IsEqual ("LOCAL"))
7261 isGlobal = Standard_False;
7263 else if (anArgCase.IsEqual ("DEF")
7264 || anArgCase.IsEqual ("DEFAULTS"))
7266 toCreate = Standard_False;
7267 aViewer->SetDefaultLights();
7269 else if (anArgCase.IsEqual ("CLR")
7270 || anArgCase.IsEqual ("CLEAR"))
7272 toCreate = Standard_False;
7273 aView->InitActiveLights();
7274 while (aView->MoreActiveLights())
7276 aViewer->DelLight (aView->ActiveLight());
7277 aView->InitActiveLights();
7280 else if (anArgCase.IsEqual ("AMB")
7281 || anArgCase.IsEqual ("AMBIENT")
7282 || anArgCase.IsEqual ("AMBLIGHT"))
7284 addLight (aLightNew, isGlobal);
7287 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7290 toCreate = Standard_False;
7291 aLightNew = new V3d_AmbientLight (aViewer);
7293 else if (anArgCase.IsEqual ("DIRECTIONAL")
7294 || anArgCase.IsEqual ("DIRLIGHT"))
7296 addLight (aLightNew, isGlobal);
7299 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7302 toCreate = Standard_False;
7303 aLightNew = new V3d_DirectionalLight (aViewer);
7305 else if (anArgCase.IsEqual ("SPOT")
7306 || anArgCase.IsEqual ("SPOTLIGHT"))
7308 addLight (aLightNew, isGlobal);
7311 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7314 toCreate = Standard_False;
7315 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
7317 else if (anArgCase.IsEqual ("POSLIGHT")
7318 || anArgCase.IsEqual ("POSITIONAL"))
7320 addLight (aLightNew, isGlobal);
7323 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7326 toCreate = Standard_False;
7327 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
7329 else if (anArgCase.IsEqual ("CHANGE"))
7331 addLight (aLightNew, isGlobal);
7332 aLightNew.Nullify();
7333 if (++anArgIt >= theArgsNb)
7335 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7339 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
7340 Standard_Integer aLightIt = 0;
7341 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
7343 if (aLightIt == aLightId)
7345 aLightOld = aView->ActiveLight();
7350 if (aLightOld.IsNull())
7352 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
7356 else if (anArgCase.IsEqual ("DEL")
7357 || anArgCase.IsEqual ("DELETE"))
7359 Handle(V3d_Light) aLightDel;
7360 if (++anArgIt >= theArgsNb)
7362 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7366 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
7367 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
7368 Standard_Integer aLightIt = 0;
7369 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
7371 aLightDel = aView->ActiveLight();
7372 if (aLightIt == aLightDelId)
7377 if (!aLightDel.IsNull())
7379 aViewer->DelLight (aLightDel);
7382 else if (anArgCase.IsEqual ("COLOR")
7383 || anArgCase.IsEqual ("COLOUR"))
7385 if (++anArgIt >= theArgsNb)
7387 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7391 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
7392 anArgNext.UpperCase();
7393 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
7394 if (!aLightCurr.IsNull())
7396 aLightCurr->SetColor (aColor);
7399 else if (anArgCase.IsEqual ("POS")
7400 || anArgCase.IsEqual ("POSITION"))
7402 if ((anArgIt + 3) >= theArgsNb)
7404 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7408 anXYZ[0] = Atof (theArgVec[++anArgIt]);
7409 anXYZ[1] = Atof (theArgVec[++anArgIt]);
7410 anXYZ[2] = Atof (theArgVec[++anArgIt]);
7411 if (!aLightDir.IsNull())
7413 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7415 else if (!aLightPos.IsNull())
7417 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7419 else if (!aLightSpot.IsNull())
7421 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7425 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7429 else if (anArgCase.IsEqual ("DIR")
7430 || anArgCase.IsEqual ("DIRECTION"))
7432 if ((anArgIt + 3) >= theArgsNb)
7434 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7438 anXYZ[0] = Atof (theArgVec[++anArgIt]);
7439 anXYZ[1] = Atof (theArgVec[++anArgIt]);
7440 anXYZ[2] = Atof (theArgVec[++anArgIt]);
7441 if (!aLightDir.IsNull())
7443 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
7445 else if (!aLightSpot.IsNull())
7447 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
7451 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7455 else if (anArgCase.IsEqual ("ANG")
7456 || anArgCase.IsEqual ("ANGLE"))
7458 if (++anArgIt >= theArgsNb)
7460 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7464 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
7466 if (!aLightSpot.IsNull())
7468 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
7471 else if (anArgCase.IsEqual ("CONSTATTEN")
7472 || anArgCase.IsEqual ("CONSTATTENUATION"))
7474 if (++anArgIt >= theArgsNb)
7476 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7480 if (!aLightPos.IsNull())
7482 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7483 anAtten[0] = Atof (theArgVec[anArgIt]);
7484 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
7486 else if (!aLightSpot.IsNull())
7488 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7489 anAtten[0] = Atof (theArgVec[anArgIt]);
7490 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
7494 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7498 else if (anArgCase.IsEqual ("LINATTEN")
7499 || anArgCase.IsEqual ("LINEARATTEN")
7500 || anArgCase.IsEqual ("LINEARATTENUATION"))
7502 if (++anArgIt >= theArgsNb)
7504 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7508 if (!aLightPos.IsNull())
7510 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7511 anAtten[1] = Atof (theArgVec[anArgIt]);
7512 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
7514 else if (!aLightSpot.IsNull())
7516 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7517 anAtten[1] = Atof (theArgVec[anArgIt]);
7518 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
7522 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7526 else if (anArgCase.IsEqual ("EXP")
7527 || anArgCase.IsEqual ("EXPONENT")
7528 || anArgCase.IsEqual ("SPOTEXP")
7529 || anArgCase.IsEqual ("SPOTEXPONENT"))
7531 if (++anArgIt >= theArgsNb)
7533 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7537 if (!aLightSpot.IsNull())
7539 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
7543 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7547 else if (anArgCase.IsEqual ("HEAD")
7548 || anArgCase.IsEqual ("HEADLIGHT"))
7550 if (++anArgIt >= theArgsNb)
7552 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7556 if (aLightAmb.IsNull()
7557 && !aLightCurr.IsNull())
7559 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
7563 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7569 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
7573 addLight (aLightNew, isGlobal);
7574 aViewer->UpdateLights();
7579 //=======================================================================
7580 //function : VRenderParams
7581 //purpose : Enables/disables rendering features
7582 //=======================================================================
7584 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
7585 Standard_Integer theArgNb,
7586 const char** theArgVec)
7588 Handle(V3d_View) aView = ViewerTest::CurrentView();
7591 std::cerr << "Error: no active viewer!\n";
7595 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
7596 TCollection_AsciiString aCmdName (theArgVec[0]);
7597 aCmdName.LowerCase();
7598 if (aCmdName == "vraytrace")
7602 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
7605 else if (theArgNb == 2)
7607 TCollection_AsciiString aValue (theArgVec[1]);
7612 aParams.Method = Graphic3d_RM_RAYTRACING;
7616 else if (aValue == "off"
7619 aParams.Method = Graphic3d_RM_RASTERIZATION;
7625 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
7631 std::cout << "Error: wrong number of arguments\n";
7638 theDI << "renderMode: ";
7639 switch (aParams.Method)
7641 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
7642 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
7645 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
7646 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
7647 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
7648 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
7649 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
7650 theDI << "shadingModel: ";
7651 switch (aView->ShadingModel())
7653 case V3d_COLOR: theDI << "color"; break;
7654 case V3d_FLAT: theDI << "flat"; break;
7655 case V3d_GOURAUD: theDI << "gouraud"; break;
7656 case V3d_PHONG: theDI << "phong"; break;
7662 Standard_Boolean toPrint = Standard_False;
7663 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7664 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7666 Standard_CString anArg (theArgVec[anArgIter]);
7667 TCollection_AsciiString aFlag (anArg);
7669 if (anUpdateTool.parseRedrawMode (aFlag))
7673 else if (aFlag == "-echo"
7674 || aFlag == "-print")
7676 toPrint = Standard_True;
7677 anUpdateTool.Invalidate();
7679 else if (aFlag == "-mode"
7680 || aFlag == "-rendermode"
7681 || aFlag == "-render_mode")
7685 switch (aParams.Method)
7687 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
7688 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
7694 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
7698 else if (aFlag == "-ray"
7699 || aFlag == "-raytrace")
7703 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
7707 aParams.Method = Graphic3d_RM_RAYTRACING;
7709 else if (aFlag == "-rast"
7710 || aFlag == "-raster"
7711 || aFlag == "-rasterization")
7715 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
7719 aParams.Method = Graphic3d_RM_RASTERIZATION;
7721 else if (aFlag == "-raydepth"
7722 || aFlag == "-ray_depth")
7726 theDI << aParams.RaytracingDepth << " ";
7729 else if (++anArgIter >= theArgNb)
7731 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
7735 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
7736 if (aDepth < 1 || aDepth > 10)
7738 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
7743 aParams.RaytracingDepth = aDepth;
7746 else if (aFlag == "-shad"
7747 || aFlag == "-shadows")
7751 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
7755 Standard_Boolean toEnable = Standard_True;
7756 if (++anArgIter < theArgNb
7757 && !parseOnOff (theArgVec[anArgIter], toEnable))
7761 aParams.IsShadowEnabled = toEnable;
7763 else if (aFlag == "-refl"
7764 || aFlag == "-reflections")
7768 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
7772 Standard_Boolean toEnable = Standard_True;
7773 if (++anArgIter < theArgNb
7774 && !parseOnOff (theArgVec[anArgIter], toEnable))
7778 aParams.IsReflectionEnabled = toEnable;
7780 else if (aFlag == "-fsaa")
7784 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
7788 Standard_Boolean toEnable = Standard_True;
7789 if (++anArgIter < theArgNb
7790 && !parseOnOff (theArgVec[anArgIter], toEnable))
7794 aParams.IsAntialiasingEnabled = toEnable;
7796 else if (aFlag == "-gleam")
7800 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
7804 Standard_Boolean toEnable = Standard_True;
7805 if (++anArgIter < theArgNb
7806 && !parseOnOff (theArgVec[anArgIter], toEnable))
7810 aParams.IsTransparentShadowEnabled = toEnable;
7812 else if (aFlag == "-shademodel"
7813 || aFlag == "-shadingmodel"
7814 || aFlag == "-shading")
7818 switch (aView->ShadingModel())
7820 case V3d_COLOR: theDI << "color "; break;
7821 case V3d_FLAT: theDI << "flat "; break;
7822 case V3d_GOURAUD: theDI << "gouraud "; break;
7823 case V3d_PHONG: theDI << "phong "; break;
7828 if (++anArgIter >= theArgNb)
7830 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
7833 TCollection_AsciiString aMode (theArgVec[anArgIter]);
7835 if (aMode == "color"
7838 aView->SetShadingModel (V3d_COLOR);
7840 else if (aMode == "flat"
7841 || aMode == "facet")
7843 aView->SetShadingModel (V3d_FLAT);
7845 else if (aMode == "gouraud"
7846 || aMode == "vertex"
7849 aView->SetShadingModel (V3d_GOURAUD);
7851 else if (aMode == "phong"
7852 || aMode == "fragment"
7854 || aMode == "pixel")
7856 aView->SetShadingModel (V3d_PHONG);
7860 std::cout << "Error: unknown shading model '" << aMode << "'\n";
7866 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
7873 //=======================================================================
7874 //function : VFrustumCulling
7875 //purpose : enables/disables view volume's culling.
7876 //=======================================================================
7877 static int VFrustumCulling (Draw_Interpretor& theDI,
7878 Standard_Integer theArgNb,
7879 const char** theArgVec)
7881 Handle(V3d_View) aView = ViewerTest::CurrentView();
7884 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
7890 theDI << (aView->IsCullingEnabled() ? "on" : "off");
7893 else if (theArgNb != 2)
7895 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
7899 TCollection_AsciiString aModeStr (theArgVec[1]);
7900 aModeStr.LowerCase();
7901 Standard_Boolean toEnable = 0;
7902 if (aModeStr == "on")
7906 else if (aModeStr == "off")
7912 toEnable = Draw::Atoi (theArgVec[1]) != 0;
7915 aView->SetFrustumCulling (toEnable);
7920 //=======================================================================
7921 //function : VHighlightSelected
7923 //=======================================================================
7924 static int VHighlightSelected (Draw_Interpretor& theDI,
7925 Standard_Integer theArgNb,
7926 const char** theArgVec)
7928 if (ViewerTest::GetAISContext().IsNull())
7930 std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n";
7934 const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7938 theDI << (aContext->ToHilightSelected() ? "on" : "off");
7944 std::cout << theArgVec[0] << " error : wrong number of parameters."
7945 << "Type 'help" << theArgVec[0] << "' for more information.";
7950 TCollection_AsciiString aMode (theArgVec[1]);
7952 Standard_Boolean toEnable = Standard_False;
7953 if (aMode.IsEqual ("on"))
7955 toEnable = Standard_True;
7957 else if (aMode.IsEqual ("off"))
7959 toEnable = Standard_False;
7963 toEnable = Draw::Atoi (theArgVec[1]) != 0;
7966 if (toEnable != aContext->ToHilightSelected())
7968 aContext->SetToHilightSelected (toEnable);
7970 // Move cursor to null position and back to process updating of detection
7971 // and highlighting of selected object immediatly.
7972 Standard_Integer aPixX = 0;
7973 Standard_Integer aPixY = 0;
7974 const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager();
7976 anEventManager->GetCurrentPosition (aPixX, aPixY);
7977 anEventManager->MoveTo (0, 0);
7978 anEventManager->MoveTo (aPixX, aPixY);
7984 //=======================================================================
7985 //function : VXRotate
7987 //=======================================================================
7988 static Standard_Integer VXRotate (Draw_Interpretor& di,
7989 Standard_Integer argc,
7992 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7993 if (aContext.IsNull())
7995 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
8001 di << "ERROR : Usage : " << argv[0] << " name angle" << "\n";
8005 TCollection_AsciiString aName (argv[1]);
8006 Standard_Real anAngle = Draw::Atof (argv[2]);
8009 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
8010 Handle(AIS_InteractiveObject) anIObj;
8011 if (!aMap.IsBound2 (aName) )
8013 di << "Use 'vdisplay' before" << "\n";
8018 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
8021 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
8022 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
8024 aContext->SetLocation (anIObj, aTransform);
8025 aContext->UpdateCurrentViewer();
8031 //=======================================================================
8032 //function : ViewerCommands
8034 //=======================================================================
8036 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
8039 const char *group = "ZeViewer";
8040 theCommands.Add("vinit",
8041 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
8042 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
8044 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
8046 " - Creates new View window with specified name view_name.\n"
8047 "By default the new view is created in the viewer and in"
8048 " graphic driver shared with active view.\n"
8049 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
8050 "If driverName isn't specified the driver will be shared with active view.\n"
8051 "If viewerName isn't specified the viewer will be shared with active view.\n"
8052 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
8053 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
8054 "is used in creation of graphic driver\n"
8056 " - l, t: pixel position of left top corner of the window\n"
8057 " - w,h: width and heigth of window respectively.\n"
8058 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
8059 __FILE__,VInit,group);
8060 theCommands.Add("vclose" ,
8061 "[view_id [keep_context=0|1]]\n"
8062 "or vclose ALL - to remove all created views\n"
8063 " - removes view(viewer window) defined by its view_id.\n"
8064 " - keep_context: by default 0; if 1 and the last view is deleted"
8065 " the current context is not removed.",
8066 __FILE__,VClose,group);
8067 theCommands.Add("vactivate" ,
8069 " - activates view(viewer window) defined by its view_id",
8070 __FILE__,VActivate,group);
8071 theCommands.Add("vviewlist",
8072 "vviewlist [format={tree, long}]"
8073 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
8074 " - format: format of result output, if tree the output is a tree view;"
8075 "otherwise it's a list of full view names. By default format = tree",
8076 __FILE__,VViewList,group);
8077 theCommands.Add("vhelp" ,
8078 "vhelp : display help on the viewer commands",
8079 __FILE__,VHelp,group);
8080 theCommands.Add("vtop" ,
8081 "vtop or <T> : Top view" ,
8082 __FILE__,VTop,group);
8083 theCommands.Add("vbottom" ,
8084 "vbottom : Bottom view" ,
8085 __FILE__,VBottom,group);
8086 theCommands.Add("vleft" ,
8087 "vleft : Left view" ,
8088 __FILE__,VLeft,group);
8089 theCommands.Add("vright" ,
8090 "vright : Right view" ,
8091 __FILE__,VRight,group);
8092 theCommands.Add("vaxo" ,
8093 " vaxo or <A> : Axonometric view ",
8094 __FILE__,VAxo,group);
8095 theCommands.Add("vfront" ,
8096 "vfront : Front view" ,
8097 __FILE__,VFront,group);
8098 theCommands.Add("vback" ,
8099 "vback : Back view" ,
8100 __FILE__,VBack,group);
8101 theCommands.Add("vpick" ,
8102 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
8104 theCommands.Add("vfit" ,
8105 "vfit or <F> : vfit",
8106 __FILE__,VFit,group);
8107 theCommands.Add ("vfitarea",
8108 "vfitarea x1 y1 x2 y2"
8109 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
8110 "\n\t\t: Fit view to show area located between two points"
8111 "\n\t\t: given in world 2D or 3D corrdinates.",
8112 __FILE__, VFitArea, group);
8113 theCommands.Add ("vzfit", "vzfit [scale]\n"
8114 " Matches Z near, Z far view volume planes to the displayed objects.\n"
8115 " \"scale\" - specifies factor to scale computed z range.\n",
8116 __FILE__, VZFit, group);
8117 theCommands.Add("vrepaint",
8118 "vrepaint : vrepaint, force redraw",
8119 __FILE__,VRepaint,group);
8120 theCommands.Add("vclear",
8122 __FILE__,VClear,group);
8123 theCommands.Add("vsetbg",
8124 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
8125 __FILE__,VSetBg,group);
8126 theCommands.Add("vsetbgmode",
8127 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
8128 __FILE__,VSetBgMode,group);
8129 theCommands.Add("vsetgradientbg",
8130 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
8131 __FILE__,VSetGradientBg,group);
8132 theCommands.Add("vsetgrbgmode",
8133 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
8134 __FILE__,VSetGradientBgMode,group);
8135 theCommands.Add("vsetcolorbg",
8136 "vsetcolorbg : vsetcolorbg r g b : Set background color",
8137 __FILE__,VSetColorBg,group);
8138 theCommands.Add("vscale",
8139 "vscale : vscale X Y Z",
8140 __FILE__,VScale,group);
8141 theCommands.Add("vzbufftrihedron",
8142 "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]"
8143 "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]"
8144 "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]"
8145 "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]"
8146 "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]"
8147 "\n\t\t: Displays a trihedron",
8148 __FILE__,VZBuffTrihedron,group);
8149 theCommands.Add("vrotate",
8150 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
8151 "\n : Option -mouseStart starts rotation according to the mouse position"
8152 "\n : Option -mouseMove continues rotation with angle computed"
8153 "\n : from last and new mouse position."
8154 "\n : vrotate AX AY AZ [X Y Z]",
8155 __FILE__,VRotate,group);
8156 theCommands.Add("vzoom",
8157 "vzoom : vzoom coef",
8158 __FILE__,VZoom,group);
8159 theCommands.Add("vpan",
8160 "vpan : vpan dx dy",
8161 __FILE__,VPan,group);
8162 theCommands.Add("vexport",
8163 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
8164 " : exports the view to a vector file of a given format"
8165 " : notice that EMF format requires patched gl2ps",
8166 __FILE__,VExport,group);
8167 theCommands.Add("vcolorscale",
8168 "vcolorscale : vcolorscale [-range RangeMin = 0 RangeMax = 100 Intervals = 10 -font HeightFont = 16 -textpos "
8169 "Position = left -xy X = 0 Y = 0] [-noupdate|-update]: draw color scale\n"
8170 "-demo/-demoversion draw a demoversion of color scale.\n"
8171 "-show/display display color scale.\n"
8172 "-hide/erase erase color scale.\n"
8173 "Please note that -show/-hide option must be the first argument!\n"
8174 "-color Index R G B: set color for indexed interval\n"
8175 "-color Index ColorName: set color for indexed interval\n"
8176 "-colors R G B R G B ...: set colors for all intervals\n"
8177 "-colors ColorName1 ColorName2 ...: set colors for all intervals\n"
8178 "-colors supports both color names and rgb values in one call\n"
8179 "-label Index Text: set label for indexed interval\n"
8180 "-labels Text Text Text ...: set labels for all intervals\n"
8181 "-title Title [Position]: set the title for color scale with certain position. Default position = center;\n"
8182 "Available text positions: left, right, center, none;\n",
8183 __FILE__,VColorScale,group);
8184 theCommands.Add("vgraduatedtrihedron",
8185 "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n"
8186 "\t[-namefont Name] [-valuesfont Name]\n"
8187 "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n"
8188 "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]"
8189 "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n"
8190 "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n"
8191 "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]"
8192 "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n"
8193 "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n"
8194 "\t[-xticks Number] [-yticks Number] [-zticks Number]\n"
8195 "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n"
8196 "\t[-drawgrid on/off] [-drawaxes on/off]\n"
8197 " - Displays or erases graduated trihedron"
8198 " - xname, yname, zname - names of axes, default: X, Y, Z\n"
8199 " - namefont - font of axes names. Default: Arial\n"
8200 " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n"
8201 " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n"
8202 " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n"
8203 " - valuesfont - font of axes values. Default: Arial\n"
8204 " - xcolor, ycolor, zcolor - color of axis and values\n"
8205 " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n"
8206 " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n",
8207 __FILE__,VGraduatedTrihedron,group);
8208 theCommands.Add("vprintview" ,
8209 "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
8210 __FILE__,VPrintView,group);
8211 theCommands.Add("vzlayer",
8212 "vzlayer add/del/get/settings/enable/disable [id]\n"
8213 " add - add new z layer to viewer and print its id\n"
8214 " del - del z layer by its id\n"
8215 " get - print sequence of z layers in increasing order of their overlay level\n"
8216 " settings - print status of z layer settings\n"
8217 " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n"
8218 " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n"
8219 " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n"
8220 "\nWhere id is the layer identificator\n"
8223 " vzlayer enable poffset 1\n"
8224 " vzlayer disable depthtest 1\n"
8226 __FILE__,VZLayer,group);
8227 theCommands.Add("voverlaytext",
8228 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
8229 " : height - pixel height of the text (default=10.0)"
8230 " : font_name - name of font (default=courier)"
8231 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
8232 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
8233 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
8234 __FILE__,VOverlayText,group);
8235 theCommands.Add("vlayerline",
8236 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
8237 __FILE__,VLayerLine,group);
8238 theCommands.Add ("vgrid",
8239 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
8240 " : Mode - rectangular or circular"
8241 " : Type - lines or points",
8242 __FILE__, VGrid, group);
8243 theCommands.Add ("vfps",
8244 "vfps [framesNb=100] : estimate average frame rate for active view",
8245 __FILE__, VFps, group);
8246 theCommands.Add ("vgldebug",
8247 "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n"
8248 " : this function is implemented only for Windows\n"
8249 " : GL_ARB_debug_output extension should be exported by OpenGL driver!",
8250 __FILE__, VGlDebug, group);
8251 theCommands.Add ("vvbo",
8252 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
8253 __FILE__, VVbo, group);
8254 theCommands.Add ("vstereo",
8255 "\nvstereo [{0|1}] : turn stereo usage On/Off; affects only newly displayed objects",
8256 __FILE__, VStereo, group);
8257 theCommands.Add ("vcaps",
8258 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
8259 "\n\t\t: [-compatibleContext {0|1}]"
8260 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
8261 "\n\t\t: Modify particular graphic driver options:"
8262 "\n\t\t: FFP - use fixed-function pipeline instead of"
8263 "\n\t\t: built-in GLSL programs"
8264 "\n\t\t: (requires compatible profile)"
8265 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
8266 "\n\t\t: arrays to GPU memory)"
8267 "\n\t\t: sprite - use textured sprites instead of bitmaps"
8268 "\n\t\t: Context creation options:"
8269 "\n\t\t: softMode - software OpenGL implementation"
8270 "\n\t\t: compatibleProfile - backward-compatible profile"
8271 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
8272 "\n\t\t: rendering paths producing the same visual result when"
8274 "\n\t\t: Command is intended for testing old hardware compatibility.",
8275 __FILE__, VCaps, group);
8276 theCommands.Add ("vmemgpu",
8277 "vmemgpu [f]: print system-dependent GPU memory information if available;"
8278 " with f option returns free memory in bytes",
8279 __FILE__, VMemGpu, group);
8280 theCommands.Add ("vreadpixel",
8281 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
8282 " : Read pixel value for active view",
8283 __FILE__, VReadPixel, group);
8284 theCommands.Add("diffimage",
8285 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
8286 __FILE__, VDiffImage, group);
8287 theCommands.Add ("vselect",
8288 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
8289 "- emulates different types of selection:\n"
8290 "- 1) single click selection\n"
8291 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
8292 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
8293 "- 4) any of these selections with shift button pressed",
8294 __FILE__, VSelect, group);
8295 theCommands.Add ("vmoveto",
8297 "- emulates cursor movement to pixel postion (x,y)",
8298 __FILE__, VMoveTo, group);
8299 theCommands.Add ("vviewparams", "vviewparams usage:\n"
8301 "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n"
8302 " [-proj [x y z]] [-center x y] [-size sx]\n"
8303 "- Gets or sets current view parameters.\n"
8304 "- If called without arguments, all view parameters are printed.\n"
8305 "- The options are:\n"
8306 " -scale [s] : prints or sets viewport relative scale.\n"
8307 " -eye [x y z] : prints or sets eye location.\n"
8308 " -at [x y z] : prints or sets center of look.\n"
8309 " -up [x y z] : prints or sets direction of up vector.\n"
8310 " -proj [x y z] : prints or sets direction of look.\n"
8311 " -center x y : sets location of center of the screen in pixels.\n"
8312 " -size [sx] : prints viewport projection width and height sizes\n"
8313 " : or changes the size of its maximum dimension.\n",
8314 __FILE__, VViewParams, group);
8315 theCommands.Add("vchangeselected",
8316 "vchangeselected shape"
8317 "- adds to shape to selection or remove one from it",
8318 __FILE__, VChangeSelected, group);
8319 theCommands.Add("vzclipping",
8320 "vzclipping [mode] [depth width]\n"
8321 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
8322 "- gets or sets ZClipping mode, width and depth",
8323 __FILE__,VZClipping,group);
8324 theCommands.Add ("vnbselected",
8325 "vnbselected", __FILE__, VNbSelected, group);
8326 theCommands.Add ("vcamera",
8327 "vcamera [-ortho] [-projtype]"
8329 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
8330 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
8331 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
8332 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
8333 "\n\t\t: Manage camera parameters."
8334 "\n\t\t: Prints current value when option called without argument."
8335 "\n\t\t: Orthographic camera:"
8336 "\n\t\t: -ortho activate orthographic projection"
8337 "\n\t\t: Perspective camera:"
8338 "\n\t\t: -persp activate perspective projection (mono)"
8339 "\n\t\t: -fovy field of view in y axis, in degrees"
8340 "\n\t\t: -distance distance of eye from camera center"
8341 "\n\t\t: Stereoscopic camera:"
8342 "\n\t\t: -stereo perspective projection (stereo)"
8343 "\n\t\t: -leftEye perspective projection (left eye)"
8344 "\n\t\t: -rightEye perspective projection (right eye)"
8345 "\n\t\t: -iod intraocular distance value"
8346 "\n\t\t: -iodType distance type, absolute or relative"
8347 "\n\t\t: -zfocus stereographic focus value"
8348 "\n\t\t: -zfocusType focus type, absolute or relative",
8349 __FILE__, VCamera, group);
8350 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
8351 "- vautozfit [on={1|0}] [scale]\n"
8352 " Prints or changes parameters of automatic z-fit mode:\n"
8353 " \"on\" - turns automatic z-fit on or off\n"
8354 " \"scale\" - specifies factor to scale computed z range.\n",
8355 __FILE__, VAutoZFit, group);
8356 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
8357 " vzrange - without parameters shows current values\n"
8358 " vzrange [znear] [zfar] - applies provided values to view",
8359 __FILE__,VZRange, group);
8360 theCommands.Add("vantialiasing",
8361 "vantialiasing 1|0",
8362 __FILE__,VAntialiasing,group);
8363 theCommands.Add ("vpurgedisplay",
8365 "- removes structures which don't belong to objects displayed in neutral point",
8366 __FILE__, VPurgeDisplay, group);
8367 theCommands.Add("vsetviewsize",
8368 "vsetviewsize size",
8369 __FILE__,VSetViewSize,group);
8370 theCommands.Add("vmoveview",
8371 "vmoveview Dx Dy Dz [Start = 1|0]",
8372 __FILE__,VMoveView,group);
8373 theCommands.Add("vtranslateview",
8374 "vtranslateview Dx Dy Dz [Start = 1|0)]",
8375 __FILE__,VTranslateView,group);
8376 theCommands.Add("vturnview",
8377 "vturnview Ax Ay Az [Start = 1|0]",
8378 __FILE__,VTurnView,group);
8379 theCommands.Add("vtextureenv",
8380 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
8381 "or user-defined file and optionally applying texture mapping parameters\n"
8383 " vtextureenv off - disables environment mapping\n"
8384 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
8385 " std_texture = (0..7)\n"
8386 " rep = {clamp|repeat}\n"
8387 " mod = {decal|modulate}\n"
8388 " flt = {nearest|bilinear|trilinear}\n"
8389 " ss, st - scale factors for s and t texture coordinates\n"
8390 " ts, tt - translation for s and t texture coordinates\n"
8391 " rot - texture rotation angle in degrees",
8392 __FILE__, VTextureEnv, group);
8393 theCommands.Add("vhlr" ,
8394 "is_enabled={on|off} [show_hidden={1|0}]"
8395 " - Hidden line removal algorithm:"
8396 " - is_enabled: if is on HLR algorithm is applied\n"
8397 " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n",
8398 __FILE__,VHLR,group);
8399 theCommands.Add("vhlrtype" ,
8400 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
8401 " - Changes the type of HLR algorithm using for shapes."
8402 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
8403 " if equals to polyalgo, polygonal HLR algorithm is applied."
8404 "If shapes are not given HLR algoithm of given type is applied"
8405 " to all shapes in the view\n",
8406 __FILE__,VHLRType,group);
8407 theCommands.Add("vclipplane", "vclipplane usage: \n"
8408 " maxplanes <view_name> - get plane limit for view.\n"
8409 " create <plane_name> - create new plane.\n"
8410 " delete <plane_name> - delete plane.\n"
8411 " clone <source_plane> <plane_name> - clone the plane definition.\n"
8412 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
8413 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
8414 " change <plane_name> on/off - turn clipping on/off.\n"
8415 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
8416 " change <plane_name> capping on/off - turn capping on/off.\n"
8417 " change <plane_name> capping color <r> <g> <b> - set color.\n"
8418 " change <plane name> capping texname <texture> - set texture.\n"
8419 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
8420 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
8421 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
8422 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
8423 " please use VSetTextureMode command to enable texture rendering in view.\n"
8424 , __FILE__, VClipPlane, group);
8425 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
8427 " 0 - no textures enabled in view.\n"
8428 " 1 - only environment textures enabled.\n"
8429 " 2 - all textures enabled.\n"
8430 " this command sets texture details mode for the specified view.\n"
8431 , __FILE__, VSetTextureMode, group);
8432 theCommands.Add("vdefaults",
8433 "vdefaults [-absDefl value]"
8434 "\n\t\t: [-devCoeff value]"
8435 "\n\t\t: [-angDefl value]"
8436 "\n\t\t: [-autoTriang {off/on | 0/1}]"
8437 , __FILE__, VDefaults, group);
8438 theCommands.Add("vlight",
8439 "tool to manage light sources, without arguments shows list of lights."
8440 "\n Main commands: "
8441 "\n 'clear' to clear lights"
8442 "\n '{def}aults' to load deafault lights"
8443 "\n 'add' (or 'new') <type> to add any light source"
8444 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
8445 "\n 'change' <lightId> to edit light source with specified lightId"
8446 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
8447 "\n {pos}ition X Y Z"
8448 "\n {dir}ection X Y Z (for directional light or for spotlight)"
8449 "\n color colorName"
8450 "\n {head}light 0|1"
8451 "\n {constAtten}uation value"
8452 "\n {linearAtten}uation value"
8454 "\n {spotexp}onent value"
8456 "\n\n example: vlight add positional head 1 pos 0 1 1 color red"
8457 "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
8458 __FILE__, VLight, group);
8459 theCommands.Add("vraytrace",
8461 "\n\t\t: Turn on/off raytracing renderer."
8462 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
8463 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
8464 __FILE__, VRenderParams, group);
8465 theCommands.Add("vrenderparams",
8466 "\n Manages rendering parameters: "
8467 "\n '-rayTrace' Enables GPU ray-tracing"
8468 "\n '-raster' Disables GPU ray-tracing"
8469 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
8470 "\n '-shadows on|off' Enables/disables shadows rendering"
8471 "\n '-reflections on|off' Enables/disables specular reflections"
8472 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
8473 "\n '-gleam on|off' Enables/disables transparency shadow effects"
8474 "\n '-shadingModel model' Controls shading model from enumeration"
8475 "\n color, flat, gouraud, phong"
8476 "\n Unlike vcaps, these parameters dramatically change visual properties."
8477 "\n Command is intended to control presentation quality depending on"
8478 "\n hardware capabilities and performance.",
8479 __FILE__, VRenderParams, group);
8480 theCommands.Add("vfrustumculling",
8481 "vfrustumculling [toEnable]: enables/disables objects clipping",
8482 __FILE__,VFrustumCulling,group);
8483 theCommands.Add("vhighlightselected",
8484 "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n"
8485 "Without arguments it shows if highlighting of selected objects is enabled now.",
8486 __FILE__,VHighlightSelected,group);
8487 theCommands.Add ("vplace",
8489 "\n\t\t: Places the point (in pixels) at the center of the window",
8490 __FILE__, VPlace, group);
8491 theCommands.Add("vxrotate",
8493 __FILE__,VXRotate,group);