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_TextureEnv.hxx>
27 #include <Graphic3d_TextureParams.hxx>
28 #include <Graphic3d_TypeOfTextureFilter.hxx>
29 #include <Graphic3d_AspectFillArea3d.hxx>
30 #include <ViewerTest.hxx>
31 #include <ViewerTest_AutoUpdater.hxx>
32 #include <ViewerTest_EventManager.hxx>
33 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
34 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
35 #include <Visual3d_View.hxx>
36 #include <Visual3d_ViewManager.hxx>
37 #include <V3d_AmbientLight.hxx>
38 #include <V3d_ColorScale.hxx>
39 #include <V3d_DirectionalLight.hxx>
40 #include <V3d_LayerMgr.hxx>
41 #include <V3d_LayerMgrPointer.hxx>
42 #include <V3d_PositionalLight.hxx>
43 #include <V3d_SpotLight.hxx>
44 #include <NCollection_DoubleMap.hxx>
45 #include <NCollection_List.hxx>
46 #include <NCollection_Vector.hxx>
47 #include <NIS_View.hxx>
48 #include <NIS_Triangulated.hxx>
49 #include <NIS_InteractiveContext.hxx>
50 #include <AIS_InteractiveContext.hxx>
51 #include <Draw_Interpretor.hxx>
53 #include <Draw_Appli.hxx>
54 #include <Aspect_PrintAlgo.hxx>
55 #include <Image_AlienPixMap.hxx>
56 #include <OpenGl_GraphicDriver.hxx>
57 #include <OSD_Timer.hxx>
58 #include <TColStd_HSequenceOfAsciiString.hxx>
59 #include <TColStd_SequenceOfInteger.hxx>
60 #include <TColStd_HSequenceOfReal.hxx>
61 #include <TColgp_Array1OfPnt2d.hxx>
62 #include <TColStd_MapOfAsciiString.hxx>
63 #include <Visual3d_LayerItem.hxx>
64 #include <Aspect_TypeOfLine.hxx>
65 #include <Image_Diff.hxx>
66 #include <Aspect_DisplayConnection.hxx>
70 #include <PrsMgr_PresentableObject.hxx>
71 #include <Graphic3d_ClipPlane.hxx>
72 #include <NCollection_DataMap.hxx>
73 #include <Graphic3d_Texture2Dmanual.hxx>
74 #include <Prs3d_ShadingAspect.hxx>
75 #include <Prs3d_Drawer.hxx>
81 #include <Visual3d_Layer.hxx>
85 #include <WNT_WClass.hxx>
86 #include <WNT_Window.hxx>
89 #define _CRT_SECURE_NO_DEPRECATE
90 #pragma warning (disable:4996)
92 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
93 #include <Cocoa_Window.hxx>
95 #include <Xw_Window.hxx>
96 #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
97 #include <X11/Xutil.h>
101 inline Standard_Boolean parseOnOff (Standard_CString theArg,
102 Standard_Boolean& theIsOn)
104 TCollection_AsciiString aFlag (theArg);
109 theIsOn = Standard_True;
110 return Standard_True;
112 else if (aFlag == "off"
115 theIsOn = Standard_False;
116 return Standard_True;
118 return Standard_False;
121 // Auxiliary definitions
122 static const char THE_KEY_DELETE = 127;
124 //==============================================================================
125 // VIEWER GLOBAL VARIABLES
126 //==============================================================================
128 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
129 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
131 Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
132 extern const Handle(NIS_InteractiveContext)& TheNISContext();
133 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
135 extern int VErase (Draw_Interpretor& theDI,
136 Standard_Integer theArgNb,
137 const char** theArgVec);
140 static Handle(WNT_Window)& VT_GetWindow() {
141 static Handle(WNT_Window) WNTWin;
144 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
145 static Handle(Cocoa_Window)& VT_GetWindow()
147 static Handle(Cocoa_Window) aWindow;
150 extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
151 extern void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle);
152 extern void GetCocoaScreenResolution (Standard_Integer& theWidth, Standard_Integer& theHeight);
155 static Handle(Xw_Window)& VT_GetWindow(){
156 static Handle(Xw_Window) XWWin;
160 static void VProcessEvents(ClientData,int);
163 static Handle(Aspect_DisplayConnection)& GetDisplayConnection()
165 static Handle(Aspect_DisplayConnection) aDisplayConnection;
166 return aDisplayConnection;
169 static void SetDisplayConnection (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
171 GetDisplayConnection() = theDisplayConnection;
174 #if defined(_WIN32) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
175 Aspect_Handle GetWindowHandle(const Handle(Aspect_Window)& theWindow)
177 Aspect_Handle aWindowHandle = (Aspect_Handle)NULL;
179 const Handle (WNT_Window) aWindow = Handle(WNT_Window)::DownCast (theWindow);
180 if (!aWindow.IsNull())
181 return aWindow->HWindow();
182 #elif (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
183 const Handle (Xw_Window) aWindow = Handle(Xw_Window)::DownCast (theWindow);
184 if (!aWindow.IsNull())
185 return aWindow->XWindow();
187 return aWindowHandle;
191 static Standard_Boolean MyHLRIsOn = Standard_False;
193 NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
194 static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
195 static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
196 static OpenGl_Caps ViewerTest_myDefaultCaps;
198 #define ZCLIPWIDTH 1.
200 static void OSWindowSetup();
202 //==============================================================================
203 // EVENT GLOBAL VARIABLES
204 //==============================================================================
206 static int Start_Rot = 0;
207 static int ZClipIsOn = 0;
208 int X_Motion = 0; // Current cursor position
210 int X_ButtonPress = 0; // Last ButtonPress position
211 int Y_ButtonPress = 0;
212 Standard_Boolean IsDragged = Standard_False;
213 Standard_Boolean DragFirst = Standard_False;
215 //==============================================================================
218 static LRESULT WINAPI ViewerWindowProc(
223 static LRESULT WINAPI AdvViewerWindowProc(
231 //==============================================================================
234 //==============================================================================
236 const Handle(MMgt_TShared)& ViewerTest::WClass()
238 static Handle(MMgt_TShared) theWClass;
240 if (theWClass.IsNull())
242 theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
243 CS_VREDRAW | CS_HREDRAW, 0, 0,
244 ::LoadCursor (NULL, IDC_ARROW));
250 //==============================================================================
251 //function : CreateName
252 //purpose : Create numerical name for new object in theMap
253 //==============================================================================
254 template <typename ObjectType>
255 TCollection_AsciiString CreateName (const NCollection_DoubleMap <TCollection_AsciiString, ObjectType>& theObjectMap,
256 const TCollection_AsciiString& theDefaultString)
258 if (theObjectMap.IsEmpty())
259 return theDefaultString + TCollection_AsciiString(1);
261 Standard_Integer aNextKey = 1;
262 Standard_Boolean isFound = Standard_False;
265 TCollection_AsciiString aStringKey = theDefaultString + TCollection_AsciiString(aNextKey);
266 // Look for objects with default names
267 if (theObjectMap.IsBound1(aStringKey))
272 isFound = Standard_True;
275 return theDefaultString + TCollection_AsciiString(aNextKey);
278 //==============================================================================
279 //structure : ViewerTest_Names
280 //purpose : Allow to operate with full view name: driverName/viewerName/viewName
281 //==============================================================================
282 struct ViewerTest_Names
285 TCollection_AsciiString myDriverName;
286 TCollection_AsciiString myViewerName;
287 TCollection_AsciiString myViewName;
291 const TCollection_AsciiString& GetDriverName () const
295 void SetDriverName (const TCollection_AsciiString& theDriverName)
297 myDriverName = theDriverName;
299 const TCollection_AsciiString& GetViewerName () const
303 void SetViewerName (const TCollection_AsciiString& theViewerName)
305 myViewerName = theViewerName;
307 const TCollection_AsciiString& GetViewName () const
311 void SetViewName (const TCollection_AsciiString& theViewName)
313 myViewName = theViewName;
316 //===========================================================================
317 //function : Constructor for ViewerTest_Names
318 //purpose : Get view, viewer, driver names from custom string
319 //===========================================================================
321 ViewerTest_Names (const TCollection_AsciiString& theInputString)
323 TCollection_AsciiString aName(theInputString);
324 if (theInputString.IsEmpty())
326 // Get current configuration
327 if (ViewerTest_myDrivers.IsEmpty())
328 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
329 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
331 myDriverName = ViewerTest_myDrivers.Find2
332 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
334 if(ViewerTest_myContexts.IsEmpty())
336 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
337 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
340 myViewerName = ViewerTest_myContexts.Find2 (ViewerTest::GetAISContext());
342 myViewName = CreateName <Handle(V3d_View)>
343 (ViewerTest_myViews, TCollection_AsciiString(myViewerName + "/View"));
347 // There is at least view name
348 Standard_Integer aParserNumber = 0;
349 for (Standard_Integer i = 0; i < 3; ++i)
351 Standard_Integer aParserPos = aName.SearchFromEnd("/");
355 aName.Split(aParserPos-1);
360 if (aParserNumber == 0)
363 if (!ViewerTest::GetAISContext().IsNull())
365 myDriverName = ViewerTest_myDrivers.Find2
366 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
367 myViewerName = ViewerTest_myContexts.Find2
368 (ViewerTest::GetAISContext());
372 // There is no opened contexts here, need to create names for viewer and driver
373 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
374 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
376 myViewerName = CreateName <Handle(AIS_InteractiveContext)>
377 (ViewerTest_myContexts, TCollection_AsciiString (myDriverName + "/Viewer"));
379 myViewName = TCollection_AsciiString(myViewerName + "/" + theInputString);
381 else if (aParserNumber == 1)
383 // Here is viewerName/viewName
384 if (!ViewerTest::GetAISContext().IsNull())
385 myDriverName = ViewerTest_myDrivers.Find2
386 (ViewerTest::GetAISContext()->CurrentViewer()->Driver());
389 // There is no opened contexts here, need to create name for driver
390 myDriverName = CreateName<Handle(Graphic3d_GraphicDriver)>
391 (ViewerTest_myDrivers, TCollection_AsciiString("Driver"));
393 myViewerName = TCollection_AsciiString(myDriverName + "/" + aName);
395 myViewName = TCollection_AsciiString(myDriverName + "/" + theInputString);
399 //Here is driverName/viewerName/viewName
400 myDriverName = TCollection_AsciiString(aName);
402 TCollection_AsciiString aViewerName(theInputString);
403 aViewerName.Split(aViewerName.SearchFromEnd("/") - 1);
404 myViewerName = TCollection_AsciiString(aViewerName);
406 myViewName = TCollection_AsciiString(theInputString);
412 //==============================================================================
413 //function : FindContextByView
414 //purpose : Find AIS_InteractiveContext by View
415 //==============================================================================
417 Handle(AIS_InteractiveContext) FindContextByView (const Handle(V3d_View)& theView)
419 Handle(AIS_InteractiveContext) anAISContext;
421 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
422 anIter (ViewerTest_myContexts); anIter.More(); anIter.Next())
424 if (anIter.Value()->CurrentViewer() == theView->Viewer())
425 return anIter.Key2();
431 //==============================================================================
432 //function : SetWindowTitle
433 //purpose : Set window title
434 //==============================================================================
436 void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
437 Standard_CString theTitle)
440 SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(),
442 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
443 SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
445 if(GetDisplayConnection()->GetDisplay())
448 Handle(Xw_Window)::DownCast(theWindow)->XWindow();
449 XStoreName (GetDisplayConnection()->GetDisplay(), aWindow , theTitle);
454 //==============================================================================
455 //function : IsWindowOverlapped
456 //purpose : Check if theWindow overlapp another view
457 //==============================================================================
459 Standard_Boolean IsWindowOverlapped (const Standard_Integer thePxLeft,
460 const Standard_Integer thePxTop,
461 const Standard_Integer thePxRight,
462 const Standard_Integer thePxBottom,
463 TCollection_AsciiString& theViewId)
465 for(NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
466 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
468 Standard_Integer aTop = 0,
472 anIter.Value()->Window()->Position(aLeft, aTop, aRight, aBottom);
473 if ((thePxLeft >= aLeft && thePxLeft <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
474 (thePxLeft >= aLeft && thePxLeft <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom) ||
475 (thePxRight >= aLeft && thePxRight <= aRight && thePxTop >= aTop && thePxTop <= aBottom) ||
476 (thePxRight >= aLeft && thePxRight <= aRight && thePxBottom >= aTop && thePxBottom <= aBottom))
478 theViewId = anIter.Key1();
479 return Standard_True;
482 return Standard_False;
485 // Workaround: to create and delete non-orthographic views outside ViewerTest
486 void ViewerTest::RemoveViewName (const TCollection_AsciiString& theName)
488 ViewerTest_myViews.UnBind1 (theName);
491 void ViewerTest::InitViewName (const TCollection_AsciiString& theName,
492 const Handle(V3d_View)& theView)
494 ViewerTest_myViews.Bind (theName, theView);
497 TCollection_AsciiString ViewerTest::GetCurrentViewName ()
499 return ViewerTest_myViews.Find2( ViewerTest::CurrentView());
501 //==============================================================================
502 //function : ViewerInit
503 //purpose : Create the window viewer and initialize all the global variable
504 //==============================================================================
506 TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft,
507 const Standard_Integer thePxTop,
508 const Standard_Integer thePxWidth,
509 const Standard_Integer thePxHeight,
510 Standard_CString theViewName,
511 Standard_CString theDisplayName)
513 // Default position and dimension of the viewer window.
514 // Note that left top corner is set to be sufficiently small to have
515 // window fit in the small screens (actual for remote desktops, see #23003).
516 // The position corresponds to the window's client area, thus some
517 // gap is added for window frame to be visible.
518 Standard_Integer aPxLeft = 20;
519 Standard_Integer aPxTop = 40;
520 Standard_Integer aPxWidth = 409;
521 Standard_Integer aPxHeight = 409;
522 Standard_Boolean toCreateViewer = Standard_False;
524 Handle(OpenGl_GraphicDriver) aGraphicDriver;
525 ViewerTest_Names aViewNames(theViewName);
526 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
527 aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
534 aPxWidth = thePxWidth;
535 if (thePxHeight != 0)
536 aPxHeight = thePxHeight;
538 // Get graphic driver (create it or get from another view)
539 if (!ViewerTest_myDrivers.IsBound1 (aViewNames.GetDriverName()))
541 // Get connection string
542 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
543 TCollection_AsciiString aDisplayName(theDisplayName);
544 if (!aDisplayName.IsEmpty())
545 SetDisplayConnection (new Aspect_DisplayConnection ());
547 SetDisplayConnection (new Aspect_DisplayConnection (aDisplayName));
549 (void)theDisplayName; // avoid warning on unused argument
550 SetDisplayConnection (new Aspect_DisplayConnection ());
552 aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
553 aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
554 ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
555 toCreateViewer = Standard_True;
559 aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
562 //Dispose the window if input parameters are default
563 if (!ViewerTest_myViews.IsEmpty() && thePxLeft == 0 && thePxTop == 0)
565 Standard_Integer aTop = 0,
572 // Get screen resolution
573 #if defined(_WIN32) || defined(__WIN32__)
575 GetClientRect(GetDesktopWindow(), &aWindowSize);
576 aScreenHeight = aWindowSize.bottom;
577 aScreenWidth = aWindowSize.right;
578 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
579 GetCocoaScreenResolution (aScreenWidth, aScreenHeight);
581 Screen *aScreen = DefaultScreenOfDisplay(GetDisplayConnection()->GetDisplay());
582 aScreenWidth = WidthOfScreen(aScreen);
583 aScreenHeight = HeightOfScreen(aScreen);
586 TCollection_AsciiString anOverlappedViewId("");
588 while (IsWindowOverlapped (aPxLeft, aPxTop, aPxLeft + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId))
590 ViewerTest_myViews.Find1(anOverlappedViewId)->Window()->Position (aLeft, aTop, aRight, aBottom);
592 if (IsWindowOverlapped (aRight + 20, aPxTop, aRight + 20 + aPxWidth, aPxTop + aPxHeight, anOverlappedViewId)
593 && aRight + 2*aPxWidth + 40 > aScreenWidth)
595 if (aBottom + aPxHeight + 40 > aScreenHeight)
602 aPxTop = aBottom + 40;
605 aPxLeft = aRight + 20;
610 TCollection_AsciiString aTitle("3D View - ");
611 aTitle = aTitle + aViewNames.GetViewName() + "(*)";
613 // Change name of current active window
614 if (!ViewerTest::CurrentView().IsNull())
616 TCollection_AsciiString aTitle("3D View - ");
618 + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
619 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
623 Handle(V3d_Viewer) a3DViewer;
624 // If it's the single view, we first look for empty context
625 if (ViewerTest_myViews.IsEmpty() && !ViewerTest_myContexts.IsEmpty())
627 NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
628 anIter(ViewerTest_myContexts);
630 ViewerTest::SetAISContext (anIter.Value());
631 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
633 else if (ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName()))
635 ViewerTest::SetAISContext(ViewerTest_myContexts.Find1(aViewNames.GetViewerName()));
636 a3DViewer = ViewerTest::GetAISContext()->CurrentViewer();
638 else if (a3DViewer.IsNull())
640 toCreateViewer = Standard_True;
641 TCollection_ExtendedString NameOfWindow("Viewer3D");
642 a3DViewer = new V3d_Viewer(aGraphicDriver, NameOfWindow.ToExtString());
644 NameOfWindow = TCollection_ExtendedString("Collector");
646 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
650 if (ViewerTest::GetAISContext().IsNull() ||
651 !(ViewerTest_myContexts.IsBound1(aViewNames.GetViewerName())))
653 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (a3DViewer);
654 ViewerTest::SetAISContext (aContext);
655 ViewerTest_myContexts.Bind (aViewNames.GetViewerName(), ViewerTest::GetAISContext());
659 ViewerTest::ResetEventManager();
664 VT_GetWindow() = new WNT_Window (aTitle.ToCString(),
665 Handle(WNT_WClass)::DownCast (WClass()),
666 Draw_VirtualWindows ? WS_POPUPWINDOW : WS_OVERLAPPEDWINDOW,
670 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
671 VT_GetWindow() = new Cocoa_Window (aTitle.ToCString(),
673 aPxWidth, aPxHeight);
674 ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
676 VT_GetWindow() = new Xw_Window (aGraphicDriver->GetDisplayConnection(),
679 aPxWidth, aPxHeight);
681 VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
684 Handle(NIS_View) aView = new NIS_View (a3DViewer, VT_GetWindow());
686 ViewerTest::CurrentView(aView);
687 ViewerTest_myViews.Bind (aViewNames.GetViewName(), aView);
688 TheNISContext()->AttachView (aView);
690 // Setup for X11 or NT
693 // Set parameters for V3d_View and V3d_Viewer
694 const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
695 aV3dView->SetComputedMode(Standard_False);
696 MyHLRIsOn = aV3dView->ComputedMode();
697 aV3dView->SetZClippingDepth(0.5);
698 aV3dView->SetZClippingWidth(ZCLIPWIDTH/2.);
700 a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
703 a3DViewer->SetDefaultLights();
704 a3DViewer->SetLightOn();
707 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
708 #if TCL_MAJOR_VERSION < 8
709 Tk_CreateFileHandler((void*)XConnectionNumber(GetDisplayConnection()->GetDisplay()),
710 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
712 Tk_CreateFileHandler(XConnectionNumber(GetDisplayConnection()->GetDisplay()),
713 TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
717 VT_GetWindow()->Map();
719 // Set the handle of created view in the event manager
720 ViewerTest::ResetEventManager();
722 ViewerTest::CurrentView()->Redraw();
727 return aViewNames.GetViewName();
730 //==============================================================================
731 //function : RedrawAllViews
732 //purpose : Redraw all created views
733 //==============================================================================
734 void ViewerTest::RedrawAllViews()
736 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
737 for (; aViewIt.More(); aViewIt.Next())
739 const Handle(V3d_View)& aView = aViewIt.Key2();
744 //==============================================================================
746 //purpose : Create the window viewer and initialize all the global variable
747 // Use Tk_CreateFileHandler on UNIX to catch the X11 Viewer event
748 //==============================================================================
750 static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
754 std::cerr << theArgVec[0] << ": incorrect number of command arguments.\n"
755 << "Type help for more information.\n";
759 TCollection_AsciiString aViewName, aDisplayName;
760 Standard_Integer aPxLeft = 0, aPxTop = 0, aPxWidth = 0, aPxHeight = 0;
761 TCollection_AsciiString aName, aValue;
762 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
764 const TCollection_AsciiString anArg = theArgVec[anArgIt];
765 TCollection_AsciiString anArgCase = anArg;
766 anArgCase.UpperCase();
767 if (ViewerTest::SplitParameter (anArg, aName, aValue))
770 if (aName.IsEqual ("NAME"))
774 else if (aName.IsEqual ("L")
775 || aName.IsEqual ("LEFT"))
777 aPxLeft = aValue.IntegerValue();
779 else if (aName.IsEqual ("T")
780 || aName.IsEqual ("TOP"))
782 aPxTop = aValue.IntegerValue();
784 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
785 else if (aName.IsEqual ("DISP")
786 || aName.IsEqual ("DISPLAY"))
788 aDisplayName = aValue;
791 else if (aName.IsEqual ("W")
792 || aName.IsEqual ("WIDTH"))
794 aPxWidth = aValue.IntegerValue();
796 else if (aName.IsEqual ("H")
797 || aName.IsEqual ("HEIGHT"))
799 aPxHeight = aValue.IntegerValue();
803 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
806 else if (aViewName.IsEmpty())
812 std::cerr << theArgVec[0] << ": Warning: unknown argument " << anArg << ".\n";
816 ViewerTest_Names aViewNames (aViewName);
817 if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName()))
819 TCollection_AsciiString aCommand = TCollection_AsciiString ("vactivate ") + aViewNames.GetViewName();
820 theDi.Eval (aCommand.ToCString());
824 TCollection_AsciiString aViewId = ViewerTest::ViewerInit (aPxLeft, aPxTop, aPxWidth, aPxHeight,
825 aViewName.ToCString(),
826 aDisplayName.ToCString());
831 //==============================================================================
833 //purpose : hidden lines removal algorithm
834 //draw args: vhlr is_enabled={on|off} [show_hidden={1|0}]
835 //==============================================================================
837 static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
839 if (ViewerTest::CurrentView().IsNull())
841 di << argv[0] << ": Call vinit before this command, please.\n";
847 di << argv[0] << ": Wrong number of command arguments.\n"
848 << "Type help " << argv[0] << " for more information.\n";
852 // Enable or disable HLR mode.
853 Standard_Boolean isHLROn =
854 (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
856 if (isHLROn != MyHLRIsOn)
859 ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
862 // Show or hide hidden lines in HLR mode.
863 Standard_Boolean isCurrentShowHidden
864 = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine();
866 Standard_Boolean isShowHidden =
867 (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False)
868 : isCurrentShowHidden;
871 if (isShowHidden != isCurrentShowHidden)
875 ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine();
879 ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine();
885 AIS_ListOfInteractive aListOfShapes;
886 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
888 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
890 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value());
900 ViewerTest::CurrentView()->Update();
904 //==============================================================================
905 //function : VHLRType
906 //purpose : change type of using HLR algorithm
907 //==============================================================================
909 static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
911 if (ViewerTest::CurrentView().IsNull())
913 di << argv[0] << ": Call vinit before this command, please.\n";
919 di << argv[0] << ": Wrong number of command arguments.\n"
920 << "Type help " << argv[0] << " for more information.\n";
924 Prs3d_TypeOfHLR aTypeOfHLR =
925 (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
929 AIS_ListOfInteractive aListOfShapes;
930 ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
931 ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
932 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
933 anIter.More(); anIter.Next())
935 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
938 if (aShape->TypeOfHLR() != aTypeOfHLR)
939 aShape->SetTypeOfHLR (aTypeOfHLR);
943 ViewerTest::CurrentView()->Update();
948 for (Standard_Integer i = 2; i < argc; ++i)
950 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
951 TCollection_AsciiString aName (argv[i]);
953 if (!aMap.IsBound2 (aName))
955 di << argv[0] << ":" << " Wrong shape name:" << aName.ToCString() << ".\n";
958 Handle(AIS_Shape) anAISObject =
959 Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
960 if (anAISObject.IsNull())
962 anAISObject->SetTypeOfHLR (aTypeOfHLR);
964 anAISObject->Redisplay();
966 ViewerTest::CurrentView()->Update();
972 //==============================================================================
973 //function : FindViewIdByWindowHandle
974 //purpose : Find theView Id in the map of views by window handle
975 //==============================================================================
976 #if defined(_WIN32) || defined(__WIN32__) || (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
977 TCollection_AsciiString FindViewIdByWindowHandle(const Aspect_Handle theWindowHandle)
979 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator
980 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
982 Aspect_Handle aWindowHandle = GetWindowHandle(anIter.Value()->Window());
983 if (aWindowHandle == theWindowHandle)
984 return anIter.Key1();
986 return TCollection_AsciiString("");
990 //==============================================================================
991 //function : ActivateView
992 //purpose : Make the view active
993 //==============================================================================
995 void ActivateView (const TCollection_AsciiString& theViewName)
997 const Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1000 Handle(AIS_InteractiveContext) anAISContext = FindContextByView(aView);
1001 if (!anAISContext.IsNull())
1003 if (!ViewerTest::CurrentView().IsNull())
1005 TCollection_AsciiString aTitle("3D View - ");
1006 aTitle = aTitle + ViewerTest_myViews.Find2 (ViewerTest::CurrentView());
1007 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1010 ViewerTest::CurrentView (aView);
1011 // Update degenerate mode
1012 MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
1013 ViewerTest::SetAISContext (anAISContext);
1014 TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
1015 aTitle = aTitle + theViewName + "(*)";
1016 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1017 #if defined(_WIN32) || defined(__WIN32__)
1018 VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
1019 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1020 VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
1022 VT_GetWindow() = Handle(Xw_Window)::DownCast(ViewerTest::CurrentView()->Window());
1024 SetDisplayConnection(ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
1025 ViewerTest::CurrentView()->Redraw();
1030 //==============================================================================
1031 //function : RemoveView
1033 //==============================================================================
1034 void ViewerTest::RemoveView (const Handle(V3d_View)& theView,
1035 const Standard_Boolean theToRemoveContext)
1037 if (!ViewerTest_myViews.IsBound2 (theView))
1042 const TCollection_AsciiString aViewName = ViewerTest_myViews.Find2 (theView);
1043 RemoveView (aViewName, theToRemoveContext);
1046 //==============================================================================
1047 //function : RemoveView
1048 //purpose : Close and remove view from display, clear maps if neccessary
1049 //==============================================================================
1050 void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const Standard_Boolean isContextRemoved)
1052 if (!ViewerTest_myViews.IsBound1(theViewName))
1054 cout << "Wrong view name\n";
1058 // Activate another view if it's active now
1059 if (ViewerTest_myViews.Find1(theViewName) == ViewerTest::CurrentView())
1061 if (ViewerTest_myViews.Extent() > 1)
1063 TCollection_AsciiString aNewViewName;
1064 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> :: Iterator
1065 anIter(ViewerTest_myViews); anIter.More(); anIter.Next())
1066 if (anIter.Key1() != theViewName)
1068 aNewViewName = anIter.Key1();
1071 ActivateView (aNewViewName);
1075 Handle(V3d_View) anEmptyView;
1076 #if defined(_WIN32) || defined(__WIN32__)
1077 Handle(WNT_Window) anEmptyWindow;
1078 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1079 Handle(Cocoa_Window) anEmptyWindow;
1081 Handle(Xw_Window) anEmptyWindow;
1083 VT_GetWindow() = anEmptyWindow;
1084 ViewerTest::CurrentView (anEmptyView);
1085 if (isContextRemoved)
1087 Handle(AIS_InteractiveContext) anEmptyContext;
1088 ViewerTest::SetAISContext(anEmptyContext);
1094 Handle(V3d_View) aView = ViewerTest_myViews.Find1(theViewName);
1095 Handle(AIS_InteractiveContext) aCurrentContext = FindContextByView(aView);
1097 // Remove view resources
1098 TheNISContext()->DetachView(Handle(NIS_View)::DownCast(aView));
1099 ViewerTest_myViews.UnBind1(theViewName);
1102 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1103 XFlush (GetDisplayConnection()->GetDisplay());
1106 // Keep context opened only if the closed view is last to avoid
1107 // unused empty contexts
1108 if (!aCurrentContext.IsNull())
1110 // Check if there are more difined views in the viewer
1111 aCurrentContext->CurrentViewer()->InitDefinedViews();
1112 if ((isContextRemoved || ViewerTest_myContexts.Size() != 1) && !aCurrentContext->CurrentViewer()->MoreDefinedViews())
1114 // Remove driver if there is no viewers that use it
1115 Standard_Boolean isRemoveDriver = Standard_True;
1116 for(NCollection_DoubleMap<TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1117 anIter(ViewerTest_myContexts); anIter.More(); anIter.Next())
1119 if (aCurrentContext != anIter.Key2() &&
1120 aCurrentContext->CurrentViewer()->Driver() == anIter.Value()->CurrentViewer()->Driver())
1122 isRemoveDriver = Standard_False;
1128 ViewerTest_myDrivers.UnBind2 (aCurrentContext->CurrentViewer()->Driver());
1129 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1130 #if TCL_MAJOR_VERSION < 8
1131 Tk_DeleteFileHandler((void*)XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1133 Tk_DeleteFileHandler(XConnectionNumber(aCurrentContext->CurrentViewer()->Driver()->GetDisplayConnection()->GetDisplay()));
1138 ViewerTest_myContexts.UnBind2(aCurrentContext);
1141 cout << "3D View - " << theViewName << " was deleted.\n";
1145 //==============================================================================
1147 //purpose : Remove the view defined by its name
1148 //==============================================================================
1150 static int VClose (Draw_Interpretor& /*theDi*/,
1151 Standard_Integer theArgsNb,
1152 const char** theArgVec)
1154 NCollection_List<TCollection_AsciiString> aViewList;
1157 TCollection_AsciiString anArg (theArgVec[1]);
1159 if (anArg.IsEqual ("ALL")
1160 || anArg.IsEqual ("*"))
1162 for (NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator anIter (ViewerTest_myViews);
1163 anIter.More(); anIter.Next())
1165 aViewList.Append (anIter.Key1());
1167 if (aViewList.IsEmpty())
1169 std::cout << "No view to close\n";
1175 ViewerTest_Names aViewName (theArgVec[1]);
1176 if (!ViewerTest_myViews.IsBound1 (aViewName.GetViewName()))
1178 std::cerr << "The view with name '" << theArgVec[1] << "' does not exist\n";
1181 aViewList.Append (aViewName.GetViewName());
1186 // close active view
1187 if (ViewerTest::CurrentView().IsNull())
1189 std::cerr << "No active view!\n";
1192 aViewList.Append (ViewerTest_myViews.Find2 (ViewerTest::CurrentView()));
1195 Standard_Boolean toRemoveContext = (theArgsNb != 3 || Draw::Atoi (theArgVec[2]) != 1);
1196 for (NCollection_List<TCollection_AsciiString>::Iterator anIter(aViewList);
1197 anIter.More(); anIter.Next())
1199 ViewerTest::RemoveView (anIter.Value(), toRemoveContext);
1205 //==============================================================================
1206 //function : VActivate
1207 //purpose : Activate the view defined by its ID
1208 //==============================================================================
1210 static int VActivate (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1214 theDi << theArgVec[0] << ": wrong number of command arguments.\n"
1215 << "Usage: " << theArgVec[0] << " ViewID\n";
1220 theDi.Eval("vviewlist");
1224 TCollection_AsciiString aNameString(theArgVec[1]);
1225 if ( strcasecmp( aNameString.ToCString(), "NONE" ) == 0 )
1227 TCollection_AsciiString aTitle("3D View - ");
1228 aTitle = aTitle + ViewerTest_myViews.Find2(ViewerTest::CurrentView());
1229 SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
1230 Handle(V3d_View) anEmptyView;
1231 #if defined(_WIN32) || defined(__WIN32__)
1232 Handle(WNT_Window) anEmptyWindow;
1233 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1234 Handle(Cocoa_Window) anEmptyWindow;
1236 Handle(Xw_Window) anEmptyWindow;
1238 VT_GetWindow() = anEmptyWindow;
1239 ViewerTest::CurrentView (anEmptyView);
1240 ViewerTest::ResetEventManager();
1241 theDi << theArgVec[0] << ": all views are inactive\n";
1245 ViewerTest_Names aViewNames(aNameString);
1247 // Check if this view exists in the viewer with the driver
1248 if (!ViewerTest_myViews.IsBound1(aViewNames.GetViewName()))
1250 theDi << "Wrong view name\n";
1254 // Check if it is active already
1255 if (ViewerTest::CurrentView() == ViewerTest_myViews.Find1(aViewNames.GetViewName()))
1257 theDi << theArgVec[0] << ": the view is active already\n";
1261 ActivateView (aViewNames.GetViewName());
1265 //==============================================================================
1266 //function : VViewList
1267 //purpose : Print current list of views per viewer and graphic driver ID
1268 // shared between viewers
1269 //==============================================================================
1271 static int VViewList (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
1275 theDi << theArgVec[0] << ": Wrong number of command arguments\n"
1276 << "Usage: " << theArgVec[0] << " name";
1279 if (ViewerTest_myContexts.Size() < 1)
1282 Standard_Boolean isTreeView =
1283 (( theArgsNb==1 ) || ( strcasecmp( theArgVec[1], "long" ) != 0 ));
1286 theDi << theArgVec[0] <<":\n";
1288 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
1289 aDriverIter(ViewerTest_myDrivers); aDriverIter.More(); aDriverIter.Next())
1292 theDi << aDriverIter.Key1() << ":\n";
1294 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)>::Iterator
1295 aContextIter(ViewerTest_myContexts); aContextIter.More(); aContextIter.Next())
1297 if (aContextIter.Key1().Search(aDriverIter.Key1()) != -1)
1301 TCollection_AsciiString aContextName(aContextIter.Key1());
1302 theDi << " " << aContextName.Split(aDriverIter.Key1().Length() + 1) << ":" << "\n";
1305 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)>::Iterator
1306 aViewIter(ViewerTest_myViews); aViewIter.More(); aViewIter.Next())
1308 if (aViewIter.Key1().Search(aContextIter.Key1()) != -1)
1310 TCollection_AsciiString aViewName(aViewIter.Key1());
1313 if (aViewIter.Value() == ViewerTest::CurrentView())
1314 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "(*)" << "\n";
1316 theDi << " " << aViewName.Split(aContextIter.Key1().Length() + 1) << "\n";
1320 theDi << aViewName << " ";
1330 //==============================================================================
1331 //function : VT_ProcessKeyPress
1332 //purpose : Handle KeyPress event from a CString
1333 //==============================================================================
1334 void VT_ProcessKeyPress (const char* buf_ret)
1336 //cout << "KeyPress" << endl;
1337 const Handle(V3d_View) aView = ViewerTest::CurrentView();
1338 const Handle(NIS_View) aNisView = Handle(NIS_View)::DownCast (aView);
1339 // Letter in alphabetic order
1341 if (!strcasecmp (buf_ret, "A"))
1344 aView->SetProj(V3d_XposYnegZpos);
1346 else if (!strcasecmp (buf_ret, "D"))
1351 else if (!strcasecmp (buf_ret, "F"))
1354 if (aNisView.IsNull())
1357 aNisView->FitAll3d();
1359 else if (!strcasecmp (buf_ret, "H"))
1362 cout << "HLR" << endl;
1363 aView->SetComputedMode (!aView->ComputedMode());
1364 MyHLRIsOn = aView->ComputedMode();
1366 else if (!strcasecmp (buf_ret, "P"))
1369 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
1370 if (aContext->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo)
1371 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_PolyAlgo);
1373 aContext->DefaultDrawer()->SetTypeOfHLR(Prs3d_TOH_Algo);
1374 if (aContext->NbCurrents()==0 || aContext->NbSelected() == 0)
1376 AIS_ListOfInteractive aListOfShapes;
1377 aContext->DisplayedObjects(aListOfShapes);
1378 for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
1379 anIter.More(); anIter.Next())
1381 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
1382 if (aShape.IsNull())
1384 if (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1385 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1387 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1388 aShape->Redisplay();
1393 for (aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
1395 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aContext->Current());
1396 if (aShape.IsNull())
1398 if(aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo)
1399 aShape->SetTypeOfHLR (Prs3d_TOH_Algo);
1401 aShape->SetTypeOfHLR (Prs3d_TOH_PolyAlgo);
1402 aShape->Redisplay();
1406 aContext->UpdateCurrentViewer();
1409 else if (!strcasecmp (buf_ret, "S"))
1411 std::cout << "setup Shaded display mode" << std::endl;
1413 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1414 if(Ctx->NbCurrents()==0 ||
1415 Ctx->NbSelected()==0)
1416 Ctx->SetDisplayMode(AIS_Shaded);
1418 if(Ctx->HasOpenedContext()){
1419 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1420 Ctx->SetDisplayMode(Ctx->Interactive(),1,Standard_False);
1423 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1424 Ctx->SetDisplayMode(Ctx->Current(),1,Standard_False);
1426 Ctx->UpdateCurrentViewer();
1429 else if (!strcasecmp (buf_ret, "U"))
1431 // Unset display mode
1432 std::cout << "reset display mode to defaults" << std::endl;
1434 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1435 if(Ctx->NbCurrents()==0 ||
1436 Ctx->NbSelected()==0)
1437 Ctx->SetDisplayMode(AIS_WireFrame);
1439 if(Ctx->HasOpenedContext()){
1440 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1441 Ctx->UnsetDisplayMode(Ctx->Interactive(),Standard_False);
1444 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1445 Ctx->UnsetDisplayMode(Ctx->Current(),Standard_False);
1447 Ctx->UpdateCurrentViewer();
1451 else if (!strcasecmp (buf_ret, "T"))
1454 aView->SetProj(V3d_Zpos);
1456 else if (!strcasecmp (buf_ret, "B"))
1459 aView->SetProj(V3d_Zneg);
1461 else if (!strcasecmp (buf_ret, "L"))
1464 aView->SetProj(V3d_Xneg);
1466 else if (!strcasecmp (buf_ret, "R"))
1469 aView->SetProj(V3d_Xpos);
1471 else if (!strcasecmp (buf_ret, "W"))
1473 std::cout << "setup WireFrame display mode" << std::endl;
1474 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1475 if(Ctx->NbCurrents()==0 ||
1476 Ctx->NbSelected()==0)
1477 Ctx->SetDisplayMode(AIS_WireFrame);
1479 if(Ctx->HasOpenedContext()){
1480 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1481 Ctx->SetDisplayMode(Ctx->Interactive(),0,Standard_False);
1484 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
1485 Ctx->SetDisplayMode(Ctx->Current(),0,Standard_False);
1487 Ctx->UpdateCurrentViewer();
1490 else if (!strcasecmp (buf_ret, "Z"))
1494 cout << "ZClipping OFF" << endl;
1497 aView->SetZClippingType(V3d_OFF);
1501 cout << "ZClipping ON" << endl;
1504 aView->SetZClippingType(V3d_FRONT);
1508 else if (!strcasecmp (buf_ret, ","))
1510 ViewerTest::GetAISContext()->HilightNextDetected(ViewerTest::CurrentView());
1512 else if (!strcasecmp (buf_ret, "."))
1514 ViewerTest::GetAISContext()->HilightPreviousDetected(ViewerTest::CurrentView());
1516 else if (*buf_ret == THE_KEY_DELETE)
1518 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1520 && aCtx->NbCurrents() > 0
1521 && aCtx->NbSelected() > 0)
1523 Draw_Interprete ("verase");
1529 Standard_Integer Num = Draw::Atoi(buf_ret);
1530 if(Num>=0 && Num<=7)
1531 ViewerTest::StandardModeActivation(Num);
1535 //==============================================================================
1536 //function : VT_ProcessExpose
1537 //purpose : Redraw the View on an Expose Event
1538 //==============================================================================
1539 void VT_ProcessExpose()
1541 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1542 if (!aView3d.IsNull())
1548 //==============================================================================
1549 //function : VT_ProcessConfigure
1550 //purpose : Resize the View on an Configure Event
1551 //==============================================================================
1552 void VT_ProcessConfigure()
1554 Handle(V3d_View) aView3d = ViewerTest::CurrentView();
1555 if (aView3d.IsNull())
1560 aView3d->MustBeResized();
1565 //==============================================================================
1566 //function : VT_ProcessButton1Press
1568 //==============================================================================
1569 Standard_Boolean VT_ProcessButton1Press (Standard_Integer ,
1570 const char** theArgVec,
1571 Standard_Boolean theToPick,
1572 Standard_Boolean theIsShift)
1576 Standard_Real X, Y, Z;
1577 ViewerTest::CurrentView()->Convert (X_Motion, Y_Motion, X, Y, Z);
1579 Draw::Set (theArgVec[1], X);
1580 Draw::Set (theArgVec[2], Y);
1581 Draw::Set (theArgVec[3], Z);
1586 ViewerTest::CurrentEventManager()->ShiftSelect();
1590 ViewerTest::CurrentEventManager()->Select();
1593 return Standard_False;
1596 //==============================================================================
1597 //function : VT_ProcessButton1Release
1598 //purpose : End selecting
1599 //==============================================================================
1600 void VT_ProcessButton1Release (Standard_Boolean theIsShift)
1604 IsDragged = Standard_False;
1605 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1608 EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1609 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1613 EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
1614 Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
1619 //==============================================================================
1620 //function : VT_ProcessButton3Press
1621 //purpose : Start Rotation
1622 //==============================================================================
1623 void VT_ProcessButton3Press()
1628 ViewerTest::CurrentView()->SetComputedMode (Standard_False);
1630 ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
1633 //==============================================================================
1634 //function : VT_ProcessButton3Release
1635 //purpose : End rotation
1636 //==============================================================================
1637 void VT_ProcessButton3Release()
1644 ViewerTest::CurrentView()->SetComputedMode (Standard_True);
1649 //==============================================================================
1650 //function : ProcessZClipMotion
1652 //==============================================================================
1654 void ProcessZClipMotion()
1656 Handle(V3d_View) a3DView = ViewerTest::CurrentView();
1657 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
1658 static Standard_Real CurZPos = 0.;
1660 //Quantity_Length VDX, VDY;
1661 //a3DView->Size(VDX,VDY);
1662 //Standard_Real VDZ = a3DView->ZSize();
1663 //printf("View size (%lf,%lf,%lf)\n", VDX, VDY, VDZ);
1665 Quantity_Length dx = a3DView->Convert(X_Motion - X_ButtonPress);
1667 // Front = Depth + width/2.
1668 Standard_Real D = 0.5;
1669 Standard_Real W = 0.1;
1675 //printf("dx %lf Depth %lf Width %lf\n", dx, D, W);
1677 a3DView->SetZClippingType(V3d_OFF);
1678 a3DView->SetZClippingDepth(D);
1679 a3DView->SetZClippingWidth(W);
1680 a3DView->SetZClippingType(V3d_FRONT);
1684 X_ButtonPress = X_Motion;
1685 Y_ButtonPress = Y_Motion;
1689 //==============================================================================
1690 //function : ProcessControlButton1Motion
1692 //==============================================================================
1694 #if defined(_WIN32) || ! defined(__APPLE__) || defined(MACOSX_USE_GLX)
1695 static void ProcessControlButton1Motion()
1697 ViewerTest::CurrentView()->Zoom( X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion);
1699 X_ButtonPress = X_Motion;
1700 Y_ButtonPress = Y_Motion;
1704 //==============================================================================
1705 //function : VT_ProcessControlButton2Motion
1707 //==============================================================================
1708 void VT_ProcessControlButton2Motion()
1710 Standard_Integer aDx = X_Motion - X_ButtonPress;
1711 Standard_Integer aDy = Y_Motion - Y_ButtonPress;
1713 aDy = -aDy; // Xwindow Y axis is from top to Bottom
1715 ViewerTest::CurrentView()->Pan (aDx, aDy);
1717 X_ButtonPress = X_Motion;
1718 Y_ButtonPress = Y_Motion;
1721 //==============================================================================
1722 //function : VT_ProcessControlButton3Motion
1723 //purpose : Rotation
1724 //==============================================================================
1725 void VT_ProcessControlButton3Motion()
1729 ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
1733 //==============================================================================
1734 //function : VT_ProcessMotion
1736 //==============================================================================
1737 void VT_ProcessMotion()
1739 //pre-hilights detected objects at mouse position
1741 Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
1742 EM->MoveTo(X_Motion, Y_Motion);
1746 void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix)
1748 Xpix = X_Motion;Ypix=Y_Motion;
1751 //==============================================================================
1752 //function : ViewProject: implements VAxo, VTop, VLeft, ...
1753 //purpose : Switches to an axonometric, top, left and other views
1754 //==============================================================================
1756 static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
1758 if ( ViewerTest::CurrentView().IsNull() )
1760 di<<"Call vinit before this command, please"<<"\n";
1764 ViewerTest::CurrentView()->SetProj(ori);
1768 //==============================================================================
1770 //purpose : Switch to an Axonometric view
1771 //Draw arg : No args
1772 //==============================================================================
1774 static int VAxo(Draw_Interpretor& di, Standard_Integer , const char** )
1776 return ViewProject(di, V3d_XposYnegZpos);
1779 //==============================================================================
1781 //purpose : Switch to a Top View
1782 //Draw arg : No args
1783 //==============================================================================
1785 static int VTop(Draw_Interpretor& di, Standard_Integer , const char** )
1787 return ViewProject(di, V3d_Zpos);
1790 //==============================================================================
1791 //function : VBottom
1792 //purpose : Switch to a Bottom View
1793 //Draw arg : No args
1794 //==============================================================================
1796 static int VBottom(Draw_Interpretor& di, Standard_Integer , const char** )
1798 return ViewProject(di, V3d_Zneg);
1801 //==============================================================================
1803 //purpose : Switch to a Left View
1804 //Draw arg : No args
1805 //==============================================================================
1807 static int VLeft(Draw_Interpretor& di, Standard_Integer , const char** )
1809 return ViewProject(di, V3d_Ypos);
1812 //==============================================================================
1814 //purpose : Switch to a Right View
1815 //Draw arg : No args
1816 //==============================================================================
1818 static int VRight(Draw_Interpretor& di, Standard_Integer , const char** )
1820 return ViewProject(di, V3d_Yneg);
1823 //==============================================================================
1825 //purpose : Switch to a Front View
1826 //Draw arg : No args
1827 //==============================================================================
1829 static int VFront(Draw_Interpretor& di, Standard_Integer , const char** )
1831 return ViewProject(di, V3d_Xpos);
1834 //==============================================================================
1836 //purpose : Switch to a Back View
1837 //Draw arg : No args
1838 //==============================================================================
1840 static int VBack(Draw_Interpretor& di, Standard_Integer , const char** )
1842 return ViewProject(di, V3d_Xneg);
1845 //==============================================================================
1847 //purpose : Dsiplay help on viewer Keyboead and mouse commands
1848 //Draw arg : No args
1849 //==============================================================================
1851 static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
1854 di << "Q : Quit the application" << "\n";
1856 di << "========================="<<"\n";
1857 di << "F : FitAll" << "\n";
1858 di << "T : TopView" << "\n";
1859 di << "B : BottomView" << "\n";
1860 di << "R : RightView" << "\n";
1861 di << "L : LeftView" << "\n";
1862 di << "A : AxonometricView" << "\n";
1863 di << "D : ResetView" << "\n";
1865 di << "========================="<<"\n";
1866 di << "S : Shading" << "\n";
1867 di << "W : Wireframe" << "\n";
1868 di << "H : HidelLineRemoval" << "\n";
1869 di << "U : Unset display mode" << "\n";
1870 di << "Delete : Remove selection from viewer" << "\n";
1872 di << "========================="<<"\n";
1873 di << "Selection mode "<<"\n";
1874 di << "0 : Shape" <<"\n";
1875 di << "1 : Vertex" <<"\n";
1876 di << "2 : Edge" <<"\n";
1877 di << "3 : Wire" <<"\n";
1878 di << "4 : Face" <<"\n";
1879 di << "5 : Shell" <<"\n";
1880 di << "6 : Solid" <<"\n";
1881 di << "7 : Compound" <<"\n";
1883 di << "========================="<<"\n";
1884 di << "Z : Switch Z clipping On/Off" << "\n";
1885 di << ", : Hilight next detected" << "\n";
1886 di << ". : Hilight previous detected" << "\n";
1893 static Standard_Boolean Ppick = 0;
1894 static Standard_Integer Pargc = 0;
1895 static const char** Pargv = NULL;
1898 static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
1903 if (!ViewerTest_myViews.IsEmpty()) {
1905 WPARAM fwKeys = wParam;
1910 // Delete view from map of views
1911 ViewerTest::RemoveView(FindViewIdByWindowHandle(hwnd));
1916 if(LOWORD(wParam) == WA_CLICKACTIVE || LOWORD(wParam) == WA_ACTIVE
1917 || ViewerTest::CurrentView().IsNull())
1919 // Activate inactive window
1920 if(GetWindowHandle(VT_GetWindow()) != hwnd)
1922 ActivateView (FindViewIdByWindowHandle(hwnd));
1929 HDC hdc = GetDC( hwnd );
1930 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1931 SetROP2( hdc, R2_NOT );
1932 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1933 ReleaseDC( hwnd, hdc );
1934 VT_ProcessButton1Release (fwKeys & MK_SHIFT);
1936 IsDragged = Standard_False;
1937 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1939 case WM_LBUTTONDOWN:
1940 if( fwKeys == MK_LBUTTON || fwKeys == ( MK_LBUTTON | MK_SHIFT ) )
1942 IsDragged = Standard_True;
1943 DragFirst = Standard_True;
1944 X_ButtonPress = LOWORD(lParam);
1945 Y_ButtonPress = HIWORD(lParam);
1947 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1954 HDC hdc = GetDC( hwnd );
1956 HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
1957 SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
1958 SetROP2( hdc, R2_NOT );
1961 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1963 DragFirst = Standard_False;
1964 X_Motion = LOWORD(lParam);
1965 Y_Motion = HIWORD(lParam);
1967 Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
1969 SelectObject( hdc, anObj );
1971 ReleaseDC( hwnd, hdc );
1974 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1978 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1982 return ViewerWindowProc( hwnd, Msg, wParam, lParam );
1986 static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
1993 if ( !ViewerTest::CurrentView().IsNull() ) {
1998 BeginPaint(hwnd, &ps);
1999 EndPaint(hwnd, &ps);
2004 VT_ProcessConfigure();
2008 if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
2011 c[0] = (char) wParam;
2013 if (wParam == VK_DELETE)
2015 c[0] = THE_KEY_DELETE;
2018 else if (wParam == VK_OEM_COMMA)
2023 else if (wParam == VK_OEM_PERIOD)
2027 VT_ProcessKeyPress (c);
2035 VT_ProcessButton3Release();
2038 case WM_LBUTTONDOWN:
2039 case WM_MBUTTONDOWN:
2040 case WM_RBUTTONDOWN:
2042 WPARAM fwKeys = wParam;
2046 X_ButtonPress = LOWORD(lParam);
2047 Y_ButtonPress = HIWORD(lParam);
2049 if (Msg == WM_LBUTTONDOWN)
2051 if (fwKeys & MK_CONTROL)
2053 Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2057 VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
2060 else if (Msg == WM_RBUTTONDOWN)
2063 VT_ProcessButton3Press();
2070 //cout << "\t WM_MOUSEMOVE" << endl;
2071 WPARAM fwKeys = wParam;
2072 X_Motion = LOWORD(lParam);
2073 Y_Motion = HIWORD(lParam);
2076 fwKeys & ( MK_LBUTTON|MK_MBUTTON|MK_RBUTTON ) ) {
2078 X_ButtonPress = LOWORD(lParam);
2079 Y_ButtonPress = HIWORD(lParam);
2081 if ( fwKeys & MK_RBUTTON ) {
2083 VT_ProcessButton3Press();
2087 if ( fwKeys & MK_CONTROL ) {
2088 if ( fwKeys & MK_LBUTTON ) {
2089 ProcessControlButton1Motion();
2091 else if ( fwKeys & MK_MBUTTON ||
2092 ((fwKeys&MK_LBUTTON) &&
2093 (fwKeys&MK_RBUTTON) ) ){
2094 VT_ProcessControlButton2Motion();
2096 else if ( fwKeys & MK_RBUTTON ) {
2097 VT_ProcessControlButton3Motion();
2101 else if ( fwKeys & MK_SHIFT ) {
2102 if ( fwKeys & MK_MBUTTON ||
2103 ((fwKeys&MK_LBUTTON) &&
2104 (fwKeys&MK_RBUTTON) ) ) {
2105 cout << "ProcessZClipMotion()" << endl;
2106 ProcessZClipMotion();
2110 else if (GetWindowHandle (VT_GetWindow()) == hwnd)
2112 if ((fwKeys & MK_MBUTTON
2113 || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
2115 ProcessZClipMotion();
2126 return( DefWindowProc( hwnd, Msg, wParam, lParam ));
2131 return DefWindowProc( hwnd, Msg, wParam, lParam );
2137 //==============================================================================
2138 //function : ViewerMainLoop
2139 //purpose : Get a Event on the view and dispatch it
2140 //==============================================================================
2143 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2145 Ppick = (argc > 0)? 1 : 0;
2153 cout << "Start picking" << endl;
2155 while ( Ppick == 1 ) {
2156 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
2157 if (GetMessage(&msg, NULL, 0, 0) ) {
2158 TranslateMessage(&msg);
2159 DispatchMessage(&msg);
2163 cout << "Picking done" << endl;
2169 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
2171 int min( int a, int b )
2179 int max( int a, int b )
2187 int ViewerMainLoop(Standard_Integer argc, const char** argv)
2190 static XEvent aReport;
2191 Standard_Boolean pick = argc > 0;
2192 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2193 XNextEvent (aDisplay, &aReport);
2195 // Handle event for the chosen display connection
2196 switch (aReport.type) {
2199 if((Atom)aReport.xclient.data.l[0] == GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW))
2202 ViewerTest::RemoveView(FindViewIdByWindowHandle (aReport.xclient.window));
2208 // Activate inactive view
2209 Window aWindow = GetWindowHandle(VT_GetWindow());
2210 if(aWindow != aReport.xfocus.window)
2212 ActivateView (FindViewIdByWindowHandle (aReport.xfocus.window));
2221 case ConfigureNotify:
2223 VT_ProcessConfigure();
2232 XComposeStatus status_in_out;
2234 ret_len = XLookupString( ( XKeyEvent *)&aReport ,
2235 (char *) buf_ret , 10 ,
2236 &ks_ret , &status_in_out ) ;
2239 buf_ret[ret_len] = '\0' ;
2243 VT_ProcessKeyPress (buf_ret);
2249 X_ButtonPress = aReport.xbutton.x;
2250 Y_ButtonPress = aReport.xbutton.y;
2252 if (aReport.xbutton.button == Button1)
2254 if (aReport.xbutton.state & ControlMask)
2256 pick = VT_ProcessButton1Press (argc, argv, pick, (aReport.xbutton.state & ShiftMask));
2260 IsDragged = Standard_True;
2261 DragFirst = Standard_True;
2264 else if (aReport.xbutton.button == Button3)
2267 VT_ProcessButton3Press();
2277 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2278 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2279 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2282 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
2283 if( aContext.IsNull() )
2285 cout << "The context is null. Please use vinit before createmesh" << endl;
2289 Standard_Boolean ShiftPressed = ( aReport.xbutton.state & ShiftMask );
2290 if( aReport.xbutton.button==1 )
2294 aContext->ShiftSelect();
2303 aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2304 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2305 ViewerTest::CurrentView());
2309 aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
2310 max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
2311 ViewerTest::CurrentView() );
2314 VT_ProcessButton3Release();
2316 IsDragged = Standard_False;
2319 VT_ProcessButton3Release();
2324 if (GetWindowHandle (VT_GetWindow()) != aReport.xmotion.window)
2330 Aspect_Handle aWindow = VT_GetWindow()->XWindow();
2331 GC gc = XCreateGC( aDisplay, aWindow, 0, 0 );
2332 XSetFunction( aDisplay, gc, GXinvert );
2335 XDrawRectangle(aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2337 X_Motion = aReport.xmotion.x;
2338 Y_Motion = aReport.xmotion.y;
2339 DragFirst = Standard_False;
2341 XDrawRectangle( aDisplay, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
2345 X_Motion = aReport.xmotion.x;
2346 Y_Motion = aReport.xmotion.y;
2348 // remove all the ButtonMotionMaskr
2349 while( XCheckMaskEvent( aDisplay, ButtonMotionMask, &aReport) ) ;
2351 if ( ZClipIsOn && aReport.xmotion.state & ShiftMask ) {
2352 if ( Abs(X_Motion - X_ButtonPress) > 2 ) {
2354 Quantity_Length VDX, VDY;
2356 ViewerTest::CurrentView()->Size(VDX,VDY);
2357 Standard_Real VDZ =0 ;
2358 VDZ = ViewerTest::CurrentView()->ZSize();
2360 printf("%f,%f,%f\n", VDX, VDY, VDZ);
2362 Quantity_Length dx = 0 ;
2363 dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
2367 dx = dx / VDX * VDZ;
2371 ViewerTest::CurrentView()->Redraw();
2375 if ( aReport.xmotion.state & ControlMask ) {
2376 if ( aReport.xmotion.state & Button1Mask ) {
2377 ProcessControlButton1Motion();
2379 else if ( aReport.xmotion.state & Button2Mask ) {
2380 VT_ProcessControlButton2Motion();
2382 else if ( aReport.xmotion.state & Button3Mask ) {
2383 VT_ProcessControlButton3Motion();
2397 //==============================================================================
2398 //function : VProcessEvents
2399 //purpose : call by Tk_CreateFileHandler() to be able to manage the
2400 // event in the Viewer window
2401 //==============================================================================
2403 static void VProcessEvents(ClientData,int)
2405 NCollection_Vector<int> anEventNumbers;
2406 // Get number of messages from every display
2407 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2408 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next())
2410 anEventNumbers.Append(XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()));
2412 // Handle events for every display
2413 int anEventIter = 0;
2414 for (NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)>::Iterator
2415 anIter (ViewerTest_myDrivers); anIter.More(); anIter.Next(), anEventIter++)
2417 for (int i = 0; i < anEventNumbers.Value(anEventIter) &&
2418 XPending (anIter.Key2()->GetDisplayConnection()->GetDisplay()) > 0; ++i)
2420 SetDisplayConnection (anIter.Key2()->GetDisplayConnection());
2421 int anEventResult = ViewerMainLoop( 0, NULL);
2422 // If window is closed or context was not found finish current event processing loop
2428 SetDisplayConnection (ViewerTest::GetAISContext()->CurrentViewer()->Driver()->GetDisplayConnection());
2433 //==============================================================================
2434 //function : OSWindowSetup
2435 //purpose : Setup for the X11 window to be able to cath the event
2436 //==============================================================================
2439 static void OSWindowSetup()
2441 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
2444 Window window = VT_GetWindow()->XWindow();
2445 SetDisplayConnection (ViewerTest::CurrentView()->Viewer()->Driver()->GetDisplayConnection());
2446 Display *aDisplay = GetDisplayConnection()->GetDisplay();
2447 XSynchronize(aDisplay, 1);
2449 // X11 : For keyboard on SUN
2451 wmhints.flags = InputHint;
2454 XSetWMHints( aDisplay, window, &wmhints);
2456 XSelectInput( aDisplay, window, ExposureMask | KeyPressMask |
2457 ButtonPressMask | ButtonReleaseMask |
2458 StructureNotifyMask |
2460 Button1MotionMask | Button2MotionMask |
2461 Button3MotionMask | FocusChangeMask
2463 Atom aDeleteWindowAtom = GetDisplayConnection()->GetAtom(Aspect_XA_DELETE_WINDOW);
2464 XSetWMProtocols(aDisplay, window, &aDeleteWindowAtom, 1);
2466 XSynchronize(aDisplay, 0);
2475 //==============================================================================
2478 //purpose : Fitall, no DRAW arguments
2479 //Draw arg : No args
2480 //==============================================================================
2482 static int VFit(Draw_Interpretor& , Standard_Integer , const char** )
2484 const Handle(V3d_View) aView = ViewerTest::CurrentView();
2485 Handle(NIS_View) V = Handle(NIS_View)::DownCast(aView);
2486 if (V.IsNull() == Standard_False) {
2488 } else if (aView.IsNull() == Standard_False) {
2494 //=======================================================================
2495 //function : VFitArea
2496 //purpose : Fit view to show area located between two points
2497 // : given in world 2D or 3D coordinates.
2498 //=======================================================================
2499 static int VFitArea (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
2501 Handle(V3d_View) aView = ViewerTest::CurrentView();
2504 std::cerr << theArgVec[0] << "Error: No active view.\n";
2509 gp_Pnt aWorldPnt1 (0.0, 0.0, 0.0);
2510 gp_Pnt aWorldPnt2 (0.0, 0.0, 0.0);
2514 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2515 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2516 aWorldPnt2.SetX (Draw::Atof (theArgVec[3]));
2517 aWorldPnt2.SetY (Draw::Atof (theArgVec[4]));
2519 else if (theArgNb == 7)
2521 aWorldPnt1.SetX (Draw::Atof (theArgVec[1]));
2522 aWorldPnt1.SetY (Draw::Atof (theArgVec[2]));
2523 aWorldPnt1.SetZ (Draw::Atof (theArgVec[3]));
2524 aWorldPnt2.SetX (Draw::Atof (theArgVec[4]));
2525 aWorldPnt2.SetY (Draw::Atof (theArgVec[5]));
2526 aWorldPnt2.SetZ (Draw::Atof (theArgVec[6]));
2530 std::cerr << theArgVec[0] << "Error: Invalid number of arguments.\n";
2531 theDI.PrintHelp(theArgVec[0]);
2535 // Convert model coordinates to view space
2536 Handle(Graphic3d_Camera) aCamera = aView->Camera();
2537 gp_Pnt aViewPnt1 = aCamera->ConvertWorld2View (aWorldPnt1);
2538 gp_Pnt aViewPnt2 = aCamera->ConvertWorld2View (aWorldPnt2);
2540 // Determine fit area
2541 gp_Pnt2d aMinCorner (Min (aViewPnt1.X(), aViewPnt2.X()), Min (aViewPnt1.Y(), aViewPnt2.Y()));
2542 gp_Pnt2d aMaxCorner (Max (aViewPnt1.X(), aViewPnt2.X()), Max (aViewPnt1.Y(), aViewPnt2.Y()));
2544 Standard_Real aDiagonal = aMinCorner.Distance (aMaxCorner);
2546 if (aDiagonal < Precision::Confusion())
2548 std::cerr << theArgVec[0] << "Error: view area is too small.\n";
2552 aView->FitAll (aMinCorner.X(), aMinCorner.Y(), aMaxCorner.X(), aMaxCorner.Y());
2556 //==============================================================================
2558 //purpose : ZFitall, no DRAW arguments
2559 //Draw arg : No args
2560 //==============================================================================
2561 static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
2563 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
2565 if (aCurrentView.IsNull())
2567 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
2573 aCurrentView->View()->ZFitAll();
2574 aCurrentView->Redraw();
2578 Standard_Real aScale = 1.0;
2582 aScale = Draw::Atoi (theArgVec[1]);
2585 aCurrentView->View()->ZFitAll (aScale);
2586 aCurrentView->Redraw();
2591 //==============================================================================
2592 //function : VRepaint
2594 //==============================================================================
2595 static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
2597 Handle(V3d_View) V = ViewerTest::CurrentView();
2598 if ( !V.IsNull() ) V->Redraw(); return 0;
2601 //==============================================================================
2603 //purpose : Remove all the object from the viewer
2604 //Draw arg : No args
2605 //==============================================================================
2607 static int VClear(Draw_Interpretor& , Standard_Integer , const char** )
2609 Handle(V3d_View) V = ViewerTest::CurrentView();
2611 ViewerTest::Clear();
2615 //==============================================================================
2618 //==============================================================================
2620 static int VPick(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2621 { if (ViewerTest::CurrentView().IsNull() ) return 1;
2624 di << argv[0] << "Invalid number of arguments" << "\n";
2628 while (ViewerMainLoop( argc, argv)) {
2634 //==============================================================================
2636 //purpose : Load image as background
2637 //==============================================================================
2639 static int VSetBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2641 if (argc < 2 || argc > 3)
2643 di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
2644 di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2648 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2649 if(AISContext.IsNull())
2651 di << "use 'vinit' command before " << argv[0] << "\n";
2655 Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
2658 const char* szType = argv[2];
2659 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2660 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2661 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2662 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2665 di << "Wrong fill type : " << szType << "\n";
2666 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2671 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2672 V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
2677 //==============================================================================
2678 //function : VSetBgMode
2679 //purpose : Change background image fill type
2680 //==============================================================================
2682 static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2686 di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
2687 di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2691 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2692 if(AISContext.IsNull())
2694 di << "use 'vinit' command before " << argv[0] << "\n";
2697 Aspect_FillMethod aFillType = Aspect_FM_NONE;
2698 const char* szType = argv[1];
2699 if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
2700 else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
2701 else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
2702 else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
2705 di << "Wrong fill type : " << szType << "\n";
2706 di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
2709 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2710 V3dView->SetBgImageStyle(aFillType, Standard_True);
2714 //==============================================================================
2715 //function : VSetGradientBg
2716 //purpose : Mount gradient background
2717 //==============================================================================
2718 static int VSetGradientBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2722 di << "Usage : " << argv[0] << " R1 G1 B1 R2 G2 B2 Type : Mount gradient background" << "\n";
2723 di << "R1,G1,B1,R2,G2,B2 = [0..255]" << "\n";
2724 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2725 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2729 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2730 if(AISContext.IsNull())
2732 di << "use 'vinit' command before " << argv[0] << "\n";
2738 Standard_Real R1 = Draw::Atof(argv[1])/255.;
2739 Standard_Real G1 = Draw::Atof(argv[2])/255.;
2740 Standard_Real B1 = Draw::Atof(argv[3])/255.;
2741 Quantity_Color aColor1(R1,G1,B1,Quantity_TOC_RGB);
2743 Standard_Real R2 = Draw::Atof(argv[4])/255.;
2744 Standard_Real G2 = Draw::Atof(argv[5])/255.;
2745 Standard_Real B2 = Draw::Atof(argv[6])/255.;
2747 Quantity_Color aColor2(R2,G2,B2,Quantity_TOC_RGB);
2748 int aType = Draw::Atoi(argv[7]);
2749 if( aType < 0 || aType > 8 )
2751 di << "Wrong fill type " << "\n";
2752 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2753 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2757 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2759 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2760 V3dView->SetBgGradientColors( aColor1, aColor2, aMethod, 1);
2766 //==============================================================================
2767 //function : VSetGradientBgMode
2768 //purpose : Change gradient background fill style
2769 //==============================================================================
2770 static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2774 di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
2775 di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2776 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2780 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2781 if(AISContext.IsNull())
2783 di << "use 'vinit' command before " << argv[0] << "\n";
2788 int aType = Draw::Atoi(argv[1]);
2789 if( aType < 0 || aType > 8 )
2791 di << "Wrong fill type " << "\n";
2792 di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
2793 di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
2797 Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
2799 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2800 V3dView->SetBgGradientStyle( aMethod, 1 );
2806 //==============================================================================
2807 //function : VSetColorBg
2808 //purpose : Set color background
2809 //==============================================================================
2810 static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2814 di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
2815 di << "R,G,B = [0..255]" << "\n";
2819 Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
2820 if(AISContext.IsNull())
2822 di << "use 'vinit' command before " << argv[0] << "\n";
2828 Standard_Real R = Draw::Atof(argv[1])/255.;
2829 Standard_Real G = Draw::Atof(argv[2])/255.;
2830 Standard_Real B = Draw::Atof(argv[3])/255.;
2831 Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
2833 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2834 V3dView->SetBackgroundColor( aColor );
2841 //==============================================================================
2843 //purpose : View Scaling
2844 //==============================================================================
2846 static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2848 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2849 if ( V3dView.IsNull() ) return 1;
2852 di << argv[0] << "Invalid number of arguments" << "\n";
2855 V3dView->SetAxialScale( Draw::Atof(argv[1]), Draw::Atof(argv[2]), Draw::Atof(argv[3]) );
2858 //==============================================================================
2859 //function : VTestZBuffTrihedron
2860 //purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron
2861 //==============================================================================
2863 static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2865 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
2866 if ( V3dView.IsNull() ) return 1;
2868 V3dView->ZBufferTriedronSetup();
2871 // Set up default trihedron parameters
2872 V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER );
2876 Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER;
2877 const char* aPosType = argv[1];
2879 if ( strcmp(aPosType, "center") == 0 )
2881 aPosition = Aspect_TOTP_CENTER;
2883 if (strcmp(aPosType, "left_lower") == 0)
2885 aPosition = Aspect_TOTP_LEFT_LOWER;
2887 if (strcmp(aPosType, "left_upper") == 0)
2889 aPosition = Aspect_TOTP_LEFT_UPPER;
2891 if (strcmp(aPosType, "right_lower") == 0)
2893 aPosition = Aspect_TOTP_RIGHT_LOWER;
2895 if (strcmp(aPosType, "right_upper") == 0)
2897 aPosition = Aspect_TOTP_RIGHT_UPPER;
2900 di << argv[1] << " Invalid type of alignment" << "\n";
2901 di << "Must be one of [ center, left_lower," << "\n";
2902 di << "left_upper, right_lower, right_upper ]" << "\n";
2906 Standard_Real R = Draw::Atof(argv[2])/255.;
2907 Standard_Real G = Draw::Atof(argv[3])/255.;
2908 Standard_Real B = Draw::Atof(argv[4])/255.;
2909 Quantity_Color aColor(R, G, B, Quantity_TOC_RGB);
2911 Standard_Real aScale = Draw::Atof(argv[5]);
2915 di << argv[5] << " Invalid value. Must be > 0" << "\n";
2919 V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER;
2920 const char* aPresType = argv[6];
2922 if ( strcmp(aPresType, "wireframe") == 0 )
2924 aPresentation = V3d_WIREFRAME;
2926 if (strcmp(aPresType, "zbuffer") == 0)
2928 aPresentation = V3d_ZBUFFER;
2931 di << argv[6] << " Invalid type of visualization" << "\n";
2932 di << "Must be one of [ wireframe, zbuffer ]" << "\n";
2936 V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation );
2940 di << argv[0] << " Invalid number of arguments" << "\n";
2944 V3dView->View()->ZFitAll();
2949 //==============================================================================
2950 //function : VRotate
2951 //purpose : Camera Rotating
2952 //==============================================================================
2954 static int VRotate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
2956 Handle(V3d_View) aView = ViewerTest::CurrentView();
2959 std::cout << "No active view!\n";
2963 Standard_Boolean hasFlags = Standard_False;
2964 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
2966 Standard_CString anArg (theArgVec[anArgIter]);
2967 TCollection_AsciiString aFlag (anArg);
2969 if (aFlag == "-mousestart"
2970 || aFlag == "-mousefrom")
2972 hasFlags = Standard_True;
2973 if (anArgIter + 2 >= theArgNb)
2975 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
2979 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
2980 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
2981 aView->StartRotation (anX, anY);
2983 else if (aFlag == "-mousemove")
2985 hasFlags = Standard_True;
2986 if (anArgIter + 2 >= theArgNb)
2988 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
2992 Standard_Integer anX = Draw::Atoi (theArgVec[++anArgIter]);
2993 Standard_Integer anY = Draw::Atoi (theArgVec[++anArgIter]);
2994 aView->Rotation (anX, anY);
2996 else if (theArgNb != 4
2999 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
3008 else if (theArgNb == 4)
3010 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3011 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3012 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3013 aView->Rotate (anAX, anAY, anAZ);
3016 else if (theArgNb == 7)
3018 Standard_Real anAX = Draw::Atof (theArgVec[1]);
3019 Standard_Real anAY = Draw::Atof (theArgVec[2]);
3020 Standard_Real anAZ = Draw::Atof (theArgVec[3]);
3022 Standard_Real anX = Draw::Atof (theArgVec[4]);
3023 Standard_Real anY = Draw::Atof (theArgVec[5]);
3024 Standard_Real anZ = Draw::Atof (theArgVec[6]);
3026 aView->Rotate (anAX, anAY, anAZ, anX, anY, anZ);
3030 std::cout << "Error: Invalid number of arguments\n";
3034 //==============================================================================
3036 //purpose : View zoom in / out (relative to current zoom)
3037 //==============================================================================
3039 static int VZoom( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3040 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3041 if ( V3dView.IsNull() ) {
3046 Standard_Real coef = Draw::Atof(argv[1]);
3047 if ( coef <= 0.0 ) {
3048 di << argv[1] << "Invalid value" << "\n";
3051 V3dView->SetZoom( Draw::Atof(argv[1]) );
3054 di << argv[0] << " Invalid number of arguments" << "\n";
3059 //==============================================================================
3061 //purpose : View panning (in pixels)
3062 //==============================================================================
3064 static int VPan( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) {
3065 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3066 if ( V3dView.IsNull() ) return 1;
3069 V3dView->Pan( Draw::Atoi(argv[1]), Draw::Atoi(argv[2]) );
3072 di << argv[0] << " Invalid number of arguments" << "\n";
3077 //==============================================================================
3079 //purpose : Place the point (in pixels) at the center of the window
3080 //==============================================================================
3081 static int VPlace (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgs)
3083 Handle(V3d_View) aView = ViewerTest::CurrentView();
3086 std::cerr << theArgs[0] << "Error: no active view." << std::endl;
3092 std::cerr << theArgs[0] << "Error: invalid number of arguments." << std::endl;
3096 aView->Place (Draw::Atoi (theArgs[1]), Draw::Atoi (theArgs[2]), aView->Scale());
3101 //==============================================================================
3102 //function : VExport
3103 //purpose : Export the view to a vector graphic format (PS, EMF, PDF)
3104 //==============================================================================
3106 static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3108 Handle(V3d_View) V3dView = ViewerTest::CurrentView();
3109 if (V3dView.IsNull())
3114 std::cout << "Usage: " << argv[0] << " Filename [Format]\n";
3118 Graphic3d_ExportFormat anExpFormat = Graphic3d_EF_PDF;
3119 TCollection_AsciiString aFormatStr;
3121 TCollection_AsciiString aFileName (argv[1]);
3122 Standard_Integer aLen = aFileName.Length();
3126 aFormatStr = TCollection_AsciiString (argv[2]);
3130 if (aFileName.Value (aLen - 2) == '.')
3132 aFormatStr = aFileName.SubString (aLen - 1, aLen);
3134 else if (aFileName.Value (aLen - 3) == '.')
3136 aFormatStr = aFileName.SubString (aLen - 2, aLen);
3140 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3146 std::cout << "Export format couln't be detected from filename '" << argv[1] << "'\n";
3150 aFormatStr.UpperCase();
3151 if (aFormatStr == "PS")
3152 anExpFormat = Graphic3d_EF_PostScript;
3153 else if (aFormatStr == "EPS")
3154 anExpFormat = Graphic3d_EF_EnhPostScript;
3155 else if (aFormatStr == "TEX")
3156 anExpFormat = Graphic3d_EF_TEX;
3157 else if (aFormatStr == "PDF")
3158 anExpFormat = Graphic3d_EF_PDF;
3159 else if (aFormatStr == "SVG")
3160 anExpFormat = Graphic3d_EF_SVG;
3161 else if (aFormatStr == "PGF")
3162 anExpFormat = Graphic3d_EF_PGF;
3163 else if (aFormatStr == "EMF")
3164 anExpFormat = Graphic3d_EF_EMF;
3167 std::cout << "Invalid export format '" << aFormatStr << "'\n";
3172 if (!V3dView->View()->Export (argv[1], anExpFormat))
3174 di << "Error: export of image to " << aFormatStr << " failed!\n";
3177 catch (Standard_Failure)
3179 di << "Error: export of image to " << aFormatStr << " failed";
3180 di << " (exception: " << Standard_Failure::Caught()->GetMessageString() << ")";
3185 //==============================================================================
3186 //function : VColorScale
3187 //purpose : representation color scale
3188 //==============================================================================
3190 static Standard_Boolean checkColor (const TCollection_AsciiString& theRed,
3191 const TCollection_AsciiString& theGreen,
3192 const TCollection_AsciiString& theBlue,
3193 Standard_Real& theRedValue,
3194 Standard_Real& theGreenValue,
3195 Standard_Real& theBlueValue)
3197 if (!theRed.IsRealValue()
3198 || !theGreen.IsRealValue()
3199 || !theBlue.IsRealValue())
3201 std::cout << "Error: RGB color values should be real!\n";
3202 return Standard_True;
3204 theRedValue = theRed .RealValue();
3205 theGreenValue = theGreen.RealValue();
3206 theBlueValue = theBlue .RealValue();
3207 if (theRedValue < 0.0 || theRedValue > 1.0
3208 || theGreenValue < 0.0 || theGreenValue > 1.0
3209 || theBlueValue < 0.0 || theBlueValue > 1.0)
3211 std::cout << "Error: RGB color values should be within range 0..1!\n";
3212 return Standard_True;
3214 return Standard_False;
3217 static int VColorScale (Draw_Interpretor& theDI,
3218 Standard_Integer theArgNb,
3219 const char** theArgVec)
3221 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
3222 Handle(V3d_View) aView = ViewerTest::CurrentView();
3223 if (aContext.IsNull())
3225 std::cout << "Error: no active view!\n";
3229 Handle(V3d_ColorScale) aCS = Handle(V3d_ColorScale)::DownCast (aView->ColorScale());
3232 std::cout << "Error: color scale is undefined!\n";
3236 Standard_Real aMinRange = aCS->GetMin();
3237 Standard_Real aMaxRange = aCS->GetMax();
3238 Standard_Integer aNbIntervals = aCS->GetNumberOfIntervals();
3239 Standard_Integer aTextHeight = aCS->GetTextHeight();
3240 Aspect_TypeOfColorScalePosition aLabPosition = aCS->GetLabelPosition();
3241 gp_XY aPos (aCS->GetXPosition(), aCS->GetYPosition());
3243 ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
3247 theDI << "Current color scale parameters:\n"
3248 << "Min range: " << aMinRange << "\n"
3249 << "Max range: " << aMaxRange << "\n"
3250 << "Number of intervals: " << aNbIntervals << "\n"
3251 << "Text height: " << aTextHeight << "\n"
3252 << "Color scale position: " << aPos.X() <<" "<< aPos.Y()<< "\n"
3253 << "Color scale title: " << aCS->GetTitle() << "\n"
3254 << "Label position: ";
3255 switch (aLabPosition)
3257 case Aspect_TOCSP_NONE:
3260 case Aspect_TOCSP_LEFT:
3263 case Aspect_TOCSP_RIGHT:
3266 case Aspect_TOCSP_CENTER:
3267 theDI << "Center\n";
3272 Standard_CString aFirstArg = theArgVec[1];
3273 TCollection_AsciiString aFlag (aFirstArg);
3275 if (aFlag == "-hide" ||
3280 std::cout << "Error: wrong syntax at argument '" << theArgVec[1] << "'!\n";
3283 if (!aView->ColorScaleIsDisplayed())
3285 std::cout << "Error: color scale is not displayed!\n";
3290 aView->ColorScaleErase();
3294 else if (aFlag == "-show" ||
3295 aFlag == "-display")
3299 std::cout << "Error: wrong syntax at argument '" << theArgVec[1] << "'!\n";
3302 aView->ColorScaleDisplay();
3306 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3308 Standard_CString anArg = theArgVec[anArgIter];
3309 TCollection_AsciiString aFlag (anArg);
3311 if (anUpdateTool.parseRedrawMode (aFlag))
3315 else if (aFlag == "-range")
3317 if (anArgIter + 3 >= theArgNb)
3319 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3323 TCollection_AsciiString anArg1 (theArgVec[++anArgIter]);
3324 TCollection_AsciiString anArg2 (theArgVec[++anArgIter]);
3325 TCollection_AsciiString anArg3 (theArgVec[++anArgIter]);
3326 if (!anArg1.IsRealValue())
3328 std::cout << "Error: the minRange value should be real!\n";
3331 else if (!anArg2.IsRealValue())
3333 std::cout << "Error: the maxRange value should be real!\n";
3336 else if (!anArg3.IsIntegerValue())
3338 std::cout << "Error: the number of intervals should be integer!\n";
3342 aMinRange = anArg1.RealValue();
3343 aMaxRange = anArg2.RealValue();
3344 aNbIntervals = anArg3.IntegerValue();
3346 else if (aFlag == "-font")
3348 if (anArgIter + 1 >= theArgNb)
3350 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3353 TCollection_AsciiString anArg (theArgVec[anArgIter + 1]);
3354 if (!anArg.IsIntegerValue())
3356 std::cout << "Error: HeightFont value should be integer!\n";
3360 aTextHeight = anArg.IntegerValue();
3363 else if (aFlag == "-textpos")
3365 if (anArgIter + 1 >= theArgNb)
3367 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3370 TCollection_AsciiString anArg (theArgVec[++anArgIter]);
3372 if (anArg == "none")
3374 aLabPosition = Aspect_TOCSP_NONE;
3376 else if (anArg == "left")
3378 aLabPosition = Aspect_TOCSP_LEFT;
3380 else if (anArg == "right")
3382 aLabPosition = Aspect_TOCSP_RIGHT;
3384 else if (anArg == "center")
3386 aLabPosition = Aspect_TOCSP_CENTER;
3390 std::cout << "Error: unknown position '" << anArg << "'!\n";
3394 else if (aFlag == "-xy")
3396 if (anArgIter + 2 >= theArgNb)
3398 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3402 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3403 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3404 if (!aX.IsRealValue()
3405 || !aY.IsRealValue())
3407 std::cout << "Error: coordinates should be real values!\n";
3411 aPos.SetCoord (aX.RealValue(), aY.RealValue());
3413 else if (aFlag == "-color")
3415 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3417 std::cout << "Error: wrong color type! Call -colors before to set user-specified colors!\n";
3421 Quantity_NameOfColor aColorName;
3422 if (anArgIter + 4 >= theArgNb)
3424 if (anArgIter + 2 >= theArgNb)
3426 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3429 else if (!Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3431 std::cout << "Error: wrong color name: '" << theArgVec[anArgIter + 2] << "' !\n";
3436 TCollection_AsciiString anInd (theArgVec[anArgIter + 1]);
3437 if (!anInd.IsIntegerValue())
3439 std::cout << "Error: Index value should be integer!\n";
3443 Standard_Integer anIndex = anInd.IntegerValue();
3445 || anIndex > aNbIntervals - 1)
3447 std::cout << "Error: Index value should be within range 0..." << (aNbIntervals - 1) <<"!\n";
3451 if (Quantity_Color::ColorFromName (theArgVec[anArgIter + 2], aColorName))
3453 aCS->SetColor (Quantity_Color (aColorName), anIndex);
3454 aCS->SetColorType(Aspect_TOCSD_USER);
3459 TCollection_AsciiString aRed (theArgVec[anArgIter + 2]);
3460 TCollection_AsciiString aGreen (theArgVec[anArgIter + 3]);
3461 TCollection_AsciiString aBlue (theArgVec[anArgIter + 4]);
3462 Standard_Real aRedValue,aGreenValue, aBlueValue;
3463 if(checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3467 aCS->SetColor (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB), anIndex);
3468 aCS->SetColorType (Aspect_TOCSD_USER);
3471 else if (aFlag == "-label")
3473 if (aCS->GetColorType() != Aspect_TOCSD_USER)
3475 std::cout << "Error: wrong label type! Call -labels before to set user-specified labels!\n";
3478 else if (anArgIter + 2 >= theArgNb)
3480 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3484 Standard_Integer anIndex = Draw::Atoi (theArgVec[anArgIter + 1]);
3486 || anIndex > aNbIntervals)
3488 std::cout << "Error: Index value should be within range 0..." << aNbIntervals <<"!\n";
3492 TCollection_ExtendedString aText (theArgVec[anArgIter + 2]);
3493 aCS->SetLabel (aText, anIndex);
3494 aCS->SetLabelType (Aspect_TOCSD_USER);
3497 else if (aFlag == "-colors")
3499 Aspect_SequenceOfColor aSeq;
3500 if (anArgIter + aNbIntervals + 1 > theArgNb)
3502 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3503 << aNbIntervals << " intervals\n";
3507 Standard_Integer aColorIter = anArgIter + 1;
3508 while (aColorIter < theArgNb)
3510 if (theArgVec[aColorIter][0] == '-')
3515 else if (theArgVec[aColorIter][0] >= 97
3516 && theArgVec[aColorIter][0] <= 122)
3518 Quantity_NameOfColor aColorName;
3519 if (!Quantity_Color::ColorFromName (theArgVec[aColorIter], aColorName))
3521 std::cout << "Error: wrong color name: " << theArgVec[aColorIter] << " !\n";
3524 aSeq.Append (Quantity_Color (aColorName));
3530 TCollection_AsciiString aRed (theArgVec[aColorIter]);
3531 TCollection_AsciiString aGreen (theArgVec[aColorIter + 1]);
3532 TCollection_AsciiString aBlue (theArgVec[aColorIter + 2]);
3533 Standard_Real aRedValue,aGreenValue, aBlueValue;
3534 if (checkColor (aRed, aGreen, aBlue, aRedValue, aGreenValue, aBlueValue))
3538 aSeq.Append (Quantity_Color (aRedValue, aGreenValue, aBlueValue, Quantity_TOC_RGB));
3543 if (aSeq.Length() < aNbIntervals)
3545 std::cout << "Error: not enough arguments! You should provide color names or RGB color values for every interval of the "
3546 << aNbIntervals << " intervals\n";
3550 aCS->SetColors (aSeq);
3551 aCS->SetColorType (Aspect_TOCSD_USER);
3553 else if (aFlag == "-labels")
3555 if (anArgIter + aNbIntervals + 1 >= theArgNb)
3557 std::cout << "Error: not enough arguments! You should provide " << (aNbIntervals + 1)
3558 << " text labels for " << aNbIntervals << " intervals.\n";
3562 TColStd_SequenceOfExtendedString aSeq;
3563 for (int aLabelIter = anArgIter + 1; aLabelIter <= anArgIter + aNbIntervals + 1; aLabelIter += 1)
3565 aSeq.Append (TCollection_ExtendedString (theArgVec[aLabelIter]));
3567 aCS->SetLabels (aSeq);
3568 aCS->SetLabelType (Aspect_TOCSD_USER);
3569 anArgIter += aSeq.Length();
3571 else if (aFlag == "-title")
3573 if (anArgIter + 1 >= theArgNb)
3575 std::cout << "Error: wrong syntax at argument '" << anArg << "'!\n";
3579 Standard_Boolean isTwoArgs = Standard_False;
3580 if (anArgIter + 2 < theArgNb)
3582 TCollection_AsciiString aSecondArg (theArgVec[anArgIter + 2]);
3583 aSecondArg.LowerCase();
3584 if (aSecondArg == "none")
3586 aCS->SetTitlePosition (Aspect_TOCSP_NONE);
3587 isTwoArgs = Standard_True;
3589 else if (aSecondArg == "left")
3591 aCS->SetTitlePosition (Aspect_TOCSP_LEFT);
3592 isTwoArgs = Standard_True;
3594 else if (aSecondArg == "right")
3596 aCS->SetTitlePosition (Aspect_TOCSP_RIGHT);
3597 isTwoArgs = Standard_True;
3599 else if (aSecondArg == "center")
3601 aCS->SetTitlePosition (Aspect_TOCSP_CENTER);
3602 isTwoArgs = Standard_True;
3606 aCS->SetTitle (theArgVec[anArgIter + 1]);
3613 else if (aFlag == "-demoversion"
3614 || aFlag == "-demo")
3616 aPos.SetCoord (0.0, 0.0);
3621 aLabPosition = Aspect_TOCSP_RIGHT;
3622 aCS->SetColorType(Aspect_TOCSD_AUTO);
3623 aCS->SetLabelType(Aspect_TOCSD_AUTO);
3627 std::cout << "Error: wrong syntax at " << anArg << " - unknown argument!\n";
3632 aCS->SetPosition (aPos.X(), aPos.Y());
3633 aCS->SetHeight (0.95);
3634 aCS->SetTextHeight (aTextHeight);
3635 aCS->SetRange (aMinRange, aMaxRange);
3636 aCS->SetNumberOfIntervals (aNbIntervals);
3637 aCS->SetLabelPosition (aLabPosition);
3639 if (!aView->ColorScaleIsDisplayed())
3641 aView->ColorScaleDisplay();
3647 //==============================================================================
3648 //function : VGraduatedTrihedron
3649 //purpose : Displays a graduated trihedron
3650 //==============================================================================
3652 static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg)
3654 const char *str = arg;
3657 unsigned short c1 = *str++;
3658 unsigned short c2 = *str++;
3659 if (!c1 || !c2) break;
3660 name += (Standard_ExtCharacter)((c1 << 8) | c2);
3664 static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3667 if (argc != 2 && argc < 5)
3669 di<<"Error: "<<argv[0]<<" - invalid number of arguments\n";
3670 di<<"Usage: type help "<<argv[0]<<"\n";
3671 return 1; //TCL_ERROR
3674 Handle(V3d_View) aV3dView = ViewerTest::CurrentView();
3676 // Create 3D view if it doesn't exist
3677 if ( aV3dView.IsNull() )
3679 ViewerTest::ViewerInit();
3680 aV3dView = ViewerTest::CurrentView();
3681 if( aV3dView.IsNull() )
3683 di << "Error: Cannot create a 3D view\n";
3684 return 1; //TCL_ERROR
3688 // Erase (==0) or display (!=0)
3689 const int display = Draw::Atoi(argv[1]);
3694 TCollection_AsciiString font;
3696 font.AssignCat("Courier");
3698 font.AssignCat(argv[5]);
3700 // Text is multibyte
3701 const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0);
3704 TCollection_ExtendedString xname, yname, zname;
3709 AddMultibyteString(xname, argv[2]);
3710 AddMultibyteString(yname, argv[3]);
3711 AddMultibyteString(zname, argv[4]);
3727 aV3dView->GraduatedTrihedronDisplay(xname, yname, zname,
3728 Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/,
3729 Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/,
3730 Standard_True/*drawgrid*/,
3731 Standard_True/*drawaxes*/,
3732 5/*nbx*/, 5/*nby*/, 5/*nbz*/,
3733 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/,
3734 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/,
3735 Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/,
3736 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/,
3737 Quantity_NOC_WHITE/*gridcolor*/,
3738 Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/,
3739 Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font);
3742 aV3dView->GraduatedTrihedronErase();
3744 ViewerTest::GetAISContext()->UpdateCurrentViewer();
3750 //==============================================================================
3751 //function : VPrintView
3752 //purpose : Test printing algorithm, print the view to image file with given
3753 // width and height. Printing implemented only for WNT.
3754 //==============================================================================
3755 static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
3759 di << "Printing implemented only for wnt!\n";
3763 Handle(AIS_InteractiveContext) aContextAIS = NULL;
3764 Handle(V3d_View) aView = NULL;
3765 aContextAIS = ViewerTest::GetAISContext();
3766 if (!aContextAIS.IsNull())
3768 const Handle(V3d_Viewer)& Vwr = aContextAIS->CurrentViewer();
3769 Vwr->InitActiveViews();
3770 if(Vwr->MoreActiveViews())
3771 aView = Vwr->ActiveView();
3777 di << "Call vinit before!\n";
3782 di << "Use: " << argv[0];
3783 di << " width height filename [print algo=0] [tile_width tile_height]\n";
3784 di << "width, height of the intermediate buffer for operation\n";
3785 di << "algo : {0|1}\n";
3786 di << " 0 - stretch algorithm\n";
3787 di << " 1 - tile algorithm\n";
3788 di << "test printing algorithms into an intermediate buffer\n";
3789 di << "using specific tile size if provided\n";
3790 di << "with saving output to an image file\n";
3794 // get the input params
3795 Standard_Integer aWidth = Draw::Atoi (argv[1]);
3796 Standard_Integer aHeight = Draw::Atoi (argv[2]);
3797 Standard_Integer aMode = 0;
3798 TCollection_AsciiString aFileName = TCollection_AsciiString (argv[3]);
3800 aMode = Draw::Atoi (argv[4]);
3802 Standard_Integer aTileWidth = 0;
3803 Standard_Integer aTileHeight = 0;
3804 Standard_Boolean isTileSizeProvided = Standard_False;
3807 isTileSizeProvided = Standard_True;
3808 aTileWidth = Draw::Atoi (argv[5]);
3809 aTileHeight = Draw::Atoi (argv[6]);
3812 // check the input parameters
3813 if (aWidth <= 0 || aHeight <= 0)
3815 di << "Width and height must be positive values!\n";
3818 if (aMode != 0 && aMode != 1)
3821 // define compatible bitmap
3822 HDC anDC = CreateCompatibleDC(0);
3823 BITMAPINFO aBitmapData;
3824 memset (&aBitmapData, 0, sizeof (BITMAPINFOHEADER));
3825 aBitmapData.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
3826 aBitmapData.bmiHeader.biWidth = aWidth ;
3827 aBitmapData.bmiHeader.biHeight = aHeight;
3828 aBitmapData.bmiHeader.biPlanes = 1;
3829 aBitmapData.bmiHeader.biBitCount = 24;
3830 aBitmapData.bmiHeader.biXPelsPerMeter = 0;
3831 aBitmapData.bmiHeader.biYPelsPerMeter = 0;
3832 aBitmapData.bmiHeader.biClrUsed = 0;
3833 aBitmapData.bmiHeader.biClrImportant = 0;
3834 aBitmapData.bmiHeader.biCompression = BI_RGB;
3835 aBitmapData.bmiHeader.biSizeImage = 0;
3837 // Create Device Independent Bitmap
3838 void* aBitsOut = NULL;
3839 HBITMAP aMemoryBitmap = CreateDIBSection (anDC, &aBitmapData, DIB_RGB_COLORS,
3840 &aBitsOut, NULL, 0);
3841 HGDIOBJ anOldBitmap = SelectObject(anDC, aMemoryBitmap);
3843 Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
3844 if (aBitsOut != NULL)
3847 isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
3850 if (isTileSizeProvided)
3852 Graphic3d_CView* aCView = static_cast<Graphic3d_CView*> (ViewerTest::CurrentView()->View()->CView());
3853 Graphic3d_PtrFrameBuffer anOldBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO);
3854 aCView->ptrFBO = aView->View()->FBOCreate (aTileWidth, aTileHeight);
3856 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
3858 Graphic3d_PtrFrameBuffer aNewBuffer = static_cast<Graphic3d_PtrFrameBuffer> (aCView->ptrFBO);
3859 aView->View()->FBORelease (aNewBuffer);
3860 aCView->ptrFBO = anOldBuffer;
3864 isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE);
3868 // succesfully printed into an intermediate buffer
3871 Image_PixMap aWrapper;
3872 aWrapper.InitWrapper (Image_PixMap::ImgBGR, (Standard_Byte* )aBitsOut, aWidth, aHeight, aWidth * 3 + aWidth % 4);
3873 aWrapper.SetTopDown (false);
3875 Image_AlienPixMap anImageBitmap;
3876 anImageBitmap.InitCopy (aWrapper);
3877 isSaved = anImageBitmap.Save (aFileName);
3881 di << "Print operation failed due to printing errors or\n";
3882 di << "insufficient memory available\n";
3883 di << "Please, try to use smaller dimensions for this test\n";
3884 di << "command, as it allocates intermediate buffer for storing\n";
3885 di << "the result\n";
3890 di << "Can't allocate memory for intermediate buffer\n";
3891 di << "Please use smaller dimensions\n";
3896 SelectObject (anDC, anOldBitmap);
3897 DeleteObject (aMemoryBitmap);
3903 di << "Save to file operation failed. This operation may fail\n";
3904 di << "if you don't have enough available memory, then you can\n";
3905 di << "use smaller dimensions for the output file\n";
3914 //==============================================================================
3915 //function : VZLayer
3916 //purpose : Test z layer operations for v3d viewer
3917 //==============================================================================
3918 static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
3920 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext ();
3921 if (aContextAIS.IsNull())
3923 di << "Call vinit before!\n";
3928 di << "Use: vzlayer ";
3929 di << " add/del/get/settings/enable/disable [id]\n";
3930 di << " add - add new z layer to viewer and print its id\n";
3931 di << " del - del z layer by its id\n";
3932 di << " get - print sequence of z layers in increasing order of their overlay level\n";
3933 di << " settings - print status of z layer settings\n";
3934 di << " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n";
3935 di << " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n";
3936 di << " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n";
3937 di << "\nWhere id is the layer identificator\n";
3938 di << "\nExamples:\n";
3939 di << " vzlayer add\n";
3940 di << " vzlayer enable poffset 1\n";
3941 di << " vzlayer disable depthtest 1\n";
3942 di << " vzlayer del 1\n";
3946 const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer();
3947 if (aViewer.IsNull())
3949 di << "No active viewer!\n";
3953 // perform operation
3954 TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]);
3957 Standard_Integer aNewId;
3958 if (!aViewer->AddZLayer (aNewId))
3960 di << "Impossible to add new z layer!\n";
3964 di << "New z layer added with index: " << aNewId << "\n";
3966 else if (anOp == "del")
3970 di << "Please also provide as argument id of z layer to remove\n";
3974 Standard_Integer aDelId = Draw::Atoi (argv[2]);
3975 if (!aViewer->RemoveZLayer (aDelId))
3977 di << "Impossible to remove the z layer or invalid id!\n";
3981 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
3982 anObjIter.More(); anObjIter.Next())
3984 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anObjIter.Key1());
3986 || aPrs->ZLayer() != aDelId)
3990 aPrs->SetZLayer (Graphic3d_ZLayerId_Default);
3993 di << "Z layer " << aDelId << " has been removed\n";
3995 else if (anOp == "get")
3997 TColStd_SequenceOfInteger anIds;
3998 aViewer->GetAllZLayers (anIds);
3999 for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++)
4001 di << anIds.Value (aSeqIdx) << " ";
4006 else if (anOp == "settings")
4010 di << "Please also provide an id\n";
4014 Standard_Integer anId = Draw::Atoi (argv[2]);
4015 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4017 di << "Depth test - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthTest) ? "enabled" : "disabled") << "\n";
4018 di << "Depth write - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthWrite) ? "enabled" : "disabled") << "\n";
4019 di << "Depth buffer clearing - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthClear) ? "enabled" : "disabled") << "\n";
4020 di << "Depth offset - " << (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthOffset) ? "enabled" : "disabled") << "\n";
4023 else if (anOp == "enable")
4027 di << "Please also provide an option to enable\n";
4033 di << "Please also provide a layer id\n";
4037 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
4038 Standard_Integer anId = Draw::Atoi (argv[3]);
4039 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4041 if (aSubOp == "depthtest" || aSubOp == "test")
4043 aSettings.EnableSetting (Graphic3d_ZLayerDepthTest);
4045 else if (aSubOp == "depthwrite" || aSubOp == "write")
4047 aSettings.EnableSetting (Graphic3d_ZLayerDepthWrite);
4049 else if (aSubOp == "depthclear" || aSubOp == "clear")
4051 aSettings.EnableSetting (Graphic3d_ZLayerDepthClear);
4053 else if (aSubOp == "depthoffset" || aSubOp == "offset")
4057 di << "Please also provide a factor and units values for depth offset\n";
4058 di << "Format is: vzlayer enable offset [factor] [units] [layerId]\n";
4062 Standard_ShortReal aFactor = static_cast<Standard_ShortReal> (Draw::Atof (argv[3]));
4063 Standard_ShortReal aUnits = static_cast<Standard_ShortReal> (Draw::Atof (argv[4]));
4064 anId = Draw::Atoi (argv[5]);
4065 aSettings = aViewer->ZLayerSettings (anId);
4067 aSettings.DepthOffsetFactor = aFactor;
4068 aSettings.DepthOffsetUnits = aUnits;
4070 aSettings.EnableSetting (Graphic3d_ZLayerDepthOffset);
4072 else if (aSubOp == "positiveoffset" || aSubOp == "poffset")
4074 aSettings.SetDepthOffsetPositive();
4076 else if (aSubOp == "negativeoffset" || aSubOp == "noffset")
4078 aSettings.SetDepthOffsetNegative();
4081 aViewer->SetZLayerSettings (anId, aSettings);
4083 else if (anOp == "disable")
4087 di << "Please also provide an option to disable\n";
4093 di << "Please also provide a layer id\n";
4097 TCollection_AsciiString aSubOp = TCollection_AsciiString (argv[2]);
4098 Standard_Integer anId = Draw::Atoi (argv[3]);
4099 Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (anId);
4101 if (aSubOp == "depthtest" || aSubOp == "test")
4103 aSettings.DisableSetting (Graphic3d_ZLayerDepthTest);
4105 else if (aSubOp == "depthwrite" || aSubOp == "write")
4107 aSettings.DisableSetting (Graphic3d_ZLayerDepthWrite);
4109 else if (aSubOp == "depthclear" || aSubOp == "clear")
4111 aSettings.DisableSetting (Graphic3d_ZLayerDepthClear);
4113 else if (aSubOp == "depthoffset" || aSubOp == "offset")
4115 aSettings.DisableSetting (Graphic3d_ZLayerDepthOffset);
4118 aViewer->SetZLayerSettings (anId, aSettings);
4122 di << "Invalid operation, please use { add / del / get / settings / enable / disable}\n";
4129 DEFINE_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
4131 // this class provides a presentation of text item in v3d view under-/overlayer
4132 class V3d_TextItem : public Visual3d_LayerItem
4137 DEFINE_STANDARD_RTTI(V3d_TextItem)
4140 Standard_EXPORT V3d_TextItem(const TCollection_AsciiString& theText,
4141 const Standard_Real theX1,
4142 const Standard_Real theY1,
4143 const Standard_Real theHeight,
4144 const TCollection_AsciiString& theFontName,
4145 const Quantity_Color& theColor,
4146 const Quantity_Color& theSubtitleColor,
4147 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
4148 const Handle(Visual3d_Layer)& theLayer);
4151 Standard_EXPORT void RedrawLayerPrs();
4157 TCollection_AsciiString myText;
4158 Standard_Real myHeight;
4159 Handle(Visual3d_Layer) myLayer;
4160 Quantity_Color myColor;
4161 Quantity_Color mySubtitleColor;
4162 Aspect_TypeOfDisplayText myType;
4163 TCollection_AsciiString myFontName;
4166 IMPLEMENT_STANDARD_HANDLE(V3d_TextItem, Visual3d_LayerItem)
4167 IMPLEMENT_STANDARD_RTTIEXT(V3d_TextItem, Visual3d_LayerItem)
4169 // create and add to display the text item
4170 V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText,
4171 const Standard_Real theX1,
4172 const Standard_Real theY1,
4173 const Standard_Real theHeight,
4174 const TCollection_AsciiString& theFontName,
4175 const Quantity_Color& theColor,
4176 const Quantity_Color& theSubtitleColor,
4177 const Aspect_TypeOfDisplayText& theTypeOfDisplay,
4178 const Handle(Visual3d_Layer)& theLayer)
4179 : myX1 (theX1), myY1 (theY1),
4181 myHeight (theHeight),
4184 mySubtitleColor (theSubtitleColor),
4185 myType (theTypeOfDisplay),
4186 myFontName (theFontName)
4188 if (!myLayer.IsNull ())
4189 myLayer->AddLayerItem (this);
4193 void V3d_TextItem::RedrawLayerPrs ()
4195 if (myLayer.IsNull ())
4198 myLayer->SetColor (myColor);
4199 myLayer->SetTextAttributes (myFontName.ToCString (), myType, mySubtitleColor);
4200 myLayer->DrawText (myText.ToCString (), myX1, myY1, myHeight);
4203 DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
4205 // The Visual3d_LayerItem line item for "vlayerline" command
4206 // it provides a presentation of line with user-defined
4207 // linewidth, linetype and transparency.
4208 class V3d_LineItem : public Visual3d_LayerItem
4212 DEFINE_STANDARD_RTTI(V3d_LineItem)
4215 Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4216 Standard_Real X2, Standard_Real Y2,
4217 V3d_LayerMgrPointer theLayerMgr,
4218 Aspect_TypeOfLine theType = Aspect_TOL_SOLID,
4219 Standard_Real theWidth = 0.5,
4220 Standard_Real theTransp = 1.0);
4223 Standard_EXPORT void RedrawLayerPrs();
4227 Standard_Real myX1, myY1, myX2, myY2;
4228 V3d_LayerMgrPointer myLayerMgr;
4229 Aspect_TypeOfLine myType;
4230 Standard_Real myWidth;
4231 Standard_Real myTransparency;
4234 IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
4235 IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
4237 // default constructor for line item
4238 V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
4239 Standard_Real X2, Standard_Real Y2,
4240 V3d_LayerMgrPointer theLayerMgr,
4241 Aspect_TypeOfLine theType,
4242 Standard_Real theWidth,
4243 Standard_Real theTransp) :
4244 myX1(X1), myY1(Y1), myX2(X2), myY2(Y2), myLayerMgr(theLayerMgr),
4245 myType(theType), myWidth(theWidth), myTransparency(theTransp)
4247 if (myLayerMgr && !myLayerMgr->Overlay().IsNull())
4248 myLayerMgr->Overlay()->AddLayerItem (this);
4252 void V3d_LineItem::RedrawLayerPrs ()
4254 Handle (Visual3d_Layer) aOverlay;
4257 aOverlay = myLayerMgr->Overlay();
4259 if (!aOverlay.IsNull())
4261 Quantity_Color aColor(1.0, 0, 0, Quantity_TOC_RGB);
4262 aOverlay->SetColor(aColor);
4263 aOverlay->SetTransparency((Standard_ShortReal)myTransparency);
4264 aOverlay->SetLineAttributes((Aspect_TypeOfLine)myType, myWidth);
4265 aOverlay->BeginPolyline();
4266 aOverlay->AddVertex(myX1, myY1);
4267 aOverlay->AddVertex(myX2, myY2);
4268 aOverlay->ClosePrimitive();
4272 //=============================================================================
4273 //function : VLayerLine
4274 //purpose : Draws line in the v3d view layer with given attributes: linetype,
4275 // : linewidth, transparency coefficient
4276 //============================================================================
4277 static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4279 // get the active view
4280 Handle(V3d_View) aView = ViewerTest::CurrentView();
4283 di << "Call vinit before!\n";
4288 di << "Use: " << argv[0];
4289 di << " x1 y1 x2 y2 [linewidth = 0.5] [linetype = 0] [transparency = 1]\n";
4290 di << " linetype : { 0 | 1 | 2 | 3 } \n";
4291 di << " 0 - solid \n";
4292 di << " 1 - dashed \n";
4293 di << " 2 - dot \n";
4294 di << " 3 - dashdot\n";
4295 di << " transparency : { 0.0 - 1.0 } \n";
4296 di << " 0.0 - transparent\n";
4297 di << " 1.0 - visible \n";
4301 // get the input params
4302 Standard_Real X1 = Draw::Atof(argv[1]);
4303 Standard_Real Y1 = Draw::Atof(argv[2]);
4304 Standard_Real X2 = Draw::Atof(argv[3]);
4305 Standard_Real Y2 = Draw::Atof(argv[4]);
4307 Standard_Real aWidth = 0.5;
4308 Standard_Integer aType = 0;
4309 Standard_Real aTransparency = 1.0;
4313 aWidth = Draw::Atof(argv[5]);
4317 aType = (Standard_Integer) Draw::Atoi(argv[6]);
4322 aTransparency = Draw::Atof(argv[7]);
4323 if (aTransparency < 0 || aTransparency > 1.0)
4324 aTransparency = 1.0;
4327 // select appropriate line type
4328 Aspect_TypeOfLine aLineType;
4332 aLineType = Aspect_TOL_DASH;
4336 aLineType = Aspect_TOL_DOT;
4340 aLineType = Aspect_TOL_DOTDASH;
4344 aLineType = Aspect_TOL_SOLID;
4347 // replace layer manager
4348 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr(aView);
4349 aView->SetLayerMgr(aMgr);
4352 Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
4358 aView->MustBeResized();
4364 //=======================================================================
4365 //function : VOverlayText
4366 //purpose : Test text displaying in view overlay
4367 //=======================================================================
4368 static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char**argv)
4370 // get the active view
4371 Handle(V3d_View) aView = ViewerTest::CurrentView();
4374 di << "No active view. Please call vinit.\n";
4377 else if (argc < 4 || argc > 13)
4379 di << "Use: " << argv[0];
4380 di << " text x y [height] [font_name] [text_color: R G B] [displayType]\n";
4381 di << "[background_color: R G B]\n";
4382 di << " height - pixel height of the text (default=10.0)\n";
4383 di << " font_name - name of font (default=courier)\n";
4384 di << " text_color - R G B values of text color (default=255.0 255.0 255.0)\n";
4385 di << " display_type = {normal/subtitle/decal/blend/dimension}, (default=normal)\n";
4386 di << " background_color- R G B values used for subtitle and decal text\n";
4387 di << "(default=255.0 255.0 255.0)\n";
4391 TCollection_AsciiString aText (argv[1]);
4392 Standard_Real aPosX = Draw::Atof(argv[2]);
4393 Standard_Real aPosY = Draw::Atof(argv[3]);
4394 Standard_Real aHeight = (argc >= 5) ? Draw::Atof (argv[4]) : 10.0;
4397 TCollection_AsciiString aFontName = "Courier";
4399 aFontName = TCollection_AsciiString (argv[5]);
4402 Quantity_Parameter aColorRed = 1.0;
4403 Quantity_Parameter aColorGreen = 1.0;
4404 Quantity_Parameter aColorBlue = 1.0;
4407 aColorRed = Draw::Atof (argv[6])/255.;
4408 aColorGreen = Draw::Atof (argv[7])/255.;
4409 aColorBlue = Draw::Atof (argv[8])/255.;
4413 TCollection_AsciiString aDispStr;
4415 aDispStr = TCollection_AsciiString (argv[9]);
4417 Aspect_TypeOfDisplayText aTextType = Aspect_TODT_NORMAL;
4418 if (aDispStr.IsEqual ("subtitle"))
4419 aTextType = Aspect_TODT_SUBTITLE;
4420 else if (aDispStr.IsEqual ("decal"))
4421 aTextType = Aspect_TODT_DEKALE;
4422 else if (aDispStr.IsEqual ("blend"))
4423 aTextType = Aspect_TODT_BLEND;
4424 else if (aDispStr.IsEqual ("dimension"))
4425 aTextType = Aspect_TODT_DIMENSION;
4428 Quantity_Parameter aSubRed = 1.0;
4429 Quantity_Parameter aSubGreen = 1.0;
4430 Quantity_Parameter aSubBlue = 1.0;
4433 aSubRed = Draw::Atof (argv[10])/255.;
4434 aSubGreen = Draw::Atof (argv[11])/255.;
4435 aSubBlue = Draw::Atof (argv[12])/255.;
4438 // check fo current overlay
4439 Handle(Visual3d_Layer) anOverlay = aView->Viewer()->Viewer()->OverLayer ();
4440 if (anOverlay.IsNull ())
4442 Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (aView);
4443 anOverlay = aMgr->Overlay ();
4444 aView->SetLayerMgr (aMgr);
4447 Quantity_Color aTextColor (aColorRed, aColorGreen,
4448 aColorBlue, Quantity_TOC_RGB);
4449 Quantity_Color aSubtColor (aSubRed, aSubGreen,
4450 aSubBlue, Quantity_TOC_RGB);
4453 Handle(V3d_TextItem) anItem = new V3d_TextItem (aText, aPosX, aPosY,
4454 aHeight, aFontName, aTextColor, aSubtColor, aTextType, anOverlay);
4457 aView->MustBeResized();
4463 //==============================================================================
4466 //==============================================================================
4468 static int VGrid (Draw_Interpretor& /*theDI*/,
4469 Standard_Integer theArgNb,
4470 const char** theArgVec)
4472 // get the active view
4473 Handle(V3d_View) aView = ViewerTest::CurrentView();
4474 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
4475 if (aView.IsNull() || aViewer.IsNull())
4477 std::cerr << "No active view. Please call vinit.\n";
4481 Aspect_GridType aType = aViewer->GridType();
4482 Aspect_GridDrawMode aMode = aViewer->GridDrawMode();
4484 Standard_Integer anIter = 1;
4485 for (; anIter < theArgNb; ++anIter)
4487 const char* aValue = theArgVec[anIter];
4490 aType = Aspect_GT_Rectangular;
4492 else if (*aValue == 'c')
4494 aType = Aspect_GT_Circular;
4496 else if (*aValue == 'l')
4498 aMode = Aspect_GDM_Lines;
4500 else if (*aValue == 'p')
4502 aMode = Aspect_GDM_Points;
4504 else if (strcmp (aValue, "off" ) == 0)
4506 aViewer->DeactivateGrid();
4515 Standard_Integer aTail = (theArgNb - anIter);
4518 aViewer->ActivateGrid (aType, aMode);
4521 else if (aTail != 2 && aTail != 5)
4523 std::cerr << "Incorrect arguments number! Usage:\n"
4524 << "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]\n";
4528 Quantity_Length anOriginX, anOriginY;
4529 Quantity_PlaneAngle aRotAngle;
4530 if (aType == Aspect_GT_Rectangular)
4532 Quantity_Length aRStepX, aRStepY;
4533 aViewer->RectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4535 anOriginX = Draw::Atof (theArgVec[anIter++]);
4536 anOriginY = Draw::Atof (theArgVec[anIter++]);
4539 aRStepX = Draw::Atof (theArgVec[anIter++]);
4540 aRStepY = Draw::Atof (theArgVec[anIter++]);
4541 aRotAngle = Draw::Atof (theArgVec[anIter++]);
4543 aViewer->SetRectangularGridValues (anOriginX, anOriginY, aRStepX, aRStepY, aRotAngle);
4544 aViewer->ActivateGrid (aType, aMode);
4546 else if (aType == Aspect_GT_Circular)
4548 Quantity_Length aRadiusStep;
4549 Standard_Integer aDivisionNumber;
4550 aViewer->CircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
4552 anOriginX = Draw::Atof (theArgVec[anIter++]);
4553 anOriginY = Draw::Atof (theArgVec[anIter++]);
4556 aRadiusStep = Draw::Atof (theArgVec[anIter++]);
4557 aDivisionNumber = Draw::Atoi (theArgVec[anIter++]);
4558 aRotAngle = Draw::Atof (theArgVec[anIter++]);
4561 aViewer->SetCircularGridValues (anOriginX, anOriginY, aRadiusStep, aDivisionNumber, aRotAngle);
4562 aViewer->ActivateGrid (aType, aMode);
4568 //==============================================================================
4571 //==============================================================================
4573 static int VFps (Draw_Interpretor& theDI,
4574 Standard_Integer theArgNb,
4575 const char** theArgVec)
4577 // get the active view
4578 Handle(V3d_View) aView = ViewerTest::CurrentView();
4581 std::cerr << "No active view. Please call vinit.\n";
4585 Standard_Integer aFramesNb = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 100;
4588 std::cerr << "Incorrect arguments!\n";
4592 // the time is meaningless for first call
4593 // due to async OpenGl rendering
4596 // redraw view in loop to estimate average values
4599 for (Standard_Integer anInter = 0; anInter < aFramesNb; ++anInter)
4605 const Standard_Real aTime = aTimer.ElapsedTime();
4606 aTimer.OSD_Chronometer::Show (aCpu);
4608 const Standard_Real aFpsAver = Standard_Real(aFramesNb) / aTime;
4609 const Standard_Real aCpuAver = aCpu / Standard_Real(aFramesNb);
4611 // return statistics
4612 theDI << "FPS: " << aFpsAver << "\n"
4613 << "CPU: " << (1000.0 * aCpuAver) << " msec\n";
4618 //==============================================================================
4619 //function : VGlDebug
4621 //==============================================================================
4623 static int VGlDebug (Draw_Interpretor& theDI,
4624 Standard_Integer theArgNb,
4625 const char** theArgVec)
4627 Handle(OpenGl_GraphicDriver) aDriver;
4628 Handle(V3d_View) aView = ViewerTest::CurrentView();
4629 if (!aView.IsNull())
4631 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver());
4635 if (aDriver.IsNull())
4637 std::cerr << "No active view. Please call vinit.\n";
4641 Standard_Boolean isActive = OpenGl_Context::CheckExtension ((const char* )glGetString (GL_EXTENSIONS),
4642 "GL_ARB_debug_output");
4643 std::cout << "Active graphic driver: debug " << (isActive ? "ON" : "OFF") << "\n";
4644 theDI << (isActive ? "1" : "0");
4648 const Standard_Boolean toEnableDebug = Draw::Atoi (theArgVec[1]) != 0;
4649 ViewerTest_myDefaultCaps.contextDebug = toEnableDebug;
4650 ViewerTest_myDefaultCaps.glslWarnings = toEnableDebug;
4651 if (aDriver.IsNull())
4656 aDriver->ChangeOptions().glslWarnings = toEnableDebug;
4660 //==============================================================================
4663 //==============================================================================
4665 static int VVbo (Draw_Interpretor& theDI,
4666 Standard_Integer theArgNb,
4667 const char** theArgVec)
4669 const Standard_Boolean toSet = (theArgNb > 1);
4670 const Standard_Boolean toUseVbo = toSet ? (Draw::Atoi (theArgVec[1]) == 0) : 1;
4673 ViewerTest_myDefaultCaps.vboDisable = toUseVbo;
4677 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4678 if (aContextAIS.IsNull())
4682 std::cerr << "No active view!\n";
4686 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver());
4687 if (!aDriver.IsNull())
4691 theDI << (aDriver->Options().vboDisable ? "0" : "1") << "\n";
4695 aDriver->ChangeOptions().vboDisable = toUseVbo;
4702 //==============================================================================
4705 //==============================================================================
4707 static int VCaps (Draw_Interpretor& theDI,
4708 Standard_Integer theArgNb,
4709 const char** theArgVec)
4711 OpenGl_Caps* aCaps = &ViewerTest_myDefaultCaps;
4712 Handle(OpenGl_GraphicDriver) aDriver;
4713 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
4714 if (!aContext.IsNull())
4716 aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Driver());
4717 aCaps = &aDriver->ChangeOptions();
4722 theDI << "VBO: " << (aCaps->vboDisable ? "0" : "1") << "\n";
4723 theDI << "Sprites: " << (aCaps->pntSpritesDisable ? "0" : "1") << "\n";
4724 theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
4725 theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
4726 theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
4730 ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView());
4731 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
4733 Standard_CString anArg = theArgVec[anArgIter];
4734 TCollection_AsciiString anArgCase (anArg);
4735 anArgCase.LowerCase();
4736 if (anUpdateTool.parseRedrawMode (anArg))
4740 else if (anArgCase == "-ffp")
4742 Standard_Boolean toEnable = Standard_True;
4743 if (++anArgIter < theArgNb
4744 && !parseOnOff (theArgVec[anArgIter], toEnable))
4748 aCaps->ffpEnable = toEnable;
4750 else if (anArgCase == "-vbo")
4752 Standard_Boolean toEnable = Standard_True;
4753 if (++anArgIter < theArgNb
4754 && !parseOnOff (theArgVec[anArgIter], toEnable))
4758 aCaps->vboDisable = !toEnable;
4760 else if (anArgCase == "-sprite"
4761 || anArgCase == "-sprites")
4763 Standard_Boolean toEnable = Standard_True;
4764 if (++anArgIter < theArgNb
4765 && !parseOnOff (theArgVec[anArgIter], toEnable))
4769 aCaps->pntSpritesDisable = !toEnable;
4771 else if (anArgCase == "-softmode")
4773 Standard_Boolean toEnable = Standard_True;
4774 if (++anArgIter < theArgNb
4775 && !parseOnOff (theArgVec[anArgIter], toEnable))
4779 aCaps->contextNoAccel = toEnable;
4781 else if (anArgCase == "-accel"
4782 || anArgCase == "-acceleration")
4784 Standard_Boolean toEnable = Standard_True;
4785 if (++anArgIter < theArgNb
4786 && !parseOnOff (theArgVec[anArgIter], toEnable))
4790 aCaps->contextNoAccel = !toEnable;
4792 else if (anArgCase == "-compat"
4793 || anArgCase == "-compatprofile"
4794 || anArgCase == "-compatible"
4795 || anArgCase == "-compatibleprofile")
4797 Standard_Boolean toEnable = Standard_True;
4798 if (++anArgIter < theArgNb
4799 && !parseOnOff (theArgVec[anArgIter], toEnable))
4803 aCaps->contextCompatible = toEnable;
4804 if (!aCaps->contextCompatible)
4806 aCaps->ffpEnable = Standard_False;
4809 else if (anArgCase == "-core"
4810 || anArgCase == "-coreprofile")
4812 Standard_Boolean toEnable = Standard_True;
4813 if (++anArgIter < theArgNb
4814 && !parseOnOff (theArgVec[anArgIter], toEnable))
4818 aCaps->contextCompatible = !toEnable;
4819 if (!aCaps->contextCompatible)
4821 aCaps->ffpEnable = Standard_False;
4826 std::cout << "Error: unknown argument '" << anArg << "'\n";
4830 if (aCaps != &ViewerTest_myDefaultCaps)
4832 ViewerTest_myDefaultCaps = *aCaps;
4837 //==============================================================================
4838 //function : VMemGpu
4840 //==============================================================================
4842 static int VMemGpu (Draw_Interpretor& theDI,
4843 Standard_Integer theArgNb,
4844 const char** theArgVec)
4847 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
4848 if (aContextAIS.IsNull())
4850 std::cerr << "No active view. Please call vinit.\n";
4854 Handle(Graphic3d_GraphicDriver) aDriver = aContextAIS->CurrentViewer()->Driver();
4855 if (aDriver.IsNull())
4857 std::cerr << "Graphic driver not available.\n";
4861 Standard_Size aFreeBytes = 0;
4862 TCollection_AsciiString anInfo;
4863 if (!aDriver->MemoryInfo (aFreeBytes, anInfo))
4865 std::cerr << "Information not available.\n";
4869 if (theArgNb > 1 && *theArgVec[1] == 'f')
4871 theDI << Standard_Real (aFreeBytes);
4881 // ==============================================================================
4882 // function : VReadPixel
4884 // ==============================================================================
4885 static int VReadPixel (Draw_Interpretor& theDI,
4886 Standard_Integer theArgNb,
4887 const char** theArgVec)
4889 // get the active view
4890 Handle(V3d_View) aView = ViewerTest::CurrentView();
4893 std::cerr << "No active view. Please call vinit.\n";
4896 else if (theArgNb < 3)
4898 std::cerr << "Usage : " << theArgVec[0] << " xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]\n";
4902 Image_PixMap::ImgFormat aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4903 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGBA;
4905 Standard_Integer aWidth, aHeight;
4906 aView->Window()->Size (aWidth, aHeight);
4907 const Standard_Integer anX = Draw::Atoi (theArgVec[1]);
4908 const Standard_Integer anY = Draw::Atoi (theArgVec[2]);
4909 if (anX < 0 || anX >= aWidth || anY < 0 || anY > aHeight)
4911 std::cerr << "Pixel coordinates (" << anX << "; " << anY << ") are out of view (" << aWidth << " x " << aHeight << ")\n";
4915 Standard_Boolean toShowName = Standard_False;
4916 Standard_Boolean toShowHls = Standard_False;
4917 for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
4919 const char* aParam = theArgVec[anIter];
4920 if ( strcasecmp( aParam, "rgb" ) == 0 )
4922 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4923 aBufferType = Graphic3d_BT_RGB;
4925 else if ( strcasecmp( aParam, "hls" ) == 0 )
4927 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR;
4928 aBufferType = Graphic3d_BT_RGB;
4929 toShowHls = Standard_True;
4931 else if ( strcasecmp( aParam, "rgbf" ) == 0 )
4933 aFormat = Image_PixMap::ImgRGBF;
4934 aBufferType = Graphic3d_BT_RGB;
4936 else if ( strcasecmp( aParam, "rgba" ) == 0 )
4938 aFormat = Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
4939 aBufferType = Graphic3d_BT_RGBA;
4941 else if ( strcasecmp( aParam, "rgbaf" ) == 0 )
4943 aFormat = Image_PixMap::ImgRGBAF;
4944 aBufferType = Graphic3d_BT_RGBA;
4946 else if ( strcasecmp( aParam, "depth" ) == 0 )
4948 aFormat = Image_PixMap::ImgGrayF;
4949 aBufferType = Graphic3d_BT_Depth;
4951 else if ( strcasecmp( aParam, "name" ) == 0 )
4953 toShowName = Standard_True;
4957 Image_PixMap anImage;
4958 if (!anImage.InitTrash (aFormat, aWidth, aHeight))
4960 std::cerr << "Image allocation failed\n";
4963 else if (!aView->ToPixMap (anImage, aWidth, aHeight, aBufferType))
4965 std::cerr << "Image dump failed\n";
4969 Quantity_Parameter anAlpha;
4970 Quantity_Color aColor = anImage.PixelColor (anX, anY, anAlpha);
4973 if (aBufferType == Graphic3d_BT_RGBA)
4975 theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha;
4979 theDI << Quantity_Color::StringName (aColor.Name());
4984 switch (aBufferType)
4987 case Graphic3d_BT_RGB:
4991 theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation();
4995 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue();
4999 case Graphic3d_BT_RGBA:
5001 theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha;
5004 case Graphic3d_BT_Depth:
5006 theDI << aColor.Red();
5015 //==============================================================================
5016 //function : VDiffImage
5017 //purpose : The draw-command compares two images.
5018 //==============================================================================
5020 static int VDiffImage (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
5024 theDI << "Not enough arguments.\n";
5029 const char* anImgPathRef = theArgVec[1];
5030 const char* anImgPathNew = theArgVec[2];
5032 // get string tolerance and check its validity
5033 Standard_Real aTolColor = Draw::Atof (theArgVec[3]);
5034 if (aTolColor < 0.0)
5036 if (aTolColor > 1.0)
5039 Standard_Boolean toBlackWhite = (Draw::Atoi (theArgVec[4]) == 1);
5040 Standard_Boolean isBorderFilterOn = (Draw::Atoi (theArgVec[5]) == 1);
5042 // image file of difference
5043 const char* aDiffImagePath = (theArgNb >= 7) ? theArgVec[6] : NULL;
5045 // compare the images
5046 Image_Diff aComparer;
5047 if (!aComparer.Init (anImgPathRef, anImgPathNew, toBlackWhite))
5052 aComparer.SetColorTolerance (aTolColor);
5053 aComparer.SetBorderFilterOn (isBorderFilterOn);
5054 Standard_Integer aDiffColorsNb = aComparer.Compare();
5055 theDI << aDiffColorsNb << "\n";
5057 // save image of difference
5058 if (aDiffImagePath != NULL)
5060 aComparer.SaveDiffImage (aDiffImagePath);
5066 //=======================================================================
5067 //function : VSelect
5068 //purpose : Emulates different types of selection by mouse:
5069 // 1) single click selection
5070 // 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)
5071 // 3) selection with polygon having corners at
5072 // pixel positions (x1,y1),...,(xn,yn)
5073 // 4) any of these selections with shift button pressed
5074 //=======================================================================
5075 static Standard_Integer VSelect (Draw_Interpretor& di,
5076 Standard_Integer argc,
5081 di << "Usage : " << argv[0] << " x1 y1 [x2 y2 [... xn yn]] [shift_selection = 1|0]" << "\n";
5085 Handle(AIS_InteractiveContext) myAIScontext = ViewerTest::GetAISContext();
5086 if(myAIScontext.IsNull())
5088 di << "use 'vinit' command before " << argv[0] << "\n";
5091 const Standard_Boolean isShiftSelection = (argc>3 && !(argc%2) && (atoi(argv[argc-1])==1));
5092 Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
5093 aCurrentEventManager->MoveTo(atoi(argv[1]),atoi(argv[2]));
5096 if(isShiftSelection)
5097 aCurrentEventManager->ShiftSelect();
5099 aCurrentEventManager->Select();
5103 if(isShiftSelection)
5104 aCurrentEventManager->ShiftSelect(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
5106 aCurrentEventManager->Select(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
5110 Standard_Integer anUpper = 0;
5112 if(isShiftSelection)
5113 anUpper = (argc-1)/2;
5116 TColgp_Array1OfPnt2d aPolyline(1,anUpper);
5118 for(Standard_Integer i=1;i<=anUpper;++i)
5119 aPolyline.SetValue(i,gp_Pnt2d(atoi(argv[2*i-1]),atoi(argv[2*i])));
5121 if(isShiftSelection)
5122 aCurrentEventManager->ShiftSelect(aPolyline);
5124 aCurrentEventManager->Select(aPolyline);
5129 //=======================================================================
5130 //function : VMoveTo
5131 //purpose : Emulates cursor movement to defined pixel position
5132 //=======================================================================
5133 static Standard_Integer VMoveTo (Draw_Interpretor& di,
5134 Standard_Integer argc,
5139 di << "Usage : " << argv[0] << " x y" << "\n";
5143 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5144 if(aContext.IsNull())
5146 di << "use 'vinit' command before " << argv[0] << "\n";
5149 ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
5153 //=================================================================================================
5154 //function : VViewParams
5155 //purpose : Gets or sets AIS View characteristics
5156 //=================================================================================================
5157 static int VViewParams (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5159 Handle(V3d_View) anAISView = ViewerTest::CurrentView();
5160 if (anAISView.IsNull())
5162 std::cout << theArgVec[0] << ": please initialize or activate view.\n";
5168 // print all of the available view parameters
5169 Quantity_Factor anAISViewScale = anAISView->Scale();
5171 Standard_Real anAISViewProjX = 0.0;
5172 Standard_Real anAISViewProjY = 0.0;
5173 Standard_Real anAISViewProjZ = 0.0;
5174 anAISView->Proj (anAISViewProjX, anAISViewProjY, anAISViewProjZ);
5176 Standard_Real anAISViewUpX = 0.0;
5177 Standard_Real anAISViewUpY = 0.0;
5178 Standard_Real anAISViewUpZ = 0.0;
5179 anAISView->Up (anAISViewUpX, anAISViewUpY, anAISViewUpZ);
5181 Standard_Real anAISViewAtX = 0.0;
5182 Standard_Real anAISViewAtY = 0.0;
5183 Standard_Real anAISViewAtZ = 0.0;
5184 anAISView->At (anAISViewAtX, anAISViewAtY, anAISViewAtZ);
5186 Standard_Real anAISViewEyeX = 0.0;
5187 Standard_Real anAISViewEyeY = 0.0;
5188 Standard_Real anAISViewEyeZ = 0.0;
5189 anAISView->Eye (anAISViewEyeX, anAISViewEyeY, anAISViewEyeZ);
5191 theDi << "Scale of current view: " << anAISViewScale << "\n";
5192 theDi << "Proj on X : " << anAISViewProjX << "; on Y: " << anAISViewProjY << "; on Z: " << anAISViewProjZ << "\n";
5193 theDi << "Up on X : " << anAISViewUpX << "; on Y: " << anAISViewUpY << "; on Z: " << anAISViewUpZ << "\n";
5194 theDi << "At on X : " << anAISViewAtX << "; on Y: " << anAISViewAtY << "; on Z: " << anAISViewAtZ << "\n";
5195 theDi << "Eye on X : " << anAISViewEyeX << "; on Y: " << anAISViewEyeY << "; on Z: " << anAISViewEyeZ << "\n";
5199 // -------------------------
5200 // Parse options and values
5201 // -------------------------
5203 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfKeysByValues;
5204 TCollection_AsciiString aParseKey;
5205 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
5207 TCollection_AsciiString anArg (theArgVec [anArgIt]);
5209 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
5212 aParseKey.Remove (1);
5213 aParseKey.UpperCase();
5214 aMapOfKeysByValues.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
5218 if (aParseKey.IsEmpty())
5220 std::cout << theArgVec[0] << ": values should be passed with key.\n";
5221 std::cout << "Type help for more information.\n";
5225 aMapOfKeysByValues(aParseKey)->Append (anArg);
5228 // ---------------------------------------------
5229 // Change or print parameters, order plays role
5230 // ---------------------------------------------
5232 // Check arguments for validity
5233 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfKeysByValues);
5234 for (; aMapIt.More(); aMapIt.Next())
5236 const TCollection_AsciiString& aKey = aMapIt.Key();
5237 const Handle(TColStd_HSequenceOfAsciiString)& aValues = aMapIt.Value();
5239 if (!(aKey.IsEqual ("SCALE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5240 && !(aKey.IsEqual ("SIZE") && (aValues->Length() == 1 || aValues->IsEmpty()))
5241 && !(aKey.IsEqual ("EYE") && (aValues->Length() == 3 || aValues->IsEmpty()))
5242 && !(aKey.IsEqual ("AT") && (aValues->Length() == 3 || aValues->IsEmpty()))
5243 && !(aKey.IsEqual ("UP") && (aValues->Length() == 3 || aValues->IsEmpty()))
5244 && !(aKey.IsEqual ("PROJ") && (aValues->Length() == 3 || aValues->IsEmpty()))
5245 && !(aKey.IsEqual ("CENTER") && aValues->Length() == 2))
5247 TCollection_AsciiString aLowerKey;
5250 aLowerKey.LowerCase();
5251 std::cout << theArgVec[0] << ": " << aLowerKey << " is unknown option, or number of arguments is invalid.\n";
5252 std::cout << "Type help for more information.\n";
5257 Handle(TColStd_HSequenceOfAsciiString) aValues;
5259 // Change view parameters in proper order
5260 if (aMapOfKeysByValues.Find ("SCALE", aValues))
5262 if (aValues->IsEmpty())
5264 theDi << "Scale: " << anAISView->Scale() << "\n";
5268 anAISView->SetScale (aValues->Value(1).RealValue());
5271 if (aMapOfKeysByValues.Find ("SIZE", aValues))
5273 if (aValues->IsEmpty())
5275 Standard_Real aSizeX = 0.0;
5276 Standard_Real aSizeY = 0.0;
5277 anAISView->Size (aSizeX, aSizeY);
5278 theDi << "Size X: " << aSizeX << " Y: " << aSizeY << "\n";
5282 anAISView->SetSize (aValues->Value(1).RealValue());
5285 if (aMapOfKeysByValues.Find ("EYE", aValues))
5287 if (aValues->IsEmpty())
5289 Standard_Real anEyeX = 0.0;
5290 Standard_Real anEyeY = 0.0;
5291 Standard_Real anEyeZ = 0.0;
5292 anAISView->Eye (anEyeX, anEyeY, anEyeZ);
5293 theDi << "Eye X: " << anEyeX << " Y: " << anEyeY << " Z: " << anEyeZ << "\n";
5297 anAISView->SetEye (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5300 if (aMapOfKeysByValues.Find ("AT", aValues))
5302 if (aValues->IsEmpty())
5304 Standard_Real anAtX = 0.0;
5305 Standard_Real anAtY = 0.0;
5306 Standard_Real anAtZ = 0.0;
5307 anAISView->At (anAtX, anAtY, anAtZ);
5308 theDi << "At X: " << anAtX << " Y: " << anAtY << " Z: " << anAtZ << "\n";
5312 anAISView->SetAt (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5315 if (aMapOfKeysByValues.Find ("PROJ", aValues))
5317 if (aValues->IsEmpty())
5319 Standard_Real aProjX = 0.0;
5320 Standard_Real aProjY = 0.0;
5321 Standard_Real aProjZ = 0.0;
5322 anAISView->Proj (aProjX, aProjY, aProjZ);
5323 theDi << "Proj X: " << aProjX << " Y: " << aProjY << " Z: " << aProjZ << "\n";
5327 anAISView->SetProj (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5330 if (aMapOfKeysByValues.Find ("UP", aValues))
5332 if (aValues->IsEmpty())
5334 Standard_Real anUpX = 0.0;
5335 Standard_Real anUpY = 0.0;
5336 Standard_Real anUpZ = 0.0;
5337 anAISView->Up (anUpX, anUpY, anUpZ);
5338 theDi << "Up X: " << anUpX << " Y: " << anUpY << " Z: " << anUpZ << "\n";
5342 anAISView->SetUp (aValues->Value(1).RealValue(), aValues->Value(2).RealValue(), aValues->Value(3).RealValue());
5345 if (aMapOfKeysByValues.Find ("CENTER", aValues))
5347 anAISView->SetCenter (aValues->Value(1).IntegerValue(), aValues->Value(2).IntegerValue());
5353 //=======================================================================
5354 //function : VChangeSelected
5355 //purpose : Adds the shape to selection or remove one from it
5356 //=======================================================================
5357 static Standard_Integer VChangeSelected (Draw_Interpretor& di,
5358 Standard_Integer argc,
5363 di<<"Usage : " << argv[0] << " shape \n";
5367 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5368 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5369 TCollection_AsciiString aName(argv[1]);
5370 Handle(AIS_InteractiveObject) anAISObject;
5372 if(!aMap.IsBound2(aName))
5374 di<<"Use 'vdisplay' before";
5379 anAISObject = Handle(AIS_InteractiveObject)::DownCast(aMap.Find2(aName));
5380 if(anAISObject.IsNull()){
5381 di<<"No interactive object \n";
5385 if(aContext->HasOpenedContext())
5387 aContext->AddOrRemoveSelected(anAISObject);
5391 aContext->AddOrRemoveCurrentObject(anAISObject);
5397 //=======================================================================
5398 //function : VZClipping
5399 //purpose : Gets or sets ZClipping mode, width and depth
5400 //=======================================================================
5401 static Standard_Integer VZClipping (Draw_Interpretor& di,
5402 Standard_Integer argc,
5407 di << "Usage : " << argv[0] << " [mode] [depth width]" << "\n"
5408 <<"mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
5411 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5412 if(aContext.IsNull())
5414 di << "use 'vinit' command before " << argv[0] << "\n";
5417 Handle(V3d_View) aView = ViewerTest::CurrentView();
5418 V3d_TypeOfZclipping aZClippingMode = V3d_OFF;
5421 TCollection_AsciiString aZClippingModeString;
5422 Quantity_Length aDepth, aWidth;
5423 aZClippingMode = aView->ZClipping(aDepth, aWidth);
5424 switch (aZClippingMode)
5427 aZClippingModeString.Copy("OFF");
5430 aZClippingModeString.Copy("BACK");
5433 aZClippingModeString.Copy("FRONT");
5436 aZClippingModeString.Copy("SLICE");
5439 aZClippingModeString.Copy(TCollection_AsciiString(aZClippingMode));
5442 di << "ZClippingMode = " << aZClippingModeString.ToCString() << "\n"
5443 << "ZClipping depth = " << aDepth << "\n"
5444 << "ZClipping width = " << aWidth << "\n";
5450 Standard_Integer aStatus = 0;
5451 if ( strcmp (argv [1], "OFF") == 0 ) {
5453 aZClippingMode = V3d_OFF;
5455 if ( strcmp (argv [1], "BACK") == 0 ) {
5457 aZClippingMode = V3d_BACK;
5459 if ( strcmp (argv [1], "FRONT") == 0 ) {
5461 aZClippingMode = V3d_FRONT;
5463 if ( strcmp (argv [1], "SLICE") == 0 ) {
5465 aZClippingMode = V3d_SLICE;
5469 di << "Bad mode; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
5470 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
5473 aView->SetZClippingType(aZClippingMode);
5477 Quantity_Length aDepth = 0., aWidth = 1.;
5480 aDepth = Draw::Atof (argv[1]);
5481 aWidth = Draw::Atof (argv[2]);
5485 aDepth = Draw::Atof (argv[2]);
5486 aWidth = Draw::Atof (argv[3]);
5489 if(aDepth<0. || aDepth>1.)
5491 di << "Bad depth; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
5492 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
5495 if(aWidth<0. || aWidth>1.)
5497 di << "Bad width; Usage : " << argv[0] << " [mode] [depth width]" << "\n"
5498 << "mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]" << "\n";
5502 aView->SetZClippingDepth(aDepth);
5503 aView->SetZClippingWidth(aWidth);
5510 //=======================================================================
5511 //function : VNbSelected
5512 //purpose : Returns number of selected objects
5513 //=======================================================================
5514 static Standard_Integer VNbSelected (Draw_Interpretor& di,
5515 Standard_Integer argc,
5520 di << "Usage : " << argv[0] << "\n";
5523 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5524 if(aContext.IsNull())
5526 di << "use 'vinit' command before " << argv[0] << "\n";
5529 di << aContext->NbSelected() << "\n";
5533 //=======================================================================
5534 //function : VAntialiasing
5535 //purpose : Switches altialiasing on or off
5536 //=======================================================================
5537 static Standard_Integer VAntialiasing (Draw_Interpretor& di,
5538 Standard_Integer argc,
5543 di << "Usage : " << argv[0] << " [1|0]" << "\n";
5547 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5548 if(aContext.IsNull())
5550 di << "use 'vinit' command before " << argv[0] << "\n";
5554 Handle(V3d_View) aView = ViewerTest::CurrentView();
5556 if((argc == 2) && (atof(argv[1]) == 0))
5557 aView->SetAntialiasingOff();
5559 aView->SetAntialiasingOn();
5564 //=======================================================================
5565 //function : VPurgeDisplay
5566 //purpose : Switches altialiasing on or off
5567 //=======================================================================
5568 static Standard_Integer VPurgeDisplay (Draw_Interpretor& di,
5569 Standard_Integer argc,
5574 di << "Usage : " << argv[0] << "\n";
5577 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5578 if (aContext.IsNull())
5580 di << "use 'vinit' command before " << argv[0] << "\n";
5583 aContext->CloseAllContexts(Standard_False);
5584 di << aContext->PurgeDisplay() << "\n";
5588 //=======================================================================
5589 //function : VSetViewSize
5591 //=======================================================================
5592 static Standard_Integer VSetViewSize (Draw_Interpretor& di,
5593 Standard_Integer argc,
5596 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5597 if(aContext.IsNull())
5599 di << "use 'vinit' command before " << argv[0] << "\n";
5604 di<<"Usage : " << argv[0] << " Size\n";
5607 Standard_Real aSize = Draw::Atof (argv[1]);
5610 di<<"Bad Size value : " << aSize << "\n";
5614 Handle(V3d_View) aView = ViewerTest::CurrentView();
5615 aView->SetSize(aSize);
5619 //=======================================================================
5620 //function : VMoveView
5622 //=======================================================================
5623 static Standard_Integer VMoveView (Draw_Interpretor& di,
5624 Standard_Integer argc,
5627 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5628 if(aContext.IsNull())
5630 di << "use 'vinit' command before " << argv[0] << "\n";
5633 if(argc < 4 || argc > 5)
5635 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
5638 Standard_Real Dx = Draw::Atof (argv[1]);
5639 Standard_Real Dy = Draw::Atof (argv[2]);
5640 Standard_Real Dz = Draw::Atof (argv[3]);
5641 Standard_Boolean aStart = Standard_True;
5644 aStart = (Draw::Atoi (argv[4]) > 0);
5647 Handle(V3d_View) aView = ViewerTest::CurrentView();
5648 aView->Move(Dx,Dy,Dz,aStart);
5652 //=======================================================================
5653 //function : VTranslateView
5655 //=======================================================================
5656 static Standard_Integer VTranslateView (Draw_Interpretor& di,
5657 Standard_Integer argc,
5660 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5661 if(aContext.IsNull())
5663 di << "use 'vinit' command before " << argv[0] << "\n";
5666 if(argc < 4 || argc > 5)
5668 di<<"Usage : " << argv[0] << " Dx Dy Dz [Start = 1|0]\n";
5671 Standard_Real Dx = Draw::Atof (argv[1]);
5672 Standard_Real Dy = Draw::Atof (argv[2]);
5673 Standard_Real Dz = Draw::Atof (argv[3]);
5674 Standard_Boolean aStart = Standard_True;
5677 aStart = (Draw::Atoi (argv[4]) > 0);
5680 Handle(V3d_View) aView = ViewerTest::CurrentView();
5681 aView->Translate(Dx,Dy,Dz,aStart);
5685 //=======================================================================
5686 //function : VTurnView
5688 //=======================================================================
5689 static Standard_Integer VTurnView (Draw_Interpretor& di,
5690 Standard_Integer argc,
5693 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
5694 if(aContext.IsNull()) {
5695 di << "use 'vinit' command before " << argv[0] << "\n";
5698 if(argc < 4 || argc > 5){
5699 di<<"Usage : " << argv[0] << " Ax Ay Az [Start = 1|0]\n";
5702 Standard_Real Ax = Draw::Atof (argv[1]);
5703 Standard_Real Ay = Draw::Atof (argv[2]);
5704 Standard_Real Az = Draw::Atof (argv[3]);
5705 Standard_Boolean aStart = Standard_True;
5708 aStart = (Draw::Atoi (argv[4]) > 0);
5711 Handle(V3d_View) aView = ViewerTest::CurrentView();
5712 aView->Turn(Ax,Ay,Az,aStart);
5716 //==============================================================================
5717 //function : VTextureEnv
5718 //purpose : ENables or disables environment mapping
5719 //==============================================================================
5720 class OCC_TextureEnv : public Graphic3d_TextureEnv
5723 OCC_TextureEnv(const Standard_CString FileName);
5724 OCC_TextureEnv(const Graphic3d_NameOfTextureEnv aName);
5725 void SetTextureParameters(const Standard_Boolean theRepeatFlag,
5726 const Standard_Boolean theModulateFlag,
5727 const Graphic3d_TypeOfTextureFilter theFilter,
5728 const Standard_ShortReal theXScale,
5729 const Standard_ShortReal theYScale,
5730 const Standard_ShortReal theXShift,
5731 const Standard_ShortReal theYShift,
5732 const Standard_ShortReal theAngle);
5733 DEFINE_STANDARD_RTTI(OCC_TextureEnv);
5735 DEFINE_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
5736 IMPLEMENT_STANDARD_HANDLE(OCC_TextureEnv, Graphic3d_TextureEnv);
5737 IMPLEMENT_STANDARD_RTTIEXT(OCC_TextureEnv, Graphic3d_TextureEnv);
5739 OCC_TextureEnv::OCC_TextureEnv(const Standard_CString theFileName)
5740 : Graphic3d_TextureEnv(theFileName)
5744 OCC_TextureEnv::OCC_TextureEnv(const Graphic3d_NameOfTextureEnv theTexId)
5745 : Graphic3d_TextureEnv(theTexId)
5749 void OCC_TextureEnv::SetTextureParameters(const Standard_Boolean theRepeatFlag,
5750 const Standard_Boolean theModulateFlag,
5751 const Graphic3d_TypeOfTextureFilter theFilter,
5752 const Standard_ShortReal theXScale,
5753 const Standard_ShortReal theYScale,
5754 const Standard_ShortReal theXShift,
5755 const Standard_ShortReal theYShift,
5756 const Standard_ShortReal theAngle)
5758 myParams->SetRepeat (theRepeatFlag);
5759 myParams->SetModulate (theModulateFlag);
5760 myParams->SetFilter (theFilter);
5761 myParams->SetScale (Graphic3d_Vec2(theXScale, theYScale));
5762 myParams->SetTranslation(Graphic3d_Vec2(theXShift, theYShift));
5763 myParams->SetRotation (theAngle);
5766 static int VTextureEnv (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
5768 // get the active view
5769 Handle(V3d_View) aView = ViewerTest::CurrentView();
5772 std::cerr << "No active view. Please call vinit.\n";
5776 // Checking the input arguments
5777 Standard_Boolean anEnableFlag = Standard_False;
5778 Standard_Boolean isOk = theArgNb >= 2;
5781 TCollection_AsciiString anEnableOpt(theArgVec[1]);
5782 anEnableFlag = anEnableOpt.IsEqual("on");
5783 isOk = anEnableFlag || anEnableOpt.IsEqual("off");
5787 isOk = (theArgNb == 3 || theArgNb == 11);
5790 TCollection_AsciiString aTextureOpt(theArgVec[2]);
5791 isOk = (!aTextureOpt.IsIntegerValue() ||
5792 (aTextureOpt.IntegerValue() >= 0 && aTextureOpt.IntegerValue() < Graphic3d_NOT_ENV_UNKNOWN));
5794 if (isOk && theArgNb == 11)
5796 TCollection_AsciiString aRepeatOpt (theArgVec[3]),
5797 aModulateOpt(theArgVec[4]),
5798 aFilterOpt (theArgVec[5]),
5799 aSScaleOpt (theArgVec[6]),
5800 aTScaleOpt (theArgVec[7]),
5801 aSTransOpt (theArgVec[8]),
5802 aTTransOpt (theArgVec[9]),
5803 anAngleOpt (theArgVec[10]);
5804 isOk = ((aRepeatOpt. IsEqual("repeat") || aRepeatOpt. IsEqual("clamp")) &&
5805 (aModulateOpt.IsEqual("modulate") || aModulateOpt.IsEqual("decal")) &&
5806 (aFilterOpt. IsEqual("nearest") || aFilterOpt. IsEqual("bilinear") || aFilterOpt.IsEqual("trilinear")) &&
5807 aSScaleOpt.IsRealValue() && aTScaleOpt.IsRealValue() &&
5808 aSTransOpt.IsRealValue() && aTTransOpt.IsRealValue() &&
5809 anAngleOpt.IsRealValue());
5816 std::cerr << "Usage :" << std::endl;
5817 std::cerr << theArgVec[0] << " off" << std::endl;
5818 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;
5824 TCollection_AsciiString aTextureOpt(theArgVec[2]);
5825 Handle(OCC_TextureEnv) aTexEnv = aTextureOpt.IsIntegerValue() ?
5826 new OCC_TextureEnv((Graphic3d_NameOfTextureEnv)aTextureOpt.IntegerValue()) :
5827 new OCC_TextureEnv(theArgVec[2]);
5831 TCollection_AsciiString aRepeatOpt(theArgVec[3]), aModulateOpt(theArgVec[4]), aFilterOpt(theArgVec[5]);
5832 aTexEnv->SetTextureParameters(
5833 aRepeatOpt. IsEqual("repeat"),
5834 aModulateOpt.IsEqual("modulate"),
5835 aFilterOpt. IsEqual("nearest") ? Graphic3d_TOTF_NEAREST :
5836 aFilterOpt.IsEqual("bilinear") ? Graphic3d_TOTF_BILINEAR :
5837 Graphic3d_TOTF_TRILINEAR,
5838 (Standard_ShortReal)Draw::Atof(theArgVec[6]),
5839 (Standard_ShortReal)Draw::Atof(theArgVec[7]),
5840 (Standard_ShortReal)Draw::Atof(theArgVec[8]),
5841 (Standard_ShortReal)Draw::Atof(theArgVec[9]),
5842 (Standard_ShortReal)Draw::Atof(theArgVec[10])
5845 aView->SetTextureEnv(aTexEnv);
5846 aView->SetSurfaceDetail(V3d_TEX_ENVIRONMENT);
5848 else // Disabling environment mapping
5850 aView->SetSurfaceDetail(V3d_TEX_NONE);
5851 Handle(Graphic3d_TextureEnv) aTexture;
5852 aView->SetTextureEnv(aTexture); // Passing null handle to clear the texture data
5859 //===============================================================================================
5860 //function : VClipPlane
5862 //===============================================================================================
5863 static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
5865 // use short-cut for created clip planes map of created (or "registered by name") clip planes
5866 typedef NCollection_DataMap<TCollection_AsciiString, Handle(Graphic3d_ClipPlane)> MapOfPlanes;
5867 static MapOfPlanes aRegPlanes;
5871 theDi << theArgVec[0] << ": command argument is required. Type help for more information.\n";
5875 TCollection_AsciiString aCommand (theArgVec[1]);
5877 // print maximum number of planes for current viewer
5878 if (aCommand == "maxplanes")
5882 theDi << theArgVec[0] << ": view name is required. Type help for more information.\n";
5886 TCollection_AsciiString aViewName (theArgVec[2]);
5888 if (!ViewerTest_myViews.IsBound1 (aViewName))
5890 theDi << theArgVec[0] << ": view is not found.\n";
5894 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
5896 theDi << theArgVec[0] << ": "
5897 << aView->Viewer()->Driver()->InquirePlaneLimit()
5898 << " plane slots provided by driver."
5899 << " Note that 2 more planes might be used (reserved for z-clipping).\n";
5904 // create / delete plane instance
5905 if (aCommand == "create" || aCommand == "delete" || aCommand == "clone")
5909 theDi << theArgVec[0] << ": plane name is required. Type help for more information.\n";
5913 Standard_Boolean toCreate = (aCommand == "create");
5914 Standard_Boolean toClone = (aCommand == "clone");
5915 TCollection_AsciiString aPlane (theArgVec[2]);
5919 if (aRegPlanes.IsBound (aPlane))
5921 theDi << theArgVec[0] << ": plane name is in use.\n";
5925 aRegPlanes.Bind (aPlane, new Graphic3d_ClipPlane());
5927 else if (toClone) // toClone
5929 if (!aRegPlanes.IsBound (aPlane))
5931 theDi << theArgVec[0] << ": no such plane.\n";
5937 theDi << theArgVec[0] << ": enter name for new plane. Type help for more information.\n";
5941 TCollection_AsciiString aClone (theArgVec[3]);
5942 if (aRegPlanes.IsBound (aClone))
5944 theDi << theArgVec[0] << ": plane name is in use.\n";
5948 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
5950 aRegPlanes.Bind (aClone, aClipPlane->Clone());
5954 if (!aRegPlanes.IsBound (aPlane))
5956 theDi << theArgVec[0] << ": no such plane.\n";
5960 Handle(Graphic3d_ClipPlane) aClipPlane = aRegPlanes.Find (aPlane);
5961 aRegPlanes.UnBind (aPlane);
5963 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIObjIt (GetMapOfAIS());
5964 for (; anIObjIt.More(); anIObjIt.Next())
5966 Handle(PrsMgr_PresentableObject) aPrs = Handle(PrsMgr_PresentableObject)::DownCast (anIObjIt.Key1());
5967 aPrs->RemoveClipPlane(aClipPlane);
5970 NCollection_DoubleMap<TCollection_AsciiString, Handle(V3d_View)>::Iterator aViewIt(ViewerTest_myViews);
5971 for (; aViewIt.More(); aViewIt.Next())
5973 const Handle(V3d_View)& aView = aViewIt.Key2();
5974 aView->RemoveClipPlane(aClipPlane);
5977 ViewerTest::RedrawAllViews();
5983 // set / unset plane command
5984 if (aCommand == "set" || aCommand == "unset")
5988 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
5992 Standard_Boolean toSet = (aCommand == "set");
5993 TCollection_AsciiString aPlane (theArgVec [2]);
5994 if (!aRegPlanes.IsBound (aPlane))
5996 theDi << theArgVec[0] << ": no such plane.\n";
6000 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6002 TCollection_AsciiString aTarget (theArgVec [3]);
6003 if (aTarget != "object" && aTarget != "view")
6005 theDi << theArgVec[0] << ": invalid target.\n";
6009 if (aTarget == "object" || aTarget == "view")
6013 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6017 Standard_Boolean isObject = (aTarget == "object");
6019 for (Standard_Integer anIt = 4; anIt < theArgsNb; ++anIt)
6021 TCollection_AsciiString anEntityName (theArgVec[anIt]);
6022 if (isObject) // to object
6024 if (!GetMapOfAIS().IsBound2 (anEntityName))
6026 theDi << theArgVec[0] << ": can not find IO with name " << anEntityName << ".\n";
6030 Handle(AIS_InteractiveObject) aIObj =
6031 Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anEntityName));
6034 aIObj->AddClipPlane (aClipPlane);
6036 aIObj->RemoveClipPlane (aClipPlane);
6040 if (!ViewerTest_myViews.IsBound1 (anEntityName))
6042 theDi << theArgVec[0] << ": can not find View with name " << anEntityName << ".\n";
6046 Handle(V3d_View) aView = ViewerTest_myViews.Find1(anEntityName);
6048 aView->AddClipPlane (aClipPlane);
6050 aView->RemoveClipPlane (aClipPlane);
6054 ViewerTest::RedrawAllViews();
6060 // change plane command
6061 if (aCommand == "change")
6065 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6069 TCollection_AsciiString aPlane (theArgVec [2]);
6070 if (!aRegPlanes.IsBound (aPlane))
6072 theDi << theArgVec[0] << ": no such plane.\n";
6076 const Handle(Graphic3d_ClipPlane)& aClipPlane = aRegPlanes.Find (aPlane);
6078 TCollection_AsciiString aChangeArg (theArgVec [3]);
6079 if (aChangeArg != "on" && aChangeArg != "off" && aChangeArg != "capping" && aChangeArg != "equation")
6081 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
6085 if (aChangeArg == "on" || aChangeArg == "off") // on / off
6087 aClipPlane->SetOn (aChangeArg == "on");
6089 else if (aChangeArg == "equation") // change equation
6093 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6097 Standard_Real aCoeffA = Draw::Atof (theArgVec [4]);
6098 Standard_Real aCoeffB = Draw::Atof (theArgVec [5]);
6099 Standard_Real aCoeffC = Draw::Atof (theArgVec [6]);
6100 Standard_Real aCoeffD = Draw::Atof (theArgVec [7]);
6101 aClipPlane->SetEquation (gp_Pln (aCoeffA, aCoeffB, aCoeffC, aCoeffD));
6103 else if (aChangeArg == "capping") // change capping aspects
6107 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6111 TCollection_AsciiString aCappingArg (theArgVec [4]);
6112 if (aCappingArg != "on" && aCappingArg != "off" &&
6113 aCappingArg != "color" && aCappingArg != "texname" &&
6114 aCappingArg != "texscale" && aCappingArg != "texorigin" &&
6115 aCappingArg != "texrotate" && aCappingArg != "hatch")
6117 theDi << theArgVec[0] << ": invalid arguments. Type help for more information.\n";
6121 if (aCappingArg == "on" || aCappingArg == "off") // on / off capping
6123 aClipPlane->SetCapping (aCappingArg == "on");
6125 else if (aCappingArg == "color") // color aspect for capping
6129 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6133 Standard_Real aRed = Draw::Atof (theArgVec [5]);
6134 Standard_Real aGrn = Draw::Atof (theArgVec [6]);
6135 Standard_Real aBlu = Draw::Atof (theArgVec [7]);
6137 Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
6138 Quantity_Color aColor (aRed, aGrn, aBlu, Quantity_TOC_RGB);
6139 aMat.SetAmbientColor (aColor);
6140 aMat.SetDiffuseColor (aColor);
6141 aClipPlane->SetCappingMaterial (aMat);
6143 else if (aCappingArg == "texname") // texture name
6147 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6151 TCollection_AsciiString aTextureName (theArgVec [5]);
6153 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
6154 if (!aTexture->IsDone ())
6156 aClipPlane->SetCappingTexture (NULL);
6160 aTexture->EnableModulate();
6161 aTexture->EnableRepeat();
6162 aClipPlane->SetCappingTexture (aTexture);
6165 else if (aCappingArg == "texscale") // texture scale
6167 if (aClipPlane->CappingTexture().IsNull())
6169 theDi << theArgVec[0] << ": no texture is set.\n";
6175 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6179 Standard_ShortReal aSx = (Standard_ShortReal)atof (theArgVec [5]);
6180 Standard_ShortReal aSy = (Standard_ShortReal)atof (theArgVec [6]);
6182 aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
6184 else if (aCappingArg == "texorigin") // texture origin
6186 if (aClipPlane->CappingTexture().IsNull())
6188 theDi << theArgVec[0] << ": no texture is set.\n";
6194 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6198 Standard_ShortReal aTx = (Standard_ShortReal)atof (theArgVec [5]);
6199 Standard_ShortReal aTy = (Standard_ShortReal)atof (theArgVec [6]);
6201 aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
6203 else if (aCappingArg == "texrotate") // texture rotation
6205 if (aClipPlane->CappingTexture().IsNull())
6207 theDi << theArgVec[0] << ": no texture is set.\n";
6213 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6217 Standard_ShortReal aRot = (Standard_ShortReal)atof (theArgVec[5]);
6219 aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
6221 else if (aCappingArg == "hatch") // hatch style
6225 theDi << theArgVec[0] << ": need more arguments. Type help for more information.\n";
6229 TCollection_AsciiString aHatchStr (theArgVec [5]);
6230 if (aHatchStr == "on")
6232 aClipPlane->SetCappingHatchOn();
6234 else if (aHatchStr == "off")
6236 aClipPlane->SetCappingHatchOff();
6240 aClipPlane->SetCappingHatch ((Aspect_HatchStyle)atoi (theArgVec[5]));
6245 ViewerTest::RedrawAllViews();
6250 theDi << theArgVec[0] << ": invalid command. Type help for more information.\n";
6254 //===============================================================================================
6255 //function : VSetTextureMode
6257 //===============================================================================================
6258 static int VSetTextureMode (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6262 theDi << theArgVec[0] << ": insufficient command arguments. Type help for more information.\n";
6266 TCollection_AsciiString aViewName (theArgVec[1]);
6267 if (!ViewerTest_myViews.IsBound1 (aViewName))
6269 theDi << theArgVec[0] << ": view is not found.\n";
6273 const Handle(V3d_View)& aView = ViewerTest_myViews.Find1 (aViewName);
6274 switch (atoi (theArgVec[2]))
6276 case 0: aView->SetSurfaceDetail (V3d_TEX_NONE); break;
6277 case 1: aView->SetSurfaceDetail (V3d_TEX_ENVIRONMENT); break;
6278 case 2: aView->SetSurfaceDetail (V3d_TEX_ALL); break;
6280 theDi << theArgVec[0] << ": invalid mode.\n";
6288 //===============================================================================================
6289 //function : VZRange
6291 //===============================================================================================
6292 static int VZRange (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6294 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
6296 if (aCurrentView.IsNull())
6298 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
6302 Handle(Graphic3d_Camera) aCamera = aCurrentView->Camera();
6306 theDi << "ZNear: " << aCamera->ZNear() << "\n";
6307 theDi << "ZFar: " << aCamera->ZFar() << "\n";
6313 Standard_Real aNewZNear = Draw::Atof (theArgVec[1]);
6314 Standard_Real aNewZFar = Draw::Atof (theArgVec[2]);
6316 if (aNewZNear >= aNewZFar)
6318 std::cout << theArgVec[0] << ": invalid arguments: znear should be less than zfar.\n";
6322 if (!aCamera->IsOrthographic() && (aNewZNear <= 0.0 || aNewZFar <= 0.0))
6324 std::cout << theArgVec[0] << ": invalid arguments: ";
6325 std::cout << "znear, zfar should be positive for perspective camera.\n";
6329 aCamera->SetZRange (aNewZNear, aNewZFar);
6333 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
6337 aCurrentView->Redraw();
6342 //===============================================================================================
6343 //function : VAutoZFit
6345 //===============================================================================================
6346 static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec)
6348 const Handle(V3d_View)& aCurrentView = ViewerTest::CurrentView();
6350 if (aCurrentView.IsNull())
6352 std::cout << theArgVec[0] << ": Call vinit before this command, please.\n";
6356 Standard_Real aScale = aCurrentView->View()->AutoZFitScaleFactor();
6360 std::cout << theArgVec[0] << ": wrong command arguments. Type help for more information.\n";
6366 theDi << "Auto z-fit mode: " << "\n"
6367 << "On: " << (aCurrentView->View()->AutoZFitMode() ? "enabled" : "disabled") << "\n"
6368 << "Scale: " << aScale << "\n";
6372 Standard_Boolean isOn = Draw::Atoi (theArgVec[1]) == 1;
6376 aScale = Draw::Atoi (theArgVec[2]);
6379 aCurrentView->View()->SetAutoZFitMode (isOn, aScale);
6380 aCurrentView->View()->AutoZFit();
6381 aCurrentView->Redraw();
6386 //! Auxiliary function to print projection type
6387 inline const char* projTypeName (Graphic3d_Camera::Projection theProjType)
6389 switch (theProjType)
6391 case Graphic3d_Camera::Projection_Orthographic: return "orthographic";
6392 case Graphic3d_Camera::Projection_Perspective: return "perspective";
6393 case Graphic3d_Camera::Projection_Stereo: return "stereoscopic";
6394 case Graphic3d_Camera::Projection_MonoLeftEye: return "monoLeftEye";
6395 case Graphic3d_Camera::Projection_MonoRightEye: return "monoRightEye";
6400 //===============================================================================================
6401 //function : VCamera
6403 //===============================================================================================
6404 static int VCamera (Draw_Interpretor& theDI,
6405 Standard_Integer theArgsNb,
6406 const char** theArgVec)
6408 Handle(V3d_View) aView = ViewerTest::CurrentView();
6411 std::cout << "Error: no active view.\n";
6415 Handle(Graphic3d_Camera) aCamera = aView->Camera();
6418 theDI << "ProjType: " << projTypeName (aCamera->ProjectionType()) << "\n";
6419 theDI << "FOVy: " << aCamera->FOVy() << "\n";
6420 theDI << "Distance: " << aCamera->Distance() << "\n";
6421 theDI << "IOD: " << aCamera->IOD() << "\n";
6422 theDI << "IODType: " << (aCamera->GetIODType() == Graphic3d_Camera::IODType_Absolute ? "absolute" : "relative") << "\n";
6423 theDI << "ZFocus: " << aCamera->ZFocus() << "\n";
6424 theDI << "ZFocusType: " << (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Absolute ? "absolute" : "relative") << "\n";
6428 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
6430 Standard_CString anArg = theArgVec[anArgIter];
6431 TCollection_AsciiString anArgCase (anArg);
6432 anArgCase.LowerCase();
6433 if (anArgCase == "-proj"
6434 || anArgCase == "-projection"
6435 || anArgCase == "-projtype"
6436 || anArgCase == "-projectiontype")
6438 theDI << projTypeName (aCamera->ProjectionType()) << " ";
6440 else if (anArgCase == "-ortho"
6441 || anArgCase == "-orthographic")
6443 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
6445 else if (anArgCase == "-persp"
6446 || anArgCase == "-perspective"
6447 || anArgCase == "-perspmono"
6448 || anArgCase == "-perspectivemono"
6449 || anArgCase == "-mono")
6451 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
6453 else if (anArgCase == "-stereo"
6454 || anArgCase == "-stereoscopic"
6455 || anArgCase == "-perspstereo"
6456 || anArgCase == "-perspectivestereo")
6458 aCamera->SetProjectionType (Graphic3d_Camera::Projection_Stereo);
6460 else if (anArgCase == "-left"
6461 || anArgCase == "-lefteye"
6462 || anArgCase == "-monoleft"
6463 || anArgCase == "-monolefteye"
6464 || anArgCase == "-perpsleft"
6465 || anArgCase == "-perpslefteye")
6467 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
6469 else if (anArgCase == "-right"
6470 || anArgCase == "-righteye"
6471 || anArgCase == "-monoright"
6472 || anArgCase == "-monorighteye"
6473 || anArgCase == "-perpsright")
6475 aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
6477 else if (anArgCase == "-dist"
6478 || anArgCase == "-distance")
6480 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
6481 if (anArgValue != NULL
6482 && *anArgValue != '-')
6485 aCamera->SetDistance (Draw::Atof (anArgValue));
6488 theDI << aCamera->Distance() << " ";
6490 else if (anArgCase == "-iod")
6492 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
6493 if (anArgValue != NULL
6494 && *anArgValue != '-')
6497 aCamera->SetIOD (aCamera->GetIODType(), Draw::Atof (anArgValue));
6500 theDI << aCamera->IOD() << " ";
6502 else if (anArgCase == "-iodtype")
6504 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
6505 TCollection_AsciiString anValueCase (anArgValue);
6506 anValueCase.LowerCase();
6507 if (anValueCase == "abs"
6508 || anValueCase == "absolute")
6511 aCamera->SetIOD (Graphic3d_Camera::IODType_Absolute, aCamera->IOD());
6514 else if (anValueCase == "rel"
6515 || anValueCase == "relative")
6518 aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, aCamera->IOD());
6521 else if (*anArgValue != '-')
6523 std::cout << "Error: unknown IOD type '" << anArgValue << "'\n";
6526 switch (aCamera->GetIODType())
6528 case Graphic3d_Camera::IODType_Absolute: theDI << "absolute "; break;
6529 case Graphic3d_Camera::IODType_Relative: theDI << "relative "; break;
6532 else if (anArgCase == "-zfocus")
6534 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
6535 if (anArgValue != NULL
6536 && *anArgValue != '-')
6539 aCamera->SetZFocus (aCamera->ZFocusType(), Draw::Atof (anArgValue));
6542 theDI << aCamera->ZFocus() << " ";
6544 else if (anArgCase == "-zfocustype")
6546 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : "";
6547 TCollection_AsciiString anValueCase (anArgValue);
6548 anValueCase.LowerCase();
6549 if (anValueCase == "abs"
6550 || anValueCase == "absolute")
6553 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Absolute, aCamera->ZFocus());
6556 else if (anValueCase == "rel"
6557 || anValueCase == "relative")
6560 aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, aCamera->ZFocus());
6563 else if (*anArgValue != '-')
6565 std::cout << "Error: unknown ZFocus type '" << anArgValue << "'\n";
6568 switch (aCamera->ZFocusType())
6570 case Graphic3d_Camera::FocusType_Absolute: theDI << "absolute "; break;
6571 case Graphic3d_Camera::FocusType_Relative: theDI << "relative "; break;
6574 else if (anArgCase == "-fov"
6575 || anArgCase == "-fovy")
6577 Standard_CString anArgValue = (anArgIter + 1 < theArgsNb) ? theArgVec[anArgIter + 1] : NULL;
6578 if (anArgValue != NULL
6579 && *anArgValue != '-')
6582 aCamera->SetFOVy (Draw::Atof (anArgValue));
6585 theDI << aCamera->FOVy() << " ";
6589 std::cout << "Error: unknown argument '" << anArg << "'\n";
6594 aView->View()->AutoZFit();
6600 //==============================================================================
6601 //function : VStereo
6603 //==============================================================================
6605 static int VStereo (Draw_Interpretor& theDI,
6606 Standard_Integer theArgNb,
6607 const char** theArgVec)
6611 Handle(V3d_View) aView = ViewerTest::CurrentView();
6614 std::cerr << "No active view. Please call vinit.\n";
6618 Standard_Boolean isActive = ViewerTest_myDefaultCaps.contextStereo;
6619 theDI << "Stereo " << (isActive ? "ON" : "OFF") << "\n";
6623 ViewerTest_myDefaultCaps.contextStereo = Draw::Atoi (theArgVec[1]) != 0;
6627 //===============================================================================================
6628 //function : VDefaults
6630 //===============================================================================================
6631 static int VDefaults (Draw_Interpretor& theDi,
6632 Standard_Integer theArgsNb,
6633 const char** theArgVec)
6635 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
6638 std::cerr << "No active viewer!\n";
6642 Handle(Prs3d_Drawer) aDefParams = aCtx->DefaultDrawer();
6645 if (aDefParams->TypeOfDeflection() == Aspect_TOD_RELATIVE)
6647 theDi << "DeflType: relative\n"
6648 << "DeviationCoeff: " << aDefParams->DeviationCoefficient() << "\n";
6652 theDi << "DeflType: absolute\n"
6653 << "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
6655 theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
6656 theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
6660 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
6662 TCollection_AsciiString anArg (theArgVec[anArgIter]);
6664 if (anArg == "-ABSDEFL"
6665 || anArg == "-ABSOLUTEDEFLECTION"
6667 || anArg == "-DEFLECTION")
6669 if (++anArgIter >= theArgsNb)
6671 std::cout << "Error: wrong syntax at " << anArg << "\n";
6674 aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
6675 aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
6677 else if (anArg == "-RELDEFL"
6678 || anArg == "-RELATIVEDEFLECTION"
6679 || anArg == "-DEVCOEFF"
6680 || anArg == "-DEVIATIONCOEFF"
6681 || anArg == "-DEVIATIONCOEFFICIENT")
6683 if (++anArgIter >= theArgsNb)
6685 std::cout << "Error: wrong syntax at " << anArg << "\n";
6688 aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
6689 aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
6691 else if (anArg == "-ANGDEFL"
6692 || anArg == "-ANGULARDEFL"
6693 || anArg == "-ANGULARDEFLECTION")
6695 if (++anArgIter >= theArgsNb)
6697 std::cout << "Error: wrong syntax at " << anArg << "\n";
6700 // currently HLRDeviationAngle is used instead of DeviationAngle in most places
6701 aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
6703 if (anArg == "-AUTOTR"
6704 || anArg == "-AUTOTRIANG"
6705 || anArg == "-AUTOTRIANGULATION")
6707 if (++anArgIter >= theArgsNb)
6709 std::cout << "Error: wrong syntax at " << anArg << "\n";
6712 TCollection_AsciiString aValue (theArgVec[anArgIter]);
6717 aDefParams->SetAutoTriangulation (Standard_True);
6719 else if (aValue == "off"
6722 aDefParams->SetAutoTriangulation (Standard_False);
6727 std::cerr << "Warning, unknown argument '" << anArg.ToCString() << "'\n";
6734 //! Auxiliary method
6735 inline void addLight (const Handle(V3d_Light)& theLightNew,
6736 const Standard_Boolean theIsGlobal)
6738 if (theLightNew.IsNull())
6745 ViewerTest::GetViewerFromContext()->SetLightOn (theLightNew);
6749 ViewerTest::CurrentView()->SetLightOn (theLightNew);
6753 //! Auxiliary method
6754 inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
6756 TCollection_AsciiString anArgNextCase (theArgNext);
6757 anArgNextCase.UpperCase();
6758 if (anArgNextCase.Length() > 5
6759 && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
6761 return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
6765 return theArgNext.IntegerValue();
6769 //===============================================================================================
6772 //===============================================================================================
6773 static int VLight (Draw_Interpretor& theDi,
6774 Standard_Integer theArgsNb,
6775 const char** theArgVec)
6777 Handle(V3d_View) aView = ViewerTest::CurrentView();
6778 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
6780 || aViewer.IsNull())
6782 std::cerr << "No active viewer!\n";
6786 Standard_Real anXYZ[3];
6787 Quantity_Coefficient anAtten[2];
6790 // print lights info
6791 Standard_Integer aLightId = 0;
6792 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightId)
6794 Handle(V3d_Light) aLight = aView->ActiveLight();
6795 const Quantity_Color aColor = aLight->Color();
6796 theDi << "Light" << aLightId << "\n";
6797 switch (aLight->Type())
6801 theDi << " Type: Ambient\n";
6804 case V3d_DIRECTIONAL:
6806 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLight);
6807 theDi << " Type: Directional\n";
6808 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
6809 if (!aLightDir.IsNull())
6811 aLightDir->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
6812 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6813 aLightDir->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
6814 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6818 case V3d_POSITIONAL:
6820 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight)::DownCast (aLight);
6821 theDi << " Type: Positional\n";
6822 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
6823 if (!aLightPos.IsNull())
6825 aLightPos->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
6826 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6827 aLightPos->Attenuation (anAtten[0], anAtten[1]);
6828 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
6834 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight)::DownCast (aLight);
6835 theDi << " Type: Spot\n";
6836 theDi << " Headlight: " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
6837 if (!aLightSpot.IsNull())
6839 aLightSpot->Position (anXYZ[0], anXYZ[1], anXYZ[2]);
6840 theDi << " Position: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6841 aLightSpot->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
6842 theDi << " Direction: " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
6843 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
6844 theDi << " Atten.: " << anAtten[0] << " " << anAtten[1] << "\n";
6845 theDi << " Angle: " << (aLightSpot->Angle() * 180.0 / M_PI) << "\n";
6846 theDi << " Exponent: " << aLightSpot->Concentration() << "\n";
6852 theDi << " Type: UNKNOWN\n";
6856 theDi << " Color: " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << "\n";
6860 Handle(V3d_Light) aLightNew;
6861 Handle(V3d_Light) aLightOld;
6862 Standard_Boolean isGlobal = Standard_True;
6863 Standard_Boolean toCreate = Standard_False;
6864 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
6866 Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
6867 Handle(V3d_AmbientLight) aLightAmb = Handle(V3d_AmbientLight) ::DownCast (aLightCurr);
6868 Handle(V3d_DirectionalLight) aLightDir = Handle(V3d_DirectionalLight)::DownCast (aLightCurr);
6869 Handle(V3d_PositionalLight) aLightPos = Handle(V3d_PositionalLight) ::DownCast (aLightCurr);
6870 Handle(V3d_SpotLight) aLightSpot = Handle(V3d_SpotLight) ::DownCast (aLightCurr);
6872 TCollection_AsciiString aName, aValue;
6873 const TCollection_AsciiString anArg (theArgVec[anArgIt]);
6874 TCollection_AsciiString anArgCase (anArg);
6875 anArgCase.UpperCase();
6876 if (anArgCase.IsEqual ("NEW")
6877 || anArgCase.IsEqual ("ADD")
6878 || anArgCase.IsEqual ("CREATE"))
6880 toCreate = Standard_True;
6882 else if (anArgCase.IsEqual ("GLOB")
6883 || anArgCase.IsEqual ("GLOBAL"))
6885 isGlobal = Standard_True;
6887 else if (anArgCase.IsEqual ("LOC")
6888 || anArgCase.IsEqual ("LOCAL"))
6890 isGlobal = Standard_False;
6892 else if (anArgCase.IsEqual ("DEF")
6893 || anArgCase.IsEqual ("DEFAULTS"))
6895 toCreate = Standard_False;
6896 aViewer->SetDefaultLights();
6898 else if (anArgCase.IsEqual ("CLR")
6899 || anArgCase.IsEqual ("CLEAR"))
6901 toCreate = Standard_False;
6902 aView->InitActiveLights();
6903 while (aView->MoreActiveLights())
6905 aViewer->DelLight (aView->ActiveLight());
6906 aView->InitActiveLights();
6909 else if (anArgCase.IsEqual ("AMB")
6910 || anArgCase.IsEqual ("AMBIENT")
6911 || anArgCase.IsEqual ("AMBLIGHT"))
6913 addLight (aLightNew, isGlobal);
6916 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6919 toCreate = Standard_False;
6920 aLightNew = new V3d_AmbientLight (aViewer);
6922 else if (anArgCase.IsEqual ("DIRECTIONAL")
6923 || anArgCase.IsEqual ("DIRLIGHT"))
6925 addLight (aLightNew, isGlobal);
6928 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6931 toCreate = Standard_False;
6932 aLightNew = new V3d_DirectionalLight (aViewer);
6934 else if (anArgCase.IsEqual ("SPOT")
6935 || anArgCase.IsEqual ("SPOTLIGHT"))
6937 addLight (aLightNew, isGlobal);
6940 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6943 toCreate = Standard_False;
6944 aLightNew = new V3d_SpotLight (aViewer, 0.0, 0.0, 0.0);
6946 else if (anArgCase.IsEqual ("POSLIGHT")
6947 || anArgCase.IsEqual ("POSITIONAL"))
6949 addLight (aLightNew, isGlobal);
6952 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6955 toCreate = Standard_False;
6956 aLightNew = new V3d_PositionalLight (aViewer, 0.0, 0.0, 0.0);
6958 else if (anArgCase.IsEqual ("CHANGE"))
6960 addLight (aLightNew, isGlobal);
6961 aLightNew.Nullify();
6962 if (++anArgIt >= theArgsNb)
6964 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6968 const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
6969 Standard_Integer aLightIt = 0;
6970 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
6972 if (aLightIt == aLightId)
6974 aLightOld = aView->ActiveLight();
6979 if (aLightOld.IsNull())
6981 std::cerr << "Light " << theArgVec[anArgIt] << " is undefined!\n";
6985 else if (anArgCase.IsEqual ("DEL")
6986 || anArgCase.IsEqual ("DELETE"))
6988 Handle(V3d_Light) aLightDel;
6989 if (++anArgIt >= theArgsNb)
6991 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
6995 const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
6996 const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
6997 Standard_Integer aLightIt = 0;
6998 for (aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights(), ++aLightIt)
7000 aLightDel = aView->ActiveLight();
7001 if (aLightIt == aLightDelId)
7006 if (!aLightDel.IsNull())
7008 aViewer->DelLight (aLightDel);
7011 else if (anArgCase.IsEqual ("COLOR")
7012 || anArgCase.IsEqual ("COLOUR"))
7014 if (++anArgIt >= theArgsNb)
7016 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7020 TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
7021 anArgNext.UpperCase();
7022 const Quantity_Color aColor = ViewerTest::GetColorFromName (anArgNext.ToCString());
7023 if (!aLightCurr.IsNull())
7025 aLightCurr->SetColor (aColor);
7028 else if (anArgCase.IsEqual ("POS")
7029 || anArgCase.IsEqual ("POSITION"))
7031 if ((anArgIt + 3) >= theArgsNb)
7033 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7037 anXYZ[0] = Atof (theArgVec[++anArgIt]);
7038 anXYZ[1] = Atof (theArgVec[++anArgIt]);
7039 anXYZ[2] = Atof (theArgVec[++anArgIt]);
7040 if (!aLightDir.IsNull())
7042 aLightDir->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7044 else if (!aLightPos.IsNull())
7046 aLightPos->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7048 else if (!aLightSpot.IsNull())
7050 aLightSpot->SetPosition (anXYZ[0], anXYZ[1], anXYZ[2]);
7054 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7058 else if (anArgCase.IsEqual ("DIR")
7059 || anArgCase.IsEqual ("DIRECTION"))
7061 if ((anArgIt + 3) >= theArgsNb)
7063 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7067 anXYZ[0] = Atof (theArgVec[++anArgIt]);
7068 anXYZ[1] = Atof (theArgVec[++anArgIt]);
7069 anXYZ[2] = Atof (theArgVec[++anArgIt]);
7070 if (!aLightDir.IsNull())
7072 aLightDir->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
7074 else if (!aLightSpot.IsNull())
7076 aLightSpot->SetDirection (anXYZ[0], anXYZ[1], anXYZ[2]);
7080 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7084 else if (anArgCase.IsEqual ("ANG")
7085 || anArgCase.IsEqual ("ANGLE"))
7087 if (++anArgIt >= theArgsNb)
7089 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7093 Standard_Real anAngle = Atof (theArgVec[anArgIt]);
7095 if (!aLightSpot.IsNull())
7097 aLightSpot->SetAngle (anAngle / 180.0 * M_PI);
7100 else if (anArgCase.IsEqual ("CONSTATTEN")
7101 || anArgCase.IsEqual ("CONSTATTENUATION"))
7103 if (++anArgIt >= theArgsNb)
7105 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7109 if (!aLightPos.IsNull())
7111 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7112 anAtten[0] = Atof (theArgVec[anArgIt]);
7113 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
7115 else if (!aLightSpot.IsNull())
7117 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7118 anAtten[0] = Atof (theArgVec[anArgIt]);
7119 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
7123 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7127 else if (anArgCase.IsEqual ("LINATTEN")
7128 || anArgCase.IsEqual ("LINEARATTEN")
7129 || anArgCase.IsEqual ("LINEARATTENUATION"))
7131 if (++anArgIt >= theArgsNb)
7133 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7137 if (!aLightPos.IsNull())
7139 aLightPos->Attenuation (anAtten[0], anAtten[1]);
7140 anAtten[1] = Atof (theArgVec[anArgIt]);
7141 aLightPos->SetAttenuation (anAtten[0], anAtten[1]);
7143 else if (!aLightSpot.IsNull())
7145 aLightSpot->Attenuation (anAtten[0], anAtten[1]);
7146 anAtten[1] = Atof (theArgVec[anArgIt]);
7147 aLightSpot->SetAttenuation (anAtten[0], anAtten[1]);
7151 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7155 else if (anArgCase.IsEqual ("EXP")
7156 || anArgCase.IsEqual ("EXPONENT")
7157 || anArgCase.IsEqual ("SPOTEXP")
7158 || anArgCase.IsEqual ("SPOTEXPONENT"))
7160 if (++anArgIt >= theArgsNb)
7162 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7166 if (!aLightSpot.IsNull())
7168 aLightSpot->SetConcentration (Atof (theArgVec[anArgIt]));
7172 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7176 else if (anArgCase.IsEqual ("HEAD")
7177 || anArgCase.IsEqual ("HEADLIGHT"))
7179 if (++anArgIt >= theArgsNb)
7181 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7185 if (aLightAmb.IsNull()
7186 && !aLightCurr.IsNull())
7188 aLightCurr->SetHeadlight (Draw::Atoi (theArgVec[anArgIt]) != 0);
7192 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
7198 std::cerr << "Warning: unknown argument '" << anArg << "'\n";
7202 addLight (aLightNew, isGlobal);
7203 aViewer->UpdateLights();
7208 //=======================================================================
7209 //function : VRenderParams
7210 //purpose : Enables/disables rendering features
7211 //=======================================================================
7213 static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
7214 Standard_Integer theArgNb,
7215 const char** theArgVec)
7217 Handle(V3d_View) aView = ViewerTest::CurrentView();
7220 std::cerr << "Error: no active viewer!\n";
7224 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
7225 TCollection_AsciiString aCmdName (theArgVec[0]);
7226 aCmdName.LowerCase();
7227 if (aCmdName == "vraytrace")
7231 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "on" : "off") << " ";
7234 else if (theArgNb == 2)
7236 TCollection_AsciiString aValue (theArgVec[1]);
7241 aParams.Method = Graphic3d_RM_RAYTRACING;
7245 else if (aValue == "off"
7248 aParams.Method = Graphic3d_RM_RASTERIZATION;
7254 std::cout << "Error: unknown argument '" << theArgVec[1] << "'\n";
7260 std::cout << "Error: wrong number of arguments\n";
7267 theDI << "renderMode: ";
7268 switch (aParams.Method)
7270 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
7271 case Graphic3d_RM_RAYTRACING: theDI << "raytrace "; break;
7274 theDI << "fsaa: " << (aParams.IsAntialiasingEnabled ? "on" : "off") << "\n";
7275 theDI << "shadows: " << (aParams.IsShadowEnabled ? "on" : "off") << "\n";
7276 theDI << "reflections: " << (aParams.IsReflectionEnabled ? "on" : "off") << "\n";
7277 theDI << "rayDepth: " << aParams.RaytracingDepth << "\n";
7278 theDI << "gleam: " << (aParams.IsTransparentShadowEnabled ? "on" : "off") << "\n";
7279 theDI << "shadingModel: ";
7280 switch (aView->ShadingModel())
7282 case V3d_COLOR: theDI << "color"; break;
7283 case V3d_FLAT: theDI << "flat"; break;
7284 case V3d_GOURAUD: theDI << "gouraud"; break;
7285 case V3d_PHONG: theDI << "phong"; break;
7291 Standard_Boolean toPrint = Standard_False;
7292 ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
7293 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7295 Standard_CString anArg (theArgVec[anArgIter]);
7296 TCollection_AsciiString aFlag (anArg);
7298 if (anUpdateTool.parseRedrawMode (aFlag))
7302 else if (aFlag == "-echo"
7303 || aFlag == "-print")
7305 toPrint = Standard_True;
7306 anUpdateTool.Invalidate();
7308 else if (aFlag == "-mode"
7309 || aFlag == "-rendermode"
7310 || aFlag == "-render_mode")
7314 switch (aParams.Method)
7316 case Graphic3d_RM_RASTERIZATION: theDI << "rasterization "; break;
7317 case Graphic3d_RM_RAYTRACING: theDI << "ray-tracing "; break;
7323 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
7327 else if (aFlag == "-ray"
7328 || aFlag == "-raytrace")
7332 theDI << (aParams.Method == Graphic3d_RM_RAYTRACING ? "true" : "false") << " ";
7336 aParams.Method = Graphic3d_RM_RAYTRACING;
7338 else if (aFlag == "-rast"
7339 || aFlag == "-raster"
7340 || aFlag == "-rasterization")
7344 theDI << (aParams.Method == Graphic3d_RM_RASTERIZATION ? "true" : "false") << " ";
7348 aParams.Method = Graphic3d_RM_RASTERIZATION;
7350 else if (aFlag == "-raydepth"
7351 || aFlag == "-ray_depth")
7355 theDI << aParams.RaytracingDepth << " ";
7358 else if (++anArgIter >= theArgNb)
7360 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
7364 const Standard_Integer aDepth = Draw::Atoi (theArgVec[anArgIter]);
7365 if (aDepth < 1 || aDepth > 10)
7367 std::cerr << "Error: invalid ray-tracing depth " << aDepth << ". Should be within range [1; 10]\n";
7372 aParams.RaytracingDepth = aDepth;
7375 else if (aFlag == "-shad"
7376 || aFlag == "-shadows")
7380 theDI << (aParams.IsShadowEnabled ? "on" : "off") << " ";
7384 Standard_Boolean toEnable = Standard_True;
7385 if (++anArgIter < theArgNb
7386 && !parseOnOff (theArgVec[anArgIter], toEnable))
7390 aParams.IsShadowEnabled = toEnable;
7392 else if (aFlag == "-refl"
7393 || aFlag == "-reflections")
7397 theDI << (aParams.IsReflectionEnabled ? "on" : "off") << " ";
7401 Standard_Boolean toEnable = Standard_True;
7402 if (++anArgIter < theArgNb
7403 && !parseOnOff (theArgVec[anArgIter], toEnable))
7407 aParams.IsReflectionEnabled = toEnable;
7409 else if (aFlag == "-fsaa")
7413 theDI << (aParams.IsAntialiasingEnabled ? "on" : "off") << " ";
7417 Standard_Boolean toEnable = Standard_True;
7418 if (++anArgIter < theArgNb
7419 && !parseOnOff (theArgVec[anArgIter], toEnable))
7423 aParams.IsAntialiasingEnabled = toEnable;
7425 else if (aFlag == "-gleam")
7429 theDI << (aParams.IsTransparentShadowEnabled ? "on" : "off") << " ";
7433 Standard_Boolean toEnable = Standard_True;
7434 if (++anArgIter < theArgNb
7435 && !parseOnOff (theArgVec[anArgIter], toEnable))
7439 aParams.IsTransparentShadowEnabled = toEnable;
7441 else if (aFlag == "-shademodel"
7442 || aFlag == "-shadingmodel"
7443 || aFlag == "-shading")
7447 switch (aView->ShadingModel())
7449 case V3d_COLOR: theDI << "color "; break;
7450 case V3d_FLAT: theDI << "flat "; break;
7451 case V3d_GOURAUD: theDI << "gouraud "; break;
7452 case V3d_PHONG: theDI << "phong "; break;
7457 if (++anArgIter >= theArgNb)
7459 std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
7462 TCollection_AsciiString aMode (theArgVec[anArgIter]);
7464 if (aMode == "color"
7467 aView->SetShadingModel (V3d_COLOR);
7469 else if (aMode == "flat"
7470 || aMode == "facet")
7472 aView->SetShadingModel (V3d_FLAT);
7474 else if (aMode == "gouraud"
7475 || aMode == "vertex"
7478 aView->SetShadingModel (V3d_GOURAUD);
7480 else if (aMode == "phong"
7481 || aMode == "fragment"
7483 || aMode == "pixel")
7485 aView->SetShadingModel (V3d_PHONG);
7489 std::cout << "Error: unknown shading model '" << aMode << "'\n";
7495 std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
7502 //=======================================================================
7503 //function : VFrustumCulling
7504 //purpose : enables/disables view volume's culling.
7505 //=======================================================================
7506 static int VFrustumCulling (Draw_Interpretor& theDI,
7507 Standard_Integer theArgNb,
7508 const char** theArgVec)
7510 Handle(V3d_View) aView = ViewerTest::CurrentView();
7513 std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
7519 theDI << (aView->IsCullingEnabled() ? "on" : "off");
7522 else if (theArgNb != 2)
7524 std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
7528 TCollection_AsciiString aModeStr (theArgVec[1]);
7529 aModeStr.LowerCase();
7530 Standard_Boolean toEnable = 0;
7531 if (aModeStr == "on")
7535 else if (aModeStr == "off")
7541 toEnable = Draw::Atoi (theArgVec[1]) != 0;
7544 aView->SetFrustumCulling (toEnable);
7549 //=======================================================================
7550 //function : VHighlightSelected
7552 //=======================================================================
7553 static int VHighlightSelected (Draw_Interpretor& theDI,
7554 Standard_Integer theArgNb,
7555 const char** theArgVec)
7557 if (ViewerTest::GetAISContext().IsNull())
7559 std::cout << theArgVec[0] << " error : Context is not created. Please call vinit before.\n";
7563 const Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7567 theDI << (aContext->ToHilightSelected() ? "on" : "off");
7573 std::cout << theArgVec[0] << " error : wrong number of parameters."
7574 << "Type 'help" << theArgVec[0] << "' for more information.";
7579 TCollection_AsciiString aMode (theArgVec[1]);
7581 Standard_Boolean toEnable = Standard_False;
7582 if (aMode.IsEqual ("on"))
7584 toEnable = Standard_True;
7586 else if (aMode.IsEqual ("off"))
7588 toEnable = Standard_False;
7592 toEnable = Draw::Atoi (theArgVec[1]) != 0;
7595 if (toEnable != aContext->ToHilightSelected())
7597 aContext->SetToHilightSelected (toEnable);
7599 // Move cursor to null position and back to process updating of detection
7600 // and highlighting of selected object immediatly.
7601 Standard_Integer aPixX = 0;
7602 Standard_Integer aPixY = 0;
7603 const Handle(ViewerTest_EventManager)& anEventManager = ViewerTest::CurrentEventManager();
7605 anEventManager->GetCurrentPosition (aPixX, aPixY);
7606 anEventManager->MoveTo (0, 0);
7607 anEventManager->MoveTo (aPixX, aPixY);
7613 //=======================================================================
7614 //function : VXRotate
7616 //=======================================================================
7617 static Standard_Integer VXRotate (Draw_Interpretor& di,
7618 Standard_Integer argc,
7621 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
7622 if (aContext.IsNull())
7624 di << argv[0] << "ERROR : use 'vinit' command before " << "\n";
7630 di << "ERROR : Usage : " << argv[0] << " name angle" << "\n";
7634 TCollection_AsciiString aName (argv[1]);
7635 Standard_Real anAngle = Draw::Atof (argv[2]);
7638 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
7639 Handle(AIS_InteractiveObject) anIObj;
7640 if (!aMap.IsBound2 (aName) )
7642 di << "Use 'vdisplay' before" << "\n";
7647 anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
7650 aTransform.SetRotation (gp_Ax1 (gp_Pnt (0.0, 0.0, 0.0), gp_Vec (1.0, 0.0, 0.0)), anAngle);
7651 aTransform.SetTranslationPart (anIObj->LocalTransformation().TranslationPart());
7653 aContext->SetLocation (anIObj, aTransform);
7654 aContext->UpdateCurrentViewer();
7660 //=======================================================================
7661 //function : ViewerCommands
7663 //=======================================================================
7665 void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
7668 const char *group = "ZeViewer";
7669 theCommands.Add("vinit",
7670 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7671 "[name=view_name] [display=display_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
7673 "[name=view_name] [l=leftPx t=topPx] [w=widthPx h=heightPx]\n"
7675 " - Creates new View window with specified name view_name.\n"
7676 "By default the new view is created in the viewer and in"
7677 " graphic driver shared with active view.\n"
7678 " - name = {driverName/viewerName/viewName | viewerName/viewName | viewName}.\n"
7679 "If driverName isn't specified the driver will be shared with active view.\n"
7680 "If viewerName isn't specified the viewer will be shared with active view.\n"
7681 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7682 " - display = HostName.DisplayNumber[:ScreenNumber] : if specified"
7683 "is used in creation of graphic driver\n"
7685 " - l, t: pixel position of left top corner of the window\n"
7686 " - w,h: width and heigth of window respectively.\n"
7687 "Additional commands for operations with views: vclose, vactivate, vviewlist.\n",
7688 __FILE__,VInit,group);
7689 theCommands.Add("vclose" ,
7690 "[view_id [keep_context=0|1]]\n"
7691 "or vclose ALL - to remove all created views\n"
7692 " - removes view(viewer window) defined by its view_id.\n"
7693 " - keep_context: by default 0; if 1 and the last view is deleted"
7694 " the current context is not removed.",
7695 __FILE__,VClose,group);
7696 theCommands.Add("vactivate" ,
7698 " - activates view(viewer window) defined by its view_id",
7699 __FILE__,VActivate,group);
7700 theCommands.Add("vviewlist",
7701 "vviewlist [format={tree, long}]"
7702 " - prints current list of views per viewer and graphic_driver ID shared between viewers"
7703 " - format: format of result output, if tree the output is a tree view;"
7704 "otherwise it's a list of full view names. By default format = tree",
7705 __FILE__,VViewList,group);
7706 theCommands.Add("vhelp" ,
7707 "vhelp : display help on the viewer commands",
7708 __FILE__,VHelp,group);
7709 theCommands.Add("vtop" ,
7710 "vtop or <T> : Top view" ,
7711 __FILE__,VTop,group);
7712 theCommands.Add("vbottom" ,
7713 "vbottom : Bottom view" ,
7714 __FILE__,VBottom,group);
7715 theCommands.Add("vleft" ,
7716 "vleft : Left view" ,
7717 __FILE__,VLeft,group);
7718 theCommands.Add("vright" ,
7719 "vright : Right view" ,
7720 __FILE__,VRight,group);
7721 theCommands.Add("vaxo" ,
7722 " vaxo or <A> : Axonometric view ",
7723 __FILE__,VAxo,group);
7724 theCommands.Add("vfront" ,
7725 "vfront : Front view" ,
7726 __FILE__,VFront,group);
7727 theCommands.Add("vback" ,
7728 "vback : Back view" ,
7729 __FILE__,VBack,group);
7730 theCommands.Add("vpick" ,
7731 "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
7733 theCommands.Add("vfit" ,
7734 "vfit or <F> : vfit",
7735 __FILE__,VFit,group);
7736 theCommands.Add ("vfitarea",
7737 "vfitarea x1 y1 x2 y2"
7738 "\n\t\t: vfitarea x1 y1 z1 x2 y2 z2"
7739 "\n\t\t: Fit view to show area located between two points"
7740 "\n\t\t: given in world 2D or 3D corrdinates.",
7741 __FILE__, VFitArea, group);
7742 theCommands.Add ("vzfit", "vzfit [scale]\n"
7743 " Matches Z near, Z far view volume planes to the displayed objects.\n"
7744 " \"scale\" - specifies factor to scale computed z range.\n",
7745 __FILE__, VZFit, group);
7746 theCommands.Add("vrepaint",
7747 "vrepaint : vrepaint, force redraw",
7748 __FILE__,VRepaint,group);
7749 theCommands.Add("vclear",
7751 __FILE__,VClear,group);
7752 theCommands.Add("vsetbg",
7753 "vsetbg : vsetbg imagefile [filltype] : Load image as background",
7754 __FILE__,VSetBg,group);
7755 theCommands.Add("vsetbgmode",
7756 "vsetbgmode : vsetbgmode filltype : Change background image fill type",
7757 __FILE__,VSetBgMode,group);
7758 theCommands.Add("vsetgradientbg",
7759 "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
7760 __FILE__,VSetGradientBg,group);
7761 theCommands.Add("vsetgrbgmode",
7762 "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
7763 __FILE__,VSetGradientBgMode,group);
7764 theCommands.Add("vsetcolorbg",
7765 "vsetcolorbg : vsetcolorbg r g b : Set background color",
7766 __FILE__,VSetColorBg,group);
7767 theCommands.Add("vscale",
7768 "vscale : vscale X Y Z",
7769 __FILE__,VScale,group);
7770 theCommands.Add("vzbufftrihedron",
7771 "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper"
7772 " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]"
7773 " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron",
7774 __FILE__,VTestZBuffTrihedron,group);
7775 theCommands.Add("vrotate",
7776 "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]"
7777 "\n : Option -mouseStart starts rotation according to the mouse position"
7778 "\n : Option -mouseMove continues rotation with angle computed"
7779 "\n : from last and new mouse position."
7780 "\n : vrotate AX AY AZ [X Y Z]",
7781 __FILE__,VRotate,group);
7782 theCommands.Add("vzoom",
7783 "vzoom : vzoom coef",
7784 __FILE__,VZoom,group);
7785 theCommands.Add("vpan",
7786 "vpan : vpan dx dy",
7787 __FILE__,VPan,group);
7788 theCommands.Add("vexport",
7789 "vexport : vexport full_file_path {PS | EPS | TEX | PDF | SVG | PGF | EMF }"
7790 " : exports the view to a vector file of a given format"
7791 " : notice that EMF format requires patched gl2ps",
7792 __FILE__,VExport,group);
7793 theCommands.Add("vcolorscale",
7794 "vcolorscale : vcolorscale [-range RangeMin = 0 RangeMax = 100 Intervals = 10 -font HeightFont = 16 -textpos "
7795 "Position = left -xy X = 0 Y = 0] [-noupdate|-update]: draw color scale\n"
7796 "-demo/-demoversion draw a demoversion of color scale.\n"
7797 "-show/display display color scale.\n"
7798 "-hide/erase erase color scale.\n"
7799 "Please note that -show/-hide option must be the first argument!\n"
7800 "-color Index R G B: set color for indexed interval\n"
7801 "-color Index ColorName: set color for indexed interval\n"
7802 "-colors R G B R G B ...: set colors for all intervals\n"
7803 "-colors ColorName1 ColorName2 ...: set colors for all intervals\n"
7804 "-colors supports both color names and rgb values in one call\n"
7805 "-label Index Text: set label for indexed interval\n"
7806 "-labels Text Text Text ...: set labels for all intervals\n"
7807 "-title Title [Position]: set the title for color scale with certain position. Default position = center;\n"
7808 "Available text positions: left, right, center, none;\n",
7809 __FILE__,VColorScale,group);
7810 theCommands.Add("vgraduatedtrihedron",
7811 "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]",
7812 __FILE__,VGraduatedTrihedron,group);
7813 theCommands.Add("vprintview" ,
7814 "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile",
7815 __FILE__,VPrintView,group);
7816 theCommands.Add("vzlayer",
7817 "vzlayer add/del/get/settings/enable/disable [id]\n"
7818 " add - add new z layer to viewer and print its id\n"
7819 " del - del z layer by its id\n"
7820 " get - print sequence of z layers in increasing order of their overlay level\n"
7821 " settings - print status of z layer settings\n"
7822 " enable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n enables given setting for the z layer\n"
7823 " enable (p[ositive]offset/n[egative]offset) \n enables given setting for the z layer\n"
7824 " disable ([depth]test/[depth]write/[depth]clear/[depth]offset) \n disables given setting for the z layer\n"
7825 "\nWhere id is the layer identificator\n"
7828 " vzlayer enable poffset 1\n"
7829 " vzlayer disable depthtest 1\n"
7831 __FILE__,VZLayer,group);
7832 theCommands.Add("voverlaytext",
7833 "voverlaytext : text x y [height] [font_name] [text_color: R G B] [display_type] [background_color: R G B]"
7834 " : height - pixel height of the text (default=10.0)"
7835 " : font_name - name of font (default=courier)"
7836 " : text_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0) "
7837 " : display_type = {normal/subtitle/decal/blend}, (default=normal) "
7838 " : background_color - three values: RedColor GreenColor BlueColor (default = 255.0 255.0 255.0), the parameter is defined for subtitle and decal display types ",
7839 __FILE__,VOverlayText,group);
7840 theCommands.Add("vlayerline",
7841 "vlayerline : vlayerline x1 y1 x2 y2 [linewidth=0.5] [linetype=0] [transparency=1.0]",
7842 __FILE__,VLayerLine,group);
7843 theCommands.Add ("vgrid",
7844 "vgrid [off] [Mode={r|c}] [Type={l|p}] [OriginX OriginY [StepX/StepRadius StepY/DivNb RotAngle]]"
7845 " : Mode - rectangular or circular"
7846 " : Type - lines or points",
7847 __FILE__, VGrid, group);
7848 theCommands.Add ("vfps",
7849 "vfps [framesNb=100] : estimate average frame rate for active view",
7850 __FILE__, VFps, group);
7851 theCommands.Add ("vgldebug",
7852 "vgldebug [{0|1}] : request debug GL context, should be called before vinit\n"
7853 " : this function is implemented only for Windows\n"
7854 " : GL_ARB_debug_output extension should be exported by OpenGL driver!",
7855 __FILE__, VGlDebug, group);
7856 theCommands.Add ("vvbo",
7857 "vvbo [{0|1}] : turn VBO usage On/Off; affects only newly displayed objects",
7858 __FILE__, VVbo, group);
7859 theCommands.Add ("vstereo",
7860 "\nvstereo [{0|1}] : turn stereo usage On/Off; affects only newly displayed objects",
7861 __FILE__, VStereo, group);
7862 theCommands.Add ("vcaps",
7863 "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
7864 "\n\t\t: [-compatibleContext {0|1}]"
7865 "\n\t\t: [-softMode {0|1}] [-noupdate|-update]"
7866 "\n\t\t: Modify particular graphic driver options:"
7867 "\n\t\t: FFP - use fixed-function pipeline instead of"
7868 "\n\t\t: built-in GLSL programs"
7869 "\n\t\t: (requires compatible profile)"
7870 "\n\t\t: VBO - use Vertex Buffer Object (copy vertex"
7871 "\n\t\t: arrays to GPU memory)"
7872 "\n\t\t: sprite - use textured sprites instead of bitmaps"
7873 "\n\t\t: Context creation options:"
7874 "\n\t\t: softMode - software OpenGL implementation"
7875 "\n\t\t: compatibleProfile - backward-compatible profile"
7876 "\n\t\t: Unlike vrenderparams, these parameters control alternative"
7877 "\n\t\t: rendering paths producing the same visual result when"
7879 "\n\t\t: Command is intended for testing old hardware compatibility.",
7880 __FILE__, VCaps, group);
7881 theCommands.Add ("vmemgpu",
7882 "vmemgpu [f]: print system-dependent GPU memory information if available;"
7883 " with f option returns free memory in bytes",
7884 __FILE__, VMemGpu, group);
7885 theCommands.Add ("vreadpixel",
7886 "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [name]"
7887 " : Read pixel value for active view",
7888 __FILE__, VReadPixel, group);
7889 theCommands.Add("diffimage",
7890 "diffimage : diffimage imageFile1 imageFile2 toleranceOfColor(0..1) blackWhite(1|0) borderFilter(1|0) [diffImageFile]",
7891 __FILE__, VDiffImage, group);
7892 theCommands.Add ("vselect",
7893 "vselect x1 y1 [x2 y2 [x3 y3 ... xn yn]] [shift_selection = 0|1]\n"
7894 "- emulates different types of selection:\n"
7895 "- 1) single click selection\n"
7896 "- 2) selection with rectangle having corners at pixel positions (x1,y1) and (x2,y2)\n"
7897 "- 3) selection with polygon having corners in pixel positions (x1,y1), (x2,y2),...,(xn,yn)\n"
7898 "- 4) any of these selections with shift button pressed",
7899 __FILE__, VSelect, group);
7900 theCommands.Add ("vmoveto",
7902 "- emulates cursor movement to pixel postion (x,y)",
7903 __FILE__, VMoveTo, group);
7904 theCommands.Add ("vviewparams", "vviewparams usage:\n"
7906 "- vviewparams [-scale [s]] [-eye [x y z]] [-at [x y z]] [-up [x y z]]\n"
7907 " [-proj [x y z]] [-center x y] [-size sx]\n"
7908 "- Gets or sets current view parameters.\n"
7909 "- If called without arguments, all view parameters are printed.\n"
7910 "- The options are:\n"
7911 " -scale [s] : prints or sets viewport relative scale.\n"
7912 " -eye [x y z] : prints or sets eye location.\n"
7913 " -at [x y z] : prints or sets center of look.\n"
7914 " -up [x y z] : prints or sets direction of up vector.\n"
7915 " -proj [x y z] : prints or sets direction of look.\n"
7916 " -center x y : sets location of center of the screen in pixels.\n"
7917 " -size [sx] : prints viewport projection width and height sizes\n"
7918 " : or changes the size of its maximum dimension.\n",
7919 __FILE__, VViewParams, group);
7920 theCommands.Add("vchangeselected",
7921 "vchangeselected shape"
7922 "- adds to shape to selection or remove one from it",
7923 __FILE__, VChangeSelected, group);
7924 theCommands.Add("vzclipping",
7925 "vzclipping [mode] [depth width]\n"
7926 "- mode = OFF|BACK|FRONT|SLICE depth = [0..1] width = [0..1]\n"
7927 "- gets or sets ZClipping mode, width and depth",
7928 __FILE__,VZClipping,group);
7929 theCommands.Add ("vnbselected",
7930 "vnbselected", __FILE__, VNbSelected, group);
7931 theCommands.Add ("vcamera",
7932 "vcamera [-ortho] [-projtype]"
7934 "\n\t\t: [-fovy [Angle]] [-distance [Distance]]"
7935 "\n\t\t: [-stereo] [-leftEye] [-rightEye]"
7936 "\n\t\t: [-iod [Distance]] [-iodType [absolute|relative]]"
7937 "\n\t\t: [-zfocus [Value]] [-zfocusType [absolute|relative]]"
7938 "\n\t\t: Manage camera parameters."
7939 "\n\t\t: Prints current value when option called without argument."
7940 "\n\t\t: Orthographic camera:"
7941 "\n\t\t: -ortho activate orthographic projection"
7942 "\n\t\t: Perspective camera:"
7943 "\n\t\t: -persp activate perspective projection (mono)"
7944 "\n\t\t: -fovy field of view in y axis, in degrees"
7945 "\n\t\t: -distance distance of eye from camera center"
7946 "\n\t\t: Stereoscopic camera:"
7947 "\n\t\t: -stereo perspective projection (stereo)"
7948 "\n\t\t: -leftEye perspective projection (left eye)"
7949 "\n\t\t: -rightEye perspective projection (right eye)"
7950 "\n\t\t: -iod intraocular distance value"
7951 "\n\t\t: -iodType distance type, absolute or relative"
7952 "\n\t\t: -zfocus stereographic focus value"
7953 "\n\t\t: -zfocusType focus type, absolute or relative",
7954 __FILE__, VCamera, group);
7955 theCommands.Add ("vautozfit", "command to enable or disable automatic z-range adjusting\n"
7956 "- vautozfit [on={1|0}] [scale]\n"
7957 " Prints or changes parameters of automatic z-fit mode:\n"
7958 " \"on\" - turns automatic z-fit on or off\n"
7959 " \"scale\" - specifies factor to scale computed z range.\n",
7960 __FILE__, VAutoZFit, group);
7961 theCommands.Add ("vzrange", "command to manually access znear and zfar values\n"
7962 " vzrange - without parameters shows current values\n"
7963 " vzrange [znear] [zfar] - applies provided values to view",
7964 __FILE__,VZRange, group);
7965 theCommands.Add("vantialiasing",
7966 "vantialiasing 1|0",
7967 __FILE__,VAntialiasing,group);
7968 theCommands.Add ("vpurgedisplay",
7970 "- removes structures which don't belong to objects displayed in neutral point",
7971 __FILE__, VPurgeDisplay, group);
7972 theCommands.Add("vsetviewsize",
7973 "vsetviewsize size",
7974 __FILE__,VSetViewSize,group);
7975 theCommands.Add("vmoveview",
7976 "vmoveview Dx Dy Dz [Start = 1|0]",
7977 __FILE__,VMoveView,group);
7978 theCommands.Add("vtranslateview",
7979 "vtranslateview Dx Dy Dz [Start = 1|0)]",
7980 __FILE__,VTranslateView,group);
7981 theCommands.Add("vturnview",
7982 "vturnview Ax Ay Az [Start = 1|0]",
7983 __FILE__,VTurnView,group);
7984 theCommands.Add("vtextureenv",
7985 "Enables or disables environment mapping in the 3D view, loading the texture from the given standard "
7986 "or user-defined file and optionally applying texture mapping parameters\n"
7988 " vtextureenv off - disables environment mapping\n"
7989 " vtextureenv on {std_texture|texture_file_name} [rep mod flt ss st ts tt rot] - enables environment mapping\n"
7990 " std_texture = (0..7)\n"
7991 " rep = {clamp|repeat}\n"
7992 " mod = {decal|modulate}\n"
7993 " flt = {nearest|bilinear|trilinear}\n"
7994 " ss, st - scale factors for s and t texture coordinates\n"
7995 " ts, tt - translation for s and t texture coordinates\n"
7996 " rot - texture rotation angle in degrees",
7997 __FILE__, VTextureEnv, group);
7998 theCommands.Add("vhlr" ,
7999 "is_enabled={on|off} [show_hidden={1|0}]"
8000 " - Hidden line removal algorithm:"
8001 " - is_enabled: if is on HLR algorithm is applied\n"
8002 " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n",
8003 __FILE__,VHLR,group);
8004 theCommands.Add("vhlrtype" ,
8005 "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
8006 " - Changes the type of HLR algorithm using for shapes."
8007 " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
8008 " if equals to polyalgo, polygonal HLR algorithm is applied."
8009 "If shapes are not given HLR algoithm of given type is applied"
8010 " to all shapes in the view\n",
8011 __FILE__,VHLRType,group);
8012 theCommands.Add("vclipplane", "vclipplane usage: \n"
8013 " maxplanes <view_name> - get plane limit for view.\n"
8014 " create <plane_name> - create new plane.\n"
8015 " delete <plane_name> - delete plane.\n"
8016 " clone <source_plane> <plane_name> - clone the plane definition.\n"
8017 " set/unset <plane_name> object <object list> - set/unset plane for IO.\n"
8018 " set/unset <plane_name> view <view list> - set/unset plane for view.\n"
8019 " change <plane_name> on/off - turn clipping on/off.\n"
8020 " change <plane_name> equation <a> <b> <c> <d> - change plane equation.\n"
8021 " change <plane_name> capping on/off - turn capping on/off.\n"
8022 " change <plane_name> capping color <r> <g> <b> - set color.\n"
8023 " change <plane name> capping texname <texture> - set texture.\n"
8024 " change <plane_name> capping texscale <sx> <sy> - set tex scale.\n"
8025 " change <plane_name> capping texorigin <tx> <ty> - set tex origin.\n"
8026 " change <plane_name> capping texrotate <angle> - set tex rotation.\n"
8027 " change <plane_name> capping hatch on/off/<id> - set hatching mask.\n"
8028 " please use VSetTextureMode command to enable texture rendering in view.\n"
8029 , __FILE__, VClipPlane, group);
8030 theCommands.Add("vsettexturemode", "vsettexturemode view_name mode \n"
8032 " 0 - no textures enabled in view.\n"
8033 " 1 - only environment textures enabled.\n"
8034 " 2 - all textures enabled.\n"
8035 " this command sets texture details mode for the specified view.\n"
8036 , __FILE__, VSetTextureMode, group);
8037 theCommands.Add("vdefaults",
8038 "vdefaults [-absDefl value]"
8039 "\n\t\t: [-devCoeff value]"
8040 "\n\t\t: [-angDefl value]"
8041 "\n\t\t: [-autoTriang {off/on | 0/1}]"
8042 , __FILE__, VDefaults, group);
8043 theCommands.Add("vlight",
8044 "tool to manage light sources, without arguments shows list of lights."
8045 "\n Main commands: "
8046 "\n 'clear' to clear lights"
8047 "\n '{def}aults' to load deafault lights"
8048 "\n 'add' (or 'new') <type> to add any light source"
8049 "\n where <type> is one of {amb}ient|directional|{spot}light|positional"
8050 "\n 'change' <lightId> to edit light source with specified lightId"
8051 "\n\n In addition to 'add' and 'change' commands you can use light parameters:"
8052 "\n {pos}ition X Y Z"
8053 "\n {dir}ection X Y Z (for directional light or for spotlight)"
8054 "\n color colorName"
8055 "\n {head}light 0|1"
8056 "\n {constAtten}uation value"
8057 "\n {linearAtten}uation value"
8059 "\n {spotexp}onent value"
8061 "\n\n example: vlight add positional head 1 pos 0 1 1 color red"
8062 "\n example: vlight change 0 direction 0 -1 0 linearAttenuation 0.2",
8063 __FILE__, VLight, group);
8064 theCommands.Add("vraytrace",
8066 "\n\t\t: Turn on/off raytracing renderer."
8067 "\n\t\t: 'vraytrace 0' alias for 'vrenderparams -raster'."
8068 "\n\t\t: 'vraytrace 1' alias for 'vrenderparams -rayTrace'.",
8069 __FILE__, VRenderParams, group);
8070 theCommands.Add("vrenderparams",
8071 "\n Manages rendering parameters: "
8072 "\n '-rayTrace' Enables GPU ray-tracing"
8073 "\n '-raster' Disables GPU ray-tracing"
8074 "\n '-rayDepth 0..10' Defines maximum ray-tracing depth"
8075 "\n '-shadows on|off' Enables/disables shadows rendering"
8076 "\n '-reflections on|off' Enables/disables specular reflections"
8077 "\n '-fsaa on|off' Enables/disables adaptive anti-aliasing"
8078 "\n '-gleam on|off' Enables/disables transparency shadow effects"
8079 "\n '-shadingModel model' Controls shading model from enumeration"
8080 "\n color, flat, gouraud, phong"
8081 "\n Unlike vcaps, these parameters dramatically change visual properties."
8082 "\n Command is intended to control presentation quality depending on"
8083 "\n hardware capabilities and performance.",
8084 __FILE__, VRenderParams, group);
8085 theCommands.Add("vfrustumculling",
8086 "vfrustumculling [toEnable]: enables/disables objects clipping",
8087 __FILE__,VFrustumCulling,group);
8088 theCommands.Add("vhighlightselected",
8089 "vhighlightselected [0|1] or vhighlightselected [on|off]: enables/disables highlighting of selected objects.\n"
8090 "Without arguments it shows if highlighting of selected objects is enabled now.",
8091 __FILE__,VHighlightSelected,group);
8092 theCommands.Add ("vplace",
8094 "\n\t\t: Places the point (in pixels) at the center of the window",
8095 __FILE__, VPlace, group);
8096 theCommands.Add("vxrotate",
8098 __FILE__,VXRotate,group);